This commit is contained in:
Roman Kelesidis 2025-06-08 10:46:31 +00:00 committed by GitHub
commit ed07788c76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 49 additions and 0 deletions

View file

@ -14,6 +14,7 @@ require __DIR__ . '/common.php';
$page_cfg['load_tpl_vars'] = [
'post_icons'
];
$page_cfg['canonical_link'] = true;
// Show last topic
$show_last_topic = true;

View file

@ -2236,3 +2236,43 @@ 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,
'sort',
'start',
'order'
];
$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,6 +123,9 @@ $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' => (isset($page_cfg['canonical_link']) && $page_cfg['canonical_link'] === true)
? getCanonicalUrl()
: ((isset($page_cfg['canonical_link']) && is_string($page_cfg['canonical_link'])) ? $page_cfg['canonical_link'] : false),
'META_DESCRIPTION' => $page_cfg['meta_description'] ?? '',
'SITENAME' => $bb_cfg['sitename'],

View file

@ -25,6 +25,9 @@
<!-- ELSE -->
<meta name="robots" content="none">
<!-- ENDIF -->
<!-- IF META_CANONICAL -->
<link rel="canonical" href="{META_CANONICAL}"/>
<!-- ENDIF -->
<!-- IF META_PREV_PAGE -->
<link rel="prev" href="{META_PREV_PAGE}">
<!-- ENDIF / META_PREV_PAGE -->

View file

@ -12,6 +12,7 @@ define('BB_SCRIPT', 'forum');
require __DIR__ . '/common.php';
$page_cfg['include_bbcode_js'] = true;
$page_cfg['canonical_link'] = true;
$show_last_topic = true;
$last_topic_max_len = 40;

View file

@ -22,6 +22,7 @@ $page_cfg['load_tpl_vars'] = [
'post_icons',
'topic_icons'
];
$page_cfg['canonical_link'] = true;
$newest = $next_topic_id = 0;
$start = isset($_GET['start']) ? abs((int)$_GET['start']) : 0;