Exemple #1
0
 public function __construct()
 {
     parent::Controller();
     if (file_exists(APPPATH . 'config/openvbx.php')) {
         $this->config->load('openvbx');
     }
     if (file_exists(APPPATH . 'config/database.php') and version_compare(PHP_VERSION, $this->min_php_version, '>=')) {
         $this->load->database();
         redirect('');
     }
     // cache is evil when not handled properly, assume the
     // possibility that we're being reinstalled so lets clear
     // any possibly lingering cache artifacts
     $this->cache = OpenVBX_Cache_Abstract::load();
     $this->cache->enabled(true);
     $this->cache->flush();
     $this->cache->enabled(false);
 }
 public function __construct()
 {
     parent::__construct();
     if (!file_exists(APPPATH . 'config/openvbx.php') || !file_exists(APPPATH . 'config/database.php')) {
         redirect('install');
     }
     $this->config->load('openvbx');
     $this->load->database();
     $this->cache = OpenVBX_Cache_Abstract::load();
     $this->api_cache = OpenVBX_Cache_Abstract::load('db');
     $this->load->model('vbx_settings');
     $this->load->model('vbx_user');
     $this->load->model('vbx_group');
     $this->load->model('vbx_flow');
     $this->load->model('vbx_flow_store');
     $this->load->model('vbx_plugin_store');
     $this->load->helper('file');
     $this->load->helper('twilio');
     $this->load->library('session');
     $this->settings = new VBX_Settings();
     $rewrite_enabled = intval($this->settings->get('rewrite_enabled', VBX_PARENT_TENANT));
     if ($rewrite_enabled) {
         /* For mod_rewrite */
         $this->config->set_item('index_page', '');
     }
     $this->tenant = $this->settings->get_tenant($this->router->tenant);
     if (!$this->tenant || !$this->tenant->active) {
         $this->session->set_userdata('loggedin', 0);
         $this->session->set_flashdata('error', 'This tenant is no longer active');
         return redirect(asset_url('auth/logout'));
     }
     if ($this->tenant && $this->tenant->url_prefix && $this->tenant->url_prefix !== $this->router->tenant) {
         // case sensitive url faux-pas, redirect to force the url case
         $this->router->tenant = $this->tenant->url_prefix;
         return redirect(current_url());
     }
     if ($this->tenant === false) {
         $this->router->tenant = '';
         redirect('');
     }
     $this->set_time_zone();
     $this->testing_mode = !empty($_REQUEST['vbx_testing_key']) ? $_REQUEST['vbx_testing_key'] == $this->config->item('testing-key') : false;
     if ($this->tenant) {
         $this->config->set_item('sess_cookie_name', $this->tenant->id . '-' . $this->config->item('sess_cookie_name'));
         $this->twilio_sid = $this->settings->get('twilio_sid', $this->tenant->id);
         $token_from = $this->tenant->type == VBX_Settings::AUTH_TYPE_CONNECT ? VBX_PARENT_TENANT : $this->tenant->id;
         $this->twilio_token = $this->settings->get('twilio_token', $token_from);
         $this->application_sid = $this->settings->get('application_sid', $this->tenant->id);
         // @deprecated, will be removed in a future release
         $this->twilio_endpoint = $this->settings->get('twilio_endpoint', VBX_PARENT_TENANT);
     }
     $this->output->enable_profiler($this->config->item('enable_profiler', false));
     $this->set_response_type();
     $this->set_request_method();
     if ($this->response_type == 'html') {
         $scripts = null;
         $js_assets = !empty($this->js_assets) ? $this->js_assets : 'js';
         if ($this->config->item('use_unminimized_js')) {
             $scripts = $this->get_assets_list($js_assets);
             if (is_array($scripts)) {
                 foreach ($scripts as $script) {
                     if ($script) {
                         $this->template->add_js($script);
                     }
                 }
             }
         } else {
             $this->template->add_js(asset_url('assets/min/?g=' . $js_assets), 'absolute');
         }
         $css_assets = !empty($this->css_assets) ? $this->css_assets : 'css';
         if ($this->config->item('use_unminimized_css')) {
             $styles = $this->get_assets_list($css_assets);
             if (is_array($styles)) {
                 foreach ($styles as $style) {
                     if ($style) {
                         $this->template->add_css($style);
                     }
                 }
             }
         } else {
             $this->template->add_css(asset_url('assets/min/?g=' . $css_assets), 'link');
         }
     }
     /**
      * Controllers can elect to suppress the error reporting - this is mainly to
      * keep API & Ajax responses from failing due to Warnings & Notices. Use carefully.
      */
     if ($this->suppress_warnings_notices) {
         ini_set('display_errors', 'off');
     }
 }