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


PHP HTMLPurifier_Context类代码示例

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


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

示例1: filter

 /**
  * @param HTMLPurifier_URI $uri
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return bool
  */
 public function filter(&$uri, $config, $context)
 {
     // check if filter not applicable
     if (!$config->get('HTML.SafeIframe')) {
         return true;
     }
     // check if the filter should actually trigger
     if (!$context->get('EmbeddedURI', true)) {
         return true;
     }
     $token = $context->get('CurrentToken', true);
     if (!($token && $token->name == 'iframe')) {
         return true;
     }
     // check if we actually have some whitelists enabled
     if ($this->regexp === null) {
         return false;
     }
     // actually check the whitelists
     if (!preg_match($this->regexp, $uri->toString())) {
         return false;
     }
     // Make sure that if we're an HTTPS site, the iframe is also HTTPS
     if (is_https() && $uri->scheme == 'http') {
         // Convert it to a protocol-relative URL
         $uri->scheme = null;
     }
     return $uri;
 }
开发者ID:rboyatt,项目名称:mahara,代码行数:35,代码来源:SafeIframe.php

示例2: filter

 /**
  * @param HTMLPurifier_URI $uri
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return bool
  */
 public function filter(&$uri, $config, $context)
 {
     if (!$context->get('EmbeddedURI', true)) {
         return true;
     }
     return parent::filter($uri, $config, $context);
 }
开发者ID:aslijiasheng,项目名称:ciFramework,代码行数:13,代码来源:DisableExternalResources.php

示例3: __construct

 /**
  * @param HTMLPurifier_Context $context
  */
 public function __construct($context)
 {
     $this->locale =& $context->get('Locale');
     $this->context = $context;
     $this->_current =& $this->_stacks[0];
     $this->errors =& $this->_stacks[0];
 }
开发者ID:Jaaviieer,项目名称:PrograWeb,代码行数:10,代码来源:ErrorCollector.php

示例4: testNull

 public function testNull()
 {
     $context = new HTMLPurifier_Context();
     $var = NULL;
     $context->register('var', $var);
     $this->assertNull($context->get('var'));
     $context->destroy('var');
 }
开发者ID:Jaaviieer,项目名称:PrograWeb,代码行数:8,代码来源:ContextTest.php

示例5: validateChildren

 /**
  * @param HTMLPurifier_Node[] $children
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return bool
  */
 public function validateChildren($children, $config, $context)
 {
     if ($context->get('IsInline') === false) {
         return $this->block->validateChildren($children, $config, $context);
     } else {
         return $this->inline->validateChildren($children, $config, $context);
     }
 }
开发者ID:HaakonME,项目名称:porticoestate,代码行数:14,代码来源:Chameleon.php

示例6: validate

 /**
  * Checks if CurrentToken is set and equal to $this->element
  * @param string $string
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return bool|string
  */
 public function validate($string, $config, $context)
 {
     $token = $context->get('CurrentToken', true);
     if ($token && $token->name == $this->element) {
         return false;
     }
     return $this->def->validate($string, $config, $context);
 }
开发者ID:beyondye,项目名称:ENPHP,代码行数:15,代码来源:DenyElementDecorator.php

示例7: purify

 /**
  * Filters an HTML snippet/document to be XSS-free and standards-compliant.
  *
  * @param $html String of HTML to purify
  * @param $config HTMLPurifier_Config object for this operation, if omitted,
  *                defaults to the config object specified during this
  *                object's construction. The parameter can also be any type
  *                that HTMLPurifier_Config::create() supports.
  * @return Purified HTML
  */
 public function purify($html, $config = null)
 {
     // :TODO: make the config merge in, instead of replace
     $config = $config ? HTMLPurifier_Config::create($config) : $this->config;
     // implementation is partially environment dependant, partially
     // configuration dependant
     $lexer = HTMLPurifier_Lexer::create($config);
     $context = new HTMLPurifier_Context();
     // setup HTML generator
     $this->generator = new HTMLPurifier_Generator($config, $context);
     $context->register('Generator', $this->generator);
     // set up global context variables
     if ($config->get('Core.CollectErrors')) {
         // may get moved out if other facilities use it
         $language_factory = HTMLPurifier_LanguageFactory::instance();
         $language = $language_factory->create($config, $context);
         $context->register('Locale', $language);
         $error_collector = new HTMLPurifier_ErrorCollector($context);
         $context->register('ErrorCollector', $error_collector);
     }
     // setup id_accumulator context, necessary due to the fact that
     // AttrValidator can be called from many places
     $id_accumulator = HTMLPurifier_IDAccumulator::build($config, $context);
     $context->register('IDAccumulator', $id_accumulator);
     $html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context);
     // setup filters
     $filter_flags = $config->getBatch('Filter');
     $custom_filters = $filter_flags['Custom'];
     unset($filter_flags['Custom']);
     $filters = array();
     foreach ($filter_flags as $filter => $flag) {
         if (!$flag) {
             continue;
         }
         if (strpos($filter, '.') !== false) {
             continue;
         }
         $class = "HTMLPurifier_Filter_{$filter}";
         $filters[] = new $class();
     }
     foreach ($custom_filters as $filter) {
         // maybe "HTMLPurifier_Filter_$filter", but be consistent with AutoFormat
         $filters[] = $filter;
     }
     $filters = array_merge($filters, $this->filters);
     // maybe prepare(), but later
     for ($i = 0, $filter_size = count($filters); $i < $filter_size; $i++) {
         $html = $filters[$i]->preFilter($html, $config, $context);
     }
     // purified HTML
     $html = $this->generator->generateFromTokens($this->strategy->execute($lexer->tokenizeHTML($html, $config, $context), $config, $context));
     for ($i = $filter_size - 1; $i >= 0; $i--) {
         $html = $filters[$i]->postFilter($html, $config, $context);
     }
     $html = HTMLPurifier_Encoder::convertFromUTF8($html, $config, $context);
     $this->context =& $context;
     return $html;
 }
开发者ID:chenyongze,项目名称:iwebshop,代码行数:68,代码来源:HTMLPurifier.standalone.php

示例8: validate

 /**
  * @param string $id
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return bool|string
  */
 public function validate($id, $config, $context)
 {
     if (!$this->selector && !$config->get('Attr.EnableID')) {
         return false;
     }
     $id = trim($id);
     // trim it first
     if ($id === '') {
         return false;
     }
     $prefix = $config->get('Attr.IDPrefix');
     if ($prefix !== '') {
         $prefix .= $config->get('Attr.IDPrefixLocal');
         // prevent re-appending the prefix
         if (strpos($id, $prefix) !== 0) {
             $id = $prefix . $id;
         }
     } elseif ($config->get('Attr.IDPrefixLocal') !== '') {
         trigger_error('%Attr.IDPrefixLocal cannot be used unless ' . '%Attr.IDPrefix is set', E_USER_WARNING);
     }
     if (!$this->selector) {
         $id_accumulator =& $context->get('IDAccumulator');
         if (isset($id_accumulator->ids[$id])) {
             return false;
         }
     }
     // we purposely avoid using regex, hopefully this is faster
     if ($config->get('Attr.ID.HTML5') === true) {
         if (preg_match('/[\\t\\n\\x0b\\x0c ]/', $id)) {
             return false;
         }
     } else {
         if (ctype_alpha($id)) {
             // OK
         } else {
             if (!ctype_alpha(@$id[0])) {
                 return false;
             }
             // primitive style of regexps, I suppose
             $trim = trim($id, 'A..Za..z0..9:-._');
             if ($trim !== '') {
                 return false;
             }
         }
     }
     $regexp = $config->get('Attr.IDBlacklistRegexp');
     if ($regexp && preg_match($regexp, $id)) {
         return false;
     }
     if (!$this->selector) {
         $id_accumulator->add($id);
     }
     // if no change was made to the ID, return the result
     // else, return the new id if stripping whitespace made it
     //     valid, or return false.
     return $id;
 }
开发者ID:spacequad,项目名称:glfusion,代码行数:63,代码来源:ID.php

示例9: validate

 /**
  * @param string $string
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return bool|string
  */
 public function validate($string, $config, $context)
 {
     $token = $context->get('CurrentToken', true);
     if (!$token || $token->name !== $this->tag) {
         return $this->withoutTag->validate($string, $config, $context);
     } else {
         return $this->withTag->validate($string, $config, $context);
     }
 }
开发者ID:beyondye,项目名称:ENPHP,代码行数:15,代码来源:Switch.php

示例10: filter

 /**
  * filter
  * 
  * @param HTMLPurifier_URI $uri
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return boolean
  */
 public function filter(&$uri, $config, $context)
 {
     $result = TRUE;
     $token = $context->get('CurrentToken', true);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' URI: ' . var_export($uri, TRUE) . ' ' . ' TOKEN: ' . var_export($token, TRUE));
     }
     if ($uri->host) {
         $result = $this->_checkExternalUrl($uri, $token);
     }
     return $result;
 }
开发者ID:bitExpert,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:20,代码来源:TransformURI.php

示例11: validate

 /**
  * @param string $uri
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return bool|string
  */
 public function validate($uri, $config, $context)
 {
     if ($config->get('URI.Disable')) {
         return false;
     }
     $uri = $this->parseCDATA($uri);
     // parse the URI
     $uri = $this->parser->parse($uri);
     if ($uri === false) {
         return false;
     }
     // add embedded flag to context for validators
     $context->register('EmbeddedURI', $this->embedsResource);
     $ok = false;
     do {
         // generic validation
         $result = $uri->validate($config, $context);
         if (!$result) {
             break;
         }
         // chained filtering
         $uri_def = $config->getDefinition('URI');
         $result = $uri_def->filter($uri, $config, $context);
         if (!$result) {
             break;
         }
         // scheme-specific validation
         $scheme_obj = $uri->getSchemeObj($config, $context);
         if (!$scheme_obj) {
             break;
         }
         if ($this->embedsResource && !$scheme_obj->browsable) {
             break;
         }
         $result = $scheme_obj->validate($uri, $config, $context);
         if (!$result) {
             break;
         }
         // Post chained filtering
         $result = $uri_def->postFilter($uri, $config, $context);
         if (!$result) {
             break;
         }
         // survived gauntlet
         $ok = true;
     } while (false);
     $context->destroy('EmbeddedURI');
     if (!$ok) {
         return false;
     }
     // back to string
     return $uri->toString();
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:59,代码来源:URI.php

示例12: test_formatMessage_tokenParameter

 public function test_formatMessage_tokenParameter()
 {
     $config = HTMLPurifier_Config::createDefault();
     $context = new HTMLPurifier_Context();
     $generator = new HTMLPurifier_Generator($config, $context);
     // replace with mock if this gets icky
     $context->register('Generator', $generator);
     $lang = new HTMLPurifier_Language($config, $context);
     $lang->_loaded = true;
     $lang->messages['LanguageTest: Element info'] = 'Element Token: $1.Name, $1.Serialized, $1.Compact, $1.Line';
     $lang->messages['LanguageTest: Data info'] = 'Data Token: $1.Data, $1.Serialized, $1.Compact, $1.Line';
     $this->assertIdentical($lang->formatMessage('LanguageTest: Element info', array(1 => new HTMLPurifier_Token_Start('a', array('href' => 'http://example.com'), 18))), 'Element Token: a, <a href="http://example.com">, <a>, 18');
     $this->assertIdentical($lang->formatMessage('LanguageTest: Data info', array(1 => new HTMLPurifier_Token_Text('data>', 23))), 'Data Token: data>, data&gt;, data&gt;, 23');
 }
开发者ID:youprofit,项目名称:casebox,代码行数:14,代码来源:LanguageTest.php

示例13: assertTransformation

 /**
  * Asserts that a transformation happens
  *
  * This assertion performs several tests on the transform:
  *
  * -# Transforms a start tag with only $name and no attributes
  * -# Transforms a start tag with $name and $attributes
  * -# Transform an end tag
  * -# Transform an empty tag with only $name and no attributes
  * -# Transform an empty tag with $name and $attributes
  *
  * In its current form, it assumes that start and empty tags would be
  * treated the same, and is really ensuring that the tag transform doesn't
  * do anything wonky to the tag type.
  *
  * @param $transformer      HTMLPurifier_TagTransform class to test
  * @param $name             Name of the original tag
  * @param $attributes       Attributes of the original tag
  * @param $expect_name      Name of output tag
  * @param $expect_attributes Attributes of output tag when $attributes
  *                          is included.
  * @param $expect_added_attributes Attributes of output tag when $attributes
  *                          are omitted.
  * @param $config_array     Configuration array for HTMLPurifier_Config
  * @param $context_array    Context array for HTMLPurifier_Context
  */
 protected function assertTransformation($transformer, $name, $attributes, $expect_name, $expect_attributes, $expect_added_attributes = array(), $config_array = array(), $context_array = array())
 {
     $config = HTMLPurifier_Config::createDefault();
     $config->loadArray($config_array);
     $context = new HTMLPurifier_Context();
     $context->loadArray($context_array);
     // start tag transform
     $this->assertIdentical(new HTMLPurifier_Token_Start($expect_name, $expect_added_attributes), $transformer->transform(new HTMLPurifier_Token_Start($name), $config, $context));
     // start tag transform with attributes
     $this->assertIdentical(new HTMLPurifier_Token_Start($expect_name, $expect_attributes), $transformer->transform(new HTMLPurifier_Token_Start($name, $attributes), $config, $context));
     // end tag transform
     $this->assertIdentical(new HTMLPurifier_Token_End($expect_name), $transformer->transform(new HTMLPurifier_Token_End($name), $config, $context));
     // empty tag transform
     $this->assertIdentical(new HTMLPurifier_Token_Empty($expect_name, $expect_added_attributes), $transformer->transform(new HTMLPurifier_Token_Empty($name), $config, $context));
     // empty tag transform with attributes
     $this->assertIdentical(new HTMLPurifier_Token_Empty($expect_name, $expect_attributes), $transformer->transform(new HTMLPurifier_Token_Empty($name, $attributes), $config, $context));
 }
开发者ID:youprofit,项目名称:casebox,代码行数:43,代码来源:TagTransformTest.php

示例14: purify

 public function purify($html, $config = null)
 {
     $config = $config ? HTMLPurifier_Config::create($config) : $this->config;
     $lexer = HTMLPurifier_Lexer::create($config);
     $context = new HTMLPurifier_Context();
     $this->generator = new HTMLPurifier_Generator($config, $context);
     $context->register('Generator', $this->generator);
     if ($config->get('Core.CollectErrors')) {
         $language_factory = HTMLPurifier_LanguageFactory::instance();
         $language = $language_factory->create($config, $context);
         $context->register('Locale', $language);
         $error_collector = new HTMLPurifier_ErrorCollector($context);
         $context->register('ErrorCollector', $error_collector);
     }
     $id_accumulator = HTMLPurifier_IDAccumulator::build($config, $context);
     $context->register('IDAccumulator', $id_accumulator);
     $html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context);
     $filter_flags = $config->getBatch('Filter');
     $custom_filters = $filter_flags['Custom'];
     unset($filter_flags['Custom']);
     $filters = array();
     foreach ($filter_flags as $filter => $flag) {
         if (!$flag) {
             continue;
         }
         if (strpos($filter, '.') !== false) {
             continue;
         }
         $class = "HTMLPurifier_Filter_{$filter}";
         $filters[] = new $class();
     }
     foreach ($custom_filters as $filter) {
         $filters[] = $filter;
     }
     $filters = array_merge($filters, $this->filters);
     for ($i = 0, $filter_size = count($filters); $i < $filter_size; $i++) {
         $html = $filters[$i]->preFilter($html, $config, $context);
     }
     $html = $this->generator->generateFromTokens($this->strategy->execute($lexer->tokenizeHTML($html, $config, $context), $config, $context));
     for ($i = $filter_size - 1; $i >= 0; $i--) {
         $html = $filters[$i]->postFilter($html, $config, $context);
     }
     $html = HTMLPurifier_Encoder::convertFromUTF8($html, $config, $context);
     $this->context =& $context;
     return $html;
 }
开发者ID:harrylongworth,项目名称:tv-bb,代码行数:46,代码来源:HTMLPurifier.standalone.php

示例15: test_loadArray

 function test_loadArray()
 {
     // references can be *really* wonky!
     $context_manual = new HTMLPurifier_Context();
     $context_load = new HTMLPurifier_Context();
     $var1 = 1;
     $var2 = 2;
     $context_manual->register('var1', $var1);
     $context_manual->register('var2', $var2);
     // you MUST set up the references when constructing the array,
     // otherwise the registered version will be a copy
     $array = array('var1' => &$var1, 'var2' => &$var2);
     $context_load->loadArray($array);
     $this->assertIdentical($context_manual, $context_load);
     $var1 = 10;
     $var2 = 20;
     $this->assertIdentical($context_manual, $context_load);
 }
开发者ID:radicaldesigns,项目名称:amp,代码行数:18,代码来源:ContextTest.php


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