1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-27 01:40:22 +02:00

Sync with v1.x functionality. setFeedUrl()

This commit is contained in:
CaMer0n
2012-08-18 00:53:04 +00:00
parent e0581d53b0
commit a08d1eb2a9

View File

@@ -145,6 +145,11 @@ class xmlClass
*/ */
protected $_optValueKey = '@value'; protected $_optValueKey = '@value';
protected $_feedUrl = FALSE;
/** /**
* Constructor - set defaults * Constructor - set defaults
* *
@@ -257,6 +262,16 @@ class xmlClass
return $this; return $this;
} }
public function setFeedUrl($feed)
{
if($feed)
{
$this->_feedUrl = $feed;
}
}
/** /**
* Get Remote file contents * Get Remote file contents
* use setOptArrayTags above if you require a consistent array result by in 1 item or many. * use setOptArrayTags above if you require a consistent array result by in 1 item or many.
@@ -269,12 +284,25 @@ class xmlClass
// Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here // Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here
$timeout = min($timeout, 120); $timeout = min($timeout, 120);
$timeout = max($timeout, 3); $timeout = max($timeout, 3);
if($this->_feedUrl) // override option for use when part of the address needs to be encoded.
{
$address = $this->_feedUrl;
echo "address=".$address;
}
else
{
$address = str_replace(array("\r", "\n", "\t"), '', $address); // May be paranoia, but streaky thought it might be a good idea $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 // ... and there shouldn't be unprintable characters in the URL anyway
}
// ... and there shouldn't be unprintable characters in the URL anyway
if (function_exists('file_get_contents') && ini_get('allow_url_fopen')) if (function_exists('file_get_contents') && ini_get('allow_url_fopen'))
{ {
$old_timeout = e107_ini_set('default_socket_timeout', $timeout); $old_timeout = e107_ini_set('default_socket_timeout', $timeout);
$data = file_get_contents(urldecode($address)); $address = ($this->_feedUrl) ? $this->_feedUrl : urldecode($address);
$data = file_get_contents($address);
// $data = file_get_contents(htmlspecialchars($address)); // buggy - sometimes fails. // $data = file_get_contents(htmlspecialchars($address)); // buggy - sometimes fails.
if ($old_timeout !== FALSE) if ($old_timeout !== FALSE)
@@ -622,11 +650,18 @@ class xmlClass
{ {
$tp = e107::getParser(); $tp = e107::getParser();
if($this->_feedUrl !== false)
{
$fname = $this->_feedUrl;
}
if (empty($fname)) if (empty($fname))
{ {
return false; return false;
} }
$xml = false; $xml = false;
if (strpos($fname, '://') !== false) if (strpos($fname, '://') !== false)
{ {
$this->getRemoteFile($fname); $this->getRemoteFile($fname);