This commit is contained in:
Roman Kelesidis 2025-06-08 13:29:11 +03:00
commit fc28d620b0
3 changed files with 41 additions and 1 deletions

View file

@ -2236,3 +2236,40 @@ function infoByIP(string $ipAddress, int $port = 0): array
return $data;
}
/**
* Generates canonical url
*
* @return string
*/
function getCanonicalUrl(): string
{
$fullUrl = rtrim(FULL_URL, '/');
$script = $_SERVER['SCRIPT_NAME'];
$allowedParams = [
POST_CAT_URL,
POST_FORUM_URL,
POST_GROUPS_URL,
POST_POST_URL,
POST_TOPIC_URL,
POST_USERS_URL,
];
$params = [];
foreach ($allowedParams as $key) {
if (isset($_GET[$key])) {
$params[$key] = $_GET[$key];
}
}
if (!empty($params)) {
ksort($params);
$queryString = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
$url = $fullUrl . $script . "?$queryString";
} else {
$url = $fullUrl . $script;
}
return htmlCHR($url);
}

View file

@ -123,7 +123,7 @@ $template->assign_vars([
'USE_TABLESORTER' => !empty($page_cfg['use_tablesorter']),
'ALLOW_ROBOTS' => !$bb_cfg['board_disable'] && (!isset($page_cfg['allow_robots']) || $page_cfg['allow_robots'] === true),
'META_CANONICAL' => $page_cfg['canonical_link'] ?? '',
'META_CANONICAL' => $page_cfg['canonical_link'] ?? getCanonicalUrl(),
'META_DESCRIPTION' => $page_cfg['meta_description'] ?? '',
'SITENAME' => $bb_cfg['sitename'],

View file

@ -15,6 +15,9 @@ require __DIR__ . '/common.php';
// Start session management
$user->session_start();
// Disable canonical for this page
$page_cfg['canonical_link'] = false;
set_die_append_msg();
$mode = request_var('mode', 'viewprofile');