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