HTMLPurifier 4.4.0
|
00001 <?php 00002 00006 class HTMLPurifier_ConfigSchema { 00007 00012 public $defaults = array(); 00013 00017 public $defaultPlist; 00018 00048 public $info = array(); 00049 00053 static protected $singleton; 00054 00055 public function __construct() { 00056 $this->defaultPlist = new HTMLPurifier_PropertyList(); 00057 } 00058 00062 public static function makeFromSerial() { 00063 $contents = file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser'); 00064 $r = unserialize($contents); 00065 if (!$r) { 00066 $hash = sha1($contents); 00067 trigger_error("Unserialization of configuration schema failed, sha1 of file was $hash", E_USER_ERROR); 00068 } 00069 return $r; 00070 } 00071 00075 public static function instance($prototype = null) { 00076 if ($prototype !== null) { 00077 HTMLPurifier_ConfigSchema::$singleton = $prototype; 00078 } elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) { 00079 HTMLPurifier_ConfigSchema::$singleton = HTMLPurifier_ConfigSchema::makeFromSerial(); 00080 } 00081 return HTMLPurifier_ConfigSchema::$singleton; 00082 } 00083 00096 public function add($key, $default, $type, $allow_null) { 00097 $obj = new stdclass(); 00098 $obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type]; 00099 if ($allow_null) $obj->allow_null = true; 00100 $this->info[$key] = $obj; 00101 $this->defaults[$key] = $default; 00102 $this->defaultPlist->set($key, $default); 00103 } 00104 00114 public function addValueAliases($key, $aliases) { 00115 if (!isset($this->info[$key]->aliases)) { 00116 $this->info[$key]->aliases = array(); 00117 } 00118 foreach ($aliases as $alias => $real) { 00119 $this->info[$key]->aliases[$alias] = $real; 00120 } 00121 } 00122 00131 public function addAllowedValues($key, $allowed) { 00132 $this->info[$key]->allowed = $allowed; 00133 } 00134 00142 public function addAlias($key, $new_key) { 00143 $obj = new stdclass; 00144 $obj->key = $new_key; 00145 $obj->isAlias = true; 00146 $this->info[$key] = $obj; 00147 } 00148 00152 public function postProcess() { 00153 foreach ($this->info as $key => $v) { 00154 if (count((array) $v) == 1) { 00155 $this->info[$key] = $v->type; 00156 } elseif (count((array) $v) == 2 && isset($v->allow_null)) { 00157 $this->info[$key] = -$v->type; 00158 } 00159 } 00160 } 00161 00162 } 00163 00164 // vim: et sw=4 sts=4