Exemplo n.º 1
0
 /**
  *	\brief Lê a URLs (em modo re-write) e transforma em variáveis $_GET
  *
  *	\note Este método não retorna valor
  */
 public static function parse_uri($UriString = NULL)
 {
     // $_GET['_rw_'] é definida no .htaccess e contém a url em modo ReWrite
     if (NULL === $UriString) {
         $UriString = !empty($_GET['_rw_']) ? $_GET['_rw_'] : '';
         //unset($_GET['_rw_']);
     }
     // [pt-br] Processa a URI
     $Segments = array();
     self::$segments = array();
     //foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $UriString)) as $val) {
     preg_match('/^([A-Za-z0-9_.\\-\\/]+)*[&]?/', $UriString, $UriString);
     if (isset($UriString[1])) {
         $UriString = $UriString[1];
         foreach (explode('/', $UriString) as $val) {
             $val = trim($val);
             if ($val != '') {
                 self::$segments[] = $val;
             }
         }
     }
     if (empty(self::$segments)) {
         self::$segments[] = 'index';
     }
     //Se suspeita de Big int > 8, Index
     foreach (self::$segments as $teste => $value) {
         if (is_numeric($value)) {
             $value = strlen($value);
             $valueLTRIM = strlen(ltrim($value, '0'));
             if ($value > 14 or $valueLTRIM > 16) {
                 Messages::getInstance()->error('URL inválida.');
                 URI::redirect(URI::build_url(array('.')));
             }
         }
     }
     // [pt-br] Guarda os parâmetros passados por GET na URL
     foreach ($_GET as $key => $value) {
         if ($key == '_rw_') {
             continue;
         }
         self::$get_params[$key] = $value;
         unset($_GET[$key]);
     }
     //Se suspeita de Big int > 8 , Index
     foreach (self::$get_params as $teste => $value) {
         if (is_numeric($value)) {
             $value = strlen($value);
             $valueLTRIM = strlen(ltrim($value, '0'));
             if ($value > 16 or $valueLTRIM > 16) {
                 Messages::getInstance()->error('Parâmetro inválido.');
                 URI::redirect(URI::build_url(array('.')));
             }
         }
     }
 }
Exemplo n.º 2
0
Arquivo: core.php Projeto: pihizi/qf
 static function default_dispatcher()
 {
     if (Input::$AJAX && Input::$AJAX['widget']) {
         $widget = Widget::factory(Input::$AJAX['widget']);
         $method = 'on_' . (Input::$AJAX['object'] ?: 'unknown') . '_' . (Input::$AJAX['event'] ?: 'unknown');
         if (method_exists($widget, $method)) {
             Event::bind('system.output', 'Output::AJAX');
             $widget->{$method}();
         }
         return;
     }
     $args = Input::args();
     $default_page = Config::get('system.default_page');
     if (!$default_page) {
         $default_page = 'index';
     }
     //从末端开始尝试
     /*
     	home/page/edit.1
     	home/page/index.php Index_Controller::edit(1)
     	home/page/index.php Index_Controller::index('edit', 1)
     	home/page.php		Page_Controller::edit(1)
     	home/page.php		Page_Controller::index('edit', 1)
     */
     $file = end($args);
     if (!preg_match('/[^\\\\]\\./', $file)) {
         //有非法字符的只能是参数
         $path = implode('/', $args);
         // home/page/edit/index => index, NULL
         $candidates[($path ? $path . '/' : '') . $default_page] = array($default_page, NULL);
         $candidates[$path] = array($file, NULL);
         // home/page/edit => edit, NULL
     }
     if ($args) {
         $params = array_pop($args);
         $file = $args ? end($args) : $default_page;
         $path = $args ? implode('/', $args) : $default_page;
         $candidates[$path] = array($file, $params);
         // home/page.php => page, edit|1
     } else {
         $candidates[$default_page] = array($default_page, NULL);
     }
     $class = NULL;
     foreach ($candidates as $path => $candidate) {
         if (Core::load(CONTROLLER_BASE, $path)) {
             $class = str_replace('/', '_', $path);
             $params = array();
             if (preg_match_all('/(.*?[^\\\\])\\./', $candidate[1] . '.', $parts)) {
                 foreach ($parts[1] as $part) {
                     $params[] = strtr($part, array('\\.' => '.'));
                 }
             }
             Config::set('system.controller_path', $path);
             Config::set('system.controller_class', $class);
             break;
         }
     }
     if (!$class) {
         URI::redirect('error/404');
     }
     if (Input::$AJAX) {
         $class .= AJAX_SUFFIX;
         if (!class_exists($class, false)) {
             Core::load(CONTROLLER_BASE, 'ajax');
             $class = 'AJAX' . CONTROLLER_SUFFIX;
         }
         $controller = new $class();
         $object = Input::$AJAX['object'];
         $event = Input::$AJAX['event'];
         $method = $params[0];
         if (!$method || $method[0] == '_') {
             $method = 'index_';
         }
         $method .= '_' . ($object ? $object . '_' : '') . $event;
         if (method_exists($controller, $method)) {
             array_shift($params);
         } else {
             $method = 'index_' . ($object ? $object . '_' : '') . $event;
             if (!method_exists($controller, $method)) {
                 $method = NULL;
             }
         }
         if ($method) {
             Controller::$CURRENT = $controller;
             Config::set('system.controller_method', $method);
             Config::set('system.controller_params', $params);
             $controller->_before_call($method, $params);
             call_user_func_array(array($controller, $method), $params);
             $controller->_after_call($method, $params);
         }
     } else {
         $class .= CONTROLLER_SUFFIX;
         $controller = new $class();
         $method = $params[0];
         if ($method && $method[0] != '_' && method_exists($controller, $method)) {
             array_shift($params);
         } elseif ($method && $method[0] != '_' && method_exists($controller, 'do_' . $method)) {
             $method = 'do_' . $method;
             array_shift($params);
         } else {
             $method = 'index';
         }
         Controller::$CURRENT = $controller;
         Config::set('system.controller_method', $method);
         Config::set('system.controller_params', $params);
         $controller->_before_call($method, $params);
         call_user_func_array(array($controller, $method), $params);
         $controller->_after_call($method, $params);
     }
 }