It adds hooks to the construct, before and after methods. example to execute functions instead of the current action: To go along before/after the action is called:
저자: Chema (chema@open-classifieds.com)
예제 #1
0
 public function before()
 {
     if (!Kohana::$is_cli) {
         throw new Kohana_HTTP_Exception_404();
     }
     parent::before();
 }
예제 #2
0
 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.");
         }
     }
 }
예제 #3
0
파일: controller.php 프로젝트: netbiel/core
 /**
  * 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();
     }
 }
예제 #4
0
 /**
  * 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();
 }
예제 #5
0
 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');
         }
     }
 }
예제 #6
0
 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"');
         }
     }
 }
예제 #7
0
 /**
  * Fill in default values for our properties before rendering the output.
  */
 public function after()
 {
     parent::after();
     if ($this->auto_render === TRUE) {
         // Add custom CSS if enabld and front controller
         if (is_subclass_of($this, 'Auth_Controller') === FALSE and ($custom_css = Theme::get_custom_css()) !== FALSE) {
             Theme::$styles = array_merge(Theme::$styles, array($custom_css => 'screen'));
         }
         //cookie consent
         if (Core::config('general.cookie_consent') == 1) {
             Theme::$styles = array_merge(Theme::$styles, array('css/jquery.cookiebar.css' => 'screen'));
             $this->template->scripts['footer'][] = 'js/jquery.cookiebar.js';
             $this->template->scripts['footer'][] = Route::url('default', array('controller' => 'jslocalization', 'action' => 'cookieconsent'));
         }
         // Add defaults to template variables.
         $this->template->styles = array_merge_recursive(Theme::$styles, $this->template->styles);
         $this->template->scripts = array_reverse(array_merge_recursive(Theme::$scripts, $this->template->scripts));
         //in case theres no description given
         if ($this->template->meta_description == '') {
             $this->template->meta_description = $this->template->title;
         }
         //title concatenate the site name
         if ($this->template->title != '') {
             $this->template->title .= ' - ';
         }
         $this->template->title .= core::config('general.site_name');
         //auto generate keywords and description from content
         seo::$charset = Kohana::$charset;
         $this->template->title = seo::text($this->template->title, 70);
         //not meta keywords given
         //remember keywords are useless :( http://googlewebmastercentral.blogspot.com/2009/09/google-does-not-use-keywords-meta-tag.html
         if ($this->template->meta_keywords == '') {
             $this->template->meta_keywords = seo::keywords($this->template->meta_description);
         }
         $this->template->meta_description = seo::text($this->template->meta_description);
     }
     $this->response->body($this->template->render());
 }
예제 #8
0
파일: auto.php 프로젝트: bosoy83/progtest
 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);
     }
 }
예제 #9
0
 function __construct(Request $request)
 {
     $this->fire = FirePHP::getInstance();
     parent::__construct($request);
 }
예제 #10
0
 public function before()
 {
     parent::before();
     I18n::lang('en-us');
 }
예제 #11
0
 /**
  * Fill in default values for our properties before rendering the output.
  */
 public function after()
 {
     parent::after();
     if ($this->auto_render === TRUE) {
         // Add defaults to template variables.
         $this->template->styles = array_merge_recursive(Theme::$styles, $this->template->styles);
         $this->template->scripts = array_reverse(array_merge_recursive(Theme::$scripts, $this->template->scripts));
         if ($this->template->title != '') {
             $concat = ' - ';
         } else {
             $concat = '';
         }
         $this->template->title .= $concat . core::config('general.site_name');
         //auto generate keywords and description from content
         $seo = new seo($this->template->meta_description, Kohana::$charset);
         if ($this->template->meta_keywords == '') {
             $this->template->meta_keywords = $seo->getKeyWords(12);
         }
         $this->template->meta_description = $seo->getMetaDescription(150);
         //die($this->template->meta_description);
     }
     $this->response->body($this->template->render());
 }
예제 #12
0
 public function __construct($request, $response)
 {
     parent::__construct($request, $response);
 }
예제 #13
0
 public function __construct(Request $request)
 {
     parent::__construct($request);
     $this->_config = Kohana_Config::instance()->load('ledger');
     $this->_user = Kuaas::instance()->get_user();
 }
 public function before()
 {
     parent::before();
     $this->container = Container::factory();
 }