當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CHtmlPurifier::setOptions方法代碼示例

本文整理匯總了PHP中CHtmlPurifier::setOptions方法的典型用法代碼示例。如果您正苦於以下問題:PHP CHtmlPurifier::setOptions方法的具體用法?PHP CHtmlPurifier::setOptions怎麽用?PHP CHtmlPurifier::setOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CHtmlPurifier的用法示例。


在下文中一共展示了CHtmlPurifier::setOptions方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: rules

 /**
  * @return array validation rules for model attributes.
  * @internal you should only define rules for those attributes that will receive user inputs
  */
 public function rules()
 {
     // On ajoute un filtre CHtmlPurifier avant l'enregistrement des données. Il sert ici moins à la protection contre
     // les attaques XSS qu'à s'assurer que le code HTML de l'actualité est valide.
     // Cette condition est indispensable pour que la classe DOMHelper puisse tronquer correctement
     // le texte pour construire des résumés (en page d'accueil par exemple)
     $htmlPurifier = new CHtmlPurifier();
     $htmlPurifier->setOptions(array('HTML.SafeIframe' => true, 'URI.SafeIframeRegexp' => '%www.youtube.com/embed/%'));
     return array(array('news_id, language_id, title', 'required'), array('title, description, keywords', 'length', 'max' => 255), array('language_id', 'exist', 'attributeName' => 'id', 'className' => 'Language'), array('news_id', 'exist', 'attributeName' => 'id', 'className' => 'News'), array('content', 'filter', 'filter' => array($htmlPurifier, 'purify')), array('tagsString', 'length', 'max' => 255), array('created_at, updated_at', 'safe'), array('news_id, language_id, title, slug, description, keywords, content, tagsString, tagIdFilter, enabled, eventDate', 'safe', 'on' => 'search'));
 }
開發者ID:ChristopheBrun,項目名稱:hLib,代碼行數:14,代碼來源:TranslatedNews.php

示例2: prepValueFromPost

 /**
  * @inheritDoc IFieldType::prepValueFromPost()
  *
  * @param mixed $value
  *
  * @return mixed
  */
 public function prepValueFromPost($value)
 {
     // Temporary fix (hopefully) for a Redactor bug where some HTML will get submitted when the field is blank,
     // if any text was typed into the field, and then deleted
     if ($value == '<p><br></p>') {
         $value = '';
     }
     if ($value) {
         // Swap any pagebreak <hr>'s with <!--pagebreak-->'s
         $value = preg_replace('/<hr class="redactor_pagebreak".*?>/', '<!--pagebreak-->', $value);
         if ($this->getSettings()->purifyHtml) {
             $purifier = new \CHtmlPurifier();
             $purifier->setOptions(array('Attr.AllowedFrameTargets' => array('_blank'), 'HTML.AllowedComments' => array('pagebreak')));
             $value = $purifier->purify($value);
         }
         if ($this->getSettings()->cleanupHtml) {
             // Remove <span> and <font> tags
             $value = preg_replace('/<(?:span|font)\\b[^>]*>/', '', $value);
             $value = preg_replace('/<\\/(?:span|font)>/', '', $value);
             // Remove inline styles
             $value = preg_replace('/(<(?:h1|h2|h3|h4|h5|h6|p|div|blockquote|pre|strong|em|b|i|u|a)\\b[^>]*)\\s+style="[^"]*"/', '$1', $value);
             // Remove empty tags
             $value = preg_replace('/<(h1|h2|h3|h4|h5|h6|p|div|blockquote|pre|strong|em|a|b|i|u)\\s*><\\/\\1>/', '', $value);
         }
     }
     // Find any element URLs and swap them with ref tags
     $value = preg_replace_callback('/(href=|src=)([\'"])[^\'"]+?#(\\w+):(\\d+)(:' . HandleValidator::$handlePattern . ')?\\2/', function ($matches) {
         return $matches[1] . $matches[2] . '{' . $matches[3] . ':' . $matches[4] . (!empty($matches[5]) ? $matches[5] : ':url') . '}' . $matches[2];
     }, $value);
     return $value;
 }
開發者ID:scisahaha,項目名稱:generator-craft,代碼行數:38,代碼來源:RichTextFieldType.php

示例3: htmlFilter

 public function htmlFilter($value)
 {
     $p = new CHtmlPurifier();
     $p->setOptions(array('HTML.Allowed' => ''));
     return $p->purify($value);
 }
開發者ID:pavlm,項目名稱:ycomments,代碼行數:6,代碼來源:Comment.php

示例4: prepValueFromPost

 /**
  * @inheritDoc IFieldType::prepValueFromPost()
  *
  * @param mixed $value
  *
  * @return mixed
  */
 public function prepValueFromPost($value)
 {
     // Temporary fix (hopefully) for a Redactor bug where some HTML will get submitted when the field is blank,
     // if any text was typed into the field, and then deleted
     if ($value == '<p><br></p>') {
         $value = '';
     }
     if ($value) {
         // Swap any pagebreak <hr>'s with <!--pagebreak-->'s
         $value = preg_replace('/<hr class="redactor_pagebreak".*?>/', '<!--pagebreak-->', $value);
         if ($this->getSettings()->purifyHtml) {
             $purifier = new \CHtmlPurifier();
             $purifier->setOptions(array('Attr.AllowedFrameTargets' => array('_blank'), 'HTML.AllowedComments' => array('pagebreak')));
             $value = $purifier->purify($value);
         }
         if ($this->getSettings()->cleanupHtml) {
             // Remove <span> and <font> tags
             $value = preg_replace('/<(?:span|font)\\b[^>]*>/', '', $value);
             $value = preg_replace('/<\\/(?:span|font)>/', '', $value);
             // Remove inline styles
             $value = preg_replace('/(<(?:h1|h2|h3|h4|h5|h6|p|div|blockquote|pre|strong|em|b|i|u|a)\\b[^>]*)\\s+style="[^"]*"/', '$1', $value);
             // Remove empty tags
             $value = preg_replace('/<(h1|h2|h3|h4|h5|h6|p|div|blockquote|pre|strong|em|a|b|i|u)\\s*><\\/\\1>/', '', $value);
         }
     }
     // Find any element URLs and swap them with ref tags
     $value = preg_replace_callback('/(href=|src=)([\'"])[^\'"#]+?(#[^\'"#]+)?(?:#|%23)(\\w+):(\\d+)(:' . HandleValidator::$handlePattern . ')?\\2/', function ($matches) {
         $refTag = '{' . $matches[4] . ':' . $matches[5] . (!empty($matches[6]) ? $matches[6] : ':url') . '}';
         $hash = !empty($matches[3]) ? $matches[3] : '';
         if ($hash) {
             // Make sure that the hash isn't actually part of the parsed URL
             // (someone's Entry URL Format could be "#{slug}", etc.)
             $url = craft()->elements->parseRefs($refTag);
             if (mb_strpos($url, $hash) !== false) {
                 $hash = '';
             }
         }
         return $matches[1] . $matches[2] . $refTag . $hash . $matches[2];
     }, $value);
     // Encode any 4-byte UTF-8 characters.
     $value = StringHelper::encodeMb4($value);
     return $value;
 }
開發者ID:imarc,項目名稱:craft-betterredactor,代碼行數:50,代碼來源:BetterRedactorFieldType.php


注:本文中的CHtmlPurifier::setOptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。