Fix two minor bugs, updating Phorum and removing unused $dir variable.
[htmlpurifier/darkodev.git] / library / HTMLPurifier / ChildDef / StrictBlockquote.php
blobdfae8a6e5e1d28f81b7484bcf81d941e4bf6dfab
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 protected $real_elements;
9 protected $fake_elements;
10 public $allow_empty = true;
11 public $type = 'strictblockquote';
12 protected $init = false;
14 /**
15 * @note We don't want MakeWellFormed to auto-close inline elements since
16 * they might be allowed.
18 public function getAllowedElements($config) {
19 $this->init($config);
20 return $this->fake_elements;
23 public function validateChildren($tokens_of_children, $config, $context) {
25 $this->init($config);
27 // trick the parent class into thinking it allows more
28 $this->elements = $this->fake_elements;
29 $result = parent::validateChildren($tokens_of_children, $config, $context);
30 $this->elements = $this->real_elements;
32 if ($result === false) return array();
33 if ($result === true) $result = $tokens_of_children;
35 $def = $config->getHTMLDefinition();
36 $block_wrap_start = new HTMLPurifier_Token_Start($def->info_block_wrapper);
37 $block_wrap_end = new HTMLPurifier_Token_End( $def->info_block_wrapper);
38 $is_inline = false;
39 $depth = 0;
40 $ret = array();
42 // assuming that there are no comment tokens
43 foreach ($result as $i => $token) {
44 $token = $result[$i];
45 // ifs are nested for readability
46 if (!$is_inline) {
47 if (!$depth) {
48 if (
49 ($token instanceof HTMLPurifier_Token_Text && !$token->is_whitespace) ||
50 (!$token instanceof HTMLPurifier_Token_Text && !isset($this->elements[$token->name]))
51 ) {
52 $is_inline = true;
53 $ret[] = $block_wrap_start;
56 } else {
57 if (!$depth) {
58 // starting tokens have been inline text / empty
59 if ($token instanceof HTMLPurifier_Token_Start || $token instanceof HTMLPurifier_Token_Empty) {
60 if (isset($this->elements[$token->name])) {
61 // ended
62 $ret[] = $block_wrap_end;
63 $is_inline = false;
68 $ret[] = $token;
69 if ($token instanceof HTMLPurifier_Token_Start) $depth++;
70 if ($token instanceof HTMLPurifier_Token_End) $depth--;
72 if ($is_inline) $ret[] = $block_wrap_end;
73 return $ret;
76 private function init($config) {
77 if (!$this->init) {
78 $def = $config->getHTMLDefinition();
79 // allow all inline elements
80 $this->real_elements = $this->elements;
81 $this->fake_elements = $def->info_content_sets['Flow'];
82 $this->fake_elements['#PCDATA'] = true;
83 $this->init = true;
88 // vim: et sw=4 sts=4