2006-08-29 02:01:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates shorthand CSS property list-style.
|
2007-01-15 00:48:54 +00:00
|
|
|
* @warning Does not support url tokens that have internal spaces.
|
2006-08-29 02:01:58 +00:00
|
|
|
*/
|
2007-02-14 20:38:51 +00:00
|
|
|
class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
|
2006-08-29 02:01:58 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-29 02:01:58 +00:00
|
|
|
/**
|
2013-07-16 11:56:14 +00:00
|
|
|
* Local copy of validators.
|
|
|
|
* @type HTMLPurifier_AttrDef[]
|
2007-02-14 20:38:51 +00:00
|
|
|
* @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
|
2006-08-29 02:01:58 +00:00
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $info;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
*/
|
|
|
|
public function __construct($config)
|
|
|
|
{
|
2006-08-31 20:33:07 +00:00
|
|
|
$def = $config->getCSSDefinition();
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['list-style-type'] = $def->info['list-style-type'];
|
2006-08-29 02:01:58 +00:00
|
|
|
$this->info['list-style-position'] = $def->info['list-style-position'];
|
2007-01-14 16:24:02 +00:00
|
|
|
$this->info['list-style-image'] = $def->info['list-style-image'];
|
2006-08-29 02:01:58 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @param string $string
|
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
* @param HTMLPurifier_Context $context
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
|
|
|
public function validate($string, $config, $context)
|
|
|
|
{
|
2006-08-29 02:01:58 +00:00
|
|
|
// regular pre-processing
|
|
|
|
$string = $this->parseCDATA($string);
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($string === '') {
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-15 00:48:54 +00:00
|
|
|
// assumes URI doesn't have spaces in it
|
2006-08-29 02:01:58 +00:00
|
|
|
$bits = explode(' ', strtolower($string)); // bits to process
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-15 00:48:54 +00:00
|
|
|
$caught = array();
|
2013-07-16 11:56:14 +00:00
|
|
|
$caught['type'] = false;
|
2007-01-15 00:48:54 +00:00
|
|
|
$caught['position'] = false;
|
2013-07-16 11:56:14 +00:00
|
|
|
$caught['image'] = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-15 00:48:54 +00:00
|
|
|
$i = 0; // number of catches
|
2007-01-15 01:14:24 +00:00
|
|
|
$none = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-29 02:01:58 +00:00
|
|
|
foreach ($bits as $bit) {
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($i >= 3) {
|
|
|
|
return;
|
|
|
|
} // optimization bit
|
|
|
|
if ($bit === '') {
|
|
|
|
continue;
|
|
|
|
}
|
2007-01-15 00:48:54 +00:00
|
|
|
foreach ($caught as $key => $status) {
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($status !== false) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-01-15 01:14:24 +00:00
|
|
|
$r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($r === false) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-01-15 01:14:24 +00:00
|
|
|
if ($r === 'none') {
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($none) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
$none = true;
|
|
|
|
}
|
|
|
|
if ($key == 'image') {
|
|
|
|
continue;
|
|
|
|
}
|
2007-01-15 01:14:24 +00:00
|
|
|
}
|
2007-01-15 00:48:54 +00:00
|
|
|
$caught[$key] = $r;
|
|
|
|
$i++;
|
2007-01-20 02:21:43 +00:00
|
|
|
break;
|
2007-01-14 16:24:02 +00:00
|
|
|
}
|
2006-08-29 02:01:58 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
if (!$i) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-15 00:48:54 +00:00
|
|
|
$ret = array();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-15 00:48:54 +00:00
|
|
|
// construct type
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($caught['type']) {
|
|
|
|
$ret[] = $caught['type'];
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-15 00:48:54 +00:00
|
|
|
// construct image
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($caught['image']) {
|
|
|
|
$ret[] = $caught['image'];
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-15 00:48:54 +00:00
|
|
|
// construct position
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($caught['position']) {
|
|
|
|
$ret[] = $caught['position'];
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
if (empty($ret)) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-01-15 00:48:54 +00:00
|
|
|
return implode(' ', $ret);
|
2006-08-29 02:01:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|