public function before() { if (!Kohana::$is_cli) { throw new Kohana_HTTP_Exception_404(); } parent::before(); }
function before() { parent::before(); // Auth redirects. if ($this->request->controller() != "api" and $this->request->controller() != "auth" and $this->request->controller() != "update" and $this->request->controller() != "install" and $this->request->controller() != "exception" and (!strlen(Session::instance()->get('auth_uid')) or !strlen(Session::instance()->get('auth_expiration')) or !strlen(Session::instance()->get('auth_key')) or !Session::instance()->get('auth_role'))) { $this->request->redirect('/'); } else { if ($this->request->controller() == "auth" and $this->request->action() != "logout" and (strlen(Session::instance()->get('auth_uid')) and strlen(Session::instance()->get('auth_expiration')) and strlen(Session::instance()->get('auth_key')) and Session::instance()->get('auth_role'))) { $this->request->redirect('/dash'); } } // Avoid a nested exception thrown. if ($this->request->controller() != "api" and $this->request->controller() != "auth" and $this->request->controller() != "update" and $this->request->controller() != "install" and $this->request->controller() != "exception" and count($this->_required_role_permissions)) { $auth_role = Session::instance()->get('auth_role'); if (!isset($this->_required_role_permissions['default'])) { throw new HTTP_Exception_401("Developer Error! No default permission set!"); } if (isset($this->_required_role_permissions[$this->request->action()]) and (!isset($auth_role->{$this->_required_role_permissions[$this->request->action()]}) or !$auth_role->{$this->_required_role_permissions[$this->request->action()]})) { throw new HTTP_Exception_401("Your account does not have access to this feature."); } if (!isset($this->_required_role_permissions[$this->request->action()]) and (!isset($auth_role->{$this->_required_role_permissions['default']}) or !$auth_role->{$this->_required_role_permissions['default']})) { throw new HTTP_Exception_401("Your account does not have access to this feature."); } } }
/** * Construct controller */ public function before() { parent::before(); Cache::$default = 'default'; // Check if this was an interna request or direct $this->internal = $this->request !== Request::instance(); // Ajax request? $this->ajax = Request::$is_ajax; // Load current user, null if none if (self::$user === false) { self::$user = Visitor::instance()->get_user(); } }
/** * Initialize properties before running the controller methods (actions), * so they are available to our action. */ public function before($template = NULL) { parent::before(); Theme::checker(); $this->maintenance(); /** * selected category */ if ($this->request->param('category', NULL) != 'all') { $slug_cat = new Model_Category(); $seo_cat = $slug_cat->where('seoname', '=', $this->request->param('category'))->limit(1)->cached()->find(); if ($seo_cat->loaded()) { self::$category = $seo_cat; } } /** * selected location */ if ($this->request->param('location', NULL) != NULL || $this->request->param('location') != 'all') { $slug_loc = new Model_Location(); $seo_loc = $slug_loc->where('seoname', '=', $this->request->param('location'))->limit(1)->cached()->find(); if ($seo_loc->loaded()) { self::$location = $seo_loc; } } if ($this->auto_render === TRUE) { // Load the template if ($template !== NULL) { $this->template = $template; } $this->template = View::factory($this->template); // Initialize template values $this->template->title = core::config('general.site_name'); $this->template->meta_keywords = ''; $this->template->meta_description = ''; $this->template->meta_copywrite = 'Open Classifieds ' . Core::version; $this->template->content = ''; $this->template->styles = array(); $this->template->scripts = array(); //we can not cache this view since theres dynamic parts //$this->template->header = View::factory('header'); //setting inner views try to get from fragment // if (Auth::instance()->logged_in()) // $this->template->header = View::fragment('header_front_login','header'); // else $this->template->header = View::factory('header'); // $this->template->header = View::fragment('header_front','header'); //no fragment since CSRF gets cached :( $this->template->footer = View::fragment('footer_front', 'footer'); } }
/** * Prevent Minion from being run over http */ public function before() { if (!Kohana::$is_cli) { throw new Kohana_Exception("Minion can only be ran from the cli"); } $this->_task = $this->request->param('task'); $options = CLI::options('help', 'task'); if (array_key_exists('help', $options)) { $this->request->action('help'); } if (!empty($options['task'])) { $this->_task = $options['task']; } return parent::before(); }
public function before() { parent::before(); // Загружаем конфиг для сайта // $this->app_config = Kohana::$config->load( 'app' ); // if (!$this->installation_required) // { // $this->install_config = Kohana::$config->load( 'install' ); // } $installation_status = Kohana::$config->load('install.status'); if ($this->installation_required) { if ($installation_status !== INSTALLED) { $this->redirect('/install'); } } }
/** * Initialize properties before running the controller methods (actions), * so they are available to our action. */ public function before($template = NULL) { parent::before(); Theme::checker(); $this->maintenance(); $this->private_site(); /** * selected category */ self::$category = Model_Category::current(); /** * selected location */ self::$location = Model_Location::current(); //Gets a coupon if selected Model_Coupon::current(); if ($this->auto_render === TRUE) { // Load the template if ($template !== NULL) { $this->template = $template; } $this->template = View::factory($this->template); // Initialize template values $this->template->title = core::config('general.site_name'); $this->template->meta_keywords = ''; $this->template->meta_description = ''; $this->template->meta_copyright = 'Open Classifieds ' . Core::VERSION; $this->template->meta_copywrite = $this->template->meta_copyright; //legacy for old themes $this->template->content = ''; $this->template->styles = array(); $this->template->scripts = array(); $this->template->amphtml = NULL; $this->template->header = View::factory('header'); $this->template->footer = View::factory('footer'); // header_front_login fragment since CSRF gets cached :( // possible workaround ? @see http://kohanaframework.org/3.0/guide/kohana/fragments // if (Auth::instance()->logged_in()) // $this->template->header = View::fragment('header_front_login','header'); // else // $this->template->header = View::fragment('header_front','header'); //$this->template->footer = View::fragment('footer_front','footer'); } }
public function before() { parent::before(); $this->logreader_config = new LogReader_Config(Kohana::$config->load('kohana-logreader')->as_array()); $store = $this->logreader_config->get_store(); $store_class = 'LogReader_Store_' . $store['type']; $logreader_store = new $store_class($store); $this->logreader = new LogReader($this->logreader_config, $logreader_store); if ($this->logreader_config->is_authentication_required()) { // Use HTTP basic authentication if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $this->user = $this->logreader->get_user_by_username_and_password($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); } // Set Authentication required response if needed if ($this->user === NULL) { throw HTTP_Exception::factory(401)->authenticate('Basic realm="Authentication required"'); } } }
public function before() { /* list($usec, $sec) = explode(" ",microtime()); $this->a = (float)$usec + (float)$sec; */ parent::before(); // Получаем наименования контроллера и действия из запроса $this->directory = $this->request->directory() ? $this->request->directory() . '_' : ''; $this->controller_name = $this->request->controller(); $this->action_name = $this->request->action(); // Пробуем получить параметр AJAX из запроса $this->ajax = $this->request->param('ajax'); // Если метку AJAX есть - добавляем к директории путь до AJAX $this->ajax = !empty($this->ajax) ? $this->ajax . '_' : ''; // Создаем имена главного и текущего видов заданного контроллера $view_name_prefix = 'View_' . $this->directory . $this->controller_name . '_' . $this->ajax; $view_name_index = $view_name_prefix . 'Index'; $view_name = $view_name_prefix . $this->action_name; $view_file_index = strtolower(str_replace('_', '/', $view_name_index)); $view_file = strtolower(str_replace('_', '/', $view_name_prefix)) . strtolower($this->action_name); // Формируем имена главного и текущего шаблонов $template_name_prefix = $this->directory . $this->controller_name . '_' . $this->ajax; $template_name_index = $template_name_prefix . 'Index'; $template_name = $template_name_prefix . $this->action_name; $template_file_index = strtolower(str_replace('_', '/', $template_name_index)); $template_file = strtolower(str_replace('_', '/', $template_name_prefix)) . strtolower($this->action_name); // Если в папке templates нет файла шаблона, берем основной шаблон if (!Kohana::find_file('templates', $template_file, 'mustache')) { $template_file = $template_file_index; } /* var_dump($view_file); exit; */ // Если в папке classes есть нужный класс if (Kohana::find_file('classes', $view_file)) { $this->view = new $view_name($template_file); } elseif (Kohana::find_file('classes', $view_file_index)) { $this->view = new $view_name_index($template_file); } }
/** * Initialize properties before running the controller methods (actions), * so they are available to our action. */ public function before($template = NULL) { parent::before(); Theme::checker(); $this->maintenance(); $this->private_site(); //get category, deprecated, to keep backwards compatibility with themes self::$category = Model_Category::current(); //Gets a coupon if selected self::$coupon = Model_Coupon::current(); //get the affiliate if any Model_Affiliate::current(); if ($this->auto_render === TRUE) { // Load the template if ($template !== NULL) { $this->template = $template; } $this->template = View::factory($this->template); // Initialize template values $this->template->title = core::config('general.site_name'); $this->template->meta_keywords = ''; $this->template->meta_description = ''; $this->template->meta_copyright = 'Open eShop ' . Core::VERSION; $this->template->content = ''; $this->template->styles = array(); $this->template->scripts = array(); //we can not cache this view since theres dynamic parts //$this->template->header = View::factory('header'); //setting inner views try to get from fragment // if (Auth::instance()->logged_in()) // $this->template->header = View::fragment('header_front_login','header'); // else $this->template->header = View::factory('header'); //no fragment since CSRF gets cached :( $this->template->footer = View::fragment('footer_front', 'footer'); } }
public function before() { parent::before(); I18n::lang('en-us'); }
public function before() { parent::before(); $this->container = Container::factory(); }