Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 3 /** 4 * Provides lookup array of attribute types to HTMLPurifier_AttrDef objects 5 */ 6 class HTMLPurifier_AttrTypes 7 { 8 /** 9 * Lookup array of attribute string identifiers to concrete implementations. 10 * @type HTMLPurifier_AttrDef[] 11 */ 12 protected $info = array(); 13 14 /** 15 * Constructs the info array, supplying default implementations for attribute 16 * types. 17 */ 18 public function __construct() 19 { 20 // XXX This is kind of poor, since we don't actually /clone/ 21 // instances; instead, we use the supplied make() attribute. So, 22 // the underlying class must know how to deal with arguments. 23 // With the old implementation of Enum, that ignored its 24 // arguments when handling a make dispatch, the IAlign 25 // definition wouldn't work. 26 27 // pseudo-types, must be instantiated via shorthand 28 $this->info['Enum'] = new HTMLPurifier_AttrDef_Enum(); 29 $this->info['Bool'] = new HTMLPurifier_AttrDef_HTML_Bool(); 30 31 $this->info['CDATA'] = new HTMLPurifier_AttrDef_Text(); 32 $this->info['ID'] = new HTMLPurifier_AttrDef_HTML_ID(); 33 $this->info['Length'] = new HTMLPurifier_AttrDef_HTML_Length(); 34 $this->info['MultiLength'] = new HTMLPurifier_AttrDef_HTML_MultiLength(); 35 $this->info['NMTOKENS'] = new HTMLPurifier_AttrDef_HTML_Nmtokens(); 36 $this->info['Pixels'] = new HTMLPurifier_AttrDef_HTML_Pixels(); 37 $this->info['Text'] = new HTMLPurifier_AttrDef_Text(); 38 $this->info['URI'] = new HTMLPurifier_AttrDef_URI(); 39 $this->info['LanguageCode'] = new HTMLPurifier_AttrDef_Lang(); 40 $this->info['Color'] = new HTMLPurifier_AttrDef_HTML_Color(); 41 $this->info['IAlign'] = self::makeEnum('top,middle,bottom,left,right'); 42 $this->info['LAlign'] = self::makeEnum('top,bottom,left,right'); 43 $this->info['FrameTarget'] = new HTMLPurifier_AttrDef_HTML_FrameTarget(); 44 45 // unimplemented aliases 46 $this->info['ContentType'] = new HTMLPurifier_AttrDef_Text(); 47 $this->info['ContentTypes'] = new HTMLPurifier_AttrDef_Text(); 48 $this->info['Charsets'] = new HTMLPurifier_AttrDef_Text(); 49 $this->info['Character'] = new HTMLPurifier_AttrDef_Text(); 50 51 // "proprietary" types 52 $this->info['Class'] = new HTMLPurifier_AttrDef_HTML_Class(); 53 54 // number is really a positive integer (one or more digits) 55 // FIXME: ^^ not always, see start and value of list items 56 $this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true); 57 } 58 59 private static function makeEnum($in) 60 { 61 return new HTMLPurifier_AttrDef_Clone(new HTMLPurifier_AttrDef_Enum(explode(',', $in))); 62 } 63 64 /** 65 * Retrieves a type 66 * @param string $type String type name 67 * @return HTMLPurifier_AttrDef Object AttrDef for type 68 */ 69 public function get($type) 70 { 71 // determine if there is any extra info tacked on 72 if (strpos($type, '#') !== false) { 73 list($type, $string) = explode('#', $type, 2); 74 } else { 75 $string = ''; 76 } 77 78 if (!isset($this->info[$type])) { 79 trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR); 80 return; 81 } 82 return $this->info[$type]->make($string); 83 } 84 85 /** 86 * Sets a new implementation for a type 87 * @param string $type String type name 88 * @param HTMLPurifier_AttrDef $impl Object AttrDef for type 89 */ 90 public function set($type, $impl) 91 { 92 $this->info[$type] = $impl; 93 } 94 } 95 96 // vim: et sw=4 sts=4
title
Description
Body
title
Description
Body
title
Description
Body
title
Body