File indexing completed on 2024-12-22 05:36:21
0001 <?php 0002 0003 /** 0004 * Provides lookup array of attribute types to HTMLPurifier_AttrDef objects 0005 */ 0006 class HTMLPurifier_AttrTypes 0007 { 0008 /** 0009 * Lookup array of attribute string identifiers to concrete implementations. 0010 * @type HTMLPurifier_AttrDef[] 0011 */ 0012 protected $info = array(); 0013 0014 /** 0015 * Constructs the info array, supplying default implementations for attribute 0016 * types. 0017 */ 0018 public function __construct() 0019 { 0020 // XXX This is kind of poor, since we don't actually /clone/ 0021 // instances; instead, we use the supplied make() attribute. So, 0022 // the underlying class must know how to deal with arguments. 0023 // With the old implementation of Enum, that ignored its 0024 // arguments when handling a make dispatch, the IAlign 0025 // definition wouldn't work. 0026 0027 // pseudo-types, must be instantiated via shorthand 0028 $this->info['Enum'] = new HTMLPurifier_AttrDef_Enum(); 0029 $this->info['Bool'] = new HTMLPurifier_AttrDef_HTML_Bool(); 0030 0031 $this->info['CDATA'] = new HTMLPurifier_AttrDef_Text(); 0032 $this->info['ID'] = new HTMLPurifier_AttrDef_HTML_ID(); 0033 $this->info['Length'] = new HTMLPurifier_AttrDef_HTML_Length(); 0034 $this->info['MultiLength'] = new HTMLPurifier_AttrDef_HTML_MultiLength(); 0035 $this->info['NMTOKENS'] = new HTMLPurifier_AttrDef_HTML_Nmtokens(); 0036 $this->info['Pixels'] = new HTMLPurifier_AttrDef_HTML_Pixels(); 0037 $this->info['Text'] = new HTMLPurifier_AttrDef_Text(); 0038 $this->info['URI'] = new HTMLPurifier_AttrDef_URI(); 0039 $this->info['LanguageCode'] = new HTMLPurifier_AttrDef_Lang(); 0040 $this->info['Color'] = new HTMLPurifier_AttrDef_HTML_Color(); 0041 $this->info['IAlign'] = self::makeEnum('top,middle,bottom,left,right'); 0042 $this->info['LAlign'] = self::makeEnum('top,bottom,left,right'); 0043 $this->info['FrameTarget'] = new HTMLPurifier_AttrDef_HTML_FrameTarget(); 0044 0045 // unimplemented aliases 0046 $this->info['ContentType'] = new HTMLPurifier_AttrDef_Text(); 0047 $this->info['ContentTypes'] = new HTMLPurifier_AttrDef_Text(); 0048 $this->info['Charsets'] = new HTMLPurifier_AttrDef_Text(); 0049 $this->info['Character'] = new HTMLPurifier_AttrDef_Text(); 0050 0051 // "proprietary" types 0052 $this->info['Class'] = new HTMLPurifier_AttrDef_HTML_Class(); 0053 0054 // number is really a positive integer (one or more digits) 0055 // FIXME: ^^ not always, see start and value of list items 0056 $this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true); 0057 } 0058 0059 private static function makeEnum($in) 0060 { 0061 return new HTMLPurifier_AttrDef_Clone(new HTMLPurifier_AttrDef_Enum(explode(',', $in))); 0062 } 0063 0064 /** 0065 * Retrieves a type 0066 * @param string $type String type name 0067 * @return HTMLPurifier_AttrDef Object AttrDef for type 0068 */ 0069 public function get($type) 0070 { 0071 // determine if there is any extra info tacked on 0072 if (strpos($type, '#') !== false) { 0073 list($type, $string) = explode('#', $type, 2); 0074 } else { 0075 $string = ''; 0076 } 0077 0078 if (!isset($this->info[$type])) { 0079 trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR); 0080 return; 0081 } 0082 return $this->info[$type]->make($string); 0083 } 0084 0085 /** 0086 * Sets a new implementation for a type 0087 * @param string $type String type name 0088 * @param HTMLPurifier_AttrDef $impl Object AttrDef for type 0089 */ 0090 public function set($type, $impl) 0091 { 0092 $this->info[$type] = $impl; 0093 } 0094 } 0095 0096 // vim: et sw=4 sts=4