2006-08-29 02:01:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/AttrDef.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
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Local copy of component validators.
|
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
|
|
|
*/
|
|
|
|
var $info;
|
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
function HTMLPurifier_AttrDef_CSS_ListStyle($config) {
|
2006-08-31 20:33:07 +00:00
|
|
|
$def = $config->getCSSDefinition();
|
2006-08-29 02:01:58 +00:00
|
|
|
$this->info['list-style-type'] = $def->info['list-style-type'];
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
function validate($string, $config, &$context) {
|
|
|
|
|
|
|
|
// regular pre-processing
|
|
|
|
$string = $this->parseCDATA($string);
|
|
|
|
if ($string === '') return false;
|
|
|
|
|
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
|
|
|
|
|
2007-01-15 00:48:54 +00:00
|
|
|
$caught = array();
|
|
|
|
$caught['type'] = false;
|
|
|
|
$caught['position'] = false;
|
|
|
|
$caught['image'] = false;
|
2006-08-29 02:01:58 +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;
|
2006-08-29 02:01:58 +00:00
|
|
|
|
|
|
|
foreach ($bits as $bit) {
|
2007-01-15 00:48:54 +00:00
|
|
|
if ($i >= 3) return; // optimization bit
|
2006-08-29 02:01:58 +00:00
|
|
|
if ($bit === '') continue;
|
2007-01-15 00:48:54 +00:00
|
|
|
foreach ($caught as $key => $status) {
|
|
|
|
if ($status !== false) continue;
|
2007-01-15 01:14:24 +00:00
|
|
|
$r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
|
2007-01-15 00:48:54 +00:00
|
|
|
if ($r === false) continue;
|
2007-01-15 01:14:24 +00:00
|
|
|
if ($r === 'none') {
|
|
|
|
if ($none) continue;
|
|
|
|
else $none = true;
|
|
|
|
if ($key == 'image') continue;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2007-01-15 00:48:54 +00:00
|
|
|
if (!$i) return false;
|
|
|
|
|
|
|
|
$ret = array();
|
|
|
|
|
|
|
|
// construct type
|
|
|
|
if ($caught['type']) $ret[] = $caught['type'];
|
|
|
|
|
|
|
|
// construct image
|
|
|
|
if ($caught['image']) $ret[] = $caught['image'];
|
|
|
|
|
|
|
|
// construct position
|
|
|
|
if ($caught['position']) $ret[] = $caught['position'];
|
|
|
|
|
|
|
|
if (empty($ret)) return false;
|
|
|
|
return implode(' ', $ret);
|
2006-08-29 02:01:58 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|