public function __construct() { // define the Named Application if (!defined('NAMED_APPLICATION')) { define('NAMED_APPLICATION', 'backend'); } // set the module $this->setModule(SpoonFilter::getGetValue('module', null, '')); // set the requested file $this->setFile(SpoonFilter::getGetValue('file', null, '')); // set the language $this->setLanguage(SpoonFilter::getGetValue('language', array_keys(BackendLanguage::getWorkingLanguages()), SITE_DEFAULT_LANGUAGE)); // build the path if ($this->module == 'core') { $path = BACKEND_CORE_PATH . '/js/' . $this->getFile(); } else { $path = BACKEND_MODULES_PATH . '/' . $this->getModule() . '/js/' . $this->getFile(); } // set correct headers SpoonHTTP::setHeaders('content-type: application/javascript'); // create a new template instance (this will handle all stuff for us) $tpl = new BackendTemplate(); // enable addslashes on each locale $tpl->setAddSlashes(true); // display $tpl->display($path, true); }
/** * Load the form */ private function loadForm() { if ($this->getParameter('id') != null) { // get the translation $translation = BackendLocaleModel::get($this->getParameter('id', 'int')); // if not empty, set the filter if (!empty($translation)) { // we are copying the given translation $isCopy = true; } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing' . $this->filterQuery); } } else { $isCopy = false; } // create form $this->frm = new BackendForm('add', BackendModel::createURLForAction() . $this->filterQuery); // create and add elements $this->frm->addDropdown('application', array('backend' => 'Backend', 'frontend' => 'Frontend'), $isCopy ? $translation['application'] : $this->filter['application']); $this->frm->addDropdown('module', BackendModel::getModulesForDropDown(false), $isCopy ? $translation['module'] : $this->filter['module']); $this->frm->addDropdown('type', BackendLocaleModel::getTypesForDropDown(), $isCopy ? $translation['type'] : $this->filter['type'][0]); $this->frm->addText('name', $isCopy ? $translation['name'] : $this->filter['name']); $this->frm->addTextarea('value', $isCopy ? $translation['value'] : $this->filter['value'], null, null, null, true); $this->frm->addDropdown('language', BackendLanguage::getWorkingLanguages(), $isCopy ? $translation['language'] : $this->filter['language'][0]); }
/** * Execute the action * We will build the classname, require the class and call the execute method. */ public function execute() { $this->loadConfig(); // is the requested action possible? If not we throw an exception. We don't redirect because that could trigger a redirect loop if (!in_array($this->getAction(), $this->config->getPossibleActions())) { throw new BackendException('This is an invalid action (' . $this->getAction() . ').'); } // build action-class-name $actionClassName = SpoonFilter::toCamelCase('backend_' . $this->getModule() . '_' . $this->getAction()); // require the config file, we know it is there because we validated it before (possible actions are defined by existance off the file). require_once BACKEND_MODULE_PATH . '/actions/' . $this->getAction() . '.php'; // validate if class exists (aka has correct name) if (!class_exists($actionClassName)) { throw new BackendException('The actionfile is present, but the classname should be: ' . $actionClassName . '.'); } // get working languages $languages = BackendLanguage::getWorkingLanguages(); $workingLanguages = array(); // loop languages and build an array that we can assign foreach ($languages as $abbreviation => $label) { $workingLanguages[] = array('abbr' => $abbreviation, 'label' => $label, 'selected' => $abbreviation == BackendLanguage::getWorkingLanguage()); } // assign the languages $this->tpl->assign('workingLanguages', $workingLanguages); // create action-object $object = new $actionClassName(); $object->execute(); }
/** * Load the form */ private function loadForm() { $this->frm = new BackendForm('edit', BackendModel::createURLForAction(null, null, null, array('id' => $this->id)) . $this->filterQuery); $this->frm->addDropdown('application', array('backend' => 'backend', 'frontend' => 'frontend'), $this->record['application']); $this->frm->addDropdown('module', BackendModel::getModulesForDropDown(false), $this->record['module']); $this->frm->addDropdown('type', BackendLocaleModel::getTypesForDropDown(), $this->record['type']); $this->frm->addText('name', $this->record['name']); $this->frm->addTextarea('value', $this->record['value'], null, 'inputText', 'inputTextError', true); $this->frm->addDropdown('language', BackendLanguage::getWorkingLanguages(), $this->record['language']); }
/** * Set the language * * @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); }
/** * 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); }
/** * 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); } } } } }
/** * Process the querystring */ 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 if ($positionQuestionMark === false) { $processedQueryString = $queryString; } else { $processedQueryString = 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 = ''; if (isset($chunks[1]) && $chunks[1] != '') { $language = 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) { // check if module path is not yet defined if (!defined('BACKEND_MODULE_PATH')) { // build path for core if ($module == 'core') { define('BACKEND_MODULE_PATH', BACKEND_PATH . '/' . $module); } else { 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')) { // in debug mode we want to see the error if (SPOON_DEBUG) { throw new BackendException('The configfile for the module (' . $module . ') can\'t be found.'); } else { // @todo don't use redirects for error, we should have something like an invoke method. // build the url $errorUrl = '/' . NAMED_APPLICATION . '/' . $language . '/error?type=action-not-allowed'; // add the querystring, it will be processed by the error-handler $errorUrl .= '&querystring=' . urlencode('/' . $this->getQueryString()); // redirect to the error page SpoonHTTP::redirect($errorUrl); } } // 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) { $this->setModule(isset($_POST['fork']['module']) ? $_POST['fork']['module'] : ''); $this->setAction(isset($_POST['fork']['action']) ? $_POST['fork']['action'] : ''); BackendLanguage::setWorkingLanguage(isset($_POST['fork']['language']) ? $_POST['fork']['language'] : SITE_DEFAULT_LANGUAGE); } else { $this->processRegularRequest($module, $action, $language); } }