Пример #1
0
 public function execute()
 {
     $api = Lib::api('admin', array('response' => 'return', 'format' => 'php'));
     $type = Req::get('type');
     if (!is_callable(array($api, $type))) {
         return Lib::redirect('error');
     }
     $result = $api->{$type}();
     $options = array('view' => 'admin');
     $ref = Req::post('ref');
     if (!$result['state']) {
         if (!empty($ref)) {
             $options['ref'] = $ref;
         }
     } else {
         $segments = explode('/', base64_decode(urldecode($ref)));
         $base = array_shift($segments);
         $type = array_shift($segments);
         $subtype = array_shift($segments);
         if (!empty($type)) {
             $options['type'] = $type;
         }
         if (!empty($subtype)) {
             $options['subtype'] = $subtype;
         }
     }
     Lib::redirect('admin', $options);
 }
Пример #2
0
 public function route($segments = array())
 {
     $name = array_shift($segments);
     $method = array_shift($segments);
     $api = Lib::api($name);
     if (!is_callable(array($api, $method))) {
         return Lib::api()->fail();
     }
     $api->{$method}($segments);
 }
Пример #3
0
 public static function route()
 {
     $prefix = '/' . Config::getBaseFolder();
     $requesturi = $_SERVER['REQUEST_URI'];
     if (substr($requesturi, 0, strlen($prefix)) == $prefix) {
         $requesturi = substr($requesturi, strlen($prefix));
     }
     $requesturi = trim($requesturi, '/');
     $requestSegments = explode('?', $requesturi);
     $segments = explode('/', $requestSegments[0]);
     if ($segments[0] !== 'index.php') {
         Lib::load('router');
         foreach (Router::getRouters() as $router) {
             if (is_string($router->allowedRoute) && $segments[0] !== $router->allowedRoute) {
                 continue;
             }
             if (is_array($router->allowedRoute) && !in_array($segments[0], $router->allowedRoute)) {
                 continue;
             }
             $router->decode($segments);
         }
     }
     // Check for API call
     if (Req::hasget('api')) {
         $apiName = Req::get('api');
         $action = Req::get('action');
         $api = Lib::api($apiName);
         if (!is_callable(array($api, $action))) {
             return Lib::api()->fail();
         }
         return $api->{$action}();
     }
     // Check for controller
     if (Req::hasget('controller')) {
         $controllerName = Req::get('controller');
         $action = Req::get('action');
         $controller = Lib::controller($controllerName);
         if (!is_callable(array($controller, $action))) {
             return $controller->execute();
         }
         return $controller->{$action}();
     }
     $viewname = Req::get('view');
     if (empty($viewname)) {
         $viewname = 'error';
     }
     return Lib::view($viewname)->display();
 }