XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
AttrTypes.php
Go to the documentation of this file.
1 <?php
2 
7 {
11  protected $info = array();
12 
17  public function __construct() {
18  // XXX This is kind of poor, since we don't actually /clone/
19  // instances; instead, we use the supplied make() attribute. So,
20  // the underlying class must know how to deal with arguments.
21  // With the old implementation of Enum, that ignored its
22  // arguments when handling a make dispatch, the IAlign
23  // definition wouldn't work.
24 
25  // pseudo-types, must be instantiated via shorthand
26  $this->info['Enum'] = new HTMLPurifier_AttrDef_Enum();
27  $this->info['Bool'] = new HTMLPurifier_AttrDef_HTML_Bool();
28 
29  $this->info['CDATA'] = new HTMLPurifier_AttrDef_Text();
30  $this->info['ID'] = new HTMLPurifier_AttrDef_HTML_ID();
31  $this->info['Length'] = new HTMLPurifier_AttrDef_HTML_Length();
32  $this->info['MultiLength'] = new HTMLPurifier_AttrDef_HTML_MultiLength();
33  $this->info['NMTOKENS'] = new HTMLPurifier_AttrDef_HTML_Nmtokens();
34  $this->info['Pixels'] = new HTMLPurifier_AttrDef_HTML_Pixels();
35  $this->info['Text'] = new HTMLPurifier_AttrDef_Text();
36  $this->info['URI'] = new HTMLPurifier_AttrDef_URI();
37  $this->info['LanguageCode'] = new HTMLPurifier_AttrDef_Lang();
38  $this->info['Color'] = new HTMLPurifier_AttrDef_HTML_Color();
39  $this->info['IAlign'] = self::makeEnum('top,middle,bottom,left,right');
40  $this->info['LAlign'] = self::makeEnum('top,bottom,left,right');
41  $this->info['FrameTarget'] = new HTMLPurifier_AttrDef_HTML_FrameTarget();
42 
43  // unimplemented aliases
44  $this->info['ContentType'] = new HTMLPurifier_AttrDef_Text();
45  $this->info['ContentTypes'] = new HTMLPurifier_AttrDef_Text();
46  $this->info['Charsets'] = new HTMLPurifier_AttrDef_Text();
47  $this->info['Character'] = new HTMLPurifier_AttrDef_Text();
48 
49  // "proprietary" types
50  $this->info['Class'] = new HTMLPurifier_AttrDef_HTML_Class();
51 
52  // number is really a positive integer (one or more digits)
53  // FIXME: ^^ not always, see start and value of list items
54  $this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true);
55  }
56 
57  private static function makeEnum($in) {
58  return new HTMLPurifier_AttrDef_Clone(new HTMLPurifier_AttrDef_Enum(explode(',', $in)));
59  }
60 
66  public function get($type) {
67 
68  // determine if there is any extra info tacked on
69  if (strpos($type, '#') !== false) list($type, $string) = explode('#', $type, 2);
70  else $string = '';
71 
72  if (!isset($this->info[$type])) {
73  trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
74  return;
75  }
76 
77  return $this->info[$type]->make($string);
78 
79  }
80 
86  public function set($type, $impl) {
87  $this->info[$type] = $impl;
88  }
89 }
90 
91 // vim: et sw=4 sts=4