public function initialize() { // check if the user is logged in $this->validateLogin(); // named application if (!defined('NAMED_APPLICATION')) { define('NAMED_APPLICATION', 'BackendAjax'); } // get values from the GET-parameters $module = isset($_GET['fork']['module']) ? $_GET['fork']['module'] : ''; $action = isset($_GET['fork']['action']) ? $_GET['fork']['action'] : ''; $language = isset($_GET['fork']['language']) ? $_GET['fork']['language'] : SITE_DEFAULT_LANGUAGE; // overrule the values with the ones provided through POST $module = isset($_POST['fork']['module']) ? $_POST['fork']['module'] : $module; $action = isset($_POST['fork']['action']) ? $_POST['fork']['action'] : $action; $language = isset($_POST['fork']['language']) ? $_POST['fork']['language'] : $language; try { // create URL instance, since the template modifiers need this object $URL = new Url($this->getKernel()); $URL->setModule($module); $this->setModule($module); $this->setAction($action); $this->setLanguage($language); // create a new action $this->ajaxAction = new AjaxAction($this->getKernel()); $this->ajaxAction->setModule($this->getModule()); $this->ajaxAction->setAction($this->getAction()); } catch (Exception $e) { $this->ajaxAction = new BackendBaseAJAXAction($this->getKernel()); $this->ajaxAction->output(BackendBaseAJAXAction::ERROR, null, $e->getMessage()); } }
/** * This method exists because the service container needs to be set before * the page's functionality gets loaded. */ public function initialize() { $url = new Url($this->getKernel()); new TwigTemplate(); new Navigation($this->getKernel()); new Header($this->getKernel()); $this->action = new Action($this->getKernel()); $this->action->setModule($url->getModule()); $this->action->setAction($url->getAction()); }
/** * Parse the header into the template */ public function parse() { // put the page title in the <title> $this->tpl->assign('page_title', BL::getLabel($this->URL->getModule())); // parse CSS $this->parseCSS(); // parse JS $this->parseJS(); }
/** * Display, this wil output the template to the browser * If no template is specified we build the path form the current module and action * * @param string $template The template to use, if not provided it will be based on the action. */ public function display($template = null) { // parse header $this->header->parse(); /* * If no template is specified, we have to build the path ourself. The default template is * based on the name of the current action */ if ($template === null) { $template = $this->getBackendModulePath() . '/Layout/Templates/' . $this->URL->getAction() . '.tpl'; } $this->content = $this->tpl->getContent($template); }
/** * Try to determine the selected state * * @param array $value The value. * @param int $key The key. * @param array $keys The previous marked keys. * @return mixed */ private function compareURL(array $value, $key, $keys = array()) { // create active url $activeURL = $this->URL->getModule() . '/' . $this->URL->getAction(); // we use the lowercased versions in the url $activeURL = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $activeURL)); // add current key $keys[] = $key; // sub action? if (isset($value['selected_for']) && in_array($activeURL, (array) $value['selected_for'])) { return $keys; } // if the URL is available and same as the active one we have what we need. if (isset($value['url']) && $value['url'] == $activeURL) { if (isset($value['children'])) { // loop the children foreach ($value['children'] as $key => $value) { // recursive here... $subKeys = $this->compareURL($value, $key, $keys); // wrap it up if (!empty($subKeys)) { return $subKeys; } } } // fallback return $keys; } // any children if (isset($value['children'])) { // loop the children foreach ($value['children'] as $key => $value) { // recursive here... $subKeys = $this->compareURL($value, $key, $keys); // wrap it up if (!empty($subKeys)) { return $subKeys; } } } }
/** * @param Form $form An instance of Form, the elements will be parsed in here. * @param int $metaId The metaID to load. * @param string $baseFieldName The field where the URL should be based on. * @param bool $custom Add/show custom-meta. * * @throws Exception */ public function __construct(Form $form, $metaId = null, $baseFieldName = 'title', $custom = false) { // check if URL is available from the reference if (!BackendModel::getContainer()->has('url')) { throw new Exception('URL should be available in the reference.'); } // get BackendURL instance $this->URL = BackendModel::getContainer()->get('url'); // should we use meta-custom $this->custom = (bool) $custom; // set form instance $this->frm = $form; // set base field name $this->baseFieldName = (string) $baseFieldName; // metaId was specified, so we should load the item if ($metaId !== null) { $this->loadMeta($metaId); } // set default callback $this->setURLCallback('Backend\\Modules\\' . $this->URL->getModule() . '\\Engine\\Model', 'getURL'); // load the form $this->loadForm(); }