From f45a286b8d62f710b519a98c7d4b75a0c34d5d10 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 22 Jun 2009 13:56:49 +0400 Subject: strip_tags_long: use htmlpurifier to properly reformat html content --- .../library/HTMLPurifier/Token/Comment.php | 22 +++++++++ .../library/HTMLPurifier/Token/Empty.php | 11 +++++ .../library/HTMLPurifier/Token/End.php | 19 ++++++++ .../library/HTMLPurifier/Token/Start.php | 11 +++++ .../library/HTMLPurifier/Token/Tag.php | 56 ++++++++++++++++++++++ .../library/HTMLPurifier/Token/Text.php | 33 +++++++++++++ 6 files changed, 152 insertions(+) create mode 100755 lib/htmlpurifier/library/HTMLPurifier/Token/Comment.php create mode 100755 lib/htmlpurifier/library/HTMLPurifier/Token/Empty.php create mode 100755 lib/htmlpurifier/library/HTMLPurifier/Token/End.php create mode 100755 lib/htmlpurifier/library/HTMLPurifier/Token/Start.php create mode 100755 lib/htmlpurifier/library/HTMLPurifier/Token/Tag.php create mode 100755 lib/htmlpurifier/library/HTMLPurifier/Token/Text.php (limited to 'lib/htmlpurifier/library/HTMLPurifier/Token') diff --git a/lib/htmlpurifier/library/HTMLPurifier/Token/Comment.php b/lib/htmlpurifier/library/HTMLPurifier/Token/Comment.php new file mode 100755 index 000000000..dc6bdcabb --- /dev/null +++ b/lib/htmlpurifier/library/HTMLPurifier/Token/Comment.php @@ -0,0 +1,22 @@ +data = $data; + $this->line = $line; + $this->col = $col; + } +} + +// vim: et sw=4 sts=4 diff --git a/lib/htmlpurifier/library/HTMLPurifier/Token/Empty.php b/lib/htmlpurifier/library/HTMLPurifier/Token/Empty.php new file mode 100755 index 000000000..2a82b47ad --- /dev/null +++ b/lib/htmlpurifier/library/HTMLPurifier/Token/Empty.php @@ -0,0 +1,11 @@ +!empty($obj->is_tag) + * without having to use a function call is_a(). + */ + public $is_tag = true; + + /** + * The lower-case name of the tag, like 'a', 'b' or 'blockquote'. + * + * @note Strictly speaking, XML tags are case sensitive, so we shouldn't + * be lower-casing them, but these tokens cater to HTML tags, which are + * insensitive. + */ + public $name; + + /** + * Associative array of the tag's attributes. + */ + public $attr = array(); + + /** + * Non-overloaded constructor, which lower-cases passed tag name. + * + * @param $name String name. + * @param $attr Associative array of attributes. + */ + public function __construct($name, $attr = array(), $line = null, $col = null) { + $this->name = ctype_lower($name) ? $name : strtolower($name); + foreach ($attr as $key => $value) { + // normalization only necessary when key is not lowercase + if (!ctype_lower($key)) { + $new_key = strtolower($key); + if (!isset($attr[$new_key])) { + $attr[$new_key] = $attr[$key]; + } + if ($new_key !== $key) { + unset($attr[$key]); + } + } + } + $this->attr = $attr; + $this->line = $line; + $this->col = $col; + } +} + +// vim: et sw=4 sts=4 diff --git a/lib/htmlpurifier/library/HTMLPurifier/Token/Text.php b/lib/htmlpurifier/library/HTMLPurifier/Token/Text.php new file mode 100755 index 000000000..82efd823d --- /dev/null +++ b/lib/htmlpurifier/library/HTMLPurifier/Token/Text.php @@ -0,0 +1,33 @@ +data = $data; + $this->is_whitespace = ctype_space($data); + $this->line = $line; + $this->col = $col; + } + +} + +// vim: et sw=4 sts=4 -- cgit v1.2.3