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