/** * Parse */ protected function parse() { parent::parse(); // set $this->record['url'] = $this->meta->getURL(); if ($this->id == 1) { $this->record['url'] = ''; } // parse some variables $this->tpl->assign('item', $this->record); $this->tpl->assign('isGod', $this->isGod); $this->tpl->assign('templates', $this->templates); $this->tpl->assign('positions', $this->positions); $this->tpl->assign('extrasData', json_encode(BackendExtensionsModel::getExtrasData())); $this->tpl->assign('extrasById', json_encode(BackendExtensionsModel::getExtras())); $this->tpl->assign('prefixURL', rtrim(BackendPagesModel::getFullURL($this->record['parent_id']), '/')); $this->tpl->assign('formErrors', (string) $this->frm->getErrors()); // init var $showDelete = true; // has children? if (BackendPagesModel::getFirstChildId($this->record['id']) !== false) { $showDelete = false; } if (!$this->record['delete_allowed']) { $showDelete = false; } // allowed? if (!BackendAuthentication::isAllowedAction('delete', $this->getModule())) { $showDelete = false; } // show delete button $this->tpl->assign('showPagesDelete', $showDelete); // assign template $this->tpl->assignArray($this->templates[$this->record['template_id']], 'template'); // parse datagrids $this->tpl->assign('revisions', $this->dgRevisions->getNumResults() != 0 ? $this->dgRevisions->getContent() : false); $this->tpl->assign('drafts', $this->dgDrafts->getNumResults() != 0 ? $this->dgDrafts->getContent() : false); // parse the tree $this->tpl->assign('tree', BackendPagesModel::getTreeHTML()); }
/** * Parse */ protected function parse() { parent::parse(); // parse some variables $this->tpl->assign('templates', $this->templates); $this->tpl->assign('isGod', $this->isGod); $this->tpl->assign('positions', $this->positions); $this->tpl->assign('extrasData', json_encode(BackendExtensionsModel::getExtrasData())); $this->tpl->assign('extrasById', json_encode(BackendExtensionsModel::getExtras())); $this->tpl->assign('prefixURL', rtrim(BackendPagesModel::getFullURL(1), '/')); $this->tpl->assign('formErrors', (string) $this->frm->getErrors()); // get default template id $defaultTemplateId = BackendModel::getModuleSetting($this->getModule(), 'default_template', 1); // assign template $this->tpl->assignArray($this->templates[$defaultTemplateId], 'template'); // parse the form $this->frm->parse($this->tpl); // parse the tree $this->tpl->assign('tree', BackendPagesModel::getTreeHTML()); }
/** * Load the form */ private function loadForm() { // create form $this->frm = new BackendForm('edit'); // init var $defaultId = BackendModel::getModuleSetting('pages', 'default_template'); // build available themes $themes = array(); foreach (BackendExtensionsModel::getThemes() as $theme) { $themes[$theme['value']] = $theme['label']; } // create elements $this->frm->addDropdown('theme', $themes, BackendModel::getModuleSetting('core', 'theme', 'core')); $this->frm->addText('label', $this->record['label']); $this->frm->addText('file', str_replace('core/layout/templates/', '', $this->record['path'])); $this->frm->addTextarea('format', str_replace('],[', "],\n[", $this->record['data']['format'])); $this->frm->addCheckbox('active', $this->record['active'] == 'Y'); $this->frm->addCheckbox('default', $this->record['id'] == $defaultId); $this->frm->addCheckbox('overwrite', false); // if this is the default template we can't alter the active/default state if ($this->record['id'] == $defaultId) { $this->frm->getField('active')->setAttributes(array('disabled' => 'disabled')); $this->frm->getField('default')->setAttributes(array('disabled' => 'disabled')); } // if the template is in use we cant alter the active state if (BackendExtensionsModel::isTemplateInUse($this->id)) { $this->frm->getField('active')->setAttributes(array('disabled' => 'disabled')); } // init vars $positions = array(); $blocks = array(); $widgets = array(); $extras = BackendExtensionsModel::getExtras(); // loop extras to populate the default extras foreach ($extras as $item) { if ($item['type'] == 'block') { $blocks[$item['id']] = SpoonFilter::ucfirst(BL::lbl($item['label'])); if (isset($item['data']['extra_label'])) { $blocks[$item['id']] = SpoonFilter::ucfirst($item['data']['extra_label']); } } elseif ($item['type'] == 'widget') { $widgets[$item['id']] = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($item['module']))) . ': ' . SpoonFilter::ucfirst(BL::lbl($item['label'])); if (isset($item['data']['extra_label'])) { $widgets[$item['id']] = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($item['module']))) . ': ' . $item['data']['extra_label']; } } } // sort asort($blocks, SORT_STRING); asort($widgets, SORT_STRING); // create array $defaultExtras = array('' => array(0 => SpoonFilter::ucfirst(BL::lbl('Editor'))), SpoonFilter::ucfirst(BL::lbl('Widgets')) => $widgets); // create default position field $position = array(); $position['i'] = 0; $position['formElements']['txtPosition'] = $this->frm->addText('position_' . $position['i'], null, 255, 'inputText positionName', 'inputTextError positionName'); $position['blocks'][]['formElements']['ddmType'] = $this->frm->addDropdown('type_' . $position['i'] . '_' . 0, $defaultExtras, null, false, 'positionBlock', 'positionBlockError'); $positions[] = $position; // content has been submitted: re-create submitted content rather than the db-fetched content if (isset($_POST['position_0'])) { // init vars $this->names = array(); $this->extras = array(); $i = 1; $errors = array(); // loop submitted positions while (isset($_POST['position_' . $i])) { // init vars $j = 0; $extras = array(); // gather position names $name = $_POST['position_' . $i]; // loop submitted blocks while (isset($_POST['type_' . $i . '_' . $j])) { // gather blocks id $extras[] = (int) $_POST['type_' . $i . '_' . $j]; // increment counter; go fetch next block $j++; } // increment counter; go fetch next position $i++; // position already exists -> error if (in_array($name, $this->names)) { $errors[] = sprintf(BL::getError('DuplicatePositionName'), $name); } // position name == fallback -> error if ($name == 'fallback') { $errors[] = sprintf(BL::getError('ReservedPositionName'), $name); } // not alphanumeric -> error if (!SpoonFilter::isValidAgainstRegexp('/^[a-z0-9]+$/i', $name)) { $errors[] = sprintf(BL::getError('NoAlphaNumPositionName'), $name); } // save positions $this->names[] = $name; $this->extras[$name] = $extras; } // add errors if ($errors) { $this->frm->addError(implode('<br />', array_unique($errors))); } } // build blocks array foreach ($this->names as $i => $name) { // create default position field $position = array(); $position['i'] = $i + 1; $position['formElements']['txtPosition'] = $this->frm->addText('position_' . $position['i'], $name, 255, 'inputText positionName', 'inputTextError positionName'); if (isset($this->extras[$name])) { foreach ($this->extras[$name] as $y => $extra) { $position['blocks'][]['formElements']['ddmType'] = $this->frm->addDropdown('type_' . $position['i'] . '_' . $y, $defaultExtras, $extra, false, 'positionBlock', 'positionBlockError'); } } $positions[] = $position; } // assign $this->tpl->assign('positions', $positions); }
/** * Load the form */ private function loadForm() { // create form $this->frm = new BackendForm('add'); // init var $maximumPositions = 30; // create elements $this->frm->addDropdown('theme', $this->availableThemes, $this->selectedTheme); $this->frm->addText('label'); $this->frm->addText('file'); $this->frm->addTextarea('format'); $this->frm->addCheckbox('active', true); $this->frm->addCheckbox('default'); // init vars $positions = array(); $blocks = array(); $widgets = array(); $extras = BackendExtensionsModel::getExtras(); // loop extras to populate the default extras foreach ($extras as $item) { if ($item['type'] == 'block') { $blocks[$item['id']] = SpoonFilter::ucfirst(BL::lbl($item['label'])); if (isset($item['data']['extra_label'])) { $blocks[$item['id']] = SpoonFilter::ucfirst($item['data']['extra_label']); } } elseif ($item['type'] == 'widget') { $widgets[$item['id']] = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($item['module']))) . ': ' . SpoonFilter::ucfirst(BL::lbl($item['label'])); if (isset($item['data']['extra_label'])) { $widgets[$item['id']] = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($item['module']))) . ': ' . $item['data']['extra_label']; } } } // sort asort($blocks, SORT_STRING); asort($widgets, SORT_STRING); // create array $defaultExtras = array('' => array(0 => SpoonFilter::ucfirst(BL::lbl('Editor'))), SpoonFilter::ucfirst(BL::lbl('Widgets')) => $widgets); // create default position field $position = array(); $position['i'] = 0; $position['formElements']['txtPosition'] = $this->frm->addText('position_' . $position['i'], null, 255, 'inputText positionName', 'inputTextError positionName'); $position['blocks'][]['formElements']['ddmType'] = $this->frm->addDropdown('type_' . $position['i'] . '_' . 0, $defaultExtras, null, false, 'positionBlock', 'positionBlockError'); $positions[] = $position; // content has been submitted: re-create submitted content rather than the db-fetched content if (isset($_POST['position_0'])) { // init vars $this->names = array(); $this->extras = array(); $i = 1; $errors = array(); // loop submitted positions while (isset($_POST['position_' . $i])) { // init vars $j = 0; $extras = array(); // gather position names $name = $_POST['position_' . $i]; // loop submitted blocks while (isset($_POST['type_' . $i . '_' . $j])) { // gather blocks id $extras[] = (int) $_POST['type_' . $i . '_' . $j]; // increment counter; go fetch next block $j++; } // increment counter; go fetch next position $i++; // position already exists -> error if (in_array($name, $this->names)) { $errors[] = sprintf(BL::getError('DuplicatePositionName'), $name); } // position name == fallback -> error if ($name == 'fallback') { $errors[] = sprintf(BL::getError('ReservedPositionName'), $name); } // not alphanumeric -> error if (!SpoonFilter::isValidAgainstRegexp('/^[a-z0-9]+$/i', $name)) { $errors[] = sprintf(BL::getError('NoAlphaNumPositionName'), $name); } // save positions $this->names[] = $name; $this->extras[$name] = $extras; } // add errors if ($errors) { $this->frm->addError(implode('<br />', array_unique($errors))); } } // build blocks array foreach ($this->names as $i => $name) { // create default position field $position = array(); $position['i'] = $i + 1; $position['formElements']['txtPosition'] = $this->frm->addText('position_' . $position['i'], $name, 255, 'inputText positionName', 'inputTextError positionName'); foreach ($this->extras[$name] as $extra) { $position['blocks'][]['formElements']['ddmType'] = $this->frm->addDropdown('type_' . $position['i'] . '_' . 0, $defaultExtras, $extra, false, 'positionBlock', 'positionBlockError'); } $positions[] = $position; } // assign $this->tpl->assign('positions', $positions); }