File indexing completed on 2024-12-22 05:36:19
0001 <?php 0002 0003 /** 0004 * Takes the contents of blockquote when in strict and reformats for validation. 0005 */ 0006 class HTMLPurifier_ChildDef_StrictBlockquote extends HTMLPurifier_ChildDef_Required 0007 { 0008 /** 0009 * @type array 0010 */ 0011 protected $real_elements; 0012 0013 /** 0014 * @type array 0015 */ 0016 protected $fake_elements; 0017 0018 /** 0019 * @type bool 0020 */ 0021 public $allow_empty = true; 0022 0023 /** 0024 * @type string 0025 */ 0026 public $type = 'strictblockquote'; 0027 0028 /** 0029 * @type bool 0030 */ 0031 protected $init = false; 0032 0033 /** 0034 * @param HTMLPurifier_Config $config 0035 * @return array 0036 * @note We don't want MakeWellFormed to auto-close inline elements since 0037 * they might be allowed. 0038 */ 0039 public function getAllowedElements($config) 0040 { 0041 $this->init($config); 0042 return $this->fake_elements; 0043 } 0044 0045 /** 0046 * @param array $children 0047 * @param HTMLPurifier_Config $config 0048 * @param HTMLPurifier_Context $context 0049 * @return array 0050 */ 0051 public function validateChildren($children, $config, $context) 0052 { 0053 $this->init($config); 0054 0055 // trick the parent class into thinking it allows more 0056 $this->elements = $this->fake_elements; 0057 $result = parent::validateChildren($children, $config, $context); 0058 $this->elements = $this->real_elements; 0059 0060 if ($result === false) { 0061 return array(); 0062 } 0063 if ($result === true) { 0064 $result = $children; 0065 } 0066 0067 $def = $config->getHTMLDefinition(); 0068 $block_wrap_name = $def->info_block_wrapper; 0069 $block_wrap = false; 0070 $ret = array(); 0071 0072 foreach ($result as $node) { 0073 if ($block_wrap === false) { 0074 if (($node instanceof HTMLPurifier_Node_Text && !$node->is_whitespace) || 0075 ($node instanceof HTMLPurifier_Node_Element && !isset($this->elements[$node->name]))) { 0076 $block_wrap = new HTMLPurifier_Node_Element($def->info_block_wrapper); 0077 $ret[] = $block_wrap; 0078 } 0079 } else { 0080 if ($node instanceof HTMLPurifier_Node_Element && isset($this->elements[$node->name])) { 0081 $block_wrap = false; 0082 0083 } 0084 } 0085 if ($block_wrap) { 0086 $block_wrap->children[] = $node; 0087 } else { 0088 $ret[] = $node; 0089 } 0090 } 0091 return $ret; 0092 } 0093 0094 /** 0095 * @param HTMLPurifier_Config $config 0096 */ 0097 private function init($config) 0098 { 0099 if (!$this->init) { 0100 $def = $config->getHTMLDefinition(); 0101 // allow all inline elements 0102 $this->real_elements = $this->elements; 0103 $this->fake_elements = $def->info_content_sets['Flow']; 0104 $this->fake_elements['#PCDATA'] = true; 0105 $this->init = true; 0106 } 0107 } 0108 } 0109 0110 // vim: et sw=4 sts=4