HTMLPurifier 4.4.0
/home/ezyang/Dev/htmlpurifier/library/HTMLPurifier/AttrDef/CSS/ImportantDecorator.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class HTMLPurifier_AttrDef_CSS_ImportantDecorator extends HTMLPurifier_AttrDef
00007 {
00008     public $def, $allow;
00009 
00014     public function __construct($def, $allow = false) {
00015         $this->def = $def;
00016         $this->allow = $allow;
00017     }
00021     public function validate($string, $config, $context) {
00022         // test for ! and important tokens
00023         $string = trim($string);
00024         $is_important = false;
00025         // :TODO: optimization: test directly for !important and ! important
00026         if (strlen($string) >= 9 && substr($string, -9) === 'important') {
00027             $temp = rtrim(substr($string, 0, -9));
00028             // use a temp, because we might want to restore important
00029             if (strlen($temp) >= 1 && substr($temp, -1) === '!') {
00030                 $string = rtrim(substr($temp, 0, -1));
00031                 $is_important = true;
00032             }
00033         }
00034         $string = $this->def->validate($string, $config, $context);
00035         if ($this->allow && $is_important) $string .= ' !important';
00036         return $string;
00037     }
00038 }
00039 
00040 // vim: et sw=4 sts=4