aboutsummaryrefslogtreecommitdiffstats
path: root/library/HTMLPurifier/ChildDef/StrictBlockquote.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/HTMLPurifier/ChildDef/StrictBlockquote.php')
-rw-r--r--library/HTMLPurifier/ChildDef/StrictBlockquote.php96
1 files changed, 59 insertions, 37 deletions
diff --git a/library/HTMLPurifier/ChildDef/StrictBlockquote.php b/library/HTMLPurifier/ChildDef/StrictBlockquote.php
index dfae8a6e5..3270a46e1 100644
--- a/library/HTMLPurifier/ChildDef/StrictBlockquote.php
+++ b/library/HTMLPurifier/ChildDef/StrictBlockquote.php
@@ -5,75 +5,97 @@
*/
class HTMLPurifier_ChildDef_StrictBlockquote extends HTMLPurifier_ChildDef_Required
{
+ /**
+ * @type array
+ */
protected $real_elements;
+
+ /**
+ * @type array
+ */
protected $fake_elements;
+
+ /**
+ * @type bool
+ */
public $allow_empty = true;
+
+ /**
+ * @type string
+ */
public $type = 'strictblockquote';
+
+ /**
+ * @type bool
+ */
protected $init = false;
/**
+ * @param HTMLPurifier_Config $config
+ * @return array
* @note We don't want MakeWellFormed to auto-close inline elements since
* they might be allowed.
*/
- public function getAllowedElements($config) {
+ public function getAllowedElements($config)
+ {
$this->init($config);
return $this->fake_elements;
}
- public function validateChildren($tokens_of_children, $config, $context) {
-
+ /**
+ * @param array $children
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function validateChildren($children, $config, $context)
+ {
$this->init($config);
// trick the parent class into thinking it allows more
$this->elements = $this->fake_elements;
- $result = parent::validateChildren($tokens_of_children, $config, $context);
+ $result = parent::validateChildren($children, $config, $context);
$this->elements = $this->real_elements;
- if ($result === false) return array();
- if ($result === true) $result = $tokens_of_children;
+ if ($result === false) {
+ return array();
+ }
+ if ($result === true) {
+ $result = $children;
+ }
$def = $config->getHTMLDefinition();
- $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;
+ $block_wrap_name = $def->info_block_wrapper;
+ $block_wrap = false;
$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;
- }
+ foreach ($result as $node) {
+ if ($block_wrap === false) {
+ if (($node instanceof HTMLPurifier_Node_Text && !$node->is_whitespace) ||
+ ($node instanceof HTMLPurifier_Node_Element && !isset($this->elements[$node->name]))) {
+ $block_wrap = new HTMLPurifier_Node_Element($def->info_block_wrapper);
+ $ret[] = $block_wrap;
}
} 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;
- }
- }
+ if ($node instanceof HTMLPurifier_Node_Element && isset($this->elements[$node->name])) {
+ $block_wrap = false;
+
}
}
- $ret[] = $token;
- if ($token instanceof HTMLPurifier_Token_Start) $depth++;
- if ($token instanceof HTMLPurifier_Token_End) $depth--;
+ if ($block_wrap) {
+ $block_wrap->children[] = $node;
+ } else {
+ $ret[] = $node;
+ }
}
- if ($is_inline) $ret[] = $block_wrap_end;
return $ret;
}
- private function init($config) {
+ /**
+ * @param HTMLPurifier_Config $config
+ */
+ private function init($config)
+ {
if (!$this->init) {
$def = $config->getHTMLDefinition();
// allow all inline elements