HTMLPurifier/AttrTypes.php Quellcode

AttrTypes.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
7 {
12  protected $info = array();
13 
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 
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 
90  public function set($type, $impl)
91  {
92  $this->info[$type] = $impl;
93  }
94 }
95 
96 // vim: et sw=4 sts=4




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.