2006-11-23 03:23:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes the contents of blockquote when in strict and reformats for validation.
|
|
|
|
*/
|
2008-01-27 00:06:10 +00:00
|
|
|
class HTMLPurifier_ChildDef_StrictBlockquote extends HTMLPurifier_ChildDef_Required
|
2006-11-23 03:23:35 +00:00
|
|
|
{
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $real_elements;
|
|
|
|
protected $fake_elements;
|
|
|
|
public $allow_empty = true;
|
|
|
|
public $type = 'strictblockquote';
|
|
|
|
protected $init = false;
|
2008-08-02 00:52:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @note We don't want MakeWellFormed to auto-close inline elements since
|
|
|
|
* they might be allowed.
|
|
|
|
*/
|
|
|
|
public function getNonAutoCloseElements($config) {
|
|
|
|
$this->init($config);
|
|
|
|
return $this->fake_elements;
|
|
|
|
}
|
|
|
|
|
2008-01-05 00:10:43 +00:00
|
|
|
public function validateChildren($tokens_of_children, $config, $context) {
|
2006-11-23 03:23:35 +00:00
|
|
|
|
2008-08-02 00:52:06 +00:00
|
|
|
$this->init($config);
|
2006-11-23 03:23:35 +00:00
|
|
|
|
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;
|
|
|
|
|
2008-08-02 00:52:06 +00:00
|
|
|
$def = $config->getHTMLDefinition();
|
2006-11-23 03:23:35 +00:00
|
|
|
$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 (
|
2008-01-19 20:23:01 +00:00
|
|
|
($token instanceof HTMLPurifier_Token_Text && !$token->is_whitespace) ||
|
|
|
|
(!$token instanceof HTMLPurifier_Token_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
|
2008-01-19 20:23:01 +00:00
|
|
|
if ($token instanceof HTMLPurifier_Token_Start || $token instanceof HTMLPurifier_Token_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;
|
2008-01-19 20:23:01 +00:00
|
|
|
if ($token instanceof HTMLPurifier_Token_Start) $depth++;
|
|
|
|
if ($token instanceof HTMLPurifier_Token_End) $depth--;
|
2006-11-23 03:23:35 +00:00
|
|
|
}
|
|
|
|
if ($is_inline) $ret[] = $block_wrap_end;
|
|
|
|
return $ret;
|
|
|
|
}
|
2008-08-02 00:52:06 +00:00
|
|
|
|
|
|
|
private function init($config) {
|
|
|
|
if (!$this->init) {
|
|
|
|
$def = $config->getHTMLDefinition();
|
|
|
|
// allow all inline elements
|
|
|
|
$this->real_elements = $this->elements;
|
|
|
|
$this->fake_elements = $def->info_content_sets['Flow'];
|
|
|
|
$this->fake_elements['#PCDATA'] = true;
|
|
|
|
$this->init = true;
|
|
|
|
}
|
|
|
|
}
|
2006-11-23 03:23:35 +00:00
|
|
|
}
|
|
|
|
|