nyroFwk  0.2
request.class.php
Go to the documentation of this file.
1 <?php
11 final class request {
12 
18  private static $cfg;
19 
39  private static $requestedUriInfo;
40 
60  private static $uriInfo;
61 
67  private static $module;
68 
74  private static $scaffold;
75 
81  private static $mobileStatus = false;
82 
86  private function __construct() {}
87 
92  public static function init() {
93  if (!empty(self::$requestArray))
94  return;
95 
96  self::$cfg = new config(factory::loadCfg(__CLASS__));
97 
98  $alias = array();
99  $outs = '(\.('.implode('|', array_keys(self::$cfg->outCfg)).'))';
100  foreach(self::$cfg->alias as $k=>$v) {
101  if ($k == '/') {
102  $alias['(/.{2})?/?'] = '\1'.$v;
103  $alias['(/.{2})?'.$outs] = '\1'.$v.'\2';
104  } else {
105  $k = '(/.{2})?'.$k;
106  $tmp = explode('\\', $v);
107  $t = '\\1'.$tmp[0];
108  unset($tmp[0]);
109  $i = 2;
110  foreach($tmp as $tt) {
111  $t.='\\'.(intval(substr($tt, 0, 1))+1).substr($tt, 1);
112  $i++;
113  }
114  if (!preg_match($outs, $k))
115  $alias[$k.'(.*)'] = $t.'\\'.$i;
116  $alias[$k] = $t;
117  }
118  }
119  $alias = array_reverse($alias, true);
120  self::$cfg->alias = $alias;
121 
122  // Put the default lang at the top of available langs
123  $avlLangsTmp = self::$cfg->avlLang;
124  $avlLangs = array();
125  foreach($avlLangsTmp as $k=>$v) {
126  if ($k == self::$cfg->lang) {
127  $avlLangs[$k] = $v;
128  unset($avlLangsTmp[$k]);
129  }
130  }
131  self::$cfg->avlLang = array_merge($avlLangs, $avlLangsTmp);
132 
133  $secure = (array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on');
134 
135  $protocol = $secure? 'https' : 'http';
136 
137  $controller = basename($_SERVER['SCRIPT_FILENAME']);
138 
139  $serverName = array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : (array_key_exists('SERVER_NAME', $_SERVER) ? $_SERVER['SERVER_NAME'] : self::$cfg->defaultServerName);
140  $stdPort = $secure ? '443' : '80';
141  $port = (array_key_exists('SERVER_PORT', $_SERVER) && $_SERVER['SERVER_PORT'] != $stdPort && $_SERVER['SERVER_PORT'])? ':'.$_SERVER['SERVER_PORT'] : '';
142  $domain = $protocol.'://'.$serverName.$port;
143 
144  $scriptName = $_SERVER['SCRIPT_NAME'];
145  $requestUri = urldecode(array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : ('/'.$scriptName.(array_key_exists(1, $_SERVER['argv']) ? $_SERVER['argv'][1] : '')));
146 
147  $redir = null;
148  $forceServerName = null;
149  if (self::$cfg->forceServerName
150  && strpos($serverName, 'localhost') === false
151  && strtolower(self::$cfg->forceServerName) != strtolower($serverName)) {
152  $forceServerName = self::$cfg->forceServerName;
153  $redir = $protocol.'://'.$forceServerName.$port.$requestUri;
154  }
155  if (self::$cfg->forceNoOut
156  && self::$cfg->noOut
157  && ($pos = strpos($requestUri, self::$cfg->noOut))
158  && $pos + strlen(self::$cfg->noOut) == strlen($requestUri)
159  ) {
160  if ($redir)
161  $redir = substr($redir, 0, -1*(strlen(self::$cfg->noOut)+1));
162  else
163  $redir = $domain.substr($requestUri, 0, $pos-1);
164  }
165  if (self::$cfg->noController && strpos($requestUri, self::$cfg->noController) !== false) {
166  if (!$redir)
167  $redir = $domain.$requestUri;
168  $redir = str_replace(self::$cfg->noController.'/', '', $redir);
169  if ($pos = strpos($redir, self::$cfg->noController))
170  $redir = substr($redir, 0, $pos);
171  }
172 
173  $path = '/';
174  $requestUriTmp = explode('/', substr($requestUri, 1));
175  $scriptNameTmp = explode('/', substr($scriptName, 1));
176  $min = min(count($requestUriTmp), count($scriptNameTmp));
177  $i = 0;
178  while ($i < $min && $requestUriTmp[$i] == $scriptNameTmp[$i]) {
179  $path.= $requestUriTmp[$i].'/';
180  $i++;
181  }
182 
183  $pathWithController = (strpos($requestUri, $controller) !== false);
184 
185  if ($pathWithController) {
186  if (strpos($path, $controller) !== false)
187  $path = substr($path, 0, -strlen($controller)-1);
188  $len = strlen($path.$controller);
189  $request = (isset($requestUri[$len]) && $requestUri[$len] == '?') ? '' : substr($requestUri, $len+1);
190  } else
191  $request = substr($requestUri, strlen($path));
192 
193  if (self::$cfg->forceNoLang) {
194  $forceNoLang = self::$cfg->forceNoLang === true ? self::$cfg->lang : self::$cfg->forceNoLang;
195  if ($requestUri != $path && strpos($requestUri, '/'.$forceNoLang.'/') !== false && $request) {
196  $redir = str_replace('/'.$forceNoLang.'/', '/', $redir ? $redir : $domain.$requestUri);
197  }
198  } else if (self::$cfg->forceLang) {
199  $forceLang = self::$cfg->forceLang === true ? self::$cfg->lang : self::$cfg->forceLang;
200  if ($requestUri != $path && strpos($requestUri, '/'.$forceLang.'/') === false
201  && $request) {
202  $continue = true;
203  $i = 0;
204  $cpt = count(self::$cfg->noForceLang);
205  while($continue && $i < $cpt) {
206  if (strpos($request, self::$cfg->noForceLang[$i]) === 0)
207  $continue = false;
208  $i++;
209  }
210  if ($continue) {
211  // lang not found, force it
212  $redirWork = $redir ? $redir : $domain.$requestUri;
213  $search = ($forceServerName ? $forceServerName : $domain).$path.($pathWithController? $controller.'/' : null);
214  $pos = strpos($redirWork, $search) + strlen($search);
215  $end = $pos < strlen($redirWork) ? strpos($redirWork, '/', $pos+1) : false;
216  $end = $end ? $end-$pos : strlen($redirWork);
217  $curLang = substr($redirWork, $pos, $end);
218  if (!self::isLang($curLang))
219  $redir = substr($redirWork, 0, $pos).$forceLang.'/'.substr($redirWork, $pos);
220  }
221  }
222  }
223 
224  if ($redir) {
225  header('HTTP/1.0 301 Moved Permanently');
226  header('Location: '.$redir);
227  exit;
228  }
229 
230  self::extractGet($request, true);
231 
232  self::$requestedUriInfo = self::analyseRequest($request);
233 
234  self::$uriInfo = array_merge(array(
235  'secure'=>$secure,
236  'protocol'=>$protocol,
237  'controller'=>$controller,
238  'serverName'=>$serverName,
239  'domain'=>$domain,
240  'path'=>$path,
241  'pathWithController'=>$pathWithController,
242  'request'=>$request,
243  'lang'=>self::$cfg->lang,
244  'module'=>self::$cfg->module,
245  'moduleScaffold'=>null,
246  'action'=>self::$cfg->action,
247  'param'=>self::$cfg->param,
248  'text'=>self::$cfg->text,
249  'out'=>self::$cfg->out
250  ), self::$requestedUriInfo);
251 
252  if (self::$cfg->forceSecure)
254 
255  self::fixFiles();
256  }
257 
261  private static function fixFiles() {
262  if (!empty($_FILES)) {
263  $tmp = array();
264  foreach($_FILES as $k=>$p) {
265  if (is_array($p['name'])) {
266  if (is_array(current($p['name']))) {
267  // multiple files with multiple element
268  $tmp[$k] = array();
269  foreach($p['name'] as $i=>$v) {
270  foreach($v as $kk=>$vv) {
271  $tmp[$k][$i][$kk] = array(
272  'name'=>$vv,
273  'type'=>$_FILES[$k]['type'][$i][$kk],
274  'tmp_name'=>$_FILES[$k]['tmp_name'][$i][$kk],
275  'error'=>$_FILES[$k]['error'][$i][$kk],
276  'size'=>$_FILES[$k]['size'][$i][$kk],
277  );
278  }
279  }
280  } else {
281  // multiple files
282  $tmp[$k] = array();
283  foreach($p['name'] as $i=>$v) {
284  $tmp[$k][$i] = array(
285  'name'=>$v,
286  'type'=>$_FILES[$k]['type'][$i],
287  'tmp_name'=>$_FILES[$k]['tmp_name'][$i],
288  'error'=>$_FILES[$k]['error'][$i],
289  'size'=>$_FILES[$k]['size'][$i],
290  );
291  }
292  }
293  } else
294  $tmp[$k] = $p;
295  }
296  $_FILES = $tmp;
297  }
298  }
299 
306  public static function parseParam($param) {
307  $ret = array();
308  $tmp = explode(self::$cfg->sepParam, $param);
309  foreach($tmp as $t) {
310  if (strpos($t, self::$cfg->sepParamSub)) {
311  list($key, $val) = explode(self::$cfg->sepParamSub, $t);
312  $ret[$key] = $val;
313  } else
314  $ret[] = $t;
315  }
316  return $ret;
317  }
318 
325  public static function createParam($param, $urlify = true) {
326  $ret = null;
327  if (is_array($param)) {
328  $tmp = array();
329  foreach($param as $key=>$val) {
330  if ($urlify)
331  $val = utils::urlify($val);
332  if (!is_numeric($key))
333  $tmp[] = $key.self::$cfg->sepParamSub.$val;
334  else
335  $tmp[] = $val;
336  }
337  $ret = implode(self::$cfg->sepParam, $tmp);
338  } else
339  $ret = $param;
340 
341  return $ret;
342  }
343 
350  public static function forward($request) {
351  self::$uriInfo = array_merge(self::$uriInfo, self::analyseRequest($request));
352  self::$module = factory::getModule(self::$uriInfo['module']);
353  return self::execModule();
354  }
355 
359  public static function forceSecure() {
360  if (!self::get('secure'))
361  response::getInstance()->redirect(str_replace('http://', 'https://', self::uriDef(array('absolute'=>1))));
362  }
363 
387  public static function get($get = null) {
388  if ($get == 'uri')
389  return self::get('domain').self::getPathControllerUri().self::get('request');
390  if ($get == 'localUri')
391  return self::getPathControllerUri().self::get('request');
392  if ($get == 'pathUri')
393  return self::getPathControllerUri().self::get('request');
394  if ($get == 'rootUri')
395  return self::get('domain').self::get('path');
396  else if ($get == null)
397  return self::$uriInfo;
398  else
399  return self::$uriInfo[$get];
400  }
401 
409  public static function getRequested($get = null) {
410  if (is_null($get)) {
411  $uriInfo = self::$requestedUriInfo;
412  unset($uriInfo['paramA']);
413  return $uriInfo;
414  } else if (array_key_exists($get, self::$requestedUriInfo))
415  return self::$requestedUriInfo[$get];
416  else
417  return null;
418  }
419 
426  public static function getCfg($key = null) {
427  if ($key === null)
428  return self::$cfg->getVars();
429  else
430  return self::$cfg->get($key);
431  }
432 
439  public static function hasPrm($key) {
440  return array_key_exists($key, self::get('paramA'));
441  }
442 
450  public static function getPrm($key, $default = null) {
451  $prmA = self::get('paramA');
452  return array_key_exists($key, $prmA)? $prmA[$key] : $default;
453  }
454 
461  public static function getPathControllerUri($forceController = false) {
462  $controller = ($forceController || self::get('pathWithController'))? self::get('controller').'/': null;
463  return self::get('path').$controller;
464  }
465 
483  public static function uri($prm = array()) {
484  if (!is_array($prm))
485  $prm = self::uriString($prm);
486 
487  if (self::isAbsolutizeAllUris() && !isset($prm['absolute']))
488  $prm['absolute'] = true;
489 
490  $sep = array_key_exists('sep', $prm)? $prm['sep'] : self::$cfg->sep;
491 
492  $tmp = array_fill(0, 4, self::$cfg->empty);
493 
494  if (array_key_exists('moduleScaffold', $prm) && !empty($prm['moduleScaffold']))
495  $tmp[0] = utils::urlify($prm['moduleScaffold']);
496  else if (array_key_exists('module', $prm) && !empty($prm['module']))
497  $tmp[0] = utils::urlify($prm['module']);
498 
499  if (array_key_exists('action', $prm) && !empty($prm['action']))
500  $tmp[1] = $prm['action'];
501 
502  if (array_key_exists('paramA', $prm) && is_array($prm['paramA']))
503  $tmp[2] = self::createParam($prm['paramA'], false);
504  else if (array_key_exists('param', $prm) && !empty($prm['param']))
505  $tmp[2] = $prm['param'];
506 
507  if (array_key_exists('text', $prm) && !empty($prm['text']))
508  $tmp[3] = utils::urlify($prm['text']);
509 
510  while(count($tmp) > 0 && (empty($tmp[count($tmp) - 1]) || $tmp[count($tmp) - 1] == self::$cfg->empty))
511  array_pop($tmp);
512 
513  $out = (array_key_exists('out', $prm) ?
514  (self::isOut($prm['out'])? $prm['out'] : null)
515  : self::getRequested('out'));
516  if (is_null($out) && (!isset($prm['out']) || is_null($prm['out'])))
517  $out = self::$cfg->defaultOut;
518  if ($out) {
519  if (false && empty($tmp))
520  $tmp[] = self::$cfg->empty.'.'.$out;
521  else if (!empty($tmp) && $out != self::$cfg->noOut)
522  $tmp[count($tmp) - 1] .= '.'.$out;
523  }
524 
525  $forceLang = self::$cfg->forceLang ? (self::$cfg->forceLang === true ? self::$cfg->lang : self::$cfg->forceLang) : null;
526  if (array_key_exists('lang', $prm)) {
527  if (self::isLang($prm['lang']))
528  array_unshift($tmp, $prm['lang']);
529  else if ($forceLang)
530  array_unshift($tmp, $forceLang);
531  } else if (self::getRequested('lang'))
532  array_unshift($tmp, self::getRequested('lang'));
533  else if (self::$cfg->lang != self::get('lang'))
534  array_unshift($tmp, self::get('lang'));
535  else if ($forceLang && count($tmp))
536  array_unshift($tmp, $forceLang);
537  if ($forceLang && count($tmp) == 1 && $tmp[0] == $forceLang)
538  $tmp = array();
539 
540  $prefix = array_key_exists('absolute', $prm) && $prm['absolute']? request::get('domain') : null;
541  $prefix.= self::get('path');
542  if (array_key_exists('controller', $prm)) {
543  if ($prm['controller'])
544  array_unshift($tmp, $prm['controller']);
545  } else if (self::get('pathWithController'))
546  $prefix.= request::get('controller').'/';
547 
548  foreach($tmp as &$t)
549  $t = str_replace(array(' ', '/'), self::$cfg->empty, $t);
550 
551  return $prefix.implode($sep, $tmp);
552  }
553 
561  public static function uploadedUri($file, array $prm = array()) {
562  return self::uri(array_merge(array(
563  'lang'=>false,
564  'module'=>'nyroUtils',
565  'action'=>'uploadedFiles',
566  'param'=>str_replace(array('/', '\\'), array(request::getCfg('sepParam'), request::getCfg('sepParam')), $file),
567  'out'=>false
568  ), $prm));
569  }
570 
579  public static function uriDef(array $prm = array(), array $use = array('lang', 'module', 'action', 'param', 'out')) {
580  $tmp = array();
581 
582  foreach($use as $u)
583  $tmp[$u] = self::getRequested($u);
584 
585  return self::uri(array_merge($tmp, $prm));
586  }
587 
596  public static function uriString($uri) {
597  $uriA = array_values(array_filter(explode(self::$cfg->sep, $uri)));
598 
599  if (empty($uriA)) {
600  if ($uri == '//')
601  return array('controller'=>false);
602  else if ($uri == '
603  return array('absolute'=>true, 'controller'=>false);
604  else
605  return array();
606  }
607 
608  $tmp = array();
609  if (strpos($uriA[0], '.php'))
610  $tmp['controller'] = array_shift($uriA);
611 
612  if (!empty($uriA)) {
613  if (self::isLang($uriA[0]))
614  $tmp['lang'] = array_shift($uriA);
615  if (!empty($uriA)) {
616  $last = $uriA[count($uriA)-1];
617  if ((($pos = strrpos($last, '.')) !== false) && self::isOut($out = substr($last, $pos+1))) {
618  $tmp['out'] = $out;
619  $uriA[count($uriA)-1] = substr($last, 0, $pos);
620  }
621  $keys = array('module', 'action', 'param', 'text');
622  $min = min(count($keys), count($uriA));
623  $keys = array_slice($keys, 0, $min);
624  $uriA = array_slice($uriA, 0, $min);
625  $tmp = array_merge($tmp, array_combine($keys, $uriA));
626  }
627  }
628 
629  if (substr($uri, 0, 2) == '//')
630  $tmp['controller'] = false;
631  if (substr($uri, 0, 3) == '
632  $tmp['absolute'] = true;
633 
634  return $tmp;
635  }
636 
644  public static function webUri($uri, $absolute = false) {
645  return ($absolute || self::isAbsolutizeAllUris() ? self::get('domain') : null).self::get('path').$uri;
646  }
647 
653  public static function isAbsolutizeAllUris() {
654  return self::$cfg->absolutizeAllUris;
655  }
656 
662  public static function getIp() {
663  return $_SERVER['REMOTE_ADDR'];
664  }
665 
671  public static function isPost() {
672  return !empty($_POST);
673  }
674 
680  public static function isLocal() {
681  return !self::get('serverName') || self::get('serverName') == 'localhost';
682  }
683 
689  public static function isAjax() {
690  return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
691  }
692 
702  public static function isMobile($test = null) {
703  if (self::$mobileStatus === false) {
704  // code from http://detectmobilebrowsers.mobi/
705  // Modified to be simpler and suite the nyroFwk need
706  // many comments removed
707 
708  $user_agent = $_SERVER['HTTP_USER_AGENT'];
709  $accept = $_SERVER['HTTP_ACCEPT'];
710  self::$mobileStatus = null;
711 
712  switch(true) {
713  case (preg_match('/ipad/i',$user_agent));
714  self::$mobileStatus = 'ipad';
715  break;
716  case (preg_match('/ipod/i',$user_agent)||preg_match('/iphone/i',$user_agent));
717  self::$mobileStatus = 'iphone';
718  break;
719  case (preg_match('/android/i',$user_agent));
720  self::$mobileStatus = 'android';
721  break;
722  case (preg_match('/opera mini/i',$user_agent));
723  self::$mobileStatus = 'opera';
724  break;
725  case (preg_match('/blackberry/i',$user_agent));
726  self::$mobileStatus = 'blackberry';
727  break;
728  case (preg_match('/(pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i',$user_agent));
729  self::$mobileStatus = 'palm';
730  break;
731  case (preg_match('/(iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)/i',$user_agent));
732  self::$mobileStatus = 'windows';
733  break;
734  case (preg_match('/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo)/i',$user_agent));
735  case ((strpos($accept,'text/vnd.wap.wml')>0)||(strpos($accept,'application/vnd.wap.xhtml+xml')>0));
736  case (isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE']));
737  case (in_array(strtolower(substr($user_agent,0,4)),array('1207'=>'1207','3gso'=>'3gso','4thp'=>'4thp','501i'=>'501i','502i'=>'502i','503i'=>'503i','504i'=>'504i','505i'=>'505i','506i'=>'506i','6310'=>'6310','6590'=>'6590','770s'=>'770s','802s'=>'802s','a wa'=>'a wa','acer'=>'acer','acs-'=>'acs-','airn'=>'airn','alav'=>'alav','asus'=>'asus','attw'=>'attw','au-m'=>'au-m','aur '=>'aur ','aus '=>'aus ','abac'=>'abac','acoo'=>'acoo','aiko'=>'aiko','alco'=>'alco','alca'=>'alca','amoi'=>'amoi','anex'=>'anex','anny'=>'anny','anyw'=>'anyw','aptu'=>'aptu','arch'=>'arch','argo'=>'argo','bell'=>'bell','bird'=>'bird','bw-n'=>'bw-n','bw-u'=>'bw-u','beck'=>'beck','benq'=>'benq','bilb'=>'bilb','blac'=>'blac','c55/'=>'c55/','cdm-'=>'cdm-','chtm'=>'chtm','capi'=>'capi','cond'=>'cond','craw'=>'craw','dall'=>'dall','dbte'=>'dbte','dc-s'=>'dc-s','dica'=>'dica','ds-d'=>'ds-d','ds12'=>'ds12','dait'=>'dait','devi'=>'devi','dmob'=>'dmob','doco'=>'doco','dopo'=>'dopo','el49'=>'el49','erk0'=>'erk0','esl8'=>'esl8','ez40'=>'ez40','ez60'=>'ez60','ez70'=>'ez70','ezos'=>'ezos','ezze'=>'ezze','elai'=>'elai','emul'=>'emul','eric'=>'eric','ezwa'=>'ezwa','fake'=>'fake','fly-'=>'fly-','fly_'=>'fly_','g-mo'=>'g-mo','g1 u'=>'g1 u','g560'=>'g560','gf-5'=>'gf-5','grun'=>'grun','gene'=>'gene','go.w'=>'go.w','good'=>'good','grad'=>'grad','hcit'=>'hcit','hd-m'=>'hd-m','hd-p'=>'hd-p','hd-t'=>'hd-t','hei-'=>'hei-','hp i'=>'hp i','hpip'=>'hpip','hs-c'=>'hs-c','htc '=>'htc ','htc-'=>'htc-','htca'=>'htca','htcg'=>'htcg','htcp'=>'htcp','htcs'=>'htcs','htct'=>'htct','htc_'=>'htc_','haie'=>'haie','hita'=>'hita','huaw'=>'huaw','hutc'=>'hutc','i-20'=>'i-20','i-go'=>'i-go','i-ma'=>'i-ma','i230'=>'i230','iac'=>'iac','iac-'=>'iac-','iac/'=>'iac/','ig01'=>'ig01','im1k'=>'im1k','inno'=>'inno','iris'=>'iris','jata'=>'jata','java'=>'java','kddi'=>'kddi','kgt'=>'kgt','kgt/'=>'kgt/','kpt '=>'kpt ','kwc-'=>'kwc-','klon'=>'klon','lexi'=>'lexi','lg g'=>'lg g','lg-a'=>'lg-a','lg-b'=>'lg-b','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-f'=>'lg-f','lg-g'=>'lg-g','lg-k'=>'lg-k','lg-l'=>'lg-l','lg-m'=>'lg-m','lg-o'=>'lg-o','lg-p'=>'lg-p','lg-s'=>'lg-s','lg-t'=>'lg-t','lg-u'=>'lg-u','lg-w'=>'lg-w','lg/k'=>'lg/k','lg/l'=>'lg/l','lg/u'=>'lg/u','lg50'=>'lg50','lg54'=>'lg54','lge-'=>'lge-','lge/'=>'lge/','lynx'=>'lynx','leno'=>'leno','m1-w'=>'m1-w','m3ga'=>'m3ga','m50/'=>'m50/','maui'=>'maui','mc01'=>'mc01','mc21'=>'mc21','mcca'=>'mcca','medi'=>'medi','meri'=>'meri','mio8'=>'mio8','mioa'=>'mioa','mo01'=>'mo01','mo02'=>'mo02','mode'=>'mode','modo'=>'modo','mot '=>'mot ','mot-'=>'mot-','mt50'=>'mt50','mtp1'=>'mtp1','mtv '=>'mtv ','mate'=>'mate','maxo'=>'maxo','merc'=>'merc','mits'=>'mits','mobi'=>'mobi','motv'=>'motv','mozz'=>'mozz','n100'=>'n100','n101'=>'n101','n102'=>'n102','n202'=>'n202','n203'=>'n203','n300'=>'n300','n302'=>'n302','n500'=>'n500','n502'=>'n502','n505'=>'n505','n700'=>'n700','n701'=>'n701','n710'=>'n710','nec-'=>'nec-','nem-'=>'nem-','newg'=>'newg','neon'=>'neon','netf'=>'netf','noki'=>'noki','nzph'=>'nzph','o2 x'=>'o2 x','o2-x'=>'o2-x','opwv'=>'opwv','owg1'=>'owg1','opti'=>'opti','oran'=>'oran','p800'=>'p800','pand'=>'pand','pg-1'=>'pg-1','pg-2'=>'pg-2','pg-3'=>'pg-3','pg-6'=>'pg-6','pg-8'=>'pg-8','pg-c'=>'pg-c','pg13'=>'pg13','phil'=>'phil','pn-2'=>'pn-2','pt-g'=>'pt-g','palm'=>'palm','pana'=>'pana','pire'=>'pire','pock'=>'pock','pose'=>'pose','psio'=>'psio','qa-a'=>'qa-a','qc-2'=>'qc-2','qc-3'=>'qc-3','qc-5'=>'qc-5','qc-7'=>'qc-7','qc07'=>'qc07','qc12'=>'qc12','qc21'=>'qc21','qc32'=>'qc32','qc60'=>'qc60','qci-'=>'qci-','qwap'=>'qwap','qtek'=>'qtek','r380'=>'r380','r600'=>'r600','raks'=>'raks','rim9'=>'rim9','rove'=>'rove','s55/'=>'s55/','sage'=>'sage','sams'=>'sams','sc01'=>'sc01','sch-'=>'sch-','scp-'=>'scp-','sdk/'=>'sdk/','se47'=>'se47','sec-'=>'sec-','sec0'=>'sec0','sec1'=>'sec1','semc'=>'semc','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','sk-0'=>'sk-0','sl45'=>'sl45','slid'=>'slid','smb3'=>'smb3','smt5'=>'smt5','sp01'=>'sp01','sph-'=>'sph-','spv '=>'spv ','spv-'=>'spv-','sy01'=>'sy01','samm'=>'samm','sany'=>'sany','sava'=>'sava','scoo'=>'scoo','send'=>'send','siem'=>'siem','smar'=>'smar','smit'=>'smit','soft'=>'soft','sony'=>'sony','t-mo'=>'t-mo','t218'=>'t218','t250'=>'t250','t600'=>'t600','t610'=>'t610','t618'=>'t618','tcl-'=>'tcl-','tdg-'=>'tdg-','telm'=>'telm','tim-'=>'tim-','ts70'=>'ts70','tsm-'=>'tsm-','tsm3'=>'tsm3','tsm5'=>'tsm5','tx-9'=>'tx-9','tagt'=>'tagt','talk'=>'talk','teli'=>'teli','topl'=>'topl','hiba'=>'hiba','up.b'=>'up.b','upg1'=>'upg1','utst'=>'utst','v400'=>'v400','v750'=>'v750','veri'=>'veri','vk-v'=>'vk-v','vk40'=>'vk40','vk50'=>'vk50','vk52'=>'vk52','vk53'=>'vk53','vm40'=>'vm40','vx98'=>'vx98','virg'=>'virg','vite'=>'vite','voda'=>'voda','vulc'=>'vulc','w3c '=>'w3c ','w3c-'=>'w3c-','wapj'=>'wapj','wapp'=>'wapp','wapu'=>'wapu','wapm'=>'wapm','wig '=>'wig ','wapi'=>'wapi','wapr'=>'wapr','wapv'=>'wapv','wapy'=>'wapy','wapa'=>'wapa','waps'=>'waps','wapt'=>'wapt','winc'=>'winc','winw'=>'winw','wonu'=>'wonu','x700'=>'x700','xda2'=>'xda2','xdag'=>'xdag','yas-'=>'yas-','your'=>'your','zte-'=>'zte-','zeto'=>'zeto','acs-'=>'acs-','alav'=>'alav','alca'=>'alca','amoi'=>'amoi','aste'=>'aste','audi'=>'audi','avan'=>'avan','benq'=>'benq','bird'=>'bird','blac'=>'blac','blaz'=>'blaz','brew'=>'brew','brvw'=>'brvw','bumb'=>'bumb','ccwa'=>'ccwa','cell'=>'cell','cldc'=>'cldc','cmd-'=>'cmd-','dang'=>'dang','doco'=>'doco','eml2'=>'eml2','eric'=>'eric','fetc'=>'fetc','hipt'=>'hipt','http'=>'http','ibro'=>'ibro','idea'=>'idea','ikom'=>'ikom','inno'=>'inno','ipaq'=>'ipaq','jbro'=>'jbro','jemu'=>'jemu','java'=>'java','jigs'=>'jigs','kddi'=>'kddi','keji'=>'keji','kyoc'=>'kyoc','kyok'=>'kyok','leno'=>'leno','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-g'=>'lg-g','lge-'=>'lge-','libw'=>'libw','m-cr'=>'m-cr','maui'=>'maui','maxo'=>'maxo','midp'=>'midp','mits'=>'mits','mmef'=>'mmef','mobi'=>'mobi','mot-'=>'mot-','moto'=>'moto','mwbp'=>'mwbp','mywa'=>'mywa','nec-'=>'nec-','newt'=>'newt','nok6'=>'nok6','noki'=>'noki','o2im'=>'o2im','opwv'=>'opwv','palm'=>'palm','pana'=>'pana','pant'=>'pant','pdxg'=>'pdxg','phil'=>'phil','play'=>'play','pluc'=>'pluc','port'=>'port','prox'=>'prox','qtek'=>'qtek','qwap'=>'qwap','rozo'=>'rozo','sage'=>'sage','sama'=>'sama','sams'=>'sams','sany'=>'sany','sch-'=>'sch-','sec-'=>'sec-','send'=>'send','seri'=>'seri','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','siem'=>'siem','smal'=>'smal','smar'=>'smar','sony'=>'sony','sph-'=>'sph-','symb'=>'symb','t-mo'=>'t-mo','teli'=>'teli','tim-'=>'tim-','tosh'=>'tosh','treo'=>'treo','tsm-'=>'tsm-','upg1'=>'upg1','upsi'=>'upsi','vk-v'=>'vk-v','voda'=>'voda','vx52'=>'vx52','vx53'=>'vx53','vx60'=>'vx60','vx61'=>'vx61','vx70'=>'vx70','vx80'=>'vx80','vx81'=>'vx81','vx83'=>'vx83','vx85'=>'vx85','wap-'=>'wap-','wapa'=>'wapa','wapi'=>'wapi','wapp'=>'wapp','wapr'=>'wapr','webc'=>'webc','whit'=>'whit','winw'=>'winw','wmlb'=>'wmlb','xda-'=>'xda-',)));
738  self::$mobileStatus = 'other';
739  break;
740  }
741  }
742 
743  if (!is_null(self::$mobileStatus)) {
744  if (!is_null($test)) {
745  if (is_array($test)) {
746  $test = array_map('strtolower', $test);
747  return in_array(self::$mobileStatus, $test);
748  } else {
749  return self::$mobileStatus == strtolower($test);
750  }
751  }
752  return true;
753  }
754  return false;
755  }
756 
762  public static function isScaffolded() {
763  return self::$scaffold;
764  }
765 
774  public static function extractGet(&$request, $affectGet = false) {
775  $req = explode('?', $request);
776  $request = $req[0];
777  $get = array_key_exists(1, $req) ? $req[1] : null;
778  $ret = array();
779  if ($get) {
780  $tmp = array_filter(explode('&', $get));
781  foreach($tmp as $elm) {
782  if (strpos($elm, '=')) {
783  list($name, $val) = explode('=', $elm);
784  $ret[$name] = $val;
785  if ($affectGet)
786  $_GET[$name] = $val;
787  }
788  }
789  }
790  return $ret;
791  }
792 
800  public static function analyseRequest($request, $alias = true) {
801  if ($alias)
802  $request = self::alias($request);
803  else
804  $request = trim($request, self::$cfg->sep);
805 
806  $ret = array();
807 
808  $out = strtolower(file::getExt($request));
809  if ($out && self::isOut($out)) {
810  $ret['out'] = $out;
811  $request = substr($request, 0, strlen($request) - (strlen($out) + 1));
812  }
813 
814  $tmp = explode(self::$cfg->sep, $request);
815  if (self::isLang($tmp[0]))
816  $ret['lang'] = array_shift($tmp);
817 
818  if (($t = array_shift($tmp)) && $t != self::$cfg->empty)
819  $ret['module'] = $t;
820 
821  if (($t = array_shift($tmp)) && $t != self::$cfg->empty)
822  $ret['action'] = $t;
823 
824  $ret['paramA'] = array();
825  if (($t = array_shift($tmp)) && $t != self::$cfg->empty) {
826  $ret['param'] = $t;
827  $ret['paramA'] = self::parseParam($ret['param']);
828  }
829 
830  if (($t = array_shift($tmp)) && $t != self::$cfg->empty)
831  $ret['text'] = $t;
832 
833  return $ret;
834  }
835 
842  public static function alias($request) {
843  if (substr($request, 0, 1) != '/')
844  $request = '/'.$request;
845  foreach(self::$cfg->alias as $k=>$v) {
846  $req = preg_replace('`^'.$k.'$`', $v, $request);
847  if ($req != $request)
848  return substr($req, 1);
849  }
850  return substr($request, 1);
851  }
852 
859  public static function removeLangOutUrl($request) {
860  return preg_replace('`(.*)(\.'.implode('|\.', array_keys(self::$cfg->outCfg)).')`', '$1',
861  preg_replace('`(/'.implode('|/', self::avlLang()).')?(/.*)`', '$2', $request));
862  }
863 
867  private static function initModule() {
868  if (!self::$module) {
869  self::$module = factory::getModule(self::$uriInfo['module'], array(), self::$scaffold, self::$cfg->allowScaffold);
870  if (self::$module instanceof module_scaffold_controller && !self::$cfg->allowScaffold) {
871  // Need to test if the action was expressly defined
872  $ref = new nReflection();
873  $className = 'module_'.self::$uriInfo['module'].'_controller';
874 
875  $prefix = null;
876  $action = self::$uriInfo['action'];
877  if (array_key_exists(NYROENV, self::$module->getCfg()->basicPrefixExec) &&
878  in_array($action, self::$module->getCfg()->getInArray('basicPrefixExec', NYROENV)))
879  $prefix = ucfirst(NYROENV);
880  else if (self::$module->getCfg()->prefixExec && !in_array($action, self::$module->getCfg()->noPrefixExec))
881  $prefix = self::$module->getCfg()->prefixExec;
882 
883  $exec = 'exec'.$prefix.ucFirst($action);
884  if ($ref->rebuild($className)) {
885  if ($ref->getMethod($exec)->getDeclaringClass()->name != $className)
886  throw new module_exception('Request - initModule: '.self::$uriInfo['module'].'.'.$exec.' not found.');
887  }
888  }
889  if (self::$scaffold) {
890  self::$uriInfo['moduleScaffold'] = self::$uriInfo['module'];
891  self::$uriInfo['module'] = 'scaffold';
892  }
893  }
894  }
895 
901  public static function getModule() {
902  self::initModule();
903  return self::$module;
904  }
905 
911  public static function execModule() {
912  self::initModule();
913  return self::$module->exec(self::$uriInfo);
914  }
915 
921  public static function publishModule() {
922  self::initModule();
923  return self::$module->publish();
924  }
925 
932  public static function isLang($lang) {
933  return in_array($lang, self::avlLang());
934  }
935 
942  public static function avlLang($withName = false) {
943  if ($withName)
944  return self::$cfg->avlLang;
945  return array_keys(self::$cfg->avlLang);
946  }
947 
953  public static function getDefaultLang() {
954  return self::$cfg->defaultLang ? self::$cfg->defaultLang : self::$cfg->lang;
955  }
956 
963  public static function isOut($out) {
964  return $out && array_key_exists($out, self::$cfg->outCfg);
965  }
966 
972  public static function getResponseName() {
973  return self::get('out') ? self::$cfg->outCfg[self::get('out')] : 'http';
974  }
975 
976 }
static get($get=null)
static getModule($name, array $cfg=array(), &$scaffold=false, $allowScaffold=true)
static urlify($text, $ignore=null)
static init()
static initModule()
static $uriInfo
static parseParam($param)
static createParam($param, $urlify=true)
if( $form->hasErrors())
Definition: add.xul.php:2
static $module
static getCfg($key=null)
static getPathControllerUri($forceController=false)
static uriString($uri)
static getPrm($key, $default=null)
static forward($request)
static $requestedUriInfo
static getInstance()
static $cfg
static loadCfg($className, $searchParent=true)
static uploadedUri($file, array $prm=array())
static alias($request)
static fixFiles()
static $scaffold
static hasPrm($key)
static $mobileStatus
static uri($prm=array())
static getRequested($get=null)
static uriDef(array $prm=array(), array $use=array('lang', 'module', 'action', 'param', 'out'))
static forceSecure()
Generated on Sun Oct 15 2017 22:25:20 for nyroFwk by doxygen 1.8.13