Fix management of hreflang
This commit is contained in:
parent
fe93ee4d08
commit
b6bb08ec2e
@ -129,6 +129,7 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
|
|||||||
|
|
||||||
$shortlangcode = '';
|
$shortlangcode = '';
|
||||||
if ($objectpage->lang) $shortlangcode = substr($objectpage->lang, 0, 2); // en_US or en-US -> en
|
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 = '';
|
||||||
$tplcontent .= "<?php // BEGIN PHP\n";
|
$tplcontent .= "<?php // BEGIN PHP\n";
|
||||||
@ -175,6 +176,7 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
|
|||||||
if ($tmppage->id > 0) {
|
if ($tmppage->id > 0) {
|
||||||
$tmpshortlangcode = '';
|
$tmpshortlangcode = '';
|
||||||
if ($tmppage->lang) $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en
|
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) {
|
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";
|
$tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $tmppage->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2)) ? '/'.$tmpshortlangcode : '').'/'.$tmppage->pageurl.'.php').'" />'."\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -940,13 +940,24 @@ if ($action == 'addcontainer')
|
|||||||
$objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
|
$objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
|
||||||
$objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
|
$objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
|
||||||
$objectpage->htmlheader = GETPOST('htmlheader', 'none');
|
$objectpage->htmlheader = GETPOST('htmlheader', 'none');
|
||||||
$objectpage->fk_page = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);
|
|
||||||
$objectpage->author_alias = GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml');
|
$objectpage->author_alias = GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml');
|
||||||
$objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS');
|
$objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS');
|
||||||
$objectpage->fk_object = GETPOST('WEBSITE_OBJECTID');
|
$objectpage->fk_object = GETPOST('WEBSITE_OBJECTID');
|
||||||
$substitutionarray = array();
|
$substitutionarray = array();
|
||||||
$substitutionarray['__WEBSITE_CREATE_BY__'] = $user->getFullName($langs);
|
$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');
|
$sample = GETPOST('sample', 'alpha');
|
||||||
if (empty($sample)) $sample = 'empty';
|
if (empty($sample)) $sample = 'empty';
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user