mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Fix canonical management in website
This commit is contained in:
parent
c3dd7733e4
commit
3c048e8116
|
|
@ -215,17 +215,17 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage,
|
|||
$canonicalurladdidlang = '';
|
||||
if ($objectpage->lang) { // A language is forced on the page, it means we may have other language files with hard links into properties of page
|
||||
$canonicalurl = (($objectpage->id == $object->fk_default_home) ? '/' : (($shortlangcode != substr($object->lang, 0, 2) ? '/'.$shortlangcode : '').'/'.$objectpage->pageurl.'.php'));
|
||||
} else { // No language forced, it means the canonical is the one with
|
||||
} else { // No language forced, it means the canonical is the one with params making url unique
|
||||
$canonicalurl = '/'.$objectpage->pageurl.'.php';
|
||||
|
||||
if ($object->lang && $listofaltlang) {
|
||||
$tmpshortlangcode = preg_replace('/[_-].*$/', '', $object->lang); // en_US or en-US -> en
|
||||
// Add parameter ID required to be unique/canonical
|
||||
$canonicalurladdidlang = '<?php echo GETPOSTINT("id") ? "?id=".GETPOSTINT("id")."&" : (GETPOSTINT("cat") ? "?cat=".GETPOSTINT("cat")."&" : "?") ?>';
|
||||
$canonicalurladdidlang .= 'l=<?php echo $weblangs->shortlang ? $weblangs->shortlang : "'.$tmpshortlangcode.'"; ?>';
|
||||
$canonicalurladdidlang = '?__SEO_CANONICAL_URL_PARAMS__';
|
||||
$canonicalurladdidlang .= '&l=<?php echo $weblangs->shortlang ? $weblangs->shortlang : "'.$tmpshortlangcode.'"; ?>';
|
||||
} else {
|
||||
// Add parameter ID required to be unique/canonical
|
||||
$canonicalurladdidlang = '<?php echo GETPOSTINT("id") ? "?id=".GETPOSTINT("id") : (GETPOSTINT("cat") ? "?cat=".GETPOSTINT("cat") : "") ?>';
|
||||
$canonicalurladdidlang = '?__SEO_CANONICAL_URL_PARAMS__';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -278,20 +278,20 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage,
|
|||
$tplcontent .= '<link rel="alternate" hreflang="'.$shortlangcode.'" href="<?php echo $website->virtualhost; ?>'.(($object->fk_default_home == $objectpage->id) ? '/' : (($shortlangcode != substr($object->lang, 0, 2)) ? '/'.$shortlangcode : '').'/'.$objectpage->pageurl.'.php').'" />'."\n";
|
||||
|
||||
$tplcontent .= '<?php } ?>'."\n";
|
||||
} else {
|
||||
} else { // No language forced, it means the canonical is the one withparams making url unique
|
||||
$canonicalurl = '/'.$objectpage->pageurl.'.php';
|
||||
$arrayofaltlang = explode(',', $listofaltlang);
|
||||
|
||||
foreach ($arrayofaltlang as $altlang) {
|
||||
// Add parameter ID required to be unique/canonical
|
||||
$canonicalurladdidlang = '<?php echo GETPOSTINT("id") ? "?id=".GETPOSTINT("id")."&" : (GETPOSTINT("cat") ? "?cat=".GETPOSTINT("cat")."&" : "?") ?>';
|
||||
$canonicalurladdidlang .= 'l='.$altlang;
|
||||
$canonicalurladdidlang = '?__SEO_CANONICAL_URL_PARAMS__';
|
||||
$canonicalurladdidlang .= '&l='.$altlang;
|
||||
$tplcontent .= '<link rel="alternate" hreflang="'.$altlang.'" href="<?php echo $website->virtualhost; ?>'.$canonicalurl.$canonicalurladdidlang.'" />'."\n";
|
||||
}
|
||||
|
||||
$tmpshortlangcode = preg_replace('/[_-].*$/', '', $object->lang); // en_US or en-US -> en
|
||||
$canonicalurladdidlang = '<?php echo GETPOSTINT("id") ? "?id=".GETPOSTINT("id")."&" : (GETPOSTINT("cat") ? "?cat=".GETPOSTINT("cat")."&" : "?") ?>';
|
||||
$canonicalurladdidlang .= 'l='.$tmpshortlangcode;
|
||||
$canonicalurladdidlang = '?__SEO_CANONICAL_URL_PARAMS__';
|
||||
$canonicalurladdidlang .= '&l='.$tmpshortlangcode;
|
||||
$tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="<?php echo $website->virtualhost; ?>'.$canonicalurl.$canonicalurladdidlang.'" />'."\n";
|
||||
}
|
||||
}
|
||||
|
|
@ -320,29 +320,34 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage,
|
|||
$tplcontent .= '<?php // BEGIN PHP'."\n";
|
||||
$tplcontent .= '$tmp = ob_get_contents(); ob_end_clean();'."\n"; // replace with ob_get_clean ?
|
||||
|
||||
$tplcontent .= "// Now fix the content for SEO or multilanguage\n";
|
||||
// Old method for custom SEO
|
||||
if (strpos($objectpage->content, '$__PAGE__TITLE__') !== false) {
|
||||
$tplcontent .= '$tmp = preg_replace("/<title>.*?<\/title>/s", "<title>" . dol_escape_htmltag($__PAGE__TITLE__) . "</title>", $tmp);'."\n";
|
||||
$tplcontent .= '$tmp = preg_replace("/<meta name=\"title\" content=\".*?\" \/>/s", "<meta name=\"title\" content=\"" . dol_string_nohtmltag($__PAGE__TITLE__) . "\" />", $tmp);';
|
||||
}
|
||||
if (strpos($objectpage->content, '$__PAGE__KEYWORDS__') !== false) {
|
||||
$tplcontent .= '$tmp = preg_replace("/<meta name=\"keywords\" content=\".*?\" \/>/s", "<meta name=\"keywords\" content=\"" . dol_string_nohtmltag($__PAGE__KEYWORDS__) . "\" />", $tmp);';
|
||||
$tplcontent .= '$tmp = preg_replace("/^<meta name=\"keywords\" content=\".*?\" \/>/ms", "<meta name=\"keywords\" content=\"" . dol_string_nohtmltag($__PAGE__KEYWORDS__) . "\" />", $tmp);'."\n";
|
||||
}
|
||||
if (strpos($objectpage->content, '$__PAGE__TITLE__') !== false) {
|
||||
$tplcontent .= '$tmp = preg_replace("/^<title>.*?<\/title>/ms", "<title>" . dol_escape_htmltag($__PAGE__TITLE__) . "</title>", $tmp);'."\n";
|
||||
$tplcontent .= '$tmp = preg_replace("/^<meta name=\"title\" content=\".*?\" \/>/ms", "<meta name=\"title\" content=\"" . dol_string_nohtmltag($__PAGE__TITLE__) . "\" />", $tmp);'."\n";
|
||||
}
|
||||
if (strpos($objectpage->content, '$__PAGE__DESC__') !== false) {
|
||||
$tplcontent .= '$tmp = preg_replace("/<meta name=\"description\" content=\".*?\" \/>/s", "<meta name=\"description\" content=\"" . dol_string_nohtmltag($__PAGE__DESC__) . "\" />", $tmp);';
|
||||
$tplcontent .= '$tmp = preg_replace("/^<meta name=\"description\" content=\".*?\" \/>/ms", "<meta name=\"description\" content=\"" . dol_string_nohtmltag($__PAGE__DESC__) . "\" />", $tmp);'."\n";
|
||||
}
|
||||
// New method for custom SEO
|
||||
if (strpos($objectpage->content, 'define("__SEO_PAGE_TITLE__"') !== false) {
|
||||
$tplcontent .= '$tmp = preg_replace("/<title>.*?<\/title>/s", "<title>" . dol_escape_htmltag(constant("__SEO_PAGE_TITLE__")) . "</title>", $tmp);'."\n";
|
||||
$tplcontent .= '$tmp = preg_replace("/<meta name=\"title\" content=\".*?\" \/>/s", "<meta name=\"title\" content=\"" . dol_string_nohtmltag(constant("__SEO_PAGE_TITLE__")) . "\" />", $tmp);';
|
||||
}
|
||||
if (strpos($objectpage->content, 'define("__SEO_PAGE_KEYWORDS__"') !== false) {
|
||||
$tplcontent .= '$tmp = preg_replace("/<meta name=\"keywords\" content=\".*?\" \/>/s", "<meta name=\"keywords\" content=\"" . dol_string_nohtmltag(constant("__SEO_PAGE_KEYWORDS__")) . "\" />", $tmp);';
|
||||
$tplcontent .= '$tmp = preg_replace("/^<meta name=\"keywords\" content=\".*?\" \/>/ms", "<meta name=\"keywords\" content=\"" . dol_string_nohtmltag(constant("__SEO_PAGE_KEYWORDS__")) . "\" />", $tmp);'."\n";
|
||||
}
|
||||
if (strpos($objectpage->content, 'define("__SEO_PAGE_TITLE__"') !== false) {
|
||||
$tplcontent .= '$tmp = preg_replace("/^<title>.*?<\/title>/ms", "<title>" . dol_escape_htmltag(constant("__SEO_PAGE_TITLE__")) . "</title>", $tmp);'."\n";
|
||||
$tplcontent .= '$tmp = preg_replace("/^<meta name=\"title\" content=\".*?\" \/>/ms", "<meta name=\"title\" content=\"" . dol_string_nohtmltag(constant("__SEO_PAGE_TITLE__")) . "\" />", $tmp);'."\n";
|
||||
}
|
||||
if (strpos($objectpage->content, 'define("__SEO_PAGE_DESC__"') !== false) {
|
||||
$tplcontent .= '$tmp = preg_replace("/<meta name=\"description\" content=\".*?\" \/>/s", "<meta name=\"description\" content=\"" . dol_string_nohtmltag(constant("__SEO_PAGE_DESC__")) . "\" />", $tmp);';
|
||||
$tplcontent .= '$tmp = preg_replace("/^<meta name=\"description\" content=\".*?\" \/>/ms", "<meta name=\"description\" content=\"" . dol_string_nohtmltag(constant("__SEO_PAGE_DESC__")) . "\" />", $tmp);'."\n";
|
||||
}
|
||||
if (empty($objectpage->lang)) { // We may need to use param into the canonical url
|
||||
$tplcontent .= 'defined("__SEO_CANONICAL_URL_PARAMS__") ? ($tmp = preg_replace("/__SEO_CANONICAL_URL_PARAMS__/", dol_string_nohtmltag(constant("__SEO_CANONICAL_URL_PARAMS__")), $tmp)) : ($tmp = preg_replace("/\?__SEO_CANONICAL_URL_PARAMS__\"/", "", preg_replace("/\?__SEO_CANONICAL_URL_PARAMS__&/", "?", $tmp)));'."\n";
|
||||
}
|
||||
|
||||
$tplcontent .= "// Now output the generated page content\n";
|
||||
$tplcontent .= 'dolWebsiteOutput($tmp, "html", '.((int) $objectpage->id).'); dolWebsiteIncrementCounter('.((int) $object->id).', "'.$objectpage->type_container.'", '.((int) $objectpage->id).');'."\n";
|
||||
$tplcontent .= "// END PHP ?>\n";
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user