mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-01 11:50:28 +02:00
Commit initial implementation of AttrDef_CSS, with text-align being the only defined property. Further development will be going on in AttrDef and CSSDefinition.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@223 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
35
library/HTMLPurifier/AttrDef/CSS.php
Normal file
35
library/HTMLPurifier/AttrDef/CSS.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDef.php';
|
||||
require_once 'HTMLPurifier/CSSDefinition.php';
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS
|
||||
{
|
||||
|
||||
function validate($css, $config, &$context) {
|
||||
|
||||
$definition = HTMLPurifier_CSSDefinition::instance();
|
||||
|
||||
// we're going to break the spec and explode by semicolons.
|
||||
// This is because semicolon rarely appears in escaped form
|
||||
|
||||
$declarations = explode(';', $css);
|
||||
$new_declarations = '';
|
||||
|
||||
foreach ($declarations as $declaration) {
|
||||
if (!$declaration) continue;
|
||||
if (!strpos($declaration, ':')) continue;
|
||||
list($property, $value) = explode(':', $declaration, 2);
|
||||
if (!isset($definition->info[$property])) continue;
|
||||
$result = $definition->info[$property]->validate($value,$config,$context);
|
||||
if ($result === false) continue;
|
||||
$new_declarations .= "$property:$result;";
|
||||
}
|
||||
|
||||
return $new_declarations ? $new_declarations : false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
30
library/HTMLPurifier/CSSDefinition.php
Normal file
30
library/HTMLPurifier/CSSDefinition.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_CSSDefinition
|
||||
{
|
||||
|
||||
var $info = array();
|
||||
|
||||
function &instance($prototype = null) {
|
||||
static $instance = null;
|
||||
if ($prototype) {
|
||||
$instance = $prototype;
|
||||
} elseif (!$instance) {
|
||||
$instance = new HTMLPurifier_CSSDefinition();
|
||||
$instance->setup();
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function HTMLPurifier_CSSDefinition() {}
|
||||
|
||||
function setup() {
|
||||
|
||||
$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
|
||||
array('left', 'right', 'center', 'justify'), false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -255,6 +255,7 @@ class HTMLPurifier_Definition
|
||||
'id' => new HTMLPurifier_AttrDef_ID(),
|
||||
'class' => new HTMLPurifier_AttrDef_Class(),
|
||||
'title' => $e_Text,
|
||||
'style' => new HTMLPurifier_AttrDef_CSS(),
|
||||
// i18n
|
||||
'dir' => new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false),
|
||||
'lang' => new HTMLPurifier_AttrDef_Lang(),
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
// pretty-printing with indentation would be pretty cool
|
||||
|
||||
class HTMLPurifier_Generator
|
||||
{
|
||||
|
||||
|
Reference in New Issue
Block a user