]>
Commit | Line | Data |
---|---|---|
d4949327 NL |
1 | <?php\r |
2 | \r | |
3 | /**\r | |
4 | * Abstract class of a tag token (start, end or empty), and its behavior.\r | |
5 | */\r | |
6 | abstract class HTMLPurifier_Token_Tag extends HTMLPurifier_Token\r | |
7 | {\r | |
8 | /**\r | |
9 | * Static bool marker that indicates the class is a tag.\r | |
10 | *\r | |
11 | * This allows us to check objects with <tt>!empty($obj->is_tag)</tt>\r | |
12 | * without having to use a function call <tt>is_a()</tt>.\r | |
13 | * @type bool\r | |
14 | */\r | |
15 | public $is_tag = true;\r | |
16 | \r | |
17 | /**\r | |
18 | * The lower-case name of the tag, like 'a', 'b' or 'blockquote'.\r | |
19 | *\r | |
20 | * @note Strictly speaking, XML tags are case sensitive, so we shouldn't\r | |
21 | * be lower-casing them, but these tokens cater to HTML tags, which are\r | |
22 | * insensitive.\r | |
23 | * @type string\r | |
24 | */\r | |
25 | public $name;\r | |
26 | \r | |
27 | /**\r | |
28 | * Associative array of the tag's attributes.\r | |
29 | * @type array\r | |
30 | */\r | |
31 | public $attr = array();\r | |
32 | \r | |
33 | /**\r | |
34 | * Non-overloaded constructor, which lower-cases passed tag name.\r | |
35 | *\r | |
36 | * @param string $name String name.\r | |
37 | * @param array $attr Associative array of attributes.\r | |
38 | * @param int $line\r | |
39 | * @param int $col\r | |
40 | * @param array $armor\r | |
41 | */\r | |
42 | public function __construct($name, $attr = array(), $line = null, $col = null, $armor = array())\r | |
43 | {\r | |
44 | $this->name = ctype_lower($name) ? $name : strtolower($name);\r | |
45 | foreach ($attr as $key => $value) {\r | |
46 | // normalization only necessary when key is not lowercase\r | |
47 | if (!ctype_lower($key)) {\r | |
48 | $new_key = strtolower($key);\r | |
49 | if (!isset($attr[$new_key])) {\r | |
50 | $attr[$new_key] = $attr[$key];\r | |
51 | }\r | |
52 | if ($new_key !== $key) {\r | |
53 | unset($attr[$key]);\r | |
54 | }\r | |
55 | }\r | |
56 | }\r | |
57 | $this->attr = $attr;\r | |
58 | $this->line = $line;\r | |
59 | $this->col = $col;\r | |
60 | $this->armor = $armor;\r | |
61 | }\r | |
62 | \r | |
63 | public function toNode() {\r | |
64 | return new HTMLPurifier_Node_Element($this->name, $this->attr, $this->line, $this->col, $this->armor);\r | |
65 | }\r | |
66 | }\r | |
67 | \r | |
68 | // vim: et sw=4 sts=4\r |