Edit File by line
/home/barbar84/public_h.../wp-inclu.../SimplePi...
File: File.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 fetching remote files and reading local files
[44] Fix | Delete
*
[45] Fix | Delete
* Supports HTTP 1.0 via cURL or fsockopen, with spotty HTTP 1.1 support
[46] Fix | Delete
*
[47] Fix | Delete
* This class can be overloaded with {@see SimplePie::set_file_class()}
[48] Fix | Delete
*
[49] Fix | Delete
* @package SimplePie
[50] Fix | Delete
* @subpackage HTTP
[51] Fix | Delete
* @todo Move to properly supporting RFC2616 (HTTP/1.1)
[52] Fix | Delete
*/
[53] Fix | Delete
class SimplePie_File
[54] Fix | Delete
{
[55] Fix | Delete
var $url;
[56] Fix | Delete
var $useragent;
[57] Fix | Delete
var $success = true;
[58] Fix | Delete
var $headers = array();
[59] Fix | Delete
var $body;
[60] Fix | Delete
var $status_code;
[61] Fix | Delete
var $redirects = 0;
[62] Fix | Delete
var $error;
[63] Fix | Delete
var $method = SIMPLEPIE_FILE_SOURCE_NONE;
[64] Fix | Delete
var $permanent_url;
[65] Fix | Delete
[66] Fix | Delete
public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false, $curl_options = array())
[67] Fix | Delete
{
[68] Fix | Delete
if (class_exists('idna_convert'))
[69] Fix | Delete
{
[70] Fix | Delete
$idn = new idna_convert();
[71] Fix | Delete
$parsed = SimplePie_Misc::parse_url($url);
[72] Fix | Delete
$url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], NULL);
[73] Fix | Delete
}
[74] Fix | Delete
$this->url = $url;
[75] Fix | Delete
$this->permanent_url = $url;
[76] Fix | Delete
$this->useragent = $useragent;
[77] Fix | Delete
if (preg_match('/^http(s)?:\/\//i', $url))
[78] Fix | Delete
{
[79] Fix | Delete
if ($useragent === null)
[80] Fix | Delete
{
[81] Fix | Delete
$useragent = ini_get('user_agent');
[82] Fix | Delete
$this->useragent = $useragent;
[83] Fix | Delete
}
[84] Fix | Delete
if (!is_array($headers))
[85] Fix | Delete
{
[86] Fix | Delete
$headers = array();
[87] Fix | Delete
}
[88] Fix | Delete
if (!$force_fsockopen && function_exists('curl_exec'))
[89] Fix | Delete
{
[90] Fix | Delete
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
[91] Fix | Delete
$fp = curl_init();
[92] Fix | Delete
$headers2 = array();
[93] Fix | Delete
foreach ($headers as $key => $value)
[94] Fix | Delete
{
[95] Fix | Delete
$headers2[] = "$key: $value";
[96] Fix | Delete
}
[97] Fix | Delete
if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
[98] Fix | Delete
{
[99] Fix | Delete
curl_setopt($fp, CURLOPT_ENCODING, '');
[100] Fix | Delete
}
[101] Fix | Delete
curl_setopt($fp, CURLOPT_URL, $url);
[102] Fix | Delete
curl_setopt($fp, CURLOPT_HEADER, 1);
[103] Fix | Delete
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
[104] Fix | Delete
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
[105] Fix | Delete
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
[106] Fix | Delete
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
[107] Fix | Delete
curl_setopt($fp, CURLOPT_REFERER, $url);
[108] Fix | Delete
curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
[109] Fix | Delete
curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
[110] Fix | Delete
foreach ($curl_options as $curl_param => $curl_value) {
[111] Fix | Delete
curl_setopt($fp, $curl_param, $curl_value);
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$this->headers = curl_exec($fp);
[115] Fix | Delete
if (curl_errno($fp) === 23 || curl_errno($fp) === 61)
[116] Fix | Delete
{
[117] Fix | Delete
curl_setopt($fp, CURLOPT_ENCODING, 'none');
[118] Fix | Delete
$this->headers = curl_exec($fp);
[119] Fix | Delete
}
[120] Fix | Delete
if (curl_errno($fp))
[121] Fix | Delete
{
[122] Fix | Delete
$this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
[123] Fix | Delete
$this->success = false;
[124] Fix | Delete
}
[125] Fix | Delete
else
[126] Fix | Delete
{
[127] Fix | Delete
// Use the updated url provided by curl_getinfo after any redirects.
[128] Fix | Delete
if ($info = curl_getinfo($fp)) {
[129] Fix | Delete
$this->url = $info['url'];
[130] Fix | Delete
}
[131] Fix | Delete
curl_close($fp);
[132] Fix | Delete
$this->headers = SimplePie_HTTP_Parser::prepareHeaders($this->headers, $info['redirect_count'] + 1);
[133] Fix | Delete
$parser = new SimplePie_HTTP_Parser($this->headers);
[134] Fix | Delete
if ($parser->parse())
[135] Fix | Delete
{
[136] Fix | Delete
$this->headers = $parser->headers;
[137] Fix | Delete
$this->body = trim($parser->body);
[138] Fix | Delete
$this->status_code = $parser->status_code;
[139] Fix | Delete
if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
[140] Fix | Delete
{
[141] Fix | Delete
$this->redirects++;
[142] Fix | Delete
$location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
[143] Fix | Delete
$previousStatusCode = $this->status_code;
[144] Fix | Delete
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
[145] Fix | Delete
$this->permanent_url = ($previousStatusCode == 301) ? $location : $url;
[146] Fix | Delete
return;
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
}
[150] Fix | Delete
}
[151] Fix | Delete
else
[152] Fix | Delete
{
[153] Fix | Delete
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
[154] Fix | Delete
$url_parts = parse_url($url);
[155] Fix | Delete
$socket_host = $url_parts['host'];
[156] Fix | Delete
if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https')
[157] Fix | Delete
{
[158] Fix | Delete
$socket_host = "ssl://$url_parts[host]";
[159] Fix | Delete
$url_parts['port'] = 443;
[160] Fix | Delete
}
[161] Fix | Delete
if (!isset($url_parts['port']))
[162] Fix | Delete
{
[163] Fix | Delete
$url_parts['port'] = 80;
[164] Fix | Delete
}
[165] Fix | Delete
$fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
[166] Fix | Delete
if (!$fp)
[167] Fix | Delete
{
[168] Fix | Delete
$this->error = 'fsockopen error: ' . $errstr;
[169] Fix | Delete
$this->success = false;
[170] Fix | Delete
}
[171] Fix | Delete
else
[172] Fix | Delete
{
[173] Fix | Delete
stream_set_timeout($fp, $timeout);
[174] Fix | Delete
if (isset($url_parts['path']))
[175] Fix | Delete
{
[176] Fix | Delete
if (isset($url_parts['query']))
[177] Fix | Delete
{
[178] Fix | Delete
$get = "$url_parts[path]?$url_parts[query]";
[179] Fix | Delete
}
[180] Fix | Delete
else
[181] Fix | Delete
{
[182] Fix | Delete
$get = $url_parts['path'];
[183] Fix | Delete
}
[184] Fix | Delete
}
[185] Fix | Delete
else
[186] Fix | Delete
{
[187] Fix | Delete
$get = '/';
[188] Fix | Delete
}
[189] Fix | Delete
$out = "GET $get HTTP/1.1\r\n";
[190] Fix | Delete
$out .= "Host: $url_parts[host]\r\n";
[191] Fix | Delete
$out .= "User-Agent: $useragent\r\n";
[192] Fix | Delete
if (extension_loaded('zlib'))
[193] Fix | Delete
{
[194] Fix | Delete
$out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
if (isset($url_parts['user']) && isset($url_parts['pass']))
[198] Fix | Delete
{
[199] Fix | Delete
$out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
[200] Fix | Delete
}
[201] Fix | Delete
foreach ($headers as $key => $value)
[202] Fix | Delete
{
[203] Fix | Delete
$out .= "$key: $value\r\n";
[204] Fix | Delete
}
[205] Fix | Delete
$out .= "Connection: Close\r\n\r\n";
[206] Fix | Delete
fwrite($fp, $out);
[207] Fix | Delete
[208] Fix | Delete
$info = stream_get_meta_data($fp);
[209] Fix | Delete
[210] Fix | Delete
$this->headers = '';
[211] Fix | Delete
while (!$info['eof'] && !$info['timed_out'])
[212] Fix | Delete
{
[213] Fix | Delete
$this->headers .= fread($fp, 1160);
[214] Fix | Delete
$info = stream_get_meta_data($fp);
[215] Fix | Delete
}
[216] Fix | Delete
if (!$info['timed_out'])
[217] Fix | Delete
{
[218] Fix | Delete
$parser = new SimplePie_HTTP_Parser($this->headers);
[219] Fix | Delete
if ($parser->parse())
[220] Fix | Delete
{
[221] Fix | Delete
$this->headers = $parser->headers;
[222] Fix | Delete
$this->body = $parser->body;
[223] Fix | Delete
$this->status_code = $parser->status_code;
[224] Fix | Delete
if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
[225] Fix | Delete
{
[226] Fix | Delete
$this->redirects++;
[227] Fix | Delete
$location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
[228] Fix | Delete
$previousStatusCode = $this->status_code;
[229] Fix | Delete
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
[230] Fix | Delete
$this->permanent_url = ($previousStatusCode == 301) ? $location : $url;
[231] Fix | Delete
return;
[232] Fix | Delete
}
[233] Fix | Delete
if (isset($this->headers['content-encoding']))
[234] Fix | Delete
{
[235] Fix | Delete
// Hey, we act dumb elsewhere, so let's do that here too
[236] Fix | Delete
switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20")))
[237] Fix | Delete
{
[238] Fix | Delete
case 'gzip':
[239] Fix | Delete
case 'x-gzip':
[240] Fix | Delete
$decoder = new SimplePie_gzdecode($this->body);
[241] Fix | Delete
if (!$decoder->parse())
[242] Fix | Delete
{
[243] Fix | Delete
$this->error = 'Unable to decode HTTP "gzip" stream';
[244] Fix | Delete
$this->success = false;
[245] Fix | Delete
}
[246] Fix | Delete
else
[247] Fix | Delete
{
[248] Fix | Delete
$this->body = trim($decoder->data);
[249] Fix | Delete
}
[250] Fix | Delete
break;
[251] Fix | Delete
[252] Fix | Delete
case 'deflate':
[253] Fix | Delete
if (($decompressed = gzinflate($this->body)) !== false)
[254] Fix | Delete
{
[255] Fix | Delete
$this->body = $decompressed;
[256] Fix | Delete
}
[257] Fix | Delete
else if (($decompressed = gzuncompress($this->body)) !== false)
[258] Fix | Delete
{
[259] Fix | Delete
$this->body = $decompressed;
[260] Fix | Delete
}
[261] Fix | Delete
else if (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false)
[262] Fix | Delete
{
[263] Fix | Delete
$this->body = $decompressed;
[264] Fix | Delete
}
[265] Fix | Delete
else
[266] Fix | Delete
{
[267] Fix | Delete
$this->error = 'Unable to decode HTTP "deflate" stream';
[268] Fix | Delete
$this->success = false;
[269] Fix | Delete
}
[270] Fix | Delete
break;
[271] Fix | Delete
[272] Fix | Delete
default:
[273] Fix | Delete
$this->error = 'Unknown content coding';
[274] Fix | Delete
$this->success = false;
[275] Fix | Delete
}
[276] Fix | Delete
}
[277] Fix | Delete
}
[278] Fix | Delete
}
[279] Fix | Delete
else
[280] Fix | Delete
{
[281] Fix | Delete
$this->error = 'fsocket timed out';
[282] Fix | Delete
$this->success = false;
[283] Fix | Delete
}
[284] Fix | Delete
fclose($fp);
[285] Fix | Delete
}
[286] Fix | Delete
}
[287] Fix | Delete
}
[288] Fix | Delete
else
[289] Fix | Delete
{
[290] Fix | Delete
$this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
[291] Fix | Delete
if (empty($url) || !($this->body = trim(file_get_contents($url))))
[292] Fix | Delete
{
[293] Fix | Delete
$this->error = 'file_get_contents could not read the file';
[294] Fix | Delete
$this->success = false;
[295] Fix | Delete
}
[296] Fix | Delete
}
[297] Fix | Delete
}
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function