[1.3.0] Huge upgrade, (X)HTML Strict now supported
[htmlpurifier.git] / library / HTMLPurifier / ChildDef / StrictBlockquote.php
blob980acac3a4b5e4bc0869afff6a4bf6b2ab39c55a
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 * From XHTML 1.0 Transitional to Strict, there is a notable change where
9 */
10 class HTMLPurifier_ChildDef_StrictBlockquote
11 extends HTMLPurifier_ChildDef_Required
13 var $allow_empty = true;
14 var $type = 'strictblockquote';
15 var $init = false;
16 function HTMLPurifier_ChildDef_StrictBlockquote() {}
17 function validateChildren($tokens_of_children, $config, &$context) {
19 $def = $config->getHTMLDefinition();
20 if (!$this->init) {
21 // allow all inline elements
22 $this->elements = $def->info_flow_elements;
23 $this->elements['#PCDATA'] = true;
24 $this->init = true;
27 $result = parent::validateChildren($tokens_of_children, $config, $context);
28 if ($result === false) return array();
29 if ($result === true) $result = $tokens_of_children;
31 $block_wrap_start = new HTMLPurifier_Token_Start($def->info_block_wrapper);
32 $block_wrap_end = new HTMLPurifier_Token_End( $def->info_block_wrapper);
33 $is_inline = false;
34 $depth = 0;
35 $ret = array();
37 // assuming that there are no comment tokens
38 foreach ($result as $i => $token) {
39 $token = $result[$i];
40 // ifs are nested for readability
41 if (!$is_inline) {
42 if (!$depth) {
43 if (($token->type == 'text') ||
44 ($def->info[$token->name]->type == 'inline')) {
45 $is_inline = true;
46 $ret[] = $block_wrap_start;
49 } else {
50 if (!$depth) {
51 // starting tokens have been inline text / empty
52 if ($token->type == 'start' || $token->type == 'empty') {
53 if ($def->info[$token->name]->type == 'block') {
54 // ended
55 $ret[] = $block_wrap_end;
56 $is_inline = false;
61 $ret[] = $token;
62 if ($token->type == 'start') $depth++;
63 if ($token->type == 'end') $depth--;
65 if ($is_inline) $ret[] = $block_wrap_end;
66 return $ret;