Skip to content

Commit

Permalink
#3504 - Add canonical URL metatag to every possible page
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Jan 18, 2022
1 parent de0bbf7 commit 826f28e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions inc/classes/BxDolPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ public function displayPage ($oTemplate = null)
$oTemplate = BxDolTemplate::getInstance();

$oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
$oTemplate->setPageUrl($this->_aObject['url']);
$oTemplate->setPageType ($this->getType());
$oTemplate->setPageInjections ($this->getInjections());
$oTemplate->setPageContent ('page_main_code', $this->getCode());
Expand Down
18 changes: 15 additions & 3 deletions inc/classes/BxDolTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ function init()
$this->aPage = array(
'name_index' => BX_PAGE_DEFAULT,
'type' => BX_PAGE_TYPE_DEFAULT,
'url' => '',
'header' => '',
'header_text' => '',
'keywords' => array(),
Expand Down Expand Up @@ -703,9 +704,18 @@ function getPageNameIndex()
* Set page type
* @param int $i page type
*/
function setPageType($a)
function setPageType($i)
{
$this->aPage['type'] = $a;
$this->aPage['type'] = $i;
}

/**
* Set page url
* @param string $s page url
*/
function setPageUrl($s)
{
$this->aPage['url'] = $s;
}

/**
Expand Down Expand Up @@ -1197,7 +1207,9 @@ function getMetaInfo()

$sRet .= "<link rel=\"alternate\" type=\"application/json+oembed\" href=\"" . BX_DOL_URL_ROOT ."em.php?url=" . urlencode($_SERVER["REQUEST_URI"]) . "&format=json\" title=\"". (isset($this->aPage['header']) ? bx_html_attribute(strip_tags($this->aPage['header'])) : '') . "\" />";

$sRet .= "<link rel=\"canonical\" href=\"" . BX_DOL_URL_ROOT . substr($_SERVER["REQUEST_URI"], 1) . "\" />";
if (!empty($this->aPage['url'])){
$sRet .= "<link rel=\"canonical\" href=\"" . BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->aPage['url']). "\" />";
}

return $sRet;
}
Expand Down

0 comments on commit 826f28e

Please sign in to comment.