Esempio n. 1
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent
     parent::execute();
     // get parameters
     $id = SpoonFilter::getPostValue('id', null, 0, 'int');
     $droppedOn = SpoonFilter::getPostValue('dropped_on', null, -1, 'int');
     $typeOfDrop = SpoonFilter::getPostValue('type', null, '');
     // validate
     if ($id === 0) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     }
     if ($droppedOn === -1) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     }
     if ($typeOfDrop == '') {
         $this->output(self::BAD_REQUEST, null, 'no type provided');
     }
     // get page
     $success = BackendPagesModel::move($id, $droppedOn, $typeOfDrop);
     // build cache
     BackendPagesModel::buildCache(BL::getWorkingLanguage());
     // output
     if ($success) {
         $this->output(self::OK, BackendPagesModel::get($id), 'page moved');
     } else {
         $this->output(self::ERROR, null, 'page not moved');
     }
 }
Esempio n. 2
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendPagesModel::existsTemplate($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // init var
         $success = false;
         // get template (we need the title)
         $item = BackendPagesModel::getTemplate($this->id);
         // valid template?
         if (!empty($item)) {
             // delete the page
             $success = BackendPagesModel::deleteTemplate($this->id);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete_template', array('id' => $this->id));
             // build cache
             BackendPagesModel::buildCache(BL::getWorkingLanguage());
         }
         // page is deleted, so redirect to the overview
         if ($success) {
             $this->redirect(BackendModel::createURLForAction('templates') . '&theme=' . $item['theme'] . '&report=deleted-template&var=' . urlencode($item['label']));
         } else {
             $this->redirect(BackendModel::createURLForAction('templates') . '&error=non-existing');
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('templates') . '&error=non-existing');
     }
 }
Esempio n. 3
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent
     parent::execute();
     // get parameters
     $id = SpoonFilter::getPostValue('id', null, 0, 'int');
     // validate
     if ($id === 0) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     }
     // get page
     $page = BackendPagesModel::get($id);
     // output
     $this->output(self::OK, $page);
 }
Esempio n. 4
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendPagesModel::exists($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // init var
         $success = false;
         // cannot have children
         if (BackendPagesModel::getFirstChildId($this->id) !== false) {
             $this->redirect(BackendModel::createURLForAction('edit') . '&error=non-existing');
         }
         $revisionId = $this->getParameter('revision_id', 'int');
         if ($revisionId == 0) {
             $revisionId = null;
         }
         // get page (we need the title)
         $page = BackendPagesModel::get($this->id, $revisionId);
         // valid page?
         if (!empty($page)) {
             // delete the page
             $success = BackendPagesModel::delete($this->id, null, $revisionId);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
             // delete search indexes
             BackendSearchModel::removeIndex($this->getModule(), $this->id);
             // build cache
             BackendPagesModel::buildCache(BL::getWorkingLanguage());
         }
         // page is deleted, so redirect to the overview
         if ($success) {
             $this->redirect(BackendModel::createURLForAction('index') . '&id=' . $page['parent_id'] . '&report=deleted&var=' . urlencode($page['title']));
         } else {
             $this->redirect(BackendModel::createURLForAction('edit') . '&error=non-existing');
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('edit') . '&error=non-existing');
     }
 }
Esempio n. 5
0
 /**
  * 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'));
         }
     }
 }
Esempio n. 6
0
 /**
  * Parse the datagrid and the reports
  */
 protected function parse()
 {
     parent::parse();
     // parse dgRecentlyEdited
     $this->tpl->assign('dgRecentlyEdited', $this->dgRecentlyEdited->getNumResults() != 0 ? $this->dgRecentlyEdited->getContent() : false);
     $this->tpl->assign('dgDrafts', $this->dgDrafts->getNumResults() != 0 ? $this->dgDrafts->getContent() : false);
     // parse the tree
     $this->tpl->assign('tree', BackendPagesModel::getTreeHTML());
     // open the tree on a specific page
     if ($this->getParameter('id', 'int') !== null) {
         $this->tpl->assign('openedPageId', $this->getParameter('id', 'int'));
     } else {
         $this->tpl->assign('openedPageId', 1);
     }
 }
Esempio n. 7
0
    /**
     * 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);
    }
Esempio n. 8
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // get the status
         $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active');
         // validate redirect
         $redirectValue = $this->frm->getField('redirect')->getValue();
         if ($redirectValue == 'internal') {
             $this->frm->getField('internal_redirect')->isFilled(BL::err('FieldIsRequired'));
         }
         if ($redirectValue == 'external') {
             $this->frm->getField('external_redirect')->isURL(BL::err('InvalidURL'));
         }
         // set callback for generating an unique URL
         $this->meta->setURLCallback('BackendPagesModel', 'getURL', array($this->record['id'], $this->record['parent_id'], $this->frm->getField('is_action')->getChecked()));
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // validate meta
         $this->meta->validate();
         // no errors?
         if ($this->frm->isCorrect()) {
             // init var
             $data = null;
             // build data
             if ($this->frm->getField('is_action')->isChecked()) {
                 $data['is_action'] = true;
             }
             if ($redirectValue == 'internal') {
                 $data['internal_redirect'] = array('page_id' => $this->frm->getField('internal_redirect')->getValue(), 'code' => '301');
             }
             if ($redirectValue == 'external') {
                 $data['external_redirect'] = array('url' => $this->frm->getField('external_redirect')->getValue(), 'code' => '301');
             }
             // build page record
             $page['id'] = $this->record['id'];
             $page['user_id'] = BackendAuthentication::getUser()->getUserId();
             $page['parent_id'] = $this->record['parent_id'];
             $page['template_id'] = (int) $this->frm->getField('template_id')->getValue();
             $page['meta_id'] = (int) $this->meta->save();
             $page['language'] = BackendLanguage::getWorkingLanguage();
             $page['type'] = $this->record['type'];
             $page['title'] = $this->frm->getField('title')->getValue();
             $page['navigation_title'] = $this->frm->getField('navigation_title')->getValue() != '' ? $this->frm->getField('navigation_title')->getValue() : $this->frm->getField('title')->getValue();
             $page['navigation_title_overwrite'] = $this->frm->getField('navigation_title_overwrite')->isChecked() ? 'Y' : 'N';
             $page['hidden'] = $this->frm->getField('hidden')->getValue();
             $page['status'] = $status;
             $page['publish_on'] = BackendModel::getUTCDate(null, $this->record['publish_on']);
             $page['created_on'] = BackendModel::getUTCDate(null, $this->record['created_on']);
             $page['edited_on'] = BackendModel::getUTCDate();
             $page['allow_move'] = $this->record['allow_move'];
             $page['allow_children'] = $this->record['allow_children'];
             $page['allow_edit'] = $this->record['allow_edit'];
             $page['allow_delete'] = $this->record['allow_delete'];
             $page['sequence'] = $this->record['sequence'];
             $page['data'] = $data !== null ? serialize($data) : null;
             if ($this->isGod) {
                 $page['allow_move'] = in_array('move', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N';
                 $page['allow_children'] = in_array('children', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N';
                 $page['allow_edit'] = in_array('edit', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N';
                 $page['allow_delete'] = in_array('delete', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N';
             }
             // set navigation title
             if ($page['navigation_title'] == '') {
                 $page['navigation_title'] = $page['title'];
             }
             // insert page, store the id, we need it when building the blocks
             $page['revision_id'] = BackendPagesModel::update($page);
             // loop blocks
             foreach ($this->blocksContent as $i => $block) {
                 // add page revision id to blocks
                 $this->blocksContent[$i]['revision_id'] = $page['revision_id'];
                 // validate blocks, only save blocks for valid positions
                 if (!in_array($block['position'], $this->templates[$this->frm->getField('template_id')->getValue()]['data']['names'])) {
                     unset($this->blocksContent[$i]);
                 }
             }
             // insert the blocks
             BackendPagesModel::insertBlocks($this->blocksContent);
             // trigger an event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $page));
             // save tags
             BackendTagsModel::saveTags($page['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // build cache
             BackendPagesModel::buildCache(BL::getWorkingLanguage());
             // active
             if ($page['status'] == 'active') {
                 // init var
                 $text = '';
                 // build search-text
                 foreach ($this->blocksContent as $block) {
                     $text .= ' ' . $block['html'];
                 }
                 // add to search index
                 BackendSearchModel::saveIndex($this->getModule(), $page['id'], array('title' => $page['title'], 'text' => $text));
                 // everything is saved, so redirect to the overview
                 $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $page['id'] . '&report=edited&var=' . urlencode($page['title']) . '&highlight=row-' . $page['id']);
             } elseif ($page['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $page['id'] . '&report=saved-as-draft&var=' . urlencode($page['title']) . '&highlight=row-' . $page['id'] . '&draft=' . $page['revision_id']);
             }
         }
     }
 }
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // required fields
         $this->frm->getField('file')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('label')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('format')->isFilled(BL::err('FieldIsRequired'));
         // validate syntax
         $syntax = trim(str_replace(array("\n", "\r", ' '), '', $this->frm->getField('format')->getValue()));
         // init var
         $table = BackendExtensionsModel::templateSyntaxToArray($syntax);
         // validate the syntax
         if ($table === false) {
             $this->frm->getField('format')->addError(BL::err('InvalidTemplateSyntax'));
         } else {
             $html = BackendExtensionsModel::buildTemplateHTML($syntax);
             $cellCount = 0;
             $first = true;
             $errors = array();
             // loop rows
             foreach ($table as $row) {
                 // first row defines the cellcount
                 if ($first) {
                     $cellCount = count($row);
                 }
                 // not same number of cells
                 if (count($row) != $cellCount) {
                     // add error
                     $errors[] = BL::err('InvalidTemplateSyntax');
                     // stop
                     break;
                 }
                 // doublecheck position names
                 foreach ($row as $cell) {
                     // ignore unavailable space
                     if ($cell != '/') {
                         // not alphanumeric -> error
                         if (!in_array($cell, $this->names)) {
                             $errors[] = sprintf(BL::getError('NonExistingPositionName'), $cell);
                         } elseif (substr_count($html, '"#position-' . $cell . '"') != 1) {
                             $errors[] = BL::err('InvalidTemplateSyntax');
                         }
                     }
                 }
                 // reset
                 $first = false;
             }
             // add errors
             if ($errors) {
                 $this->frm->getField('format')->addError(implode('<br />', array_unique($errors)));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build array
             $item['id'] = $this->id;
             $item['theme'] = $this->frm->getField('theme')->getValue();
             $item['label'] = $this->frm->getField('label')->getValue();
             $item['path'] = 'core/layout/templates/' . $this->frm->getField('file')->getValue();
             $item['active'] = $this->frm->getField('active')->getChecked() ? 'Y' : 'N';
             $item['data']['format'] = trim(str_replace(array("\n", "\r", ' '), '', $this->frm->getField('format')->getValue()));
             $item['data']['names'] = $this->names;
             $item['data']['default_extras'] = $this->extras;
             $item['data']['default_extras_' . BackendLanguage::getWorkingLanguage()] = $this->extras;
             // serialize
             $item['data'] = serialize($item['data']);
             // if this is the default template make the template active
             if (BackendModel::getModuleSetting('pages', 'default_template') == $this->record['id']) {
                 $item['active'] = 'Y';
             }
             // if the template is in use we can't de-activate it
             if (BackendExtensionsModel::isTemplateInUse($item['id'])) {
                 $item['active'] = 'Y';
             }
             // insert the item
             BackendExtensionsModel::updateTemplate($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_template', array('item' => $item));
             // set default template
             if ($this->frm->getField('default')->getChecked() && $item['theme'] == BackendModel::getModuleSetting('core', 'theme', 'core')) {
                 BackendModel::setModuleSetting('pages', 'default_template', $item['id']);
             }
             // update all existing pages using this template to add the newly inserted block(s)
             if (BackendExtensionsModel::isTemplateInUse($item['id'])) {
                 BackendPagesModel::updatePagesTemplates($item['id'], $item['id'], $this->frm->getField('overwrite')->getChecked());
             }
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('theme_templates') . '&theme=' . $item['theme'] . '&report=edited-template&var=' . urlencode($item['label']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Esempio n. 10
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // required fields
         $this->frm->getField('file')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('label')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('format')->isFilled(BL::err('FieldIsRequired'));
         // loop the know fields and validate them
         for ($i = 1; $i <= $this->frm->getField('num_blocks')->getValue(); $i++) {
             $this->frm->getField('name_' . $i)->isFilled(BL::err('FieldIsRequired'));
         }
         // validate syntax
         $syntax = trim(str_replace(array("\n", "\r"), '', $this->frm->getField('format')->getValue()));
         // init var
         $table = BackendPagesModel::templateSyntaxToArray($syntax);
         $cellCount = 0;
         $first = true;
         // loop rows
         foreach ($table as $row) {
             // first row defines the cellcount
             if ($first) {
                 $cellCount = count($row);
             }
             // not same number of cells
             if (count($row) != $cellCount) {
                 // add error
                 $this->frm->getField('format')->addError(BL::err('InvalidTemplateSyntax'));
                 // stop
                 break;
             }
             // reset
             $first = false;
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build array
             $item['theme'] = $this->frm->getField('theme')->getValue();
             $item['label'] = $this->frm->getField('label')->getValue();
             $item['path'] = 'core/layout/templates/' . $this->frm->getField('file')->getValue();
             $item['num_blocks'] = $this->frm->getField('num_blocks')->getValue();
             $item['active'] = $this->frm->getField('active')->getChecked() ? 'Y' : 'N';
             $item['data']['format'] = trim(str_replace(array("\n", "\r"), '', $this->frm->getField('format')->getValue()));
             // loop fields
             for ($i = 1; $i <= $this->frm->getField('num_blocks')->getValue(); $i++) {
                 $item['data']['names'][] = $this->frm->getField('name_' . $i)->getValue();
                 $item['data']['default_extras'][] = $this->frm->getField('type_' . $i)->getValue();
                 $item['data']['default_extras_' . BackendLanguage::getWorkingLanguage()][] = $this->frm->getField('type_' . $i)->getValue();
             }
             // serialize the data
             $item['data'] = serialize($item['data']);
             // insert the item
             $item['id'] = BackendPagesModel::insertTemplate($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_template', array('item' => $item));
             // set default template
             if ($this->frm->getField('default')->getChecked() && $item['theme'] == BackendModel::getModuleSetting('core', 'theme', 'core')) {
                 BackendModel::setModuleSetting($this->getModule(), 'default_template', $item['id']);
             }
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('templates') . '&theme=' . $item['theme'] . '&report=added-template&var=' . urlencode($item['label']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Esempio n. 11
0
 /**
  * Get the page-keys
  *
  * @return	array
  * @param	string[optional] $language	The language wherefor the navigation should be loaded, if not provided we will load the language that was provided in the URL.
  */
 public static function getKeys($language = null)
 {
     // redefine
     $language = $language !== null ? (string) $language : FRONTEND_LANGUAGE;
     // does the keys exists in the cache?
     if (!isset(self::$keys[$language]) || empty(self::$keys[$language])) {
         // validate file
         if (!SpoonFile::exists(FRONTEND_CACHE_PATH . '/navigation/keys_' . $language . '.php')) {
             // require BackendPagesModel
             require_once PATH_WWW . '/backend/core/engine/model.php';
             require_once PATH_WWW . '/backend/modules/pages/engine/model.php';
             // generate the cache
             BackendPagesModel::buildCache($language);
             // recall
             return self::getKeys($language);
         }
         // init var
         $keys = array();
         // require file
         require FRONTEND_CACHE_PATH . '/navigation/keys_' . $language . '.php';
         // validate keys
         if (empty($keys)) {
             throw new FrontendException('No pages for ' . $language . '.');
         }
         // store
         self::$keys[$language] = $keys;
     }
     // return from cache
     return self::$keys[$language];
 }
Esempio n. 12
0
    /**
     * Switch templates for all existing pages
     *
     * @param int $oldTemplateId The id of the new template to replace.
     * @param int $newTemplateId The id of the new template to use.
     * @param bool[optional] $overwrite Overwrite all pages with default blocks.
     */
    public static function updatePagesTemplates($oldTemplateId, $newTemplateId, $overwrite = false)
    {
        $newTemplateId = (int) $newTemplateId;
        $oldTemplateId = (int) $oldTemplateId;
        $overwrite = (bool) $overwrite;
        // fetch new template data
        $newTemplate = BackendExtensionsModel::getTemplate($newTemplateId);
        $newTemplate['data'] = @unserialize($newTemplate['data']);
        // fetch all pages
        $pages = (array) BackendModel::getDB()->getRecords('SELECT *
			 FROM pages
			 WHERE template_id = ? AND status IN (?, ?)', array($oldTemplateId, 'active', 'draft'));
        // there is no active/draft page with the old template id
        if (empty($pages)) {
            return;
        }
        // loop pages
        foreach ($pages as $page) {
            // fetch blocks
            $blocksContent = BackendPagesModel::getBlocks($page['id'], $page['revision_id'], $page['language']);
            // unset revision id
            unset($page['revision_id']);
            // change template
            $page['template_id'] = $newTemplateId;
            // save new page revision
            $page['revision_id'] = BackendPagesModel::update($page);
            // overwrite all blocks with current defaults
            if ($overwrite) {
                // init var
                $blocksContent = array();
                // fetch default blocks for this page
                $defaultBlocks = array();
                if (isset($newTemplate['data']['default_extras_' . $page['language']])) {
                    $defaultBlocks = $newTemplate['data']['default_extras_' . $page['language']];
                } elseif (isset($newTemplate['data']['default_extras'])) {
                    $defaultBlocks = $newTemplate['data']['default_extras'];
                }
                // loop positions
                foreach ($defaultBlocks as $position => $blocks) {
                    // loop blocks
                    foreach ($blocks as $extraId) {
                        // build block
                        $block = array();
                        $block['revision_id'] = $page['revision_id'];
                        $block['position'] = $position;
                        $block['extra_id'] = $extraId;
                        $block['html'] = '';
                        $block['created_on'] = BackendModel::getUTCDate();
                        $block['edited_on'] = $block['created_on'];
                        $block['visible'] = 'Y';
                        $block['sequence'] = count($defaultBlocks[$position]) - 1;
                        // add to the list
                        $blocksContent[] = $block;
                    }
                }
            } else {
                // set new page revision id
                foreach ($blocksContent as &$block) {
                    $block['revision_id'] = $page['revision_id'];
                }
            }
            // insert the blocks
            BackendPagesModel::insertBlocks($blocksContent);
        }
    }
Esempio n. 13
0
 /**
  * Get the navigation-items
  *
  * @return	array
  * @param	string[optional] $language		The language to use, if not provided we will use the working language.
  */
 public static function getNavigation($language = null)
 {
     // redefine
     $language = $language !== null ? (string) $language : FRONTEND_LANGUAGE;
     // does the keys exists in the cache?
     if (!isset(self::$navigation[$language]) || empty(self::$navigation[$language])) {
         // validate file
         if (!SpoonFile::exists(FRONTEND_CACHE_PATH . '/navigation/navigation_' . $language . '.php')) {
             // regenerate cache
             BackendPagesModel::buildCache($language);
         }
         // init var
         $navigation = array();
         // require file
         require FRONTEND_CACHE_PATH . '/navigation/navigation_' . $language . '.php';
         // store
         self::$navigation[$language] = $navigation;
     }
     // return
     return self::$navigation[$language];
 }
Esempio n. 14
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // get the status
         $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active');
         // validate redirect
         $redirectValue = $this->frm->getField('redirect')->getValue();
         if ($redirectValue == 'internal') {
             $this->frm->getField('internal_redirect')->isFilled(BL::err('FieldIsRequired'));
         }
         if ($redirectValue == 'external') {
             $this->frm->getField('external_redirect')->isURL(BL::err('InvalidURL'));
         }
         // init var
         $templateId = (int) $this->frm->getField('template_id')->getValue();
         // loop blocks in template
         for ($i = 0; $i < $this->templates[$templateId]['num_blocks']; $i++) {
             // get the extra id
             $extraId = (int) $this->frm->getField('block_extra_id_' . $i)->getValue();
             // reset some stuff
             if ($extraId > 0) {
                 // type of block
                 if (isset($this->extras[$extraId]['type']) && $this->extras[$extraId]['type'] == 'block') {
                     // home can't have blocks
                     if ($this->record['id'] == 1) {
                         $this->frm->getField('block_html_' . $i)->addError(BL::err('HomeCantHaveBlocks'));
                         $this->frm->addError(BL::err('HomeCantHaveBlocks'));
                     }
                 }
             }
         }
         // set callback for generating an unique URL
         $this->meta->setURLCallback('BackendPagesModel', 'getURL', array($this->record['id'], $this->record['parent_id'], $this->frm->getField('is_action')->getChecked()));
         // cleanup the submitted fields, ignore fields that were edited by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // validate meta
         $this->meta->validate();
         // no errors?
         if ($this->frm->isCorrect()) {
             // init var
             $data = null;
             // build data
             if ($this->frm->getField('is_action')->isChecked()) {
                 $data['is_action'] = true;
             }
             if ($redirectValue == 'internal') {
                 $data['internal_redirect'] = array('page_id' => $this->frm->getField('internal_redirect')->getValue(), 'code' => '301');
             }
             if ($redirectValue == 'external') {
                 $data['external_redirect'] = array('url' => $this->frm->getField('external_redirect')->getValue(), 'code' => '301');
             }
             // build page record
             $page['id'] = $this->record['id'];
             $page['user_id'] = BackendAuthentication::getUser()->getUserId();
             $page['parent_id'] = $this->record['parent_id'];
             $page['template_id'] = (int) $this->frm->getField('template_id')->getValue();
             $page['meta_id'] = (int) $this->meta->save();
             $page['language'] = BackendLanguage::getWorkingLanguage();
             $page['type'] = $this->record['type'];
             $page['title'] = $this->frm->getField('title')->getValue();
             $page['navigation_title'] = $this->frm->getField('navigation_title')->getValue() != '' ? $this->frm->getField('navigation_title')->getValue() : $this->frm->getField('title')->getValue();
             $page['navigation_title_overwrite'] = $this->frm->getField('navigation_title_overwrite')->isChecked() ? 'Y' : 'N';
             $page['hidden'] = $this->frm->getField('hidden')->getValue();
             $page['status'] = $status;
             $page['publish_on'] = BackendModel::getUTCDate(null, $this->record['publish_on']);
             $page['created_on'] = BackendModel::getUTCDate(null, $this->record['created_on']);
             $page['edited_on'] = BackendModel::getUTCDate();
             $page['allow_move'] = $this->record['allow_move'];
             $page['allow_children'] = $this->record['allow_children'];
             $page['allow_edit'] = $this->record['allow_edit'];
             $page['allow_delete'] = $this->record['allow_delete'];
             $page['sequence'] = $this->record['sequence'];
             $page['data'] = $data !== null ? serialize($data) : null;
             // set navigation title
             if ($page['navigation_title'] == '') {
                 $page['navigation_title'] = $page['title'];
             }
             // insert page, store the id, we need it when building the blocks
             $page['revision_id'] = BackendPagesModel::update($page);
             // init var
             $hasBlock = false;
             // build blocks
             $blocks = array();
             // no blocks should go to waste; even if the new template has fewer blocks, retain existing content
             $maxNumBlocks = max(count($this->blocksContent), $this->templates[$page['template_id']]['num_blocks']);
             // loop blocks in template
             for ($i = 0; $i < $maxNumBlocks; $i++) {
                 // check if this block has been submitted
                 if (isset($_POST['block_extra_id_' . $i])) {
                     // get the extra id
                     $extraId = (int) $this->frm->getField('block_extra_id_' . $i)->getValue();
                     // reset some stuff
                     if ($extraId <= 0) {
                         $extraId = null;
                     }
                     // init var
                     $html = null;
                     // extra-type is HTML
                     if ($extraId === null) {
                         // reset vars
                         $extraId = null;
                         $html = (string) $this->frm->getField('block_html_' . $i)->getValue();
                     } else {
                         // type of block
                         if (isset($this->extras[$extraId]['type']) && $this->extras[$extraId]['type'] == 'block') {
                             // home can't have blocks
                             if ($this->record['id'] == 1) {
                                 throw new BackendException('Home can\'t have any blocks.');
                             }
                             // set error
                             if ($hasBlock) {
                                 throw new BackendException('Can\'t add 2 blocks');
                             }
                             // reset var
                             $hasBlock = true;
                         }
                     }
                     // build block
                     $block = array();
                     $block['id'] = isset($this->blocksContent[$i]['id']) ? $this->blocksContent[$i]['id'] : BackendPagesModel::getMaximumBlockId() + ($i + 1);
                     $block['revision_id'] = $page['revision_id'];
                     $block['extra_id'] = $extraId;
                     $block['html'] = $html;
                     $block['status'] = 'active';
                     $block['created_on'] = isset($this->blocksContent[$i]['created_on']) ? BackendModel::getUTCDate(null, $this->blocksContent[$i]['created_on']) : BackendModel::getUTCDate();
                     $block['edited_on'] = BackendModel::getUTCDate();
                 } else {
                     $block = $this->blocksContent[$i];
                     $block['revision_id'] = $page['revision_id'];
                 }
                 // add block
                 $blocks[] = $block;
             }
             // update the blocks
             BackendPagesModel::updateBlocks($blocks, $hasBlock);
             // trigger an event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $page));
             // save tags
             BackendTagsModel::saveTags($page['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // build cache
             BackendPagesModel::buildCache(BL::getWorkingLanguage());
             // active
             if ($page['status'] == 'active') {
                 // edit search index
                 if (is_callable(array('BackendSearchModel', 'editIndex'))) {
                     // init var
                     $text = '';
                     // build search-text
                     foreach ($blocks as $block) {
                         $text .= ' ' . $block['html'];
                     }
                     // add
                     BackendSearchModel::editIndex($this->getModule(), $page['id'], array('title' => $page['title'], 'text' => $text));
                 }
                 // build URL
                 $redirectUrl = BackendModel::createURLForAction('edit') . '&id=' . $page['id'] . '&report=edited&var=' . urlencode($page['title']) . '&highlight=row-' . $page['id'];
             } elseif ($page['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $redirectUrl = BackendModel::createURLForAction('edit') . '&id=' . $page['id'] . '&report=saved-as-draft&var=' . urlencode($page['title']) . '&highlight=row-' . $page['id'] . '&draft=' . $page['revision_id'];
             }
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
Esempio n. 15
0
    /**
     * Switch templates for all existing pages
     *
     * @return	void
     * @param	int $oldTemplateId			The id of the new template to replace.
     * @param	int $newTemplateId			The id of the new template to use.
     */
    public static function updatePagesTemplates($oldTemplateId, $newTemplateId)
    {
        // fetch new template data
        $newTemplate = BackendPagesModel::getTemplate($newTemplateId);
        $newTemplate['data'] = @unserialize($newTemplate['data']);
        // fetch all pages
        $pages = BackendModel::getDB()->getRecords('SELECT *
													FROM pages
													WHERE template_id = ? AND status IN (?, ?)', array($oldTemplateId, 'active', 'draft'));
        // there is no active/draft page with the old template id
        if (empty($pages)) {
            return;
        }
        // loop pages
        foreach ($pages as $page) {
            // fetch blocks
            $blocksContent = BackendPagesModel::getBlocksRevision($page['id'], $page['revision_id'], $page['language']);
            // unset revision id
            unset($page['revision_id']);
            // change template
            $page['template_id'] = $newTemplateId;
            // save new page revision
            $page['revision_id'] = BackendPagesModel::update($page);
            // init blocks array
            $blocks = array();
            // loop missing blocks
            for ($i = 0; $i < max(count($blocksContent), (int) $newTemplate['num_blocks']); $i++) {
                $block = array();
                // block already exists
                if (isset($blocksContent[$i])) {
                    $block = $blocksContent[$i];
                    $block['created_on'] = BackendModel::getUTCDate(null, $block['created_on']);
                    $block['edited_on'] = BackendModel::getUTCDate(null, $block['edited_on']);
                    $block['revision_id'] = $page['revision_id'];
                } else {
                    $block['id'] = BackendPagesModel::getMaximumBlockId() + $i + 1;
                    $block['revision_id'] = $page['revision_id'];
                    $block['html'] = '';
                    $block['status'] = 'active';
                    $block['created_on'] = BackendModel::getUTCDate();
                    $block['edited_on'] = $block['created_on'];
                    $block['html'] = '';
                    $block['extra_id'] = null;
                    $block['has_extra'] = 'N';
                }
                // verify that there is no existing content and that we actually have new default content
                if (!isset($blocksContent[$i]) || !$blocksContent[$i]['html'] && !$blocksContent[$i]['extra_id'] && $i < $newTemplate['num_blocks']) {
                    // get default extras in this language
                    if (isset($newTemplate['data']['default_extras_' . $page['language']])) {
                        // check if a default extra has been defined
                        if ($newTemplate['data']['default_extras_' . $page['language']][$i] != 'editor') {
                            $page['has_extra'] = 'Y';
                            $block['extra_id'] = $newTemplate['data']['default_extras_' . $page['language']][$i];
                        } else {
                            $block['extra_id'] = null;
                        }
                    } else {
                        // check if a default extra has been defined
                        if ($newTemplate['data']['default_extras'][$i] != 'editor') {
                            $page['has_extra'] = 'Y';
                            $block['extra_id'] = $newTemplate['data']['default_extras'][$i];
                        } else {
                            $block['extra_id'] = null;
                        }
                    }
                }
                // add block
                $blocks[] = $block;
            }
            // insert the blocks
            BackendPagesModel::updateBlocks($blocks, $page['has_extra'] == 'Y');
        }
    }