示例#1
0
 /**
  * Check for the user session
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     $sess = $application->getService('session');
     $action = $application->router()->getRouteMatch()->getAction();
     $route = $application->router()->getRouteMatch()->getRoute();
     $isInstall = substr($route, 0, strlen(APP_URI . '/install')) == APP_URI . '/install';
     // Special install check
     if (isset($sess->app_uri) && strpos($_SERVER['REQUEST_URI'], 'install/config') !== false) {
         if (BASE_PATH . APP_URI == BASE_PATH . $sess->app_uri && $application->config()['db']) {
             Response::redirect(BASE_PATH . APP_URI . '/install/user');
             exit;
         }
     }
     // If logged in, and a system URL, redirect to dashboard
     if (isset($sess->user) && ($action == 'login' || $action == 'register' || $action == 'verify' || $action == 'forgot' || $isInstall)) {
         Response::redirect(BASE_PATH . (APP_URI != '' ? APP_URI : '/'));
         exit;
         // Else, if NOT logged in and NOT a system URL, redirect to login
     } else {
         if (!isset($sess->user) && ($action != 'login' && $action != 'register' && !$isInstall && $action != 'unsubscribe' && $action != 'verify' && $action != 'forgot' && null !== $action) && substr($route, 0, strlen(APP_URI)) == APP_URI) {
             Response::redirect(BASE_PATH . APP_URI . '/login');
             exit;
         }
     }
 }
示例#2
0
 /**
  * Save click
  *
  * @param  Application $application
  * @return void
  */
 public static function save(Application $application)
 {
     if (!$_POST && $application->router()->getController() instanceof \Phire\Content\Controller\IndexController) {
         $uri = $application->router()->getController()->request()->getRequestUri();
         if ($uri != '/favicon.ico') {
             $click = new Model\Click();
             if ($application->router()->getController()->response()->getCode() == 200) {
                 $click->saveContent($uri, 'content');
             } else {
                 if ($application->router()->getController()->response()->getCode() == 404) {
                     $click->saveContent($uri, 'error');
                 }
             }
         }
     }
 }
示例#3
0
文件: Db.php 项目: phirecms/phirecms
 /**
  * Check if the database has been installed and a database connection is available
  *
  * @param  Application $application
  * @throws \Phire\Exception
  * @return void
  */
 public static function check(Application $application)
 {
     $route = $application->router()->getRouteMatch()->getRoute();
     if (!$application->config()['db'] && substr($route, 0, strlen(APP_URI . '/install')) != APP_URI . '/install') {
         $exception = new \Phire\Exception('Error: The database has not been installed. ' . 'Please check the config file or <a href="' . BASE_PATH . APP_URI . '/install">install</a> the system.');
         $exception->setInstallErrorFlag(true);
         throw $exception;
     }
 }
示例#4
0
 /**
  * Check if the user session is allowed with the ACL service
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     $application->module('app')->initAcl();
     $sess = $application->getService('session');
     $acl = $application->getService('acl');
     if (isset($sess->user) && isset($sess->user->role) && $acl->hasRole($sess->user->role)) {
         // Get routes with slash options
         $route = $application->router()->getRouteMatch()->getRoute();
         $routes = $application->router()->getRouteMatch()->getRoutes();
         if (isset($routes[$route]) && isset($routes[$route]['acl']) && isset($routes[$route]['acl']['resource'])) {
             $resource = $routes[$route]['acl']['resource'];
             $permission = isset($routes[$route]['acl']['permission']) ? $routes[$route]['acl']['permission'] : null;
             if (!$acl->isAllowed($sess->user->role, $resource, $permission)) {
                 Response::redirect('/');
                 exit;
             }
         }
     }
 }
示例#5
0
 /**
  * Check for the member session
  *
  * @param  Application $application
  * @return void
  */
 public static function sessionCheck(Application $application)
 {
     if (null !== $application->router()->getController() && $application->router()->getController() instanceof \Phire\Members\Controller\IndexController) {
         $sess = $application->getService('session');
         $action = $application->router()->getRouteMatch()->getAction();
         $route = $application->router()->getRouteMatch()->getRoute();
         $memberUri = $application->router()->getController()->getMemberUri();
         // If logged in, and a member URL, redirect to dashboard
         if (isset($sess->member) && ($action == 'login' || $action == 'register' || $action == 'verify' || $action == 'forgot')) {
             Response::redirect(BASE_PATH . $memberUri);
             exit;
             // Else, if NOT logged in and NOT a system URL, redirect to login
         } else {
             if (!isset($sess->member) && ($action != 'login' && $action != 'register' && $action != 'unsubscribe' && $action != 'verify' && $action != 'forgot' && null !== $action) && substr($route, 0, strlen($memberUri)) == $memberUri) {
                 Response::redirect(BASE_PATH . $memberUri . '/login');
                 exit;
             }
         }
     }
 }
示例#6
0
 /**
  * Save content to cache
  *
  * @param  Application $application
  * @return void
  */
 public static function save(Application $application)
 {
     if ($application->router()->getController() instanceof \Phire\Content\Controller\IndexController && $application->router()->getController()->response()->getCode() == 200 && empty($_SERVER['QUERY_STRING']) && !$_POST) {
         $sess = $application->services()->get('session');
         $uri = $application->router()->getController()->request()->getRequestUri();
         $cache = (new Model\Cache())->getCacheAdapter();
         $exclude = $application->module('phire-cache')['exclude'];
         if (null !== $cache && !isset($sess->user) && !in_array($uri, $exclude)) {
             $contentType = $application->router()->getController()->response()->getHeader('Content-Type');
             $body = $application->router()->getController()->response()->getBody();
             if ($contentType == 'text/html') {
                 $body .= PHP_EOL . PHP_EOL . '<!-- Generated by the phire-cache module on ' . date('M j, Y H:i:s') . '. //-->' . PHP_EOL . PHP_EOL;
             } else {
                 if (stripos($contentType, 'xml') !== false) {
                     $body .= PHP_EOL . PHP_EOL . '<!-- Generated by the phire-cache module on ' . date('M j, Y H:i:s') . '. -->' . PHP_EOL . PHP_EOL;
                 }
             }
             $cache->save($uri, ['content-type' => $contentType, 'body' => $body]);
         }
     }
 }
示例#7
0
 /**
  * Register module
  *
  * @param  Application $application
  * @return ModuleInterface
  */
 public function register(Application $application)
 {
     $this->application = $application;
     if (null !== $this->config) {
         // If the autoloader is set and the the module config has a
         // defined prefix and src, register the module with the autoloader
         if (null !== $this->application && null !== $this->application->autoloader() && isset($this->config['prefix']) && isset($this->config['src']) && file_exists($this->config['src'])) {
             // Register as PSR-0
             if (isset($this->config['psr-0']) && $this->config['psr-0']) {
                 $this->application->autoloader()->add($this->config['prefix'], $this->config['src']);
                 // Else, default to PSR-4
             } else {
                 $this->application->autoloader()->addPsr4($this->config['prefix'], $this->config['src']);
             }
         }
         // If routes are set in the module config, register them with the application
         if (isset($this->config['routes']) && null !== $this->application && null !== $this->application->router()) {
             $this->application->router()->addRoutes($this->config['routes']);
         }
         // If services are set in the module config, register them with the application
         if (isset($this->config['services']) && null !== $this->application && null !== $this->application->services()) {
             foreach ($this->config['services'] as $name => $service) {
                 if (isset($service['call']) && isset($service['params'])) {
                     $this->application->setService($name, $service['call'], $service['params']);
                 } else {
                     if (isset($service['call'])) {
                         $this->application->setService($name, $service['call']);
                     }
                 }
             }
         }
         // If events are set in the app config, register them with the application
         if (isset($this->config['events']) && null !== $this->application && null !== $this->application->events()) {
             foreach ($this->config['events'] as $event) {
                 if (isset($event['name']) && isset($event['action'])) {
                     $this->application->on($event['name'], $event['action'], isset($event['priority']) ? $event['priority'] : 0);
                 }
             }
         }
     }
     return $this;
 }
示例#8
0
 /**
  * Check for the user session
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     $sess = $application->getService('session');
     $action = $application->router()->getRouteMatch()->getAction();
     if (isset($sess->user) && isset($sess->user->sess_id) && !isset(Table\UserSessions::findById($sess->user->sess_id)->id)) {
         $user = new Model\User();
         $user->logout($sess);
         unset($sess->user);
         $sess->setRequestValue('expired', true);
         Response::redirect('/login');
         exit;
     } else {
         if (isset($sess->user) && ($action == 'login' || $action == 'forgot' || $action == 'verify')) {
             Response::redirect('/');
             exit;
         } else {
             if (!isset($sess->user) && $action != 'login' && $action != 'forgot' && $action != 'verify') {
                 Response::redirect('/login');
                 exit;
             }
         }
     }
 }
示例#9
0
 /**
  * Init category nav and categories
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function init(AbstractController $controller, Application $application)
 {
     if (!$_POST && $controller->hasView()) {
         $category = new Model\Category();
         $category->show_total = $application->module('phire-categories')['show_total'];
         $category->filters = $application->module('phire-categories')['filters'];
         $category->datetime_formats = $application->module('phire-categories')['datetime_formats'];
         $controller->view()->category_nav = $category->getNav($application->module('phire-categories')['nav_config']);
         if ($application->isRegistered('phire-templates') && $controller->view()->isStream() && (strpos($controller->view()->getTemplate()->getTemplate(), '[{category_') !== false || strpos($controller->view()->getTemplate()->getTemplate(), '[{categories_') !== false)) {
             $catIds = self::parseCategoryIds($controller->view()->getTemplate()->getTemplate());
             $catParentIds = self::parseParentCategoryIds($controller->view()->getTemplate()->getTemplate());
             if (count($catIds) > 0) {
                 foreach ($catIds as $key => $value) {
                     $category->getById($value['id']);
                     $categoryName = 'category_' . $value['id'];
                     if (isset($value['limit']) && $value['limit'] > 0 && $category->hasPages($value['limit'])) {
                         $limit = $value['limit'];
                         $categoryName .= '_' . $limit;
                         $pages = null;
                     } else {
                         if ($category->pagination > 0 && $category->hasPages($category->pagination)) {
                             $limit = $category->pagination;
                             $pages = new \Pop\Paginator\Paginator($category->getCount(), $limit);
                             $pages->useInput(true);
                         } else {
                             $limit = null;
                             $pages = null;
                         }
                     }
                     if (null !== $pages) {
                         $controller->view()->pages = $pages;
                     }
                     $controller->view()->{$categoryName} = $category->getItems($limit, $controller->request()->getQuery('page'));
                 }
             }
             if (count($catParentIds) > 0) {
                 foreach ($catParentIds as $key => $value) {
                     if (isset($value['limit']) && $value['limit'] > 0) {
                         $limit = $value['limit'];
                         $categoryName = 'categories_' . $value['id'] . '_' . $limit;
                     } else {
                         $limit = null;
                         $categoryName = 'categories_' . $value['id'];
                     }
                     $controller->view()->{$categoryName} = $category->getCategoryChildren($value['id'], $limit);
                 }
             }
         } else {
             if (($controller instanceof \Phire\Content\Controller\IndexController || $controller instanceof \Phire\Categories\Controller\IndexController) && $controller->view()->isFile()) {
                 $controller->view()->phire->category = $category;
             }
         }
         if (($controller instanceof \Phire\Content\Controller\ContentController || $controller instanceof \Phire\Media\Controller\IndexController) && $application->router()->getRouteMatch()->getAction()) {
             $categories = [];
             $cats = Table\Categories::findAll();
             foreach ($cats->rows() as $cat) {
                 $categories[$cat->id] = $cat->title;
             }
             $controller->view()->categories = $categories;
         }
     }
 }
示例#10
0
 /**
  * Record logout/session end
  *
  * @param  \Pop\Application $application
  * @return void
  */
 public static function logout(Application $application)
 {
     $sess = $application->getService('session');
     $userUri = APP_URI;
     $key = 'user';
     if (isset($sess->member) && $application->isRegistered('phire-members')) {
         $key = 'member';
         $memberAdmin = new \Phire\Members\Model\MembersAdmin();
         $memberAdmin->getByRoleId($sess->member->role_id);
         if (isset($memberAdmin->uri)) {
             $userUri = $memberAdmin->uri;
         }
     }
     if ($application->router()->getRouteMatch()->getRoute() == $userUri . '/logout') {
         $path = BASE_PATH . APP_URI;
         if ($path == '') {
             $path = '/';
         }
         $cookie = Cookie::getInstance(['path' => $path]);
         $cookie->delete('phire_session_timeout');
         $cookie->delete('phire_session_path');
         $cookie->delete('phire_session_warning_dismiss');
         $sess = $application->getService('session');
         if (isset($sess[$key]) && isset($sess[$key]->session)) {
             $session = Table\UserSessions::findById((int) $sess[$key]->session->id);
             if (isset($session->id)) {
                 $session->delete();
             }
         }
     }
 }
示例#11
0
 /**
  * Determine if the field is allowed for the form
  *
  * @param  array       $model
  * @param  Application $application
  * @return boolean
  */
 protected static function isAllowed(array $model, Application $application)
 {
     $allowed = true;
     if ($model['model'] == 'Phire\\Model\\Register' || $model['model'] == 'Phire\\Model\\RegisterEmail' || $model['model'] == 'Phire\\Model\\Profile' || $model['model'] == 'Phire\\Model\\ProfileEmail') {
         $model['model'] = 'Phire\\Model\\User';
     }
     // Determine if there is a model type restraint on the field
     if (!empty($model['type_field']) && !empty($model['type_value']) && count($application->router()->getRouteMatch()->getDispatchParams()) > 0) {
         $params = $application->router()->getRouteMatch()->getDispatchParams();
         if (isset($params['id'])) {
             $id = $params['id'];
             if (substr($application->router()->getRouteMatch()->getRoute(), -4) == 'edit') {
                 $modelClass = $model['model'];
                 $modelType = $model['type_field'];
                 $modelObject = new $modelClass();
                 if (method_exists($modelObject, 'getById')) {
                     $modelObject->getById($id);
                     $allowed = isset($modelObject->{$modelType}) && $modelObject->{$modelType} == $model['type_value'];
                 }
             } else {
                 if (substr($application->router()->getRouteMatch()->getRoute(), -8) == 'register') {
                     $allowed = !empty($model['type_value']) && $id == $model['type_value'] || empty($model['type_value']);
                 }
             }
         } else {
             $type_id = $params[key($params)];
             $allowed = $model['type_value'] == $type_id;
         }
     }
     return $allowed;
 }