Since: 2.2.0
Author: Henry Ruhs
Inheritance: implements Redaxscript\Filter\Filter
Exemple #1
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $urlFilter = new Filter\Url();
     $htmlFilter = new Filter\Html();
     /* process post */
     $postArray = ['author' => $specialFilter->sanitize($this->_request->getPost('author')), 'email' => $emailFilter->sanitize($this->_request->getPost('email')), 'url' => $urlFilter->sanitize($this->_request->getPost('url')), 'text' => $htmlFilter->sanitize($this->_request->getPost('text')), 'article' => $specialFilter->sanitize($this->_request->getPost('article')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     $route = build_route('articles', $postArray['article']);
     /* handle error */
     $messageArray = $this->_validate($postArray);
     if ($messageArray) {
         return $this->_error(['route' => $route, 'message' => $messageArray]);
     }
     /* handle success */
     $createArray = ['author' => $postArray['author'], 'email' => $postArray['email'], 'url' => $postArray['url'], 'text' => $postArray['text'], 'language' => Db::forTablePrefix('articles')->whereIdIs($postArray['article'])->findOne()->language, 'article' => $postArray['article'], 'status' => Db::getSetting('verification') ? 0 : 1];
     $mailArray = ['email' => $postArray['email'], 'url' => $postArray['url'], 'route' => $route, 'author' => $postArray['author'], 'text' => $postArray['text'], 'article' => Db::forTablePrefix('articles')->whereIdIs($postArray['article'])->findOne()->title];
     /* create */
     if (!$this->_create($createArray)) {
         return $this->_error(['route' => $route, 'message' => $this->_language->get('something_wrong')]);
     }
     /* mail */
     if (!$this->_mail($mailArray)) {
         return $this->_warning(['route' => $route, 'message' => $this->_language->get('email_failed')]);
     }
     return $this->_success(['route' => $route, 'timeout' => Db::getSetting('notification') ? 2 : 0, 'message' => Db::getSetting('moderation') ? $this->_language->get('comment_moderation') : $this->_language->get('comment_sent')]);
 }
 /**
  * testHtml
  *
  * @since 2.2.0
  *
  * @param string $html
  * @param string $expect
  *
  * @dataProvider providerHtml
  */
 public function testHtml($html = null, $expect = null)
 {
     /* setup */
     $filter = new Filter\Html();
     /* actual */
     $actual = $filter->sanitize($html);
     /* compare */
     $this->assertEquals($expect, $actual);
 }
Exemple #3
0
 /**
  * process
  *
  * @since 3.0.0
  *
  * @return string
  */
 public static function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $urlFilter = new Filter\Url();
     $htmlFilter = new Filter\Html();
     /* process post */
     $postArray = ['author' => $specialFilter->sanitize(Request::getPost('author')), 'email' => $emailFilter->sanitize(Request::getPost('email')), 'url' => $urlFilter->sanitize(Request::getPost('url')), 'text' => nl2br($htmlFilter->sanitize(Request::getPost('text'))), 'task' => Request::getPost('task'), 'solution' => Request::getPost('solution')];
     /* handle error */
     $messageArray = self::_validate($postArray);
     if ($messageArray) {
         return self::_error(['message' => $messageArray]);
     }
     /* handle success */
     $mailArray = ['author' => $postArray['author'], 'email' => $postArray['email'], 'url' => $postArray['url'], 'text' => $postArray['text']];
     /* mail */
     if (self::_mail($mailArray)) {
         return self::_success();
     }
     return self::_error(['message' => Language::get('something_wrong')]);
 }
 /**
  * process
  *
  * @since 2.6.0
  */
 public static function _process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $urlFilter = new Filter\Url();
     $htmlFilter = new Filter\Html();
     $emailValidator = new Validator\Email();
     $urlValidator = new Validator\Url();
     $captchaValidator = new Validator\Captcha();
     /* process post */
     $postData = array('author' => $specialFilter->sanitize(Request::getPost('author')), 'email' => $emailFilter->sanitize(Request::getPost('email')), 'url' => $urlFilter->sanitize(Request::getPost('url')), 'text' => nl2br($htmlFilter->sanitize(Request::getPost('text'))), 'task' => Request::getPost('task'), 'solution' => Request::getPost('solution'));
     /* validate post */
     if (!$postData['author']) {
         $errorData['author'] = Language::get('author_empty');
     }
     if (!$postData['email']) {
         $errorData['email'] = Language::get('email_empty');
     } else {
         if ($emailValidator->validate($postData['email']) === Validator\ValidatorInterface::FAILED) {
             $errorData['email'] = Language::get('email_incorrect');
         }
     }
     if ($errorData['url'] && $urlValidator->validate($postData['url']) === Validator\ValidatorInterface::FAILED) {
         $errorData['url'] = Language::get('url_incorrect');
     }
     if (!$postData['text']) {
         $errorData['text'] = Language::get('message_empty');
     }
     if ($captchaValidator->validate($postData['task'], $postData['solution']) === Validator\ValidatorInterface::FAILED) {
         $errorData['captcha'] = Language::get('captcha_incorrect');
     }
     /* handle error */
     if ($errorData) {
         notification(Language::get('error_occurred'), $errorData, Language::get('home'), Registry::get('root'));
     } else {
         notification(Language::get('operation_completed'), Language::get('message_sent', '_contact'), Language::get('home'), Registry::get('root'));
         self::_send($postData);
     }
 }