getTemplates() public static method

Get templates
public static getTemplates ( string $theme = null ) : array
$theme string The theme we want to fetch the templates from.
return array
Esempio n. 1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // load record
     $this->loadData();
     // add js
     $this->header->addJS('jstree/jquery.tree.js', null, false);
     $this->header->addJS('jstree/lib/jquery.cookie.js', null, false);
     $this->header->addJS('jstree/plugins/jquery.tree.cookie.js', null, false);
     // add css
     $this->header->addCSS('/src/Backend/Modules/Pages/Js/jstree/themes/fork/style.css', null, true);
     // get the templates
     $this->templates = BackendExtensionsModel::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 = BackendExtensionsModel::getExtras();
     $this->loadForm();
     $this->loadDrafts();
     $this->loadRevisions();
     $this->validateForm();
     $this->parse();
     $this->display();
 }
Esempio n. 2
0
 /**
  * Execute the action
  */
 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', null, false);
     $this->header->addJS('jstree/lib/jquery.cookie.js', null, false);
     $this->header->addJS('jstree/plugins/jquery.tree.cookie.js', null, false);
     // get the templates
     $this->templates = BackendExtensionsModel::getTemplates();
     $this->isGod = BackendAuthentication::getUser()->isGod();
     // init var
     $defaultTemplateId = $this->get('fork.settings')->get('Pages', '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 = BackendExtensionsModel::getExtras();
     $this->loadForm();
     $this->validateForm();
     $this->parse();
     $this->display();
 }
Esempio n. 3
0
 /**
  * Load the record
  */
 private function loadData()
 {
     // get record
     $this->id = $this->getParameter('id', 'int');
     // validate id
     if ($this->id === null || !BackendExtensionsModel::existsTemplate($this->id)) {
         $this->redirect(BackendModel::createURLForAction('ThemeTemplates') . '&error=non-existing');
     }
     // get the record
     $this->record = BackendExtensionsModel::getTemplate($this->id);
     // unserialize
     $this->record['data'] = unserialize($this->record['data']);
     $this->names = $this->record['data']['names'];
     if (isset($this->record['data']['default_extras_' . BL::getWorkingLanguage()])) {
         $this->extras = $this->record['data']['default_extras_' . BL::getWorkingLanguage()];
     } elseif (isset($this->record['data']['default_extras'])) {
         $this->extras = $this->record['data']['default_extras'];
     }
     if (!array_key_exists('image', (array) $this->record['data'])) {
         $this->record['data']['image'] = false;
     }
     // assign
     $this->tpl->assign('template', $this->record);
     // is the template being used
     $inUse = BackendExtensionsModel::isTemplateInUse($this->id);
     // determine if deleting is allowed
     $deleteAllowed = true;
     if ($this->record['id'] == $this->get('fork.settings')->get('Pages', 'default_template')) {
         $deleteAllowed = false;
     } elseif (count(BackendExtensionsModel::getTemplates()) == 1) {
         $deleteAllowed = false;
     } elseif ($inUse) {
         $deleteAllowed = false;
     }
     // assign
     $this->tpl->assign('inUse', $inUse);
     $this->tpl->assign('allowExtensionsDeleteThemeTemplate', $deleteAllowed);
 }
Esempio n. 4
0
 /**
  * Validates the form.
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // no errors?
         if ($this->frm->isCorrect()) {
             // determine themes
             $newTheme = $this->frm->getField('installedThemes')->getValue();
             $oldTheme = $this->get('fork.settings')->get('Core', 'theme', 'core');
             // check if we actually switched themes
             if ($newTheme != $oldTheme) {
                 // fetch templates
                 $oldTemplates = BackendExtensionsModel::getTemplates($oldTheme);
                 $newTemplates = BackendExtensionsModel::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[$this->get('fork.settings')->get('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
                 $this->get('fork.settings')->set('Core', 'theme', $newTheme);
                 // save new default template
                 $this->get('fork.settings')->set('Pages', 'default_template', $newDefaultTemplateId);
                 // loop old templates
                 foreach ($oldTemplates as $oldTemplateId => $oldTemplate) {
                     // loop new templates
                     foreach ($newTemplates as $newTemplateId => $newTemplate) {
                         // if the templates don't match we can skip this one
                         if ($oldTemplate['path'] != $newTemplate['path']) {
                             continue;
                         }
                         // 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'));
         }
     }
 }