diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index b592539d6c41d4ce322b32dfa791eea830a03c1c..38e6bc71c5988ae4fe9c95dbdf6d9a37dda42ae5 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -522,71 +522,10 @@ class SimpleSAML_Utilities { /** - * This function parses the Accept-Language http header and returns an associative array with each - * language and the score for that language. - * - * If an language includes a region, then the result will include both the language with the region - * and the language without the region. - * - * The returned array will be in the same order as the input. - * - * @return An associative array with each language and the score for that language. + * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getAcceptLanguage() instead. */ public static function getAcceptLanguage() { - - if(!array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) { - /* No Accept-Language header - return empty set. */ - return array(); - } - - $languages = explode(',', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); - - $ret = array(); - - foreach($languages as $l) { - $opts = explode(';', $l); - - $l = trim(array_shift($opts)); /* The language is the first element.*/ - - $q = 1.0; - - /* Iterate over all options, and check for the quality option. */ - foreach($opts as $o) { - $o = explode('=', $o); - if(count($o) < 2) { - /* Skip option with no value. */ - continue; - } - - $name = trim($o[0]); - $value = trim($o[1]); - - if($name === 'q') { - $q = (float)$value; - } - } - - /* Remove the old key to ensure that the element is added to the end. */ - unset($ret[$l]); - - /* Set the quality in the result. */ - $ret[$l] = $q; - - if(strpos($l, '-')) { - /* The language includes a region part. */ - - /* Extract the language without the region. */ - $l = explode('-', $l); - $l = $l[0]; - - /* Add this language to the result (unless it is defined already). */ - if(!array_key_exists($l, $ret)) { - $ret[$l] = $q; - } - } - } - - return $ret; + return \SimpleSAML\Utils\HTTP::getAcceptLanguage(); } diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index 96577ff30bc7890baa414a0ad66de31bc8b6c4ba..e754b17bb105b7d3768b44ce02921c93890d6b59 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -207,6 +207,74 @@ class HTTP } + /** + * This function parses the Accept-Language HTTP header and returns an associative array with each language and the + * score for that language. If a language includes a region, then the result will include both the language with + * the region and the language without the region. + * + * The returned array will be in the same order as the input. + * + * @return array An associative array with each language and the score for that language. + * + * @author Olav Morken, UNINETT AS <olav.morken@uninett.no> + */ + public static function getAcceptLanguage() + { + if (!array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) { + // no Accept-Language header, return an empty set + return array(); + } + + $languages = explode(',', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); + + $ret = array(); + + foreach ($languages as $l) { + $opts = explode(';', $l); + + $l = trim(array_shift($opts)); // the language is the first element + + $q = 1.0; + + // iterate over all options, and check for the quality option + foreach ($opts as $o) { + $o = explode('=', $o); + if (count($o) < 2) { + // skip option with no value + continue; + } + + $name = trim($o[0]); + $value = trim($o[1]); + + if ($name === 'q') { + $q = (float) $value; + } + } + + // remove the old key to ensure that the element is added to the end + unset($ret[$l]); + + // set the quality in the result + $ret[$l] = $q; + + if (strpos($l, '-')) { + // the language includes a region part + + // extract the language without the region + $l = explode('-', $l); + $l = $l[0]; + + // add this language to the result (unless it is defined already) + if (!array_key_exists($l, $ret)) { + $ret[$l] = $q; + } + } + } + return $ret; + } + + /** * Retrieve the base URL of the SimpleSAMLphp installation. The URL will always end with a '/'. For example: * https://idp.example.org/simplesaml/ diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index d259aebab116f1175ab94f9e9ecdc9afc9b38b0c..b47cc772c6da9369732c8e6b1803d38f8c202ca7 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -141,7 +141,7 @@ class SimpleSAML_XHTML_Template { * languages in the header were available. */ private function getHTTPLanguage() { - $languageScore = SimpleSAML_Utilities::getAcceptLanguage(); + $languageScore = \SimpleSAML\Utils\HTTP::getAcceptLanguage(); /* For now we only use the default language map. We may use a configurable language map * in the future.