/** * 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')); // validate meta $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { // build item $item['title'] = $this->frm->getField('title')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['meta_id'] = $this->meta->save(); $item['sequence'] = BackendSlideshowModel::getMaximumCategorySequence() + 1; // insert the item $item['id'] = BackendSlideshowModel::insertCategory($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_category', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Categories') . '&report=added-category&var=' . urlencode($item['title']) . '&highlight=' . $item['id']); } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); $fields['title']->isFilled(BL::err('FieldIsRequired')); if ($this->frm->isCorrect()) { $item['title'] = $fields['title']->getValue(); $item['id'] = BackendMailengineModel::insertGroup($item); //--Check if there are users if (isset($fields["users"])) { //--Get all the users $users = $fields["users"]->getValue(); foreach ($users as $key => $value) { $userGroup = array(); $userGroup["group_id"] = $item['id']; $userGroup["user_id"] = $value; //--Add user to the group BackendMailengineModel::insertUserToGroup($userGroup); } } BackendModel::triggerEvent($this->getModule(), 'after_add_group', $item); $this->redirect(BackendModel::createURLForAction('groups') . '&report=added&highlight=row-' . $item['id']); } } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $id = \SpoonFilter::getPostValue('id', null, '', 'int'); $name = trim(\SpoonFilter::getPostValue('value', null, '', 'string')); // validate if ($name == '') { $this->output(self::BAD_REQUEST, null, 'no name provided'); } else { // get existing id $existingId = BackendMailmotorModel::getCampaignId($name); // validate if ($existingId !== 0 && $id !== $existingId) { $this->output(self::ERROR, array('id' => $existingId, 'error' => true), BL::err('CampaignExists', $this->getModule())); } else { // build array $item = array(); $item['id'] = $id; $item['name'] = $name; $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // get page $rows = BackendMailmotorModel::updateCampaign($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'edited_campaign', array('item' => $item)); // output if ($rows !== 0) { $this->output(self::OK, array('id' => $id), BL::msg('CampaignEdited', $this->getModule())); } else { $this->output(self::ERROR, null, BL::err('CampaignNotEdited', $this->getModule())); } } } }
/** * 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(); // shorten fields $txtName = $this->frm->getField('name'); $rbtDefaultForLanguage = $this->frm->getField('default'); // validate fields if ($txtName->isFilled(BL::err('NameIsRequired'))) { // check if the group exists by name if (BackendMailmotorModel::existsGroupByName($txtName->getValue())) { $txtName->addError(BL::err('GroupAlreadyExists')); } } // no errors? if ($this->frm->isCorrect()) { // build item $item['name'] = $txtName->getValue(); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $item['language'] = $rbtDefaultForLanguage->getValue() === '0' ? null : $rbtDefaultForLanguage->getValue(); $item['is_default'] = $rbtDefaultForLanguage->getChecked() ? 'Y' : 'N'; // insert the item $item['id'] = BackendMailmotorCMHelper::insertGroup($item); // check if all default groups were set BackendMailmotorModel::checkDefaultGroups(); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_group', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Groups') . '&report=added&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']); } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); $fields['title']->isFilled(Language::err('TitleIsRequired')); $fields['description']->isFilled(Language::err('FieldIsRequired')); $fields['author_name']->isFilled(Language::err('FieldIsRequired')); $fields['author_url']->isFilled(Language::err('FieldIsRequired')); $fields['author_email']->isFilled(Language::err('FieldIsRequired')); // cleanup the modulename $title = preg_replace('/[^A-Za-z ]/', '', $fields['title']->getValue()); // check if there is already a module with this name if (BackendExtensionsModel::existsModule($title)) { $fields['title']->addError(Language::err('DuplicateModuleName')); } if ($this->frm->isCorrect()) { $this->record['title'] = $title; $this->record['description'] = trim($fields['description']->getValue()); $this->record['author_name'] = $fields['author_name']->getValue(); $this->record['author_url'] = $fields['author_url']->getValue(); $this->record['author_email'] = $fields['author_email']->getValue(); $this->record['camel_case_name'] = BackendModuleMakerHelper::buildCamelCasedName($title); $this->record['underscored_name'] = BackendModuleMakerHelper::buildUnderscoredName($title); \SpoonSession::set('module', $this->record); $this->redirect(Model::createURLForAction('AddStep2')); } } }
/** * 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=' . urlencode($item['term']) . '&highlight=row-' . $id); } } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $categoryTitle = trim(\SpoonFilter::getPostValue('value', null, '', 'string')); // validate if ($categoryTitle === '') { $this->output(self::BAD_REQUEST, null, BL::err('TitleIsRequired')); } else { // get the data // build array $item['title'] = \SpoonFilter::htmlspecialchars($categoryTitle); $item['language'] = BL::getWorkingLanguage(); $meta['keywords'] = $item['title']; $meta['keywords_overwrite'] = 'N'; $meta['description'] = $item['title']; $meta['description_overwrite'] = 'N'; $meta['title'] = $item['title']; $meta['title_overwrite'] = 'N'; $meta['url'] = BackendBlogModel::getURLForCategory(\SpoonFilter::urlise($item['title'])); // update $item['id'] = BackendBlogModel::insertCategory($item, $meta); // output $this->output(self::OK, $item, vsprintf(BL::msg('AddedCategory'), array($item['title']))); } }
/** * Parse the correct messages into the template */ protected function parse() { parent::parse(); // grab the error-type from the parameters $errorType = $this->getParameter('type'); // set correct headers switch ($errorType) { case 'module-not-allowed': case 'action-not-allowed': header('HTTP/1.1 403 Forbidden'); break; case 'not-found': header('HTTP/1.1 404 Not Found'); break; } // querystring provided? if ($this->getParameter('querystring') !== null) { // split into file and parameters $chunks = explode('?', $this->getParameter('querystring')); // get extension $extension = pathinfo($chunks[0], PATHINFO_EXTENSION); // if the file has an extension it is a non-existing-file if ($extension != '' && $extension != $chunks[0]) { // set correct headers header('HTTP/1.1 404 Not Found'); // give a nice error, so we can detect which file is missing echo 'Requested file (' . htmlspecialchars($this->getParameter('querystring')) . ') not found.'; // stop script execution exit; } } // assign the correct message into the template $this->tpl->assign('message', BL::err(\SpoonFilter::toCamelCase(htmlspecialchars($errorType), '-'))); }
private function validateForm() { if ($this->frm->isSubmitted()) { $fields = $this->frm->getFields(); $fields['title']->isFilled(BL::err('TitleIsRequired')); if ($this->frm->isCorrect()) { $item = []; $item['title'] = $fields['title']->getValue(); $item['capacity'] = $fields['capacity']->getValue(); $item['price'] = $fields['price']->getValue(); $item['count'] = $fields['count']->getValue(); $item['image'] = null; $item['hotel_id'] = $this->id; if ($fields['image']->isFilled()) { // the image path $imagePath = FRONTEND_FILES_PATH . '/rooms/images'; // create folders if needed $fs = new Filesystem(); $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128')); $item['image'] = $fields['image']->getFileName(false) . '.' . $fields['image']->getExtension(); $i = 2; while ($fs->exists($imagePath . '/source/' . $item['image'])) { $item['image'] = $fields['image']->getFileName(false) . '(' . $i . ')' . '.' . $fields['image']->getExtension(); $i++; } // upload the image & generate thumbnails $fields['image']->generateThumbnails($imagePath, $item['image']); } $item['id'] = BackendHotelsModel::insertRecord('hotels_rooms', $item); $this->redirect(BackendModel::createURLForAction('Rooms') . '&id=' . $this->id . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // redefine fields /** @var $fileFile \SpoonFormFile */ $fileFile = $this->frm->getField('file'); $chkOverwrite = $this->frm->getField('overwrite'); // name checks if ($fileFile->isFilled(BL::err('FieldIsRequired'))) { // only xml files allowed if ($fileFile->isAllowedExtension(array('xml'), sprintf(BL::getError('ExtensionNotAllowed'), 'xml'))) { // load xml $xml = @simplexml_load_file($fileFile->getTempFileName()); // invalid xml if ($xml === false) { $fileFile->addError(BL::getError('InvalidXML')); } } } if ($this->frm->isCorrect()) { // import $statistics = BackendLocaleModel::importXML($xml, $chkOverwrite->getValue()); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_import', array('statistics' => $statistics)); // everything is imported, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Index') . '&report=imported&var=' . ($statistics['imported'] . '/' . $statistics['total']) . $this->filterQuery); } } }
private function validateForm() { if ($this->form->isSubmitted()) { $fields = $this->form->getFields(); if (!$fields['start_date']->isFilled(Language::err('FieldIsRequired')) || !$fields['end_date']->isFilled(Language::err('FieldIsRequired'))) { return; } if (!$fields['start_date']->isValid(Language::err('DateIsInvalid')) || !$fields['end_date']->isValid(Language::err('DateIsInvalid'))) { return; } $newStartDate = Model::getUTCTimestamp($fields['start_date']); $newEndDate = Model::getUTCTimestamp($fields['end_date']); // startdate cannot be before 2005 (earliest valid google startdate) if ($newStartDate < mktime(0, 0, 0, 1, 1, 2005)) { $fields['start_date']->setError(BL::err('DateRangeIsInvalid')); } // enddate cannot be in the future if ($newEndDate > time()) { $fields['start_date']->setError(BL::err('DateRangeIsInvalid')); } // enddate cannot be before the startdate if ($newStartDate > $newEndDate) { $fields['start_date']->setError(BL::err('DateRangeIsInvalid')); } if ($this->form->isCorrect()) { $this->startDate = $newStartDate; $this->endDate = $newEndDate; } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); $fields['name']->isFilled(BL::err('FieldIsRequired')); $fields['email']->isFilled(BL::err('FieldIsRequired')); $fields['email']->isEmail(BL::err('EmailIsInvalid')); if ($this->frm->isCorrect()) { $item['name'] = $fields['name']->getValue(); $item['email'] = $fields['email']->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['id'] = BackendMailengineModel::insertUser($item); //--Check if there are groups if (isset($fields['groups'])) { //--Get all the groups $groups = $fields["groups"]->getValue(); foreach ($groups as $key => $value) { $groupUser = array(); $groupUser["user_id"] = $item['id']; $groupUser["group_id"] = $value; //--Add user to the group BackendMailengineModel::insertUserToGroup($groupUser); } } BackendModel::triggerEvent($this->getModule(), 'after_add_user', $item); $this->redirect(BackendModel::createURLForAction('users') . '&report=added&highlight=row-' . $item['id']); } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); $fields = $this->frm->getFields(); $fields['email']->isFilled(BL::err('FieldIsRequired')); if ($this->frm->isCorrect()) { //--Get the mail $mailing = BackendMailengineModel::get($this->id); //--Get the template $template = BackendMailengineModel::getTemplate($mailing['template_id']); //--Create basic mail $text = BackendMailengineModel::createMail($mailing, $template); $mailing['from_email'] = $template['from_email']; $mailing['from_name'] = html_entity_decode($template['from_name']); $mailing['reply_email'] = $template['reply_email']; $mailing['reply_name'] = html_entity_decode($template['reply_name']); $emails = explode(',', $fields['email']->getValue()); if (!empty($emails)) { foreach ($emails as $email) { $email = trim($email); if (\SpoonFilter::isEmail($email)) { //--Send test mailing BackendMailengineModel::sendMail(html_entity_decode($mailing['subject']), $text, $email, 'Test Recepient', $mailing); } } } //--Redirect \SpoonHTTP::redirect(BackendModel::createURLForAction('index', $this->module) . "&id=" . $this->id . "&report=TestEmailSend"); } } $this->frm->parse($this->tpl); }
/** * 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']))); } } } }
/** * 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(); // XML provided? if ($this->frm->getField('wordpress')->isFilled()) { $this->frm->getField('wordpress')->isAllowedExtension(array('xml'), BL::err('XMLFilesOnly')); } else { // No file $this->frm->getField('wordpress')->addError(BL::err('FieldIsRequired')); } // No errors? if ($this->frm->isCorrect()) { // Move the file $this->frm->getField('wordpress')->moveFile(FRONTEND_FILES_PATH . '/wordpress.xml'); // Process the XML $this->processXML(); // Remove the file $this->fs->remove(FRONTEND_FILES_PATH . '/wordpress.xml'); // Everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=imported'); } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); $frmFields = $this->frm->getFields(); // validate form if ($frmFields['twitter']->isChecked()) { // we need fields when search is ticked $frmFields['twitter_name']->isFilled(Language::err('FieldIsRequired')); } if ($this->frm->isCorrect()) { // if this field is checked, let's add a boolean searchable true to the chosen fields if ($frmFields['twitter']->isChecked()) { $this->record['twitter'] = $frmFields['twitter_name']->getValue(); } else { if (array_key_exists('twitter', $this->record)) { unset($this->record['twitter']); } } // save the object in our session \SpoonSession::set('module', $this->record); $this->redirect(Model::createURLForAction('Generate')); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { //--Clean form $this->frm->cleanupFields(); //--Get fields $fields = $this->frm->getFields(); //--Field required $fields['csv']->isFilled(BL::err('CSVIsRequired')); //--Check if form is correct if ($fields['csv']->isFilled()) { // convert the CSV file to an array $csv = BackendCSV::fileToArray($fields['csv']->getTempFileName(), array("email", "name"), null, ';'); //--check if the csv is correct if ($csv === false || empty($csv) || !isset($csv[0])) { $fields['csv']->addError(BL::err('InvalidCSV')); } //--Get all the groups $groups = $fields["groups"]->getValue(); $language = $fields["languages"]->getValue(); //--Process CSV $return = $this->processCsv($csv, $groups, $language); if (is_array($return)) { $this->tpl->assign('hideForm', true); $this->tpl->assign('return', $return); } } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate fields $this->frm->getField('author')->isFilled(BL::err('AuthorIsRequired')); $this->frm->getField('email')->isEmail(BL::err('EmailIsInvalid')); $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired')); if ($this->frm->getField('website')->isFilled()) { $this->frm->getField('website')->isURL(BL::err('InvalidURL')); } // no errors? if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['status'] = $this->record['status']; $item['author'] = $this->frm->getField('author')->getValue(); $item['email'] = $this->frm->getField('email')->getValue(); $item['website'] = $this->frm->getField('website')->isFilled() ? $this->frm->getField('website')->getValue() : null; $item['text'] = $this->frm->getField('text')->getValue(); // insert the item BackendBlogModel::updateComment($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_comment', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Comments') . '&report=edited-comment&id=' . $item['id'] . '&highlight=row-' . $item['id'] . '#tab' . \SpoonFilter::toCamelCase($item['status'])); } } }
/** * 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']); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // get fields $ddmGroup = $this->frm->getField('group'); $fileFile = $this->frm->getField('file'); $csv = array(); // validate input $ddmGroup->isFilled(BL::getError('FieldIsRequired')); if ($fileFile->isFilled(BL::err('FieldIsRequired'))) { if ($fileFile->isAllowedExtension(array('csv'), sprintf(BL::getError('ExtensionNotAllowed'), 'csv'))) { $csv = Csv::fileToArray($fileFile->getTempFileName()); if ($csv === false) { $fileFile->addError(BL::getError('InvalidCSV')); } } } if ($this->frm->isCorrect()) { // import the profiles $overwrite = $this->frm->getField('overwrite_existing')->isChecked(); $statistics = BackendProfilesModel::importCsv($csv, $ddmGroup->getValue(), $overwrite); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_import', array('statistics' => $statistics)); // build redirect url with the right message $redirectUrl = BackendModel::createURLForAction('index') . '&report='; $redirectUrl .= $overwrite ? 'profiles-imported-and-updated' : 'profiles-imported'; $redirectUrl .= '&var[]=' . $statistics['count']['inserted']; $redirectUrl .= '&var[]=' . $statistics['count']['exists']; // everything is saved, so redirect to the overview $this->redirect($redirectUrl); } } }
/** * Validate the form */ private function validateForm() { 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 item $item['title'] = $this->frm->getField('title')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['publish_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $item['hidden'] = $this->frm->getField('hidden')->getValue(); // get the highest sequence available $item['sequence'] = BackendGalleryModel::getMaximumCategorySequence() + 1; // insert the item $item['id'] = BackendGalleryModel::insertCategory($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_category', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('categories') . '&report=added-category&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); $fields = $this->frm->getFields(); // validate fields $fields['title']->isFilled(BL::err('TitleIsRequired')); if ($this->frm->isCorrect()) { // build item $item['id'] = BackendContentBlocksModel::getMaximumId() + 1; $item['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['template'] = count($this->templates) > 1 ? $fields['template']->getValue() : $this->templates[0]; $item['language'] = BL::getWorkingLanguage(); $item['title'] = $fields['title']->getValue(); $item['text'] = $fields['text']->getValue(); $item['hidden'] = $fields['hidden']->getValue() ? 'N' : 'Y'; $item['status'] = 'active'; $item['created_on'] = BackendModel::getUTCDate(); $item['edited_on'] = BackendModel::getUTCDate(); // insert the item $item['revision_id'] = BackendContentBlocksModel::insert($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']); } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); $fields['title']->isFilled(BL::err('FieldIsRequired')); $this->meta->validate(); if ($this->frm->isCorrect()) { $item['meta_id'] = $this->meta->save(); $item['title'] = $fields['title']->getValue(); $item['parent_id'] = $fields['group']->getValue() != 0 ? $fields['group']->getValue() : null; $item['id'] = BackendAddressesModel::insertGroup($item); if (isset($fields["addresses"])) { //--Get all the users $addresses = $fields["addresses"]->getValue(); foreach ($addresses as $value) { $userGroup = array(); $userGroup["group_id"] = $item['id']; $userGroup["address_id"] = $value; //--Add user to the group BackendAddressesModel::insertAddressToGroup($userGroup); } } BackendModel::triggerEvent($this->getModule(), 'after_add_group', $item); $this->redirect(BackendModel::createURLForAction('groups') . '&report=added&highlight=row-' . $item['id']); } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); $fields['username']->isFilled(Language::err('FieldIsRequired')); if ($this->frm->isCorrect()) { $item['id'] = $this->id; $item['username'] = $fields['username']->getValue(); // lookup user id $userObj = Helper::searchUser($item['username']); if (isset($userObj->data)) { $userId = $userObj->data[0]->id; $item['user_id'] = $userId; } else { $this->redirect(Model::createURLForAction('Index') . '&error=api_error'); } BackendInstagramModel::update($item); $item['id'] = $this->id; Model::triggerEvent($this->getModule(), 'after_edit', $item); $this->redirect(Model::createURLForAction('Index') . '&report=edited&highlight=row-' . $item['id']); } } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $url = \SpoonFilter::getPostValue('url', null, ''); $username = \SpoonFilter::getPostValue('username', null, ''); $password = \SpoonFilter::getPostValue('password', null, ''); // filter out the 'http://' from the URL if (strpos($url, 'http://') !== false) { $url = str_replace('http://', '', $url); } if (strpos($url, 'https://') !== false) { $url = str_replace('https://', '', $url); } // init validation $errors = array(); // validate input if (empty($url)) { $errors['url'] = BL::err('NoCMAccountCredentials'); } if (empty($username)) { $errors['username'] = BL::err('NoCMAccountCredentials'); } if (empty($password)) { $errors['password'] = BL::err('NoCMAccountCredentials'); } // got errors if (!empty($errors)) { $this->output(self::OK, array('errors' => $errors), 'form contains errors'); } else { try { // check if the CampaignMonitor class exists if (!is_file(PATH_LIBRARY . '/external/campaignmonitor.php')) { throw new \Exception(BL::err('ClassDoesNotExist')); } // require CampaignMonitor class require_once PATH_LIBRARY . '/external/campaignmonitor.php'; // init CampaignMonitor object new \CampaignMonitor($url, $username, $password, 10); // save the new data $this->get('fork.settings')->set($this->getModule(), 'cm_url', $url); $this->get('fork.settings')->set($this->getModule(), 'cm_username', $username); $this->get('fork.settings')->set($this->getModule(), 'cm_password', $password); // account was linked $this->get('fork.settings')->set($this->getModule(), 'cm_account', true); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_account_linked'); // CM was successfully initialized $this->output(self::OK, array('message' => 'account-linked'), BL::msg('AccountLinked', $this->getModule())); } catch (\Exception $e) { // timeout occurred if ($e->getMessage() == 'Error Fetching http headers') { $this->output(self::BAD_REQUEST, null, BL::err('CmTimeout', $this->getModule())); } // other error $this->output(self::ERROR, array('field' => 'url'), sprintf(BL::err('CampaignMonitorError', $this->getModule()), $e->getMessage())); } } }
/** * This function will return the errors. It is extended so we can do image checks automatically. * * @return string */ public function getErrors() { // do an image validation if ($this->isFilled()) { $this->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), Language::err('JPGGIFAndPNGOnly')); $this->isAllowedMimeType(array('image/jpeg', 'image/gif', 'image/png'), Language::err('JPGGIFAndPNGOnly')); } return $this->errors; }
/** * Execute the action */ public function execute() { parent::execute(); $isGod = BackendAuthentication::getUser()->isGod(); // get possible languages if ($isGod) { $possibleLanguages = array_unique(array_merge(BL::getWorkingLanguages(), BL::getInterfaceLanguages())); } else { $possibleLanguages = BL::getWorkingLanguages(); } // get parameters $language = \SpoonFilter::getPostValue('language', array_keys($possibleLanguages), null, 'string'); $module = \SpoonFilter::getPostValue('module', BackendModel::getModules(), null, 'string'); $name = \SpoonFilter::getPostValue('name', null, null, 'string'); $type = \SpoonFilter::getPostValue('type', BackendModel::getContainer()->get('database')->getEnumValues('locale', 'type'), null, 'string'); $application = \SpoonFilter::getPostValue('application', array('Backend', 'Frontend'), null, 'string'); $value = \SpoonFilter::getPostValue('value', null, null, 'string'); // validate values if (trim($value) == '' || $language == '' || $module == '' || $type == '' || $application == '' || $application == 'Frontend' && $module != 'Core') { $error = BL::err('InvalidValue'); } // in case this is a 'act' type, there are special rules concerning possible values if ($type == 'act' && !isset($error)) { if (urlencode($value) != CommonUri::getUrl($value)) { $error = BL::err('InvalidActionValue', $this->getModule()); } } // no error? if (!isset($error)) { // build item $item['language'] = $language; $item['module'] = $module; $item['name'] = $name; $item['type'] = $type; $item['application'] = $application; $item['value'] = $value; $item['edited_on'] = BackendModel::getUTCDate(); $item['user_id'] = BackendAuthentication::getUser()->getUserId(); // does the translation exist? if (BackendLocaleModel::existsByName($name, $type, $module, $language, $application)) { // add the id to the item $item['id'] = (int) BackendLocaleModel::getByName($name, $type, $module, $language, $application); // update in db BackendLocaleModel::update($item); } else { // insert in db BackendLocaleModel::insert($item); } // output OK $this->output(self::OK); } else { $this->output(self::ERROR, null, $error); } }
/** * Validate the form add image * * @return void */ private function validateForm() { //--Check if the add-image form is submitted if ($this->frm->isSubmitted()) { //--Clean up fields in the form $this->frm->cleanupFields(); //--Get image field $filImage = $this->frm->getField('images'); //--Check if the field is filled in if ($filImage->isFilled()) { //--Image extension and mime type $filImage->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly')); $filImage->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly')); //--Check if there are no errors. $strError = $filImage->getErrors(); if ($strError === null) { //--Get the filename $strFilename = BackendGalleriaModel::checkFilename(substr($filImage->getFilename(), 0, 0 - (strlen($filImage->getExtension()) + 1)), $filImage->getExtension()); //--Fill in the item $item = array(); $item["album_id"] = (int) $this->id; $item["user_id"] = BackendAuthentication::getUser()->getUserId(); $item["language"] = BL::getWorkingLanguage(); $item["filename"] = $strFilename; $item["description"] = ""; $item["publish_on"] = BackendModel::getUTCDate(); $item["hidden"] = "N"; $item["sequence"] = BackendGalleriaModel::getMaximumImageSequence($this->id) + 1; //--the image path $imagePath = FRONTEND_FILES_PATH . '/Galleria/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 . '/800x')) { \SpoonDirectory::create($imagePath . '/800x'); } //--image provided? if ($filImage->isFilled()) { //--upload the image & generate thumbnails $filImage->generateThumbnails($imagePath, $item["filename"]); } //--Add item to the database BackendGalleriaModel::insert($item); } } } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $id = \SpoonFilter::getPostValue('id', null, '', 'int'); // validate if ($id == '' || !BackendMailmotorModel::existsMailing($id)) { $this->output(self::BAD_REQUEST, null, 'No mailing found.'); } else { // get mailing record $mailing = BackendMailmotorModel::getMailing($id); /* mailing was already sent We use a custom status code 900 because we want to do more with JS than triggering an error */ if ($mailing['status'] == 'sent') { $this->output(500, null, BL::err('MailingAlreadySent', $this->getModule())); } else { // make a regular date out of the send_on timestamp $mailing['delivery_date'] = date('Y-m-d H:i:s', $mailing['send_on']); // send the mailing try { // only update the mailing if it was queued if ($mailing['status'] == 'queued') { BackendMailmotorCMHelper::updateMailing($mailing); } else { // send the mailing if it wasn't queued BackendMailmotorCMHelper::sendMailing($mailing); } } catch (\Exception $e) { // stop the script and show our error $this->output(500, null, $e->getMessage()); return; } // set status to 'sent' $item['id'] = $id; $item['status'] = $mailing['send_on'] > time() ? 'queued' : 'sent'; // update the mailing record BackendMailmotorModel::updateMailing($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_mailing_status_' . $item['status'], array('item' => $item)); // we made it \o/ $this->output(self::OK, array('mailing_id' => $item['id']), BL::msg('MailingSent', $this->getModule())); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); if ($this->frm->getField('image')->isFilled()) { $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()) { // build item $item['id'] = $this->id; $item['title'] = $this->frm->getField('title')->getValue(); $item['meta_id'] = $this->meta->save(true); // the image path $imagePath = FRONTEND_FILES_PATH . '/catalog/brands'; // create folders if needed $fs = new Filesystem(); if (!$fs->exists($imagePath . '/source/')) { $fs->mkdir($imagePath . '/source/'); $fs->mkdir($imagePath . '/150x150/'); } if ($this->frm->getField('delete_image')->isChecked()) { BackendModel::deleteThumbnails($imagePath, $this->record['image']); $item['image'] = null; } // image provided? if ($this->frm->getField('image')->isFilled()) { BackendModel::deleteThumbnails($imagePath, $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']); } // update the item BackendCatalogModel::updateBrand($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_brand', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('brands') . '&report=edited-brand&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']); } } }