Example #1
0
 /**
  * Производит анализ и выполнение действий, переданных в URI
  */
 public function run()
 {
     if (Router::isAdmin() && !Auth::getInstance()->hasAccess(1)) {
         throw new Exception(lang('access_denied', __CLASS__));
     }
     MySQL::setOnPage(Config::get('OnPage'));
     $this->route = Router::getPath();
     if (count($this->route) == 0) {
         $this->index = true;
     }
     $this->folder = Router::isAdmin() ? '/admin/' : '/public/';
     if (!Router::isAdmin() && Router::getDefaultModule() == 'Page') {
         Page_Handler::findPage($this);
     }
     foreach ($this->route as $key => $path) {
         $path = ucfirst(mb_strtolower($path));
         if (is_dir(CORE_ROOT . 'controller' . $this->folder . $this->pathToController . $path) && $path != '') {
             $this->pathToController .= $path . '/';
         }
         if (is_file(CORE_ROOT . 'controller' . $this->folder . $this->pathToController . $path . '.php')) {
             $this->controller = $path;
             $this->pathToView .= $path . '/';
             unset($this->route[$key]);
         }
         if (is_file(CORE_ROOT . 'view' . $this->folder . $this->pathToView . '_footer.phtml') && is_file(CORE_ROOT . 'view' . $this->folder . $this->pathToView . '_header.phtml')) {
             $this->pathToTemplate = $this->pathToView;
         }
         if (is_file(CORE_ROOT . 'view' . $this->folder . $this->pathToView . mb_strtolower($path) . '.phtml')) {
             $this->action = mb_strtolower($path);
             unset($this->route[$key]);
         }
     }
     if ($this->controller == '') {
         $this->controller = Router::isAdmin() ? 'Page' : Router::getDefaultModule();
         $this->pathToView = $this->controller . '/';
     }
     if ($this->action == '') {
         if ($this->controller == 'Page' && !$this->index && !Router::isAdmin() && Page_Handler::getPageID() == 0) {
             $this->action = 'page404';
         } else {
             $this->action = 'index';
         }
     }
     $this->route = array_values($this->route);
     if (!is_file(CORE_ROOT . 'controller' . $this->folder . $this->pathToController . $this->controller . '.php')) {
         throw new Exception(lang('error_controller_not_found', __CLASS__));
     }
     include CORE_ROOT . 'class/Controller/AbstractController.php';
     if (Router::isAdmin()) {
         include CORE_ROOT . 'class/Controller/AdminController.php';
     } else {
         include CORE_ROOT . 'class/Controller/PublicController.php';
     }
     include CORE_ROOT . 'controller' . $this->folder . $this->pathToController . $this->controller . '.php';
     $this->controller .= 'Controller';
     $oController = new $this->controller($this);
     $oController->{$this->action}();
     if (!is_file(CORE_ROOT . 'view' . $this->folder . $this->pathToView . $this->action . '.phtml')) {
         throw new Exception(lang('error_view_not_found', __CLASS__) . ':<br />' . 'view' . $this->folder . $this->pathToView . $this->action . '.phtml');
     }
     $oTemplate = new Template($this);
     $oTemplate->load($oController);
     $oTemplate->show();
 }