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: $this->info['ContentEditable'] = new HTMLPurifier_AttrDef_HTML_ContentEditable();
45:
46: // unimplemented aliases
47: $this->info['ContentType'] = new HTMLPurifier_AttrDef_Text();
48: $this->info['ContentTypes'] = new HTMLPurifier_AttrDef_Text();
49: $this->info['Charsets'] = new HTMLPurifier_AttrDef_Text();
50: $this->info['Character'] = new HTMLPurifier_AttrDef_Text();
51:
52: // "proprietary" types
53: $this->info['Class'] = new HTMLPurifier_AttrDef_HTML_Class();
54:
55: // number is really a positive integer (one or more digits)
56: // FIXME: ^^ not always, see start and value of list items
57: $this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true);
58: }
59:
60: private static function makeEnum($in)
61: {
62: return new HTMLPurifier_AttrDef_Clone(new HTMLPurifier_AttrDef_Enum(explode(',', $in)));
63: }
64:
65: /**
66: * Retrieves a type
67: * @param string $type String type name
68: * @return HTMLPurifier_AttrDef Object AttrDef for type
69: */
70: public function get($type)
71: {
72: // determine if there is any extra info tacked on
73: if (strpos($type, '#') !== false) {
74: list($type, $string) = explode('#', $type, 2);
75: } else {
76: $string = '';
77: }
78:
79: if (!isset($this->info[$type])) {
80: trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
81: return;
82: }
83: return $this->info[$type]->make($string);
84: }
85:
86: /**
87: * Sets a new implementation for a type
88: * @param string $type String type name
89: * @param HTMLPurifier_AttrDef $impl Object AttrDef for type
90: */
91: public function set($type, $impl)
92: {
93: $this->info[$type] = $impl;
94: }
95: }
96:
97: // vim: et sw=4 sts=4
98: