8 function __construct($aParams = null)
10 $this->aParams = ($aParams === null) ? $_GET : $aParams;
13 function getBool($sName, $bDefault = false)
15 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
19 return (bool) $this->aParams[$sName];
22 function getInt($sName, $bDefault = false)
24 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
28 if (!preg_match('/^[+-]?[0-9]+$/', $this->aParams[$sName])) {
29 userError("Integer number expected for parameter '$sName'");
32 return (int) $this->aParams[$sName];
35 function getFloat($sName, $bDefault = false)
37 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
41 if (!preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $this->aParams[$sName])) {
42 userError("Floating-point number expected for parameter '$sName'");
45 return (float) $this->aParams[$sName];
48 function getString($sName, $bDefault = false)
50 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
54 return $this->aParams[$sName];
57 function getSet($sName, $aValues, $sDefault = false)
59 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
63 if (!in_array($this->aParams[$sName], $aValues)) {
64 userError("Parameter '$sName' must be one of: ".join(', ', $aValues));
67 return $this->aParams[$sName];
70 function getStringList($sName, $aDefault = false)
72 $sValue = $this->getString($sName);
75 return explode(',', $sValue);
81 function getPreferredLanguages($sFallback = null)
83 if ($sFallback === null && isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
84 $sFallback = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
87 $aLanguages = array();
88 $sLangString = $this->getString('accept-language', $sFallback);
91 if (preg_match_all('/(([a-z]{1,8})(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $sLangString, $aLanguagesParse, PREG_SET_ORDER)) {
92 foreach ($aLanguagesParse as $iLang => $aLanguage) {
93 $aLanguages[$aLanguage[1]] = isset($aLanguage[5])?(float)$aLanguage[5]:1 - ($iLang/100);
94 if (!isset($aLanguages[$aLanguage[2]])) $aLanguages[$aLanguage[2]] = $aLanguages[$aLanguage[1]]/10;
99 if (!sizeof($aLanguages) && CONST_Default_Language) {
100 $aLanguages[CONST_Default_Language] = 1;
103 foreach ($aLanguages as $sLanguage => $fLanguagePref) {
104 $aLangPrefOrder['short_name:'.$sLanguage] = 'short_name:'.$sLanguage;
105 $aLangPrefOrder['name:'.$sLanguage] = 'name:'.$sLanguage;
107 $aLangPrefOrder['short_name'] = 'short_name';
108 $aLangPrefOrder['name'] = 'name';
109 $aLangPrefOrder['brand'] = 'brand';
110 foreach ($aLanguages as $sLanguage => $fLanguagePref) {
111 $aLangPrefOrder['official_name:'.$sLanguage] = 'official_name:'.$sLanguage;
113 $aLangPrefOrder['official_name'] = 'official_name';
114 $aLangPrefOrder['ref'] = 'ref';
115 $aLangPrefOrder['type'] = 'type';
116 return $aLangPrefOrder;