]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTypes.php
4 * Provides lookup array of attribute types to HTMLPurifier_AttrDef objects
6 class HTMLPurifier_AttrTypes
9 * Lookup array of attribute string identifiers to concrete implementations.
10 * @type HTMLPurifier_AttrDef[]
12 protected $info = array();
15 * Constructs the info array, supplying default implementations for attribute
18 public function __construct()
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.
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();
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();
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();
51 // "proprietary" types
52 $this->info
['Class'] = new HTMLPurifier_AttrDef_HTML_Class();
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);
59 private static function makeEnum($in)
61 return new HTMLPurifier_AttrDef_Clone(new HTMLPurifier_AttrDef_Enum(explode(',', $in)));
66 * @param string $type String type name
67 * @return HTMLPurifier_AttrDef Object AttrDef for type
69 public function get($type)
71 // determine if there is any extra info tacked on
72 if (strpos($type, '#') !== false) {
73 list($type, $string) = explode('#', $type, 2);
78 if (!isset($this->info
[$type])) {
79 trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR
);
82 return $this->info
[$type]->make($string);
86 * Sets a new implementation for a type
87 * @param string $type String type name
88 * @param HTMLPurifier_AttrDef $impl Object AttrDef for type
90 public function set($type, $impl)
92 $this->info
[$type] = $impl;