/** * Load the record * * @return void */ private function loadData() { // get record $this->id = $this->getParameter('id', 'int'); // validate id if ($this->id === null || !BackendPagesModel::existsTemplate($this->id)) { $this->redirect(BackendModel::createURLForAction('templates') . '&error=non-existing'); } // get the record $this->record = BackendPagesModel::getTemplate($this->id); // unserialize $this->record['data'] = unserialize($this->record['data']); // assign $this->tpl->assign('template', $this->record); // is the template being used $inUse = BackendPagesModel::isTemplateInUse($this->id); // determine if deleting is allowed $deleteAllowed = true; if ($this->record['id'] == BackendModel::getModuleSetting($this->getModule(), 'default_template')) { $deleteAllowed = false; } elseif (count(BackendPagesModel::getTemplates()) == 1) { $deleteAllowed = false; } elseif ($inUse) { $deleteAllowed = false; } // assign $this->tpl->assign('inUse', $inUse); $this->tpl->assign('deleteAllowed', $deleteAllowed); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably edit some general CSS/JS or other required files parent::execute(); // load record $this->loadData(); // add js $this->header->addJS('jstree/jquery.tree.js'); $this->header->addJS('jstree/lib/jquery.cookie.js'); $this->header->addJS('jstree/plugins/jquery.tree.cookie.js'); // add css $this->header->addCSS('/backend/modules/pages/js/jstree/themes/fork/style.css', null, true); // get the templates $this->templates = BackendPagesModel::getTemplates(); // set the default template as checked $this->templates[$this->record['template_id']]['checked'] = true; // homepage? if ($this->id == 1) { // loop and set disabled state foreach ($this->templates as &$row) { $row['disabled'] = $row['has_block']; } } // get the extras $this->extras = BackendPagesModel::getExtras(); // get maximum number of blocks $maxNumBlocks = BackendModel::getModuleSetting($this->getModule(), 'template_max_blocks', 5); // build blocks array for ($i = 0; $i < $maxNumBlocks; $i++) { $this->blocks[$i] = array('index' => $i, 'name' => 'name ' . $i); } // load the form $this->loadForm(); // load drafts $this->loadDrafts(); // load the datagrid with the versions $this->loadRevisions(); // validate the form $this->validateForm(); // parse $this->parse(); // display the page $this->display(); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // add js $this->header->addJS('jstree/jquery.tree.js'); $this->header->addJS('jstree/lib/jquery.cookie.js'); $this->header->addJS('jstree/plugins/jquery.tree.cookie.js'); // add css $this->header->addCSS('/backend/modules/pages/js/jstree/themes/fork/style.css', null, true); // get the templates $this->templates = BackendPagesModel::getTemplates(); // init var $defaultTemplateId = BackendModel::getModuleSetting($this->getModule(), 'default_template', false); // fallback if ($defaultTemplateId === false) { // get first key $keys = array_keys($this->templates); // set the first items as default if no template was set as default. $defaultTemplateId = $this->templates[$keys[0]]['id']; } // set the default template as checked $this->templates[$defaultTemplateId]['checked'] = true; // get the extras $this->extras = BackendPagesModel::getExtras(); // get maximum number of blocks $maxNumBlocks = BackendModel::getModuleSetting($this->getModule(), 'template_max_blocks', 5); // build blocks array for ($i = 0; $i < $maxNumBlocks; $i++) { $this->blocks[$i] = array('index' => $i, 'name' => 'name ' . $i); } // load the form $this->loadForm(); // validate the form $this->validateForm(); // parse $this->parse(); // display the page $this->display(); }
/** * Validates the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // no errors? if ($this->frm->isCorrect()) { // determine themes $newTheme = $this->frm->getField('theme')->getValue(); $oldTheme = BackendModel::getModuleSetting('core', 'theme', 'core'); // check if we actually switched themes if ($newTheme != $oldTheme) { // fetch templates $oldTemplates = BackendPagesModel::getTemplates($oldTheme); $newTemplates = BackendPagesModel::getTemplates($newTheme); // check if templates already exist if (empty($newTemplates)) { // templates do not yet exist; don't switch $this->redirect(BackendModel::createURLForAction('themes') . '&error=no-templates-available'); exit; } // fetch current default template $oldDefaultTemplatePath = $oldTemplates[BackendModel::getModuleSetting('pages', 'default_template')]['path']; // loop new templates foreach ($newTemplates as $newTemplateId => $newTemplate) { // check if a a similar default template exists if ($newTemplate['path'] == $oldDefaultTemplatePath) { // set new default id $newDefaultTemplateId = (int) $newTemplateId; break; } } // no default template was found, set first template as default if (!isset($newDefaultTemplateId)) { $newDefaultTemplateId = array_keys($newTemplates); $newDefaultTemplateId = $newDefaultTemplateId[0]; } // update theme BackendModel::setModuleSetting('core', 'theme', $newTheme); // set amount of blocks BackendPagesModel::setMaximumBlocks(); // save new default template BackendModel::setModuleSetting('pages', 'default_template', $newDefaultTemplateId); // loop old templates foreach ($oldTemplates as $oldTemplateId => $oldTemplate) { // loop new templates foreach ($newTemplates as $newTemplateId => $newTemplate) { // check if we have a matching template if ($oldTemplate['path'] == $newTemplate['path']) { // switch template BackendPagesModel::updatePagesTemplates($oldTemplateId, $newTemplateId); // break loop continue 2; } } // getting here meant we found no matching template for the new theme; pick first theme's template as default BackendPagesModel::updatePagesTemplates($oldTemplateId, $newDefaultTemplateId); } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_changed_theme'); } // assign report $this->tpl->assign('report', true); $this->tpl->assign('reportMessage', BL::msg('Saved')); } } }