Example #1
0
 public function testConstruction()
 {
     $kirby = $this->kirbyInstance();
     $site = $this->siteInstance($kirby);
     $page = new Page($site, '1-a');
     $this->assertInstanceOf('Kirby', $page->kirby());
     $this->assertEquals($kirby, $page->kirby());
     $this->assertInstanceOf('Site', $page->site());
     $this->assertEquals($site, $page->site());
     $this->assertInstanceOf('Site', $page->parent());
     $this->assertEquals($site, $page->parent());
     $this->assertEquals('1-a', $page->dirname());
     $this->assertEquals(1, $page->depth());
     $this->assertEquals($kirby->roots()->content() . DS . '1-a', $page->root());
     $this->assertEquals('1', $page->num());
     $this->assertEquals('a', $page->uid());
     $this->assertEquals('a', $page->id());
     $this->assertEquals('1-a', $page->diruri());
     $this->assertEquals('/a', $page->url());
     $this->assertTrue($page->isCachable());
     $this->assertEquals('a', $page->slug());
     $this->assertTrue($page->is($page));
     $this->assertTrue($page->equals($page));
     $this->assertFalse($page->isSite());
     $this->assertFalse($page->isActive());
     $this->assertFalse($page->isOpen());
     $this->assertTrue($page->isVisible());
     $this->assertFalse($page->isInvisible());
     $this->assertFalse($page->isHomePage());
     $this->assertFalse($page->isErrorPage());
     $this->assertEquals($page->id(), (string) $page);
 }
Example #2
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);
 }