PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / library / HTMLPurifier / ChildDef / StrictBlockquote.php
blob89831a7191ea68abc27501fb7ad403c98c8774df
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 $tokens_of_children
47 * @param HTMLPurifier_Config $config
48 * @param HTMLPurifier_Context $context
49 * @return array
51 public function validateChildren($tokens_of_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($tokens_of_children, $config, $context);
58 $this->elements = $this->real_elements;
60 if ($result === false) {
61 return array();
63 if ($result === true) {
64 $result = $tokens_of_children;
67 $def = $config->getHTMLDefinition();
68 $block_wrap_start = new HTMLPurifier_Token_Start($def->info_block_wrapper);
69 $block_wrap_end = new HTMLPurifier_Token_End($def->info_block_wrapper);
70 $is_inline = false;
71 $depth = 0;
72 $ret = array();
74 // assuming that there are no comment tokens
75 foreach ($result as $i => $token) {
76 $token = $result[$i];
77 // ifs are nested for readability
78 if (!$is_inline) {
79 if (!$depth) {
80 if (($token instanceof HTMLPurifier_Token_Text && !$token->is_whitespace) ||
81 (!$token instanceof HTMLPurifier_Token_Text && !isset($this->elements[$token->name]))) {
82 $is_inline = true;
83 $ret[] = $block_wrap_start;
86 } else {
87 if (!$depth) {
88 // starting tokens have been inline text / empty
89 if ($token instanceof HTMLPurifier_Token_Start || $token instanceof HTMLPurifier_Token_Empty) {
90 if (isset($this->elements[$token->name])) {
91 // ended
92 $ret[] = $block_wrap_end;
93 $is_inline = false;
98 $ret[] = $token;
99 if ($token instanceof HTMLPurifier_Token_Start) {
100 $depth++;
102 if ($token instanceof HTMLPurifier_Token_End) {
103 $depth--;
106 if ($is_inline) {
107 $ret[] = $block_wrap_end;
109 return $ret;
113 * @param HTMLPurifier_Config $config
115 private function init($config)
117 if (!$this->init) {
118 $def = $config->getHTMLDefinition();
119 // allow all inline elements
120 $this->real_elements = $this->elements;
121 $this->fake_elements = $def->info_content_sets['Flow'];
122 $this->fake_elements['#PCDATA'] = true;
123 $this->init = true;
128 // vim: et sw=4 sts=4