Пример #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $id = \SpoonFilter::getPostValue('id', null, 0, 'int');
     $tag = trim(\SpoonFilter::getPostValue('value', null, '', 'string'));
     // validate id
     if ($id === 0) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     } else {
         // validate tag name
         if ($tag === '') {
             $this->output(self::BAD_REQUEST, null, BL::err('NameIsRequired'));
         } else {
             // check if tag exists
             if (BackendTagsModel::existsTag($tag)) {
                 $this->output(self::BAD_REQUEST, null, BL::err('TagAlreadyExists'));
             } else {
                 $item['id'] = $id;
                 $item['tag'] = \SpoonFilter::htmlspecialchars($tag);
                 $item['url'] = BackendTagsModel::getURL(CommonUri::getUrl(\SpoonFilter::htmlspecialcharsDecode($item['tag'])), $id);
                 BackendTagsModel::update($item);
                 $this->output(self::OK, $item, vsprintf(BL::msg('Edited'), array($item['tag'])));
             }
         }
     }
 }
Пример #2
0
 /**
  * Delete a question
  *
  * @param int $id
  */
 public static function delete($id)
 {
     $question = self::get($id);
     /** @var $db \SpoonDatabase */
     $db = BackendModel::getContainer()->get('database');
     $db->delete('faq_questions', 'id = ?', array((int) $id));
     $db->delete('meta', 'id = ?', array((int) $question['meta_id']));
     BackendTagsModel::saveTags($id, '', 'Faq');
 }
Пример #3
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $term = \SpoonFilter::getPostValue('term', null, '');
     // validate
     if ($term == '') {
         $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.');
     } else {
         // get tags
         $tags = BackendTagsModel::getStartsWith($term);
         // output
         $this->output(self::OK, $tags);
     }
 }
Пример #4
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // action to execute
     $action = \SpoonFilter::getGetValue('action', array('delete'), 'delete');
     // no id's provided
     if (!isset($_GET['id'])) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=no-selection');
     } else {
         // at least one id
         // redefine id's
         $aIds = (array) $_GET['id'];
         // delete comment(s)
         if ($action == 'delete') {
             BackendTagsModel::delete($aIds);
         }
     }
     // redirect
     $this->redirect(BackendModel::createURLForAction('Index') . '&report=deleted');
 }
Пример #5
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendCatalogModel::exists($this->id)) {
         parent::execute();
         $this->record = BackendCatalogModel::get($this->id);
         // clean the tags
         BackendTagsModel::saveTags($this->id, '', $this->URL->getModule());
         // clean the related products
         BackendCatalogModel::saveRelatedProducts($this->id, array());
         // delete record
         BackendCatalogModel::delete($this->id);
         // delete search indexes
         BackendSearchModel::removeIndex($this->getModule(), $this->id);
         BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         $this->redirect(BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['title']));
     } else {
         $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing');
     }
 }
Пример #6
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         // required fields
         $fields['category_id']->isFilled(BL::err('FieldIsRequired'));
         if ($fields['category_id']->getValue() == 'no_category') {
             $fields['category_id']->addError(BL::err('FieldIsRequired'));
         }
         // validate meta
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build the item
             $item['language'] = BL::getWorkingLanguage();
             $item['price'] = $fields['price']->getValue();
             $item['summary'] = $fields['summary_nl']->getValue();
             $item['text'] = $fields['text_nl']->getValue();
             $item['allow_comments'] = $fields['allow_comments']->getChecked() ? 'Y' : 'N';
             $item['num_comments'] = 0;
             $item['sequence'] = BackendCatalogModel::getMaximumSequence() + 1;
             $item['category_id'] = $fields['category_id']->getValue();
             $item['brand_id'] = $fields['brand_id']->getValue();
             $item['meta_id'] = $this->meta->save();
             $item['ballcolor'] = $fields['ballcolor']->getValue();
             $item['frontpage'] = $fields['frontpage']->getChecked();
             $item['contact'] = $fields['contact']->getChecked();
             // insert it
             $item['id'] = BackendCatalogModel::insert($item);
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['title'] = $this->frm->getField('title_' . $language)->getValue();
                 $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['summary'] = $this->frm->getField('summary_' . $language)->getValue();
                 $itemLanguage['url'] = BackendCatalogModel::getURLLanguage($this->frm->getField('title_' . $language)->getValue(), null, $language);
                 $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue();
                 BackendCatalogModel::insertLanguage($itemLanguage);
             }
             $specificationArray = array();
             // loop trough specifications and insert values
             foreach ($this->specifications as $specification) {
                 // build the specification
                 $specificationArray['product_id'] = $item['id'];
                 $specificationArray['specification_id'] = $specification['id'];
                 foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                     $field = 'specification' . $specification['id'] . '_' . $language;
                     // check if there is an value
                     if ($fields[$field]->getValue() != null) {
                         $specificationArray['value'] = $fields[$field]->getValue();
                         $specificationArray['language'] = $language;
                         // insert specification with product id and value
                         BackendCatalogModel::insertSpecificationValue($specificationArray);
                     }
                 }
             }
             // save the tags
             BackendTagsModel::saveTags($item['id'], $fields['tags']->getValue(), $this->URL->getModule());
             // save the related products
             BackendCatalogModel::saveRelatedProducts($item['id'], $this->frm->getField('related_products')->getValue());
             // add search index
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $this->frm->getField('title_nl')->getValue(), 'summary' => $this->frm->getField('summary_nl')->getValue(), 'text' => $this->frm->getField('text_nl')->getValue()));
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', $item);
             // redirect page
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']);
         }
     }
 }
Пример #7
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $this->output(self::OK, BackendTagsModel::getAll());
 }
Пример #8
0
 /**
  * Inserts a complete post item based on some arrays of data
  *
  * This method's purpose is to be able to insert a post (possibly with all its metadata, tags, and comments)
  * in one method call. As much data as possible has been made optional, to be able to do imports where only
  * fractions of the data we need are known.
  *
  * The item array should have at least a 'title' and a 'text' property other properties are optional.
  * The meta array has only optional properties. You can use these to override the defaults.
  * The tags array is just a list of tagnames as string.
  * The comments array is an array of arrays with comment properties. A comment should have
  * at least 'author', 'email', and 'text' properties.
  *
  * @param array $item     The data to insert.
  * @param array $meta     The metadata to insert.
  * @param array $tags     The tags to connect to this post.
  * @param array $comments The comments attached to this post.
  *
  * @return int
  * @throws Exception
  */
 public static function insertCompletePost($item, $meta = array(), $tags = array(), $comments = array())
 {
     // Build item
     if (!isset($item['id'])) {
         $item['id'] = (int) self::getMaximumId() + 1;
     }
     if (!isset($item['user_id'])) {
         $item['user_id'] = BackendAuthentication::getUser()->getUserId();
     }
     if (!isset($item['hidden'])) {
         $item['hidden'] = 'N';
     }
     if (!isset($item['allow_comments'])) {
         $item['allow_comments'] = 'Y';
     }
     if (!isset($item['num_comments'])) {
         $item['num_comments'] = 0;
     }
     if (!isset($item['status'])) {
         $item['status'] = 'active';
     }
     if (!isset($item['language'])) {
         $item['language'] = BL::getWorkingLanguage();
     }
     if (!isset($item['publish_on'])) {
         $item['publish_on'] = BackendModel::getUTCDate();
     }
     if (!isset($item['created_on'])) {
         $item['created_on'] = BackendModel::getUTCDate();
     }
     if (!isset($item['edited_on'])) {
         $item['edited_on'] = BackendModel::getUTCDate();
     }
     if (!isset($item['category_id'])) {
         $item['category_id'] = 1;
     }
     if (!isset($item['title']) || !isset($item['text'])) {
         throw new Exception('$item should at least have a title and a text property');
     }
     // Set drafts hidden
     if (strtotime((string) $item['publish_on']) > time()) {
         $item['hidden'] = 'Y';
         $item['status'] = 'draft';
     }
     // Build meta
     if (!is_array($meta)) {
         $meta = array();
     }
     if (!isset($meta['keywords'])) {
         $meta['keywords'] = $item['title'];
     }
     if (!isset($meta['keywords_overwrite'])) {
         $meta['keywords_overwrite'] = 'N';
     }
     if (!isset($meta['description'])) {
         $meta['description'] = $item['title'];
     }
     if (!isset($meta['description_overwrite'])) {
         $meta['description_overwrite'] = 'N';
     }
     if (!isset($meta['title'])) {
         $meta['title'] = $item['title'];
     }
     if (!isset($meta['title_overwrite'])) {
         $meta['title_overwrite'] = 'N';
     }
     if (!isset($meta['url'])) {
         $meta['url'] = self::getURL($item['title']);
     }
     if (!isset($meta['url_overwrite'])) {
         $meta['url_overwrite'] = 'N';
     }
     if (!isset($meta['data'])) {
         $meta['data'] = serialize(array('seo_index' => 'index', 'seo_follow' => 'follow'));
     }
     // Write meta to db
     $item['meta_id'] = BackendModel::getContainer()->get('database')->insert('meta', $meta);
     // Write post to db
     $item['revision_id'] = self::insert($item);
     // Any tags?
     if (!empty($tags)) {
         BackendTagsModel::saveTags($item['id'], implode(',', $tags), 'blog');
     }
     // Any comments?
     foreach ($comments as $comment) {
         // We require some fields (author, email, text)
         if (!isset($comment['author']) || !isset($comment['email']) || !isset($comment['text'])) {
             continue;
         }
         // Set some defaults
         if (!isset($comment['language'])) {
             $comment['language'] = BL::getWorkingLanguage();
         }
         if (!isset($comment['created_on'])) {
             $comment['created_on'] = BackendModel::getUTCDate();
         }
         if (!isset($comment['status'])) {
             $comment['status'] = 'published';
         }
         if (!isset($comment['data'])) {
             $comment['data'] = serialize(array('server' => $_SERVER));
         }
         if (!isset($comment['website'])) {
             $comment['website'] = '';
         }
         $comment['post_id'] = $item['id'];
         $comment['data'] = serialize(array('server' => $_SERVER));
         // Insert the comment
         self::insertComment($comment);
     }
     // Return
     return $item['revision_id'];
 }
Пример #9
0
 /**
  * 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::saveIndex($this->getModule(), $item['id'], array('title' => $item['question'], 'text' => $item['answer']));
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=added&var=' . urlencode($item['question']) . '&highlight=' . $item['id']);
         }
     }
 }
Пример #10
0
 /**
  * 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();
         // validate fields
         $this->frm->getField('name')->isFilled(BL::err('NameIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build tag
             $item['id'] = $this->id;
             $item['tag'] = $this->frm->getField('name')->getValue();
             $item['url'] = BackendTagsModel::getURL(CommonUri::getUrl(\SpoonFilter::htmlspecialcharsDecode($item['tag'])), $this->id);
             // update the item
             BackendTagsModel::update($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=edited&var=' . urlencode($item['tag']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Пример #11
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();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build album array
             $album['language'] = BL::getWorkingLanguage();
             $album['meta_id'] = $this->meta->save();
             $album['title'] = (string) $this->frm->getField('title')->getValue();
             $album['sequence'] = (int) BackendGalleryModel::getMaximumAlbumSequence() + 1;
             $album['hidden'] = (string) $this->frm->getField('hidden')->getValue();
             $album['show_in_overview'] = (string) $this->frm->getField('show_in_overview')->getValue();
             $album['category_id'] = (int) $this->frm->getField('category')->getValue();
             $album['publish_on'] = BackendModel::getUTCDate();
             $album['description'] = (string) $this->frm->getField('description')->getValue();
             // first, insert the album
             $album['id'] = BackendGalleryModel::insertAlbum($album, (bool) $this->frm->getField('gallery')->getValue(), (bool) $this->frm->getField('slideshow')->getValue());
             // save the tags
             BackendTagsModel::saveTags($album['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_album', array('item' => $album));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('albums') . '&report=added-album&var=' . urlencode($album['title']) . '&highlight=row-' . $album['id']);
         }
     }
 }
Пример #12
0
 /**
  * Delete a page
  *
  * @param int    $id         The id of the page to delete.
  * @param string $language   The language wherein the page will be deleted,
  *                           if not provided we will use the working language.
  * @param int    $revisionId If specified the given revision will be deleted, used for deleting drafts.
  *
  * @return bool
  */
 public static function delete($id, $language = null, $revisionId = null)
 {
     // redefine
     $id = (int) $id;
     $language = $language === null ? BL::getWorkingLanguage() : (string) $language;
     // get db
     $db = BackendModel::getContainer()->get('database');
     // get record
     $page = self::get($id, $revisionId, $language);
     // validate
     if (empty($page)) {
         return false;
     }
     if ($page['allow_delete'] == 'N') {
         return false;
     }
     // get revision ids
     $revisionIDs = (array) $db->getColumn('SELECT i.revision_id
          FROM pages AS i
          WHERE i.id = ? AND i.language = ?', array($id, $language));
     // get meta ids
     $metaIDs = (array) $db->getColumn('SELECT i.meta_id
          FROM pages AS i
          WHERE i.id = ? AND i.language = ?', array($id, $language));
     // 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 tags
     BackendTagsModel::saveTags($id, '', 'Pages');
     // return
     return true;
 }
Пример #13
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');
         // 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'));
         // validate meta
         $this->meta->validate();
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['meta_id'] = $this->meta->save();
             // this is used to let our model know the status (active, archive, draft) of the edited item
             $item['revision_id'] = $this->record['revision_id'];
             $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['edited_on'] = BackendModel::getUTCDate();
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['status'] = $status;
             if ($this->imageIsAllowed) {
                 $item['image'] = $this->record['image'];
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/blog/images';
                 // create folders if needed
                 $fs = new Filesystem();
                 $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128'));
                 // If the image should be deleted, only the database entry is refreshed.
                 // The revision should keep it's file.
                 if ($this->frm->getField('delete_image')->isChecked()) {
                     // reset the name
                     $item['image'] = null;
                 }
                 // new image given?
                 if ($this->frm->getField('image')->isFilled()) {
                     // build the image name
                     // we use the previous revision-id in the filename to make the filename unique between
                     // the different revisions, to prevent that a new file would
                     // overwrite images of previous revisions that have the same title, and thus, the same filename
                     $item['image'] = $this->meta->getURL() . '-' . BL::getWorkingLanguage() . '-' . $item['revision_id'] . '.' . $this->frm->getField('image')->getExtension();
                     // upload the image & generate thumbnails
                     $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
                 } elseif ($item['image'] != null) {
                     // generate the new filename
                     $image = new File($imagePath . '/source/' . $item['image']);
                     $newName = $this->meta->getURL() . '-' . BL::getWorkingLanguage() . '-' . $item['revision_id'] . '.' . $image->getExtension();
                     // extract the filenames excluding …-[language]-[revision-id].jpg
                     // to properly compare them to eachother
                     $regex = '/(.*)-[a-z]{2}-[0-9]+\\.(.*)/';
                     // only copy if the new name differs from the old filename
                     if (preg_replace($regex, '$1', $newName) != preg_replace($regex, '$1', $item['image'])) {
                         // loop folders
                         foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) {
                             $fs->copy($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $newName);
                         }
                         // assign the new name to the database
                         $item['image'] = $newName;
                     }
                 }
             } else {
                 $item['image'] = null;
             }
             // update the item
             $item['revision_id'] = BackendBlogModel::update($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // recalculate comment count so the new revision has the correct count
             BackendBlogModel::reCalculateCommentCount(array($this->id));
             // save the tags
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // active
             if ($item['status'] == 'active') {
                 // edit search index
                 BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text']));
                 // ping
                 if ($this->get('fork.settings')->get($this->URL->getModule(), 'ping_services', false)) {
                     BackendModel::ping(SITE_URL . BackendModel::getURLForBlock($this->URL->getModule(), 'detail') . '/' . $this->meta->getURL());
                 }
                 // build URL
                 $redirectUrl = BackendModel::createURLForAction('Index') . '&report=edited&var=' . urlencode($item['title']) . '&id=' . $this->id . '&highlight=row-' . $item['revision_id'];
             } elseif ($item['status'] == 'draft') {
                 // draft: everything is saved, so redirect to the edit action
                 $redirectUrl = BackendModel::createURLForAction('Edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id'];
             }
             // append to redirect URL
             if ($this->categoryId != null) {
                 $redirectUrl .= '&category=' . $this->categoryId;
             }
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
Пример #14
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         //            $fields['title']->isFilled(BL::err('FieldIsRequired'));
         //            $fields['summary']->isFilled(BL::err('FieldIsRequired'));
         $fields['category_id']->isFilled(BL::err('FieldIsRequired'));
         if ($fields['category_id']->getValue() == 'no_category') {
             $fields['category_id']->addError(BL::err('FieldIsRequired'));
         }
         // validate meta
         $this->meta->validate();
         //--Validate Media
         $this->media->validate();
         if ($this->frm->isCorrect()) {
             $item['id'] = $this->id;
             $item['language'] = BL::getWorkingLanguage();
             $item['price'] = $fields['price']->getValue();
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['brand_id'] = $fields['brand_id']->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['frontpage'] = $this->frm->getField('frontpage')->getChecked();
             $item['contact'] = $this->frm->getField('contact')->getChecked();
             $item['meta_id'] = $this->meta->save();
             $item['ballcolor'] = $fields['ballcolor']->getValue();
             BackendCatalogModel::update($item);
             $item['id'] = $this->id;
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['title'] = $this->frm->getField('title_' . $language)->getValue();
                 $itemLanguage['summary'] = $this->frm->getField('summary_' . $language)->getValue();
                 $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['url'] = BackendCatalogModel::getURLLanguage($this->frm->getField('title_' . $language)->getValue(), $item['id'], $language);
                 $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue();
                 BackendCatalogModel::updateLanguage($itemLanguage, $language);
             }
             $specificationArray = array();
             // loop trough specifications and insert values
             foreach ($this->specifications as $specification) {
                 foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                     $field = 'specification' . $specification['id'] . '_' . $language;
                     $specificationArray['value'] = $fields[$field]->getValue();
                     $specificationArray['language'] = $language;
                     $specificationArray['product_id'] = $item['id'];
                     $specificationArray['specification_id'] = $specification['id'];
                     // when specification value already exists. update value
                     if (BackendCatalogModel::existsSpecificationValue($item['id'], $specification['id'], $language) != false) {
                         // update specification with product id and value
                         BackendCatalogModel::updateSpecificationValue($specification['id'], $item['id'], $language, $specificationArray);
                     } else {
                         // when specification value doesnt exists, insert new value
                         BackendCatalogModel::insertSpecificationValue($specificationArray);
                     }
                 }
             }
             // save the tags
             BackendTagsModel::saveTags($item['id'], $fields['tags']->getValue(), $this->URL->getModule());
             // add search index
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $this->frm->getField('title_nl')->getValue(), 'summary' => $this->frm->getField('summary_nl')->getValue(), 'text' => $this->frm->getField('text_nl')->getValue()));
             // save related projects
             BackendCatalogModel::saveRelatedProducts($item['id'], $this->frm->getField('related_products')->getValue(), $this->relatedProducts);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }
Пример #15
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');
         // 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;
             // insert the item
             $item['revision_id'] = BackendBlogModel::insert($item);
             if ($this->imageIsAllowed) {
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/blog/images';
                 // create folders if needed
                 $fs = new Filesystem();
                 $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128'));
                 // image provided?
                 if ($this->frm->getField('image')->isFilled()) {
                     // build the image name
                     $item['image'] = $this->meta->getURL() . '-' . BL::getWorkingLanguage() . '-' . $item['revision_id'] . '.' . $this->frm->getField('image')->getExtension();
                     // upload the image & generate thumbnails
                     $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
                     // add the image to the database without changing the revision id
                     BackendBlogModel::updateRevision($item['revision_id'], array('image' => $item['image']));
                 }
             }
             // 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::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text']));
                 // ping
                 if ($this->get('fork.settings')->get($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') {
                 // 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']);
             }
         }
     }
 }
Пример #16
0
 /**
  * Validate the form
  *
  * @return void
  */
 private function validateForm()
 {
     //--Check if the form is submitted
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // first, build the album array
             $album['id'] = (int) $this->id;
             $album['extra_id'] = $this->record['extra_id'];
             $album['title'] = (string) $this->frm->getField('title')->getValue();
             $album['description'] = (string) $this->frm->getField('description')->getValue();
             $album['category_id'] = (int) $this->frm->getField('category')->getValue();
             $album['meta_id'] = $this->meta->save();
             $album['language'] = (string) BL::getWorkingLanguage();
             $album['hidden'] = (string) $this->frm->getField('hidden')->getValue();
             $album['show_in_overview'] = (string) $this->frm->getField('show_in_overview')->getValue();
             // ... then, update the album
             BackendGalleriaModel::updateAlbum($album);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_album', array('item' => $album));
             // save the tags
             BackendTagsModel::saveTags($album['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('albums') . '&report=edited-album&var=' . urlencode($album['title']) . '&highlight=row-' . $album['id']);
         }
     }
 }
Пример #17
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->meta->setUrlCallback('Backend\\Modules\\Faq\\Engine\\Model', 'getURL', array($this->record['id']));
         $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['id'] = $this->id;
             $item['meta_id'] = $this->meta->save(true);
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['language'] = $this->record['language'];
             $item['question'] = $this->frm->getField('title')->getValue();
             $item['answer'] = $this->frm->getField('answer')->getValue(true);
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             // update the item
             BackendFaqModel::update($item);
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // edit search index
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['question'], 'text' => $item['answer']));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=saved&var=' . urlencode($item['question']) . '&highlight=' . $item['id']);
         }
     }
 }
Пример #18
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('Backend\\Modules\\Pages\\Engine\\Model', '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' => BackendPagesModel::getEncodedRedirectURL($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'] = BL::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')->getActualValue();
             $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']);
             }
         }
     }
 }