err() public static method

Get an error from the language-file
public static err ( string $key, string $module = null ) : string
$key string The key to get.
$module string The module wherein we should search.
return string
Beispiel #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);
         }
     }
 }
Beispiel #2
0
 /**
  * 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);
         }
     }
 }
Beispiel #3
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();
         // 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->filesystem->remove(FRONTEND_FILES_PATH . '/wordpress.xml');
             // Everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('index') . '&report=imported');
         }
     }
 }
Beispiel #4
0
 /**
  * @return bool
  */
 private function isValid()
 {
     $fields = $this->form->getFields();
     if (!$fields['start_date']->isFilled(Language::err('FieldIsRequired')) || !$fields['end_date']->isFilled(Language::err('FieldIsRequired'))) {
         return $this->form->isCorrect();
     }
     if (!$fields['start_date']->isValid(Language::err('DateIsInvalid')) || !$fields['end_date']->isValid(Language::err('DateIsInvalid'))) {
         return $this->form->isCorrect();
     }
     $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(Language::err('DateRangeIsInvalid'));
     }
     // enddate cannot be in the future
     if ($newEndDate > time()) {
         $fields['start_date']->setError(Language::err('DateRangeIsInvalid'));
     }
     // enddate cannot be before the startdate
     if ($newStartDate > $newEndDate) {
         $fields['start_date']->setError(Language::err('DateRangeIsInvalid'));
     }
     return $this->form->isCorrect();
 }
Beispiel #5
0
 /**
  * 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':
             $this->statusCode = Response::HTTP_FORBIDDEN;
             break;
         case 'not-found':
             $this->statusCode = Response::HTTP_NOT_FOUND;
             break;
         default:
             $this->statusCode = Response::HTTP_BAD_REQUEST;
             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]) {
             // give a nice error, so we can detect which file is missing
             throw new ExitException('File not found', 'Requested file (' . htmlspecialchars($this->getParameter('querystring')) . ') not found.', Response::HTTP_NOT_FOUND);
         }
     }
     // assign the correct message into the template
     $this->tpl->assign('message', BL::err(\SpoonFilter::toCamelCase(htmlspecialchars($errorType), '-')));
 }
Beispiel #6
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $id = \SpoonFilter::getPostValue('id', null, 0, 'int');
     $tag = trim(\SpoonFilter::getPostValue('value', null, '', 'string'));
     // validate id
     if ($id === 0) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     } else {
         // validate tag name
         if ($tag === '') {
             $this->output(self::BAD_REQUEST, null, BL::err('NameIsRequired'));
         } else {
             // check if tag exists
             if (BackendTagsModel::existsTag($tag)) {
                 $this->output(self::BAD_REQUEST, null, BL::err('TagAlreadyExists'));
             } else {
                 $item['id'] = $id;
                 $item['tag'] = \SpoonFilter::htmlspecialchars($tag);
                 $item['url'] = BackendTagsModel::getURL(CommonUri::getUrl(\SpoonFilter::htmlspecialcharsDecode($item['tag'])), $id);
                 BackendTagsModel::update($item);
                 $this->output(self::OK, $item, vsprintf(BL::msg('Edited'), array($item['tag'])));
             }
         }
     }
 }
Beispiel #7
0
 /**
  * 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']));
         }
     }
 }
Beispiel #8
0
 /**
  * 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'])));
     }
 }
Beispiel #9
0
 /**
  * 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);
         }
     }
 }
Beispiel #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=' . rawurlencode($item['question']) . '&highlight=' . $item['id']);
         }
     }
 }
 /**
  * @return bool
  */
 private function isValid()
 {
     $fileField = $this->form->getField('certificate');
     $emailField = $this->form->getField('email');
     if ($fileField->isFilled(Language::err('FieldIsRequired'))) {
         $fileField->isAllowedExtension(['p12'], Language::err('P12Only'));
     }
     $emailField->isFilled(Language::err('FieldIsRequired'));
     $emailField->isEmail(Language::err('EmailIsInvalid'));
     return $this->form->isCorrect();
 }
Beispiel #12
0
 /**
  * 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 (rawurlencode($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);
     }
 }
Beispiel #13
0
 /**
  * This function will return the errors. It is extended so we can do file checks automatically.
  *
  * @return string
  */
 public function getErrors()
 {
     // if the image is bigger then the allowed configuration it won't show up as filled but it is submitted
     // the empty check is added because otherwise this error is shown like 7 times
     if ($this->isSubmitted() && isset($_FILES[$this->getName()]['error']) && empty($this->errors)) {
         $imageError = $_FILES[$this->getName()]['error'];
         if ($imageError === UPLOAD_ERR_INI_SIZE && empty($this->errors)) {
             $this->addError(SpoonFilter::ucfirst(sprintf(BackendLanguage::err('FileTooBig'), Form::getUploadMaxFileSize())));
         }
     }
     return $this->errors;
 }
Beispiel #14
0
 /**
  * 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'), BackendLanguage::err('JPGGIFAndPNGOnly'));
         $this->isAllowedMimeType(array('image/jpeg', 'image/gif', 'image/png'), BackendLanguage::err('JPGGIFAndPNGOnly'));
     }
     // if the image is bigger then the allowed configuration it won't show up as filled but it is submitted
     // the empty check is added because otherwise this error is shown like 7 times
     if ($this->isSubmitted() && isset($_FILES[$this->getName()]['error']) && empty($this->errors)) {
         $imageError = $_FILES[$this->getName()]['error'];
         if ($imageError === UPLOAD_ERR_INI_SIZE && empty($this->errors)) {
             $this->addError(SpoonFilter::ucfirst(sprintf(BackendLanguage::err('FileTooBig'), Form::getUploadMaxFileSize())));
         }
     }
     return $this->errors;
 }
Beispiel #15
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $itemId = trim(\SpoonFilter::getPostValue('id', null, '', 'int'));
     $lat = \SpoonFilter::getPostValue('lat', null, null, 'float');
     $lng = \SpoonFilter::getPostValue('lng', null, null, 'float');
     // validate id
     if ($itemId == 0) {
         $this->output(self::BAD_REQUEST, null, BL::err('NonExisting'));
     } else {
         //update
         $updateData = array('id' => $itemId, 'lat' => $lat, 'lng' => $lng, 'language' => BL::getWorkingLanguage());
         BackendLocationModel::update($updateData);
         // output
         $this->output(self::OK);
     }
 }
Beispiel #16
0
 /**
  * Checks the settings and optionally returns an array with warnings
  *
  * @return array
  */
 public static function checkSettings()
 {
     $warnings = array();
     // check if debug-mode is active
     if (BackendModel::getContainer()->getParameter('kernel.debug')) {
         $warnings[] = array('message' => BackendLanguage::err('DebugModeIsActive'));
     }
     // check if this action is allowed
     if (Authentication::isAllowedAction('Index', 'Settings')) {
         // check if the fork API keys are available
         if (self::get('fork.settings')->get('Core', 'fork_api_private_key') == '' || self::get('fork.settings')->get('Core', 'fork_api_public_key') == '') {
             $warnings[] = array('message' => sprintf(BackendLanguage::err('ForkAPIKeys'), self::createURLForAction('Index', 'Settings')));
         }
     }
     // check for extensions warnings
     $warnings = array_merge($warnings, BackendExtensionsModel::checkSettings());
     return $warnings;
 }
Beispiel #17
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->meta->setURLCallback('Backend\\Modules\\Faq\\Engine\\Model', 'getURLForCategory');
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->meta->validate();
         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'] = BackendFaqModel::getMaximumCategorySequence() + 1;
             // save the data
             $item['id'] = BackendFaqModel::insertCategory($item);
             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=' . rawurlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Beispiel #18
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $fromEmail = \SpoonFilter::getPostValue('mailer_from_email', null, '');
     $fromName = \SpoonFilter::getPostValue('mailer_from_name', null, '');
     $toEmail = \SpoonFilter::getPostValue('mailer_to_email', null, '');
     $toName = \SpoonFilter::getPostValue('mailer_to_name', null, '');
     $replyToEmail = \SpoonFilter::getPostValue('mailer_reply_to_email', null, '');
     $replyToName = \SpoonFilter::getPostValue('mailer_reply_to_name', null, '');
     // init validation
     $errors = array();
     // validate
     if ($fromEmail == '' || !\SpoonFilter::isEmail($fromEmail)) {
         $errors['from'] = BL::err('EmailIsInvalid');
     }
     if ($toEmail == '' || !\SpoonFilter::isEmail($toEmail)) {
         $errors['to'] = BL::err('EmailIsInvalid');
     }
     if ($replyToEmail == '' || !\SpoonFilter::isEmail($replyToEmail)) {
         $errors['reply'] = BL::err('EmailIsInvalid');
     }
     // got errors?
     if (!empty($errors)) {
         $this->output(self::BAD_REQUEST, array('errors' => $errors), 'invalid fields');
     } else {
         $message = \Swift_Message::newInstance('Test')->setFrom(array($fromEmail => $fromName))->setTo(array($toEmail => $toName))->setReplyTo(array($replyToEmail => $replyToName))->setBody(BL::msg('TestMessage'), 'text/plain');
         $transport = TransportFactory::create(\SpoonFilter::getPostValue('mailer_type', array('smtp', 'mail'), 'mail'), \SpoonFilter::getPostValue('smtp_server', null, ''), \SpoonFilter::getPostValue('smtp_port', null, ''), \SpoonFilter::getPostValue('smtp_username', null, ''), \SpoonFilter::getPostValue('smtp_password', null, ''), \SpoonFilter::getPostValue('smtp_secure_layer', null, ''));
         $mailer = \Swift_Mailer::newInstance($transport);
         try {
             if ($mailer->send($message)) {
                 $this->output(self::OK, null, '');
             } else {
                 $this->output(self::ERROR, null, 'unknown');
             }
         } catch (\Exception $e) {
             $this->output(self::ERROR, null, $e->getMessage());
         }
     }
 }
Beispiel #19
0
 /**
  * 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'));
         // validate meta
         $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);
             // update the item
             BackendBlogModel::updateCategory($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_category', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Categories') . '&report=edited-category&var=' . rawurlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Beispiel #20
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             // build item
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['street'] = $this->frm->getField('street')->getValue();
             $item['number'] = $this->frm->getField('number')->getValue();
             $item['zip'] = $this->frm->getField('zip')->getValue();
             $item['city'] = $this->frm->getField('city')->getValue();
             $item['country'] = $this->frm->getField('country')->getValue();
             // define coordinates
             $coordinates = BackendLocationModel::getCoordinates($item['street'], $item['number'], $item['city'], $item['zip'], $item['country']);
             // define latitude and longitude
             $item['lat'] = $coordinates['latitude'];
             $item['lng'] = $coordinates['longitude'];
             // insert the item
             $item['id'] = BackendLocationModel::insert($item);
             // everything is saved, so redirect to the overview
             if ($item['lat'] && $item['lng']) {
                 // trigger event
                 BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             }
             // redirect
             $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $item['id'] . '&report=added&var=' . rawurlencode($item['title']));
         }
     }
 }
Beispiel #21
0
 /**
  * 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(mb_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 (rawurlencode($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=' . rawurlencode($item['name']) . '&highlight=row-' . $item['id'] . $this->filterQuery);
         }
     }
 }
 /**
  * @return bool
  */
 private function isValid()
 {
     $this->form->getField('web_property_id')->isFilled(Language::err('FieldIsRequired'));
     return $this->form->isCorrect();
 }
Beispiel #23
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // shorten fields
         $newPassword = $this->frm->getField('backend_new_password');
         $newPasswordRepeated = $this->frm->getField('backend_new_password_repeated');
         // required fields
         $newPassword->isFilled(BL::err('PasswordIsRequired'));
         $newPasswordRepeated->isFilled(BL::err('PasswordRepeatIsRequired'));
         // all fields are ok?
         if ($newPassword->isFilled() && $newPasswordRepeated->isFilled()) {
             // the passwords entered match
             if ($newPassword->getValue() !== $newPasswordRepeated->getValue()) {
                 // add error
                 $this->frm->addError(BL::err('PasswordsDontMatch'));
                 // show error
                 $this->tpl->assign('error', BL::err('PasswordsDontMatch'));
             }
         }
         if ($this->frm->isCorrect()) {
             // change the users password
             BackendUsersModel::updatePassword($this->user, $newPassword->getValue());
             // attempt to login the user
             if (!BackendAuthentication::loginUser($this->user->getEmail(), $newPassword->getValue())) {
                 // redirect to the login form with an error
                 $this->redirect(BackendModel::createURLForAction('Index', null, null, array('login' => 'failed')));
             }
             // redirect to the login form
             $this->redirect(BackendModel::createURLForAction('Index', 'Dashboard', null, array('password_reset' => 'success')));
         }
     }
 }
Beispiel #24
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['language'] = BL::getWorkingLanguage();
             $item['extra_id'] = $this->record['extra_id'];
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['street'] = $this->frm->getField('street')->getValue();
             $item['number'] = $this->frm->getField('number')->getValue();
             $item['zip'] = $this->frm->getField('zip')->getValue();
             $item['city'] = $this->frm->getField('city')->getValue();
             $item['country'] = $this->frm->getField('country')->getValue();
             // check if it's necessary to geocode again
             if ($this->record['lat'] === null || $this->record['lng'] === null || $item['street'] != $this->record['street'] || $item['number'] != $this->record['number'] || $item['zip'] != $this->record['zip'] || $item['city'] != $this->record['city'] || $item['country'] != $this->record['country']) {
                 // define coordinates
                 $coordinates = BackendLocationModel::getCoordinates($item['street'], $item['number'], $item['city'], $item['zip'], $item['country']);
                 // define latitude and longitude
                 $item['lat'] = $coordinates['latitude'];
                 $item['lng'] = $coordinates['longitude'];
             } else {
                 $item['lat'] = $this->record['lat'];
                 $item['lng'] = $this->record['lng'];
             }
             // insert the item
             BackendLocationModel::update($item);
             // everything is saved, so redirect to the overview
             if ($item['lat'] && $item['lng']) {
                 // trigger event
                 BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             }
             // redirect to the overview
             if ($this->frm->getField('redirect')->getValue() == 'overview') {
                 $this->redirect(BackendModel::createURLForAction('Index') . '&report=edited&var=' . rawurlencode($item['title']) . '&highlight=row-' . $item['id']);
             } else {
                 $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $item['id'] . '&report=edited');
             }
         }
     }
 }
Beispiel #25
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();
         // required fields
         $this->frm->getField('file')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('label')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('format')->isFilled(BL::err('FieldIsRequired'));
         // check if the template file exists
         if ($this->frm->getField('theme')->getValue() == 'Core') {
             $templateFile = PATH_WWW . '/src/Frontend/Core/Layout/Templates/' . $this->frm->getField('file')->getValue();
         } else {
             $templateFile = PATH_WWW . '/src/Frontend/Themes/' . $this->frm->getField('theme')->getValue() . '/Core/Layout/Templates/' . $this->frm->getField('file')->getValue();
         }
         if (!is_file($templateFile)) {
             $this->frm->getField('file')->addError(BL::err('TemplateFileNotFound'));
         }
         // validate syntax
         $syntax = trim(str_replace(array("\n", "\r", ' '), '', $this->frm->getField('format')->getValue()));
         // init var
         $table = BackendExtensionsModel::templateSyntaxToArray($syntax);
         // validate the syntax
         if ($table === false) {
             $this->frm->getField('format')->addError(BL::err('InvalidTemplateSyntax'));
         } else {
             $html = BackendExtensionsModel::buildTemplateHTML($syntax);
             $cellCount = 0;
             $first = true;
             $errors = array();
             // loop rows
             foreach ($table as $row) {
                 // first row defines the cellcount
                 if ($first) {
                     $cellCount = count($row);
                 }
                 // not same number of cells
                 if (count($row) != $cellCount) {
                     // add error
                     $errors[] = BL::err('InvalidTemplateSyntax');
                     // stop
                     break;
                 }
                 // doublecheck position names
                 foreach ($row as $cell) {
                     // ignore unavailable space
                     if ($cell != '/') {
                         // not alphanumeric -> error
                         if (!in_array($cell, $this->names)) {
                             $errors[] = sprintf(BL::getError('NonExistingPositionName'), $cell);
                         } elseif (mb_substr_count($html, '"#position-' . $cell . '"') != 1) {
                             // can't build proper html -> error
                             $errors[] = BL::err('InvalidTemplateSyntax');
                         }
                     }
                 }
                 // reset
                 $first = false;
             }
             // add errors
             if ($errors) {
                 $this->frm->getField('format')->addError(implode('<br />', array_unique($errors)));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build array
             $item['theme'] = $this->frm->getField('theme')->getValue();
             $item['label'] = $this->frm->getField('label')->getValue();
             $item['path'] = 'Core/Layout/Templates/' . $this->frm->getField('file')->getValue();
             $item['active'] = $this->frm->getField('active')->getActualValue();
             $item['data']['format'] = trim(str_replace(array("\n", "\r", ' '), '', $this->frm->getField('format')->getValue()));
             $item['data']['names'] = $this->names;
             $item['data']['default_extras'] = $this->extras;
             $item['data']['default_extras_' . BL::getWorkingLanguage()] = $this->extras;
             $item['data']['image'] = $this->frm->getField('image')->isChecked();
             // serialize the data
             $item['data'] = serialize($item['data']);
             // insert the item
             $item['id'] = BackendExtensionsModel::insertTemplate($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_template', array('item' => $item));
             // set default template
             if ($this->frm->getField('default')->getChecked() && $item['theme'] == $this->get('fork.settings')->get('Core', 'theme', 'core')) {
                 $this->get('fork.settings')->set($this->getModule(), 'default_template', $item['id']);
             }
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('ThemeTemplates') . '&theme=' . $item['theme'] . '&report=added-template&var=' . rawurlencode($item['label']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Beispiel #26
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();
         // get fields
         $txtEmail = $this->frm->getField('email');
         $txtDisplayName = $this->frm->getField('display_name');
         $txtPassword = $this->frm->getField('password');
         $txtFirstName = $this->frm->getField('first_name');
         $txtLastName = $this->frm->getField('last_name');
         $txtCity = $this->frm->getField('city');
         $ddmGender = $this->frm->getField('gender');
         $ddmDay = $this->frm->getField('day');
         $ddmMonth = $this->frm->getField('month');
         $ddmYear = $this->frm->getField('year');
         $ddmCountry = $this->frm->getField('country');
         // email filled in?
         if ($txtEmail->isFilled(BL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(BL::getError('EmailIsInvalid'))) {
                 // email already exists?
                 if (BackendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     // set error
                     $txtEmail->addError(BL::getError('EmailExists'));
                 }
             }
         }
         // display name filled in?
         if ($txtDisplayName->isFilled(BL::getError('DisplayNameIsRequired'))) {
             // display name already exists?
             if (BackendProfilesModel::existsDisplayName($txtDisplayName->getValue())) {
                 // set error
                 $txtDisplayName->addError(BL::getError('DisplayNameExists'));
             }
         }
         // profile must not be notified, password must not be empty
         if (!$this->notifyProfile) {
             $txtPassword->isFilled(BL::err('FieldIsRequired'));
         }
         // one of the birthday fields are filled in
         if ($ddmDay->isFilled() || $ddmMonth->isFilled() || $ddmYear->isFilled()) {
             // valid date?
             if (!checkdate($ddmMonth->getValue(), $ddmDay->getValue(), $ddmYear->getValue())) {
                 // set error
                 $ddmYear->addError(BL::getError('DateIsInvalid'));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             $salt = BackendProfilesModel::getRandomString();
             $password = $txtPassword->isFilled() ? $txtPassword->getValue() : BackendModel::generatePassword(8);
             // build item
             $values = array('email' => $txtEmail->getValue(), 'registered_on' => BackendModel::getUTCDate(), 'display_name' => $txtDisplayName->getValue(), 'url' => BackendProfilesModel::getUrl($txtDisplayName->getValue()), 'last_login' => BackendModel::getUTCDate(null, 0), 'password' => BackendProfilesModel::getEncryptedString($password, $salt));
             $this->id = BackendProfilesModel::insert($values);
             // update salt
             BackendProfilesModel::setSetting($this->id, 'salt', $salt);
             // bday is filled in
             if ($ddmYear->isFilled()) {
                 // mysql format
                 $birthDate = $ddmYear->getValue() . '-';
                 $birthDate .= str_pad($ddmMonth->getValue(), 2, '0', STR_PAD_LEFT) . '-';
                 $birthDate .= str_pad($ddmDay->getValue(), 2, '0', STR_PAD_LEFT);
             } else {
                 // not filled in
                 $birthDate = null;
             }
             // update settings
             BackendProfilesModel::setSetting($this->id, 'first_name', $txtFirstName->getValue());
             BackendProfilesModel::setSetting($this->id, 'last_name', $txtLastName->getValue());
             BackendProfilesModel::setSetting($this->id, 'gender', $ddmGender->getValue());
             BackendProfilesModel::setSetting($this->id, 'birth_date', $birthDate);
             BackendProfilesModel::setSetting($this->id, 'city', $txtCity->getValue());
             BackendProfilesModel::setSetting($this->id, 'country', $ddmCountry->getValue());
             // notify values
             $notifyValues = array_merge($values, array('id' => $this->id, 'first_name' => $txtFirstName->getValue(), 'last_name' => $txtLastName->getValue(), 'unencrypted_password' => $password));
             $redirectUrl = BackendModel::createURLForAction('Edit') . '&id=' . $this->id . '&var=' . rawurlencode($values['display_name']) . '&report=';
             // notify new profile user
             if ($this->notifyProfile) {
                 BackendProfilesModel::notifyProfile($notifyValues);
                 $redirectUrl .= 'saved-and-notified';
             } else {
                 $redirectUrl .= 'saved';
             }
             // notify admin
             if ($this->notifyAdmin) {
                 BackendProfilesModel::notifyAdmin($notifyValues);
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $values));
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
Beispiel #27
0
 /**
  * Validates the settings form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // validation
         $this->frm->getField('rss_title')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             // set our settings
             $this->get('fork.settings')->set($this->URL->getModule(), 'overview_num_items', (int) $this->frm->getField('overview_number_of_items')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'recent_articles_full_num_items', (int) $this->frm->getField('recent_articles_full_number_of_items')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'recent_articles_list_num_items', (int) $this->frm->getField('recent_articles_list_number_of_items')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'spamfilter', (bool) $this->frm->getField('spamfilter')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'allow_comments', (bool) $this->frm->getField('allow_comments')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'moderation', (bool) $this->frm->getField('moderation')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'notify_by_email_on_new_comment_to_moderate', (bool) $this->frm->getField('notify_by_email_on_new_comment_to_moderate')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'notify_by_email_on_new_comment', (bool) $this->frm->getField('notify_by_email_on_new_comment')->getValue());
             // @TODO remove this when the api is kicked out
             $this->get('fork.settings')->set($this->URL->getModule(), 'ping_services', (bool) $this->frm->getField('ping_services')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'rss_title_' . BL::getWorkingLanguage(), $this->frm->getField('rss_title')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'rss_description_' . BL::getWorkingLanguage(), $this->frm->getField('rss_description')->getValue());
             $this->get('fork.settings')->set($this->URL->getModule(), 'rss_meta_' . BL::getWorkingLanguage(), $this->frm->getField('rss_meta')->getValue());
             if ($this->isGod) {
                 $this->get('fork.settings')->set($this->URL->getModule(), 'show_image_form', (bool) $this->frm->getField('show_image_form')->getChecked());
             }
             if ($this->get('fork.settings')->get('Core', 'akismet_key') === null) {
                 $this->get('fork.settings')->set($this->URL->getModule(), 'spamfilter', false);
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_saved_settings');
             // redirect to the settings page
             $this->redirect(BackendModel::createURLForAction('Settings') . '&report=saved');
         }
     }
 }
Beispiel #28
0
 /**
  * Checks the settings and optionally returns an array with warnings
  *
  * @return array
  */
 public static function checkSettings()
 {
     $warnings = array();
     // check if this action is allowed
     if (BackendAuthentication::isAllowedAction('Settings', 'Blog')) {
         // rss title
         if (BackendModel::get('fork.settings')->get('Blog', 'rss_title_' . BL::getWorkingLanguage(), null) == '') {
             $warnings[] = array('message' => sprintf(BL::err('RSSTitle', 'Blog'), BackendModel::createURLForAction('Settings', 'Blog')));
         }
         // rss description
         if (BackendModel::get('fork.settings')->get('Blog', 'rss_description_' . BL::getWorkingLanguage(), null) == '') {
             $warnings[] = array('message' => sprintf(BL::err('RSSDescription', 'Blog'), BackendModel::createURLForAction('Settings', 'Blog')));
         }
     }
     return $warnings;
 }
Beispiel #29
0
 /**
  * Get an error from the language-file
  *
  * @param string $key The key to get.
  * @param string $module The module wherein we should search.
  *
  * @deprecated
  *
  * @return string
  */
 public static function err($key, $module = null)
 {
     trigger_error('Backend\\Core\\Engine\\Language is deprecated.
          It has been moved to Backend\\Core\\Language\\Language', E_USER_DEPRECATED);
     return parent::err($key, $module);
 }
Beispiel #30
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $bundledActionPermissions = array();
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // get fields
         $nameField = $this->frm->getField('name');
         foreach ($this->modules as $module) {
             // loop through actions
             foreach ($this->actions[$module['value']] as $action) {
                 // collect permissions if not bundled
                 if (!array_key_exists('group', $action)) {
                     $actionPermissions[] = $this->frm->getField('actions_' . $module['label'] . '_' . $action['label']);
                 }
             }
             // loop through bundled actions
             foreach ($this->actionGroups as $key => $group) {
                 // loop through all fields
                 foreach ($this->frm->getFields() as $field) {
                     // field exists?
                     if ($field->getName() == 'actions_' . $module['label'] . '_' . 'Group_' . \SpoonFilter::ucfirst($key)) {
                         // add to bundled actions
                         $bundledActionPermissions[] = $this->frm->getField('actions_' . $module['label'] . '_' . 'Group_' . \SpoonFilter::ucfirst($key));
                     }
                 }
             }
         }
         // loop through widgets and collect presets
         $widgetPresets = array();
         foreach ($this->widgets as $widget) {
             $widgetPresets[] = $this->frm->getField('widgets_' . $widget['checkbox_name']);
         }
         // validate fields
         $nameField->isFilled(BL::err('NameIsRequired'));
         // group already exists?
         if (BackendGroupsModel::alreadyExists($nameField->getValue())) {
             $nameField->setError(BL::err('GroupAlreadyExists'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // insert widgets
             $group = $this->insertWidgets($widgetPresets);
             // assign id
             $this->id = $group['id'];
             // insert permissions
             $this->insertPermissions($actionPermissions, $bundledActionPermissions);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $group));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=added&var=' . rawurlencode($group['name']) . '&highlight=row-' . $group['id']);
         }
     }
 }