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


PHP HTMLPurifier_Config::getHTMLDefinition方法代码示例

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


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

示例1: __construct

 /**
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  */
 public function __construct($config, $context)
 {
     $this->config = $config;
     $this->_scriptFix = $config->get('Output.CommentScriptContents');
     $this->_innerHTMLFix = $config->get('Output.FixInnerHTML');
     $this->_sortAttr = $config->get('Output.SortAttr');
     $this->_flashCompat = $config->get('Output.FlashCompat');
     $this->_def = $config->getHTMLDefinition();
     $this->_xhtml = $this->_def->doctype->xml;
 }
开发者ID:mayliupeng,项目名称:ciFramework,代码行数:14,代码来源:Generator.php

示例2: validateChildren

 /**
  * @param array $children
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return array
  */
 public function validateChildren($children, $config, $context)
 {
     // Flag for subclasses
     $this->whitespace = false;
     // if there are no tokens, delete parent node
     if (empty($children)) {
         return false;
     }
     // if li is not allowed, delete parent node
     if (!isset($config->getHTMLDefinition()->info['li'])) {
         trigger_error("Cannot allow ul/ol without allowing li", E_USER_WARNING);
         return false;
     }
     // the new set of children
     $result = array();
     // a little sanity check to make sure it's not ALL whitespace
     $all_whitespace = true;
     $current_li = false;
     foreach ($children as $node) {
         if (!empty($node->is_whitespace)) {
             $result[] = $node;
             continue;
         }
         $all_whitespace = false;
         // phew, we're not talking about whitespace
         if ($node->name === 'li') {
             // good
             $current_li = $node;
             $result[] = $node;
         } else {
             // we want to tuck this into the previous li
             // Invariant: we expect the node to be ol/ul
             // ToDo: Make this more robust in the case of not ol/ul
             // by distinguishing between existing li and li created
             // to handle non-list elements; non-list elements should
             // not be appended to an existing li; only li created
             // for non-list. This distinction is not currently made.
             if ($current_li === false) {
                 $current_li = new HTMLPurifier_Node_Element('li');
                 $result[] = $current_li;
             }
             $current_li->children[] = $node;
             $current_li->empty = false;
             // XXX fascinating! Check for this error elsewhere ToDo
         }
     }
     if (empty($result)) {
         return false;
     }
     if ($all_whitespace) {
         return false;
     }
     return $result;
 }
开发者ID:spacequad,项目名称:glfusion,代码行数:60,代码来源:List.php

示例3: render

 /**
  * @param HTMLPurifier_Config $config
  * @return string
  */
 public function render($config)
 {
     $ret = '';
     $this->config =& $config;
     $this->def = $config->getHTMLDefinition();
     $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
     $ret .= $this->renderDoctype();
     $ret .= $this->renderEnvironment();
     $ret .= $this->renderContentSets();
     $ret .= $this->renderInfo();
     $ret .= $this->end('div');
     return $ret;
 }
开发者ID:HaakonME,项目名称:porticoestate,代码行数:17,代码来源:HTMLDefinition.php

示例4: create

 /**
  * @param  string|array|HTMLPurifier_Config $config
  * @param  HTMLPurifier_ConfigSchema $schema
  * @return HTMLPurifier_Config
  */
 public static function create($config = null, HTMLPurifier_ConfigSchema $schema = null)
 {
     if (!$schema instanceof HTMLPurifier_ConfigSchema) {
         $schema = HTMLPurifier_ConfigSchema::makeFromSerial();
     }
     if ($config instanceof HTMLPurifier_Config) {
         $configObj = $config;
     } else {
         $configObj = new HTMLPurifier_Config($schema);
         $configObj->set('Core.Encoding', 'UTF-8');
         $configObj->set('HTML.Doctype', 'HTML 4.01 Transitional');
         if (is_string($config)) {
             $configObj->loadIni($config);
         } elseif (is_array($config)) {
             $configObj->loadArray($config);
         }
     }
     $def = $configObj->getHTMLDefinition(true);
     // this finalizes config
     HTMLPurifier_HTML5Definition::setup($def);
     return $configObj;
 }
开发者ID:xemlock,项目名称:htmlpurifier-html5,代码行数:27,代码来源:HTML5Config.php

示例5: execute

 /**
  * @param HTMLPurifier_Token[] $tokens
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return array|HTMLPurifier_Token[]
  */
 public function execute($tokens, $config, $context)
 {
     $definition = $config->getHTMLDefinition();
     $generator = new HTMLPurifier_Generator($config, $context);
     $result = array();
     $escape_invalid_tags = $config->get('Core.EscapeInvalidTags');
     $remove_invalid_img = $config->get('Core.RemoveInvalidImg');
     // currently only used to determine if comments should be kept
     $trusted = $config->get('HTML.Trusted');
     $comment_lookup = $config->get('HTML.AllowedComments');
     $comment_regexp = $config->get('HTML.AllowedCommentsRegexp');
     $check_comments = $comment_lookup !== array() || $comment_regexp !== null;
     $remove_script_contents = $config->get('Core.RemoveScriptContents');
     $hidden_elements = $config->get('Core.HiddenElements');
     // remove script contents compatibility
     if ($remove_script_contents === true) {
         $hidden_elements['script'] = true;
     } elseif ($remove_script_contents === false && isset($hidden_elements['script'])) {
         unset($hidden_elements['script']);
     }
     $attr_validator = new HTMLPurifier_AttrValidator();
     // removes tokens until it reaches a closing tag with its value
     $remove_until = false;
     // converts comments into text tokens when this is equal to a tag name
     $textify_comments = false;
     $token = false;
     $context->register('CurrentToken', $token);
     $e = false;
     if ($config->get('Core.CollectErrors')) {
         $e =& $context->get('ErrorCollector');
     }
     foreach ($tokens as $token) {
         if ($remove_until) {
             if (empty($token->is_tag) || $token->name !== $remove_until) {
                 continue;
             }
         }
         if (!empty($token->is_tag)) {
             // DEFINITION CALL
             // before any processing, try to transform the element
             if (isset($definition->info_tag_transform[$token->name])) {
                 $original_name = $token->name;
                 // there is a transformation for this tag
                 // DEFINITION CALL
                 $token = $definition->info_tag_transform[$token->name]->transform($token, $config, $context);
                 if ($e) {
                     $e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', $original_name);
                 }
             }
             if (isset($definition->info[$token->name])) {
                 // mostly everything's good, but
                 // we need to make sure required attributes are in order
                 if (($token instanceof HTMLPurifier_Token_Start || $token instanceof HTMLPurifier_Token_Empty) && $definition->info[$token->name]->required_attr && ($token->name != 'img' || $remove_invalid_img)) {
                     $attr_validator->validateToken($token, $config, $context);
                     $ok = true;
                     foreach ($definition->info[$token->name]->required_attr as $name) {
                         if (!isset($token->attr[$name])) {
                             $ok = false;
                             break;
                         }
                     }
                     if (!$ok) {
                         if ($e) {
                             $e->send(E_ERROR, 'Strategy_RemoveForeignElements: Missing required attribute', $name);
                         }
                         continue;
                     }
                     $token->armor['ValidateAttributes'] = true;
                 }
                 if (isset($hidden_elements[$token->name]) && $token instanceof HTMLPurifier_Token_Start) {
                     $textify_comments = $token->name;
                 } elseif ($token->name === $textify_comments && $token instanceof HTMLPurifier_Token_End) {
                     $textify_comments = false;
                 }
             } elseif ($escape_invalid_tags) {
                 // invalid tag, generate HTML representation and insert in
                 if ($e) {
                     $e->send(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text');
                 }
                 $token = new HTMLPurifier_Token_Text($generator->generateFromToken($token));
             } else {
                 // check if we need to destroy all of the tag's children
                 // CAN BE GENERICIZED
                 if (isset($hidden_elements[$token->name])) {
                     if ($token instanceof HTMLPurifier_Token_Start) {
                         $remove_until = $token->name;
                     } elseif ($token instanceof HTMLPurifier_Token_Empty) {
                         // do nothing: we're still looking
                     } else {
                         $remove_until = false;
                     }
                     if ($e) {
                         $e->send(E_ERROR, 'Strategy_RemoveForeignElements: Foreign meta element removed');
                     }
//.........这里部分代码省略.........
开发者ID:dingdong2310,项目名称:g5_theme,代码行数:101,代码来源:HTMLPurifier.standalone.php

示例6: validateToken

 /**
  * Validates the attributes of a token, mutating it as necessary.
  * that has valid tokens
  * @param HTMLPurifier_Token $token Token to validate.
  * @param HTMLPurifier_Config $config Instance of HTMLPurifier_Config
  * @param HTMLPurifier_Context $context Instance of HTMLPurifier_Context
  */
 public function validateToken($token, $config, $context)
 {
     $definition = $config->getHTMLDefinition();
     $e =& $context->get('ErrorCollector', true);
     // initialize IDAccumulator if necessary
     $ok =& $context->get('IDAccumulator', true);
     if (!$ok) {
         $id_accumulator = HTMLPurifier_IDAccumulator::build($config, $context);
         $context->register('IDAccumulator', $id_accumulator);
     }
     // initialize CurrentToken if necessary
     $current_token =& $context->get('CurrentToken', true);
     if (!$current_token) {
         $context->register('CurrentToken', $token);
     }
     if (!$token instanceof HTMLPurifier_Token_Start && !$token instanceof HTMLPurifier_Token_Empty) {
         return;
     }
     // create alias to global definition array, see also $defs
     // DEFINITION CALL
     $d_defs = $definition->info_global_attr;
     // don't update token until the very end, to ensure an atomic update
     $attr = $token->attr;
     // do global transformations (pre)
     // nothing currently utilizes this
     foreach ($definition->info_attr_transform_pre as $transform) {
         $attr = $transform->transform($o = $attr, $config, $context);
         if ($e) {
             if ($attr != $o) {
                 $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
             }
         }
     }
     // do local transformations only applicable to this element (pre)
     // ex. <p align="right"> to <p style="text-align:right;">
     foreach ($definition->info[$token->name]->attr_transform_pre as $transform) {
         $attr = $transform->transform($o = $attr, $config, $context);
         if ($e) {
             if ($attr != $o) {
                 $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
             }
         }
     }
     // create alias to this element's attribute definition array, see
     // also $d_defs (global attribute definition array)
     // DEFINITION CALL
     $defs = $definition->info[$token->name]->attr;
     $attr_key = false;
     $context->register('CurrentAttr', $attr_key);
     // iterate through all the attribute keypairs
     // Watch out for name collisions: $key has previously been used
     foreach ($attr as $attr_key => $value) {
         // call the definition
         if (isset($defs[$attr_key])) {
             // there is a local definition defined
             if ($defs[$attr_key] === false) {
                 // We've explicitly been told not to allow this element.
                 // This is usually when there's a global definition
                 // that must be overridden.
                 // Theoretically speaking, we could have a
                 // AttrDef_DenyAll, but this is faster!
                 $result = false;
             } else {
                 // validate according to the element's definition
                 $result = $defs[$attr_key]->validate($value, $config, $context);
             }
         } elseif (isset($d_defs[$attr_key])) {
             // there is a global definition defined, validate according
             // to the global definition
             $result = $d_defs[$attr_key]->validate($value, $config, $context);
         } else {
             // system never heard of the attribute? DELETE!
             $result = false;
         }
         // put the results into effect
         if ($result === false || $result === null) {
             // this is a generic error message that should replaced
             // with more specific ones when possible
             if ($e) {
                 $e->send(E_ERROR, 'AttrValidator: Attribute removed');
             }
             // remove the attribute
             unset($attr[$attr_key]);
         } elseif (is_string($result)) {
             // generally, if a substitution is happening, there
             // was some sort of implicit correction going on. We'll
             // delegate it to the attribute classes to say exactly what.
             // simple substitution
             $attr[$attr_key] = $result;
         } else {
             // nothing happens
         }
         // we'd also want slightly more complicated substitution
//.........这里部分代码省略.........
开发者ID:youprofit,项目名称:casebox,代码行数:101,代码来源:AttrValidator.php

示例7: checkNeeded

 /**
  * This function checks if the HTML environment
  * will work with the Injector: if p tags are not allowed, the
  * Auto-Paragraphing injector should not be enabled.
  * @param HTMLPurifier_Config $config
  * @return bool|string Boolean false if success, string of missing needed element/attribute if failure
  */
 public function checkNeeded($config)
 {
     $def = $config->getHTMLDefinition();
     foreach ($this->needed as $element => $attributes) {
         if (is_int($element)) {
             $element = $attributes;
         }
         if (!isset($def->info[$element])) {
             return $element;
         }
         if (!is_array($attributes)) {
             continue;
         }
         foreach ($attributes as $name) {
             if (!isset($def->info[$element]->attr[$name])) {
                 return "{$element}.{$name}";
             }
         }
     }
     return false;
 }
开发者ID:aslijiasheng,项目名称:ciFramework,代码行数:28,代码来源:Injector.php

示例8: init

 /**
  * @param HTMLPurifier_Config $config
  */
 private function init($config)
 {
     if (!$this->init) {
         $def = $config->getHTMLDefinition();
         // allow all inline elements
         $this->real_elements = $this->elements;
         $this->fake_elements = $def->info_content_sets['Flow'];
         $this->fake_elements['#PCDATA'] = true;
         $this->init = true;
     }
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:14,代码来源:StrictBlockquote.php

示例9: execute

 /**
  * @param HTMLPurifier_Token[] $tokens
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return HTMLPurifier_Token[]
  * @throws HTMLPurifier_Exception
  */
 public function execute($tokens, $config, $context)
 {
     $definition = $config->getHTMLDefinition();
     // local variables
     $generator = new HTMLPurifier_Generator($config, $context);
     $escape_invalid_tags = $config->get('Core.EscapeInvalidTags');
     // used for autoclose early abortion
     $global_parent_allowed_elements = $definition->info_parent_def->child->getAllowedElements($config);
     $e = $context->get('ErrorCollector', true);
     $i = false;
     // injector index
     list($zipper, $token) = HTMLPurifier_Zipper::fromArray($tokens);
     if ($token === NULL) {
         return array();
     }
     $reprocess = false;
     // whether or not to reprocess the same token
     $stack = array();
     // member variables
     $this->stack =& $stack;
     $this->tokens =& $tokens;
     $this->token =& $token;
     $this->zipper =& $zipper;
     $this->config = $config;
     $this->context = $context;
     // context variables
     $context->register('CurrentNesting', $stack);
     $context->register('InputZipper', $zipper);
     $context->register('CurrentToken', $token);
     // -- begin INJECTOR --
     $this->injectors = array();
     $injectors = $config->getBatch('AutoFormat');
     $def_injectors = $definition->info_injector;
     $custom_injectors = $injectors['Custom'];
     unset($injectors['Custom']);
     // special case
     foreach ($injectors as $injector => $b) {
         // XXX: Fix with a legitimate lookup table of enabled filters
         if (strpos($injector, '.') !== false) {
             continue;
         }
         $injector = "HTMLPurifier_Injector_{$injector}";
         if (!$b) {
             continue;
         }
         $this->injectors[] = new $injector();
     }
     foreach ($def_injectors as $injector) {
         // assumed to be objects
         $this->injectors[] = $injector;
     }
     foreach ($custom_injectors as $injector) {
         if (!$injector) {
             continue;
         }
         if (is_string($injector)) {
             $injector = "HTMLPurifier_Injector_{$injector}";
             $injector = new $injector();
         }
         $this->injectors[] = $injector;
     }
     // give the injectors references to the definition and context
     // variables for performance reasons
     foreach ($this->injectors as $ix => $injector) {
         $error = $injector->prepare($config, $context);
         if (!$error) {
             continue;
         }
         array_splice($this->injectors, $ix, 1);
         // rm the injector
         trigger_error("Cannot enable {$injector->name} injector because {$error} is not allowed", E_USER_WARNING);
     }
     // -- end INJECTOR --
     // a note on reprocessing:
     //      In order to reduce code duplication, whenever some code needs
     //      to make HTML changes in order to make things "correct", the
     //      new HTML gets sent through the purifier, regardless of its
     //      status. This means that if we add a start token, because it
     //      was totally necessary, we don't have to update nesting; we just
     //      punt ($reprocess = true; continue;) and it does that for us.
     // isset is in loop because $tokens size changes during loop exec
     for (;; $reprocess ? $reprocess = false : ($token = $zipper->next($token))) {
         // check for a rewind
         if (is_int($i)) {
             // possibility: disable rewinding if the current token has a
             // rewind set on it already. This would offer protection from
             // infinite loop, but might hinder some advanced rewinding.
             $rewind_offset = $this->injectors[$i]->getRewindOffset();
             if (is_int($rewind_offset)) {
                 for ($j = 0; $j < $rewind_offset; $j++) {
                     if (empty($zipper->front)) {
                         break;
                     }
//.........这里部分代码省略.........
开发者ID:aslijiasheng,项目名称:ciFramework,代码行数:101,代码来源:MakeWellFormed.php

示例10: __addHtmlDef

 /**
  * HTML定義を追加
  *
  * @param HTMLPurifier_Config $config HTMLPurifier_Config instance
  * @return void
  */
 private function __addHtmlDef(HTMLPurifier_Config $config)
 {
     if ($def = $config->getHTMLDefinition(true, true)) {
         // http://developers.whatwg.org/sections.html
         $def->addElement('article', 'Block', 'Flow', 'Common');
         $def->addElement('section', 'Block', 'Flow', 'Common');
         $def->addElement('nav', 'Block', 'Flow', 'Common');
         $def->addElement('aside', 'Block', 'Flow', 'Common');
         $def->addElement('hgroup', 'Block', 'Required: h1 | h2 | h3 | h4 | h5 | h6', 'Common');
         $def->addElement('header', 'Block', 'Flow', 'Common');
         $def->addElement('footer', 'Block', 'Flow', 'Common');
         // http://developers.whatwg.org/grouping-content.html
         $def->addElement('figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common');
         $def->addElement('figcaption', 'Inline', 'Flow', 'Common');
         // http://developers.whatwg.org/the-video-element.html#the-video-element
         $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array('src' => 'URI', 'type' => 'Text', 'width' => 'Length', 'height' => 'Length', 'poster' => 'URI', 'preload' => 'Enum#auto,metadata,none', 'controls' => 'Bool'));
         $def->addElement('source', 'Block', 'Flow', 'Common', array('src' => 'URI', 'type' => 'Text'));
         // http://developers.whatwg.org/text-level-semantics.html
         $def->addElement('s', 'Inline', 'Inline', 'Common');
         $def->addElement('mark', 'Inline', 'Inline', 'Common');
         $def->addElement('wbr', 'Inline', 'Empty', 'Core');
         $def->addElement('ruby', 'Block', 'Flow', 'Common');
         $def->addElement('rt', 'Block', 'Flow', 'Common');
         $def->addElement('rp', 'Block', 'Flow', 'Common');
         // NetCommonsで許可するタグ、属性を追加
         $def->addElement('embed', 'Block', 'Flow', 'Common');
         $def->addElement('noembed', 'Block', 'Flow', 'Common');
         $def->addAttribute('hr', 'color', 'Text');
         $def->addAttribute('tbody', 'bgcolor', 'Text');
         $def->addAttribute('tbody', 'char', 'Text');
         $def->addAttribute('tr', 'colspan', 'Text');
         $def->addAttribute('tr', 'rowspan', 'Text');
         $def->addAttribute('td', 'char', 'Text');
         $def->addAttribute('td', 'axis', 'Text');
         $def->addAttribute('td', 'headers', 'Text');
         $def->addAttribute('th', 'char', 'Text');
         $def->addAttribute('th', 'axis', 'Text');
         $def->addAttribute('th', 'headers', 'Text');
         $def->addAttribute('caption', 'valign', 'Text');
         $def->addAttribute('pre', 'cols', 'Text');
         $def->addAttribute('pre', 'wrap', 'Text');
         $def->addAttribute('object', 'border', 'Text');
         $def->addAttribute('object', 'code', 'Text');
         $def->addAttribute('object', 'usemap', 'Text');
         $def->addAttribute('object', 'align', 'Text');
         $def->addAttribute('object', 'hspace', 'Text');
         $def->addAttribute('object', 'vspace', 'Text');
         $def->addAttribute('iframe', 'hspace', 'Text');
         $def->addAttribute('iframe', 'vspace', 'Text');
         $def->addAttribute('iframe', 'allowfullscreen', 'Bool');
         $def->addAttribute('iframe', 'allowtransparency', 'Bool');
         $def->addAttribute('iframe', 'border', 'Text');
         $def->addAttribute('iframe', 'bordercolor', 'Text');
         $embedAttributes = array('src', 'height', 'width', 'hspace', 'vspace', 'units', 'border', 'frameborder', 'play', 'loop', 'quality', 'pluginspage', 'type', 'allowscriptaccess', 'allowfullscreen', 'flashvars');
         foreach ($embedAttributes as $attribute) {
             $def->addAttribute('embed', $attribute, 'Text');
         }
         // 全要素で使用する属性を設定
         $def->addElement('*', 'Block', 'Flow', 'Common');
         $def->info_global_attr = array('class' => true, 'id' => true, 'title' => true, 'cite' => true, 'background' => true, 'style' => true, 'align' => true, 'dir' => true, 'lang' => true, 'language' => true);
         if ($def->manager) {
             $def->manager->addModule('Ruby');
         }
     }
 }
开发者ID:NetCommons3,项目名称:Wysiwyg,代码行数:71,代码来源:PurifiableBehavior.php


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