Redaxscript\Filter\Html::sanitize PHP Метод

sanitize() публичный Метод

sanitize the html
С версии: 2.4.0
public sanitize ( string $html = null, boolean $filter = true ) : string
$html string target html
$filter boolean optional filter nodes
Результат string
    public function sanitize($html = null, $filter = true)
    {
        $charset = Db::getSetting('charset');
        $html = mb_convert_encoding($html, 'html-entities', $charset);
        $doc = $this->_createDocument($html);
        $doc = $this->_cleanDocument($doc);
        /* filter nodes */
        if ($filter === true) {
            $doc = $this->_stripTags($doc);
            $doc = $this->_stripAttributes($doc);
            $doc = $this->_stripValues($doc);
        }
        /* collect output */
        $output = trim($doc->saveHTML());
        return $output;
    }

Usage Example

Пример #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')]);
 }
All Usage Examples Of Redaxscript\Filter\Html::sanitize