Warning, file /documentation/digikam-doc/404handler.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 <?php 0002 0003 // This script is intended to handle requests for files that do not exist 0004 // This may occur because: 0005 // 1) It is a language-free URL and we need to send the user to the most language appropriate version for them 0006 // 2) The page has moved elsewhere and we need to send them to the appropriate page 0007 // 3) The request is for a legacy page that existed on the older Mediawiki based setup, in which case we need to once again send them to the most appropriate page 0008 // 0009 // SPDX-License-Identifier: MIT 0010 0011 // NOTE: enable supported languages. 0012 // English is always enabled. Respect alphabetic order. 0013 // Other languages must be listed in locale/ sub-directory from root directory of this git repository. 0014 // All changes from this list must be also applied to the docs-digikam-org section from the JSON config file in binary-factory-tooling repository 0015 // https://invent.kde.org/sysadmin/binary-factory-tooling/-/blob/master/staticweb/custom-jobs.json 0016 // all_langs list in ressources/static/js/version_switch.js file from this repository needs to be also updated. 0017 0018 $supported_languages = array( 0019 "ca", 0020 "cs", 0021 "da", 0022 "de", 0023 "en", 0024 "es", 0025 "fr", 0026 "it", 0027 "ja", 0028 "ko", 0029 "lt", 0030 "nl", 0031 "sk", 0032 "sl", 0033 "sv", 0034 "ru", 0035 "tr", 0036 "pl", 0037 "pt_BR", 0038 "pt_PT", 0039 "uk_UA", 0040 "zh_CN", 0041 "zh_TW" 0042 ); 0043 0044 // List of page redirect rules 0045 // These should always be free of the language code, as this will be automatically added on when formulating the URL to forward the user on to 0046 $redirect_rules = array( 0047 // Default front page 0048 "^$" => "index.html" 0049 ); 0050 0051 //// SETTINGS END 0052 //// CHANGES SHOULD NOT BE NEEDED TO THE BELOW 0053 0054 // Helper function to determine the most appropriate language for the user 0055 // Parameters: 0056 // $request The web path that the user is trying to reach 0057 // $browser_languages The languages accepted by the user browser, in Accept-Language format 0058 // $supported_languages Array of languages that we support - in ISO language code format 0059 function determine_appropriate_language( $request, $browser_languages, $supported_languages ) 0060 { 0061 // First we start by looking at the request we have received 0062 // If this contains a language code, then we should be using that as the user has chosen to use that language explicitly 0063 // We assume that this language is supported 0064 if( preg_match( '/^([a-z][a-z](_[A-Z][A-Z])?)\//', $request, $result ) ) { 0065 // Then the user has specified a language - let's use that! 0066 return $result[1]; 0067 } 0068 0069 // Now that we know that the URL has not specified a language we can move on to looking at Accept-Language 0070 // First split the list up by the language separator 0071 $browser_requested_languages = explode( ",", $browser_languages ); 0072 0073 // Now go through each browser requested language in turn 0074 foreach( $browser_requested_languages as $language ) { 0075 // First as this might have a weighting value on it, we need to rip that off 0076 // Safest way to do this is just to split again by the appropriate separator for that 0077 $components = explode(";", $language); 0078 $language = $components[0]; 0079 0080 if( preg_match( '/^zh(-han[ts])?(-[a-z]{2})?$/i', $language, $result, PREG_UNMATCHED_AS_NULL ) ) { 0081 // Handle Chinese as a special case. Chinese lang tags may carry 0082 // a `Hant` or `Hans` script subtag, and/or a region subtag. 0083 // As long as a translation for `zh_HK` isn't available, this 0084 // matching is sufficient. 0085 if( strcasecmp($result[1], "-hant") === 0 ) { 0086 $language = "zh_TW"; 0087 } else if( strcasecmp($result[1], "-hans") === 0 ) { 0088 $language = "zh_CN"; 0089 } else if( strcasecmp($result[2], "-tw") === 0 || strcasecmp($result[2], "-hk") === 0 || strcasecmp($result[2], "-mo") === 0 ) { 0090 $language = "zh_TW"; 0091 } else { 0092 // Note this also matches `zh` without script or region subtag. 0093 $language = "zh_CN"; 0094 } 0095 } else { 0096 // Browsers use dashes to seperate language variants 0097 // But KDE translation systems use underscores for this so ensure we are consistent here 0098 $language = str_replace("-", "_", $language); 0099 } 0100 0101 // Is this one of our supported languages? 0102 if( in_array($language, $supported_languages) ) { 0103 // Then we have a winner! 0104 return $language; 0105 } 0106 } 0107 0108 // Finally if we found nothing we fallback to English 0109 return 'en'; 0110 } 0111 0112 // Start - Retrieve the values we need to work with here 0113 $requested_url = $_SERVER['REQUEST_URI']; 0114 $requested_languages = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; 0115 0116 // Before we can do anything else we need to clean up the URL we have received to remove the leading slash 0117 $requested_url = substr($requested_url, 1); 0118 0119 // Now determine the language we should be sending the user to 0120 $language = determine_appropriate_language( $requested_url, $requested_languages, $supported_languages ); 0121 0122 // Split out the content part of the URL 0123 // We will need this for the matching we are about to do above 0124 if( !preg_match( '/^([a-z][a-z](_[A-Z][A-Z])?\/)?(.*)/', $requested_url, $result ) ) { 0125 // This shouldn't happen... 0126 // But in case it does, serve a 404 and bail 0127 http_response_code(404); 0128 include("../$language/404.html"); 0129 exit(); 0130 } 0131 0132 // Save our result... 0133 $requested_page = $result[3]; 0134 0135 // First do a local check and see if $language/$requested_page exists.. 0136 // This allows for urls such as https://docs.krita.org/user_manual/getting_started/starting_krita.html to work 0137 if( file_exists("../$language/$requested_page") ) { 0138 // Then redirect them there 0139 header("HTTP/1.1 301 Moved Permanently"); 0140 header("Location: /$language/$requested_page"); 0141 exit(); 0142 } 0143 0144 // Go across all of our redirect rules now and see if we have any matches 0145 foreach( $redirect_rules as $rule => $replacement ) { 0146 // Try to match it... 0147 if( !preg_match( "/$rule/", $requested_page, $result ) ) { 0148 // Then we need to try another one... 0149 continue; 0150 } 0151 0152 // We have a winner! 0153 // Perform the redirect 0154 header("HTTP/1.1 301 Moved Permanently"); 0155 header("Location: /$language/$replacement"); 0156 exit(); 0157 } 0158 0159 // Alas it looks like we have no match :( 0160 // Send a 404 0161 http_response_code(404); 0162 include("../$language/404.html"); 0163 exit(); 0164 0165 ?>