コード例 #1
0
ファイル: copy.php プロジェクト: netconstructor/forkcms
    /**
     * 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);
    }
コード例 #2
0
ファイル: add.php プロジェクト: richsage/forkcms
 /**
  * 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');
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid'));
         $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid'));
         $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->getField('category_id')->getValue() == 'new_category') {
             $this->frm->getField('category_id')->addError(BL::err('FieldIsRequired'));
         }
         if ($this->imageIsAllowed) {
             // validate the image
             if ($this->frm->getField('image')->isFilled()) {
                 // image extension and mime type
                 $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
                 $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
             }
         }
         // validate meta
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = (int) BackendBlogModel::getMaximumId() + 1;
             $item['meta_id'] = $this->meta->save();
             $item['category_id'] = (int) $this->frm->getField('category_id')->getValue();
             $item['user_id'] = $this->frm->getField('user_id')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['introduction'] = $this->frm->getField('introduction')->getValue();
             $item['text'] = $this->frm->getField('text')->getValue();
             $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time')));
             $item['created_on'] = BackendModel::getUTCDate();
             $item['edited_on'] = $item['created_on'];
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['num_comments'] = 0;
             $item['status'] = $status;
             if ($this->imageIsAllowed) {
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/blog/images';
                 // validate the image
                 if ($this->frm->getField('image')->isFilled()) {
                     // build the image name
                     $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                     // upload the image
                     $this->frm->getField('image')->moveFile($imagePath . '/source/' . $item['image']);
                 }
             }
             // insert the item
             $item['revision_id'] = BackendBlogModel::insert($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // save the tags
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // active
             if ($item['status'] == 'active') {
                 // add search index
                 BackendSearchModel::addIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text']));
                 // ping
                 if (BackendModel::getModuleSetting($this->getModule(), 'ping_services', false)) {
                     BackendModel::ping(SITE_URL . BackendModel::getURLForBlock('blog', 'detail') . '/' . $this->meta->getURL());
                 }
                 // everything is saved, so redirect to the overview
                 $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['revision_id']);
             } elseif ($item['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $this->redirect(BackendModel::createURLForAction('edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id']);
             }
         }
     }
 }
コード例 #3
0
ファイル: add.php プロジェクト: richsage/forkcms
 /**
  * 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(0, null, $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
             $parentId = 0;
             $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'] = BackendPagesModel::getMaximumPageId() + 1;
             $page['user_id'] = BackendAuthentication::getUser()->getUserId();
             $page['parent_id'] = $parentId;
             $page['template_id'] = (int) $this->frm->getField('template_id')->getValue();
             $page['meta_id'] = (int) $this->meta->save();
             $page['language'] = BackendLanguage::getWorkingLanguage();
             $page['type'] = 'root';
             $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();
             $page['created_on'] = BackendModel::getUTCDate();
             $page['edited_on'] = BackendModel::getUTCDate();
             $page['allow_move'] = 'Y';
             $page['allow_children'] = 'Y';
             $page['allow_edit'] = 'Y';
             $page['allow_delete'] = 'Y';
             $page['sequence'] = BackendPagesModel::getMaximumSequence($parentId) + 1;
             $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::insert($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_add', $page);
             // save tags
             BackendTagsModel::saveTags($page['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // build the 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::addIndex($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=added&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['revision_id'] . '&draft=' . $page['revision_id']);
             }
         }
     }
 }
コード例 #4
0
ファイル: add.php プロジェクト: netconstructor/forkcms
 /**
  * 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'));
         }
         // set callback for generating an unique URL
         $this->meta->setURLCallback('BackendPagesModel', 'getURL', array(0, null, $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
             $parentId = 0;
             $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'] = BackendPagesModel::getMaximumPageId() + 1;
             $page['user_id'] = BackendAuthentication::getUser()->getUserId();
             $page['parent_id'] = $parentId;
             $page['template_id'] = (int) $this->frm->getField('template_id')->getValue();
             $page['meta_id'] = (int) $this->meta->save();
             $page['language'] = BackendLanguage::getWorkingLanguage();
             $page['type'] = 'root';
             $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();
             $page['created_on'] = BackendModel::getUTCDate();
             $page['edited_on'] = BackendModel::getUTCDate();
             $page['allow_move'] = 'Y';
             $page['allow_children'] = 'Y';
             $page['allow_edit'] = 'Y';
             $page['allow_delete'] = 'Y';
             $page['sequence'] = BackendPagesModel::getMaximumSequence($parentId) + 1;
             $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::insert($page);
             // init var
             $hasBlock = false;
             // build blocks
             $blocks = array();
             // loop blocks in template
             for ($i = 0; $i < $this->templates[$page['template_id']]['num_blocks']; $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 = $this->frm->getField('block_html_' . $i)->getValue();
                 } else {
                     // type of block
                     if (isset($this->extras[$extraId]['type']) && $this->extras[$extraId]['type'] == 'block') {
                         // set error
                         if ($hasBlock) {
                             $this->frm->getField('block_extra_id_' . $i)->addError('Can\'t add 2 blocks');
                         }
                         // reset var
                         $hasBlock = true;
                     }
                 }
                 // build block
                 $block = array();
                 $block['id'] = BackendPagesModel::getMaximumBlockId() + ($i + 1);
                 $block['revision_id'] = $page['revision_id'];
                 $block['extra_id'] = $extraId;
                 $block['html'] = $html;
                 $block['status'] = 'active';
                 $block['created_on'] = BackendModel::getUTCDate();
                 $block['edited_on'] = $block['created_on'];
                 // add block
                 $blocks[] = $block;
             }
             // insert the blocks
             BackendPagesModel::insertBlocks($blocks, $hasBlock);
             // trigger an event
             BackendModel::triggerEvent($this->getModule(), 'after_add', $page);
             // save tags
             BackendTagsModel::saveTags($page['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // build the cache
             BackendPagesModel::buildCache(BL::getWorkingLanguage());
             // active
             if ($page['status'] == 'active') {
                 // add search index
                 if (is_callable(array('BackendSearchModel', 'addIndex'))) {
                     // init var
                     $text = '';
                     // build search-text
                     foreach ($blocks as $block) {
                         $text .= ' ' . $block['html'];
                     }
                     // add
                     BackendSearchModel::addIndex($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=added&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['revision_id'] . '&draft=' . $page['revision_id']);
             }
         }
     }
 }
コード例 #5
0
ファイル: add.php プロジェクト: richsage/forkcms
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('QuestionIsRequired'));
         $this->frm->getField('answer')->isFilled(BL::err('AnswerIsRequired'));
         $this->frm->getField('category_id')->isFilled(BL::err('CategoryIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['meta_id'] = $this->meta->save();
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['user_id'] = BackendAuthentication::getUser()->getUserId();
             $item['language'] = BL::getWorkingLanguage();
             $item['question'] = $this->frm->getField('title')->getValue();
             $item['answer'] = $this->frm->getField('answer')->getValue(true);
             $item['created_on'] = BackendModel::getUTCDate();
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['sequence'] = BackendFaqModel::getMaximumSequence($this->frm->getField('category_id')->getValue()) + 1;
             // save the data
             $item['id'] = BackendFaqModel::insert($item);
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // add search index
             BackendSearchModel::addIndex('faq', $item['id'], array('title' => $item['question'], 'text' => $item['answer']));
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['question']) . '&highlight=row-' . $item['id']);
         }
     }
 }