/** * Set language * * @param string $value The language to load. */ public function setLanguage($value) { // get the possible languages $possibleLanguages = BackendLanguage::getWorkingLanguages(); // validate if (!in_array($value, array_keys($possibleLanguages))) { throw new BackendException('Invalid language.'); } // set property $this->language = $value; // set the locale (we need this for the labels) BackendLanguage::setLocale($this->language); // set working language BackendLanguage::setWorkingLanguage($this->language); }
/** * Set language * * @param string $value The language to load. */ private function setLanguage($value) { // set property $this->language = (string) $value; // is this a authenticated user? if (BackendAuthentication::isLoggedIn()) { $language = BackendAuthentication::getUser()->getSetting('interface_language'); } else { $language = BackendModel::getModuleSetting('core', 'default_interface_language'); } // set the locale (we need this for the labels) BackendLanguage::setLocale($language); // set the working language BackendLanguage::setWorkingLanguage($this->language); }
/** * Process the querystring * * @return void */ private function processQueryString() { // store the querystring local, so we don't alter it. $queryString = $this->getQueryString(); // find the position of ? (which seperates real URL and GET-parameters) $positionQuestionMark = strpos($queryString, '?'); // remove the GET-chunk from the parameters $processedQueryString = $positionQuestionMark === false ? $queryString : substr($queryString, 0, $positionQuestionMark); // split into chunks, a Backend URL will always look like /<lang>/<module>/<action>(?GET) $chunks = (array) explode('/', trim($processedQueryString, '/')); // check if this is a request for a JS-file $isJS = isset($chunks[1]) && $chunks[1] == 'js.php'; // check if this is a request for a AJAX-file $isAJAX = isset($chunks[1]) && $chunks[1] == 'ajax.php'; // get the language, this will always be in front $language = isset($chunks[1]) && $chunks[1] != '' ? SpoonFilter::getValue($chunks[1], array_keys(BackendLanguage::getWorkingLanguages()), '') : ''; // no language provided? if ($language == '' && !$isJS && !$isAJAX) { // remove first element array_shift($chunks); // redirect to login SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . SITE_DEFAULT_LANGUAGE . '/' . implode('/', $chunks)); } // get the module, null will be the default $module = isset($chunks[2]) && $chunks[2] != '' ? $chunks[2] : 'dashboard'; // get the requested action, if it is passed if (isset($chunks[3]) && $chunks[3] != '') { $action = $chunks[3]; } elseif (!$isJS && !$isAJAX) { // build path to the module and define it. This is a constant because we can use this in templates. if (!defined('BACKEND_MODULE_PATH')) { define('BACKEND_MODULE_PATH', BACKEND_MODULES_PATH . '/' . $module); } // check if the config is present? If it isn't present there is a huge problem, so we will stop our code by throwing an error if (!SpoonFile::exists(BACKEND_MODULE_PATH . '/config.php')) { throw new BackendException('The configfile for the module (' . $module . ') can\'t be found.'); } // build config-object-name $configClassName = 'Backend' . SpoonFilter::toCamelCase($module . '_config'); // require the config file, we validated before for existence. require_once BACKEND_MODULE_PATH . '/config.php'; // validate if class exists (aka has correct name) if (!class_exists($configClassName)) { throw new BackendException('The config file is present, but the classname should be: ' . $configClassName . '.'); } // create config-object, the constructor will do some magic $config = new $configClassName($module); // set action $action = $config->getDefaultAction() !== null ? $config->getDefaultAction() : 'index'; } // if it is an request for a JS-file or an AJAX-file we only need the module if ($isJS || $isAJAX) { // set the working language, this is not the interface language BackendLanguage::setWorkingLanguage(SpoonFilter::getGetValue('language', null, SITE_DEFAULT_LANGUAGE)); // set current module $this->setModule(SpoonFilter::getGetValue('module', null, null)); // set action $this->setAction('index'); } else { // the person isn't logged in? or the module doesn't require authentication if (!BackendAuthentication::isLoggedIn() && !BackendAuthentication::isAllowedModule($module)) { // redirect to login SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/authentication/?querystring=' . urlencode('/' . $this->getQueryString())); } else { // does our user has access to this module? if (!BackendAuthentication::isAllowedModule($module)) { // the user doesn't have access, redirect to error page SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/error?type=module-not-allowed&querystring=' . urlencode('/' . $this->getQueryString())); } else { // can our user execute the requested action? if (!BackendAuthentication::isAllowedAction($action, $module)) { // the user hasn't access, redirect to error page SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/error?type=action-not-allowed&querystring=' . urlencode('/' . $this->getQueryString())); } else { // set the working language, this is not the interface language BackendLanguage::setWorkingLanguage($language); // is the user authenticated if (BackendAuthentication::getUser()->isAuthenticated()) { // set interface language based on the user preferences BackendLanguage::setLocale(BackendAuthentication::getUser()->getSetting('interface_language', 'nl')); } else { // init var $interfaceLanguage = BackendModel::getModuleSetting('core', 'default_interface_language'); // override with cookie value if that exists if (SpoonCookie::exists('interface_language') && in_array(SpoonCookie::get('interface_language'), array_keys(BackendLanguage::getInterfaceLanguages()))) { // set interface language based on the perons' cookies $interfaceLanguage = SpoonCookie::get('interface_language'); } // set interface language BackendLanguage::setLocale($interfaceLanguage); } // set current module $this->setModule($module); $this->setAction($action); } } } } }
/** * Set the language * * @return void * @param string $value The language to set. */ public function setLanguage($value) { // get the possible languages $possibleLanguages = BackendLanguage::getWorkingLanguages(); // validate if (!in_array($value, array_keys($possibleLanguages))) { // set correct headers SpoonHTTP::setHeadersByCode(500); // output $fakeAction = new BackendBaseAJAXAction('', ''); $fakeAction->output(BackendBaseAJAXAction::FORBIDDEN, null, 'Languages not provided.'); } // set working language BackendLanguage::setWorkingLanguage($value); }
/** * Process a regular request * * @param string $module The requested module. * @param string $action The requested action. * @param strring $language The requested language. */ private function processRegularRequest($module, $action, $language) { // the person isn't logged in? or the module doesn't require authentication if (!BackendAuthentication::isLoggedIn() && !BackendAuthentication::isAllowedModule($module)) { // redirect to login SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/authentication/?querystring=' . urlencode('/' . $this->getQueryString())); } else { // does our user has access to this module? if (!BackendAuthentication::isAllowedModule($module)) { // if the module is the dashboard redirect to the first allowed module if ($module == 'dashboard') { // require navigation-file require_once BACKEND_CACHE_PATH . '/navigation/navigation.php'; // loop the navigation to find the first allowed module foreach ($navigation as $key => $value) { // split up chunks list($module, $action) = explode('/', $value['url']); // user allowed? if (BackendAuthentication::isAllowedModule($module)) { // redirect to the page SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/' . $value['url']); } } } // the user doesn't have access, redirect to error page SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/error?type=module-not-allowed&querystring=' . urlencode('/' . $this->getQueryString())); } else { // can our user execute the requested action? if (!BackendAuthentication::isAllowedAction($action, $module)) { // the user hasn't access, redirect to error page SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/error?type=action-not-allowed&querystring=' . urlencode('/' . $this->getQueryString())); } else { // set the working language, this is not the interface language BackendLanguage::setWorkingLanguage($language); $this->setLocale(); $this->setModule($module); $this->setAction($action); } } } }