コード例 #1
0
ファイル: Bootstrap.php プロジェクト: biggtfish/cms
 /**
  * Init some subsystems after engine initialization.
  */
 public function afterEngine()
 {
     $di = $this->getDI();
     $config = $this->getConfig();
     $this->_initI18n($di, $config);
     if (!$config->installed) {
         return;
     }
     // Remove profiler for non-user.
     if (!User::getViewer()->id) {
         $di->remove('profiler');
     }
     // Init widgets system.
     $this->_initWidgets($di);
     /**
      * Listening to events in the dispatcher using the Acl.
      */
     if ($config->installed) {
         $this->getEventsManager()->attach('dispatch', $di->get('core')->acl());
     }
     // Install assets if required.
     if ($config->application->debug) {
         $di->get('assets')->installAssets(PUBLIC_PATH . '/themes/' . Settings::getSetting('system_theme'));
     }
 }
コード例 #2
0
ファイル: Profiler.php プロジェクト: biggtfish/cms
 /**
  * Render profiler.
  *
  * @return string
  */
 public function render()
 {
     $di = $this->getDI();
     $this->_config = $di->get('config');
     $this->_view = $di->get('view');
     if (!$di->has('profiler')) {
         return '';
     }
     // check admin area
     if (substr($di->get('dispatcher')->getControllerName(), 0, 5) == 'Admin') {
         return '';
     }
     $viewer = User::getViewer();
     if (!$viewer->id || !$viewer->isAdmin()) {
         return '';
     }
     $profiler = $di->get('profiler');
     $router = $di->get('router');
     $dbProfiler = $profiler->getDbProfiler();
     $handlerValues = [];
     //////////////////////////////////////
     /// Router.
     //////////////////////////////////////
     $handlerValues['router'] = ucfirst($router->getControllerName()) . 'Controller::' . ucfirst($router->getActionName()) . 'Action';
     //////////////////////////////////////
     /// Memory.
     //////////////////////////////////////
     $memoryData = memory_get_usage();
     $memoryLimit = (int) ini_get('memory_limit') * 1024 * 1024;
     $currentMemoryPercent = round($memoryData / ($memoryLimit / 100));
     $colorClass = $currentMemoryPercent > 30 ? $currentMemoryPercent < 75 ? 'item-normal' : 'item-bad' : 'item-good';
     $handlerValues['memory'] = ['class' => $colorClass, 'value' => round($memoryData / 1024, 2)];
     //////////////////////////////////////
     /// Time.
     //////////////////////////////////////
     $timeData = round((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]) * 1000, 2);
     $colorClass = $timeData > 200 ? $timeData < 500 ? 'item-normal' : 'item-bad' : 'item-good';
     $handlerValues['time'] = ['class' => $colorClass, 'value' => $timeData];
     //////////////////////////////////////
     /// Files.
     //////////////////////////////////////
     $filesData = get_included_files();
     $handlerValues['files'] = count($filesData);
     //////////////////////////////////////
     /// SQL.
     //////////////////////////////////////
     $handlerValues['sql'] = $totalSqlStatements = $dbProfiler->getNumberTotalStatements();
     //////////////////////////////////////
     /// Errors.
     //////////////////////////////////////
     $errorsData = $profiler->getData('error');
     $errorsCount = count($errorsData);
     $colorClass = $errorsCount == 0 ? 'item-good' : 'item-bad';
     $handlerValues['errors'] = ['class' => $colorClass, 'value' => $errorsCount];
     $output = $this->_viewRender('main', ['handlerValues' => $handlerValues, 'htmlConfig' => $this->_getHtmlConfig(), 'htmlRouter' => $this->_getHtmlRouter(), 'htmlMemory' => $this->_getHtmlMemory(), 'htmlTime' => $this->_getHtmlTime($timeData), 'htmlFiles' => $this->_getHtmlFiles($filesData), 'htmlSql' => $this->_getHtmlSql($dbProfiler, $totalSqlStatements), 'htmlErrors' => $this->_getHtmlErrors($errorsData, $errorsCount)]);
     return trim(preg_replace('/\\s\\s+/', ' ', $output));
 }
コード例 #3
0
ファイル: Controller.php プロジェクト: biggtfish/cms
 /**
  * Get widget cache key.
  *
  * @return string|null
  */
 public function getCacheKey()
 {
     $key = self::CACHE_PREFIX;
     $role = User::getViewer()->getRole();
     if ($role) {
         $key .= $role->type;
     } else {
         $key .= Role::getRoleByType(Acl::DEFAULT_ROLE_GUEST)->type;
     }
     $key .= '_' . $this->getDI()->getSession()->get('language');
     return $key;
 }
コード例 #4
0
ファイル: MenuItem.php プロジェクト: biggtfish/cms
 /**
  * Check if menu item output is allowed.
  *
  * @return bool
  */
 public function isAllowed()
 {
     $valid = true;
     $viewer = User::getViewer();
     $roles = $this->getRoles();
     if (!empty($roles)) {
         $valid = in_array($viewer->role_id, $roles);
     }
     if (!$valid) {
         return false;
     }
     $valid = true;
     $language = $this->getDI()->get('session')->get('language', 'en');
     $languages = $this->getLanguages();
     if (!empty($languages)) {
         $valid = in_array($language, $languages);
     }
     return $valid;
 }
コード例 #5
0
ファイル: Renderer.php プロジェクト: biggtfish/cms
 /**
  * Check that this widget is allowed for current user.
  *
  * @param array $params User params.
  *
  * @return bool
  */
 public function widgetIsAllowed($params)
 {
     $viewer = User::getViewer();
     if (empty($params['roles']) || !is_array($params['roles'])) {
         return true;
     }
     return in_array($viewer->role_id, $params['roles']);
 }
コード例 #6
0
ファイル: Page.php プロジェクト: biggtfish/cms
 /**
  * Check if this page is allowed to view.
  *
  * @return bool
  */
 public function isAllowed()
 {
     $viewer = User::getViewer();
     if (empty($this->roles)) {
         return true;
     }
     return in_array($viewer->role_id, $this->roles);
 }
コード例 #7
0
ファイル: Acl.php プロジェクト: biggtfish/cms
 /**
  * Check allowed value.
  *
  * @param mixed  $resource  Resource.
  * @param string $valueName Value name.
  *
  * @return mixed
  */
 public function getAllowed($resource, $valueName)
 {
     $viewer = User::getViewer();
     return $this->getDI()->get('core')->acl()->getAllowedValue($resource, $viewer->getRole(), $valueName);
 }
コード例 #8
0
ファイル: User.php プロジェクト: biggtfish/cms
 /**
  * Is current viewer is user.
  *
  * @return bool
  */
 public function isUser()
 {
     return (bool) UserModel::getViewer()->id;
 }
コード例 #9
0
ファイル: AuthController.php プロジェクト: biggtfish/cms
 /**
  * Register action.
  *
  * @return mixed
  *
  * @Route("/register", methods={"GET", "POST"}, name="register")
  */
 public function registerAction()
 {
     if (User::getViewer()->id) {
         return $this->response->redirect();
     }
     $form = new RegisterForm();
     if (!$this->request->isPost() || !$form->isValid()) {
         $this->view->form = $form;
         return;
     }
     $password = $form->getValue('password');
     $repeatPassword = $form->getValue('repeatPassword');
     if ($password != $repeatPassword) {
         $form->addError("Passwords doesn't match!", 'password');
         $this->view->form = $form;
         return;
     }
     $user = new User();
     $data = $form->getValues();
     $user->role_id = Role::getDefaultRole()->id;
     if (!$user->save($data)) {
         foreach ($user->getMessages() as $message) {
             $form->addError($message);
         }
         $this->view->form = $form;
         return;
     }
     $this->core->auth()->authenticate($user->id);
     return $this->response->redirect();
 }