/** * Load the form */ private function loadForm() { // get values for the form $rbtHiddenValues[] = array('label' => BL::lbl('Hidden'), 'value' => 'Y'); $rbtHiddenValues[] = array('label' => BL::lbl('Published'), 'value' => 'N'); $categories = BackendFaqModel::getCategories(); // create form $this->frm = new BackendForm('edit'); $this->frm->addText('title', $this->record['question'], null, 'inputText title', 'inputTextError title'); $this->frm->addEditor('answer', $this->record['answer']); $this->frm->addRadiobutton('hidden', $rbtHiddenValues, $this->record['hidden']); $this->frm->addDropdown('category_id', $categories, $this->record['category_id']); $this->frm->addText('tags', BackendTagsModel::getTags($this->URL->getModule(), $this->record['id']), null, 'inputText tagBox', 'inputTextError tagBox'); $this->meta = new BackendMeta($this->frm, $this->record['meta_id'], 'title', true); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $from = $this->getParameter('from'); $to = $this->getParameter('to'); // validate if ($from == '') { throw new BackendException('Specify a from-parameter.'); } if ($to == '') { throw new BackendException('Specify a to-parameter.'); } // get db $db = BackendModel::getDB(true); // get all old pages $ids = $db->getColumn('SELECT id FROM pages AS i WHERE i.language = ? AND i.status = ?', array($to, 'active')); // any old pages if (!empty($ids)) { // delete existing pages foreach ($ids as $id) { // redefine $id = (int) $id; // get revision ids $revisionIDs = (array) $db->getColumn('SELECT i.revision_id FROM pages AS i WHERE i.id = ? AND i.language = ?', array($id, $to)); // get meta ids $metaIDs = (array) $db->getColumn('SELECT i.meta_id FROM pages AS i WHERE i.id = ? AND i.language = ?', array($id, $to)); // delete meta records if (!empty($metaIDs)) { $db->delete('meta', 'id IN (' . implode(',', $metaIDs) . ')'); } // delete blocks and their revisions if (!empty($revisionIDs)) { $db->delete('pages_blocks', 'revision_id IN (' . implode(',', $revisionIDs) . ')'); } // delete page and the revisions if (!empty($revisionIDs)) { $db->delete('pages', 'revision_id IN (' . implode(',', $revisionIDs) . ')'); } } } // delete search indexes $db->delete('search_index', 'module = ? AND language = ?', array('pages', $to)); // get all active pages $ids = BackendModel::getDB()->getColumn('SELECT id FROM pages AS i WHERE i.language = ? AND i.status = ?', array($from, 'active')); // loop foreach ($ids as $id) { // get data $sourceData = BackendPagesModel::get($id, $from); // get and build meta $meta = $db->getRecord('SELECT * FROM meta WHERE id = ?', $sourceData['meta_id']); // remove id unset($meta['id']); // build page record $page = array(); $page['id'] = $sourceData['id']; $page['user_id'] = BackendAuthentication::getUser()->getUserId(); $page['parent_id'] = $sourceData['parent_id']; $page['template_id'] = $sourceData['template_id']; $page['meta_id'] = (int) $db->insert('meta', $meta); $page['language'] = $to; $page['type'] = $sourceData['type']; $page['title'] = $sourceData['title']; $page['navigation_title'] = $sourceData['navigation_title']; $page['navigation_title_overwrite'] = $sourceData['navigation_title_overwrite']; $page['hidden'] = $sourceData['hidden']; $page['status'] = 'active'; $page['publish_on'] = BackendModel::getUTCDate(); $page['created_on'] = BackendModel::getUTCDate(); $page['edited_on'] = BackendModel::getUTCDate(); $page['allow_move'] = $sourceData['allow_move']; $page['allow_children'] = $sourceData['allow_children']; $page['allow_edit'] = $sourceData['allow_edit']; $page['allow_delete'] = $sourceData['allow_delete']; $page['sequence'] = $sourceData['sequence']; $page['data'] = $sourceData['data'] !== null ? serialize($sourceData['data']) : null; // insert page, store the id, we need it when building the blocks $revisionId = BackendPagesModel::insert($page); // init var $blocks = array(); $hasBlock = $sourceData['has_extra'] == 'Y'; // get the blocks $sourceBlocks = BackendPagesModel::getBlocks($id, $from); // loop blocks foreach ($sourceBlocks as $sourceBlock) { // build block $block = array(); $block['id'] = $sourceBlock['id']; $block['revision_id'] = $revisionId; $block['extra_id'] = $sourceBlock['extra_id']; $block['html'] = $sourceBlock['html']; $block['status'] = 'active'; $block['created_on'] = BackendModel::getUTCDate(); $block['edited_on'] = BackendModel::getUTCDate(); // add block $blocks[] = $block; } // insert the blocks BackendPagesModel::insertBlocks($blocks, $hasBlock); // check if the method exists if (method_exists('BackendSearchModel', 'addIndex')) { // init var $text = ''; // build search-text foreach ($blocks as $block) { $text .= ' ' . $block['html']; } // add BackendSearchModel::addIndex('pages', (int) $page['id'], array('title' => $page['title'], 'text' => $text), $to); } // get tags $tags = BackendTagsModel::getTags('pages', $id, 'string', $from); // save tags if ($tags != '') { BackendTagsModel::saveTags($page['id'], $tags, 'pages'); } } // build cache BackendPagesModel::buildCache($to); }
/** * Load the form */ private function loadForm() { // get default template id $defaultTemplateId = BackendModel::getModuleSetting('pages', 'default_template', 1); // create form $this->frm = new BackendForm('edit'); // assign in template $this->tpl->assign('defaultTemplateId', $defaultTemplateId); // create elements $this->frm->addText('title', $this->record['title'], null, 'inputText title', 'inputTextError title'); $this->frm->addEditor('html'); $this->frm->addHidden('template_id', $this->record['template_id']); $this->frm->addRadiobutton('hidden', array(array('label' => BL::lbl('Hidden'), 'value' => 'Y'), array('label' => BL::lbl('Published'), 'value' => 'N')), $this->record['hidden']); // a god user should be able to adjust the detailed settings for a page easily if ($this->isGod) { // init some vars $items = array('move', 'children', 'edit', 'delete'); $checked = array(); $values = array(); foreach ($items as $value) { $values[] = array('label' => BL::msg(SpoonFilter::toCamelCase('allow_' . $value)), 'value' => $value); if (isset($this->record['allow_' . $value]) && $this->record['allow_' . $value] == 'Y') { $checked[] = $value; } } $this->frm->addMultiCheckbox('allow', $values, $checked); } // build prototype block $block['index'] = 0; $block['formElements']['chkVisible'] = $this->frm->addCheckbox('block_visible_' . $block['index'], true); $block['formElements']['hidExtraId'] = $this->frm->addHidden('block_extra_id_' . $block['index'], 0); $block['formElements']['hidPosition'] = $this->frm->addHidden('block_position_' . $block['index'], 'fallback'); $block['formElements']['txtHTML'] = $this->frm->addTextArea('block_html_' . $block['index'], ''); // this is no editor; we'll add the editor in JS // add default block to "fallback" position, the only one which we can rest assured to exist $this->positions['fallback']['blocks'][] = $block; // content has been submitted: re-create submitted content rather than the db-fetched content if (isset($_POST['block_html_0'])) { // init vars $this->blocksContent = array(); $hasBlock = false; $i = 1; // loop submitted blocks while (isset($_POST['block_position_' . $i])) { // init var $block = array(); // save block position $block['position'] = $_POST['block_position_' . $i]; $positions[$block['position']][] = $block; // set linked extra $block['extra_id'] = $_POST['block_extra_id_' . $i]; // reset some stuff if ($block['extra_id'] <= 0) { $block['extra_id'] = null; } // init html $block['html'] = null; // extra-type is HTML if ($block['extra_id'] === null) { // reset vars $block['extra_id'] = null; $block['html'] = $_POST['block_html_' . $i]; } else { // type of block if (isset($this->extras[$block['extra_id']]['type']) && $this->extras[$block['extra_id']]['type'] == 'block') { // set error if ($hasBlock) { $this->frm->addError(BL::err('CantAdd2Blocks')); } // home can't have blocks if ($this->record['id'] == 1) { $this->frm->addError(BL::err('HomeCantHaveBlocks')); } // reset var $hasBlock = true; } } // set data $block['created_on'] = BackendModel::getUTCDate(); $block['edited_on'] = $block['created_on']; $block['visible'] = isset($_POST['block_visible_' . $i]) && $_POST['block_visible_' . $i] == 'Y' ? 'Y' : 'N'; $block['sequence'] = count($positions[$block['position']]) - 1; // add to blocks $this->blocksContent[] = $block; // increment counter; go fetch next block $i++; } } // build blocks array foreach ($this->blocksContent as $i => $block) { $block['index'] = $i + 1; $block['formElements']['chkVisible'] = $this->frm->addCheckbox('block_visible_' . $block['index'], $block['visible'] == 'Y'); $block['formElements']['hidExtraId'] = $this->frm->addHidden('block_extra_id_' . $block['index'], (int) $block['extra_id']); $block['formElements']['hidPosition'] = $this->frm->addHidden('block_position_' . $block['index'], $block['position']); $block['formElements']['txtHTML'] = $this->frm->addTextArea('block_html_' . $block['index'], $block['html']); // this is no editor; we'll add the editor in JS $this->positions[$block['position']]['blocks'][] = $block; } // redirect $redirectValue = 'none'; if (isset($this->record['data']['internal_redirect']['page_id'])) { $redirectValue = 'internal'; } if (isset($this->record['data']['external_redirect']['url'])) { $redirectValue = 'external'; } $redirectValues = array(array('value' => 'none', 'label' => SpoonFilter::ucfirst(BL::lbl('None'))), array('value' => 'internal', 'label' => SpoonFilter::ucfirst(BL::lbl('InternalLink')), 'variables' => array('isInternal' => true)), array('value' => 'external', 'label' => SpoonFilter::ucfirst(BL::lbl('ExternalLink')), 'variables' => array('isExternal' => true))); $this->frm->addRadiobutton('redirect', $redirectValues, $redirectValue); $this->frm->addDropdown('internal_redirect', BackendPagesModel::getPagesForDropdown(), $redirectValue == 'internal' ? $this->record['data']['internal_redirect']['page_id'] : null); $this->frm->addText('external_redirect', $redirectValue == 'external' ? $this->record['data']['external_redirect']['url'] : null, null, null, null, true); // page info $this->frm->addCheckbox('navigation_title_overwrite', $this->record['navigation_title_overwrite'] == 'Y'); $this->frm->addText('navigation_title', $this->record['navigation_title']); // tags $this->frm->addText('tags', BackendTagsModel::getTags($this->URL->getModule(), $this->id), null, 'inputText tagBox', 'inputTextError tagBox'); // a specific action $isAction = isset($this->record['data']['is_action']) && $this->record['data']['is_action'] == true ? true : false; $this->frm->addCheckbox('is_action', $isAction); // extra $this->frm->addDropdown('extra_type', BackendPagesModel::getTypes()); // meta $this->meta = new BackendMeta($this->frm, $this->record['meta_id'], 'title', true); // set callback for generating an unique URL $this->meta->setURLCallback('BackendPagesModel', 'getURL', array($this->record['id'], $this->record['parent_id'], $isAction)); }
/** * Load the form */ private function loadForm() { // create form $this->frm = new BackendForm('edit'); // set hidden values $rbtHiddenValues[] = array('label' => BL::lbl('Hidden'), 'value' => 'Y'); $rbtHiddenValues[] = array('label' => BL::lbl('Published'), 'value' => 'N'); // get categories $categories = BackendBlogModel::getCategories(); $categories['new_category'] = SpoonFilter::ucfirst(BL::getLabel('AddCategory')); // create elements $this->frm->addText('title', $this->record['title'], null, 'inputText title', 'inputTextError title'); $this->frm->addEditor('text', $this->record['text']); $this->frm->addEditor('introduction', $this->record['introduction']); $this->frm->addRadiobutton('hidden', $rbtHiddenValues, $this->record['hidden']); $this->frm->addCheckbox('allow_comments', $this->record['allow_comments'] === 'Y' ? true : false); $this->frm->addDropdown('category_id', $categories, $this->record['category_id']); if (count($categories) != 2) { $this->frm->getField('category_id')->setDefaultElement(''); } $this->frm->addDropdown('user_id', BackendUsersModel::getUsers(), $this->record['user_id']); $this->frm->addText('tags', BackendTagsModel::getTags($this->URL->getModule(), $this->record['id']), null, 'inputText tagBox', 'inputTextError tagBox'); $this->frm->addDate('publish_on_date', $this->record['publish_on']); $this->frm->addTime('publish_on_time', date('H:i', $this->record['publish_on'])); if ($this->imageIsAllowed) { $this->frm->addImage('image'); $this->frm->addCheckbox('delete_image'); } // meta object $this->meta = new BackendMeta($this->frm, $this->record['meta_id'], 'title', true); // set callback for generating a unique URL $this->meta->setUrlCallback('BackendBlogModel', 'getURL', array($this->record['id'])); }
/** * Load the form * * @return void */ private function loadForm() { // get default template id $defaultTemplateId = BackendModel::getModuleSetting($this->getModule(), 'default_template', 1); // create form $this->frm = new BackendForm('edit'); // assign in template $this->tpl->assign('defaultTemplateId', $defaultTemplateId); // create elements $this->frm->addText('title', $this->record['title'], null, 'inputText title', 'inputTextError title'); $this->frm->addHidden('template_id', $this->record['template_id']); $this->frm->addRadiobutton('hidden', array(array('label' => BL::lbl('Hidden'), 'value' => 'Y'), array('label' => BL::lbl('Published'), 'value' => 'N')), $this->record['hidden']); // get maximum number of blocks $maxNumBlocks = BackendModel::getModuleSetting($this->getModule(), 'template_max_blocks', 5); // build blocks array for ($i = 0; $i < $maxNumBlocks; $i++) { // init var $html = null; $selectedExtra = null; // reset data, if it is available if (isset($this->blocksContent[$i])) { $html = $this->blocksContent[$i]['html']; $selectedExtra = $this->blocksContent[$i]['extra_id']; } // create elements $this->blocks[$i]['formElements']['hidExtraId'] = $this->frm->addHidden('block_extra_id_' . $i, $selectedExtra); $this->blocks[$i]['formElements']['txtHTML'] = $this->frm->addEditor('block_html_' . $i, $html); // add class $this->frm->getField('block_extra_id_' . $i)->setAttribute('class', 'block_extra_id'); } // redirect $redirectValue = 'none'; if (isset($this->record['data']['internal_redirect']['page_id'])) { $redirectValue = 'internal'; } if (isset($this->record['data']['external_redirect']['url'])) { $redirectValue = 'external'; } $redirectValues = array(array('value' => 'none', 'label' => ucfirst(BL::lbl('None'))), array('value' => 'internal', 'label' => ucfirst(BL::lbl('InternalLink')), 'variables' => array('isInternal' => true)), array('value' => 'external', 'label' => ucfirst(BL::lbl('ExternalLink')), 'variables' => array('isExternal' => true))); $this->frm->addRadiobutton('redirect', $redirectValues, $redirectValue); $this->frm->addDropdown('internal_redirect', BackendPagesModel::getPagesForDropdown(), $redirectValue == 'internal' ? $this->record['data']['internal_redirect']['page_id'] : null); $this->frm->addText('external_redirect', $redirectValue == 'external' ? $this->record['data']['external_redirect']['url'] : null, null, null, null, true); // page info $this->frm->addCheckbox('navigation_title_overwrite', $this->record['navigation_title_overwrite'] == 'Y'); $this->frm->addText('navigation_title', $this->record['navigation_title']); // tags $this->frm->addText('tags', BackendTagsModel::getTags($this->URL->getModule(), $this->id), null, 'inputText tagBox', 'inputTextError tagBox'); // extra $this->frm->addDropdown('extra_type', BackendPagesModel::getTypes()); // a specific action $isAction = isset($this->record['data']['is_action']) && $this->record['data']['is_action'] == true ? true : false; $this->frm->addCheckbox('is_action', $isAction); // meta $this->meta = new BackendMeta($this->frm, $this->record['meta_id'], 'title', true); }