Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updating magpie to version 0.72

  • Loading branch information...
commit e53b6045fe286636a5bb81c714626c5eda8e48c0 1 parent ae4b4fd
dhawes authored
View
41 lib/magpie/CHANGES
@@ -0,0 +1,41 @@
+Version 0.72
+-----------
+ - fix security exploit: http://www.sec-consult.com/216.html
+
+Version 0.7
+-----------
+ - support for input and output charset encoding
+ based on the work in FoF, uses iconv or mbstring if available
+ -
+
+Version 0.6
+-----------
+ - basic support for Atom syndication format
+ including support for Atom content constructs
+ - fixed support for private feeds (HTTP Auth and SSL)
+ (thanks to silverorange.com for providing test feeds)
+ - support for some broken webservers
+
+Version 0.52
+-----------
+ - support GZIP content negoiation
+ - PHP 4.3.2 support
+
+Version 0.4
+-----------
+ - improved error handling, better access for script authors
+ - included example scripts of working with MagpieRSS
+ - new Smarty plugin for RSS date parsing
+
+Version 0.3
+-----------
+ - added support for conditional gets (Last-Modified, ETag)
+ - now use Snoopy to handle fetching RSS files
+
+Version 0.2
+-----------
+ - MAJOR CLEAN UP
+ - removed kludgy $options array in favour of constants
+ - phased out returning arrays
+ - added better error handling
+ - re-worked comments
View
2  lib/magpie/README_MOODLE.txt
@@ -1,3 +1,5 @@
This folder is the MagpieRSS news feed client library
http://magpierss.sourceforge.net/
Moodle's rss_client block uses these libraries to download, parse and cache remote new feeds.
+
+Magpie version 0.72 added to Moodle 1.6dev on 20051213
View
22 lib/magpie/rss_cache.inc
@@ -93,10 +93,14 @@ class RSSCache {
return 0;
}
- $data = fread( $fp, filesize($cache_file) );
- $rss = $this->unserialize( $data );
+ if ($filesize = filesize($cache_file) ) {
+ $data = fread( $fp, filesize($cache_file) );
+ $rss = $this->unserialize( $data );
- return $rss;
+ return $rss;
+ }
+
+ return 0;
}
/*=======================================================================*\
@@ -130,6 +134,18 @@ class RSSCache {
}
}
+ function cache_age( $cache_key ) {
+ $filename = $this->file_name( $url );
+ if ( file_exists( $filename ) ) {
+ $mtime = filemtime( $filename );
+ $age = time() - $mtime;
+ return $age;
+ }
+ else {
+ return -1;
+ }
+ }
+
/*=======================================================================*\
Function: serialize
\*=======================================================================*/
View
42 lib/magpie/rss_fetch.inc
@@ -81,7 +81,7 @@ require_once( MAGPIE_EXTLIB . 'Snoopy.class.inc');
version will be return, if it exists (and if MAGPIE_CACHE_FRESH_ONLY is off)
\*=======================================================================*/
-define('MAGPIE_VERSION', '0.7');
+define('MAGPIE_VERSION', '0.72');
$MAGPIE_ERROR = "";
@@ -90,7 +90,7 @@ function fetch_rss ($url) {
init();
if ( !isset($url) ) {
- do_error("fetch_rss called without a url");
+ error("fetch_rss called without a url");
return false;
}
@@ -102,7 +102,7 @@ function fetch_rss ($url) {
return _response_to_rss( $resp );
}
else {
- do_error("Failed to fetch $url and cache is off");
+ error("Failed to fetch $url and cache is off");
return false;
}
}
@@ -117,7 +117,7 @@ function fetch_rss ($url) {
$cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );
if (MAGPIE_DEBUG and $cache->ERROR) {
- do_debug($cache->ERROR, E_USER_WARNING);
+ debug($cache->ERROR, E_USER_WARNING);
}
@@ -134,15 +134,16 @@ function fetch_rss ($url) {
// return cache HIT, MISS, or STALE
$cache_status = $cache->check_cache( $cache_key);
}
-
+
// if object cached, and cache is fresh, return cached obj
if ( $cache_status == 'HIT' ) {
$rss = $cache->get( $cache_key );
if ( isset($rss) and $rss ) {
+ // should be cache age
$rss->from_cache = 1;
if ( MAGPIE_DEBUG > 1) {
- do_debug("MagpieRSS: Cache HIT", E_USER_NOTICE);
- }
+ debug("MagpieRSS: Cache HIT", E_USER_NOTICE);
+ }
return $rss;
}
}
@@ -151,11 +152,8 @@ function fetch_rss ($url) {
// setup headers
if ( $cache_status == 'STALE' ) {
- // modified by Daryl Hawes - stale cache reads were failing because the wrong
- // string was being passed for filename
-// $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-Last-Modified'] = $rss->last_modified;
}
@@ -164,10 +162,10 @@ function fetch_rss ($url) {
$resp = _fetch_remote_file( $url, $request_headers );
if (isset($resp) and $resp) {
- if ($resp->status == '304' ) {
+ if ($resp->status == '304' ) {
// we have the most current copy
if ( MAGPIE_DEBUG > 1) {
- do_debug("Got 304 for $url");
+ debug("Got 304 for $url");
}
// reset cache on 304 (at minutillo insistent prodding)
$cache->set($cache_key, $rss);
@@ -177,7 +175,7 @@ function fetch_rss ($url) {
$rss = _response_to_rss( $resp );
if ( $rss ) {
if (MAGPIE_DEBUG > 1) {
- do_debug("Fetch successful");
+ debug("Fetch successful");
}
// add object to cache
$cache->set( $cache_key, $rss );
@@ -185,7 +183,7 @@ function fetch_rss ($url) {
}
}
else {
- $errormsg = "Failed to fetch $url. ";
+ $errormsg = "Failed to fetch $url ";
if ( $resp->status == '-100' ) {
$errormsg .= "(Request timed out after " . MAGPIE_FETCH_TIME_OUT . " seconds)";
}
@@ -209,13 +207,13 @@ function fetch_rss ($url) {
// attempt to return cached object
if ($rss) {
if ( MAGPIE_DEBUG ) {
- do_debug("Returning STALE object for $url");
+ debug("Returning STALE object for $url");
}
return $rss;
}
// else we totally failed
- do_error( $errormsg );
+ error( $errormsg );
return false;
@@ -226,9 +224,8 @@ function fetch_rss ($url) {
Function: error
Purpose: set MAGPIE_ERROR, and trigger error
\*=======================================================================*/
-//Daryl Hawes note: had to rename this function from error to do_error for moodle
-// due to conflict with existing moodle function name
-function do_error ($errormsg, $lvl=E_USER_WARNING) {
+
+function error ($errormsg, $lvl=E_USER_WARNING) {
global $MAGPIE_ERROR;
// append PHP's error message if track_errors enabled
@@ -242,8 +239,7 @@ function do_error ($errormsg, $lvl=E_USER_WARNING) {
}
}
-//Daryl Hawes note: renamed this function from debug to do_debug for moodle
-function do_debug ($debugmsg, $lvl=E_USER_NOTICE) {
+function debug ($debugmsg, $lvl=E_USER_NOTICE) {
trigger_error("MagpieRSS [debug] $debugmsg", $lvl);
}
@@ -323,7 +319,7 @@ function _response_to_rss ($resp) {
if ($rss) {
$errormsg .= " (" . $rss->ERROR . ")";
}
- do_error($errormsg);
+ error($errormsg);
return false;
} // end if ($rss and !$rss->error)
View
24 lib/magpie/rss_parse.inc
@@ -60,7 +60,6 @@ class MagpieRSS {
var $incontent = false; // if in Atom <content mode="xml"> field
var $intextinput = false;
var $inimage = false;
- var $current_field = '';
var $current_namespace = false;
@@ -259,7 +258,6 @@ class MagpieRSS {
function feed_cdata ($p, $text) {
-
if ($this->feed_type == ATOM and $this->incontent)
{
$this->append_content( $text );
@@ -391,7 +389,7 @@ class MagpieRSS {
$atom_date = (isset($item['issued']) ) ? $item['issued'] : $item['modified'];
if ( $atom_date ) {
- $epoch = @parse_w3cdtf($item['modified']);
+ $epoch = @parse_w3cdtf($atom_date);
if ($epoch and $epoch > 0) {
$item['date_timestamp'] = $epoch;
}
@@ -560,7 +558,7 @@ class MagpieRSS {
function error ($errormsg, $lvl=E_USER_WARNING) {
// append PHP's error message if track_errors enabled
- if ( $php_errormsg ) {
+ if ( isset($php_errormsg) ) {
$errormsg .= " ($php_errormsg)";
}
if ( MAGPIE_DEBUG ) {
@@ -585,5 +583,23 @@ function map_attrs($k, $v) {
return "$k=\"$v\"";
}
+// patch to support medieval versions of PHP4.1.x,
+// courtesy, Ryan Currie, ryan@digibliss.com
+
+if (!function_exists('array_change_key_case')) {
+ define("CASE_UPPER",1);
+ define("CASE_LOWER",0);
+
+
+ function array_change_key_case($array,$case=CASE_LOWER) {
+ if ($case=CASE_LOWER) $cmd=strtolower;
+ elseif ($case=CASE_UPPER) $cmd=strtoupper;
+ foreach($array as $key=>$value) {
+ $output[$cmd($key)]=$value;
+ }
+ return $output;
+ }
+
+}
?>
View
53 lib/magpie/rss_utils.inc
@@ -23,17 +23,17 @@
\*======================================================================*/
function parse_w3cdtf ( $date_str ) {
-
+
# regex to match wc3dtf
$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 ) ) {
- 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]);
-
+
# calc epoch for current date assuming GMT
$epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year);
-
+
$offset = 0;
if ( $match[10] == 'Z' ) {
# zulu time, aka GMT
@@ -41,20 +41,20 @@ function parse_w3cdtf ( $date_str ) {
else {
list( $tz_mod, $tz_hour, $tz_min ) =
array( $match[8], $match[9], $match[10]);
-
+
# zero out the variables
if ( ! $tz_hour ) { $tz_hour = 0; }
if ( ! $tz_min ) { $tz_min = 0; }
-
+
$offset_secs = (($tz_hour*60)+$tz_min)*60;
-
+
# is timezone ahead of GMT? then subtract offset
#
if ( $tz_mod == '+' ) {
$offset_secs = $offset_secs * -1;
}
-
- $offset = $offset_secs;
+
+ $offset = $offset_secs;
}
$epoch = $epoch + $offset;
return $epoch;
@@ -64,37 +64,4 @@ function parse_w3cdtf ( $date_str ) {
}
}
- if (! function_exists('array_change_key_case') ) {
-
- function array_change_key_case($input, $case=0) {
-
- if (! is_array($input) ) {
- return $input;
- }
-
- switch ($case) {
- case 'CASE_UPPER':
- case 1:
- $func = 'strtoupper';
- break;
- default:
- $func = 'strtolower';
- }
-
- $tmp = array();
- foreach ($input as $key => $value) {
-
- if ( is_array($value) ) {
- $value = array_change_key_case($value, $case);
- }
-
- $tmp[$func($key)] = $value;
- }
-
- unset($input);
- return $tmp;
-
- }
-
- }
?>
Please sign in to comment.
Something went wrong with that request. Please try again.