当前位置: 首页>>代码示例>>PHP>>正文


PHP HTMLPurifier类代码示例

本文整理汇总了PHP中HTMLPurifier的典型用法代码示例。如果您正苦于以下问题:PHP HTMLPurifier类的具体用法?PHP HTMLPurifier怎么用?PHP HTMLPurifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTMLPurifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: html_purify

 function html_purify($dirty_html, $config = FALSE)
 {
     require_once APPPATH . 'third_party/htmlpurifier-4.6.0-standalone/HTMLPurifier.standalone.php';
     if (is_array($dirty_html)) {
         foreach ($dirty_html as $key => $val) {
             $clean_html[$key] = html_purify($val, $config);
         }
     } else {
         $ci =& get_instance();
         switch ($config) {
             //settings for rhe WYSIWYG
             case 'comment':
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('Core.Encoding', $ci->config->item('charset'));
                 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                 $config->set('HTML.Allowed', 'a[href|title],img[title|src|alt],em,strong,cite,blockquote,code,ul,ol,li,dl,dt,dd,p,br,h1,h2,h3,h4,h5,h6,span,*[style]');
                 $config->set('AutoFormat.AutoParagraph', TRUE);
                 $config->set('AutoFormat.Linkify', TRUE);
                 $config->set('AutoFormat.RemoveEmpty', TRUE);
                 break;
             case FALSE:
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('Core.Encoding', $ci->config->item('charset'));
                 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                 break;
             default:
                 show_error('The HTMLPurifier configuration labeled "' . htmlentities($config, ENT_QUOTES, 'UTF-8') . '" could not be found.');
         }
         $purifier = new HTMLPurifier($config);
         $clean_html = $purifier->purify($dirty_html);
     }
     return $clean_html;
 }
开发者ID:sanekagr,项目名称:phoneshop,代码行数:33,代码来源:htmlpurifier_helper.php

示例2: filterData

 /**
  * 过滤数据 重组
  * @param array $data
  * @param array $modelfield
  */
 public function filterData($data = array(), $modelfield = array())
 {
     $newmodelfield = $this->parseModelField($modelfield);
     $newdata = $data;
     foreach ($data as $k => $d) {
         if (key_exists($k, $newmodelfield)) {
             switch ($newmodelfield[$k]['type']) {
                 case 'editor':
                     //编辑器过滤XSS
                     Vendor('Htmlpurifier.library.HTMLPurifier#auto');
                     $config = \HTMLPurifier_Config::createDefault();
                     $purifier = new \HTMLPurifier($config);
                     $newdata[$k] = $purifier->purify(htmlspecialchars_decode($d));
                     break;
                 case 'position':
                     //推荐位
                     $newdata[$k] = implode(',', $d);
                     break;
                 case 'checkbox':
                     $newdata[$k] = implode(',', $d);
                     break;
             }
         }
     }
     return $newdata;
 }
开发者ID:liutongju,项目名称:DreamCMSCN,代码行数:31,代码来源:ContentBaseModel.class.php

示例3: sanitize

 /**
  * Value sanitation. Sanitize input and output with ease using one of the sanitation types below.
  * 
  * @param  string $data the string/value you wish to sanitize
  * @param  string $type the type of sanitation you wish to use.
  * @return string       the sanitized string
  */
 public function sanitize($data, $type = '')
 {
     ## Use the HTML Purifier, as it help remove malicious scripts and code. ##
     ##       HTML Purifier 4.4.0 - Standards Compliant HTML Filtering       ##
     require_once 'htmlpurifier/HTMLPurifier.standalone.php';
     $purifier = new HTMLPurifier();
     $config = HTMLPurifier_Config::createDefault();
     $config->set('Core.Encoding', 'UTF-8');
     // If no type if selected, it will simply run it through the HTML purifier only.
     switch ($type) {
         // Remove HTML tags (can have issues with invalid tags, keep that in mind!)
         case 'purestring':
             $data = strip_tags($data);
             break;
             // Only allow a-z (H & L case)
         // Only allow a-z (H & L case)
         case 'atoz':
             $data = preg_replace('/[^a-zA-Z]+/', '', $data);
             break;
             // Integers only - Remove any non 0-9 and use Intval() to make sure it is an integer which comes out.
         // Integers only - Remove any non 0-9 and use Intval() to make sure it is an integer which comes out.
         case 'integer':
             $data = intval(preg_replace('/[^0-9]+/', '', $data));
             break;
     }
     /* HTML purifier to help prevent XSS in case anything slipped through. */
     $data = $purifier->purify($data);
     return $data;
 }
开发者ID:J0ker98,项目名称:Zolid-AJAX-Chat-Admin-Extension,代码行数:36,代码来源:livechat.processor.php

示例4: saveAction

 public function saveAction()
 {
     $form = new News_Form_Article();
     $formData = $this->_request->getPost();
     $form->populate($formData);
     if (!$form->isValid($formData)) {
         $appSession = Zend_Registry::get('appSession');
         $appSession->articleForm = $form;
         $this->_forward('index');
         return;
     }
     $news = new News_Model_News();
     if ($this->_getParam('id')) {
         if (!($article = $news->getRowInstance($this->_getParam('id')))) {
             $this->_helper->FlashMessenger->addMessage($this->view->translate('The article doesn\'t exist.'));
             $this->_redirect('/news');
             return;
         }
     } else {
         $article = $news->createRow();
     }
     require_once 'htmlpurifier/library/HTMLPurifier.auto.php';
     $config = HTMLPurifier_Config::createDefault();
     $purifier = new HTMLPurifier($config);
     $cleanHtml = $purifier->purify($form->getValue('content'));
     $article->title = $form->getValue('title');
     $article->date = $form->getValue('date');
     $article->excerpt = $form->getValue('excerpt');
     $article->content = $cleanHtml;
     $article->save();
     $this->_helper->FlashMessenger->addMessage($this->view->translate('The article has been saved.'));
     $this->_redirect('/news');
 }
开发者ID:sdgdsffdsfff,项目名称:auth-center,代码行数:33,代码来源:EditController.php

示例5: filterHTML

 /**
  * Gets the selected HTML Filter & filters the content
  * @param    string  $html    input to be cleaned
  * @TODO	allow the webmasters to select which HTML Filter they want to use such as
  *			HTMLPurifier, HTMLLawed etc, for now we just have HTMLPurifier.
  * @return   string
  **/
 public function filterHTML($html)
 {
     $icmsConfigPurifier = icms::$config->getConfigsByCat(ICMS_CONF_PURIFIER);
     $fcomment = '<!-- filtered with htmlpurifier -->';
     $purified = strpos($html, $fcomment);
     if ($purified !== FALSE) {
         $html = str_replace($fcomment, '', $html);
     }
     if ($icmsConfigPurifier['enable_purifier'] !== 0) {
         ICMS_PLUGINS_PATH;
         require_once ICMS_LIBRARIES_PATH . '/htmlpurifier/HTMLPurifier.standalone.php';
         require_once ICMS_LIBRARIES_PATH . '/htmlpurifier/HTMLPurifier.autoload.php';
         if ($icmsConfigPurifier['purifier_Filter_ExtractStyleBlocks'] !== 0) {
             require_once ICMS_PLUGINS_PATH . '/csstidy/class.csstidy.php';
         }
         // get the Config Data
         $icmsPurifyConf = self::getHTMLFilterConfig();
         // uncomment for specific config debug info
         //parent::filterDebugInfo('icmsPurifyConf', $icmsPurifyConf);
         $purifier = new HTMLPurifier($icmsPurifyConf);
         $html = $purifier->purify($html);
         $html .= $fcomment;
     }
     return $html;
 }
开发者ID:nao-pon,项目名称:impresscms,代码行数:32,代码来源:HTMLFilter.php

示例6: save

 function save()
 {
     $this->import_parameters();
     $this->load_library('htmlpurifier-4.5.0-lite/library/HTMLPurifier.auto');
     $config = HTMLPurifier_Config::createDefault();
     $purifier = new HTMLPurifier($config);
     $message = $purifier->purify(html_entity_decode($this->message));
     $this->set('message', $message);
     $reference_object = new $this->reference_object($this->reference_id);
     //if the message is being created for an object other than a project, then the project id will be retrieved from
     //the actual object
     //if the message is being posted on a project, then the project id is the messages reference_id
     if ($this->reference_object != 'project') {
         $project_id = isset($reference_object->project_id) ? $reference_object->project_id : false;
     } else {
         $project_id = $this->reference_id;
     }
     if ($project_id) {
         $this->set('project_id', $project_id);
     }
     if (isset($reference_object->client_id)) {
         $this->set('client_id', $reference_object->client_id);
     }
     $this->set('user_id', current_user()->id);
     //these two parameters shouldn't be set yet (they are set when we log activity which happens after the save),
     //but let's just make sure
     $this->unset_param('linked_object');
     $this->unset_param('linked_object_title');
     $result = parent::save();
     ActivityManager::message_created($this);
     return $result;
 }
开发者ID:neevan1e,项目名称:Done,代码行数:32,代码来源:message.php

示例7: _purifyValue

 protected function _purifyValue($val)
 {
     if ($val == $this->_example) {
         $val = null;
     } else {
         static $purifier = null;
         if ($this->_prevent_xss) {
             if (!empty($val)) {
                 if ($purifier == null && class_exists('HTMLPurifier')) {
                     if (iconv_get_encoding("internal_encoding") != "UTF-8") {
                         $config = HTMLPurifier_Config::createDefault();
                         $config->set('Core.Encoding', iconv_get_encoding("internal_encoding"));
                         // replace with your encoding
                         $purifier = new HTMLPurifier($config);
                     } else {
                         $purifier = new HTMLPurifier();
                     }
                 }
                 if ($purifier != null) {
                     $val = $purifier->purify($val);
                 }
             }
         }
     }
     return $val;
 }
开发者ID:laiello,项目名称:lion-framework,代码行数:26,代码来源:InputComponent.class.php

示例8: scrape

function scrape($url, $path, $parse)
{
    $config = HTMLPurifier_Config::createDefault();
    $config->set('Core.Encoding', 'UTF-8');
    //encoding of output
    $config->set('HTML.Doctype', 'XHTML 1.1');
    //doctype of output
    $purifier = new HTMLPurifier($config);
    $dirty_html = file_get_contents($url);
    $clean_html = $purifier->purify($dirty_html);
    $html = str_get_html($clean_html);
    switch ($parse) {
        case 'tag':
            $ret = $html->find($path)->tag;
            break;
        case 'outertext':
            $ret = $html->find($path)->outertext;
            break;
        case 'innertext':
            $ret = $html->find($path)->innertext;
            break;
        case 'plaintext':
            $ret = $html->find($path)->plaintext;
            break;
        default:
            $ret = $html->find($path);
            break;
    }
    // clean up memory
    $html->clear();
    unset($dirty_html);
    unset($clean_html);
    unset($html);
    return $ret;
}
开发者ID:anubhaBhargava,项目名称:OpenRecommender,代码行数:35,代码来源:index.php

示例9: clean

 /**
  * clean the comment text field from html, in order to use it as submitted text
  * uses the htmlpurifier library, or a simple strip_tags call, based on the app.yml config file
  *
  * @return String
  * @param  String - the text to be cleaned
  *
  * @author Guglielmo Celata
  * @see    http://htmlpurifier.org/
  **/
 public static function clean($text)
 {
     $allowed_html_tags = sfConfig::get('app_deppPropelActAsCommentableBehaviorPlugin_allowed_tags', array());
     $use_htmlpurifier = sfConfig::get('app_deppPropelActAsCommentableBehaviorPlugin_use_htmlpurifier', false);
     if ($use_htmlpurifier) {
         $htmlpurifier_path = sfConfig::get('app_deppPropelActAsCommentableBehaviorPlugin_htmlpurifier_path', SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'htmlpurifier' . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR);
         require_once $htmlpurifier_path . 'HTMLPurifier.auto.php';
         $config = HTMLPurifier_Config::createDefault();
         $config->set('HTML', 'Doctype', 'XHTML 1.0 Strict');
         $config->set('HTML', 'Allowed', implode(',', array_keys($allowed_html_tags)));
         if (isset($allowed_html_tags['a'])) {
             $config->set('HTML', 'AllowedAttributes', 'a.href');
             $config->set('AutoFormat', 'Linkify', true);
         }
         if (isset($allowed_html_tags['p'])) {
             $config->set('AutoFormat', 'AutoParagraph', true);
         }
         $purifier = new HTMLPurifier($config);
         $clean_text = $purifier->purify($text);
     } else {
         $allowed_html_tags_as_string = "";
         foreach ($allowed_html_tags as $tag) {
             $allowed_html_tags_as_string .= "{$tag}";
         }
         $clean_text = strip_tags($text, $allowed_html_tags_as_string);
     }
     return $clean_text;
 }
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:38,代码来源:deppPropelActAsCommentableToolkit.class.php

示例10: generate

 public function generate($f3)
 {
     require_once '***/libs/htmlpurifier/library/HTMLPurifier.auto.php';
     $purifier = new HTMLPurifier();
     make_seed();
     $models = array('cv2/lm_lstm_epoch50.00_0.5080.t7', 'cv/lm_lstm_epoch46.00_0.7940.t7');
     $rnx = array_rand($models, 1);
     $model = $models[$rnx];
     $seed = round(rand());
     $cmd = 'cd ***/char-rnn && th ***/char-rnn/sample.lua -verbose 0 -temperature 0.8 -gpuid -1 -seed ' . $seed . ' -length 2048 -primetext "<poem><html><head><meta charset=\\"utf-8\\"><style>body{background-color:#000;color:#0c0;}</style></head><body>" /home/drakh/klingon-poetry/' . $model;
     $postVars = array('cmd' => $cmd);
     $options = array('method' => 'POST', 'content' => http_build_query($postVars));
     $r = \Web::instance()->request('http://127.0.0.1:1337', $options);
     $clean_html = $purifier->purify($r['body']);
     $poem = nl2br(trim($clean_html));
     $db_data = array('seed' => $seed, 'model' => $model, 'poem' => $poem);
     $data_to_save = json_encode($db_data, JSON_UNESCAPED_UNICODE);
     $this->model->poem = $data_to_save;
     $this->model->written_date = date('d.m.Y H:i:s');
     $this->model->save();
     $id = $this->model->id_poem;
     $postVars = array('id' => $id);
     $options = array('method' => 'POST', 'content' => http_build_query($postVars));
     $r = \Web::instance()->request('http://127.0.0.1:1338', $options);
     $f3->reroute('/poem/' . $id);
 }
开发者ID:kl-ing-one,项目名称:klingon-poetry.zhadum.space,代码行数:26,代码来源:index.php

示例11: edit_contact

 public function edit_contact()
 {
     if (isset($_POST['edit_contact_btn'])) {
         $data_post = $this->input->post();
         $this->load->helper('HTMLPurifier');
         $config = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($config);
         $data_update['content'] = $purifier->purify($data_post['content_contact']);
         if ($this->Contact->update($data_update)) {
             $content = 'Cập nhật thông tin liên lạc thành công.';
             set_notice('status', SUCCESS_STATUS, $content);
             header('location:' . base_url() . 'index.php/_admin/manage_site/contact/show_contact');
         } else {
             $content = 'Cập nhật thông tin liên lạc thất bại.';
             set_notice('status', FAILED_STATUS, $content);
             header('location:' . base_url() . 'index.php/_admin/manage_site/contact/show_contact');
         }
     } else {
         $data['contact'] = $this->Contact->get_contact();
         $data['subView'] = '/manage_site/contact/edit_contact_layout';
         $data['title'] = "Cập nhật thông tin liên hệ";
         $data['subData'] = $data;
         $this->load->view('/main/main_layout', $data);
     }
 }
开发者ID:tuanvu5503,项目名称:thungrac.vn,代码行数:25,代码来源:Contact.php

示例12: purify

 public function purify($html, $options = array())
 {
     if (empty($html)) {
         return '';
     }
     require_once Config::get('HTML_PURIFIER');
     require_once 'HTMLPurifier.func.php';
     $html = Util\toUTF8String($html);
     $config = \HTMLPurifier_Config::createDefault();
     $config->set('AutoFormat.AutoParagraph', false);
     $config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
     //$config->set('AutoFormat.RemoveEmpty', true);//slows down htmls parsing
     //$config->set('AutoFormat.RemoveSpansWithoutAttributes', true); //medium slows down htmls parsing
     $config->set('HTML.ForbiddenElements', array('head'));
     $config->set('HTML.SafeIframe', true);
     $config->set('HTML.TargetBlank', true);
     $config->set('URI.DefaultScheme', 'https');
     $config->set('Attr.EnableID', true);
     if (!empty($options)) {
         foreach ($options as $k => $v) {
             $config->set($k, $v);
         }
     }
     $purifier = new \HTMLPurifier($config);
     // This storage is freed on error
     Cache::set('memory', str_repeat('*', 1024 * 1024));
     register_shutdown_function(array($this, 'onScriptShutdown'));
     $html = $purifier->purify($html);
     Cache::remove('memory');
     $html = str_replace('/preview/#', '#', $html);
     return $html;
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:32,代码来源:PreviewExtractor.php

示例13: sanitize

function sanitize($input, $type = "old")
{
    switch ($type) {
        case "int":
            $input = filter_var($input, FILTER_SANITIZE_NUMBER_INT);
            break;
        case "string":
            $input = filter_var($input, FILTER_SANITIZE_STRING);
            break;
        case "url":
            $input = filter_var($input, FILTER_SANITIZE_URL);
            break;
        case "email":
            $input = strtolower(filter_var($input, FILTER_SANITIZE_EMAIL));
            break;
        case "markdown":
            include_once ROOT . DS . 'libraries' . DS . 'purifier' . DS . 'HTMLPurifier.auto.php';
            $purifier = new HTMLPurifier();
            $input = $purifier->purify($input);
            break;
        case "comment":
            $input = htmlentities($input, ENT_QUOTES, "UTF-8");
            break;
        case "old":
            echo "Old version of sanitize called";
            exit;
            break;
    }
    return $input;
}
开发者ID:jerome42,项目名称:Qwench,代码行数:30,代码来源:shared.php

示例14: smarty_modifier_xoops_html_purifier

function smarty_modifier_xoops_html_purifier($html, $ecoding = null, $doctype = null)
{
    require_once XOOPS_LIBRARY_PATH . '/htmlpurifier/library/HTMLPurifier.auto.php';
    $encoding = $encoding ? $encoding : _CHARSET;
    $doctypeArr = array("HTML 4.01 Strict", "HTML 4.01 Transitional", "XHTML 1.0 Strict", "XHTML 1.0 Transitional", "XHTML 1.1");
    $config = HTMLPurifier_Config::createDefault();
    if (in_array($doctype, $doctypeArr)) {
        $config->set('HTML.Doctype', $doctype);
    }
    if ($_conv = $encoding !== 'UTF-8' && function_exists('mb_convert_encoding')) {
        $_substitute = mb_substitute_character();
        mb_substitute_character('none');
        $html = mb_convert_encoding($html, 'UTF-8', $encoding);
        $config->set('Core.Encoding', 'UTF-8');
    } else {
        $config->set('Core.Encoding', $encoding);
    }
    $purifier = new HTMLPurifier($config);
    $html = $purifier->purify($html);
    if ($_conv) {
        $html = mb_convert_encoding($html, $encoding, 'UTF-8');
        mb_substitute_character($_substitute);
    }
    return $html;
}
开发者ID:hiro1173,项目名称:legacy,代码行数:25,代码来源:modifier.xoops_html_purifier.php

示例15: loadHttpData

 /**
  * Prebehneme data HTML purifierom
  * @param  array
  * @return void
  */
 public function loadHttpData()
 {
     $data = $this->getForm()->getHttpData();
     $name = $this->getName();
     $value = isset($data[$name]) && is_scalar($data[$name]) ? $data[$name] : NULL;
     $config = HTMLPurifier_Config::createDefault();
     $config->set('Core.Encoding', $this->encoding);
     if (!is_null($this->docType)) {
         $config->set('HTML.Doctype', $this->docType);
     }
     $config->set('HTML.Allowed', 'p,a[href],strong,em,b,i,ul,ol,li,h1,h2,h3,h4,h5,div[class],span[class],br,sup,table[border],tr,td,th,thead,tbody,img[src],img[style]');
     //        $config->set('HTML.Allowed', 'p,a[href],strong,em,ul,ol,li,h1,h2,div[class],span[class],br,sup');
     //        $config->set('HTML.Allowed', 'p,a[href],strong,em,ul,ol,li,h2,h3,h4,h5');
     // povoli lubovolny obsah pre href atribut odkazu - aby sa dali vyuzit latte links
     $config->set('HTML.DefinitionID', 'enduser-customize.html tutorial');
     //        $config->set('HTML.DefinitionRev', 1);
     //        $config->set('Cache.DefinitionImpl', null); // remove this later!
     $def = $config->getHTMLDefinition(true);
     $def->addAttribute('a', 'href*', 'Text');
     $purifier = new HTMLPurifier($config);
     //        var_dump($value);
     //		 kedze CKEDITOR to escapuje a neviem ho prinutit aby to nerobil, tak to tu dam naspat, Purifier to nasledne aj tak spravne zescapuje
     //        $value = html_entity_decode($value);
     //        var_dump($value);
     //        var_dump($purifier->purify($value));die();
     $this->setValue($purifier->purify($value));
 }
开发者ID:radypala,项目名称:maga-website,代码行数:32,代码来源:RichTextArea.php


注:本文中的HTMLPurifier类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。