<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class core extends MX_Controller {

    function __construct() {
        parent::__construct();

        // XSS filter $_POST, $_GET, $_COOKIE
        $global_xss_filtering = $this->config->item('global_xss_filtering');
        if ($global_xss_filtering === FALSE) {
            $_GET = $this->input->get(NULL, TRUE);
            $_POST = $this->input->post(NULL, TRUE);
            $_COOKIE = $this->input->cookie(NULL, TRUE);
        }
    }

    public function index() {

        // Browser check
        if ($this->config->item('check_browser') == TRUE) {
            $this->load->library('ciext/browser');
            $this->browser->check_browser();
        }

        // Check for database class loaded
        if (!$this->load->is_loaded('session')) {

            redirect(base_url() . 'admin/install');
        }

        $this->load->model('core_model');
        $this->lang->load('core');

        // Get page
        $page = $this->core_model->get_page();
        
        // If not found
        if (empty($page)) {

            show_404();
        }

        // Render page
        $this->parser->parse_string($page, array());
    }

    public function get_assets($file = '') {
        $this->load->driver('cache', $this->config->item('cache_init_config'));
        $ext = pathinfo($file, PATHINFO_EXTENSION);
        $data = '';
        // Enable GZip encoding.
        ob_start("ob_gzhandler");
        // Enable caching
        header('Cache-Control: public');
        // Expire in one week
        header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT');

        switch ($ext) {
            case 'css' :
                header("Content-Type: text/css");
                $data = $this->cache->get($file);
                break;

            case 'js':
                header('Content-Type: application/javascript');
                $data = $this->cache->get($file);
                break;

            default :
                break;
        }

        die($data);
    }

}

/* End of file core.php */
