Example #1
0
 public function __construct($kirby, $root)
 {
     // check requirements
     $this->requirements();
     // store the instance as a singleton
     static::$instance = $this;
     $this->kirby = $kirby;
     $this->roots = new \Kirby\Panel\Roots($this, $root);
     $this->urls = new \Kirby\Panel\Urls($this, $root);
     // add the panel default options
     $this->kirby->options = array_merge($this->defaults(), $this->kirby->options);
     // setup the blueprints roots
     UserBlueprint::$root = $this->kirby->roots()->blueprints() . DS . 'users';
     PageBlueprint::$root = $this->kirby->roots()->blueprints();
     // load the site object
     $this->site = $this->site();
     // setup the session
     $this->session();
     // setup the multilang site stuff
     $this->multilang();
     // load all Kirby extensions (methods, tags, smartypants)
     $this->kirby->extensions();
     $this->kirby->plugins();
     // setup the form plugin
     form::$root = array('default' => $this->roots->fields, 'custom' => $this->kirby->roots()->fields());
     // force ssl if set in config
     if ($this->kirby->option('ssl') and !r::secure()) {
         // rebuild the current url with https
         go(url::build(array('scheme' => 'https')));
     }
     // load all available routes
     $this->routes = array_merge($this->routes, require $this->roots->config . DS . 'routes.php');
     // start the router
     $this->router = new Router($this->routes);
     // register router filters
     $this->router->filter('auth', function () use($kirby) {
         try {
             $user = panel()->user();
         } catch (Exception $e) {
             panel()->redirect('login');
         }
     });
     // check for a completed installation
     $this->router->filter('isInstalled', function () use($kirby) {
         $installer = new Installer();
         if (!$installer->isCompleted()) {
             panel()->redirect('install');
         }
     });
     // check for valid csrf tokens. Can be used for get requests
     // since all post requests are blocked anyway
     $this->router->filter('csrf', function () {
         panel()->csrfCheck();
     });
     // csrf protection for every post request
     if (r::is('post')) {
         $this->csrfCheck();
     }
 }