public function route_parser() { foreach ($this->load as $load) { $this->section = array(); $file = ''; if (isset($this->model, $this->model->permission) && is_array($this->model->permission)) { $this->permission = $this->model->permission; } if (is_array($load)) { \Routerunner\Helper::loadParser($load[0], $this, $parsed_section); if (isset($this->files[$parsed_section])) { if (!is_array($this->files[$parsed_section])) { $files = array($this->files[$parsed_section]); } else { $files = $this->files[$parsed_section]; } $regexp = str_replace('~', '', trim($this->route, DIRECTORY_SEPARATOR) . '\\.'); foreach ($load as $section) { $parsed = \Routerunner\Helper::loadParser($section, $this, $parsed_value); if ($parsed_value) { $regexp .= $parsed; } $this->section[] = $parsed_value; $files = preg_grep('/\\b' . $regexp . '/', $files); } $files = preg_grep('/^' . $regexp . '$/', $files); if (count($files) == 1) { $file = array_shift($files); } elseif (count($files) > 1) { $file = array_shift($files); while ($file_row = array_shift($files)) { if (strlen($file_row) > strlen($file)) { $file = $file_row; } } } else { // exception: no file match } } } elseif (isset($this->files[$load])) { $this->section[] = $load; $file = $this->route . '.' . $load; } if ($file) { if (!$this->readable()) { $debug = 1; } if ($this->readable() && ($this->section[0] == 'view' || $this->section[0] == 'list')) { if (\runner::config('mode') != 'backend' && $this->router->cache_route && ($html = $this->router->get_cache($_model))) { if (\runner::config('silent')) { $html = str_replace(array("\t", PHP_EOL . PHP_EOL), "", $html); } $this->html = $html; if ($_model) { $this->model = $_model; } return true; } \model::stack(); Routerunner::$context = $this->context; \Routerunner\Helper::prepareLoader($this->route, $file, $this->version, $path, $class, false, false, $this->router); $this->view = $class; if (isset($this->model) && $this->model === false) { // todo: check view permission $this->render(); } elseif (isset($this->model) && count($this->model) == 1 && ($this->section[0] != 'list' || isset($this->model_context['force_view']) && $this->model_context['force_view'] === true)) { if (is_array($this->model)) { $this->model = array_shift($this->model); } if (!$this->model->readable()) { $debug = 1; } if ($this->model->readable()) { $explode = explode('\\', get_class($this->model)); if ($explode[0] != "backend") { \model::object($this->model); } $this->render(); } } elseif (isset($this->model)) { $models = $this->model; if (!is_array($models)) { $models = array($models); } $this->render_list($models); $this->model = $models; } elseif (!isset($this->model) && isset($this->files['list']) && is_array($this->files['list']) && in_array(trim($this->route, '/\\') . '.list.null.', $this->files['list'])) { $this->render_null(); } elseif (!isset($this->model) && (isset($this->model_context['force_view']) && $this->model_context['force_view'] === true) && isset($this->files['view']) && is_array($this->files['view']) && in_array(trim($this->route, '/\\') . '.view.null.', $this->files['view'])) { $this->render_null(); } elseif (!isset($this->model) && (isset($this->model_context['force_view']) && $this->model_context['force_view'] === true)) { $this->render(); } \model::unstack(); } elseif ($this->section[0] == 'event' && ($this->section[count($this->section) - 1] == 'before' || $this->section[count($this->section) - 1] == 'after' || $this->section[count($this->section) - 1] == 'load')) { if ($this->section[count($this->section) - 1] == 'before') { $this->event_before = $file; } elseif ($this->section[count($this->section) - 1] == 'after') { $this->event_after = $file; } elseif ($this->section[count($this->section) - 1] == 'load') { $this->event_load = $file; } } elseif ($this->section[0] == 'backend' && \runner::config('mode') == 'backend') { \Routerunner\Helper::loader($this, $file, $output); /* if ($this->section[1] == "model" && isset($this->backend_context["model"]["fields"])) { foreach ($this->backend_context["model"]["fields"] as $field_name => & $field_data) { if (!isset($field_data["default"])) { if (\runner::config("default." . $field_name)) { $field_data["default"] = \runner::config("default." . $field_name); } elseif (\runner::config("default.type." . $field_data["type"])) { $field_data["default"] = \runner::config("default.type." . $field_data["type"]); } } } $_model = false; if (isset($this->model) && $this->model && is_array($this->model) && isset($this->model[0]->route)) { $_model = $this->model[0]; } elseif (isset($this->model) && $this->model && isset($this->model->route)) { $_model = $this->model; } if (($model_create = \runner::stack("model_create")) && $_model && isset($model_create["route"]) && $model_create["route"] == $_model->route) { foreach ($this->backend_context["model"]["fields"] as $field_name => $field_data) { if (isset($field_data["default"])) { $_model->$field_name = $field_data["default"]; } } } } */ } elseif (\runner::config('mode') == 'backend' || $this->section[0] != 'backend') { \Routerunner\Helper::loader($this, $file, $output); } } } }