示例#1
0
 public function __construct()
 {
     parent::__construct();
     $this->start_time = microtime(true);
     $this->request = new \stdClass();
     $this->request->ssl = is_https();
     $this->request->method = $this->detectMethod();
     $this->request->lang = $this->detectLanguage();
     // Load our language, requested.
     if (!empty($this->request->lang)) {
         $file = !empty($this->language_file) ? $this->language_file : 'application';
         if (is_array($this->request->lang)) {
             $this->load->language($file, $this->request->lang[0]);
         } else {
             $this->load->language($file, $this->request->lang);
         }
         unset($file);
     }
     $this->config->load('api');
     // Gather config defaults when a value isn't set for this controller
     if (empty($this->enable_logging)) {
         $this->enable_logging = config_item('api.enable_logging');
     }
     if (empty($this->enable_rate_limits)) {
         $this->enable_rate_limits = config_item('api.enable_rate_limits');
     }
     if (empty($this->rate_limits)) {
         $this->rate_limits = config_item('api.rate_limits');
     }
     // Should we restrict to SSL requests?
     if (config_item('api.require_ssl') === true && !$this->request->ssl) {
         $this->failForbidden(lang('api.ssl_required'));
     }
     // Should we restrict to only allow AJAX requests?
     if (config_item('api.ajax_only') === true && !$this->input->is_ajax_request()) {
         $this->failForbidden(lang('api.ajax_required'));
     }
     $this->detectPage();
     if ($this->do_auth_check) {
         // Override the config setting for authentication
         // so that we can have an application and API co-exist
         // in a single codebase.
         get_instance()->config->set_item('api.authenticate_lib', $this->authenticate_class);
         if (!$this->restrict(null, true)) {
             $this->logTime();
             $this->failUnauthorized(lang('api.unauthorized'));
         }
     }
     // Has the user hit rate limits for this hour?
     if ($this->enable_rate_limits && !$this->isWithinLimits()) {
         $this->failTooManyRequests(sprintf(lang('api.too_many_requests'), $this->rate_limits));
     }
     // NEVER allow profiling via API.
     $this->output->enable_profiler(false);
     // Set logging default value
     $this->enable_logging = config_item('api.enable_logging');
 }
示例#2
0
 /**
  * Constructor takes care of getting the template engine up and running
  * and bound to our DI object, as well as any other preliminary needs,
  * like detecting the variant to use, etc.
  */
 public function __construct()
 {
     parent::__construct();
     // Setup our Template Engine
     $themer = config_item('active_themer');
     if (empty($themer)) {
         throw new \RuntimeException(lang('no_themer'));
     }
     $this->themer = new $themer(get_instance());
     // Register our paths with the themer
     $paths = config_item('theme.paths');
     foreach ($paths as $key => $path) {
         $this->themer->addThemePath($key, $path);
     }
     // Set our default theme.
     $this->themer->setDefaultTheme(config_item('theme.default_theme'));
     // Register our variants with the engine.
     $variants = config_item('theme.variants');
     foreach ($variants as $key => $value) {
         $this->themer->addVariant($key, $value);
     }
     $this->detectVariant();
     // Ensure that our UIKit is loaded up if we're using one.
     $uikit = config_item('theme.uikit');
     if ($uikit) {
         $this->uikit = new $uikit();
     }
     // Load up our meta collection
     $this->meta = new MetaCollection(get_instance());
     // Should we autoescape vars?
     if (is_null($this->auto_escape)) {
         $this->auto_escape = config_item('theme.auto_escape');
     }
 }