diff --git a/common_config.php b/common_config.php index 7c33c0f..705028b 100644 --- a/common_config.php +++ b/common_config.php @@ -170,3 +170,23 @@ function set_curl_options($ch): void curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_ENCODING, ''); } + +function alt_links(): void +{ + global $language; + $canonical_query = []; + if(isset($_REQUEST['cat'])) { + $canonical_query['cat'] = $_REQUEST['cat']; + } + if(isset($_REQUEST['pg'])) { + $canonical_query['pg'] = $_REQUEST['pg']; + } + foreach(LANGUAGES as $lang => $data) { + if($lang === $language){ + continue; + } + $canonical_query['lang'] = $lang; + $link = CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($canonical_query); + echo '<link rel="alternate" href="'.$link.'" hreflang="'.$lang.'" />'; + } +} diff --git a/www/admin.php b/www/admin.php index cc3d453..a1d6193 100644 --- a/www/admin.php +++ b/www/admin.php @@ -19,6 +19,8 @@ asort($categories); <meta name=viewport content="width=device-width, initial-scale=1"> <meta name="robots" content="noindex"> <link rel="canonical" href="<?php echo CANONICAL_URL . $_SERVER['SCRIPT_NAME']; ?>"> +<link rel="alternate" href="<?php echo CANONICAL_URL . $_SERVER['SCRIPT_NAME']; ?>" hreflang="x-default"> +<?php alt_links(); ?> <style><?php echo $style; ?></style> </head><body><main> <h1><?php echo _('Admin interface'); ?></h1> diff --git a/www/onions.php b/www/onions.php index 4983513..f176e5b 100644 --- a/www/onions.php +++ b/www/onions.php @@ -122,6 +122,8 @@ function send_html(): void echo '<meta name="viewport" content="width=device-width, initial-scale=1">'; echo '<meta name="description" content="Huge link list of Tor hidden service onions. All the darknet links you need in one place.">'; echo '<link rel="canonical" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . (empty($canonical_query) ? '' : '?' . http_build_query($canonical_query)) . '">'; + echo '<link rel="alternate" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . (empty($canonical_query) ? '' : '?' . http_build_query($canonical_query)) . '" hreflang="x-default">'; + alt_links(); echo '<style>'.$style.'</style>'; echo '<base target="_blank">'; echo '</head><body><main>'; diff --git a/www/test.php b/www/test.php index 314b891..96aa5cb 100644 --- a/www/test.php +++ b/www/test.php @@ -10,6 +10,8 @@ echo '<meta name="author" content="Daniel Winzen">'; echo '<meta name="viewport" content="width=device-width, initial-scale=1">'; echo '<meta name="description" content="Test whether a Tor hidden service onion is online or offline">'; echo '<link rel="canonical" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . '">'; +echo '<link rel="alternate" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . '" hreflang="x-default">'; +alt_links(); echo '<style>'.$style.'</style>'; echo '</head><body><main>'; echo "<h1>"._('Online-Test')."</h1>";