Пример #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();
         }
     }
 }
Пример #2
0
 /**
  * @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();
         }
     }
 }
Пример #3
0
 /**
  * if cacheing is active and a cached file is availible it outputs the cache and exits the script
  *
  * @return void
  */
 public function load()
 {
     // gets the current uri - example: /folder/folder2
     $filename = $this->getCacheName();
     // create the cache filename
     $cacheFilename = self::DIR_PAGES . $filename . '.cache.php';
     $cacheFilenamePhpData = self::DIR_PAGES . $filename . '.cache.config.php';
     $menuItemTranslation = false;
     $domain = false;
     $httpStatusCode = 200;
     $executedBlocks = [];
     if (defined('GLOBAL_CACHING_ENABLED') && GLOBAL_CACHING_ENABLED && !$this->request->isXmlHttpRequest() && !$this->request->isPost() && $this->user->isAdmin() === false && is_file($cacheFilename) && is_file($cacheFilenamePhpData)) {
         include $cacheFilenamePhpData;
         if ($menuItemTranslation) {
             $menuItemTranslation = json_decode($menuItemTranslation);
             if (is_object($menuItemTranslation)) {
                 if ($this->request->isXmlHttpRequest() === false && $this->route->isHttps() === false && $menuItemTranslation->menuItem->https === true) {
                     $this->route->redirectToUrl('https://' . $this->route->getRequestRoute());
                 }
                 $this->locale->setLocale($menuItemTranslation->locale);
                 $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir);
                 $this->route->setCurrentMenuItem($menuItemTranslation->menuItem);
                 $this->route->setCurrentMenuItemTranslation($menuItemTranslation);
                 $this->route->setCurrentDomain($domain);
                 if ($this->isCachingActive($menuItemTranslation->menuItem)) {
                     $this->blockParser->setExecutedBlocks(json_decode($executedBlocks));
                     // display the cached file to the client
                     $contents = file_get_contents($cacheFilename);
                     $this->blockParser->setParseCached(true);
                     $content = $this->blockParser->parse($contents, 'outputFilter');
                     $this->response->sendHTTPStatusCode($httpStatusCode);
                     echo $this->core->includeScript($content);
                     exit;
                 }
             }
         }
     }
 }
Пример #4
0
 /**
  * @param \Fraym\Menu\Entity\MenuItemTranslation $page404
  * @return bool|void
  */
 private function render404Site(\Fraym\Menu\Entity\MenuItemTranslation $page404)
 {
     $this->setupPage($page404);
     $this->response->sendHTTPStatusCode(404);
     if ($this->request->isXmlHttpRequest() === true) {
         return false;
     }
     $this->siteManager->addAdminPanel();
     return $this->template->renderString($this->currentMenuItem->template->html);
 }