Beispiel #1
0
 public function __construct($site, $lang)
 {
     $this->code = $lang['code'];
     $this->name = $lang['name'];
     $this->locale = $lang['locale'];
     $this->default = isset($lang['default']) and $lang['default'];
     $this->url = isset($lang['url']) ? url::makeAbsolute($lang['url'], $site->url()) : url::makeAbsolute($lang['code'], $site->url());
 }
 public function __construct($path)
 {
     $this->kirby = kirby::instance();
     if (is_a($path, 'Media')) {
         parent::__construct($path->root(), $path->url());
     } else {
         parent::__construct(url::isAbsolute($path) ? null : $this->kirby->roots()->index() . DS . ltrim($path, DS), url::makeAbsolute($path));
     }
 }
Beispiel #3
0
 /**
  * Constructor
  *
  */
 public function __construct($params = array())
 {
     $this->options = array_merge($this->options, $params);
     $this->url = $this->options['url'];
     $this->depth = 0;
     $this->uri = '';
     $this->site = $this;
     $this->page = null;
     // build ugly urls if rewriting is disabled
     if ($this->options['rewrite'] === false) {
         $this->url .= '/index.php';
     }
     if (!isset($this->options['root.templates'])) {
         $this->options['root.templates'] = $this->options['root.site'] . DS . 'templates';
     }
     $this->root = $this->options['root.content'];
     $this->dirname = basename($this->root);
     // default fallback for the content folder url
     if (!isset($this->options['content.url'])) {
         $this->options['content.url'] = url::makeAbsolute('content', $this->options['url']);
     }
 }
Beispiel #4
0
 public function url()
 {
     return url::makeAbsolute($this->url, $this->site->url());
 }
 public function configure()
 {
     // load all available config files
     $root = $this->roots()->config();
     $configs = array('main' => 'config.php', 'host' => 'config.' . server::get('SERVER_NAME') . '.php', 'addr' => 'config.' . server::get('SERVER_ADDR') . '.php');
     $allowed = array_filter(dir::read($root), function ($file) {
         return substr($file, 0, 7) === 'config.' and substr($file, -4) === '.php';
     });
     foreach ($configs as $config) {
         $file = $root . DS . $config;
         if (in_array($config, $allowed, true) and file_exists($file)) {
             include_once $file;
         }
     }
     // apply the options
     $this->options = array_merge($this->options, c::$data);
     // overwrite the autodetected url
     if ($this->options['url']) {
         $this->urls->index = $this->options['url'];
     }
     // connect the url class with its handlers
     url::$home = $this->urls()->index();
     url::$to = $this->option('url.to', function ($url = '', $lang = null) {
         if (url::isAbsolute($url)) {
             return $url;
         }
         $start = substr($url, 0, 1);
         switch ($start) {
             case '#':
                 return $url;
                 break;
             case '.':
                 return page()->url() . '/' . $url;
                 break;
             default:
                 if ($page = page($url)) {
                     // use the "official" page url
                     return $page->url($lang);
                 } else {
                     // don't convert absolute urls
                     return url::makeAbsolute($url);
                 }
                 break;
         }
     });
     // setup the pagination redirect to the error page
     pagination::$defaults['redirect'] = $this->option('error');
     // setting up the email class
     email::$defaults['service'] = $this->option('email.service');
     email::$defaults['from'] = $this->option('email.from');
     email::$defaults['to'] = $this->option('email.to');
     email::$defaults['replyTo'] = $this->option('email.replyTo');
     email::$defaults['subject'] = $this->option('email.subject');
     email::$defaults['body'] = $this->option('email.body');
     email::$defaults['options'] = $this->option('email.options');
     // simple error handling
     if ($this->options['debug'] === true) {
         error_reporting(E_ALL);
         ini_set('display_errors', 1);
     } else {
         if ($this->options['debug'] === false) {
             error_reporting(0);
             ini_set('display_errors', 0);
         }
     }
 }
Beispiel #6
0
 public function configure()
 {
     // load all available config files
     $root = $this->roots()->config();
     $configs = array('main' => $root . DS . 'config.php', 'host' => $root . DS . 'config.' . server::get('HTTP_HOST') . '.php', 'addr' => $root . DS . 'config.' . server::get('SERVER_ADDR') . '.php');
     foreach ($configs as $config) {
         if (file_exists($config)) {
             include_once $config;
         }
     }
     // apply the options
     $this->options = array_merge($this->options, c::$data);
     // connect the url class with its handlers
     url::$home = $this->urls()->index();
     url::$to = $this->option('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;
         }
     });
     // setup the thumbnail generator
     thumb::$defaults['root'] = $this->roots->thumbs();
     thumb::$defaults['url'] = $this->urls->thumbs();
     thumb::$defaults['driver'] = $this->option('thumbs.driver');
     thumb::$defaults['filename'] = $this->option('thumbs.filename');
 }
Beispiel #7
0
 public function assets()
 {
     return isset($this->assets) ? $this->assets : url::makeAbsolute('assets', $this->index);
 }
Beispiel #8
0
 public function configure()
 {
     // load all available config files
     $root = $this->roots()->config();
     $configs = array('main' => 'config.php', 'host' => 'config.' . server::get('SERVER_NAME') . '.php', 'addr' => 'config.' . server::get('SERVER_ADDR') . '.php');
     $allowed = array_filter(dir::read($root), function ($file) {
         return substr($file, 0, 7) === 'config.' and substr($file, -4) === '.php';
     });
     foreach ($configs as $config) {
         $file = $root . DS . $config;
         if (in_array($config, $allowed, true) and file_exists($file)) {
             include_once $file;
         }
     }
     // apply the options
     $this->options = array_merge($this->options, c::$data);
     // overwrite the autodetected url
     if ($this->options['url']) {
         $this->urls->index = $this->options['url'];
     }
     // connect the url class with its handlers
     url::$home = $this->urls()->index();
     url::$to = $this->option('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;
         }
     });
     // setup the thumbnail generator
     thumb::$defaults['root'] = $this->roots->thumbs();
     thumb::$defaults['url'] = $this->urls->thumbs();
     thumb::$defaults['driver'] = $this->option('thumbs.driver');
     thumb::$defaults['filename'] = $this->option('thumbs.filename');
     // simple error handling
     if ($this->options['debug'] === true) {
         error_reporting(E_ALL);
         ini_set('display_errors', 1);
     } else {
         if ($this->options['debug'] === false) {
             error_reporting(0);
             ini_set('display_errors', 0);
         }
     }
 }
Beispiel #9
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;
 }