<commit_before><?php

/**
 * This class is the main execution point for all page requests. It
 * checks and configures the Nails environment.
 *
 * @package     Nails
 * @subpackage  common
 * @category    Controller
 * @author      Nails Dev Team
 * @link
 */

// use Monolog\Logger;
// use Monolog\Handler\StreamHandler;

class CORE_NAILS_Controller extends MX_Controller
{

    protected $data;
    protected $user;
    protected $nailsErrorHandler;
    protected $log;

    // --------------------------------------------------------------------------

    /**
     * Build the main framework. All autoloaded items have been loaded and
     * instantiated by this point and are safe to use.
     */
    public function __construct()
    {
        parent::__construct();

        // --------------------------------------------------------------------------

        //  Include the composer autoloader
        if (!file_exists(FCPATH . 'vendor/autoload.php')) {

            $_ERROR = 'Composer autoloader not found; run <code>composer install</code> to install dependencies';

            include NAILS_COMMON_PATH . 'errors/startup_error.php';
        }

        require_once FCPATH . 'vendor/autoload.php';

        // --------------------------------------------------------------------------

        //  Set up services
        \Nails\Factory::setup();

        // --------------------------------------------------------------------------

        //  Is Nails in maintenance mode?
        $this->maintenanceMode();

        // --------------------------------------------------------------------------

        //  Nails PHP Version Check
        $this->checkPhpVersion();

        // --------------------------------------------------------------------------

        //  Configure logging and error reporting
        // $this->setLogging();
        $this->setErrorReporting();

        // --------------------------------------------------------------------------

        //  Set the default content-type
        $this->output->set_content_type('text/html; charset=utf-8');

        // --------------------------------------------------------------------------

        //  Define data array (used extensively in views)
        $this->data =& getControllerData();

        // --------------------------------------------------------------------------

        //  Define all the packages
        $this->autoloadItems();

        // --------------------------------------------------------------------------

        /**
         * If we're on a staging environment then prompt for a password; but only if
         * a password has been defined in app.php
         */

        $this->staging();

        // --------------------------------------------------------------------------

        //  Test that the cache is writeable
        $this->testCache();

        // --------------------------------------------------------------------------

        //  Instanciate the user model
        $this->instantiateUser();

        // --------------------------------------------------------------------------

        //  Instanciate languages
        $this->instantiateLanguages();

        // --------------------------------------------------------------------------

        /**
         * Is the user suspended?
         * Executed here so that both the user and language systems are initialised
         * (so that any errors can be shown in the correct language).
         */

        $this->isUserSuspended();

        // --------------------------------------------------------------------------

        //  Instanciate DateTime
        $this->instantiateDateTime();

        // --------------------------------------------------------------------------

        //  Need to generate the routes_app.php file?
        if (defined('NAILS_STARTUP_GENERATE_APP_ROUTES') && NAILS_STARTUP_GENERATE_APP_ROUTES) {

            $this->load->model('routes_model');

            if (!$this->routes_model->update()) {

                //  Fall over, routes_app.php *must* be there
                $subject  = 'Failed To generate routes_app.php';
                $message  = 'routes_app.php was not found and could not be generated. ';
                $message .= $this->routes_model->last_error();

                showFatalError($subject, $message);

            } else {

                //  Routes exist now, instruct the browser to try again
                if ($this->input->post()) {

                    redirect($this->input->server('REQUEST_URI'), 'Location', 307);

                } else {

                    redirect($this->input->server('REQUEST_URI'));
                }
            }
        }

        // --------------------------------------------------------------------------

        //  Set User Feedback alerts for the views
        $this->data['notice']  = $this->userFeedback->get('notice')  ?: $this->session->flashdata('notice');
        $this->data['message'] = $this->userFeedback->get('message') ?: $this->session->flashdata('message');
        $this->data['error']   = $this->userFeedback->get('error')   ?: $this->session->flashdata('error');
        $this->data['success'] = $this->userFeedback->get('success') ?: $this->session->flashdata('success');

        // --------------------------------------------------------------------------

        //  Other defaults
        $this->data['page']                   = new stdClass();
        $this->data['page']->title            = '';
        $this->data['page']->seo              = new stdClass();
        $this->data['page']->seo->title       = '';
        $this->data['page']->seo->description = '';
        $this->data['page']->seo->keywords    = '';

        // --------------------------------------------------------------------------

        /**
         * Forced maintenance mode?
         */
        if (app_setting('maintenance_mode_enabled', 'site')) {

            $this->maintenanceMode(true);
        }

        // --------------------------------------------------------------------------

        /**
         * Finally, set some meta tags which should be used on every site.
         */

        $this->meta->addRaw(array(
            'charset' => 'utf8'
        ));
    }

    // --------------------------------------------------------------------------

    /**
     * Checks that the version of PHP is sufficient to run all enabled modules
     * @return void
     */
    protected function checkPhpVersion()
    {
        /**
         * PHP Version Check
         * =================
         *
         * We need to loop through all available modules and have a look at what version
         * of PHP they require, we'll then take the highest version and set that as our
         * minimum supported value.
         *
         * To set a requirement, within the module's nails object in composer.json,
         * specify the minPhpVersion value. You should also specify the appropriate<commit_msg>Removed viewpoer scaling for mbile by default<commit_after><?php

/**
 * This class is the main execution point for all page requests. It
 * checks and configures the Nails environment.
 *
 * @package     Nails
 * @subpackage  common
 * @category    Controller
 * @author      Nails Dev Team
 * @link
 */

// use Monolog\Logger;
// use Monolog\Handler\StreamHandler;

class CORE_NAILS_Controller extends MX_Controller
{

    protected $data;
    protected $user;
    protected $nailsErrorHandler;
    protected $log;

    // --------------------------------------------------------------------------

    /**
     * Build the main framework. All autoloaded items have been loaded and
     * instantiated by this point and are safe to use.
     */
    public function __construct()
    {
        parent::__construct();

        // --------------------------------------------------------------------------

        //  Include the composer autoloader
        if (!file_exists(FCPATH . 'vendor/autoload.php')) {

            $_ERROR = 'Composer autoloader not found; run <code>composer install</code> to install dependencies';

            include NAILS_COMMON_PATH . 'errors/startup_error.php';
        }

        require_once FCPATH . 'vendor/autoload.php';

        // --------------------------------------------------------------------------

        //  Set up services
        \Nails\Factory::setup();

        // --------------------------------------------------------------------------

        //  Is Nails in maintenance mode?
        $this->maintenanceMode();

        // --------------------------------------------------------------------------

        //  Nails PHP Version Check
        $this->checkPhpVersion();

        // --------------------------------------------------------------------------

        //  Configure logging and error reporting
        // $this->setLogging();
        $this->setErrorReporting();

        // --------------------------------------------------------------------------

        //  Set the default content-type
        $this->output->set_content_type('text/html; charset=utf-8');

        // --------------------------------------------------------------------------

        //  Define data array (used extensively in views)
        $this->data =& getControllerData();

        // --------------------------------------------------------------------------

        //  Define all the packages
        $this->autoloadItems();

        // --------------------------------------------------------------------------

        /**
         * If we're on a staging environment then prompt for a password; but only if
         * a password has been defined in app.php
         */

        $this->staging();

        // --------------------------------------------------------------------------

        //  Test that the cache is writeable
        $this->testCache();

        // --------------------------------------------------------------------------

        //  Instanciate the user model
        $this->instantiateUser();

        // --------------------------------------------------------------------------

        //  Instanciate languages
        $this->instantiateLanguages();

        // --------------------------------------------------------------------------

        /**
         * Is the user suspended?
         * Executed here so that both the user and language systems are initialised
         * (so that any errors can be shown in the correct language).
         */

        $this->isUserSuspended();

        // --------------------------------------------------------------------------

        //  Instanciate DateTime
        $this->instantiateDateTime();

        // --------------------------------------------------------------------------

        //  Need to generate the routes_app.php file?
        if (defined('NAILS_STARTUP_GENERATE_APP_ROUTES') && NAILS_STARTUP_GENERATE_APP_ROUTES) {

            $this->load->model('routes_model');

            if (!$this->routes_model->update()) {

                //  Fall over, routes_app.php *must* be there
                $subject  = 'Failed To generate routes_app.php';
                $message  = 'routes_app.php was not found and could not be generated. ';
                $message .= $this->routes_model->last_error();

                showFatalError($subject, $message);

            } else {

                //  Routes exist now, instruct the browser to try again
                if ($this->input->post()) {

                    redirect($this->input->server('REQUEST_URI'), 'Location', 307);

                } else {

                    redirect($this->input->server('REQUEST_URI'));
                }
            }
        }

        // --------------------------------------------------------------------------

        //  Set User Feedback alerts for the views
        $this->data['notice']  = $this->userFeedback->get('notice')  ?: $this->session->flashdata('notice');
        $this->data['message'] = $this->userFeedback->get('message') ?: $this->session->flashdata('message');
        $this->data['error']   = $this->userFeedback->get('error')   ?: $this->session->flashdata('error');
        $this->data['success'] = $this->userFeedback->get('success') ?: $this->session->flashdata('success');

        // --------------------------------------------------------------------------

        //  Other defaults
        $this->data['page']                   = new stdClass();
        $this->data['page']->title            = '';
        $this->data['page']->seo              = new stdClass();
        $this->data['page']->seo->title       = '';
        $this->data['page']->seo->description = '';
        $this->data['page']->seo->keywords    = '';

        // --------------------------------------------------------------------------

        /**
         * Forced maintenance mode?
         */
        if (app_setting('maintenance_mode_enabled', 'site')) {

            $this->maintenanceMode(true);
        }

        // --------------------------------------------------------------------------

        /**
         * Finally, set some meta tags which should be used on every site.
         */

        $this->meta->addRaw(array(
            'charset' => 'utf8'
        ));

        $this->meta->addRaw(array(
            'name'    => 'viewport',
            'content' => 'width=device-width, initial-scale=1'
        ));
    }

    // --------------------------------------------------------------------------

    /**
     * Checks that the version of PHP is sufficient to run all enabled modules
     * @return void
     */
    protected function checkPhpVersion()
    {
        /**
         * PHP Version Check
         * =================
         *
         * We need to loop through all available modules and have a look at what version
         * of PHP they require, we'll then take the highest version and set that as our
         * minimum supported value.
         *
         * To set a requirement, within the module's nails object in composer.json,
         * specify the minPhpVersion value. You should also specify the appropriate
{'fraction_non_alphanumeric': 0.31948746831878344, 'fraction_numerical': 0.0007744297381019432, 'mean_word_length': 0.9701803051317615, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3926277', 'n_tokens_mistral': 3147, 'n_tokens_neox': 2967, 'n_words': 783}