Skip to content
Snippets Groups Projects
Commit 98c98884 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Mise a jour de librairie embarquée magpierss. Ajout de la notice de license de...

Mise a jour de librairie embarquée magpierss. Ajout de la notice de license de magpierss qui doit etre distribué si magpierss distribué.
parent 6fdc63c2
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
\version $Revision$ \version $Revision$
*/ */
include_once(DOL_DOCUMENT_ROOT."/includes/magpierss/rss_fetch.inc"); include_once(MAGPIERSS_PATH."rss_fetch.inc");
include_once(DOL_DOCUMENT_ROOT."/includes/boxes/modules_boxes.php"); include_once(DOL_DOCUMENT_ROOT."/includes/boxes/modules_boxes.php");
......
NAME
MagpieRSS - a simple RSS integration tool
SYNOPSIS
require_once(rss_fetch.inc);
$url = $_GET['url'];
$rss = fetch_rss( $url );
echo "Channel Title: " . $rss->channel['title'] . "<p>";
echo "<ul>";
foreach ($rss->items as $item) {
$href = $item['link'];
$title = $item['title'];
echo "<li><a href=$href>$title</a></li>";
}
echo "</ul>";
DESCRIPTION
MapieRSS is an XML-based RSS parser in PHP. It attempts to be "PHP-like",
and simple to use.
Some features include:
* supports RSS 0.9 - 1.0, with limited RSS 2.0 support
* supports namespaces, and modules, including mod_content and mod_event
* open minded [1]
* simple, functional interface, to object oriented backend parser
* automatic caching of parsed RSS objects makes its easy to integrate
* supports conditional GET with Last-Modified, and ETag
* uses constants for easy override of default behaviour
* heavily commented
1. By open minded I mean Magpie will accept any tag it finds in good faith that
it was supposed to be here. For strict validation, look elsewhere.
GETTING STARTED
COPYRIGHT:
Copyright(c) 2002 kellan@protest.net. All rights reserved.
This software is released under the GNU General Public License.
Please read the disclaimer at the top of the Snoopy.class.inc file.
...@@ -198,8 +198,10 @@ class Snoopy ...@@ -198,8 +198,10 @@ class Snoopy
return true; return true;
break; break;
case "https": case "https":
if(!$this->curl_path || (!is_executable($this->curl_path))) if(!$this->curl_path || (!is_executable($this->curl_path))) {
$this->error = "Bad curl ($this->curl_path), can't fetch HTTPS \n";
return false; return false;
}
$this->host = $URI_PARTS["host"]; $this->host = $URI_PARTS["host"];
if(!empty($URI_PARTS["port"])) if(!empty($URI_PARTS["port"]))
$this->port = $URI_PARTS["port"]; $this->port = $URI_PARTS["port"];
...@@ -258,325 +260,6 @@ class Snoopy ...@@ -258,325 +260,6 @@ class Snoopy
return true; return true;
} }
/*======================================================================*\
Function: submit
Purpose: submit an http form
Input: $URI the location to post the data
$formvars the formvars to use.
format: $formvars["var"] = "val";
Output: $this->results the text output from the post
\*======================================================================*/
function submit($URI, $formvars="", $formfiles="")
{
unset($postdata);
$postdata = $this->_prepare_post_body($formvars, $formfiles);
$URI_PARTS = parse_url($URI);
if (!empty($URI_PARTS["user"]))
$this->user = $URI_PARTS["user"];
if (!empty($URI_PARTS["pass"]))
$this->pass = $URI_PARTS["pass"];
switch($URI_PARTS["scheme"])
{
case "http":
$this->host = $URI_PARTS["host"];
if(!empty($URI_PARTS["port"]))
$this->port = $URI_PARTS["port"];
if($this->_connect($fp))
{
if($this->_isproxy)
{
// using proxy, send entire URI
$this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata);
}
else
{
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
// no proxy, send only the path
$this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata);
}
$this->_disconnect($fp);
if($this->_redirectaddr)
{
/* url was redirected, check if we've hit the max depth */
if($this->maxredirs > $this->_redirectdepth)
{
if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
// only follow redirect if it's on this site, or offsiteok is true
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
{
/* follow the redirect */
$this->_redirectdepth++;
$this->lastredirectaddr=$this->_redirectaddr;
$this->submit($this->_redirectaddr,$formvars, $formfiles);
}
}
}
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
{
$frameurls = $this->_frameurls;
$this->_frameurls = array();
while(list(,$frameurl) = each($frameurls))
{
if($this->_framedepth < $this->maxframes)
{
$this->fetch($frameurl);
$this->_framedepth++;
}
else
break;
}
}
}
else
{
return false;
}
return true;
break;
case "https":
if(!$this->curl_path || (!is_executable($this->curl_path)))
return false;
$this->host = $URI_PARTS["host"];
if(!empty($URI_PARTS["port"]))
$this->port = $URI_PARTS["port"];
if($this->_isproxy)
{
// using proxy, send entire URI
$this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata);
}
else
{
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
// no proxy, send only the path
$this->_httpsrequest($path, $URI, $this->_submit_method, $this->_submit_type, $postdata);
}
if($this->_redirectaddr)
{
/* url was redirected, check if we've hit the max depth */
if($this->maxredirs > $this->_redirectdepth)
{
if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
// only follow redirect if it's on this site, or offsiteok is true
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
{
/* follow the redirect */
$this->_redirectdepth++;
$this->lastredirectaddr=$this->_redirectaddr;
$this->submit($this->_redirectaddr,$formvars, $formfiles);
}
}
}
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
{
$frameurls = $this->_frameurls;
$this->_frameurls = array();
while(list(,$frameurl) = each($frameurls))
{
if($this->_framedepth < $this->maxframes)
{
$this->fetch($frameurl);
$this->_framedepth++;
}
else
break;
}
}
return true;
break;
default:
// not a valid protocol
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
return false;
break;
}
return true;
}
/*======================================================================*\
Function: fetchlinks
Purpose: fetch the links from a web page
Input: $URI where you are fetching from
Output: $this->results an array of the URLs
\*======================================================================*/
function fetchlinks($URI)
{
if ($this->fetch($URI))
{
if(is_array($this->results))
{
for($x=0;$x<count($this->results);$x++)
$this->results[$x] = $this->_striplinks($this->results[$x]);
}
else
$this->results = $this->_striplinks($this->results);
if($this->expandlinks)
$this->results = $this->_expandlinks($this->results, $URI);
return true;
}
else
return false;
}
/*======================================================================*\
Function: fetchform
Purpose: fetch the form elements from a web page
Input: $URI where you are fetching from
Output: $this->results the resulting html form
\*======================================================================*/
function fetchform($URI)
{
if ($this->fetch($URI))
{
if(is_array($this->results))
{
for($x=0;$x<count($this->results);$x++)
$this->results[$x] = $this->_stripform($this->results[$x]);
}
else
$this->results = $this->_stripform($this->results);
return true;
}
else
return false;
}
/*======================================================================*\
Function: fetchtext
Purpose: fetch the text from a web page, stripping the links
Input: $URI where you are fetching from
Output: $this->results the text from the web page
\*======================================================================*/
function fetchtext($URI)
{
if($this->fetch($URI))
{
if(is_array($this->results))
{
for($x=0;$x<count($this->results);$x++)
$this->results[$x] = $this->_striptext($this->results[$x]);
}
else
$this->results = $this->_striptext($this->results);
return true;
}
else
return false;
}
/*======================================================================*\
Function: submitlinks
Purpose: grab links from a form submission
Input: $URI where you are submitting from
Output: $this->results an array of the links from the post
\*======================================================================*/
function submitlinks($URI, $formvars="", $formfiles="")
{
if($this->submit($URI,$formvars, $formfiles))
{
if(is_array($this->results))
{
for($x=0;$x<count($this->results);$x++)
{
$this->results[$x] = $this->_striplinks($this->results[$x]);
if($this->expandlinks)
$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
}
}
else
{
$this->results = $this->_striplinks($this->results);
if($this->expandlinks)
$this->results = $this->_expandlinks($this->results,$URI);
}
return true;
}
else
return false;
}
/*======================================================================*\
Function: submittext
Purpose: grab text from a form submission
Input: $URI where you are submitting from
Output: $this->results the text from the web page
\*======================================================================*/
function submittext($URI, $formvars = "", $formfiles = "")
{
if($this->submit($URI,$formvars, $formfiles))
{
if(is_array($this->results))
{
for($x=0;$x<count($this->results);$x++)
{
$this->results[$x] = $this->_striptext($this->results[$x]);
if($this->expandlinks)
$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
}
}
else
{
$this->results = $this->_striptext($this->results);
if($this->expandlinks)
$this->results = $this->_expandlinks($this->results,$URI);
}
return true;
}
else
return false;
}
/*======================================================================*\
Function: set_submit_multipart
Purpose: Set the form submission content type to
multipart/form-data
\*======================================================================*/
function set_submit_multipart()
{
$this->_submit_type = "multipart/form-data";
}
/*======================================================================*\
Function: set_submit_normal
Purpose: Set the form submission content type to
application/x-www-form-urlencoded
\*======================================================================*/
function set_submit_normal()
{
$this->_submit_type = "application/x-www-form-urlencoded";
}
/*======================================================================*\ /*======================================================================*\
...@@ -812,7 +495,8 @@ class Snoopy ...@@ -812,7 +495,8 @@ class Snoopy
return false; return false;
} }
if($currentHeader == "\r\n") // if($currentHeader == "\r\n")
if(preg_match("/^\r?\n$/", $currentHeader) )
break; break;
// if a header begins with Location: or URI:, set the redirect // if a header begins with Location: or URI:, set the redirect
...@@ -970,6 +654,8 @@ class Snoopy ...@@ -970,6 +654,8 @@ class Snoopy
$headerfile = uniqid(time()); $headerfile = uniqid(time());
# accept self-signed certs
$cmdline_params .= " -k";
exec($this->curl_path." -D \"/tmp/$headerfile\"".$cmdline_params." ".$URI,$results,$return); exec($this->curl_path." -D \"/tmp/$headerfile\"".$cmdline_params." ".$URI,$results,$return);
if($return) if($return)
...@@ -1010,8 +696,13 @@ class Snoopy ...@@ -1010,8 +696,13 @@ class Snoopy
} }
if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
{
$this->response_code = $result_headers[$currentHeader]; $this->response_code = $result_headers[$currentHeader];
if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$this->response_code, $match))
{
$this->status= $match[1];
}
}
$this->headers[] = $result_headers[$currentHeader]; $this->headers[] = $result_headers[$currentHeader];
} }
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
/* /*
* Project: MagpieRSS: a simple RSS integration tool * Project: MagpieRSS: a simple RSS integration tool
* File: rss_cache.inc, a simple, rolling(no GC), cache * File: rss_cache.inc, a simple, rolling(no GC), cache
* for RSS objects, keyed on URL. * for RSS objects, keyed on URL.
* Author: Kellan Elliott-McCrea <kellan@protest.net> * Author: Kellan Elliott-McCrea <kellan@protest.net>
* Version: 0.51 * Version: 0.51
* License: GPL * License: GPL
* *
* The lastest version of MagpieRSS can be obtained from: * The lastest version of MagpieRSS can be obtained from:
* http://magpierss.sourceforge.net * http://magpierss.sourceforge.net
...@@ -17,167 +17,167 @@ ...@@ -17,167 +17,167 @@
*/ */
class RSSCache { class RSSCache {
var $BASE_CACHE = './cache'; // where the cache files are stored var $BASE_CACHE = './cache'; // where the cache files are stored
var $MAX_AGE = 3600; // when are files stale, default one hour var $MAX_AGE = 3600; // when are files stale, default one hour
var $ERROR = ""; // accumulate error messages var $ERROR = ""; // accumulate error messages
function RSSCache ($base='', $age='') { function RSSCache ($base='', $age='') {
if ( $base ) { if ( $base ) {
$this->BASE_CACHE = $base; $this->BASE_CACHE = $base;
} }
if ( $age ) { if ( $age ) {
$this->MAX_AGE = $age; $this->MAX_AGE = $age;
} }
// attempt to make the cache directory // attempt to make the cache directory
if ( ! file_exists( $this->BASE_CACHE ) ) { if ( ! file_exists( $this->BASE_CACHE ) ) {
$status = @mkdir( $this->BASE_CACHE, 0755 ); $status = @mkdir( $this->BASE_CACHE, 0755 );
// if make failed // if make failed
if ( ! $status ) { if ( ! $status ) {
$this->error( $this->error(
"Cache couldn't make dir '" . $this->BASE_CACHE . "'." "Cache couldn't make dir '" . $this->BASE_CACHE . "'."
); );
} }
} }
} }
/*=======================================================================*\ /*=======================================================================*\
Function: set Function: set
Purpose: add an item to the cache, keyed on url Purpose: add an item to the cache, keyed on url
Input: url from wich the rss file was fetched Input: url from wich the rss file was fetched
Output: true on sucess Output: true on sucess
\*=======================================================================*/ \*=======================================================================*/
function set ($url, $rss) { function set ($url, $rss) {
$this->ERROR = ""; $this->ERROR = "";
$cache_file = $this->file_name( $url ); $cache_file = $this->file_name( $url );
$fp = @fopen( $cache_file, 'w' ); $fp = @fopen( $cache_file, 'w' );
if ( ! $fp ) { if ( ! $fp ) {
$this->error( $this->error(
"Cache unable to open file for writing: $cache_file" "Cache unable to open file for writing: $cache_file"
); );
return 0; return 0;
} }
$data = $this->serialize( $rss ); $data = $this->serialize( $rss );
fwrite( $fp, $data ); fwrite( $fp, $data );
fclose( $fp ); fclose( $fp );
return $cache_file; return $cache_file;
} }
/*=======================================================================*\ /*=======================================================================*\
Function: get Function: get
Purpose: fetch an item from the cache Purpose: fetch an item from the cache
Input: url from wich the rss file was fetched Input: url from wich the rss file was fetched
Output: cached object on HIT, false on MISS Output: cached object on HIT, false on MISS
\*=======================================================================*/ \*=======================================================================*/
function get ($url) { function get ($url) {
$this->ERROR = ""; $this->ERROR = "";
$cache_file = $this->file_name( $url ); $cache_file = $this->file_name( $url );
if ( ! file_exists( $cache_file ) ) { if ( ! file_exists( $cache_file ) ) {
$this->debug( $this->debug(
"Cache doesn't contain: $url (cache file: $cache_file)" "Cache doesn't contain: $url (cache file: $cache_file)"
); );
return 0; return 0;
} }
$fp = @fopen($cache_file, 'r'); $fp = @fopen($cache_file, 'r');
if ( ! $fp ) { if ( ! $fp ) {
$this->error( $this->error(
"Failed to open cache file for reading: $cache_file" "Failed to open cache file for reading: $cache_file"
); );
return 0; return 0;
} }
$data = fread( $fp, filesize($cache_file) ); $data = fread( $fp, filesize($cache_file) );
$rss = $this->unserialize( $data ); $rss = $this->unserialize( $data );
return $rss; return $rss;
} }
/*=======================================================================*\ /*=======================================================================*\
Function: check_cache Function: check_cache
Purpose: check a url for membership in the cache Purpose: check a url for membership in the cache
and whether the object is older then MAX_AGE (ie. STALE) and whether the object is older then MAX_AGE (ie. STALE)
Input: url from wich the rss file was fetched Input: url from wich the rss file was fetched
Output: cached object on HIT, false on MISS Output: cached object on HIT, false on MISS
\*=======================================================================*/ \*=======================================================================*/
function check_cache ( $url ) { function check_cache ( $url ) {
$this->ERROR = ""; $this->ERROR = "";
$filename = $this->file_name( $url ); $filename = $this->file_name( $url );
if ( file_exists( $filename ) ) { if ( file_exists( $filename ) ) {
// find how long ago the file was added to the cache // find how long ago the file was added to the cache
// and whether that is longer then MAX_AGE // and whether that is longer then MAX_AGE
$mtime = filemtime( $filename ); $mtime = filemtime( $filename );
$age = time() - $mtime; $age = time() - $mtime;
if ( $this->MAX_AGE > $age ) { if ( $this->MAX_AGE > $age ) {
// object exists and is current // object exists and is current
return 'HIT'; return 'HIT';
} }
else { else {
// object exists but is old // object exists but is old
return 'STALE'; return 'STALE';
} }
} }
else { else {
// object does not exist // object does not exist
return 'MISS'; return 'MISS';
} }
} }
/*=======================================================================*\ /*=======================================================================*\
Function: serialize Function: serialize
\*=======================================================================*/ \*=======================================================================*/
function serialize ( $rss ) { function serialize ( $rss ) {
return serialize( $rss ); return serialize( $rss );
} }
/*=======================================================================*\ /*=======================================================================*\
Function: unserialize Function: unserialize
\*=======================================================================*/ \*=======================================================================*/
function unserialize ( $data ) { function unserialize ( $data ) {
return unserialize( $data ); return unserialize( $data );
} }
/*=======================================================================*\ /*=======================================================================*\
Function: file_name Function: file_name
Purpose: map url to location in cache Purpose: map url to location in cache
Input: url from wich the rss file was fetched Input: url from wich the rss file was fetched
Output: a file name Output: a file name
\*=======================================================================*/ \*=======================================================================*/
function file_name ($url) { function file_name ($url) {
$filename = md5( $url ); $filename = md5( $url );
return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) ); return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) );
} }
/*=======================================================================*\ /*=======================================================================*\
Function: error Function: error
Purpose: register error Purpose: register error
\*=======================================================================*/ \*=======================================================================*/
function error ($errormsg, $lvl=E_USER_WARNING) { function error ($errormsg, $lvl=E_USER_WARNING) {
// append PHP's error message if track_errors enabled // append PHP's error message if track_errors enabled
if ( isset($php_errormsg) ) { if ( isset($php_errormsg) ) {
$errormsg .= " ($php_errormsg)"; $errormsg .= " ($php_errormsg)";
} }
$this->ERROR = $errormsg; $this->ERROR = $errormsg;
if ( MAGPIE_DEBUG ) { if ( MAGPIE_DEBUG ) {
trigger_error( $errormsg, $lvl); trigger_error( $errormsg, $lvl);
} }
else { else {
error_log( $errormsg, 0); error_log( $errormsg, 0);
} }
} }
function debug ($debugmsg, $lvl=E_USER_NOTICE) { function debug ($debugmsg, $lvl=E_USER_NOTICE) {
if ( MAGPIE_DEBUG ) { if ( MAGPIE_DEBUG ) {
$this->error("MagpieRSS [debug] $debugmsg", $lvl); $this->error("MagpieRSS [debug] $debugmsg", $lvl);
} }
} }
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
to fetching and parsing RSS files, via the to fetching and parsing RSS files, via the
function fetch_rss() function fetch_rss()
* Author: Kellan Elliott-McCrea <kellan@protest.net> * Author: Kellan Elliott-McCrea <kellan@protest.net>
* Version: 0.51 * Modified by Laurent Destailleur <eldy@users.sourceforge.net> for Dolibarr
* License: GPL * License: GPL
* *
* The lastest version of MagpieRSS can be obtained from: * The lastest version of MagpieRSS can be obtained from:
...@@ -82,7 +82,7 @@ require_once( MAGPIE_EXTLIB . 'Snoopy.class.inc'); ...@@ -82,7 +82,7 @@ require_once( MAGPIE_EXTLIB . 'Snoopy.class.inc');
version will be return, if it exists (and if MAGPIE_CACHE_FRESH_ONLY is off) version will be return, if it exists (and if MAGPIE_CACHE_FRESH_ONLY is off)
\*=======================================================================*/ \*=======================================================================*/
define('MAGPIE_VERSION', '0.51'); define('MAGPIE_VERSION', '0.7');
$MAGPIE_ERROR = ""; $MAGPIE_ERROR = "";
...@@ -117,10 +117,8 @@ function fetch_rss ($url) { ...@@ -117,10 +117,8 @@ function fetch_rss ($url) {
$cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );
if ($cache->ERROR) { if (MAGPIE_DEBUG and $cache->ERROR) {
// Erreur debug($cache->ERROR, E_USER_WARNING);
print $cache->ERROR;
if (MAGPIE_DEBUG) { debug($cache->ERROR, E_USER_WARNING); }
} }
...@@ -129,15 +127,20 @@ function fetch_rss ($url) { ...@@ -129,15 +127,20 @@ function fetch_rss ($url) {
$rss = 0; // parsed RSS object $rss = 0; // parsed RSS object
$errormsg = 0; // errors, if any $errormsg = 0; // errors, if any
// store parsed XML by desired output encoding
// as character munging happens at parse time
$cache_key = $url . MAGPIE_OUTPUT_ENCODING;
if (!$cache->ERROR) { if (!$cache->ERROR) {
// return cache HIT, MISS, or STALE // return cache HIT, MISS, or STALE
$cache_status = $cache->check_cache( $url ); $cache_status = $cache->check_cache( $cache_key);
} }
// if object cached, and cache is fresh, return cached obj // if object cached, and cache is fresh, return cached obj
if ( $cache_status == 'HIT' ) { if ( $cache_status == 'HIT' ) {
$rss = $cache->get( $url ); $rss = $cache->get( $cache_key );
if ( isset($rss) and $rss ) { if ( isset($rss) and $rss ) {
// should be cache age
$rss->from_cache = 1; $rss->from_cache = 1;
if ( MAGPIE_DEBUG > 1) { if ( MAGPIE_DEBUG > 1) {
debug("MagpieRSS: Cache HIT", E_USER_NOTICE); debug("MagpieRSS: Cache HIT", E_USER_NOTICE);
...@@ -150,8 +153,8 @@ function fetch_rss ($url) { ...@@ -150,8 +153,8 @@ function fetch_rss ($url) {
// setup headers // setup headers
if ( $cache_status == 'STALE' ) { if ( $cache_status == 'STALE' ) {
$rss = $cache->get( $url ); $rss = $cache->get( $cache_key );
if ( $rss->etag and $rss->last_modified ) { if ( $rss and $rss->etag and $rss->last_modified ) {
$request_headers['If-None-Match'] = $rss->etag; $request_headers['If-None-Match'] = $rss->etag;
$request_headers['If-Last-Modified'] = $rss->last_modified; $request_headers['If-Last-Modified'] = $rss->last_modified;
} }
...@@ -166,7 +169,7 @@ function fetch_rss ($url) { ...@@ -166,7 +169,7 @@ function fetch_rss ($url) {
debug("Got 304 for $url"); debug("Got 304 for $url");
} }
// reset cache on 304 (at minutillo insistent prodding) // reset cache on 304 (at minutillo insistent prodding)
$cache->set($url, $rss); $cache->set($cache_key, $rss);
return $rss; return $rss;
} }
elseif ( is_success( $resp->status ) ) { elseif ( is_success( $resp->status ) ) {
...@@ -176,18 +179,22 @@ function fetch_rss ($url) { ...@@ -176,18 +179,22 @@ function fetch_rss ($url) {
debug("Fetch successful"); debug("Fetch successful");
} }
// add object to cache // add object to cache
$cache->set( $url, $rss ); $cache->set( $cache_key, $rss );
return $rss; return $rss;
} }
} }
else { else {
$errormsg = "Failed to fetch $url. "; $errormsg = "Failed to fetch $url ";
if ( $resp->error ) { if ( $resp->status == '-100' ) {
$errormsg .= "(Request timed out after " . MAGPIE_FETCH_TIME_OUT . " seconds)";
}
elseif ( $resp->error ) {
# compensate for Snoopy's annoying habbit to tacking # compensate for Snoopy's annoying habbit to tacking
# on '\n' # on '\n'
$http_error = substr($resp->error, 0, -2);
// LDR FIX BUG // LDR FIX BUG (plus necessaire car corrig par ligne du dessus)
$http_error = eregi_replace("\n","",$resp->error); //$http_error = eregi_replace("\n","",$resp->error);
$errormsg .= "(HTTP Error: $http_error)"; $errormsg .= "(HTTP Error: $http_error)";
} }
...@@ -198,7 +205,7 @@ function fetch_rss ($url) { ...@@ -198,7 +205,7 @@ function fetch_rss ($url) {
// LDR FIX BUG Si echec recup http mais cache bien lu, on stock erreur dans object rss // LDR FIX BUG Si echec recup http mais cache bien lu, on stock erreur dans object rss
if ($rss) { if ($rss) {
$rss->ERROR=$errormsg; $rss->ERROR=$errormsg;
if ($cache && $url) $rss->date=filemtime($cache->file_name($url)); if ($cache && $cache_key) $rss->date=filemtime($cache->file_name($url));
} }
} }
} }
...@@ -290,7 +297,7 @@ function _fetch_remote_file ($url, $headers = "" ) { ...@@ -290,7 +297,7 @@ function _fetch_remote_file ($url, $headers = "" ) {
Output: parsed RSS object (see rss_parse) Output: parsed RSS object (see rss_parse)
\*=======================================================================*/ \*=======================================================================*/
function _response_to_rss ($resp) { function _response_to_rss ($resp) {
$rss = new MagpieRSS( $resp->results ); $rss = new MagpieRSS( $resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING );
// if RSS parsed successfully // if RSS parsed successfully
if ( $rss and !$rss->ERROR) { if ( $rss and !$rss->ERROR) {
...@@ -339,11 +346,11 @@ function init () { ...@@ -339,11 +346,11 @@ function init () {
return; return;
} }
else { else {
define('MAGPIE_INITALIZED', 1); define('MAGPIE_INITALIZED', true);
} }
if ( !defined('MAGPIE_CACHE_ON') ) { if ( !defined('MAGPIE_CACHE_ON') ) {
define('MAGPIE_CACHE_ON', 1); define('MAGPIE_CACHE_ON', true);
} }
if ( !defined('MAGPIE_CACHE_DIR') ) { if ( !defined('MAGPIE_CACHE_DIR') ) {
...@@ -372,9 +379,21 @@ function init () { ...@@ -372,9 +379,21 @@ function init () {
} }
if ( !defined('MAGPIE_CACHE_FRESH_ONLY') ) { if ( !defined('MAGPIE_CACHE_FRESH_ONLY') ) {
define('MAGPIE_CACHE_FRESH_ONLY', 0); define('MAGPIE_CACHE_FRESH_ONLY', false);
} }
if ( !defined('MAGPIE_OUTPUT_ENCODING') ) {
define('MAGPIE_OUTPUT_ENCODING', 'ISO-8859-1');
}
if ( !defined('MAGPIE_INPUT_ENCODING') ) {
define('MAGPIE_INPUT_ENCODING', null);
}
if ( !defined('MAGPIE_DETECT_ENCODING') ) {
define('MAGPIE_DETECT_ENCODING', true);
}
if ( !defined('MAGPIE_DEBUG') ) { if ( !defined('MAGPIE_DEBUG') ) {
define('MAGPIE_DEBUG', 0); define('MAGPIE_DEBUG', 0);
} }
......
This diff is collapsed.
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
* Project: MagpieRSS: a simple RSS integration tool * Project: MagpieRSS: a simple RSS integration tool
* File: rss_utils.inc, utility methods for working with RSS * File: rss_utils.inc, utility methods for working with RSS
* Author: Kellan Elliott-McCrea <kellan@protest.net> * Author: Kellan Elliott-McCrea <kellan@protest.net>
* Version: 0.51 * Version: 0.51
* License: GPL * License: GPL
* *
* The lastest version of MagpieRSS can be obtained from: * The lastest version of MagpieRSS can be obtained from:
* http://magpierss.sourceforge.net * http://magpierss.sourceforge.net
...@@ -19,49 +19,49 @@ ...@@ -19,49 +19,49 @@
Function: parse_w3cdtf Function: parse_w3cdtf
Purpose: parse a W3CDTF date into unix epoch Purpose: parse a W3CDTF date into unix epoch
NOTE: http://www.w3.org/TR/NOTE-datetime NOTE: http://www.w3.org/TR/NOTE-datetime
\*======================================================================*/ \*======================================================================*/
function parse_w3cdtf ( $date_str ) { function parse_w3cdtf ( $date_str ) {
# regex to match wc3dtf # regex to match wc3dtf
$pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/";
if ( preg_match( $pat, $date_str, $match ) ) { if ( preg_match( $pat, $date_str, $match ) ) {
list( $year, $month, $day, $hours, $minutes, $seconds) = list( $year, $month, $day, $hours, $minutes, $seconds) =
array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]);
# calc epoch for current date assuming GMT # calc epoch for current date assuming GMT
$epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year);
$offset = 0; $offset = 0;
if ( $match[10] == 'Z' ) { if ( $match[10] == 'Z' ) {
# zulu time, aka GMT # zulu time, aka GMT
} }
else { else {
list( $tz_mod, $tz_hour, $tz_min ) = list( $tz_mod, $tz_hour, $tz_min ) =
array( $match[8], $match[9], $match[10]); array( $match[8], $match[9], $match[10]);
# zero out the variables # zero out the variables
if ( ! $tz_hour ) { $tz_hour = 0; } if ( ! $tz_hour ) { $tz_hour = 0; }
if ( ! $tz_min ) { $tz_min = 0; } if ( ! $tz_min ) { $tz_min = 0; }
$offset_secs = (($tz_hour*60)+$tz_min)*60; $offset_secs = (($tz_hour*60)+$tz_min)*60;
# is timezone ahead of GMT? then subtract offset # is timezone ahead of GMT? then subtract offset
# #
if ( $tz_mod == '+' ) { if ( $tz_mod == '+' ) {
$offset_secs = $offset_secs * -1; $offset_secs = $offset_secs * -1;
} }
$offset = $offset_secs; $offset = $offset_secs;
} }
$epoch = $epoch + $offset; $epoch = $epoch + $offset;
return $epoch; return $epoch;
} }
else { else {
return -1; return -1;
} }
} }
?> ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment