Ejemplo n.º 1
0
 public static function loadParser($pattern, \Routerunner\BaseRunner $runner = null, &$pattern_value = false)
 {
     if (strpos($pattern, ':view|list:') !== false) {
         $pattern_value = !isset($runner->model) || count($runner->model) <= 1 ? 'view' : 'list';
         if (isset($runner->model_context['force_list']) && $runner->model_context['force_list'] === true) {
             $pattern_value = 'list';
         } elseif (isset($runner->model_context['force_view']) && $runner->model_context['force_view'] === true) {
             $pattern_value = 'view';
         }
         return str_replace(':view|list:', $pattern_value . '\\.', $pattern);
     } elseif (strpos($pattern, ':lang:') !== false) {
         $pattern_value = false;
         $pattern_value = Routerunner::get('lang');
         if ($runner && isset($runner->path) && strpos($runner->path, "/backend/") === 0 && ($backend_lang_id = \runner::config('backend_language'))) {
             if (is_numeric($backend_lang_id) && ($pattern_result = \db::query('SELECT code FROM `{PREFIX}lang` WHERE id = ?', array($backend_lang_id)))) {
                 $pattern_value = $pattern_result[0]['code'];
             } else {
                 $pattern_value = $backend_lang_id;
             }
         } elseif ((!isset($pattern_value) || !$pattern_value) && ($lang_id = \runner::config('language'))) {
             if ($pattern_result = \db::query('SELECT code FROM `{PREFIX}lang` WHERE id = ?', array($lang_id))) {
                 $pattern_value = $pattern_result[0]['code'];
             }
         }
         if ($pattern_value) {
             $pattern_value .= '.';
         }
         return str_replace(':lang:', $pattern_value, $pattern);
     } elseif (strpos($pattern, ':owner:') !== false) {
         $me = \user::me();
         $uid = (int) $me;
         $pattern_value = '';
         // todo: rework to list models to use listitem's owner & group
         $model = is_array($runner->model) && isset($runner->model[0]) ? $runner->model[0] : $runner->model;
         $owner = isset($model, $model->owner) ? $model->owner : (isset($runner->owner) ? $runner->owner : false);
         if ($owner !== false && $owner === $uid) {
             $pattern_value = 'owner';
         }
         return !$pattern_value ? '' : str_replace(':owner:', $pattern_value . '\\.', $pattern);
     } elseif (strpos($pattern, ':group:') !== false) {
         $email = null;
         $name = null;
         $group = null;
         \user::me($email, $name, $group);
         $gid = (int) $group;
         $pattern_value = '';
         // todo: rework to list models to use listitem's owner & group
         $model = is_array($runner->model) && isset($runner->model[0]) ? $runner->model[0] : $runner->model;
         $group = isset($model, $model->group) ? $model->group : (isset($runner->group) ? $runner->group : false);
         if ($group !== false && $group === $gid) {
             $pattern_value = 'group';
         }
         return !$pattern_value ? '' : str_replace(':group:', $pattern_value . '\\.', $pattern);
     } elseif (strpos($pattern, ':owner|group:') !== false) {
         $email = null;
         $name = null;
         $group = null;
         $me = \user::me($email, $name, $group);
         $uid = (int) $me;
         $gid = (int) $group;
         $pattern_value = '';
         // todo: rework to list models to use listitem's owner & group
         $model = is_array($runner->model) && isset($runner->model[0]) ? $runner->model[0] : $runner->model;
         $owner = isset($model, $model->owner) ? $model->owner : (isset($runner->owner) ? $runner->owner : false);
         $group = isset($model, $model->group) ? $model->group : (isset($runner->group) ? $runner->group : false);
         if ($owner !== false && $owner === $uid && $group !== false && $group === $gid) {
             $pattern_value = 'owner|group';
         } elseif ($owner !== false && $owner === $uid) {
             $pattern_value = 'owner';
         } elseif ($group !== false && $group === $gid) {
             $pattern_value = 'group';
         }
         return !$pattern_value ? '' : str_replace(':owner|group:', $pattern_value . '\\.', $pattern);
     } elseif (strpos($pattern, ':group|owner:') !== false) {
         $email = null;
         $name = null;
         $group = null;
         $me = \user::me($email, $name, $group);
         $uid = (int) $me;
         $gid = (int) $group;
         $pattern_value = '';
         // todo: rework to list models to use listitem's owner & group
         $model = is_array($runner->model) && isset($runner->model[0]) ? $runner->model[0] : $runner->model;
         $owner = isset($model, $model->owner) ? $model->owner : (isset($runner->owner) ? $runner->owner : false);
         $group = isset($model, $model->group) ? $model->group : (isset($runner->group) ? $runner->group : false);
         if ($group !== false && $group === $gid) {
             $pattern_value = 'group';
         } elseif ($owner !== false && $owner === $uid) {
             $pattern_value = 'owner';
         }
         return !$pattern_value ? '' : str_replace(':group|owner:', $pattern_value . '\\.', $pattern);
     } elseif (strpos($pattern, ':request:') !== false) {
         $pattern_value = Routerunner::get('request');
         return str_replace(':request:', $pattern_value . '\\.', $pattern);
     } else {
         $pattern_value = $pattern;
         return $pattern . '\\.';
     }
 }
 /**
  * Constructor
  * @param  array $arguments Associative array of application settings
  */
 public function __construct($arguments = null, $function = null)
 {
     if (ini_get('xdebug.max_nesting_level')) {
         ini_set('xdebug.max_nesting_level', 200);
     }
     if (!isset($_SESSION["runner"]) && is_array($arguments)) {
         Routerunner::setRunnerParams($arguments);
     }
     if (!self::$loaded) {
         require 'BaseClasses' . DIRECTORY_SEPARATOR . 'BaseRunner.php';
         require 'BaseClasses' . DIRECTORY_SEPARATOR . 'BaseModel.php';
         require 'BaseClasses' . DIRECTORY_SEPARATOR . 'BaseBootstrap.php';
         require 'Tunnel.php';
         require 'Slim' . DIRECTORY_SEPARATOR . 'Slim.php';
         require 'Slim' . DIRECTORY_SEPARATOR . 'RunnerSlim.php';
         \Slim\RunnerSlim::registerAutoloader();
         require 'SlimView.php';
         require_once 'phpquery' . DIRECTORY_SEPARATOR . 'phpQuery.php';
     }
     self::$loaded = true;
     if (isset($arguments) && is_array($arguments)) {
         $this->container['settings'] = array_merge(static::getDefaultSettings(), $arguments);
     } else {
         $this->container['settings'] = static::getDefaultSettings();
     }
     if (isset($_SESSION["routerunner-config"])) {
         $this->container['settings'] = array_merge($_SESSION["routerunner-config"], $this->container['settings']);
     }
     if (isset($this->settings['DOCUMENT_ROOT'])) {
         $site_root = $this->settings['DOCUMENT_ROOT'];
         if (substr($site_root, -1) !== DIRECTORY_SEPARATOR) {
             $site_root .= DIRECTORY_SEPARATOR;
         }
     } else {
         $site_root = rtrim(isset($_SERVER["DOCUMENT_ROOT"]) ? $_SERVER["DOCUMENT_ROOT"] : $this->settings['DOCUMENT_ROOT'], '/\\') . DIRECTORY_SEPARATOR . $this->settings['SITEROOT'];
         if (substr($site_root, -1) !== DIRECTORY_SEPARATOR) {
             $site_root .= DIRECTORY_SEPARATOR;
         }
     }
     $this->container['settings']['SITEROOT'] = $site_root;
     if (!function_exists("backend_mode")) {
         require $site_root . 'runner-config.php';
     }
     Routerunner::$static = $this;
     \Routerunner\Db::initialize($this->settings);
     new \Routerunner\Helper($this);
     \Routerunner\Routerunner::$slim = new \Slim\RunnerSlim(array('view' => new \Routerunner\CustomView(), 'templates.path' => \Routerunner\Helper::$scaffold_class));
     \Routerunner\Routerunner::$slim->notFound(function () {
         return false;
     });
     $method = "get";
     $resource = "/";
     if (!isset($arguments["bootstrap"]) || $arguments["bootstrap"] !== false) {
         \Routerunner\Bootstrap::initialize($this->settings, false);
         $method = \Routerunner\Bootstrap::getMethod();
         $resource = \Routerunner\Bootstrap::getResource();
     }
     if (isset($arguments["method"])) {
         $method = $arguments["method"];
     }
     if (isset($arguments["resource"])) {
         $resource = $arguments["resource"];
     }
     if ($method == "head") {
         $method = "get";
     }
     $routerunner_object = $this;
     \Routerunner\Config::custom_config($this->container['settings']);
     \runner::config("notFound", false);
     if (\Routerunner\Bootstrap::$component) {
         return false;
         exit;
     }
     if (isset($arguments) && isset($function) && !is_string($function) && is_callable($function) && \Routerunner\Routerunner::$slim->now('redirect_url')) {
         $arguments["skip_redirect"] = true;
         $arguments["skip_route"] = true;
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         }, $function, function () {
             if (\Routerunner\Routerunner::$slim->now('redirect_url')) {
                 \Routerunner\Routerunner::$slim->redirect(\Routerunner\Routerunner::$slim->now('redirect_url'));
             }
         });
         \Routerunner\Routerunner::$slim->run();
     } elseif (isset($arguments) && isset($function) && !is_string($function) && is_callable($function)) {
         $arguments["skip_redirect"] = true;
         $arguments["skip_route"] = true;
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         }, $function);
         \Routerunner\Routerunner::$slim->notFound(function () use($routerunner_object, $arguments) {
             \runner::config("notFound", true);
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->run();
     } elseif (isset($arguments) && is_array($arguments) && isset($arguments['root'])) {
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->notFound(function () use($routerunner_object, $arguments) {
             \runner::config("notFound", true);
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->run();
     } elseif (!is_string($arguments) && is_callable($arguments)) {
         $function = $arguments;
         $arguments = array("skip_redirect" => true, "skip_route" => true);
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         }, $function, function () {
             if (\Routerunner\Routerunner::$slim->now('redirect_url')) {
                 $this->redirect(\Routerunner\Routerunner::$slim->now('redirect_url'));
             }
         });
         \Routerunner\Routerunner::$slim->notFound(function () use($routerunner_object, $arguments) {
             \runner::config("notFound", true);
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->run();
     } else {
         $arguments = array("skip_redirect" => true, "skip_route" => true);
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->notFound(function () use($routerunner_object, $arguments) {
             \runner::config("notFound", true);
             $this->middleware($routerunner_object, $arguments);
         });
     }
 }