]>
Commit | Line | Data |
---|---|---|
d4949327 NL |
1 | <?php\r |
2 | \r | |
3 | /**\r | |
4 | * Takes the contents of blockquote when in strict and reformats for validation.\r | |
5 | */\r | |
6 | class HTMLPurifier_ChildDef_StrictBlockquote extends HTMLPurifier_ChildDef_Required\r | |
7 | {\r | |
8 | /**\r | |
9 | * @type array\r | |
10 | */\r | |
11 | protected $real_elements;\r | |
12 | \r | |
13 | /**\r | |
14 | * @type array\r | |
15 | */\r | |
16 | protected $fake_elements;\r | |
17 | \r | |
18 | /**\r | |
19 | * @type bool\r | |
20 | */\r | |
21 | public $allow_empty = true;\r | |
22 | \r | |
23 | /**\r | |
24 | * @type string\r | |
25 | */\r | |
26 | public $type = 'strictblockquote';\r | |
27 | \r | |
28 | /**\r | |
29 | * @type bool\r | |
30 | */\r | |
31 | protected $init = false;\r | |
32 | \r | |
33 | /**\r | |
34 | * @param HTMLPurifier_Config $config\r | |
35 | * @return array\r | |
36 | * @note We don't want MakeWellFormed to auto-close inline elements since\r | |
37 | * they might be allowed.\r | |
38 | */\r | |
39 | public function getAllowedElements($config)\r | |
40 | {\r | |
41 | $this->init($config);\r | |
42 | return $this->fake_elements;\r | |
43 | }\r | |
44 | \r | |
45 | /**\r | |
46 | * @param array $children\r | |
47 | * @param HTMLPurifier_Config $config\r | |
48 | * @param HTMLPurifier_Context $context\r | |
49 | * @return array\r | |
50 | */\r | |
51 | public function validateChildren($children, $config, $context)\r | |
52 | {\r | |
53 | $this->init($config);\r | |
54 | \r | |
55 | // trick the parent class into thinking it allows more\r | |
56 | $this->elements = $this->fake_elements;\r | |
57 | $result = parent::validateChildren($children, $config, $context);\r | |
58 | $this->elements = $this->real_elements;\r | |
59 | \r | |
60 | if ($result === false) {\r | |
61 | return array();\r | |
62 | }\r | |
63 | if ($result === true) {\r | |
64 | $result = $children;\r | |
65 | }\r | |
66 | \r | |
67 | $def = $config->getHTMLDefinition();\r | |
68 | $block_wrap_name = $def->info_block_wrapper;\r | |
69 | $block_wrap = false;\r | |
70 | $ret = array();\r | |
71 | \r | |
72 | foreach ($result as $node) {\r | |
73 | if ($block_wrap === false) {\r | |
74 | if (($node instanceof HTMLPurifier_Node_Text && !$node->is_whitespace) ||\r | |
75 | ($node instanceof HTMLPurifier_Node_Element && !isset($this->elements[$node->name]))) {\r | |
76 | $block_wrap = new HTMLPurifier_Node_Element($def->info_block_wrapper);\r | |
77 | $ret[] = $block_wrap;\r | |
78 | }\r | |
79 | } else {\r | |
80 | if ($node instanceof HTMLPurifier_Node_Element && isset($this->elements[$node->name])) {\r | |
81 | $block_wrap = false;\r | |
82 | \r | |
83 | }\r | |
84 | }\r | |
85 | if ($block_wrap) {\r | |
86 | $block_wrap->children[] = $node;\r | |
87 | } else {\r | |
88 | $ret[] = $node;\r | |
89 | }\r | |
90 | }\r | |
91 | return $ret;\r | |
92 | }\r | |
93 | \r | |
94 | /**\r | |
95 | * @param HTMLPurifier_Config $config\r | |
96 | */\r | |
97 | private function init($config)\r | |
98 | {\r | |
99 | if (!$this->init) {\r | |
100 | $def = $config->getHTMLDefinition();\r | |
101 | // allow all inline elements\r | |
102 | $this->real_elements = $this->elements;\r | |
103 | $this->fake_elements = $def->info_content_sets['Flow'];\r | |
104 | $this->fake_elements['#PCDATA'] = true;\r | |
105 | $this->init = true;\r | |
106 | }\r | |
107 | }\r | |
108 | }\r | |
109 | \r | |
110 | // vim: et sw=4 sts=4\r |