Add conversion functions for our own tree format.
[htmlpurifier.git] / library / HTMLPurifier / Token / Tag.php
blobd643fa64e20271b56edfc687d53d8f91dedcfbb4
1 <?php
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
8 /**
9 * Static bool marker that indicates the class is a tag.
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
15 public $is_tag = true;
17 /**
18 * The lower-case name of the tag, like 'a', 'b' or 'blockquote'.
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
25 public $name;
27 /**
28 * Associative array of the tag's attributes.
29 * @type array
31 public $attr = array();
33 /**
34 * Non-overloaded constructor, which lower-cases passed tag name.
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
42 public function __construct($name, $attr = array(), $line = null, $col = null, $armor = array())
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];
52 if ($new_key !== $key) {
53 unset($attr[$key]);
57 $this->attr = $attr;
58 $this->line = $line;
59 $this->col = $col;
60 $this->armor = $armor;
63 public function toNode() {
64 return new HTMLPurifier_Node_Element($this->name, $this->attr, $this->line, $this->col, $this->armor);
68 // vim: et sw=4 sts=4