2006-11-23 03:23:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/ChildDef/Required.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes the contents of blockquote when in strict and reformats for validation.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_ChildDef_StrictBlockquote
|
|
|
|
extends HTMLPurifier_ChildDef_Required
|
|
|
|
{
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $real_elements;
|
|
|
|
protected $fake_elements;
|
|
|
|
public $allow_empty = true;
|
|
|
|
public $type = 'strictblockquote';
|
|
|
|
protected $init = false;
|
|
|
|
public function validateChildren($tokens_of_children, $config, &$context) {
|
2006-11-23 03:23:35 +00:00
|
|
|
|
|
|
|
$def = $config->getHTMLDefinition();
|
|
|
|
if (!$this->init) {
|
|
|
|
// allow all inline elements
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->real_elements = $this->elements;
|
2007-02-04 22:08:51 +00:00
|
|
|
$this->fake_elements = $def->info_content_sets['Flow'];
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->fake_elements['#PCDATA'] = true;
|
2006-11-23 03:23:35 +00:00
|
|
|
$this->init = true;
|
|
|
|
}
|
|
|
|
|
2007-02-04 03:53:57 +00:00
|
|
|
// trick the parent class into thinking it allows more
|
|
|
|
$this->elements = $this->fake_elements;
|
2006-11-23 03:23:35 +00:00
|
|
|
$result = parent::validateChildren($tokens_of_children, $config, $context);
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->elements = $this->real_elements;
|
|
|
|
|
2006-11-23 03:23:35 +00:00
|
|
|
if ($result === false) return array();
|
|
|
|
if ($result === true) $result = $tokens_of_children;
|
|
|
|
|
|
|
|
$block_wrap_start = new HTMLPurifier_Token_Start($def->info_block_wrapper);
|
|
|
|
$block_wrap_end = new HTMLPurifier_Token_End( $def->info_block_wrapper);
|
|
|
|
$is_inline = false;
|
|
|
|
$depth = 0;
|
|
|
|
$ret = array();
|
|
|
|
|
|
|
|
// assuming that there are no comment tokens
|
|
|
|
foreach ($result as $i => $token) {
|
|
|
|
$token = $result[$i];
|
|
|
|
// ifs are nested for readability
|
|
|
|
if (!$is_inline) {
|
|
|
|
if (!$depth) {
|
2007-02-04 03:53:57 +00:00
|
|
|
if (
|
2007-06-18 19:53:46 +00:00
|
|
|
($token->type == 'text' && !$token->is_whitespace) ||
|
|
|
|
($token->type != 'text' && !isset($this->elements[$token->name]))
|
2007-02-04 03:53:57 +00:00
|
|
|
) {
|
2006-11-23 03:23:35 +00:00
|
|
|
$is_inline = true;
|
|
|
|
$ret[] = $block_wrap_start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!$depth) {
|
|
|
|
// starting tokens have been inline text / empty
|
|
|
|
if ($token->type == 'start' || $token->type == 'empty') {
|
2007-02-04 03:53:57 +00:00
|
|
|
if (isset($this->elements[$token->name])) {
|
2006-11-23 03:23:35 +00:00
|
|
|
// ended
|
|
|
|
$ret[] = $block_wrap_end;
|
|
|
|
$is_inline = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ret[] = $token;
|
|
|
|
if ($token->type == 'start') $depth++;
|
|
|
|
if ($token->type == 'end') $depth--;
|
|
|
|
}
|
|
|
|
if ($is_inline) $ret[] = $block_wrap_end;
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|