Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / ChildDef / StrictBlockquote.php
blob60dcbc4a15237f4bfe102f66577709195fae8dff
1 <?php
3 require_once 'HTMLPurifier/ChildDef/Required.php';
5 /**
6 * Takes the contents of blockquote when in strict and reformats for validation.
7 */
8 class HTMLPurifier_ChildDef_StrictBlockquote
9 extends HTMLPurifier_ChildDef_Required
11 var $real_elements;
12 var $fake_elements;
13 var $allow_empty = true;
14 var $type = 'strictblockquote';
15 var $init = false;
16 function validateChildren($tokens_of_children, $config, &$context) {
18 $def = $config->getHTMLDefinition();
19 if (!$this->init) {
20 // allow all inline elements
21 $this->real_elements = $this->elements;
22 $this->fake_elements = $def->info_content_sets['Flow'];
23 $this->fake_elements['#PCDATA'] = true;
24 $this->init = true;
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 $block_wrap_start = new HTMLPurifier_Token_Start($def->info_block_wrapper);
36 $block_wrap_end = new HTMLPurifier_Token_End( $def->info_block_wrapper);
37 $is_inline = false;
38 $depth = 0;
39 $ret = array();
41 // assuming that there are no comment tokens
42 foreach ($result as $i => $token) {
43 $token = $result[$i];
44 // ifs are nested for readability
45 if (!$is_inline) {
46 if (!$depth) {
47 if (
48 ($token->type == 'text' && !$token->is_whitespace) ||
49 ($token->type != 'text' && !isset($this->elements[$token->name]))
50 ) {
51 $is_inline = true;
52 $ret[] = $block_wrap_start;
55 } else {
56 if (!$depth) {
57 // starting tokens have been inline text / empty
58 if ($token->type == 'start' || $token->type == 'empty') {
59 if (isset($this->elements[$token->name])) {
60 // ended
61 $ret[] = $block_wrap_end;
62 $is_inline = false;
67 $ret[] = $token;
68 if ($token->type == 'start') $depth++;
69 if ($token->type == 'end') $depth--;
71 if ($is_inline) $ret[] = $block_wrap_end;
72 return $ret;