mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-14 09:18:41 +00:00
522c8ed7c2
- Add FSTools:globr() - require_once removed from all files - HTMLPurifier.autoload.php added to register autoload handler - Removed redundant chdir in maintenance script - Modified standalone to use HTMLPurifier.includes.php for including stuff - Added maintenance script remove-require-once.php which we used once and should never use again git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1516 48356398-32a2-884e-a903-53898d9a118a
73 lines
2.7 KiB
PHP
73 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Takes the contents of blockquote when in strict and reformats for validation.
|
|
*/
|
|
class HTMLPurifier_ChildDef_StrictBlockquote extends HTMLPurifier_ChildDef_Required
|
|
{
|
|
protected $real_elements;
|
|
protected $fake_elements;
|
|
public $allow_empty = true;
|
|
public $type = 'strictblockquote';
|
|
protected $init = false;
|
|
public function validateChildren($tokens_of_children, $config, $context) {
|
|
|
|
$def = $config->getHTMLDefinition();
|
|
if (!$this->init) {
|
|
// 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;
|
|
}
|
|
|
|
// trick the parent class into thinking it allows more
|
|
$this->elements = $this->fake_elements;
|
|
$result = parent::validateChildren($tokens_of_children, $config, $context);
|
|
$this->elements = $this->real_elements;
|
|
|
|
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) {
|
|
if (
|
|
($token instanceof HTMLPurifier_Token_Text && !$token->is_whitespace) ||
|
|
(!$token instanceof HTMLPurifier_Token_Text && !isset($this->elements[$token->name]))
|
|
) {
|
|
$is_inline = true;
|
|
$ret[] = $block_wrap_start;
|
|
}
|
|
}
|
|
} else {
|
|
if (!$depth) {
|
|
// starting tokens have been inline text / empty
|
|
if ($token instanceof HTMLPurifier_Token_Start || $token instanceof HTMLPurifier_Token_Empty) {
|
|
if (isset($this->elements[$token->name])) {
|
|
// ended
|
|
$ret[] = $block_wrap_end;
|
|
$is_inline = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$ret[] = $token;
|
|
if ($token instanceof HTMLPurifier_Token_Start) $depth++;
|
|
if ($token instanceof HTMLPurifier_Token_End) $depth--;
|
|
}
|
|
if ($is_inline) $ret[] = $block_wrap_end;
|
|
return $ret;
|
|
}
|
|
}
|
|
|