Example #1
0
 /**
  * Renders the HTML for the page or fetches it from the cache
  *
  * @param Page $page
  * @param boolean $headers
  * @return string
  */
 public function render(Page $page, $data = array(), $headers = true)
 {
     // register the currently rendered page
     $this->page = $page;
     // send all headers for the page
     if ($headers) {
         $page->headers();
     }
     // configure pagination urls
     $query = (string) $this->request()->query();
     $params = (string) $this->request()->params() . r($query, '?') . $query;
     pagination::$defaults['url'] = $page->url() . r($params, '/') . $params;
     // cache the result if possible
     if ($this->options['cache'] and $page->isCachable()) {
         // try to read the cache by cid (cache id)
         $cacheId = md5(url::current());
         // check for modified content within the content folder
         // and auto-expire the page cache in such a case
         if ($this->options['cache.autoupdate'] and $this->cache()->exists($cacheId)) {
             // get the creation date of the cache file
             $created = $this->cache()->created($cacheId);
             // make sure to kill the cache if the site has been modified
             if ($this->site->wasModifiedAfter($created)) {
                 $this->cache()->remove($cacheId);
             }
         }
         // try to fetch the template from cache
         $template = $this->cache()->get($cacheId);
         // fetch fresh content if the cache is empty
         if (empty($template)) {
             $template = $this->template($page, $data);
             // store the result for the next round
             $this->cache()->set($cacheId, $template);
         }
         return $template;
     }
     // return a fresh template
     return $this->template($page, $data);
 }
Example #2
0
 /**
  * Renders the HTML for the page or fetches it from the cache
  *
  * @param Page $page
  * @param boolean $headers
  * @return string
  */
 public static function render(Page $page, $data = array(), $headers = true)
 {
     // register the currently rendered page
     static::$page = $page;
     // send all headers for the page
     if ($headers) {
         $page->headers();
     }
     // load all language variables
     static::localize();
     // if the cache is activated…
     if (c::$data['cache']) {
         // return the page from cache
         return static::cache($page, $data);
     } else {
         // render the template
         return static::template($page, $data);
     }
 }