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
|
|
|
{
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @type array
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $real_elements;
|
2013-07-16 11:56:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type array
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $fake_elements;
|
2013-07-16 11:56:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type bool
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public $allow_empty = true;
|
2013-07-16 11:56:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type string
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public $type = 'strictblockquote';
|
2013-07-16 11:56:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type bool
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $init = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-08-02 00:52:06 +00:00
|
|
|
/**
|
2013-07-16 11:56:14 +00:00
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
* @return array
|
2008-08-02 00:52:06 +00:00
|
|
|
* @note We don't want MakeWellFormed to auto-close inline elements since
|
|
|
|
* they might be allowed.
|
|
|
|
*/
|
2013-07-16 11:56:14 +00:00
|
|
|
public function getAllowedElements($config)
|
|
|
|
{
|
2008-08-02 00:52:06 +00:00
|
|
|
$this->init($config);
|
|
|
|
return $this->fake_elements;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
2013-10-21 05:18:59 +00:00
|
|
|
* @param array $children
|
2013-07-16 11:56:14 +00:00
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
* @param HTMLPurifier_Context $context
|
|
|
|
* @return array
|
|
|
|
*/
|
2013-10-21 05:18:59 +00:00
|
|
|
public function validateChildren($children, $config, $context)
|
2013-07-16 11:56:14 +00:00
|
|
|
{
|
2008-08-02 00:52:06 +00:00
|
|
|
$this->init($config);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-04 03:53:57 +00:00
|
|
|
// trick the parent class into thinking it allows more
|
|
|
|
$this->elements = $this->fake_elements;
|
2013-10-21 05:18:59 +00:00
|
|
|
$result = parent::validateChildren($children, $config, $context);
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->elements = $this->real_elements;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($result === false) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
if ($result === true) {
|
2013-10-21 05:18:59 +00:00
|
|
|
$result = $children;
|
2013-07-16 11:56:14 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-08-02 00:52:06 +00:00
|
|
|
$def = $config->getHTMLDefinition();
|
2013-10-21 05:18:59 +00:00
|
|
|
$block_wrap_name = $def->info_block_wrapper;
|
|
|
|
$block_wrap = false;
|
2006-11-23 03:23:35 +00:00
|
|
|
$ret = array();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-10-21 05:18:59 +00:00
|
|
|
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;
|
2006-11-23 03:23:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-10-21 05:18:59 +00:00
|
|
|
if ($node instanceof HTMLPurifier_Node_Element && isset($this->elements[$node->name])) {
|
|
|
|
$block_wrap = false;
|
|
|
|
|
2006-11-23 03:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-21 05:18:59 +00:00
|
|
|
if ($block_wrap) {
|
|
|
|
$block_wrap->children[] = $node;
|
|
|
|
} else {
|
|
|
|
$ret[] = $node;
|
2013-07-16 11:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-23 03:23:35 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
*/
|
|
|
|
private function init($config)
|
|
|
|
{
|
2008-08-02 00:52:06 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|