public function before() { $this->_controller = $this->controller = $this->request->param('_controller'); $this->_action = $this->action = $this->request->param('_action'); if ($this->has_controller_and_action()) { $this->_controller_base->before(); $this->_controller_base->{'action_' . $this->_controller_base->action}(); } else { parent::before(); } }
public function before() { if (!Auth::instance()->logged_in('admin')) { exit; } parent::before(); }
public function before() { parent::before(); View::bind_global('preview', $this->preview); if ($this->request->action() === 'index') { $this->page = Model_Page::find_by_slug($this->request->param('catcher')); } else { if (!Can::show()) { throw new Kohana_Exception("Permission Denied."); } $this->preview = TRUE; if ($this->request->query('preview') !== NULL) { $this->preview = (bool) $this->request->query('preview'); } if ($this->request->query('id_page') !== NULL) { $id_page = (bool) $this->request->query('id_page'); $this->page = Model_Page::factory('Page')->where('id_page', '=', $id_page)->order_by('id', 'DESC')->find(); dd($this->page); } else { $page_id = (int) $this->request->param('id'); $this->page = Model_Page::factory('Page', $page_id); } } View::bind_global('page', $this->page); $this->content = $this->page->render_blocks(); }
public function before() { $fullBaseUrl = Url::base(true); //was user on our site? if (strpos($this->request->referrer(), $fullBaseUrl) === 0) { //now check that a controller set, it wasn't the user controller, and that the session var "noReturn" is not false $uri = parse_url($this->request->referrer(), PHP_URL_PATH); // correct the path for url_base and index_file, in part taken from Kohana_Request::detect_uri() // Get the path from the base URL, including the index file $base_url = parse_url(Kohana::$base_url, PHP_URL_PATH); if (strpos($uri, $base_url) === 0) { // Remove the base URL from the URI $uri = (string) substr($uri, strlen($base_url)); } if (Kohana::$index_file and strpos($uri, Kohana::$index_file) === 0) { // Remove the index file from the URI $uri = (string) substr($uri, strlen(Kohana::$index_file)); } $processedRef = Request::process_uri($uri); $referrerController = Arr::path($processedRef, 'params.controller', false); if ($referrerController && $referrerController != 'user' && !Session::instance()->get('noReturn', false)) { Session::instance()->set('returnUrl', $this->request->referrer()); } } parent::before(); }
public function before() { $baseUrl = Url::base(true); if (substr($this->request->referrer(), 0, strlen($baseUrl)) == $baseUrl) { $urlPath = ltrim(parse_url($this->request->referrer(), PHP_URL_PATH), '/'); $processedRef = Request::process_uri($urlPath); $referrerController = Arr::path($processedRef, 'params.controller', false); if ($referrerController && $referrerController != 'user' && !Session::instance()->get('noReturn', false)) { Session::instance()->set('returnUrl', $this->request->referrer()); } } parent::before(); }
/** * Before action * * @throws HTTP_Exception_403 */ public function before() { parent::before(); $this->auth = Auth::instance(); $this->user = $this->auth->get_user(); $this->is_admin = $this->auth->logged_in('admin'); // Проверяем права на доступ к текущей странице if ($this->auth_required !== false and $this->auth->logged_in($this->auth_required) === false or is_array($this->secure_actions) and array_key_exists($this->request->action(), $this->secure_actions) and $this->auth->logged_in($this->secure_actions[$this->request->action()]) === false) { // Если нет прав и AJAX запрос, то выдаем эксепшен if ($this->auth->logged_in() and $this->request->is_ajax()) { throw new HTTP_Exception_403('Unauthorised access attempt'); } else { throw new HTTP_Exception_403('Unauthorised access attempt'); Message::error(__('Unauthorised access attempt!')); HTTP::redirect(Route::url('f_home')); } } }
public function before() { $baseUrl = URL::base(true); if (substr($this->request->referrer(), 0, strlen($baseUrl)) == $baseUrl) { $urlPath = ltrim(parse_url($this->request->referrer(), PHP_URL_PATH), '/'); $processedRef = Request::process(new Request($urlPath)); $referrerController = Arr::path($processedRef, 'params.controller', false); if ($referrerController && $referrerController != 'user' && !Session::instance()->get('noReturn', false)) { Session::instance()->set('returnUrl', $this->request->referrer()); } } if ($this->request->action() == "profile") { if (isset($_GET["old"])) { $this->template = "admin"; } else { $this->template = "admin"; } } parent::before(); }
public function before() { if (!Can::show()) { // Record only when invalid session, prevent ximite. if (!Auth::instance()->logged_in()) { Session::instance()->set('manager_login_reference', URL::current()); } return HTTP::redirect('manager/login'); } $success = Session::instance()->get_once('success'); View::set_global('success', $success); if (!$this->model_name and class_exists('Model_' . $this->request->controller())) { $this->model_name = $this->request->controller(); } if ($this->title === NULL) { $this->title = $this->model_name; } if (!$this->parents) { $this->parents = $this->request->param('parents'); $this->parents = explode('/', $this->parents); $parents = array(); if (count($this->parents) > 1) { foreach ($this->parents as $index => $value) { if ($index % 2) { continue; } $parents[] = array('model' => $value, 'table' => Inflector::plural($value), 'model_id' => $this->parents[$index + 1]); } } $this->parents = array_reverse($parents); } if (!$this->parent) { $this->parent = $this->request->param('parent'); } if (!$this->parent_id) { $this->parent_id = $this->request->param('parent_id'); } $boolean_fields = array(); $image_fields = array(); $upload_fields = array(); $text_fields = array(); $date_fields = array(); if ($this->model_name) { $this->model = ORM::factory(ORM::get_model_name($this->model_name), $this->request->param('id')); if ($this->parents) { $current_parent_table = strtolower($this->model_name); foreach ($this->parents as $index => $values) { $this->model->join(Arr::get($values, 'table')); $this->model->on(Arr::get($values, 'table') . '.id', '=', $current_parent_table . '.' . Arr::get($values, 'model') . '_id'); $this->model->where(Arr::get($values, 'table') . '.id', '=', Arr::get($values, 'model_id')); $current_parent_table = Arr::get($values, 'table'); } } if ($this->parent_id) { $this->foreign_key = strtolower($this->parent) . '_id'; $this->parent_model = ORM::factory(ORM::get_model_name($this->parent), $this->parent_id); $model_has_many = Inflector::plural(strtolower($this->model_name)); if (in_array($this->foreign_key, array_keys($this->model->as_array()))) { $this->model->where($this->foreign_key, '=', $this->parent_id); } else { if (in_array($model_has_many, array_keys($this->parent_model->as_array()))) { $this->model = $this->parent_model->{$model_has_many}; } } } $text_field_formats = Kohana::$config->load('huia/model.models'); if ($text_field_formats) { $this->text_field_formats = Arr::merge($this->text_field_formats, $text_field_formats); } $this->model->reload_columns(TRUE); foreach ($this->model->table_columns() as $column => $values) { if (Arr::get($values, 'data_type') === 'text') { $format = Arr::path($this->text_field_formats, $this->model->object_name() . '.' . $column, 'ckeditor'); $text_fields[$column] = array('format' => $format); } else { if (Arr::get($values, 'data_type') === 'tinyint' and Arr::get($values, 'display') == 1) { $boolean_fields[] = $column; } else { if (preg_match('/^(image|thumb)/', $column)) { $image_fields[] = $column; } else { if (preg_match('/^(file|upload)/', $column)) { $upload_fields[] = $column; } else { if (Arr::get($values, 'data_type') === 'date') { $date_fields[] = $column; } } } } } } View::set_global('date_fields', $date_fields); View::set_global('text_fields', $text_fields); $this->belongs_to = Arr::merge($this->belongs_to, $this->model->belongs_to()); $this->has_many = Arr::merge($this->has_many, $this->model->has_many()); $model_labels = $this->model->labels(); foreach ($model_labels as $key => $value) { // ignore through secundary $has_many_key = Arr::get($this->has_many, $key); if ($has_many_key) { $through = Arr::get($has_many_key, 'through'); $is_secundary = preg_match('/^' . $key . '_/', $through); $same_table = $through === $key . '_' . $key; if ($is_secundary and !$same_table) { unset($model_labels[$key]); } } // ignore composite if (preg_match('/^id_/', $key)) { unset($model_labels[$key]); } } $this->labels = Arr::merge($this->labels, $model_labels); } // auto upload if ($this->upload_fields === NULL) { $this->upload_fields = $upload_fields; } // auto booleans if ($this->boolean_fields === NULL) { $this->boolean_fields = $boolean_fields; } // auto images if ($this->image_fields === NULL) { $this->image_fields = $image_fields; } foreach ($this->boolean_fields as $field) { if (!isset($this->boolean_fields_labels[$field])) { $this->boolean_fields_labels[$field] = $this->boolean_fields_labels['default']; } } $model_classes = ORM_Autogen::get_models(); View::set_global('model_classes', $model_classes); parent::before(); // autogen controllers if (Kohana::$environment === Kohana::DEVELOPMENT) { self::generate_controllers($model_classes); } }