Skip to content

Commit

Permalink
latest magpie. moved from rss folder to lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhawes committed Jan 23, 2005
1 parent 04280e8 commit 29a6bbd
Show file tree
Hide file tree
Showing 19 changed files with 3,477 additions and 0 deletions.
1 change: 1 addition & 0 deletions rss/magpie/magpie/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kellan <[email protected]>
48 changes: 48 additions & 0 deletions rss/magpie/magpie/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 [email protected]. 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.
3 changes: 3 additions & 0 deletions rss/magpie/magpie/README_MOODLE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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.
152 changes: 152 additions & 0 deletions rss/magpie/magpie/TROUBLESHOOTING
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
TROUBLESHOOTING


Trouble Installing MagpieRSS:

1. Fatal error: Failed opening required '/path/to/script/rss_fetch.inc'
(include_path='.:/usr/local/lib/php:/usr/local/lib/php/pear')

2. Cache couldn't make dir './cache'.

3. Fatal error: Failed to load PHP's XML Extension.
http://www.php.net/manual/en/ref.xml.php

Trouble Using MagpieRSS

4. Warning: MagpieRSS: Failed to fetch example.com/index.rdf.
(HTTP Error: Invalid protocol "")

5. Warning: MagpieRSS: Failed to parse RSS file.
(not well-formed (invalid token) at line 19, column 98)

6. Warning: MagpieRSS: Failed to fetch http://localhost/rss/features.1-0.rss.
(HTTP Response: HTTP/1.1 404 Not Found)

If you would rather provide a custom error, see the COOKBOOK
(http://magpierss.sf.net/cookbook.html) recipe 2.

*************************************************************************
1. Fatal error: Failed opening required '/path/to/script/rss_fetch.inc'
(include_path='.:/usr/local/lib/php:/usr/local/lib/php/pear')

This could mean that:

a) PHP can't find the MagpieRSS files.
b) PHP found them the MagpieRSS files, but can't read them.

a. Telling PHP where to look for MagpieRSS file.

This might mean your PHP program can't find the MagpieRSS libraries.
Magpie relies on 4 include files, rss_fetch.inc, rss_parse.inc,
rss_cache.inc, rss_util.inc, and for normal use you'll need all 4 (see the
cookbook for exceptions).

This can be fixed by making sure the MagpieRSS files are in your include
path.

If you can edit your include path (for example your on a shared host) then
you need to replace:

require_once('rss_fetch.inc');

-with-

define('MAGPIE_DIR', '/path/to/magpierss/');
require_once(MAGPIE_DIR.'rss_fetch.inc');

b. PHP can't read the MagpieRSS files

All PHP libraries need to be readable by your webserver.

On Unix you can accomplish this with:

chmod 755 rss_fetch.inc rss_parse.inc rss_cache.inc rss_util.inc

*************************************************************************
2. Cache couldn't make dir './cache'.

MagpieRSS caches the results of fetched and parsed RSS to reduce the load on
both your server, and the remote server providing the RSS. It does this by
writing files to a cache directory.

This error means the webserver doesn't have write access to the current
directory.

a. Make a webserver writeable cache directory

Find the webserver's group. (on my system it is 'www')

mkdir ./cache
chgrp www directory_name
chmod g+w directory_name

(this is the best, and desired solution)

b. Tell MagpieRSS to create the cache directory somewhere the webserver can
write to.

define('MAGPIE_CACHE_DIR', '/tmp/magpierss');

(this is not a great solution, and might have security considerations)

c. Turn off cacheing.

Magpie can work fine with cacheing, but it will be slower, and you might
become a nuiance to the RSS provider, but it is an option.

define('MAGPIE_CACHE_ON', 0);

d. And lastly, do NOT

chmod 777 ./cache

Any of the above solutions are better then this.

NOTE: If none of this works for you, let me know. I've got root, and a
custom compiled Apache on almost any box I ever touch, so I can be a little
out of touch with reality. But I won't know that if I don't feedback.

************************************************************************* 3.
3. Fatal error: Failed to load PHP's XML Extension.
http://www.php.net/manual/en/ref.xml.php

-or-

Fatal error: Failed to create an instance of PHP's XML parser.
http://www.php.net/manual/en/ref.xml.php

Make sure your PHP was built with --with-xml

This has been turned on by default for several versions of PHP, but it might
be turned off in your build.

See php.net for details on building and configuring PHP.


*************************************************************************
4. Warning: MagpieRSS: Failed to fetch index.rdf.
(HTTP Error: Invalid protocol "")

You need to put http:// in front of your the URL to your RSS feed

*************************************************************************
5. Warning: MagpieRSS: Failed to parse RSS file.
(not well-formed (invalid token) at line 19, column 98)

There is a problem with the RSS feed you are trying to read.
MagpieRSS is an XML parser, and therefore can't parse RSS feed with invalid
characters. Some RSS parser are based on regular expressions, and can
parse invalid RSS but they have their own problems.

You could try contacting the author of the RSS feed, and pointing them to
the online RSS validator at:

http://feeds.archive.org/validator/

*************************************************************************
6. Warning: MagpieRSS: Failed to fetch http://example.com/index.rdf
(HTTP Response: HTTP/1.1 404 Not Found)

Its a 404! The RSS file ain't there.


125 changes: 125 additions & 0 deletions rss/magpie/magpie/cookbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
MAGPIERSS RECIPES: Cooking with Corbies

"Four and twenty blackbirds baked in a pie."

1. LIMIT THE NUMBER OF HEADLINES(AKA ITEMS) RETURNED.

PROBLEM:

You want to display the 10 (or 3) most recent headlines, but the RSS feed
contains 15.

SOLUTION:

$num_items = 10;
$rss = fetch_rss($url);

$items = array_slice($rss->items, 0, $num_items);

DISCUSSION:

Rather then trying to limit the number of items Magpie parses, a much simpler,
and more flexible approach is to take a "slice" of the array of items. And
array_slice() is smart enough to do the right thing if the feed has less items
then $num_items.

See: http://www.php.net/array_slice


2. DISPLAY A CUSTOM ERROR MESSAGE IF SOMETHING GOES WRONG

PROBLEM:

You don't want Magpie's error messages showing up if something goes wrong.

SOLUTION:

# Magpie throws USER_WARNINGS only
# so you can cloak these, by only showing ERRORs
error_reporting(E_ERROR);

# check the return value of fetch_rss()

$rss = fetch_rss($url);

if ( $rss ) {
...display rss feed...
}
else {
echo "An error occured! " .
"Consider donating more $$$ for restoration of services." .
"<br>Error Message: " . magpie_error();
}

DISCUSSION:

MagpieRSS triggers a warning in a number of circumstances. The 2 most common
circumstances are: if the specified RSS file isn't properly formed (usually
because it includes illegal HTML), or if Magpie can't download the remote RSS
file, and there is no cached version.

If you don't want your users to see these warnings change your error_reporting
settings to only display ERRORs. Another option is to turn off display_error,
so that WARNINGs, and NOTICEs still go to the error_log but not to the webpages.

You can do this with:

ini_set('display_errors', 0);

See: http://www.php.net/error_reporting,
http://www.php.net/ini_set,
http://www.php.net/manual/en/ref.errorfunc.php

3. GENERATE A NEW RSS FEED

PROBLEM:

Create an RSS feed for other people to use.

SOLUTION:

Use Useful Inc's RSSWriter (http://usefulinc.com/rss/rsswriter/)

DISCUSSION:

An example of turning a Magpie parsed RSS object back into an RSS file is forth
coming. In the meantime RSSWriter has great documentation.

4. DISPLAY HEADLINES MORE RECENT THEN X DATE

PROBLEM:

You only want to display headlines that were published on, or after a certain
date.


SOLUTION:

require 'rss_utils.inc';

# get all headlines published today
$today = getdate();

# today, 12AM
$date = mktime(0,0,0,$today['mon'], $today['mday'], $today['year']);

$rss = fetch_rss($url);

foreach ( $rss->items as $item ) {
$published = parse_w3cdtf($item['dc']['date']);
if ( $published >= $date ) {
echo "Title: " . $item['title'];
echo "Published: " . date("h:i:s A", $published);
echo "<p>";
}
}

DISCUSSION:

This recipe only works for RSS 1.0 feeds that include the <dc:date> field.
(which is very good RSS style)

parse_w3cdtf is defined in rss_utils.inc, and parses RSS style dates into Unix
epoch seconds.

See: http://www.php.net/manual/en/ref.datetime.php
Loading

0 comments on commit 29a6bbd

Please sign in to comment.