mirror of
https://github.com/e107inc/e107.git
synced 2025-08-11 00:54:49 +02:00
CURL init cleanup.
This commit is contained in:
@@ -435,128 +435,10 @@ class xmlClass
|
||||
{
|
||||
$_file = e107::getFile();
|
||||
$this->xmlFileContents = $_file->getRemoteContent($address, array('timeout' => $timeout, 'post' => $postData));
|
||||
$this->error = $_file->error;
|
||||
$this->error = $_file->getErrorMessage();
|
||||
|
||||
return $this->xmlFileContents;
|
||||
|
||||
// ------ MOVED TO FILE HANDLER ------ //
|
||||
// Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here
|
||||
$timeout = min($timeout, 120);
|
||||
$timeout = max($timeout, 3);
|
||||
$this->xmlFileContents = '';
|
||||
|
||||
$mes = e107::getMessage();
|
||||
|
||||
if($this->_feedUrl) // override option for use when part of the address needs to be encoded.
|
||||
{
|
||||
$mes->addDebug("getting Remote File: ".$this->_feedUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
$address = str_replace(array("\r", "\n", "\t"), '', $address); // May be paranoia, but streaky thought it might be a good idea
|
||||
// ... and there shouldn't be unprintable characters in the URL anyway
|
||||
}
|
||||
|
||||
if($this->urlPrefix !== false)
|
||||
{
|
||||
$address = $this->urlPrefix.$address;
|
||||
}
|
||||
|
||||
|
||||
// ... and there shouldn't be unprintable characters in the URL anyway
|
||||
|
||||
|
||||
// Keep this in first position.
|
||||
if (function_exists("curl_init")) // Preferred.
|
||||
{
|
||||
$cu = curl_init();
|
||||
curl_setopt($cu, CURLOPT_URL, $address);
|
||||
curl_setopt($cu, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($cu, CURLOPT_HEADER, 0);
|
||||
curl_setopt($cu, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($cu, CURLOPT_REFERER, e_REQUEST_HTTP);
|
||||
curl_setopt($cu, CURLOPT_FOLLOWLOCATION, 0);
|
||||
curl_setopt($cu, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
||||
curl_setopt($cu, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
|
||||
curl_setopt($cu, CURLOPT_COOKIEJAR, e_SYSTEM.'cookies.txt');
|
||||
|
||||
if(!file_exists(e_SYSTEM.'cookies.txt'))
|
||||
{
|
||||
file_put_contents(e_SYSTEM.'cookies.txt','');
|
||||
}
|
||||
|
||||
$this->xmlFileContents = curl_exec($cu);
|
||||
if (curl_error($cu))
|
||||
{
|
||||
$this->error = "Curl error: ".curl_errno($cu).", ".curl_error($cu);
|
||||
return FALSE;
|
||||
}
|
||||
curl_close($cu);
|
||||
return $this->xmlFileContents;
|
||||
}
|
||||
|
||||
|
||||
if (function_exists('file_get_contents') && ini_get('allow_url_fopen'))
|
||||
{
|
||||
$old_timeout = e107_ini_set('default_socket_timeout', $timeout);
|
||||
$address = ($this->_feedUrl) ? $this->_feedUrl : urldecode($address);
|
||||
|
||||
$data = file_get_contents($address);
|
||||
|
||||
// $data = file_get_contents(htmlspecialchars($address)); // buggy - sometimes fails.
|
||||
if ($old_timeout !== FALSE)
|
||||
{
|
||||
e107_ini_set('default_socket_timeout', $old_timeout);
|
||||
}
|
||||
if ($data !== FALSE)
|
||||
{
|
||||
$this->xmlFileContents = $data;
|
||||
return $data;
|
||||
}
|
||||
$this->error = "File_get_contents(XML) error"; // Fill in more info later
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (ini_get("allow_url_fopen"))
|
||||
{
|
||||
$old_timeout = e107_ini_set('default_socket_timeout', $timeout);
|
||||
$remote = @fopen($address, "r");
|
||||
if (!$remote)
|
||||
{
|
||||
$this->error = "fopen: Unable to open remote XML file: ".$address;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$old_timeout = $timeout;
|
||||
$tmp = parse_url($address);
|
||||
if (!$remote = fsockopen($tmp['host'], 80, $errno, $errstr, $timeout))
|
||||
{
|
||||
$this->error = "Sockets: Unable to open remote XML file: ".$address;
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
socket_set_timeout($remote, $timeout);
|
||||
fputs($remote, "GET ".urlencode($address)." HTTP/1.0\r\n\r\n");
|
||||
}
|
||||
}
|
||||
$this->xmlFileContents = "";
|
||||
while (!feof($remote))
|
||||
{
|
||||
$this->xmlFileContents .= fgets($remote, 4096);
|
||||
}
|
||||
fclose($remote);
|
||||
if ($old_timeout != $timeout)
|
||||
{
|
||||
if ($old_timeout !== FALSE)
|
||||
{
|
||||
e107_ini_set('default_socket_timeout', $old_timeout);
|
||||
}
|
||||
}
|
||||
return $this->xmlFileContents;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user