2006-08-27 00:49:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates the border property as defined by CSS.
|
|
|
|
*/
|
2007-02-14 20:38:51 +00:00
|
|
|
class HTMLPurifier_AttrDef_CSS_Border extends HTMLPurifier_AttrDef
|
2006-08-27 00:49:34 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-27 00:49:34 +00:00
|
|
|
/**
|
|
|
|
* Local copy of properties this property is shorthand for.
|
2013-07-16 11:56:14 +00:00
|
|
|
* @type HTMLPurifier_AttrDef[]
|
2006-08-27 00:49:34 +00:00
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $info = array();
|
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();
|
2006-08-27 00:49:34 +00:00
|
|
|
$this->info['border-width'] = $def->info['border-width'];
|
|
|
|
$this->info['border-style'] = $def->info['border-style'];
|
|
|
|
$this->info['border-top-color'] = $def->info['border-top-color'];
|
|
|
|
}
|
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-27 00:49:34 +00:00
|
|
|
$string = $this->parseCDATA($string);
|
2008-03-16 19:14:39 +00:00
|
|
|
$string = $this->mungeRgb($string);
|
2006-08-27 00:49:34 +00:00
|
|
|
$bits = explode(' ', $string);
|
|
|
|
$done = array(); // segments we've finished
|
|
|
|
$ret = ''; // return value
|
|
|
|
foreach ($bits as $bit) {
|
|
|
|
foreach ($this->info as $propname => $validator) {
|
2013-07-16 11:56:14 +00:00
|
|
|
if (isset($done[$propname])) {
|
|
|
|
continue;
|
|
|
|
}
|
2006-08-27 02:08:50 +00:00
|
|
|
$r = $validator->validate($bit, $config, $context);
|
2006-08-27 00:49:34 +00:00
|
|
|
if ($r !== false) {
|
|
|
|
$ret .= $r . ' ';
|
|
|
|
$done[$propname] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rtrim($ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|