public function __construct($options = array())
 {
     $this->roots = new Roots(dirname(__DIR__));
     $this->urls = new Urls();
     $this->options = array_merge($this->defaults(), $options);
     $this->path = implode('/', (array) url::fragments(detect::path()));
     // make sure the instance is stored / overwritten
     static::$instance = $this;
 }
Example #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()));
 }
Example #3
0
 /**
  * Iterate through every route to find a matching route.
  *
  * @param  string $path Optional path to match against
  * @return Route
  */
 public function run($path = null)
 {
     $method = r::method();
     $ajax = r::ajax();
     $https = r::ssl();
     $routes = a::get($this->routes, $method, array());
     // detect path if not set manually
     if ($path === null) {
         $path = implode('/', (array) url::fragments(detect::path()));
     }
     // empty urls should never happen
     if (empty($path)) {
         $path = '/';
     }
     foreach ($routes as $route) {
         if ($route->https and !$https) {
             continue;
         }
         if ($route->ajax and !$ajax) {
             continue;
         }
         // handle exact matches
         if ($route->pattern == $path) {
             $this->route = $route;
             break;
         }
         // We only need to check routes with regular expression since all others
         // would have been able to be matched by the search for literal matches
         // we just did before we started searching.
         if (strpos($route->pattern, '(') === false) {
             continue;
         }
         $preg = '#^' . $this->wildcards($route->pattern) . '$#u';
         // If we get a match we'll return the route and slice off the first
         // parameter match, as preg_match sets the first array item to the
         // full-text match of the pattern.
         if (preg_match($preg, $path, $parameters)) {
             $this->route = $route;
             $this->route->arguments = array_slice($parameters, 1);
             break;
         }
     }
     if ($this->route and $this->filterer($this->route->filter) !== false) {
         return $this->route;
     } else {
         return null;
     }
 }
Example #4
0
 /**
  * The path which will be used for the router
  *
  * @return string
  */
 public static function path()
 {
     return implode('/', (array) url::fragments(detect::path()));
 }