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