Prepended constants with C_ to avoid reserved words as per https://www.php.net/manual...
[htmlpurifier/darkodev.git] / library / HTMLPurifier / ChildDef / StrictBlockquote.php
blob3270a46e1bf9a060dc0d8c0f446e3fa06c74ce39
1 <?php
3 /**
4 * Takes the contents of blockquote when in strict and reformats for validation.
5 */
6 class HTMLPurifier_ChildDef_StrictBlockquote extends HTMLPurifier_ChildDef_Required
8 /**
9 * @type array
11 protected $real_elements;
13 /**
14 * @type array
16 protected $fake_elements;
18 /**
19 * @type bool
21 public $allow_empty = true;
23 /**
24 * @type string
26 public $type = 'strictblockquote';
28 /**
29 * @type bool
31 protected $init = false;
33 /**
34 * @param HTMLPurifier_Config $config
35 * @return array
36 * @note We don't want MakeWellFormed to auto-close inline elements since
37 * they might be allowed.
39 public function getAllowedElements($config)
41 $this->init($config);
42 return $this->fake_elements;
45 /**
46 * @param array $children
47 * @param HTMLPurifier_Config $config
48 * @param HTMLPurifier_Context $context
49 * @return array
51 public function validateChildren($children, $config, $context)
53 $this->init($config);
55 // trick the parent class into thinking it allows more
56 $this->elements = $this->fake_elements;
57 $result = parent::validateChildren($children, $config, $context);
58 $this->elements = $this->real_elements;
60 if ($result === false) {
61 return array();
63 if ($result === true) {
64 $result = $children;
67 $def = $config->getHTMLDefinition();
68 $block_wrap_name = $def->info_block_wrapper;
69 $block_wrap = false;
70 $ret = array();
72 foreach ($result as $node) {
73 if ($block_wrap === false) {
74 if (($node instanceof HTMLPurifier_Node_Text && !$node->is_whitespace) ||
75 ($node instanceof HTMLPurifier_Node_Element && !isset($this->elements[$node->name]))) {
76 $block_wrap = new HTMLPurifier_Node_Element($def->info_block_wrapper);
77 $ret[] = $block_wrap;
79 } else {
80 if ($node instanceof HTMLPurifier_Node_Element && isset($this->elements[$node->name])) {
81 $block_wrap = false;
85 if ($block_wrap) {
86 $block_wrap->children[] = $node;
87 } else {
88 $ret[] = $node;
91 return $ret;
94 /**
95 * @param HTMLPurifier_Config $config
97 private function init($config)
99 if (!$this->init) {
100 $def = $config->getHTMLDefinition();
101 // allow all inline elements
102 $this->real_elements = $this->elements;
103 $this->fake_elements = $def->info_content_sets['Flow'];
104 $this->fake_elements['#PCDATA'] = true;
105 $this->init = true;
110 // vim: et sw=4 sts=4