2011-12-26 06:00:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Definition for list containers ul and ol.
|
2013-10-21 05:18:59 +00:00
|
|
|
*
|
|
|
|
* What does this do? The big thing is to handle ol/ul at the top
|
|
|
|
* level of list nodes, which should be handled specially by /folding/
|
|
|
|
* them into the previous list node. We generally shouldn't ever
|
|
|
|
* see other disallowed elements, because the autoclose behavior
|
|
|
|
* in MakeWellFormed handles it.
|
2011-12-26 06:00:34 +00:00
|
|
|
*/
|
|
|
|
class HTMLPurifier_ChildDef_List extends HTMLPurifier_ChildDef
|
|
|
|
{
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @type string
|
|
|
|
*/
|
2011-12-26 06:00:34 +00:00
|
|
|
public $type = 'list';
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @type array
|
|
|
|
*/
|
2011-12-26 06:00:34 +00:00
|
|
|
// lying a little bit, so that we can handle ul and ol ourselves
|
|
|
|
// XXX: This whole business with 'wrap' is all a bit unsatisfactory
|
|
|
|
public $elements = array('li' => true, 'ul' => true, 'ol' => true);
|
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
|
|
|
{
|
2011-12-26 06:00:34 +00:00
|
|
|
// Flag for subclasses
|
|
|
|
$this->whitespace = false;
|
|
|
|
|
|
|
|
// if there are no tokens, delete parent node
|
2013-10-21 05:18:59 +00:00
|
|
|
if (empty($children)) {
|
2013-07-16 11:56:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-12-26 06:00:34 +00:00
|
|
|
|
2016-03-27 05:41:54 +00:00
|
|
|
// if li is not allowed, delete parent node
|
|
|
|
if (!isset($config->getHTMLDefinition()->info['li'])) {
|
|
|
|
trigger_error("Cannot allow ul/ol without allowing li", E_USER_WARNING);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-26 06:00:34 +00:00
|
|
|
// the new set of children
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
// a little sanity check to make sure it's not ALL whitespace
|
|
|
|
$all_whitespace = true;
|
|
|
|
|
2017-06-01 13:32:25 +00:00
|
|
|
$current_li = new stdClass();
|
2011-12-26 06:00:34 +00:00
|
|
|
|
2013-10-21 05:18:59 +00:00
|
|
|
foreach ($children as $node) {
|
|
|
|
if (!empty($node->is_whitespace)) {
|
|
|
|
$result[] = $node;
|
2011-12-26 06:00:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$all_whitespace = false; // phew, we're not talking about whitespace
|
|
|
|
|
2013-10-21 05:18:59 +00:00
|
|
|
if ($node->name === 'li') {
|
|
|
|
// good
|
|
|
|
$current_li = $node;
|
|
|
|
$result[] = $node;
|
|
|
|
} else {
|
|
|
|
// we want to tuck this into the previous li
|
|
|
|
// Invariant: we expect the node to be ol/ul
|
|
|
|
// ToDo: Make this more robust in the case of not ol/ul
|
|
|
|
// by distinguishing between existing li and li created
|
|
|
|
// to handle non-list elements; non-list elements should
|
|
|
|
// not be appended to an existing li; only li created
|
|
|
|
// for non-list. This distinction is not currently made.
|
2017-06-01 13:32:25 +00:00
|
|
|
if (get_class($current_li) === "stdClass") {
|
2013-10-21 05:18:59 +00:00
|
|
|
$current_li = new HTMLPurifier_Node_Element('li');
|
|
|
|
$result[] = $current_li;
|
2011-12-26 06:00:34 +00:00
|
|
|
}
|
2013-10-21 05:18:59 +00:00
|
|
|
$current_li->children[] = $node;
|
|
|
|
$current_li->empty = false; // XXX fascinating! Check for this error elsewhere ToDo
|
2011-12-26 06:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-16 11:56:14 +00:00
|
|
|
if (empty($result)) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-26 06:00:34 +00:00
|
|
|
if ($all_whitespace) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: et sw=4 sts=4
|