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) {
18 return (bool) $this->aParams[$sName];
21 function getInt($sName, $bDefault = false)
23 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
27 if (!preg_match('/^[+-]?[0-9]+$/', $this->aParams[$sName])) {
28 userError("Integer number expected for parameter '$sName'");
31 return (int) $this->aParams[$sName];
34 function getFloat($sName, $bDefault = false)
36 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
40 if (!preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $this->aParams[$sName])) {
41 userError("Floating-point number expected for parameter '$sName'");
44 return (float) $this->aParams[$sName];
47 function getString($sName, $bDefault = false)
49 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
53 return $this->aParams[$sName];
56 function getSet($sName, $aValues, $sDefault = false)
58 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
62 if (!in_array($this->aParams[$sName], $aValues)) {
63 userError("Parameter '$sName' must be one of: ".join(', ', $aValues));
66 return $this->aParams[$sName];
69 function getStringList($sName, $aDefault = false)
71 $sValue = $this->getString($sName);
74 return explode(',', $sValue);
80 function getPreferredLanguages($sFallback = NULL)
82 if ($sFallback === NULL && isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
83 $sFallback = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
86 $aLanguages = array();
87 $sLangString = $this->getString('accept-language', $sFallback);
90 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)) {
91 foreach ($aLanguagesParse as $iLang => $aLanguage) {
92 $aLanguages[$aLanguage[1]] = isset($aLanguage[5])?(float)$aLanguage[5]:1 - ($iLang/100);
93 if (!isset($aLanguages[$aLanguage[2]])) $aLanguages[$aLanguage[2]] = $aLanguages[$aLanguage[1]]/10;
98 if (!sizeof($aLanguages) && CONST_Default_Language) {
99 $aLanguages[CONST_Default_Language] = 1;
102 foreach ($aLanguages as $sLanguage => $fLanguagePref) {
103 $aLangPrefOrder['short_name:'.$sLanguage] = 'short_name:'.$sLanguage;
104 $aLangPrefOrder['name:'.$sLanguage] = 'name:'.$sLanguage;
106 $aLangPrefOrder['short_name'] = 'short_name';
107 $aLangPrefOrder['name'] = 'name';
108 $aLangPrefOrder['brand'] = 'brand';
109 foreach ($aLanguages as $sLanguage => $fLanguagePref) {
110 $aLangPrefOrder['official_name:'.$sLanguage] = 'official_name:'.$sLanguage;
112 $aLangPrefOrder['official_name'] = 'official_name';
113 $aLangPrefOrder['ref'] = 'ref';
114 $aLangPrefOrder['type'] = 'type';
115 return $aLangPrefOrder;