Fix management of hreflang

This commit is contained in:
Laurent Destailleur
2020-12-19 13:44:15 +01:00
parent fe93ee4d08
commit b6bb08ec2e
2 changed files with 14 additions and 1 deletions

View File

@@ -129,6 +129,7 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
$shortlangcode = '';
if ($objectpage->lang) $shortlangcode = substr($objectpage->lang, 0, 2); // en_US or en-US -> en
if (empty($shortlangcode)) $shortlangcode = substr($object->lang, 0, 2); // en_US or en-US -> en
$tplcontent = '';
$tplcontent .= "<?php // BEGIN PHP\n";
@@ -175,6 +176,7 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
if ($tmppage->id > 0) {
$tmpshortlangcode = '';
if ($tmppage->lang) $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en
if (empty($tmpshortlangcode)) $tmpshortlangcode = preg_replace('/[_-].*$/', '', $object->lang); // en_US or en-US -> en
if ($tmpshortlangcode != $shortlangcode) {
$tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $tmppage->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2)) ? '/'.$tmpshortlangcode : '').'/'.$tmppage->pageurl.'.php').'" />'."\n";
}

View File

@@ -940,13 +940,24 @@ if ($action == 'addcontainer')
$objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
$objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
$objectpage->htmlheader = GETPOST('htmlheader', 'none');
$objectpage->fk_page = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);
$objectpage->author_alias = GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml');
$objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS');
$objectpage->fk_object = GETPOST('WEBSITE_OBJECTID');
$substitutionarray = array();
$substitutionarray['__WEBSITE_CREATE_BY__'] = $user->getFullName($langs);
// Define id of page the new page is translation of
$pageidfortranslation = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);
if ($pageidfortranslation > 0) {
// Check if the page we are translation of is alreayd a translation of a source page. if yes, we will use source id instead
$objectpagetmp = new WebsitePage($db);
$objectpagetmp->fetch($pageidfortranslation);
if ($objectpagetmp->fk_page > 0) {
$pageidfortranslation = $objectpagetmp->fk_page;
}
}
$objectpage->fk_page = $pageidfortranslation;
$sample = GETPOST('sample', 'alpha');
if (empty($sample)) $sample = 'empty';