/** * */ public static function checkPermissions() { $request = Core_Request::getInstance(); // permissions structure $data = array('module' => $request->getRoute('module'), 'controller' => $request->getRoute('controller'), 'action' => $request->getRoute('action')); $model = Admin_PermissionsModel::getInstance(); $flag = $model->getFlag($data); // $flag = 0 - is a free acces of the page if ($flag === 0) { return true; } if (!$flag) { // we need to check that method exist $model->add($data); } else { if (!s()->user->id) { // @todo Core_View::getInstance()->addFlashMessage(__('Please Login'), 'danger'); Core_Response::getInstance()->setStatus(1)->redirect('admin')->toJson(); } if (!Core_Bit::check(s()->user->access['permissions'], $flag)) { // well an owner has ALL access $role_rs = Admin_RolesModel::get(array('id' => s()->user->role_id)); if ($role_rs->is_owner === 1 || s()->user->is_developer === 1) { return true; } Core_View::getInstance()->addFlashMessage(__('You Don\'t have permission to access this page'), 'danger'); Core_Response::getInstance()->setStatus(1)->redirect('admin')->toJson(); } } }
/** * */ protected function initView() { $this->view = Core_View::getInstance(); $this->view->addHelper(new Admin_View_BaseHelper()); $this->view->addHelper(new Admin_View_MessagesHelper()); $this->view->addHelper(new Admin_View_PagingHelper()); }
/** * @param $host * @param $user * @param $pass * @param $name * @param string $driver */ public function __construct($host, $user, $pass, $name, $driver = 'pgsql') { try { parent::__construct($driver . ':dbname=' . $name . ';host=' . $host, $user, $pass); } catch (Exception $e) { if (!cfg()->dev_mode && Core_Request::getInstance()->getRoute('module') == 'default') { $view = Core_View::getInstance(); $view->setLayoutFile('$maintenance/db_connect.phtml'); $view->displayLayout(); die; } else { print get_class($e) . ': ' . $e->getMessage() . PHP_EOL; die; } } if (cfg()->dev_mode) { $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } else { $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); } $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Core_Db_Statement', array($this))); if (cfg()->dev_mode) { // Core_Debug::getInstance()->initPdoDebug($this); } }
/** * @throws Exception */ protected function loadCfg() { $match_id = PHP_SAPI == 'cli' ? $this->getRequest()->getArgv(1) : $this->getRequest()->cfg_id; cfg()->load($match_id, Core_Cfg::MATCH_TYPE_ID); Core_View::getInstance()->disableLayout(); if (PHP_SAPI != 'cli') { p404('only admin or cli sapi'); } }
/** * @param array $connectionParams */ public static function init(array $connectionParams) { if (!dibi::isConnected()) { try { $connection = dibi::connect(array('driver' => $connectionParams['driver'], 'host' => $connectionParams['host'], 'dsn' => 'mysql:host=' . $connectionParams['host'] . ';dbname=' . $connectionParams['db'] . '', 'persistent' => true, 'username' => $connectionParams['user'], 'password' => $connectionParams['pass'], 'database' => $connectionParams['db'], 'charset' => isset($connectionParams['charset']) ? $connectionParams['charset'] : 'utf8', 'result' => array('detectTypes' => true, 'formatDate' => "Y-m-d", 'formatDateTime' => 'Y-m-d H:i:s'), 'profiler' => array('run' => true), 'flags' => MYSQLI_CLIENT_COMPRESS)); $panel = new Dibi\Bridges\Tracy\Panel(); $panel->register($connection); } catch (DibiException $e) { dd($e->getMessage()); $view = Core_View::getInstance(); $view->setLayoutFile('$maintenance/db_connect.phtml'); $view->displayLayout(); die; } } }
/** * @return mixed */ public final function getView() { return Core_View::getInstance(); }
public function dispatch() { $controller = $this->_dispatchInfo['controller']; $action = $this->_dispatchInfo['action']; $params = $this->_dispatchInfo['params']; // 储存URL参数 if ($params) { Core_Request::getInstance()->setParams($params); } // 如果抛出异常,则由异常处理器处理 if ($controller == 'Core_Exception_Error') { $className = $controller; $classPath = SYS_PATH . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $controller) . '.php'; } else { $className = "Controller" . "_" . ucfirst($controller); $classPath = APP_PATH . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; } // 先检测文件是否查找 if (!file_exists($classPath)) { throw new Core_Exception_Fatal('Unable To find file - ' . $classPath); } // 然后再包含文件 require $classPath; if (!class_exists($className)) { throw new Core_Exception_Fatal('Unable to find controller - ' . $classPath); } $controllerObj = new $className(); $actionMethod = $action . 'Action'; // 方法不存在 if (!method_exists($controllerObj, $actionMethod)) { throw new Core_Exception_Fatal('Unable to find action - ' . $className . '::' . $actionMethod, 404); } $result = call_user_func(array($controllerObj, $actionMethod)); if (isset($controllerObj->autoRender) && $controllerObj->autoRender) { if (null === $result || $result !== false) { $tpl = $controllerObj->getTpl() ?: strtolower($controller) . DS . strtolower($action); $tplFilePath = template($tpl); if (!is_file($tplFilePath)) { throw new Core_Exception_Fatal('Unable to find template - ' . $tplFilePath); } Core_View::getInstance()->display($tpl); } } }
/** * */ protected function disableLayout() { Core_View::getInstance()->disableLayout(); }
/** * 异常处理 * @return [type] [description] */ public function handle() { header('HTTP/1.1 500 Server Error'); Core_View::getInstance()->display('error/500.php'); }
/** * */ protected function initView() { $this->view = Core_View::getInstance(); }
public function display($tpl, $data = null) { $this->_loadMeta(); return Core_View::getInstance()->display($tpl, $data); }
public function handle() { header('HTTP/1.1 404 Not Found'); Core_View::getInstance()->display('error/404.php'); }
/** * @param null $reason * @param null $type */ public static function p404($reason = null, $type = null) { header('HTTP/1.0 404 Not Found'); $view = Core_View::getInstance(); if (is_file($view->getDirectory() . '$maintenance/404.phtml')) { $view->reason = $reason; $view->type = $type; $view->backtrace = debug_backtrace(); $view->setLayoutFile('$maintenance/404.phtml'); $view->enableLayout(); $view->displayLayout(); } else { print '<h1>Page Not Found!</h1>'; if ($reason) { print '<pre>' . $reason . '</pre>'; } print '<pre>'; debug_print_backtrace(); print '</pre>'; } die; }