Example #1
0
 /**
  * Load the active theme.
  *
  * This is called at bootstrap time.
  * We will only ever have one theme active for any given request.
  *
  * @uses Kohana::modules
  */
 public static function load_themes()
 {
     $config = Config::load('site');
     self::$themes = self::available(FALSE);
     //set admin theme based on path info
     $path = ltrim(Request::detect_uri(), '/');
     Theme::$is_admin = $path == "admin" || !strncmp($path, "admin/", 6);
     if (Theme::$is_admin) {
         // Load the admin theme
         Theme::$active = $config->get('admin_theme', 'cerber');
     } else {
         // Load the site theme
         Theme::$active = $config->get('theme', 'cerber');
     }
     //Set mobile theme, if enabled and mobile request
     if (Request::is_mobile() and $config->get('mobile_theme', FALSE)) {
         // Load the mobile theme
         Theme::$active = $config->get('mobile_theme', 'cerber');
     }
     // Admins can override the site theme, temporarily. This lets us preview themes.
     if (User::is_admin() and isset($_GET['theme']) and $override = Text::plain($_GET['theme'])) {
         Theme::$active = $override;
     }
     //Finally set the active theme
     Theme::set_theme();
 }
Example #2
0
 public static function instance(&$uri = TRUE)
 {
     if (!Request::$instance and !Kohana::$is_cli) {
         // Detect mobile environment from HTTP HOST
         Request::$is_mobile = !!strstr(URL::base(TRUE, TRUE), '//mobile.');
     }
     return parent::instance($uri);
 }
Example #3
0
 /**
  * 
  * @return boolean
  */
 public static function is_mobile()
 {
     if (self::$is_mobile !== NULL) {
         return self::$is_mobile;
     }
     if (Kohana::$profiling === TRUE) {
         $benchmark = Profiler::start('Kohana', 'detect mobile');
     }
     $agent = strtolower(Request::$user_agent);
     $mobile_browser = 0;
     if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', $agent)) {
         $mobile_browser++;
     }
     if (isset($_SERVER['HTTP_ACCEPT']) and strpos(strtolower($_SERVER['HTTP_ACCEPT']), 'application/vnd.wap.xhtml+xml') !== false) {
         $mobile_browser++;
     }
     if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
         $mobile_browser++;
     }
     if (isset($_SERVER['HTTP_PROFILE'])) {
         $mobile_browser++;
     }
     $mobile_ua = substr($agent, 0, 4);
     $mobile_agents = array('w3c ', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac', 'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'inno', 'ipaq', 'java', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-', 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-', 'newt', 'noki', 'oper', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox', 'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar', 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-', 'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp', 'wapr', 'webc', 'winw', 'xda', 'xda-');
     if (in_array($mobile_ua, $mobile_agents)) {
         $mobile_browser++;
     }
     if (isset($_SERVER['ALL_HTTP']) and strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== FALSE) {
         $mobile_browser++;
     }
     // Pre-final check to reset everything if the user is on Windows
     if (strpos($agent, 'windows') !== FALSE) {
         $mobile_browser = 0;
     }
     // But WP7 is also Windows, with a slightly different characteristic
     if (strpos($agent, 'windows phone') !== FALSE) {
         $mobile_browser++;
     }
     if (isset($benchmark)) {
         Profiler::stop($benchmark);
     }
     if ($mobile_browser > 0) {
         self::$is_mobile = TRUE;
     }
     self::$is_mobile = FALSE;
     return self::$is_mobile;
 }
Example #4
0
 /**
  * Loads the template View object, if it is direct request
  *
  * @return  void
  * @throws  Http_Exception_415  If none of the accept-types are supported
  */
 public function before()
 {
     // Execute parent::before first
     parent::before();
     if ($this->bare == FALSE) {
         // Load the config
         $this->_config = Config::load('site');
         if (Kohana::$profiling) {
             // Start a new benchmark token
             $this->_benchmark = Profiler::start('Gleez', ucfirst($this->request->controller()) . ' Controller');
         }
         // Test whether the current request is command line request
         if (Kohana::$is_cli) {
             $this->_ajax = FALSE;
             $this->auto_render = FALSE;
         }
         // Test whether the current request is the first request
         if (!$this->request->is_initial()) {
             $this->_internal = TRUE;
             $this->auto_render = FALSE;
         }
         // Test whether the current request is ajax request
         if ($this->request->is_ajax()) {
             $this->_ajax = TRUE;
             $this->auto_render = FALSE;
         }
         // Test whether the current request is jquery mobile request. ugly hack
         if (Request::is_mobile() and $this->_config->get('mobile_theme', FALSE)) {
             $this->_ajax = FALSE;
             $this->auto_render = TRUE;
         }
         // Test whether the current request is datatables request
         if (Request::is_datatables()) {
             $this->_ajax = TRUE;
             $this->auto_render = FALSE;
         }
         $this->response->headers('X-Powered-By', Gleez::getVersion(TRUE, TRUE) . ' (' . Gleez::CODENAME . ')');
         $this->_auth = Auth::instance();
         // Get desired response formats
         $accept_types = Request::accept_type();
         $accept_types = Arr::extract($accept_types, array_keys($this->_accept_formats));
         // Set response format to first matched element
         $this->_response_format = $this->request->headers()->preferred_accept(array_keys($this->_accept_formats));
         $site_name = Template::getSiteName();
         $url = URL::site(NULL, TRUE);
         View::bind_global('site_name', $site_name);
         View::bind_global('site_url', $url);
     }
     if ($this->auto_render && $this->bare == FALSE) {
         // Throw exception if none of the accept-types are supported
         if (!($accept_types = array_filter($accept_types))) {
             throw new Http_Exception_415('Unsupported accept-type', 415);
         }
         // Initiate a Format instance
         $this->_format = Format::instance();
         // Load the template
         $this->template = View::factory($this->template);
         $this->title_separator = $this->_config->get('title_separator', ' | ');
         $this->_widgets = Widgets::instance();
         $this->template->_admin = Theme::$is_admin;
         // Set the destination & redirect url
         $this->_desti = array('destination' => $this->request->uri());
         $this->redirect = $this->request->query('destination') !== NULL ? $this->request->query('destination') : array();
         // Bind the generic page variables
         $this->template->set('site_name', Template::getSiteName())->set('site_slogan', $this->_config->get('site_slogan', __('Innovate IT')))->set('site_url', URL::site(NULL, TRUE))->set('site_logo', $this->_config->get('site_logo', FALSE))->set('sidebar_left', array())->set('sidebar_right', array())->set('column_class', '')->set('main_column', 12)->set('head_title', $this->title)->set('title', $this->title)->set('subtitle', $this->subtitle)->set('icon', $this->icon)->set('schemaType', $this->schemaType)->set('front', FALSE)->set('mission', FALSE)->set('tabs', FALSE)->set('subtabs', FALSE)->set('actions', FALSE)->set('_user', $this->_auth->get_user())->bind('datatables', $this->_datatables);
         // Page Title
         $this->title = ucwords($this->request->controller());
         // Assign the default css files
         $this->_set_default_css();
         // Assign the default js files
         $this->_set_default_js();
         // Set default server headers
         $this->_set_default_server_headers();
         // Set default meta data and media
         $this->_set_default_meta_links();
         $this->_set_default_meta_tags();
         /**
          * Make your view template available to all your other views
          * so easily you could access template variables
          */
         View::bind_global('template', $this->template);
     }
     if (Kohana::$environment === Kohana::DEVELOPMENT) {
         Log::debug('Executing Controller [:controller] action [:action]', array(':controller' => $this->request->controller(), ':action' => $this->request->action()));
     }
 }