<commit_before><?php

/**
 * @file Controller.php
 * This file is part of MOVIM.
 *
 * @brief Implements a request handler that ensures application worklfow.
 *
 * @author Movim Project <<EMAIL>>
 *
 * @version 1.0
 * @date 13 October 2010
 *
 * Copyright (C)2010 Movim Project
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

class ControllerBase
{
    protected $default_handler = 'index';
    protected $token;

    public function __construct($token = 'q')
    {
        $this->load_language();
        $this->token = $token;
    }

    public function handle()
    {
        $r = new Route();
        // Note that the request is always specified by 'q'.
        if($request = $this->fetch_get('q')) {
            $this->run_req($request);
        } else {
            $this->error404();
        }
    }

    /**
     * Loads up the language, either from the User or default.
     */
    function load_language() {
        $user = new user();
        if($user->isLogged()) {
            try{
                $lang = $user->getConfig('language');
                load_language($lang);
            }
            catch(MovimException $e) {
                // Load default language.
                load_language(Conf::getServerConfElement('defLang'));
            }
        }
        else if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
            load_language_auto();
        }
        else {
            load_language(Conf::getServerConfElement('defLang'));
        }
    }

    /**
     * Attempts to call back the given function.
     */
    protected function run_req($request)
    {
        if(is_callable(array($this, $request))) {
            call_user_func(array($this, $request));
        } else {
            die('not found query');
        }
    }

    /**
     * Returns the value of a $_GET variable. Mainly used to avoid getting
     * notices from PHP when attempting to fetch an empty variable.
     * @param name is the desired variable's name.
     * @return the value of the requested variable, or FALSE.
     */
    protected function fetch_get($name)
    {
        if(isset($_GET[$name])) {
            return htmlentities($_GET[$name]);
        } else {
            return false;<commit_msg>- Forget some namespaces<commit_after><?php

/**
 * @file Controller.php
 * This file is part of MOVIM.
 *
 * @brief Implements a request handler that ensures application worklfow.
 *
 * @author Movim Project <<EMAIL>>
 *
 * @version 1.0
 * @date 13 October 2010
 *
 * Copyright (C)2010 Movim Project
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

class ControllerBase
{
    protected $default_handler = 'index';
    protected $token;

    public function __construct($token = 'q')
    {
        $this->load_language();
        $this->token = $token;
    }

    public function handle()
    {
        $r = new Route();
        // Note that the request is always specified by 'q'.
        if($request = $this->fetch_get('q')) {
            $this->run_req($request);
        } else {
            $this->error404();
        }
    }

    /**
     * Loads up the language, either from the User or default.
     */
    function load_language() {
        $user = new user();
        if($user->isLogged()) {
            try{
                $lang = $user->getConfig('language');
                load_language($lang);
            }
            catch(MovimException $e) {
                // Load default language.
                load_language(\system\Conf::getServerConfElement('defLang'));
            }
        }
        else if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
            load_language_auto();
        }
        else {
            load_language(\system\Conf::getServerConfElement('defLang'));
        }
    }

    /**
     * Attempts to call back the given function.
     */
    protected function run_req($request)
    {
        if(is_callable(array($this, $request))) {
            call_user_func(array($this, $request));
        } else {
            die('not found query');
        }
    }

    /**
     * Returns the value of a $_GET variable. Mainly used to avoid getting
     * notices from PHP when attempting to fetch an empty variable.
     * @param name is the desired variable's name.
     * @return the value of the requested variable, or FALSE.
     */
    protected function fetch_get($name)
    {
        if(isset($_GET[$name])) {
            return htmlentities($_GET[$name]);
        } else {
            return false;
{'fraction_non_alphanumeric': 0.1079615048118985, 'fraction_numerical': 0.0055993000874890635, 'mean_word_length': 2.1737923375902275, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6944575', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1517, 'n_words': 530}