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