7 function __construct($aParams=NULL)
9 $this->aParams = ($aParams === NULL) ? $_GET : $aParams;
12 function getBool($sName, $bDefault=false)
14 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)
29 if (!preg_match('/^[+-]?[0-9]+$/', $this->aParams[$sName]))
31 userError("Integer number expected for parameter '$sName'");
34 return (int) $this->aParams[$sName];
37 function getFloat($sName, $bDefault=false)
39 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0)
44 if (!preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $this->aParams[$sName]))
46 userError("Floating-point number expected for parameter '$sName'");
49 return (float) $this->aParams[$sName];
52 function getString($sName, $bDefault=false)
54 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0)
59 return $this->aParams[$sName];
62 function getSet($sName, $aValues, $sDefault=false)
64 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0)
69 if (!in_array($this->aParams[$sName], $aValues))
71 userError("Parameter '$sName' must be one of: ".join(', ', $aValues));
74 return $this->aParams[$sName];
77 function getStringList($sName, $aDefault=false)
79 $sValue = $this->getString($sName);
83 return explode(',', $sValue);
89 function getPreferredLanguages($sFallback=NULL)
91 if ($sFallback === NULL && isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
93 $sFallback = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
96 $aLanguages = array();
97 $sLangString = $this->getString('accept-language', $sFallback);
101 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))
103 foreach($aLanguagesParse as $iLang => $aLanguage)
105 $aLanguages[$aLanguage[1]] = isset($aLanguage[5])?(float)$aLanguage[5]:1 - ($iLang/100);
106 if (!isset($aLanguages[$aLanguage[2]])) $aLanguages[$aLanguage[2]] = $aLanguages[$aLanguage[1]]/10;
111 if (!sizeof($aLanguages) && CONST_Default_Language)
113 $aLanguages[CONST_Default_Language] = 1;
116 foreach($aLanguages as $sLanguage => $fLanguagePref)
118 $aLangPrefOrder['short_name:'.$sLanguage] = 'short_name:'.$sLanguage;
119 $aLangPrefOrder['name:'.$sLanguage] = 'name:'.$sLanguage;
121 $aLangPrefOrder['short_name'] = 'short_name';
122 $aLangPrefOrder['name'] = 'name';
123 $aLangPrefOrder['brand'] = 'brand';
124 foreach($aLanguages as $sLanguage => $fLanguagePref)
126 $aLangPrefOrder['official_name:'.$sLanguage] = 'official_name:'.$sLanguage;
128 $aLangPrefOrder['official_name'] = 'official_name';
129 $aLangPrefOrder['ref'] = 'ref';
130 $aLangPrefOrder['type'] = 'type';
131 return $aLangPrefOrder;