Rss reader use the timeout and proxy if setup
This commit is contained in:
parent
3687dc8be9
commit
437a6f699e
@ -39,18 +39,42 @@ class RssParser
|
|||||||
protected $_rssarray=array();
|
protected $_rssarray=array();
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
public function getFormat() { return $this->_format; }
|
public function getFormat() {
|
||||||
public function getUrlRss() { return $this->_urlRSS; }
|
return $this->_format;
|
||||||
public function getLanguage() { return $this->_language; }
|
}
|
||||||
public function getGenerator() { return $this->_generator; }
|
public function getUrlRss() {
|
||||||
public function getCopyright() { return $this->_copyright; }
|
return $this->_urlRSS;
|
||||||
public function getLastBuildDate() { return $this->_lastbuilddate; }
|
}
|
||||||
public function getImageUrl() { return $this->_imageurl; }
|
public function getLanguage() {
|
||||||
public function getLink() { return $this->_link; }
|
return $this->_language;
|
||||||
public function getTitle() { return $this->_title; }
|
}
|
||||||
public function getDescription() { return $this->_description; }
|
public function getGenerator() {
|
||||||
public function getLastFetchDate() { return $this->_lastfetchdate; }
|
return $this->_generator;
|
||||||
public function getItems() { return $this->_rssarray; }
|
}
|
||||||
|
public function getCopyright() {
|
||||||
|
return $this->_copyright;
|
||||||
|
}
|
||||||
|
public function getLastBuildDate() {
|
||||||
|
return $this->_lastbuilddate;
|
||||||
|
}
|
||||||
|
public function getImageUrl() {
|
||||||
|
return $this->_imageurl;
|
||||||
|
}
|
||||||
|
public function getLink() {
|
||||||
|
return $this->_link;
|
||||||
|
}
|
||||||
|
public function getTitle() {
|
||||||
|
return $this->_title;
|
||||||
|
}
|
||||||
|
public function getDescription() {
|
||||||
|
return $this->_description;
|
||||||
|
}
|
||||||
|
public function getLastFetchDate() {
|
||||||
|
return $this->_lastfetchdate;
|
||||||
|
}
|
||||||
|
public function getItems() {
|
||||||
|
return $this->_rssarray;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// For parsing with xmlparser
|
// For parsing with xmlparser
|
||||||
@ -80,6 +104,8 @@ class RssParser
|
|||||||
*/
|
*/
|
||||||
public function parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='')
|
public function parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='')
|
||||||
{
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
|
include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
|
||||||
|
|
||||||
$str=''; // This will contain content of feed
|
$str=''; // This will contain content of feed
|
||||||
@ -124,9 +150,17 @@ class RssParser
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
|
ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
|
||||||
ini_set("max_execution_time", 10);
|
ini_set("max_execution_time", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
|
||||||
$str = file_get_contents($this->_urlRSS);
|
ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
|
||||||
|
|
||||||
|
$opts = array('http'=>array('method'=>"GET"));
|
||||||
|
if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
|
||||||
|
if (! empty($conf->global->MAIN_PROXY_USE)) $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
|
||||||
|
//var_dump($opts);exit;
|
||||||
|
$context = stream_context_create($opts);
|
||||||
|
|
||||||
|
$str = file_get_contents($this->_urlRSS, false, $context);
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage();
|
print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage();
|
||||||
@ -143,7 +177,9 @@ class RssParser
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$xmlparser=xml_parser_create('');
|
$xmlparser=xml_parser_create('');
|
||||||
if (!is_resource($xmlparser)) { $this->error="ErrorFailedToCreateParser"; return -1; }
|
if (!is_resource($xmlparser)) {
|
||||||
|
$this->error="ErrorFailedToCreateParser"; return -1;
|
||||||
|
}
|
||||||
|
|
||||||
xml_set_object($xmlparser, $this);
|
xml_set_object($xmlparser, $this);
|
||||||
xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element' );
|
xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element' );
|
||||||
@ -235,13 +271,18 @@ class RssParser
|
|||||||
if (!empty($rss->channel['title'])) $this->_title = (string) $rss->channel['title'];
|
if (!empty($rss->channel['title'])) $this->_title = (string) $rss->channel['title'];
|
||||||
//if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description'];
|
//if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description'];
|
||||||
}
|
}
|
||||||
if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) { $tmprss=xml2php($rss); $items=$tmprss['entry'];} // With simplexml
|
if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
|
||||||
|
$tmprss=xml2php($rss); $items=$tmprss['entry'];
|
||||||
|
} // With simplexml
|
||||||
else $items=$rss->items; // With xmlparse
|
else $items=$rss->items; // With xmlparse
|
||||||
//var_dump($items);exit;
|
//var_dump($items);exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
// Loop on each record
|
// Loop on each record
|
||||||
|
if (is_array($items))
|
||||||
|
{
|
||||||
foreach($items as $item)
|
foreach($items as $item)
|
||||||
{
|
{
|
||||||
//var_dump($item);exit;
|
//var_dump($item);exit;
|
||||||
@ -314,6 +355,7 @@ class RssParser
|
|||||||
|
|
||||||
if ($i > $maxNb) break; // We get all records we want
|
if ($i > $maxNb) break; // We get all records we want
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user