<commit_before><?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2014 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*	$Id$                                               *
********************************************************************************************************/

/**
 * The request-dispatcher is called by all external request-entries and acts as a controller.
 * It dispatches the requests to the matching modules and areas, taking care of login-status and more.
 *
 * @package module_system
 * @author <EMAIL>
 * @since 3.4.1
 */
class class_request_dispatcher {

    private $arrTimestampStart;

    /**
     * @var class_response_object
     */
    private $objResponse = null;

    /**
     * @var class_session
     */
    private $objSession;

    /**
     * Standard constructor
     *
     * @param class_response_object $objResponse
     *
     * @return \class_request_dispatcher
     */
    public function __construct(class_response_object $objResponse) {
        $this->arrTimestampStart = gettimeofday();
        $this->objSession = class_carrier::getInstance()->getObjSession();
        $this->objResponse = $objResponse;
    }

    /**
     * Global controller entry, triggers all further actions, splits up admin- and portal loading
     *
     * @param bool $bitAdmin
     * @param string $strModule
     * @param string $strAction
     * @param string $strLanguageParam
     *
     * @return string
     */
    public function processRequest($bitAdmin, $strModule, $strAction, $strLanguageParam) {

        if($bitAdmin) {
            $strReturn = $this->processAdminRequest($strModule, $strAction, $strLanguageParam);
            $strReturn = $this->callScriptlets($strReturn, interface_scriptlet::BIT_CONTEXT_ADMIN);
        }
        else {
            $strReturn = $this->processPortalRequest($strModule, $strAction, $strLanguageParam);
            $strReturn = $this->callScriptlets($strReturn, interface_scriptlet::BIT_CONTEXT_PORTAL_PAGE);
        }


        $strReturn = $this->cleanupOutput($strReturn);
        $strReturn = $this->getDebugInfo($strReturn);
        $this->sendConditionalGetHeaders($strReturn);

        $this->objResponse->setStrContent($strReturn);
        $this->objSession->sessionClose();
    }

    /**
     * Processes an admin-request
     *
     * @param string $strModule
     * @param string $strAction
     * @param string $strLanguageParam
     *
     * @throws class_exception
     * @return string
     */
    private function processAdminRequest($strModule, $strAction, $strLanguageParam) {
        $strReturn = "";
        $bitLogin = false;

        //validate https status
        if(_admin_only_https_ == "true") {
            //check which headers to compare
            $strHeaderName = class_carrier::getInstance()->getObjConfig()->getConfig("https_header");
            $strHeaderValue = strtolower(class_carrier::getInstance()->getObjConfig()->getConfig("https_header_value"));

            //header itself given?
            if(!issetServer($strHeaderName)) {
                //reload to https
                if(_xmlLoader_ === true) {
                    class_response_object::getInstance()->setStrRedirectUrl(uniStrReplace("http:", "https:", _xmlpath_) . "?" . getServer("QUERY_STRING"));
                }
                else {
                    class_response_object::getInstance()->setStrRedirectUrl(uniStrReplace("http:", "https:", _indexpath_) . "?" . getServer("QUERY_STRING"));
                }

                class_response_object::getInstance()->sendHeaders();
                die("Reloading using https...");
            }
            //value of header correct?
            else if($strHeaderValue != "" && $strHeaderValue != strtolower(getServer($strHeaderName))) {
                //reload to https
                if(_xmlLoader_ === true) {
                    class_response_object::getInstance()->setStrRedirectUrl(uniStrReplace("http:", "https:", _xmlpath_) . "?" . getServer("QUERY_STRING"));
                }
                else {
                    class_response_object::getInstance()->setStrRedirectUrl(uniStrReplace("http:", "https:", _indexpath_) . "?" . getServer("QUERY_STRING"));
                }

                class_response_object::getInstance()->sendHeaders();
                die("Reloading using https...");
            }
        }

        //process language-param
        $objLanguage = new class_module_languages_language();
        $objLanguage->setStrAdminLanguageToWorkOn($strLanguageParam);

        //set the current backend skin. right here to do it only once.
        class_adminskin_helper::defineSkinWebpath();

        //validate login-status / process login-request
        if($strModule != "login" && $this->objSession->isLoggedin()) {
            if($this->objSession->isAdmin()) {
                //try to load the module
                $objModuleRequested = class_module_system_module::getModuleByName($strModule);
                if($objModuleRequested != null) {

                    //see if there is data from a previous, failed request
                    if(class_carrier::getInstance()->getObjSession()->getSession(class_module_login_admin::SESSION_LOAD_FROM_PARAMS) === "true") {
                        foreach(class_carrier::getInstance()->getObjSession()->getSession(class_module_login_admin::SESSION_PARAMS) as $strOneKey => $strOneVal)
                            class_carrier::getInstance()->setParam($strOneKey, $strOneVal);

                        class_carrier::getInstance()->getObjSession()->sessionUnset(class_module_login_admin::SESSION_LOAD_FROM_PARAMS);
                        class_carrier::getInstance()->getObjSession()->sessionUnset(class_module_login_admin::SESSION_PARAMS);
                    }


                    if(_xmlLoader_) {
                        if($objModuleRequested->getStrXmlNameAdmin() != "") {
                            $strClassname = str_replace(".php", "", $objModuleRequested->getStrXmlNameAdmin());
                            $objConcreteModule = new $strClassname();
                            $strReturn = $objConcreteModule->action($strAction);
                        }
                        else {
                            //xml-loader not defined, try to use the regular dispatcher
                            $objConcreteModule = $objModuleRequested->getAdminInstanceOfConcreteModule();
                            $strReturn = $objConcreteModule->action($strAction);
                        }
                    }
                    else {

                        //fill the history array to track actions
                        $objHistory = new class_history();
                        //Writing to the history
                        if(class_carrier::getInstance()->getParam("folderview") == "") {
                            $objHistory->setAdminHistory();
                        }

                        //execute the action only if peClose is not set
                        if(class_carrier::getInstance()->getParam("peClose") != "1") {
                            $objConcreteModule = $objModuleRequested->getAdminInstanceOfConcreteModule();
                            //$objConcreteModule->action($strAction);
                            $objConcreteModule->action();
                            $strReturn = $objConcreteModule->getModuleOutput();
                        }

                        //React, if admin was opened by the portaleditor
                        if(class_carrier::getInstance()->getParam("peClose") == "1") {<commit_msg>Revert "module_system | class_request_dispatcher -> if parameter peClose is set then no action will be exectuted anymore"<commit_after><?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2014 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*	$Id$                                               *
********************************************************************************************************/

/**
 * The request-dispatcher is called by all external request-entries and acts as a controller.
 * It dispatches the requests to the matching modules and areas, taking care of login-status and more.
 *
 * @package module_system
 * @author <EMAIL>
 * @since 3.4.1
 */
class class_request_dispatcher {

    private $arrTimestampStart;

    /**
     * @var class_response_object
     */
    private $objResponse = null;

    /**
     * @var class_session
     */
    private $objSession;

    /**
     * Standard constructor
     *
     * @param class_response_object $objResponse
     *
     * @return \class_request_dispatcher
     */
    public function __construct(class_response_object $objResponse) {
        $this->arrTimestampStart = gettimeofday();
        $this->objSession = class_carrier::getInstance()->getObjSession();
        $this->objResponse = $objResponse;
    }

    /**
     * Global controller entry, triggers all further actions, splits up admin- and portal loading
     *
     * @param bool $bitAdmin
     * @param string $strModule
     * @param string $strAction
     * @param string $strLanguageParam
     *
     * @return string
     */
    public function processRequest($bitAdmin, $strModule, $strAction, $strLanguageParam) {

        if($bitAdmin) {
            $strReturn = $this->processAdminRequest($strModule, $strAction, $strLanguageParam);
            $strReturn = $this->callScriptlets($strReturn, interface_scriptlet::BIT_CONTEXT_ADMIN);
        }
        else {
            $strReturn = $this->processPortalRequest($strModule, $strAction, $strLanguageParam);
            $strReturn = $this->callScriptlets($strReturn, interface_scriptlet::BIT_CONTEXT_PORTAL_PAGE);
        }


        $strReturn = $this->cleanupOutput($strReturn);
        $strReturn = $this->getDebugInfo($strReturn);
        $this->sendConditionalGetHeaders($strReturn);

        $this->objResponse->setStrContent($strReturn);
        $this->objSession->sessionClose();
    }

    /**
     * Processes an admin-request
     *
     * @param string $strModule
     * @param string $strAction
     * @param string $strLanguageParam
     *
     * @throws class_exception
     * @return string
     */
    private function processAdminRequest($strModule, $strAction, $strLanguageParam) {
        $strReturn = "";
        $bitLogin = false;

        //validate https status
        if(_admin_only_https_ == "true") {
            //check which headers to compare
            $strHeaderName = class_carrier::getInstance()->getObjConfig()->getConfig("https_header");
            $strHeaderValue = strtolower(class_carrier::getInstance()->getObjConfig()->getConfig("https_header_value"));

            //header itself given?
            if(!issetServer($strHeaderName)) {
                //reload to https
                if(_xmlLoader_ === true) {
                    class_response_object::getInstance()->setStrRedirectUrl(uniStrReplace("http:", "https:", _xmlpath_) . "?" . getServer("QUERY_STRING"));
                }
                else {
                    class_response_object::getInstance()->setStrRedirectUrl(uniStrReplace("http:", "https:", _indexpath_) . "?" . getServer("QUERY_STRING"));
                }

                class_response_object::getInstance()->sendHeaders();
                die("Reloading using https...");
            }
            //value of header correct?
            else if($strHeaderValue != "" && $strHeaderValue != strtolower(getServer($strHeaderName))) {
                //reload to https
                if(_xmlLoader_ === true) {
                    class_response_object::getInstance()->setStrRedirectUrl(uniStrReplace("http:", "https:", _xmlpath_) . "?" . getServer("QUERY_STRING"));
                }
                else {
                    class_response_object::getInstance()->setStrRedirectUrl(uniStrReplace("http:", "https:", _indexpath_) . "?" . getServer("QUERY_STRING"));
                }

                class_response_object::getInstance()->sendHeaders();
                die("Reloading using https...");
            }
        }

        //process language-param
        $objLanguage = new class_module_languages_language();
        $objLanguage->setStrAdminLanguageToWorkOn($strLanguageParam);

        //set the current backend skin. right here to do it only once.
        class_adminskin_helper::defineSkinWebpath();

        //validate login-status / process login-request
        if($strModule != "login" && $this->objSession->isLoggedin()) {
            if($this->objSession->isAdmin()) {
                //try to load the module
                $objModuleRequested = class_module_system_module::getModuleByName($strModule);
                if($objModuleRequested != null) {

                    //see if there is data from a previous, failed request
                    if(class_carrier::getInstance()->getObjSession()->getSession(class_module_login_admin::SESSION_LOAD_FROM_PARAMS) === "true") {
                        foreach(class_carrier::getInstance()->getObjSession()->getSession(class_module_login_admin::SESSION_PARAMS) as $strOneKey => $strOneVal)
                            class_carrier::getInstance()->setParam($strOneKey, $strOneVal);

                        class_carrier::getInstance()->getObjSession()->sessionUnset(class_module_login_admin::SESSION_LOAD_FROM_PARAMS);
                        class_carrier::getInstance()->getObjSession()->sessionUnset(class_module_login_admin::SESSION_PARAMS);
                    }


                    if(_xmlLoader_) {
                        if($objModuleRequested->getStrXmlNameAdmin() != "") {
                            $strClassname = str_replace(".php", "", $objModuleRequested->getStrXmlNameAdmin());
                            $objConcreteModule = new $strClassname();
                            $strReturn = $objConcreteModule->action($strAction);
                        }
                        else {
                            //xml-loader not defined, try to use the regular dispatcher
                            $objConcreteModule = $objModuleRequested->getAdminInstanceOfConcreteModule();
                            $strReturn = $objConcreteModule->action($strAction);
                        }
                    }
                    else {

                        //fill the history array to track actions
                        $objHistory = new class_history();
                        //Writing to the history
                        if(class_carrier::getInstance()->getParam("folderview") == "") {
                            $objHistory->setAdminHistory();
                        }

                        $objConcreteModule = $objModuleRequested->getAdminInstanceOfConcreteModule();
                        //$objConcreteModule->action($strAction);
                        $objConcreteModule->action();
                        $strReturn = $objConcreteModule->getModuleOutput();

                        //React, if admin was opened by the portaleditor
                        if(class_carrier::getInstance()->getParam("peClose") == "1") {
{'fraction_non_alphanumeric': 0.14903213681638788, 'fraction_numerical': 0.0028190189813944748, 'mean_word_length': 1.9579395960718917, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4223234', 'n_tokens_mistral': 3925, 'n_tokens_neox': 3717, 'n_words': 705}