Example #1
0
 /**
  * @param int $mode
  */
 public function init($mode = Core::ROUTE_NORMAL)
 {
     $globalConfigs = array('ENV' => self::ENV_DEVELOPMENT, 'JS_FOLDER' => '/js', 'CSS_FOLDER' => '/css', 'CONSOLIDATE_FOLDER' => '/consolidated', 'PROFILER_ENABLED' => false);
     foreach ($globalConfigs as $config => $val) {
         if (!defined($config)) {
             define($config, $val);
         }
     }
     if (ENV == self::ENV_DEVELOPMENT) {
         error_reporting(E_ALL | E_STRICT);
         ini_set("display_errors", 1);
     }
     if (is_object($this->session) && $this->isCLI() === false) {
         $this->session->start();
     }
     $this->mode = $mode;
     $this->startTimer(__CLASS__);
     // Assign our output handler to output clean errors
     ob_start();
     // ingore user abort, is recommed for ajax request and db changes
     if ($this->request->isXmlHttpRequest()) {
         ignore_user_abort(true);
     }
     $this->registryManager->init();
     if ($this->isCLI() === false) {
         // Sanitize all request variables
         $_GET = $this->sanitize($_GET);
         $_POST = $this->sanitize($_POST);
         $_COOKIE = $this->sanitize($_COOKIE);
         if ($mode === Core::ROUTE_NORMAL) {
             $this->cache->load();
             // Try to load a site by the requested URI
             $this->route->loadSite();
             if (!$this->request->isXmlHttpRequest() && !$this->request->isPost()) {
                 echo '<!-- ' . $this->getPageLoadTime() . 'sec -->';
             }
             $this->response->finish(false, true);
         }
     } else {
         $params = getopt('p:');
         if ($params['p']) {
             $_SERVER['REQUEST_URI'] = $params['p'];
             $this->route->loadVirtualRoutes();
             echo $this->route->checkVirtualRoute();
         }
     }
 }
Example #2
0
 /**
  * @param $userId
  * @return $this
  */
 public function setUserId($userId)
 {
     $this->user = $this->db->getRepository('\\Fraym\\User\\Entity\\User')->findOneById($userId);
     if (!$this->user) {
         $this->session->destroy();
         return $this;
     }
     $this->userId = $userId;
     $this->session->set('userId', $this->userId);
     if ($this->user) {
         $this->isLoggedIn = true;
         $this->user->isOnline = true;
         $this->user->lastLogin = new \DateTime();
         $this->db->persist($this->user);
         $this->db->flush();
     }
     return $this;
 }
Example #3
0
File: Core.php Project: fraym/core
 /**
  * @param int $mode
  */
 public function init($mode = Core::ROUTE_NORMAL)
 {
     if (ENV == self::ENV_DEVELOPMENT) {
         error_reporting(E_ALL | E_STRICT);
         ini_set("display_errors", 1);
     }
     if (is_object($this->session) && $this->isCLI() === false) {
         $this->session->start();
     }
     $this->mode = $mode;
     $this->startTimer(__CLASS__);
     // Assign our output handler to output clean errors
     ob_start();
     // ingore user abort, is recommed for ajax request and db changes
     if ($this->request->isXmlHttpRequest()) {
         ignore_user_abort(true);
     }
     $this->registryManager->init();
     if ($this->isCLI() === false) {
         // Sanitize all request variables
         $_GET = $this->sanitize($_GET);
         $_POST = $this->sanitize($_POST);
         $_COOKIE = $this->sanitize($_COOKIE);
         if ($mode === Core::ROUTE_NORMAL) {
             $this->cache->load();
             // Try to load a site by the requested URI
             $this->route->loadSite();
             $this->response->finish(false, true);
         }
     } else {
         $params = getopt('p:');
         if ($params['p']) {
             $_SERVER['REQUEST_URI'] = $params['p'];
             $this->route->loadRoutes();
             echo $this->route->getVirtualRouteContent();
         }
     }
 }
Example #4
0
 /**
  *
  */
 public function menuItemNotFound()
 {
     $page404 = null;
     if ($this->currentMenuItem) {
         $localeId = $this->session->get('localeId', false);
         $page404 = $this->db->createQueryBuilder()->select("menuItemTranslation, menuItem, template, site, locale")->from('\\Fraym\\Menu\\Entity\\MenuItemTranslation', 'menuItemTranslation')->join('menuItemTranslation.menuItem', 'menuItem')->leftJoin("menuItem.template", 'template')->join("menuItem.site", 'site')->join("menuItemTranslation.locale", 'locale')->setMaxResults(1)->setParameter('site', $this->currentMenuItem->site->id)->where("site.id = :site AND menuItem.is404 = 1 AND menuItem.active = 1");
         if ($localeId) {
             $page404 = $page404->andWhere('locale.id = :locale')->setParameter('locale', $localeId);
         } else {
             $page404 = $page404->andWhere('locale.default = 1');
         }
         $page404 = $page404->getQuery()->getOneOrNullResult();
     }
     // call site note found view
     if (is_object($page404)) {
         $this->render404Site($page404);
         // cache the 404 page
         $this->cache->setCacheContent();
     } else {
         error_log('Menuitem not found or template not set!');
         $this->response->sendHTTPStatusCode(500);
     }
     $this->response->finish(true, true);
 }
Example #5
0
 /**
  * @param $val
  * @return bool
  */
 public function setEditMode($val)
 {
     $this->inEditMode = $val;
     $this->session->set('inEditMode', $this->inEditMode);
     return true;
 }
Example #6
0
 /**
  * @return string
  */
 private function getCacheName()
 {
     $uri = $this->route->getRequestRoute();
     $user = $this->session->get('userId', '');
     return md5($uri . $user);
 }
Example #7
0
File: Cache.php Project: fraym/core
 /**
  * @return string
  */
 protected function getCacheName()
 {
     $uri = trim($this->route->getRequestRoute(), '/');
     $user = $this->session->get('userId', null);
     return md5($uri) . ($user ? '_' . $user : '');
 }