web/wp-includes/SimplePie/Sanitize.php
author Anthony Ly <anthonyly.com@gmail.com>
Wed, 19 Dec 2012 17:50:20 -0800
changeset 205 a4f7897e21a9
parent 204 09a1c134465b
permissions -rw-r--r--
dump sql
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     1
<?php
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     2
/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     3
 * SimplePie
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     4
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     5
 * A PHP-Based RSS and Atom Feed Framework.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     6
 * Takes the hard work out of managing a complete RSS/Atom solution.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     7
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     8
 * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     9
 * All rights reserved.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    10
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    11
 * Redistribution and use in source and binary forms, with or without modification, are
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    12
 * permitted provided that the following conditions are met:
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    13
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    14
 * 	* Redistributions of source code must retain the above copyright notice, this list of
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    15
 * 	  conditions and the following disclaimer.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    16
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    17
 * 	* Redistributions in binary form must reproduce the above copyright notice, this list
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    18
 * 	  of conditions and the following disclaimer in the documentation and/or other materials
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    19
 * 	  provided with the distribution.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    20
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    21
 * 	* Neither the name of the SimplePie Team nor the names of its contributors may be used
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    22
 * 	  to endorse or promote products derived from this software without specific prior
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    23
 * 	  written permission.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    24
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    25
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    26
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    27
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    28
 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    29
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    30
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    31
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    32
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    33
 * POSSIBILITY OF SUCH DAMAGE.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    34
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    35
 * @package SimplePie
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    36
 * @version 1.3.1
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    37
 * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    38
 * @author Ryan Parman
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    39
 * @author Geoffrey Sneddon
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    40
 * @author Ryan McCue
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    41
 * @link http://simplepie.org/ SimplePie
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    42
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    43
 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    44
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    45
/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    46
 * Used for data cleanup and post-processing
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    47
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    48
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    49
 * This class can be overloaded with {@see SimplePie::set_sanitize_class()}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    50
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    51
 * @package SimplePie
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    52
 * @todo Move to using an actual HTML parser (this will allow tags to be properly stripped, and to switch between HTML and XHTML), this will also make it easier to shorten a string while preserving HTML tags
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    53
 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    54
class SimplePie_Sanitize
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    55
{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    56
	// Private vars
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    57
	var $base;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    58
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    59
	// Options
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    60
	var $remove_div = true;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    61
	var $image_handler = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    62
	var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    63
	var $encode_instead_of_strip = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    64
	var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    65
	var $strip_comments = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    66
	var $output_encoding = 'UTF-8';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    67
	var $enable_cache = true;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    68
	var $cache_location = './cache';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    69
	var $cache_name_function = 'md5';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    70
	var $timeout = 10;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    71
	var $useragent = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    72
	var $force_fsockopen = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    73
	var $replace_url_attributes = null;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    74
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    75
	public function __construct()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    76
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    77
		// Set defaults
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    78
		$this->set_url_replacements(null);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    79
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    80
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    81
	public function remove_div($enable = true)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    82
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    83
		$this->remove_div = (bool) $enable;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    84
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    85
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    86
	public function set_image_handler($page = false)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    87
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    88
		if ($page)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    89
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    90
			$this->image_handler = (string) $page;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    91
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    92
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    93
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    94
			$this->image_handler = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    95
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    96
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    97
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    98
	public function set_registry(SimplePie_Registry $registry)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    99
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   100
		$this->registry = $registry;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   101
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   102
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   103
	public function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache')
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   104
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   105
		if (isset($enable_cache))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   106
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   107
			$this->enable_cache = (bool) $enable_cache;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   108
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   109
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   110
		if ($cache_location)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   111
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   112
			$this->cache_location = (string) $cache_location;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   113
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   114
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   115
		if ($cache_name_function)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   116
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   117
			$this->cache_name_function = (string) $cache_name_function;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   118
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   119
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   120
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   121
	public function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   122
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   123
		if ($timeout)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   124
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   125
			$this->timeout = (string) $timeout;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   126
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   127
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   128
		if ($useragent)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   129
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   130
			$this->useragent = (string) $useragent;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   131
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   132
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   133
		if ($force_fsockopen)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   134
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   135
			$this->force_fsockopen = (string) $force_fsockopen;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   136
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   137
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   138
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   139
	public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   140
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   141
		if ($tags)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   142
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   143
			if (is_array($tags))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   144
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   145
				$this->strip_htmltags = $tags;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   146
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   147
			else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   148
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   149
				$this->strip_htmltags = explode(',', $tags);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   150
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   151
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   152
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   153
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   154
			$this->strip_htmltags = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   155
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   156
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   157
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   158
	public function encode_instead_of_strip($encode = false)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   159
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   160
		$this->encode_instead_of_strip = (bool) $encode;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   161
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   162
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   163
	public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   164
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   165
		if ($attribs)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   166
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   167
			if (is_array($attribs))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   168
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   169
				$this->strip_attributes = $attribs;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   170
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   171
			else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   172
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   173
				$this->strip_attributes = explode(',', $attribs);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   174
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   175
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   176
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   177
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   178
			$this->strip_attributes = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   179
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   180
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   181
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   182
	public function strip_comments($strip = false)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   183
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   184
		$this->strip_comments = (bool) $strip;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   185
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   186
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   187
	public function set_output_encoding($encoding = 'UTF-8')
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   188
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   189
		$this->output_encoding = (string) $encoding;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   190
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   191
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   192
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   193
	 * Set element/attribute key/value pairs of HTML attributes
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   194
	 * containing URLs that need to be resolved relative to the feed
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   195
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   196
	 * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   197
	 * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   198
	 * |q|@cite
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   199
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   200
	 * @since 1.0
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   201
	 * @param array|null $element_attribute Element/attribute key/value pairs, null for default
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   202
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   203
	public function set_url_replacements($element_attribute = null)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   204
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   205
		if ($element_attribute === null)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   206
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   207
			$element_attribute = array(
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   208
				'a' => 'href',
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   209
				'area' => 'href',
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   210
				'blockquote' => 'cite',
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   211
				'del' => 'cite',
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   212
				'form' => 'action',
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   213
				'img' => array(
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   214
					'longdesc',
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   215
					'src'
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   216
				),
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   217
				'input' => 'src',
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   218
				'ins' => 'cite',
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   219
				'q' => 'cite'
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   220
			);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   221
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   222
		$this->replace_url_attributes = (array) $element_attribute;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   223
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   224
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   225
	public function sanitize($data, $type, $base = '')
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   226
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   227
		$data = trim($data);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   228
		if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   229
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   230
			if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   231
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   232
				if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   233
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   234
					$type |= SIMPLEPIE_CONSTRUCT_HTML;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   235
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   236
				else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   237
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   238
					$type |= SIMPLEPIE_CONSTRUCT_TEXT;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   239
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   240
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   241
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   242
			if ($type & SIMPLEPIE_CONSTRUCT_BASE64)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   243
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   244
				$data = base64_decode($data);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   245
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   246
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   247
			if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   248
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   249
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   250
				if (!class_exists('DOMDocument'))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   251
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   252
					$this->registry->call('Misc', 'error', array('DOMDocument not found, unable to use sanitizer', E_USER_WARNING, __FILE__, __LINE__));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   253
					return '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   254
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   255
				$document = new DOMDocument();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   256
				$document->encoding = 'UTF-8';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   257
				$data = $this->preprocess($data, $type);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   258
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   259
				set_error_handler(array('SimplePie_Misc', 'silence_errors'));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   260
				$document->loadHTML($data);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   261
				restore_error_handler();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   262
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   263
				// Strip comments
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   264
				if ($this->strip_comments)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   265
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   266
					$xpath = new DOMXPath($document);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   267
					$comments = $xpath->query('//comment()');
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   268
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   269
					foreach ($comments as $comment)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   270
					{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   271
						$comment->parentNode->removeChild($comment);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   272
					}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   273
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   274
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   275
				// Strip out HTML tags and attributes that might cause various security problems.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   276
				// Based on recommendations by Mark Pilgrim at:
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   277
				// http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   278
				if ($this->strip_htmltags)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   279
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   280
					foreach ($this->strip_htmltags as $tag)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   281
					{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   282
						$this->strip_tag($tag, $document, $type);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   283
					}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   284
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   285
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   286
				if ($this->strip_attributes)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   287
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   288
					foreach ($this->strip_attributes as $attrib)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   289
					{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   290
						$this->strip_attr($attrib, $document);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   291
					}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   292
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   293
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   294
				// Replace relative URLs
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   295
				$this->base = $base;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   296
				foreach ($this->replace_url_attributes as $element => $attributes)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   297
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   298
					$this->replace_urls($document, $element, $attributes);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   299
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   300
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   301
				// If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   302
				if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   303
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   304
					$images = $document->getElementsByTagName('img');
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   305
					foreach ($images as $img)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   306
					{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   307
						if ($img->hasAttribute('src'))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   308
						{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   309
							$image_url = call_user_func($this->cache_name_function, $img->getAttribute('src'));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   310
							$cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, $image_url, 'spi'));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   311
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   312
							if ($cache->load())
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   313
							{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   314
								$img->setAttribute('src', $this->image_handler . $image_url);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   315
							}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   316
							else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   317
							{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   318
								$file = $this->registry->create('File', array($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   319
								$headers = $file->headers;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   320
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   321
								if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   322
								{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   323
									if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   324
									{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   325
										$img->setAttribute('src', $this->image_handler . $image_url);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   326
									}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   327
									else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   328
									{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   329
										trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   330
									}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   331
								}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   332
							}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   333
						}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   334
					}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   335
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   336
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   337
				// Remove the DOCTYPE
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   338
				// Seems to cause segfaulting if we don't do this
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   339
				if ($document->firstChild instanceof DOMDocumentType)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   340
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   341
					$document->removeChild($document->firstChild);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   342
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   343
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   344
				// Move everything from the body to the root
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   345
				$real_body = $document->getElementsByTagName('body')->item(0)->childNodes->item(0);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   346
				$document->replaceChild($real_body, $document->firstChild);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   347
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   348
				// Finally, convert to a HTML string
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   349
				$data = trim($document->saveHTML());
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   350
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   351
				if ($this->remove_div)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   352
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   353
					$data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   354
					$data = preg_replace('/<\/div>$/', '', $data);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   355
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   356
				else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   357
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   358
					$data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   359
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   360
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   361
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   362
			if ($type & SIMPLEPIE_CONSTRUCT_IRI)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   363
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   364
				$absolute = $this->registry->call('Misc', 'absolutize_url', array($data, $base));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   365
				if ($absolute !== false)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   366
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   367
					$data = $absolute;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   368
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   369
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   370
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   371
			if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   372
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   373
				$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   374
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   375
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   376
			if ($this->output_encoding !== 'UTF-8')
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   377
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   378
				$data = $this->registry->call('Misc', 'change_encoding', array($data, 'UTF-8', $this->output_encoding));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   379
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   380
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   381
		return $data;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   382
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   383
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   384
	protected function preprocess($html, $type)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   385
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   386
		$ret = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   387
		if ($type & ~SIMPLEPIE_CONSTRUCT_XHTML)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   388
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   389
			// Atom XHTML constructs are wrapped with a div by default
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   390
			// Note: No protection if $html contains a stray </div>!
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   391
			$html = '<div>' . $html . '</div>';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   392
			$ret .= '<!DOCTYPE html>';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   393
			$content_type = 'text/html';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   394
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   395
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   396
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   397
			$ret .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   398
			$content_type = 'application/xhtml+xml';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   399
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   400
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   401
		$ret .= '<html><head>';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   402
		$ret .= '<meta http-equiv="Content-Type" content="' . $content_type . '; charset=utf-8" />';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   403
		$ret .= '</head><body>' . $html . '</body></html>';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   404
		return $ret;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   405
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   406
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   407
	public function replace_urls($document, $tag, $attributes)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   408
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   409
		if (!is_array($attributes))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   410
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   411
			$attributes = array($attributes);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   412
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   413
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   414
		if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   415
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   416
			$elements = $document->getElementsByTagName($tag);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   417
			foreach ($elements as $element)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   418
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   419
				foreach ($attributes as $attribute)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   420
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   421
					if ($element->hasAttribute($attribute))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   422
					{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   423
						$value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   424
						if ($value !== false)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   425
						{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   426
							$element->setAttribute($attribute, $value);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   427
						}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   428
					}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   429
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   430
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   431
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   432
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   433
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   434
	public function do_strip_htmltags($match)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   435
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   436
		if ($this->encode_instead_of_strip)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   437
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   438
			if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   439
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   440
				$match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   441
				$match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   442
				return "&lt;$match[1]$match[2]&gt;$match[3]&lt;/$match[1]&gt;";
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   443
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   444
			else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   445
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   446
				return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   447
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   448
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   449
		elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   450
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   451
			return $match[4];
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   452
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   453
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   454
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   455
			return '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   456
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   457
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   458
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   459
	protected function strip_tag($tag, $document, $type)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   460
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   461
		$xpath = new DOMXPath($document);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   462
		$elements = $xpath->query('body//' . $tag);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   463
		if ($this->encode_instead_of_strip)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   464
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   465
			foreach ($elements as $element)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   466
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   467
				$fragment = $document->createDocumentFragment();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   468
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   469
				// For elements which aren't script or style, include the tag itself
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   470
				if (!in_array($tag, array('script', 'style')))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   471
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   472
					$text = '<' . $tag;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   473
					if ($element->hasAttributes())
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   474
					{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   475
						$attrs = array();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   476
						foreach ($element->attributes as $name => $attr)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   477
						{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   478
							$value = $attr->value;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   479
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   480
							// In XHTML, empty values should never exist, so we repeat the value
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   481
							if (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_XHTML))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   482
							{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   483
								$value = $name;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   484
							}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   485
							// For HTML, empty is fine
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   486
							elseif (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_HTML))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   487
							{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   488
								$attrs[] = $name;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   489
								continue;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   490
							}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   491
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   492
							// Standard attribute text
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   493
							$attrs[] = $name . '="' . $attr->value . '"';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   494
						}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   495
						$text .= ' ' . implode(' ', $attrs);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   496
					}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   497
					$text .= '>';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   498
					$fragment->appendChild(new DOMText($text));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   499
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   500
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   501
				$number = $element->childNodes->length;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   502
				for ($i = $number; $i > 0; $i--)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   503
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   504
					$child = $element->childNodes->item(0);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   505
					$fragment->appendChild($child);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   506
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   507
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   508
				if (!in_array($tag, array('script', 'style')))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   509
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   510
					$fragment->appendChild(new DOMText('</' . $tag . '>'));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   511
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   512
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   513
				$element->parentNode->replaceChild($fragment, $element);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   514
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   515
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   516
			return;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   517
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   518
		elseif (in_array($tag, array('script', 'style')))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   519
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   520
			foreach ($elements as $element)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   521
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   522
				$element->parentNode->removeChild($element);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   523
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   524
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   525
			return;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   526
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   527
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   528
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   529
			foreach ($elements as $element)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   530
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   531
				$fragment = $document->createDocumentFragment();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   532
				$number = $element->childNodes->length;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   533
				for ($i = $number; $i > 0; $i--)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   534
				{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   535
					$child = $element->childNodes->item(0);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   536
					$fragment->appendChild($child);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   537
				}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   538
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   539
				$element->parentNode->replaceChild($fragment, $element);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   540
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   541
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   542
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   543
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   544
	protected function strip_attr($attrib, $document)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   545
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   546
		$xpath = new DOMXPath($document);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   547
		$elements = $xpath->query('//*[@' . $attrib . ']');
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   548
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   549
		foreach ($elements as $element)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   550
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   551
			$element->removeAttribute($attrib);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   552
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   553
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   554
}