10 public function __construct($aParams = null)
12 $this->aParams = ($aParams === null) ? $_GET : $aParams;
15 public function getBool($sName, $bDefault = false)
17 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
21 return (bool) $this->aParams[$sName];
24 public function getInt($sName, $bDefault = false)
26 if (!isset($this->aParams[$sName])) {
30 if (!preg_match('/^[+-]?[0-9]+$/', $this->aParams[$sName])) {
31 userError("Integer number expected for parameter '$sName'");
34 return (int) $this->aParams[$sName];
37 public function getFloat($sName, $bDefault = false)
39 if (!isset($this->aParams[$sName])) {
43 if (!preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $this->aParams[$sName])) {
44 userError("Floating-point number expected for parameter '$sName'");
47 return (float) $this->aParams[$sName];
50 public function getString($sName, $bDefault = false)
52 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
56 return $this->aParams[$sName];
59 public function getSet($sName, $aValues, $sDefault = false)
61 if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
65 if (!in_array($this->aParams[$sName], $aValues)) {
66 userError("Parameter '$sName' must be one of: ".join(', ', $aValues));
69 return $this->aParams[$sName];
72 public function getStringList($sName, $aDefault = false)
74 $sValue = $this->getString($sName);
77 // removes all NULL, FALSE and Empty Strings but leaves 0 (zero) values
78 return array_values(array_filter(explode(',', $sValue), 'strlen'));
84 public function getPreferredLanguages($sFallback = null)
86 if ($sFallback === null && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
87 $sFallback = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
90 $aLanguages = array();
91 $sLangString = $this->getString('accept-language', $sFallback);
94 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)) {
95 foreach ($aLanguagesParse as $iLang => $aLanguage) {
96 $aLanguages[$aLanguage[1]] = isset($aLanguage[5])?(float)$aLanguage[5]:1 - ($iLang/100);
97 if (!isset($aLanguages[$aLanguage[2]])) $aLanguages[$aLanguage[2]] = $aLanguages[$aLanguage[1]]/10;
102 if (empty($aLanguages) && CONST_Default_Language) {
103 $aLanguages[CONST_Default_Language] = 1;
106 foreach ($aLanguages as $sLanguage => $fLanguagePref) {
107 $aLangPrefOrder['short_name:'.$sLanguage] = 'short_name:'.$sLanguage;
108 $aLangPrefOrder['name:'.$sLanguage] = 'name:'.$sLanguage;
110 $aLangPrefOrder['short_name'] = 'short_name';
111 $aLangPrefOrder['name'] = 'name';
112 $aLangPrefOrder['brand'] = 'brand';
113 foreach ($aLanguages as $sLanguage => $fLanguagePref) {
114 $aLangPrefOrder['official_name:'.$sLanguage] = 'official_name:'.$sLanguage;
116 $aLangPrefOrder['official_name'] = 'official_name';
117 $aLangPrefOrder['ref'] = 'ref';
118 $aLangPrefOrder['type'] = 'type';
119 return $aLangPrefOrder;