Example #1
0
 /**
  * Constructor
  *
  */
 public function __construct(Kirby $kirby)
 {
     $this->kirby = $kirby;
     $this->url = $kirby->urls()->index();
     $this->depth = 0;
     $this->uri = '';
     $this->site = $this;
     $this->page = null;
     // build ugly urls if rewriting is disabled
     if ($this->kirby->options['rewrite'] === false) {
         $this->url .= '/index.php';
     }
     $this->root = $kirby->roots()->content();
     $this->dirname = basename($this->root);
 }
Example #2
0
 public function testAutoloading()
 {
     $kirby = new Kirby(array('debug' => true));
     $kirby->roots->content = TEST_ROOT_ETC . DS . 'content';
     $kirby->roots->site = TEST_ROOT_ETC . DS . 'site';
     // autoload all models
     $kirby->models();
     $site = new Site($kirby);
     $a = $site->find('a');
     $this->assertInstanceOf('Page', $a);
     $this->assertInstanceOf('APage', $a);
     $this->assertEquals('test', $a->customTestMethod());
     $b = $site->find('b');
     $this->assertInstanceOf('Page', $b);
     $this->assertFalse(is_a($b, 'APage'));
     $this->assertFalse('test' == $b->customTestMethod());
 }
Example #3
0
 /**
  * Get files based on types option
  *
  * @since 1.0.0
  *
  * @return \Files
  */
 public function files()
 {
     /**
      * FIX: When used in site options, we don't have a `$this->page`
      * property we can use to access the pages files.
      *
      * (1) If we have page property, we'll use that to fetch the files.
      * (2) If we don't have a page property we're on the site options page.
      *     (2.1) If we're using Kirby 2.1+ we can use the new `site()->files()`
      *           method to get access to the new global site files to use them.
      *     (2.2) If we are using a lower version, global site files don't
      *           exist. We'll return an empty collection object instead.
      *
      * @since 1.3.0
      */
     if (!is_null($this->page)) {
         /* (1) */
         $files = $this->page->files();
         /* (1) */
     } else {
         /* (2) */
         if (version_compare(Kirby::version(), '2.1', '>=')) {
             /* (2.1) */
             $files = site()->files();
             /* (2.1) */
         } else {
             return new Collection();
             /* (2.2) */
         }
     }
     /**
      * FIX: Create a new reference to $this to overcome the unavailability
      * of $this within closures in PHP < 5.4.0 by passing this new reference
      * with the "use" language construct.
      *
      * @since 1.0.1
      */
     $field =& $this;
     $files = $files->sortBy($this->sort, $this->flip ? 'desc' : 'asc')->filter(function ($file) use($field) {
         return $field->includeAllFiles() or in_array($file->type(), $field->types);
     });
     /**
      * Filter files using a regular expression.
      *
      * @since 1.4.0
      */
     if ($this->isRegExp($this->filter)) {
         $files = $files->filter(function ($file) use($field) {
             return preg_match($this->filter, $file->filename()) === 1;
         });
     } elseif ($this->filter) {
         $files = $files->filterBy('filename', '*=', $this->filter);
     }
     return $files;
 }
Example #4
0
 public function files()
 {
     if (!is_null($this->page)) {
         $files = $this->page->files();
     } else {
         if (version_compare(Kirby::version(), '2.1', '>=')) {
             $files = site()->files();
         } else {
             return new Collection();
         }
     }
     return $files;
 }
Example #5
0
 /**
  * Get files based on types option
  *
  * @since 1.0.0
  *
  * @return \Files
  */
 public function files()
 {
     /**
      * FIX: When used in site options, we don't have a `$this->page`
      * property we can use to access the pages files.
      *
      * (1) If we have page property, we'll use that to fetch the files.
      * (2) If we don't have a page property we're on the site options page.
      *     (2.1) If we're using Kirby 2.1+ we can use the new `site()->files()`
      *           method to get access to the new global site files to use them.
      *     (2.2) If we are using a lower version, global site files don't
      *           exist. We'll return an empty collection object instead.
      *
      * @since 1.3.0
      */
     if (!is_null($this->page)) {
         /* (1) */
         $files = $this->page->files();
         /* (1) */
     } else {
         /* (2) */
         if (version_compare(Kirby::version(), '2.1', '>=')) {
             /* (2.1) */
             $files = site()->files();
             /* (2.1) */
         } else {
             return new Collection();
             /* (2.2) */
         }
     }
     return $files;
 }