コード例 #1
0
ファイル: Request.php プロジェクト: andelux/landingpages
 public function getCacheResponse()
 {
     // If cache is disabled
     if (!Mvc::getConfig()->getData('app.cache', true)) {
         return null;
     }
     // If POST no cache
     if (count($_POST) > 0) {
         return null;
     }
     // Get cache response
     $response = new Cache();
     return $response->hasCache() ? $response : null;
 }
コード例 #2
0
ファイル: Response.php プロジェクト: andelux/landingpages
 public function exec()
 {
     // Download binary file
     if ($this->_binary_file) {
         // Send headers
         $this->_sendHeaders();
         // Send file
         readfile($this->_binary_file);
         exit;
     }
     // 404? (without template)
     if (!$this->_template || !Template::exists($this->_template) && $this->_template != '_404') {
         $this->setData('cache.excluded', true);
         $this->_template = '_404';
     }
     // Output
     timer('start', 'template_parse');
     ob_start();
     Template::parse($this->_template, $this->_data);
     $content = ob_get_clean();
     $content = Event::filter('content', $content);
     timer('end', 'template_parse');
     // If not excluding cache, then save cache
     if (!$this->getData('cache.excluded')) {
         Cache::factory()->save($this->_headers, $content, $this->getData('page_ttl'));
     }
     // Send headers
     $this->_sendHeaders();
     // Send content
     echo Event::filter('cache', $content);
 }
コード例 #3
0
ファイル: Mvc.php プロジェクト: andelux/landingpages
 public function __construct($root_dir)
 {
     global $MVC;
     $MVC = $this;
     $root_dir = realpath($root_dir);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // 1. Config
     $this->config = new Config($root_dir . '/etc/config.ini');
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // 2. Setup
     $this->session = new Session();
     require $root_dir . '/functions.php';
     define('LP_DEBUG', $this->config->getData('app.debug', false) ? true : false);
     timer('start', 'init');
     define('LP_ROOT_DIRECTORY', $root_dir);
     define('LP_APP_DIRECTORY', "{$root_dir}/app/{$this->config->getData('app.name', 'default')}");
     define('LP_DEFAULT_APP_DIRECTORY', "{$root_dir}/app/default");
     // /landingpages/
     $document_root = realpath($_SERVER['DOCUMENT_ROOT']);
     $base_uri = trim(substr($root_dir, strlen($document_root)), '/');
     define('LP_BASE_URI', str_replace('//', '/', "/{$base_uri}/"));
     define('LP_APP_URI', LP_BASE_URI . "app/{$this->config->getData('app.name', 'default')}/");
     define('LP_DEFAULT_APP_URI', LP_BASE_URI . "app/default/");
     // Ex: http://localhost/landingpages/example-simple-v1.html
     $uri = trim(array_shift(explode('?', $_SERVER['REQUEST_URI'])), '/');
     if (preg_match('/^(.*)\\/index\\.php$/', $uri, $M)) {
         $uri = $M[1];
     }
     define('LP_URL', "http://{$_SERVER['SERVER_NAME']}/{$uri}");
     define('LP_BASE_URL', "http://{$_SERVER['SERVER_NAME']}" . LP_BASE_URI);
     // Ex: example-simple-v1.html
     $uri = trim(substr($uri, strlen($base_uri)), '/');
     define('LP_URI', $uri);
     // languages
     if (!$this->config->issetData('locale.detect_methods')) {
         $this->config->setData('locale.detect_methods', 'url,domain,geoip,browser');
     }
     if (!$this->config->issetData('locale.enabled')) {
         $this->config->setData('locale.enabled', 'en_US,en_GB');
     }
     if (!$this->config->issetData('locale.default')) {
         $this->config->setData('locale.default', array_shift(explode(',', $this->config->getData('locale.enabled'))));
     }
     // Database
     if (!$this->config->issetData('database')) {
         $this->config->setData('database', 'sqlite:' . LP_ROOT_DIRECTORY . '/var/general.db');
     }
     Response::init();
     Response\Cache::init();
     Block::init();
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // 3. Request
     $this->request = new Request();
     $this->request->setRootDirectory(LP_ROOT_DIRECTORY);
     $this->request->setUrl(LP_URL);
     $this->request->setBaseUri(LP_BASE_URI);
     $this->request->setUri(LP_URI);
     $this->request->setSession($this->session);
     $this->request->setConfig($this->config);
     if (!($this->response = $this->request->getCacheResponse())) {
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         // 4. Router
         $this->router = new Router($this->request);
         $token = $this->router->getToken();
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         // 5. Dispatcher
         $this->dispatcher = new Dispatcher($this->request);
         if (!$token || !$this->dispatcher->isDispatchable($token)) {
             $token = array('error', '404', array('uri' => LP_URI));
         }
         // We have a token to dispatch
         $this->dispatcher->addToken($token);
         // Dispatch tokens and get the final response
         /** @var Response $response */
         $this->response = $this->dispatcher->doLoop();
     }
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // 6. Response
     $this->response->exec();
     timer('end', 'init');
     timer('print');
 }