Example #1
0
 public static function init()
 {
     if (!self::$init) {
         if (self::$mode == self::MODE_REQUEST) {
             if ($_SERVER['SERVER_PORT'] == 443 || !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
                 $secure = true;
             } else {
                 $secure = false;
             }
             if (WEB_SUB_FOLDER == '/') {
                 //WTF?
                 //print_stacktrace(); die;
             }
             if (session_id() == '') {
                 session_set_cookie_params(0, WEB_SUB_FOLDER, null, $secure, true);
                 session_name('Controller');
                 @session_start();
             }
             date_default_timezone_set(ConfigValue::get('Timezone', 'Africa/Johannesburg'));
         }
         self::check_quotes();
         self::$salt = ConfigValue::get('Salt', 'Change this to something random!');
         //TODO jrgns: Don't know if I like this here...
         $user = BackendUser::check();
         //Debugging
         self::$debug = false;
         if (SITE_STATE != 'production' || $user && in_array('superadmin', $user->roles)) {
             switch (true) {
                 case array_key_exists('debug', self::$query_vars):
                     //Default to lowest level
                     self::$debug = is_numeric(self::$query_vars['debug']) ? (int) self::$query_vars['debug'] : 1;
                     break;
             }
         }
         if ($config_debug = ConfigValue::get('Debug', false)) {
             self::$debug = $config_debug;
         }
         Backend::add('debug', self::$debug);
         if (SITE_STATE != 'production' || self::$debug) {
             ini_set('display_errors', 1);
             ini_set('error_reporting', E_ALL | E_STRICT);
         } else {
             ini_set('display_errors', 0);
         }
         //q in the payload overrides the q in the query string
         $query = array_key_exists('q', self::$payload) ? self::$payload['q'] : (array_key_exists('q', self::$query_vars) ? self::$query_vars['q'] : '');
         $query = self::checkQuery(Request::getQuery($query));
         $query = Hook::run('init', 'pre', array($query));
         self::parseQuery($query);
         //View
         self::$view = View::getInstance();
         if (!self::$view instanceof View) {
             self::$view = View::getInstance(ConfigValue::get('DefaultView', 'HtmlView'));
             self::whoops('Unrecognized Request', array('message' => 'Could not find a View for the Request', 'code_hint' => 406));
             if (self::$debug) {
                 print_stacktrace();
                 var_dump(self::$query_vars, $query, $_REQUEST, $_SERVER);
             }
         }
         //Sessions
         if (array_key_exists('error', $_SESSION)) {
             Backend::addError($_SESSION['error']);
         }
         if (array_key_exists('notice', $_SESSION)) {
             Backend::addNotice($_SESSION['notice']);
         }
         if (array_key_exists('success', $_SESSION)) {
             Backend::addSuccess($_SESSION['success']);
         }
         Hook::run('init', 'post');
         self::$init = true;
     }
 }