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


PHP HTMLPurifier_Config::create方法代码示例

本文整理汇总了PHP中HTMLPurifier_Config::create方法的典型用法代码示例。如果您正苦于以下问题:PHP HTMLPurifier_Config::create方法的具体用法?PHP HTMLPurifier_Config::create怎么用?PHP HTMLPurifier_Config::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTMLPurifier_Config的用法示例。


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

示例1: testLineNumbers

 function testLineNumbers()
 {
     //       .  .     .     .  .     .     .           .      .             .
     //       01234567890123 01234567890123 0123456789012345 0123456789012   012345
     $html = "<b>Line 1</b>\n<i>Line 2</i>\nStill Line 2<br\n/>Now Line 4\n\n<br />";
     $expect = array(0 => new HTMLPurifier_Token_Start('b'), 1 => new HTMLPurifier_Token_Text('Line 1'), 2 => new HTMLPurifier_Token_End('b'), 3 => new HTMLPurifier_Token_Text("\n"), 4 => new HTMLPurifier_Token_Start('i'), 5 => new HTMLPurifier_Token_Text('Line 2'), 6 => new HTMLPurifier_Token_End('i'), 7 => new HTMLPurifier_Token_Text("\nStill Line 2"), 8 => new HTMLPurifier_Token_Empty('br'), 9 => new HTMLPurifier_Token_Text("Now Line 4\n\n"), 10 => new HTMLPurifier_Token_Empty('br'));
     $context = new HTMLPurifier_Context();
     $config = HTMLPurifier_Config::createDefault();
     $output = $this->DirectLex->tokenizeHTML($html, $config, $context);
     $this->assertIdentical($output, $expect);
     $context = new HTMLPurifier_Context();
     $config = HTMLPurifier_Config::create(array('Core.MaintainLineNumbers' => true));
     $expect[0]->position(1, 0);
     $expect[1]->position(1, 3);
     $expect[2]->position(1, 9);
     $expect[3]->position(2, -1);
     $expect[4]->position(2, 0);
     $expect[5]->position(2, 3);
     $expect[6]->position(2, 9);
     $expect[7]->position(3, -1);
     $expect[8]->position(3, 12);
     $expect[9]->position(4, 2);
     $expect[10]->position(6, 0);
     $output = $this->DirectLex->tokenizeHTML($html, $config, $context);
     $this->assertIdentical($output, $expect);
 }
开发者ID:artbypravesh,项目名称:morningpages,代码行数:26,代码来源:DirectLexTest.php

示例2: prepareCommon

 /**
  * Accepts config and context and prepares them into a valid state
  * @param &$config Reference to config variable
  * @param &$context Reference to context variable
  */
 protected function prepareCommon(&$config, &$context)
 {
     $config = HTMLPurifier_Config::create($config);
     if (!$context) {
         $context = new HTMLPurifier_Context();
     }
 }
开发者ID:ajnok,项目名称:yii2book,代码行数:12,代码来源:Harness.php

示例3: test_setup

 public function test_setup()
 {
     $i = 0;
     // counter, helps us isolate expectations
     // initialize partial mock
     $module = new HTMLPurifier_HTMLModule_Tidy_TestForConstruct();
     $module->fixesForLevel['light'] = array('light-fix-1', 'light-fix-2');
     $module->fixesForLevel['medium'] = array('medium-fix-1', 'medium-fix-2');
     $module->fixesForLevel['heavy'] = array('heavy-fix-1', 'heavy-fix-2');
     $j = 0;
     $fixes = array('light-fix-1' => $lf1 = $j++, 'light-fix-2' => $lf2 = $j++, 'medium-fix-1' => $mf1 = $j++, 'medium-fix-2' => $mf2 = $j++, 'heavy-fix-1' => $hf1 = $j++, 'heavy-fix-2' => $hf2 = $j++);
     $module->setReturnValue('makeFixes', $fixes);
     $config = HTMLPurifier_Config::create(array('HTML.TidyLevel' => 'none'));
     $module->expectAt($i++, 'populate', array(array()));
     $module->setup($config);
     // basic levels
     $config = HTMLPurifier_Config::create(array('HTML.TidyLevel' => 'light'));
     $module->expectAt($i++, 'populate', array(array('light-fix-1' => $lf1, 'light-fix-2' => $lf2)));
     $module->setup($config);
     $config = HTMLPurifier_Config::create(array('HTML.TidyLevel' => 'heavy'));
     $module->expectAt($i++, 'populate', array(array('light-fix-1' => $lf1, 'light-fix-2' => $lf2, 'medium-fix-1' => $mf1, 'medium-fix-2' => $mf2, 'heavy-fix-1' => $hf1, 'heavy-fix-2' => $hf2)));
     $module->setup($config);
     // fine grained tuning
     $config = HTMLPurifier_Config::create(array('HTML.TidyLevel' => 'none', 'HTML.TidyAdd' => array('light-fix-1', 'medium-fix-1')));
     $module->expectAt($i++, 'populate', array(array('light-fix-1' => $lf1, 'medium-fix-1' => $mf1)));
     $module->setup($config);
     $config = HTMLPurifier_Config::create(array('HTML.TidyLevel' => 'medium', 'HTML.TidyRemove' => array('light-fix-1', 'medium-fix-1')));
     $module->expectAt($i++, 'populate', array(array('light-fix-2' => $lf2, 'medium-fix-2' => $mf2)));
     $module->setup($config);
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:30,代码来源:TidyTest.php

示例4: generateEnLanguage

 protected function generateEnLanguage()
 {
     $factory = HTMLPurifier_LanguageFactory::instance();
     $config = HTMLPurifier_Config::create(array('Core.Language' => 'en'));
     $context = new HTMLPurifier_Context();
     return $factory->create($config, $context);
 }
开发者ID:youprofit,项目名称:casebox,代码行数:7,代码来源:LanguageTest.php

示例5: test

 function test()
 {
     generate_mock_once('HTMLPurifier_URIScheme');
     $config = HTMLPurifier_Config::create(array('URI.AllowedSchemes' => 'http, telnet', 'URI.OverrideAllowedSchemes' => true));
     $context = new HTMLPurifier_Context();
     $registry = new HTMLPurifier_URISchemeRegistry();
     $this->assertIsA($registry->getScheme('http', $config, $context), 'HTMLPurifier_URIScheme_http');
     $scheme_http = new HTMLPurifier_URISchemeMock();
     $scheme_telnet = new HTMLPurifier_URISchemeMock();
     $scheme_foobar = new HTMLPurifier_URISchemeMock();
     // register a new scheme
     $registry->register('telnet', $scheme_telnet);
     $this->assertIdentical($registry->getScheme('telnet', $config, $context), $scheme_telnet);
     // overload a scheme, this is FINAL (forget about defaults)
     $registry->register('http', $scheme_http);
     $this->assertIdentical($registry->getScheme('http', $config, $context), $scheme_http);
     // when we register a scheme, it's automatically allowed
     $registry->register('foobar', $scheme_foobar);
     $this->assertIdentical($registry->getScheme('foobar', $config, $context), $scheme_foobar);
     // now, test when overriding is not allowed
     $config = HTMLPurifier_Config::create(array('URI.AllowedSchemes' => 'http, telnet', 'URI.OverrideAllowedSchemes' => false));
     $this->assertNull($registry->getScheme('foobar', $config, $context));
     // scheme not allowed and never registered
     $this->assertNull($registry->getScheme('ftp', $config, $context));
 }
开发者ID:artbypravesh,项目名称:morningpages,代码行数:25,代码来源:URISchemeRegistryTest.php

示例6: process

 /**
  * Passes markup through HTMLPurifier making it safe to output to end user
  *
  * @param string $content
  * @param array|null $config
  * @return string
  */
 public static function process($content, $config = null)
 {
     $configInstance = \HTMLPurifier_Config::create($config);
     $configInstance->autoFinalize = false;
     $purifier = \HTMLPurifier::instance($configInstance);
     $purifier->config->set('Cache.SerializerPath', \Yii::$app->getRuntimePath());
     return $purifier->purify($content);
 }
开发者ID:yuexiaoyun,项目名称:lulucms,代码行数:15,代码来源:BaseHtmlPurifier.php

示例7: purifyHTML

 /**
  * @param string $html
  * @param array $config
  * @return string
  */
 protected function purifyHTML($html, $config)
 {
     $configInstance = \HTMLPurifier_Config::create($config);
     $configInstance->autoFinalize = false;
     $purifier = \HTMLPurifier::instance($configInstance);
     $purifier->config->set('Cache.SerializerPath', $this->tmpPath);
     return $purifier->purify($html);
 }
开发者ID:CatoTH,项目名称:html2opendocument,代码行数:13,代码来源:Base.php

示例8: __construct

 public function __construct($root_dir)
 {
     $config = \HTMLPurifier_Config::create(array('Cache.SerializerPath' => $root_dir));
     $def = $config->getHTMLDefinition(true);
     $def->addAttribute('a', 'data-code', 'Text');
     $this->purifier_service = new \HTMLPurifier($config);
     $this->markdown_service = new \Parsedown();
 }
开发者ID:ScotSalmon,项目名称:thronesdb,代码行数:8,代码来源:Texts.php

示例9: setup

 public function setup()
 {
     $this->config = HTMLPurifier_Config::create(array('Core.CollectErrors' => true));
     $this->context = new HTMLPurifier_Context();
     generate_mock_once('HTMLPurifier_ErrorCollector');
     $this->collector = new HTMLPurifier_ErrorCollectorEMock();
     $this->collector->prepare($this->context);
     $this->context->register('ErrorCollector', $this->collector);
     $this->callCount = 0;
 }
开发者ID:artbypravesh,项目名称:morningpages,代码行数:10,代码来源:ErrorsHarness.php

示例10: process

 /**
  * Passes markup through HTMLPurifier making it safe to output to end user
  *
  * @param string $content The HTML content to purify
  * @param array|\Closure|null $config The config to use for HtmlPurifier.
  * If not specified or `null` the default config will be used.
  * You can use an array or an anonymous function to provide configuration options:
  *
  * - An array will be passed to the `HTMLPurifier_Config::create()` method.
  * - An anonymous function will be called after the config was created.
  *   The signature should be: `function($config)` where `$config` will be an
  *   instance of `HTMLPurifier_Config`.
  *
  *   Here is a usage example of such a function:
  *
  *   ~~~
  *   // Allow the HTML5 data attribute `data-type` on `img` elements.
  *   $content = HtmlPurifier::process($content, function ($config) {
  *     $config->getHTMLDefinition(true)
  *            ->addAttribute('img', 'data-type', 'Text');
  *   });
  * ~~~
  *
  * @return string the purified HTML content.
  */
 public static function process($content, $config = null)
 {
     $configInstance = \HTMLPurifier_Config::create($config instanceof \Closure ? null : $config);
     $configInstance->autoFinalize = false;
     $purifier = \HTMLPurifier::instance($configInstance);
     $purifier->config->set('Cache.SerializerPath', Application::$app->getRuntimePath());
     if ($config instanceof \Closure) {
         call_user_func($config, $configInstance);
     }
     return $purifier->purify($content);
 }
开发者ID:ercling,项目名称:auth,代码行数:36,代码来源:HtmlPurifier.php

示例11: truncateHtml

 protected static function truncateHtml($string, $count, $suffix, $wordsPerLine, $encoding)
 {
     $config = \HTMLPurifier_Config::create(null);
     $config->set('Cache.SerializerPath', \Yii::$app->getRuntimePath());
     $lexer = \HTMLPurifier_Lexer::create($config);
     $tokens = $lexer->tokenizeHTML($string, $config, null);
     $openTokens = 0;
     $totalCount = 0;
     $truncated = [];
     foreach ($tokens as $token) {
         if ($token instanceof \HTMLPurifier_Token_Start) {
             //Tag begins
             $openTokens++;
             $truncated[] = $token;
         } elseif ($token instanceof \HTMLPurifier_Token_Text && $totalCount <= $count) {
             //Text
             if (false === $encoding) {
                 $token->data = self::truncateWords($token->data, ($count - $totalCount) * $wordsPerLine, '');
                 $currentWords = str_word_count($token->data);
             } else {
                 $token->data = self::truncate($token->data, ($count - $totalCount) * $wordsPerLine, '', $encoding) . ' ';
                 $currentWords = mb_strlen($token->data, $encoding);
             }
             //$totalCount += $currentWords;
             if (!$token->is_whitespace) {
                 $totalCount += intval(ceil($currentWords / $wordsPerLine));
             }
             //turn into lines
             if (1 === $currentWords) {
                 $token->data = ' ' . $token->data;
             }
             $truncated[] = $token;
         } elseif ($token instanceof \HTMLPurifier_Token_End) {
             //Tag ends
             $openTokens--;
             $truncated[] = $token;
         } elseif ($token instanceof \HTMLPurifier_Token_Empty) {
             //Self contained tags, i.e. <img/> etc.
             if ($token->name == 'img') {
                 //filter img tag
             } else {
                 $truncated[] = $token;
             }
         }
         if (0 === $openTokens && $totalCount >= $count) {
             break;
         }
     }
     $context = new \HTMLPurifier_Context();
     $generator = new \HTMLPurifier_Generator($config, $context);
     return $generator->generateFromTokens($truncated) . $suffix;
 }
开发者ID:gouchaoer,项目名称:yii2-starter-kit,代码行数:52,代码来源:StringHelper.php

示例12: testAllowedModules

 public function testAllowedModules()
 {
     $manager = new HTMLPurifier_HTMLModuleManager();
     $manager->doctypes->register('Fantasy Inventory 1.0', true, array('Weapons', 'Magic'));
     // register these modules so it doesn't blow up
     $weapons_module = new HTMLPurifier_HTMLModule();
     $weapons_module->name = 'Weapons';
     $manager->registerModule($weapons_module);
     $magic_module = new HTMLPurifier_HTMLModule();
     $magic_module->name = 'Magic';
     $manager->registerModule($magic_module);
     $config = HTMLPurifier_Config::create(array('HTML.CustomDoctype' => 'Fantasy Inventory 1.0', 'HTML.AllowedModules' => 'Weapons'));
     $manager->setup($config);
     $this->assertTrue(isset($manager->modules['Weapons']));
     $this->assertFalse(isset($manager->modules['Magic']));
 }
开发者ID:Jaaviieer,项目名称:PrograWeb,代码行数:16,代码来源:HTMLModuleManagerTest.php

示例13: phorum_htmlpurifier_get_config

/**
 * Initializes the appropriate configuration from either a PHP file
 * or a module configuration value
 * @return Instance of HTMLPurifier_Config
 */
function phorum_htmlpurifier_get_config()
{
    global $PHORUM;
    $config_exists = phorum_htmlpurifier_config_file_exists();
    if ($config_exists || !isset($PHORUM['mod_htmlpurifier']['config'])) {
        $config = HTMLPurifier_Config::createDefault();
        include dirname(__FILE__) . '/config.default.php';
        if ($config_exists) {
            include dirname(__FILE__) . '/config.php';
        }
        unset($PHORUM['mod_htmlpurifier']['config']);
        // unnecessary
    } else {
        $config = HTMLPurifier_Config::create($PHORUM['mod_htmlpurifier']['config']);
    }
    return $config;
}
开发者ID:hasshy,项目名称:sahana-tw,代码行数:22,代码来源:init-config.php

示例14: purify

 public static function purify($var)
 {
     $external = Ajde_Core_ExternalLibs::getInstance();
     if ($external->has('HTMLPurifier')) {
         $purifier = $external->get('HTMLPurifier');
         /* @var $purifier HTMLPurifier */
         $config = HTMLPurifier_Config::createDefault();
         $config->set('AutoFormat.AutoParagraph', true);
         $config->set('AutoFormat.DisplayLinkURI', false);
         $config->set('AutoFormat.Linkify', false);
         $config->set('AutoFormat.RemoveEmpty', true);
         $config->set('AutoFormat.RemoveSpansWithoutAttributes', true);
         $config->set('CSS.AllowedProperties', '');
         $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
         $config->set('URI.DisableExternalResources', true);
         $purifier->config = HTMLPurifier_Config::create($config);
         return $purifier->purify($var);
     } else {
         return self::clean($var);
     }
 }
开发者ID:nabble,项目名称:ajde,代码行数:21,代码来源:String.php

示例15: truncateHtml

 /**
  * Truncate a string while preserving the HTML.
  * 
  * @param string $string The string to truncate
  * @param integer $count
  * @param string $suffix String to append to the end of the truncated string.
  * @param string|boolean $encoding
  * @return string
  * @since 2.0.1
  */
 protected static function truncateHtml($string, $count, $suffix, $encoding = false)
 {
     $config = \HTMLPurifier_Config::create(null);
     $lexer = \HTMLPurifier_Lexer::create($config);
     $tokens = $lexer->tokenizeHTML($string, $config, null);
     $openTokens = 0;
     $totalCount = 0;
     $truncated = [];
     foreach ($tokens as $token) {
         if ($token instanceof \HTMLPurifier_Token_Start) {
             //Tag begins
             $openTokens++;
             $truncated[] = $token;
         } else {
             if ($token instanceof \HTMLPurifier_Token_Text && $totalCount <= $count) {
                 //Text
                 if (false === $encoding) {
                     $token->data = self::truncateWords($token->data, $count - $totalCount, '');
                     $currentCount = str_word_count($token->data);
                 } else {
                     $token->data = self::truncate($token->data, $count - $totalCount, '', $encoding) . ' ';
                     $currentCount = mb_strlen($token->data, $encoding);
                 }
                 $totalCount += $currentCount;
                 if (1 === $currentCount) {
                     $token->data = ' ' . $token->data;
                 }
                 $truncated[] = $token;
             } else {
                 if ($token instanceof \HTMLPurifier_Token_End) {
                     //Tag ends
                     $openTokens--;
                     $truncated[] = $token;
                 } else {
                     if ($token instanceof \HTMLPurifier_Token_Empty) {
                         //Self contained tags, i.e. <img/> etc.
                         $truncated[] = $token;
                     }
                 }
             }
         }
         if (0 === $openTokens && $totalCount >= $count) {
             break;
         }
     }
     $context = new \HTMLPurifier_Context();
     $generator = new \HTMLPurifier_Generator($config, $context);
     return $generator->generateFromTokens($truncated) . $suffix;
 }
开发者ID:aoopvn,项目名称:EduSec4.0.0,代码行数:59,代码来源:BaseStringHelper.php


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