1 : <?php
2 :
3 : /**
4 : * Abstract class of a tag token (start, end or empty), and its behavior.
5 : */
6 1 : 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 : */
14 : public $is_tag = true;
15 :
16 : /**
17 : * The lower-case name of the tag, like 'a', 'b' or 'blockquote'.
18 : *
19 : * @note Strictly speaking, XML tags are case sensitive, so we shouldn't
20 : * be lower-casing them, but these tokens cater to HTML tags, which are
21 : * insensitive.
22 : */
23 : public $name;
24 :
25 : /**
26 : * Associative array of the tag's attributes.
27 : */
28 : public $attr = array();
29 :
30 : /**
31 : * Non-overloaded constructor, which lower-cases passed tag name.
32 : *
33 : * @param $name String name.
34 : * @param $attr Associative array of attributes.
35 : */
36 : public function __construct($name, $attr = array(), $line = null) {
37 2 : $this->name = ctype_lower($name) ? $name : strtolower($name);
38 2 : foreach ($attr as $key => $value) {
39 : // normalization only necessary when key is not lowercase
40 2 : if (!ctype_lower($key)) {
41 : $new_key = strtolower($key);
42 : if (!isset($attr[$new_key])) {
43 : $attr[$new_key] = $attr[$key];
44 : }
45 : if ($new_key !== $key) {
46 : unset($attr[$key]);
47 : }
48 : }
49 2 : }
50 2 : $this->attr = $attr;
51 2 : $this->line = $line;
52 2 : }
53 : }
|