Ejemplo n.º 1
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 field
         $this->frm->getField('synonym')->isFilled(BL::err('SynonymIsRequired'));
         $this->frm->getField('term')->isFilled(BL::err('TermIsRequired'));
         if (BackendSearchModel::existsSynonymByTerm($this->frm->getField('term')->getValue())) {
             $this->frm->getField('term')->addError(BL::err('TermExists'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item = array();
             $item['term'] = $this->frm->getField('term')->getValue();
             $item['synonym'] = $this->frm->getField('synonym')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             // insert the item
             $id = BackendSearchModel::insertSynonym($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_synonym', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Synonyms') . '&report=added-synonym&var=' . rawurlencode($item['term']) . '&highlight=row-' . $id);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendBlogModel::exists($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // set category id
         $this->categoryId = \SpoonFilter::getGetValue('category', null, null, 'int');
         if ($this->categoryId == 0) {
             $this->categoryId = null;
         }
         // get data
         $this->record = (array) BackendBlogModel::get($this->id);
         // delete item
         BackendBlogModel::delete($this->id);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         // delete search indexes
         BackendSearchModel::removeIndex($this->getModule(), $this->id);
         // build redirect URL
         $redirectUrl = BackendModel::createURLForAction('Index') . '&report=deleted&var=' . urlencode($this->record['title']);
         // append to redirect URL
         if ($this->categoryId != null) {
             $redirectUrl .= '&category=' . $this->categoryId;
         }
         // item was deleted, so redirect
         $this->redirect($redirectUrl);
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
Ejemplo n.º 3
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendMailengineModel::exists($this->id)) {
         parent::execute();
         $this->record = (array) BackendMailengineModel::get($this->id);
         BackendMailengineModel::delete($this->id);
         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['subject']));
     } else {
         $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing');
     }
 }
Ejemplo n.º 4
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendAddressesModel::exists($this->id)) {
         parent::execute();
         $this->record = (array) BackendAddressesModel::get($this->id);
         BackendAddressesModel::delete($this->id);
         BackendAddressesModel::deleteGroupsFromAddress($this->id);
         // delete the image
         \SpoonFile::delete(FRONTEND_FILES_PATH . '/Addresses/Images/Source/' . $this->record['image']);
         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['id']));
     } else {
         $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing');
     }
 }
Ejemplo n.º 5
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendSearchModel::existsSynonymById($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // get data
         $this->record = (array) BackendSearchModel::getSynonym($this->id);
         // delete item
         BackendSearchModel::deleteSynonym($this->id);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_delete_synonym', array('id' => $this->id));
         // item was deleted, so redirect
         $this->redirect(BackendModel::createURLForAction('Synonyms') . '&report=deleted-synonym&var=' . rawurlencode($this->record['term']));
     } else {
         $this->redirect(BackendModel::createURLForAction('Synonyms') . '&error=non-existing');
     }
 }
Ejemplo n.º 6
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=' . rawurlencode($page['title']));
         } else {
             $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing');
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing');
     }
 }
Ejemplo n.º 7
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');
     }
 }
Ejemplo n.º 8
0
 /**
  * Validates the settings form
  */
 private function validateForm()
 {
     // form is submitted
     if ($this->frm->isSubmitted()) {
         // validate module weights
         foreach ($this->modules as $i => $module) {
             // only if this module is enabled
             if ($this->frm->getField('search_' . $module['module'])->getChecked()) {
                 // valid weight?
                 $this->frm->getField('search_' . $module['module'] . '_weight')->isDigital(BL::err('WeightNotNumeric'));
                 $this->modules[$i]['txtError'] = $this->frm->getField('search_' . $module['module'] . '_weight')->getErrors();
             }
         }
         // form is validated
         if ($this->frm->isCorrect()) {
             // set our settings
             $this->get('fork.settings')->set($this->getModule(), 'overview_num_items', $this->frm->getField('overview_num_items')->getValue());
             $this->get('fork.settings')->set($this->getModule(), 'autocomplete_num_items', $this->frm->getField('autocomplete_num_items')->getValue());
             $this->get('fork.settings')->set($this->getModule(), 'autosuggest_num_items', $this->frm->getField('autosuggest_num_items')->getValue());
             $this->get('fork.settings')->set($this->getModule(), 'use_sitelinks_search_box', $this->frm->getField('use_sitelinks_search_box')->isChecked());
             // module search
             foreach ((array) $this->modules as $module) {
                 $searchable = $this->frm->getField('search_' . $module['module'])->getChecked() ? 'Y' : 'N';
                 $weight = $this->frm->getField('search_' . $module['module'] . '_weight')->getValue();
                 // insert, or update
                 BackendSearchModel::insertModuleSettings($module, $searchable, $weight);
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_changed_settings');
             // redirect to the settings page
             $this->redirect(BackendModel::createURLForAction('Settings') . '&report=saved');
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * Copy pages
  *
  * @param string $from The language code to copy the pages from.
  * @param string $to   The language code we want to copy the pages to.
  */
 public static function copy($from, $to)
 {
     // get db
     $db = BackendModel::getContainer()->get('database');
     // copy contentBlocks and get copied contentBlockIds
     $copyContentBlocks = new CopyContentBlocksToOtherLocale(Locale::fromString($to), Locale::fromString($from));
     BackendModel::get('command_bus')->handle($copyContentBlocks);
     $contentBlockIds = $copyContentBlocks->extraIdMap;
     // define old block ids
     $contentBlockOldIds = array_keys($contentBlockIds);
     // 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::getContainer()->get('database')->getColumn('SELECT id
          FROM pages AS i
          WHERE i.language = ? AND i.status = ?', array($from, 'active'));
     // loop
     foreach ($ids as $id) {
         // get data
         $sourceData = self::get($id, null, $from);
         // get and build meta
         $meta = $db->getRecord('SELECT *
              FROM meta
              WHERE id = ?', array($sourceData['meta_id']));
         // remove id
         unset($meta['id']);
         // init page
         $page = array();
         // build page
         $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 = self::insert($page);
         // init var
         $blocks = array();
         // get the blocks
         $sourceBlocks = self::getBlocks($id, null, $from);
         // loop blocks
         foreach ($sourceBlocks as $sourceBlock) {
             // build block
             $block = $sourceBlock;
             $block['revision_id'] = $revisionId;
             $block['created_on'] = BackendModel::getUTCDate();
             $block['edited_on'] = BackendModel::getUTCDate();
             if (in_array($block['extra_id'], $contentBlockOldIds)) {
                 $block['extra_id'] = $contentBlockIds[$block['extra_id']];
             }
             // add block
             $blocks[] = $block;
         }
         // insert the blocks
         self::insertBlocks($blocks);
         // init var
         $text = '';
         // build search-text
         foreach ($blocks as $block) {
             $text .= ' ' . $block['html'];
         }
         // add
         BackendSearchModel::saveIndex('Pages', (int) $page['id'], array('title' => $page['title'], 'text' => $text), $to);
         // get tags
         $tags = BackendTagsModel::getTags('pages', $id, 'string', $from);
         // save tags
         if ($tags != '') {
             $saveWorkingLanguage = BL::getWorkingLanguage();
             // If we don't set the working language to the target language,
             // BackendTagsModel::getURL() will use the current working
             // language, possibly causing unnecessary '-2' suffixes in
             // tags.url
             BL::setWorkingLanguage($to);
             BackendTagsModel::saveTags($page['id'], $tags, 'pages', $to);
             BL::setWorkingLanguage($saveWorkingLanguage);
         }
     }
     // build cache
     self::buildCache($to);
 }
Ejemplo n.º 10
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']);
         }
     }
 }
Ejemplo n.º 11
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']);
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         $fields['subject']->isFilled(BL::err('FieldIsRequired'));
         $fields['text']->isFilled(BL::err('FieldIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             $item['meta_id'] = $this->meta->save();
             $item['subject'] = $fields['subject']->getValue();
             $item['text'] = $fields['text']->getValue();
             $item['hidden'] = $fields['hidden']->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['template_id'] = $fields['template_id']->getValue();
             $item['show_on_website'] = $fields['show_on_website']->getValue();
             BackendMailengineModel::update($this->id, $item);
             $item['id'] = $this->id;
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['subject'], 'text' => $item['text']));
             BackendModel::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }
Ejemplo n.º 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'));
         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']);
             }
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * Save the tags
  *
  * @param int    $otherId  The id of the item to tag.
  * @param mixed  $tags     The tags for the item.
  * @param string $module   The module wherein the item is located.
  * @param string $language The language wherein the tags will be inserted,
  *                         if not provided the workinglanguage will be used.
  */
 public static function saveTags($otherId, $tags, $module, $language = null)
 {
     $otherId = (int) $otherId;
     $module = (string) $module;
     $language = $language != null ? (string) $language : BL::getWorkingLanguage();
     // redefine the tags as an array
     if (!is_array($tags)) {
         $tags = (array) explode(',', (string) $tags);
     }
     // make sure the list of tags contains only unique and non-empty elements
     $tags = array_filter(array_unique($tags));
     // get db
     $db = BackendModel::getContainer()->get('database');
     // get current tags for item
     $currentTags = (array) $db->getPairs('SELECT i.tag, i.id
          FROM tags AS i
          INNER JOIN modules_tags AS mt ON i.id = mt.tag_id
          WHERE mt.module = ? AND mt.other_id = ? AND i.language = ?', array($module, $otherId, $language));
     // remove old links
     if (!empty($currentTags)) {
         $db->delete('modules_tags', 'tag_id IN (' . implode(', ', array_values($currentTags)) . ') AND other_id = ? AND module = ?', array($otherId, $module));
     }
     if (!empty($tags)) {
         // loop tags
         foreach ($tags as $key => $tag) {
             // cleanup
             $tag = strtolower(trim($tag));
             // unset if the tag is empty
             if ($tag == '') {
                 unset($tags[$key]);
             } else {
                 $tags[$key] = $tag;
             }
         }
         // don't do a regular implode, mysql injection might be possible
         $placeholders = array_fill(0, count($tags), '?');
         // get tag ids
         $tagsAndIds = (array) $db->getPairs('SELECT i.tag, i.id
              FROM tags AS i
              WHERE i.tag IN (' . implode(',', $placeholders) . ') AND i.language = ?', array_merge($tags, array($language)));
         // loop again and create tags that don't already exist
         foreach ($tags as $tag) {
             // doesn' exist yet
             if (!isset($tagsAndIds[$tag])) {
                 // insert tag
                 $tagsAndIds[$tag] = self::insert($tag, $language);
             }
         }
         // init items to insert
         $rowsToInsert = array();
         // loop again
         foreach ($tags as $tag) {
             // get tagId
             $tagId = (int) $tagsAndIds[$tag];
             // not linked before so increment the counter
             if (!isset($currentTags[$tag])) {
                 $db->execute('UPDATE tags SET number = number + 1 WHERE id = ?', $tagId);
             }
             // add to insert array
             $rowsToInsert[] = array('module' => $module, 'tag_id' => $tagId, 'other_id' => $otherId);
         }
         // insert the rows at once if there are items to insert
         if (!empty($rowsToInsert)) {
             $db->insert('modules_tags', $rowsToInsert);
         }
     }
     // add to search index
     BackendSearchModel::saveIndex($module, $otherId, array('tags' => implode(' ', (array) $tags)), $language);
     // decrement number
     foreach ($currentTags as $tag => $tagId) {
         // if the tag can't be found in the new tags we lower the number of tags by one
         if (array_search($tag, $tags) === false) {
             $db->execute('UPDATE tags SET number = number - 1 WHERE id = ?', $tagId);
         }
     }
     // remove all tags that don't have anything linked
     $db->delete('tags', 'number = ?', 0);
 }
Ejemplo n.º 15
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['begin_date_date']->isFilled(BL::err('FieldIsRequired'));
         $fields['begin_date_time']->isFilled(BL::err('FieldIsRequired'));
         $fields['begin_date_date']->isValid(BL::err('DateIsInvalid'));
         $fields['begin_date_time']->isValid(BL::err('TimeIsInvalid'));
         $fields['end_date_date']->isFilled(BL::err('FieldIsRequired'));
         $fields['end_date_time']->isFilled(BL::err('FieldIsRequired'));
         $fields['end_date_date']->isValid(BL::err('DateIsInvalid'));
         $fields['end_date_time']->isValid(BL::err('TimeIsInvalid'));
         $fields['category_id']->isFilled(BL::err('FieldIsRequired'));
         if ($fields['price']->isFilled()) {
             $fields['price']->isPrice(BL::err('InvalidValue'));
         }
         // validate meta
         $this->meta->validate();
         $this->media->validate();
         if ($this->frm->isCorrect()) {
             $item['id'] = $this->id;
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $fields['title']->getValue();
             $item['text'] = $fields['text']->getValue();
             $item['introduction'] = $fields['introduction']->getValue();
             $item['begin_date'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('begin_date_date'), $this->frm->getField('begin_date_time')));
             $item['end_date'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('end_date_date'), $this->frm->getField('end_date_time')));
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['price'] = $fields['price']->getValue();
             $item['whole_day'] = $fields['whole_day']->getChecked() ? 'Y' : 'N';
             $item['recurring'] = $fields['recurring']->getChecked() ? 'Y' : 'N';
             $item['allow_subscriptions'] = $fields['subscriptions']->getValue();
             $item['google_maps'] = $fields['google_maps']->getChecked() ? 'Y' : 'N';
             $item['location_name'] = $fields['name']->getValue();
             $item['street'] = $fields['street']->getValue();
             $item['number'] = $fields['number']->getValue();
             $item['zip'] = $fields['zip']->getValue();
             $item['city'] = $fields['city']->getValue();
             $item['country'] = $fields['country']->getValue();
             $item['meta_id'] = $this->meta->save();
             // geocode address
             $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['street'] . ' ' . $item['number'] . ', ' . $item['zip'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false';
             $geocode = json_decode(\SpoonHTTP::getContent($url));
             $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
             $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
             // update item
             BackendAgendaModel::update($item);
             $item['id'] = $this->id;
             // recurring item
             if ($item['recurring'] == 'Y') {
                 $recurringItem['id'] = $this->recurringOptions['id'];
                 $recurringItem['agenda_id'] = $item['id'];
                 $recurringItem['type'] = $fields['type']->getValue();
                 $recurringItem['interval'] = $fields['interval']->getValue();
                 $recurringItem['ends_on'] = $fields['ends_on']->getValue();
                 // if recurring type is weekly, get days checked
                 if ($recurringItem['type'] == 1) {
                     $days = $fields['days']->getChecked();
                     $recurringItem['days'] = implode(",", $days);
                 }
                 // if item ends on x amount of times
                 if ($recurringItem['ends_on'] == 1) {
                     $recurringItem['frequency'] = $fields['frequency']->getValue();
                 } else {
                     if ($recurringItem['ends_on'] == 2) {
                         // item ends on specific date
                         // check date/time fields
                         if ($fields['recurr_end_date_date']->isFilled() || $fields['recurr_end_date_time']->isFilled()) {
                             $recurringItem['end_date'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('recurr_end_date_date'), $this->frm->getField('recurr_end_date_time')));
                         }
                     }
                 }
                 // update if options exist
                 if (BackendAgendaModel::existsRecurringOptions($recurringItem['id'], $recurringItem['agenda_id'])) {
                     BackendAgendaModel::updateRecurringOptions($recurringItem);
                 } else {
                     // insert new options
                     BackendAgendaModel::insertRecurringOptions($recurringItem);
                 }
             }
             // add search index
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'Text' => $item['text']));
             BackendModel::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }
Ejemplo n.º 16
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']);
             }
         }
     }
 }
Ejemplo n.º 17
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         // 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'));
         }
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             $item['meta_id'] = $this->meta->save();
             $item['company'] = $fields['company']->getValue();
             $item['name'] = $fields['name']->getValue();
             $item['firstname'] = $fields['firstname']->getValue();
             $item['email'] = $fields['email']->getValue();
             $item['address'] = $fields['address']->getValue();
             $item['zipcode'] = $fields['zipcode']->getValue();
             $item['city'] = $fields['city']->getValue();
             $item['country'] = $fields['country']->getValue();
             $item['phone'] = $fields['phone']->getValue();
             $item['fax'] = $fields['fax']->getValue();
             $item['website'] = str_replace("http://", "", $fields['website']->getValue());
             $item['text'] = $fields['text']->getValue();
             $item['zipcodes'] = $fields['zipcodes']->getValue();
             $item['remark'] = $fields['remark']->getValue();
             //$item['assort'] = $fields['assort']->getValue();
             //$item['open'] = $fields['open']->getValue();
             //$item['closed'] = $fields['closed']->getValue();
             //$item['visit'] = $fields['visit']->getValue();
             //$item['size'] = $fields['size']->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['hidden'] = $fields['hidden']->getValue();
             if ($item['country'] == '') {
                 $item['country'] = 'BE';
             }
             //--Create url
             $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false';
             //--Get lat
             $geocode = json_decode(\SpoonHTTP::getContent($url));
             //--Sleep between the requests
             sleep(0.05);
             //--Check result
             $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
             $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/Addresses/Images';
             // create folders if needed
             if (!\SpoonDirectory::exists($imagePath . '/Source')) {
                 \SpoonDirectory::create($imagePath . '/Source');
             }
             if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                 \SpoonDirectory::create($imagePath . '/128x128');
             }
             if (!\SpoonDirectory::exists($imagePath . '/400x300')) {
                 \SpoonDirectory::create($imagePath . '/400x300');
             }
             if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                 \SpoonDirectory::create($imagePath . '/800x');
             }
             // image provided?
             if ($this->frm->getField('image')->isFilled()) {
                 // build the image name
                 $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                 // upload the image & generate thumbnails
                 $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
             }
             $item['id'] = BackendAddressesModel::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['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['opening_hours'] = $this->frm->getField('opening_hours_' . $language)->getValue();
                 BackendAddressesModel::insertLanguage($itemLanguage);
             }
             if (isset($fields["groups"])) {
                 //--Get all the groups
                 $groups = $fields["groups"]->getValue();
                 foreach ($groups as $value) {
                     $groupAddress = array();
                     $groupAddress["address_id"] = $item['id'];
                     $groupAddress["group_id"] = $value;
                     //--Add user to the group
                     BackendAddressesModel::insertAddressToGroup($groupAddress);
                 }
             }
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['name'], 'text' => $item['name']));
             BackendModel::triggerEvent($this->getModule(), 'after_add', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']);
         }
     }
 }
Ejemplo n.º 18
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']);
         }
     }
 }
Ejemplo n.º 19
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);
         }
     }
 }
Ejemplo n.º 20
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']);
         }
     }
 }
Ejemplo n.º 21
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         //			$fields['name']->isFilled(BL::err('FieldIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             $item['meta_id'] = $this->meta->save();
             $item['company'] = $fields['company']->getValue();
             $item['name'] = $fields['name']->getValue();
             $item['firstname'] = $fields['firstname']->getValue();
             $item['email'] = $fields['email']->getValue();
             $item['address'] = $fields['address']->getValue();
             $item['zipcode'] = $fields['zipcode']->getValue();
             $item['city'] = $fields['city']->getValue();
             $item['country'] = $fields['country']->getValue();
             $item['phone'] = $fields['phone']->getValue();
             $item['fax'] = $fields['fax']->getValue();
             $item['website'] = str_replace("http://", "", $fields['website']->getValue());
             $item['zipcodes'] = $fields['zipcodes']->getValue();
             $item['remark'] = $fields['remark']->getValue();
             //$item['text'] = $fields['text']->getValue();
             //$item['assort'] = $fields['assort']->getValue();
             //$item['open'] = $fields['open']->getValue();
             //$item['closed'] = $fields['closed']->getValue();
             //$item['visit'] = $fields['visit']->getValue();
             //$item['size'] = $fields['size']->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['hidden'] = $fields['hidden']->getValue();
             if ($item['country'] == '') {
                 $item['country'] = 'BE';
             }
             //--Create url
             $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false';
             //--Get lat
             $geocode = json_decode(\SpoonHTTP::getContent($url));
             //--Sleep between the requests
             sleep(0.05);
             //--Check result
             $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
             $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
             $item['image'] = $this->record['image'];
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/Addresses/Images';
             // create folders if needed
             if (!\SpoonDirectory::exists($imagePath . '/Source')) {
                 \SpoonDirectory::create($imagePath . '/Source');
             }
             if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                 \SpoonDirectory::create($imagePath . '/128x128');
             }
             if (!\SpoonDirectory::exists($imagePath . '/400x300')) {
                 \SpoonDirectory::create($imagePath . '/400x300');
             }
             if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                 \SpoonDirectory::create($imagePath . '/800x');
             }
             // if the image should be deleted
             if ($this->frm->getField('delete_image')->isChecked()) {
                 // delete the image
                 \SpoonFile::delete($imagePath . '/Source/' . $item['image']);
                 // reset the name
                 $item['image'] = null;
             }
             // new image given?
             if ($this->frm->getField('image')->isFilled()) {
                 // delete the old image
                 \SpoonFile::delete($imagePath . '/Source/' . $this->record['image']);
                 // build the image name
                 $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                 // upload the image & generate thumbnails
                 $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
             } elseif ($item['image'] != null) {
                 // get the old file extension
                 $imageExtension = \SpoonFile::getExtension($imagePath . '/Source/' . $item['image']);
                 // get the new image name
                 $newName = $this->meta->getURL() . '.' . $imageExtension;
                 // only change the name if there is a difference
                 if ($newName != $item['image']) {
                     // loop folders
                     foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) {
                         // move the old file to the new name
                         \SpoonFile::move($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $newName);
                     }
                     // assign the new name to the database
                     $item['image'] = $newName;
                 }
             }
             BackendAddressesModel::update($this->id, $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['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['opening_hours'] = $this->frm->getField('opening_hours_' . $language)->getValue();
                 BackendAddressesModel::updateLanguage($itemLanguage);
             }
             if (isset($fields["groups"])) {
                 //--Get all the groups
                 $groups = $fields["groups"]->getValue();
                 BackendAddressesModel::deleteGroupsFromAddress($item['id']);
                 foreach ($groups as $value) {
                     $groupAddress = array();
                     $groupAddress["address_id"] = $item['id'];
                     $groupAddress["group_id"] = $value;
                     //--Add user to the group
                     BackendAddressesModel::insertAddressToGroup($groupAddress);
                 }
             }
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['name'], 'text' => $item['name']));
             BackendModel::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }