2006-11-22 18:55:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Definition that allows a set of elements, and allows no children.
|
|
|
|
* @note This is a hack to reuse code from HTMLPurifier_ChildDef_Required,
|
|
|
|
* really, one shouldn't inherit from the other. Only altered behavior
|
|
|
|
* is to overload a returned false with an array. Thus, it will never
|
|
|
|
* return false.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_ChildDef_Optional extends HTMLPurifier_ChildDef_Required
|
|
|
|
{
|
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 = 'optional';
|
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
|
|
|
{
|
2013-10-21 05:18:59 +00:00
|
|
|
$result = parent::validateChildren($children, $config, $context);
|
|
|
|
// we assume that $children is not modified
|
2007-10-02 01:19:46 +00:00
|
|
|
if ($result === false) {
|
2013-10-21 05:18:59 +00:00
|
|
|
if (empty($children)) {
|
2013-07-16 11:56:14 +00:00
|
|
|
return true;
|
|
|
|
} elseif ($this->whitespace) {
|
2013-10-21 05:18:59 +00:00
|
|
|
return $children;
|
2013-07-16 11:56:14 +00:00
|
|
|
} else {
|
|
|
|
return array();
|
|
|
|
}
|
2007-10-02 01:19:46 +00:00
|
|
|
}
|
2006-11-22 18:55:15 +00:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|