Exemple #1
0
 public function __construct($dir = null)
 {
     $this->dir = $dir ? $dir : kirby()->roots()->cache();
     if (!file_exists($this->dir)) {
         mkdir($this->dir);
     }
     $this->Cache = cache::setup('file', array('root' => $this->dir));
 }
Exemple #2
0
 public function __construct($query)
 {
     $this->query = trim($query);
     $this->pages = new Collection();
     $this->users = new Collection();
     // temporary disable the search cache
     $this->cache = cache::setup('mock');
     // try {
     //   $root = kirby()->roots()->cache() . DS . 'search';
     //   dir::make($root);
     //   $this->cache = cache::setup('file', array('root' => $root));
     // } catch(Exception $e) {
     //   $this->cache = cache::setup('session');
     // }
     $this->run();
 }
 /**
  * Cache setup
  *
  * @return Cache
  */
 public function cache()
 {
     if (!is_null($this->cache)) {
         return $this->cache;
     }
     // cache setup
     if ($this->options['cache']) {
         if ($this->options['cache.driver'] == 'file' and empty($this->options['cache.options'])) {
             $this->options['cache.options'] = array('root' => $this->roots()->cache());
         }
         return $this->cache = cache::setup($this->options['cache.driver'], $this->options['cache.options']);
     } else {
         return $this->cache = cache::setup('mock');
     }
 }
Exemple #4
0
 /**
  * Sets all defaults and loads the user configuration
  *
  * @param array $config
  */
 protected static function configure($config = array())
 {
     // start with a fresh configuration
     c::$data = array();
     // set some defaults
     c::$data['root'] = dirname(__DIR__);
     c::$data['root.kirby'] = __DIR__;
     c::$data['root.content'] = c::$data['root'] . DS . 'content';
     c::$data['root.site'] = c::$data['root'] . DS . 'site';
     // the default timezone
     c::$data['timezone'] = 'UTC';
     // tinyurl handling
     c::$data['tinyurl.enabled'] = true;
     c::$data['tinyurl.folder'] = 'x';
     // disable the cache by default
     c::$data['cache'] = false;
     c::$data['cache.driver'] = 'file';
     c::$data['cache.options'] = array();
     // set the default license code
     c::$data['license'] = null;
     // url rewriting
     c::$data['rewrite'] = true;
     // markdown defaults
     c::$data['markdown'] = true;
     c::$data['markdown.extra'] = false;
     c::$data['markdown.breaks'] = true;
     // pass the config vars from the constructor
     // to be able to set all roots
     c::$data = array_merge(c::$data, $config);
     // set the subroots for site
     c::$data['root.cache'] = c::$data['root.site'] . DS . 'cache';
     c::$data['root.plugins'] = c::$data['root.site'] . DS . 'plugins';
     c::$data['root.templates'] = c::$data['root.site'] . DS . 'templates';
     c::$data['root.snippets'] = c::$data['root.site'] . DS . 'snippets';
     c::$data['root.controllers'] = c::$data['root.site'] . DS . 'controllers';
     c::$data['root.config'] = c::$data['root.site'] . DS . 'config';
     c::$data['root.tags'] = c::$data['root.site'] . DS . 'tags';
     c::$data['root.accounts'] = c::$data['root.site'] . DS . 'accounts';
     // auto css and js setup
     c::$data['auto.css.url'] = 'assets/css/templates';
     c::$data['auto.css.root'] = c::$data['root'] . DS . 'assets' . DS . 'css' . DS . 'templates';
     c::$data['auto.js.url'] = 'assets/js/templates';
     c::$data['auto.js.root'] = c::$data['root'] . DS . 'assets' . DS . 'js' . DS . 'templates';
     // load all available config files
     $configs = array('main' => c::$data['root.config'] . DS . 'config.php', 'host' => c::$data['root.config'] . DS . 'config.' . server::get('HTTP_HOST') . '.php', 'addr' => c::$data['root.config'] . DS . 'config.' . server::get('SERVER_ADDR') . '.php');
     foreach ($configs as $confile) {
         if (file_exists($confile)) {
             include_once $confile;
         }
     }
     // pass the config vars from the constructor again to overwrite
     // stuff from the user config
     c::$data = array_merge(c::$data, $config);
     // detect and store the url
     static::url();
     // default url handler
     if (empty(c::$data['url.to'])) {
         c::$data['url.to'] = function ($url = '') {
             if (url::isAbsolute($url)) {
                 return $url;
             }
             $start = substr($url, 0, 1);
             switch ($start) {
                 case '#':
                     return $url;
                     break;
                 case '.':
                     return page()->url() . '/' . $url;
                     break;
                 default:
                     // don't convert absolute urls
                     return url::makeAbsolute($url);
                     break;
             }
         };
     }
     // connect the url class with its handlers
     url::$home = c::$data['url'];
     url::$to = c::$data['url.to'];
     // setup the thumbnail generator
     thumb::$defaults['root'] = isset(c::$data['thumb.root']) ? c::$data['thumb.root'] : c::$data['root'] . DS . 'thumbs';
     thumb::$defaults['url'] = isset(c::$data['thumb.url']) ? c::$data['thumb.url'] : 'thumbs';
     thumb::$defaults['driver'] = isset(c::$data['thumb.driver']) ? c::$data['thumb.driver'] : 'gd';
     thumb::$defaults['filename'] = isset(c::$data['thumb.filename']) ? c::$data['thumb.filename'] : '{safeName}-{hash}.{extension}';
     // build absolute urls
     c::$data['auto.css.url'] = url::makeAbsolute(c::$data['auto.css.url'], url::$home);
     c::$data['auto.js.url'] = url::makeAbsolute(c::$data['auto.js.url'], url::$home);
     thumb::$defaults['url'] = url::makeAbsolute(thumb::$defaults['url'], url::$home);
     // cache setup
     if (c::$data['cache']) {
         if (c::$data['cache.driver'] == 'file' and empty(c::$data['cache.options'])) {
             c::$data['cache.options'] = array('root' => c::get('root.cache'));
         }
         cache::setup(c::$data['cache.driver'], c::$data['cache.options']);
     } else {
         cache::setup('mock');
     }
     // set the timezone for all date functions
     date_default_timezone_set(c::$data['timezone']);
     // return the entire config array
     return c::$data;
 }