Exemplo n.º 1
0
 public function __construct($kirby, $dir)
 {
     static::$instance = $this;
     $this->kirby = $kirby;
     $this->site = $kirby->site();
     $this->roots = new Panel\Roots($dir);
     $this->urls = new Panel\Urls($kirby->urls()->index() . '/' . basename($dir));
     $this->load();
     // load all available routes
     $this->routes = array_merge($this->routes, require $this->roots->routes . DS . 'api.php');
     $this->routes = array_merge($this->routes, require $this->roots->routes . DS . 'views.php');
     // setup the blueprint root
     blueprint::$root = $this->kirby->roots()->blueprints();
     // setup the form plugin
     form::setup($this->roots->fields, $this->kirby->roots()->fields());
     // start the router
     $this->router = new Router($this->routes);
     // register router filters
     $this->router->filter('auth', function () use($kirby) {
         $user = $kirby->site()->user();
         if (!$user or !$user->hasPanelAccess()) {
             if ($user) {
                 $user->logout();
             }
             go('panel/login');
         }
     });
     // check for a completed installation
     $this->router->filter('isInstalled', function () use($kirby) {
         if ($kirby->site()->users()->count() == 0) {
             go('panel/install');
         }
     });
 }
Exemplo n.º 2
0
 public static function configure()
 {
     if (is_null(static::$site)) {
         static::$site = kirby::panelsetup();
     }
     // load all available routes
     static::$routes = array_merge(static::$routes, require root('panel.app.routes') . DS . 'api.php');
     static::$routes = array_merge(static::$routes, require root('panel.app.routes') . DS . 'views.php');
     // setup the blueprint root
     blueprint::$root = c::get('root.site') . DS . 'blueprints';
     // start the router
     static::$router = new Router();
     static::$router->register(static::$routes);
     // content language switcher variable
     if (static::$site->multilang()) {
         if ($language = server::get('http_language') or $language = s::get('lang')) {
             static::$site->visit('/', $language);
         }
         app::$language = static::$site->language()->code();
         s::set('lang', app::$language);
     }
     // load the interface language file
     if (static::$site->user()) {
         $languageCode = static::$site->user()->language();
     } else {
         $languageCode = c::get('panel.language', 'en');
     }
     // validate the language code
     if (!in_array($languageCode, static::languages()->keys())) {
         $languageCode = 'en';
     }
     // store the interface language
     app::$interfaceLanguage = $languageCode;
     $language = (require root('panel.app.languages') . DS . $languageCode . '.php');
     // set all language variables
     l::$data = $language['data'];
     // register router filters
     static::$router->filter('auth', function () {
         if (!app::$site->user()) {
             go('panel/login');
         }
     });
     // check for a completed installation
     static::$router->filter('isInstalled', function () {
         if (app::$site->users()->count() == 0) {
             go('panel/install');
         }
     });
     // only use the fragments of the path without params
     static::$path = implode('/', (array) url::fragments(detect::path()));
 }