/** * Generate an url, using the predefined callback. * * @param string $url The base-url to start from. * @param string $class The Fully Qualified Class Name or service name * @param string $method The method that needs to be called * @param array $parameters The parameters for the callback * * @throws Exception When the function does not exist * * @return string */ public function generateURL($url, $class, $method, array $parameters = []) { // check if the class is a service if (Model::getContainer()->has($class)) { $class = Model::getContainer()->get($class); } // validate (check if the function exists) if (!is_callable([$class, $method])) { throw new Exception('The callback-method doesn\'t exist.'); } // when using ->getValue() in SpoonFormText fields the function is using htmlentities(), // so we must decode it again first! $url = SpoonFilter::htmlentitiesDecode($url); $actualParameters = []; // build parameters for use in the callback $actualParameters[] = Uri::getUrl($url); // add parameters set by user if (!empty($parameters)) { foreach ($parameters as $parameter) { $actualParameters[] = $parameter; } } // get the real url return call_user_func_array([$class, $method], $actualParameters); }
/** * 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']))); } } } }
/** * Set the image for the feed. * * @param string $url URL of the image. * @param string $title Title of the image. * @param string $link Link of the image. * @param int $width Width of the image. * @param int $height Height of the image. * @param string $description Description of the image. */ public function setImage($url, $title, $link, $width = null, $height = null, $description = null) { // add UTM-parameters $link = Model::addURLParameters($link, array('utm_source' => 'feed', 'utm_medium' => 'rss', 'utm_campaign' => CommonUri::getUrl($this->getTitle()))); // call the parent parent::setImage($url, $title, $link, $width, $height, $description); }
/** * Retrieve the unique URL for an teamMember * * @param string $url * @param int $id The id of the teamMember to ignore. * @return string */ public static function getUrl($url, $id = null) { $url = CommonUri::getUrl((string) $url); $database = BackendModel::get('database'); if ($id === null) { $urlExists = (bool) $database->getVar('SELECT 1 FROM team_members AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? LIMIT 1', [Language::getWorkingLanguage(), $url]); } else { $urlExists = (bool) $database->getVar('SELECT 1 FROM team_members AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? AND i.id != ? LIMIT 1', [Language::getWorkingLanguage(), $url, $id]); } if ($urlExists) { $url = Model::addNumber($url); return self::getUrl($url, $id); } return $url; }
/** * 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); } }
/** * Set the author. * * @param string $author The author to use. */ public function setAuthor($author) { // remove special chars $author = (string) \SpoonFilter::htmlspecialcharsDecode($author); // add fake-emailaddress if (!\SpoonFilter::isEmail($author)) { $author = CommonUri::getUrl($author) . '@example.com (' . $author . ')'; } // add fake email address if (!\SpoonFilter::isEmail($author)) { $author = \SpoonFilter::urlise($author) . '@example.com (' . $author . ')'; } // set author parent::setAuthor($author); }
/** * Default constructor. * * @param string $title The title for the item. * @param string $link The link for the item. * @param string $description The content for the item. */ public function __construct($title, $link, $description) { // set UTM-campaign $this->utm['utm_campaign'] = CommonUri::getUrl($title); // convert to plain text $description = FrontendModel::convertToPlainText($description); // set title $this->setSummary($title); // set url $this->setUrl(FrontendModel::addURLParameters($link, $this->utm)); // set description $this->setDescription($this->processLinks($description)); // set identifier $this->setUniqueIdentifier(md5($link)); // build properties $properties['X-GOOGLE-CALENDAR-CONTENT-TITLE'] = $title; $properties['X-GOOGLE-CALENDAR-CONTENT-ICON'] = SITE_URL . '/favicon.ico'; $properties['X-GOOGLE-CALENDAR-CONTENT-URL'] = $this->getUrl(); // set properties $this->setXProperties($properties); }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $formId = \SpoonFilter::getPostValue('form_id', null, '', 'int'); $fieldId = \SpoonFilter::getPostValue('field_id', null, '', 'int'); $type = \SpoonFilter::getPostValue('type', array('checkbox', 'dropdown', 'datetime', 'heading', 'paragraph', 'radiobutton', 'submit', 'textarea', 'textbox'), '', 'string'); $label = trim(\SpoonFilter::getPostValue('label', null, '', 'string')); $values = trim(\SpoonFilter::getPostValue('values', null, '', 'string')); // this is somewhat a nasty hack, but it makes special chars work. $values = \SpoonFilter::htmlspecialcharsDecode($values); $defaultValues = trim(\SpoonFilter::getPostValue('default_values', null, '', 'string')); $placeholder = trim(\SpoonFilter::getPostValue('placeholder', null, '', 'string')); $required = \SpoonFilter::getPostValue('required', array('Y', 'N'), 'N', 'string'); $requiredErrorMessage = trim(\SpoonFilter::getPostValue('required_error_message', null, '', 'string')); $validation = \SpoonFilter::getPostValue('validation', array('email', 'numeric', 'time'), '', 'string'); $validationParameter = trim(\SpoonFilter::getPostValue('validation_parameter', null, '', 'string')); $errorMessage = trim(\SpoonFilter::getPostValue('error_message', null, '', 'string')); // special field for textbox: reply to $replyTo = \SpoonFilter::getPostValue('reply_to', array('Y', 'N'), 'N', 'string'); // special fields for datetime $inputType = \SpoonFilter::getPostValue('input_type', array('date', 'time'), 'date', 'string'); $valueAmount = trim(\SpoonFilter::getPostValue('value_amount', null, '', 'string')); $valueType = trim(\SpoonFilter::getPostValue('value_type', null, '', 'string')); // invalid form id if (!BackendFormBuilderModel::exists($formId)) { $this->output(self::BAD_REQUEST, null, 'form does not exist'); } else { // invalid fieldId if ($fieldId !== 0 && !BackendFormBuilderModel::existsField($fieldId, $formId)) { $this->output(self::BAD_REQUEST, null, 'field does not exist'); } else { // invalid type if ($type == '') { $this->output(self::BAD_REQUEST, null, 'invalid type provided'); } else { // extra validation is only possible for textfields & datetime fields if ($type != 'textbox' && $type != 'datetime') { $validation = ''; $validationParameter = ''; $errorMessage = ''; } // init $errors = array(); // validate textbox if ($type == 'textbox') { if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($validation != '' && $errorMessage == '') { $errors['error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($replyTo == 'Y' && $validation != 'email') { $errors['reply_to_error_message'] = BL::getError('EmailValidationIsRequired'); } } elseif ($type == 'textarea') { // validate textarea if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($validation != '' && $errorMessage == '') { $errors['error_message'] = BL::getError('ErrorMessageIsRequired'); } } elseif ($type == 'datetime') { // validate datetime if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if (in_array($valueType, array('day', 'week', 'month', 'year')) && $valueAmount == '') { $errors['default_value_error_message'] = BL::getError('ValueIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($validation != '' && $errorMessage == '') { $errors['error_message'] = BL::getError('ErrorMessageIsRequired'); } } elseif ($type == 'heading' && $values == '') { // validate heading $errors['values'] = BL::getError('ValueIsRequired'); } elseif ($type == 'paragraph' && $values == '') { // validate paragraphs $errors['values'] = BL::getError('ValueIsRequired'); } elseif ($type == 'submit' && $values == '') { // validate submitbuttons $errors['values'] = BL::getError('ValueIsRequired'); } elseif ($type == 'dropdown') { // validate dropdown $values = trim($values, ','); // validate if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($values == '') { $errors['values'] = BL::getError('ValueIsRequired'); } } elseif ($type == 'radiobutton') { // validate radiobutton if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($values == '') { $errors['values'] = BL::getError('ValueIsRequired'); } } elseif ($type == 'checkbox') { // validate checkbox if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } } // got errors if (!empty($errors)) { $this->output(self::OK, array('errors' => $errors), 'form contains errors'); } else { // htmlspecialchars except for paragraphs if ($type != 'paragraph') { if ($values != '') { $values = \SpoonFilter::htmlspecialchars($values); } if ($defaultValues != '') { $defaultValues = \SpoonFilter::htmlspecialchars($defaultValues); } } // split if ($type == 'dropdown' || $type == 'checkbox') { $values = (array) explode('|', $values); } elseif ($type == 'radiobutton') { $postedValues = (array) explode('|', $values); $values = array(); foreach ($postedValues as $postedValue) { $values[] = array('value' => CommonUri::getUrl($postedValue), 'label' => $postedValue); } } /** * Save! */ // settings $settings = array(); if ($label != '') { $settings['label'] = \SpoonFilter::htmlspecialchars($label); } if (isset($values)) { $settings['values'] = $values; } if ($defaultValues != '') { $settings['default_values'] = $defaultValues; } if ($placeholder != '') { $settings['placeholder'] = \SpoonFilter::htmlspecialchars($placeholder); } // reply-to, only for textboxes if ($type == 'textbox') { $settings['reply_to'] = $replyTo == 'Y'; } // only for datetime input if ($type == 'datetime') { $settings['input_type'] = $inputType; if ($inputType == 'date') { $settings['value_amount'] = $valueAmount; $settings['value_type'] = $valueType; } } // build array $field = array(); $field['form_id'] = $formId; $field['type'] = $type; $field['settings'] = !empty($settings) ? serialize($settings) : null; // existing field if ($fieldId !== 0) { // update field BackendFormBuilderModel::updateField($fieldId, $field); // delete all validation (added again later) BackendFormBuilderModel::deleteFieldValidation($fieldId); } else { // sequence $field['sequence'] = BackendFormBuilderModel::getMaximumSequence($formId) + 1; // insert $fieldId = BackendFormBuilderModel::insertField($field); } // required if ($required == 'Y') { // build array $validate['field_id'] = $fieldId; $validate['type'] = 'required'; $validate['error_message'] = \SpoonFilter::htmlspecialchars($requiredErrorMessage); // add validation BackendFormBuilderModel::insertFieldValidation($validate); // add to field (for parsing) $field['validations']['required'] = $validate; } // other validation if ($validation != '') { // build array $validate['field_id'] = $fieldId; $validate['type'] = $validation; $validate['error_message'] = \SpoonFilter::htmlspecialchars($errorMessage); $validate['parameter'] = $validationParameter != '' ? \SpoonFilter::htmlspecialchars($validationParameter) : null; // add validation BackendFormBuilderModel::insertFieldValidation($validate); // add to field (for parsing) $field['validations'][$type] = $validate; } // get item from database (i do this call again to keep the pof as low as possible) $field = BackendFormBuilderModel::getField($fieldId); // submit button isnt parsed but handled directly via javascript if ($type == 'submit') { $fieldHTML = ''; } else { // parse field to html $fieldHTML = FormBuilderHelper::parseField($field); } // success output $this->output(self::OK, array('field_id' => $fieldId, 'field_html' => $fieldHTML), 'field saved'); } } } } }
/** * @param string $html The html to convert links in. * @param string $subject The subject of the mail * @return string */ private function addUTM($html, $subject) { // match links $matches = array(); preg_match_all('/href="(http:\\/\\/(.*))"/iU', $html, $matches); // any links? $utm = array('utm_source' => 'mail', 'utm_medium' => 'email', 'utm_campaign' => Uri::getUrl($subject)); if (isset($matches[0]) && !empty($matches[0])) { $searchLinks = array(); $replaceLinks = array(); // loop old links foreach ($matches[1] as $i => $link) { $searchLinks[] = $matches[0][$i]; $replaceLinks[] = 'href="' . Model::addURLParameters($link, $utm) . '"'; } $html = str_replace($searchLinks, $replaceLinks, $html); } return $html; }
/** * Validates the form * It checks if there is a value when a checkbox is checked */ public function validate() { // page title overwrite is checked if ($this->frm->getField('page_title_overwrite')->isChecked()) { $this->frm->getField('page_title')->isFilled(BackendLanguage::err('FieldIsRequired')); } // meta description overwrite is checked if ($this->frm->getField('meta_description_overwrite')->isChecked()) { $this->frm->getField('meta_description')->isFilled(BackendLanguage::err('FieldIsRequired')); } // meta keywords overwrite is checked if ($this->frm->getField('meta_keywords_overwrite')->isChecked()) { $this->frm->getField('meta_keywords')->isFilled(BackendLanguage::err('FieldIsRequired')); } // URL overwrite is checked if ($this->frm->getField('url_overwrite')->isChecked()) { $this->frm->getField('url')->isFilled(BackendLanguage::err('FieldIsRequired')); $url = \SpoonFilter::htmlspecialcharsDecode($this->frm->getField('url')->getValue()); $generatedUrl = $this->generateURL($url); // check if urls are different if (CommonUri::getUrl($url) != $generatedUrl) { $this->frm->getField('url')->addError(BackendLanguage::err('URLAlreadyExists')); } } // if the form was submitted correctly the data array should be populated if ($this->frm->isCorrect()) { // get meta keywords $keywords = $this->frm->getField('meta_keywords_overwrite')->getActualValue($this->frm->getField('meta_keywords')->getValue(), $this->frm->getField($this->baseFieldName)->getValue()); // get meta description $description = $this->frm->getField('meta_description_overwrite')->getActualValue($this->frm->getField('meta_description')->getValue(), $this->frm->getField($this->baseFieldName)->getValue()); // get page title $title = $this->frm->getField('page_title_overwrite')->getActualValue($this->frm->getField('page_title')->getValue(), $this->frm->getField($this->baseFieldName)->getValue()); // get URL $url = $this->frm->getField('url_overwrite')->getActualValue(\SpoonFilter::htmlspecialcharsDecode($this->frm->getField('url')->getValue()), \SpoonFilter::htmlspecialcharsDecode($this->frm->getField($this->baseFieldName)->getValue())); // get the real URL $url = $this->generateURL($url); // get meta custom if ($this->custom && $this->frm->getField('meta_custom')->isFilled()) { $custom = $this->frm->getField('meta_custom')->getValue(); } else { $custom = null; } // set data $this->data['keywords'] = $keywords; $this->data['keywords_overwrite'] = $this->frm->getField('meta_keywords_overwrite')->getActualValue(); $this->data['description'] = $description; $this->data['description_overwrite'] = $this->frm->getField('meta_description_overwrite')->getActualValue(); $this->data['title'] = $title; $this->data['title_overwrite'] = $this->frm->getField('page_title_overwrite')->getActualValue(); $this->data['url'] = $url; $this->data['url_overwrite'] = $this->frm->getField('url_overwrite')->getActualValue(); $this->data['custom'] = $custom; if ($this->frm->getField('seo_index')->getValue() == 'none') { unset($this->data['data']['seo_index']); } else { $this->data['data']['seo_index'] = $this->frm->getField('seo_index')->getValue(); } if ($this->frm->getField('seo_follow')->getValue() == 'none') { unset($this->data['data']['seo_follow']); } else { $this->data['data']['seo_follow'] = $this->frm->getField('seo_follow')->getValue(); } } }
/** * Insert a meta item * * @param string $keywords The keyword of the item. * @param string $description A description of the item. * @param string $title The page title for the item. * @param string $url The unique URL. * @param bool $keywordsOverwrite Should the keywords be overwritten? * @param bool $descriptionOverwrite Should the descriptions be overwritten? * @param bool $titleOverwrite Should the page title be overwritten? * @param bool $urlOverwrite Should the URL be overwritten? * @param string $custom Any custom meta-data. * @param array $data Any custom meta-data. * @return int */ protected function insertMeta($keywords, $description, $title, $url, $keywordsOverwrite = false, $descriptionOverwrite = false, $titleOverwrite = false, $urlOverwrite = false, $custom = null, $data = null) { $item = array('keywords' => (string) $keywords, 'keywords_overwrite' => $keywordsOverwrite && $keywordsOverwrite !== 'N' ? 'Y' : 'N', 'description' => (string) $description, 'description_overwrite' => $descriptionOverwrite && $descriptionOverwrite !== 'N' ? 'Y' : 'N', 'title' => (string) $title, 'title_overwrite' => $titleOverwrite && $titleOverwrite !== 'N' ? 'Y' : 'N', 'url' => CommonUri::getUrl((string) $url, BackendModel::getContainer()->getParameter('kernel.charset')), 'url_overwrite' => $urlOverwrite && $urlOverwrite !== 'N' ? 'Y' : 'N', 'custom' => !is_null($custom) ? (string) $custom : null, 'data' => !is_null($data) ? serialize($data) : null); return (int) $this->getDB()->insert('meta', $item); }
/** * Retrieve the unique URL for a category * * @param string $url * @param int[optional] $id The id of the category to ignore. * @return string */ public static function getURLForCategory($url, $id = null) { $url = CommonUri::getUrl((string) $url); $db = BackendModel::getContainer()->get('database'); // new category if ($id === null) { if ((bool) $db->getVar('SELECT 1 FROM slideshow_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? LIMIT 1', array(BL::getWorkingLanguage(), $url))) { $url = BackendModel::addNumber($url); return self::getURLForCategory($url); } } else { // current category should be excluded if ((bool) $db->getVar('SELECT 1 FROM slideshow_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? AND i.id != ? LIMIT 1', array(BL::getWorkingLanguage(), $url, $id))) { $url = BackendModel::addNumber($url); return self::getURLForCategory($url, $id); } } return $url; }
/** * Update a locale item. * * @param array $item The new data. */ public static function update(array $item) { // actions should be urlized if ($item['type'] == 'act' && urldecode($item['value']) != $item['value']) { $item['value'] = CommonUri::getUrl($item['value']); } // update category $updated = BackendModel::getContainer()->get('database')->update('locale', $item, 'id = ?', array($item['id'])); // rebuild the cache self::buildCache($item['language'], $item['application']); return $updated; }
/** * Get a unique URL for a tag * * @param string $URL The URL to use as a base. * @param int $id The ID to ignore. * @return string */ public static function getURL($URL, $id = null) { $URL = CommonUri::getUrl((string) $URL); $language = BL::getWorkingLanguage(); // get db $db = BackendModel::getContainer()->get('database'); // no specific id if ($id === null) { // get number of tags with the specified url $number = (int) $db->getVar('SELECT 1 FROM tags AS i WHERE i.url = ? AND i.language = ? LIMIT 1', array($URL, $language)); // there are items so, call this method again. if ($number != 0) { // add a number $URL = BackendModel::addNumber($URL); // recall this method, but with a new url $URL = self::getURL($URL, $id); } } else { // specific id given // get number of tags with the specified url $number = (int) $db->getVar('SELECT 1 FROM tags AS i WHERE i.url = ? AND i.language = ? AND i.id != ? LIMIT 1', array($URL, $language, $id)); // there are items so, call this method again. if ($number != 0) { // add a number $URL = BackendModel::addNumber($URL); // recall this method, but with a new url $URL = self::getURL($URL, $id); } } return $URL; }
/** * Retrieve a unique URL for a profile based on the display name. * * @param string $displayName The display name to base on. * @param int $id The id of the profile to ignore. * @return string */ public static function getUrl($displayName, $id = null) { // decode special chars $displayName = \SpoonFilter::htmlspecialcharsDecode((string) $displayName); // urlise $url = (string) CommonUri::getUrl($displayName); // get db $db = FrontendModel::getContainer()->get('database'); // new item if ($id === null) { // get number of profiles with this URL $number = (int) $db->getVar('SELECT 1 FROM profiles AS p WHERE p.url = ? LIMIT 1', (string) $url); // already exists if ($number != 0) { // add number $url = FrontendModel::addNumber($url); // try again return self::getURL($url); } } else { // current profile should be excluded // get number of profiles with this URL $number = (int) $db->getVar('SELECT 1 FROM profiles AS p WHERE p.url = ? AND p.id != ? LIMIT 1', array((string) $url, (int) $id)); // already exists if ($number != 0) { // add number $url = FrontendModel::addNumber($url); // try again return self::getURL($url, $id); } } return $url; }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate fields $this->frm->getField('name')->isFilled(BL::err('NameIsRequired')); // no errors? if ($this->frm->isCorrect()) { // build tag $item['id'] = $this->id; $item['tag'] = $this->frm->getField('name')->getValue(); $item['url'] = BackendTagsModel::getURL(CommonUri::getUrl(\SpoonFilter::htmlspecialcharsDecode($item['tag'])), $this->id); // update the item BackendTagsModel::update($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Index') . '&report=edited&var=' . urlencode($item['tag']) . '&highlight=row-' . $item['id']); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // redefine fields $txtName = $this->frm->getField('name'); $txtValue = $this->frm->getField('value'); // name checks if ($txtName->isFilled(BL::err('FieldIsRequired'))) { // allowed regex (a-z and 0-9) if ($txtName->isValidAgainstRegexp('|^([a-z0-9])+$|i', BL::err('InvalidName'))) { // first letter does not seem to be a capital one if (!in_array(substr($txtName->getValue(), 0, 1), range('A', 'Z'))) { $txtName->setError(BL::err('InvalidName')); } else { // this name already exists in this language if (BackendLocaleModel::existsByName($txtName->getValue(), $this->frm->getField('type')->getValue(), $this->frm->getField('module')->getValue(), $this->frm->getField('language')->getValue(), $this->frm->getField('application')->getValue())) { $txtName->setError(BL::err('AlreadyExists')); } } } } // value checks if ($txtValue->isFilled(BL::err('FieldIsRequired'))) { // in case this is a 'act' type, there are special rules concerning possible values if ($this->frm->getField('type')->getValue() == 'act') { if (urlencode($txtValue->getValue()) != CommonUri::getUrl($txtValue->getValue())) { $txtValue->addError(BL::err('InvalidValue')); } } } // module should be 'core' for any other application than backend if ($this->frm->getField('application')->getValue() != 'Backend' && $this->frm->getField('module')->getValue() != 'Core') { $this->frm->getField('module')->setError(BL::err('ModuleHasToBeCore')); } if ($this->frm->isCorrect()) { // build item $item['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['language'] = $this->frm->getField('language')->getValue(); $item['application'] = $this->frm->getField('application')->getValue(); $item['module'] = $this->frm->getField('module')->getValue(); $item['type'] = $this->frm->getField('type')->getValue(); $item['name'] = $this->frm->getField('name')->getValue(); $item['value'] = $this->frm->getField('value')->getValue(); $item['edited_on'] = BackendModel::getUTCDate(); // update item $item['id'] = BackendLocaleModel::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', null, null, null) . '&report=added&var=' . urlencode($item['name']) . '&highlight=row-' . $item['id'] . $this->filterQuery); } } }
/** * 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 $fileCSV = $this->frm->getField('csv'); $chkGroups = $this->frm->getField('groups'); // validate fields $fileCSV->isFilled(BL::err('CSVIsRequired')); // convert the CSV file to an array $csv = $fileCSV->isFilled() ? BackendCSV::fileToArray($fileCSV->getTempFileName()) : null; // check if the csv is valid if ($csv === false || empty($csv) || !isset($csv[0])) { $fileCSV->addError(BL::err('InvalidCSV')); } // there was a csv file found if (!empty($csv)) { // fetch the columns of the first row $columns = array_keys($csv[0]); // loop the columns foreach ($csv as $row) { // fetch the row columns $rowColumns = array_keys($row); // check if the arrays match if ($rowColumns != $columns) { // add an error to the CSV files $fileCSV->addError(BL::err('InvalidCSV')); // exit loop break; } } } // get values $values = $this->frm->getValues(); // check if at least one recipient group is chosen if (empty($values['groups'])) { $chkGroups->addError(BL::err('ChooseAtLeastOneGroup')); } // no errors? if ($this->frm->isCorrect()) { // convert the CSV file to an array, and fetch the group's CM ID $csv = BackendCSV::fileToArray($fileCSV->getTempFileName()); // process our import, and get the failed subscribers $failedSubscribers = $this->processImport($csv, $values['groups']); // show a detailed report $this->tpl->assign('import', false); // no failed subscribers found if (empty($failedSubscribers)) { // trigger event BackendModel::triggerEvent($this->getModule(), 'after_import_address'); // redirect to success message $this->redirect(BackendModel::createURLForAction('Addresses') . '&report=imported-addresses&var[]=' . count($csv) . '&var[]=' . count($values['groups'])); } else { // write a CSV file to the cache $csvFile = 'import-report-' . CommonUri::getUrl(BackendModel::getUTCDate()) . '.csv'; BackendCSV::arrayToFile(BACKEND_CACHE_PATH . '/Mailmotor/' . $csvFile, $failedSubscribers, null, null, ';', '"'); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_import_address_with_failed_items', array('failed' => $failedSubscribers)); // redirect to failed message with an additional parameter to // display a download link to the report-csv form cache. $this->redirect(BackendModel::createURLForAction('Addresses') . '&error=imported-addresses&var[]=' . count($csv) . '&var[]=' . count($values['groups']) . '&var[]=' . count($failedSubscribers) . '&csv=' . $csvFile); } } } }