Example #1
0
 /**
  * Construct controller.
  */
 public function before()
 {
     if ($this->request->is_ajax()) {
         $this->_request_type = self::REQUEST_AJAX;
         $this->ajax = true;
     } else {
         if (!$this->request->is_initial()) {
             $this->_request_type = self::REQUEST_INTERNAL;
             $this->internal = true;
         }
     }
     // Update history?
     $this->history = $this->history && !$this->ajax;
     // Initialize session
     $this->session = Session::instance();
     // Load current user, null if none
     if (self::$user === false) {
         $visitor = Visitor::instance();
         Controller::$user = $visitor->get_user();
         // If still no user, try auto login
         if (!Controller::$user && $visitor->auto_login()) {
             Controller::$user = $visitor->get_user();
         }
         unset($visitor);
     }
     // Update current online user for initial and ajax requests
     if ($this->_request_type !== self::REQUEST_INTERNAL) {
         Model_User_Online::update(self::$user);
     }
     // Open outside links to a new tab/window
     HTML::$windowed_urls = true;
     // Load template
     if ($this->auto_render) {
         $this->page_id = $this->page_id ? $this->page_id : $this->request->controller();
         // Figure out what format the client wants
         $accept_types = Request::accept_type();
         if (isset($accept_types['*/*'])) {
             // All formats accepted
             $accept_types = $this->_accept_formats;
         } else {
             // Only some formats accepted
             $accept_types = Arr::extract($accept_types, array_keys($this->_accept_formats));
             if (!($accept_types = array_filter($accept_types))) {
                 throw new HTTP_Exception_415('Unsupported accept type');
             }
         }
         $this->_response_format = key($accept_types);
     }
 }