Warwick Blogs Grabber
About
Warwick Blogs Grabber is a PHP script I wrote to grab and process the RSS feed for my Warwick University blog so I could display it on my website, and thanks to the flexibility of Warwick Blogs' RSS feeds the number of entries shown is customisable.
Because the "Title" in all the RSS feeds is always the main title of the blog, the page title can be manually set if the feed is not the main feed (the feed for a tag, for example).
The author of an entry is not output by default, however it is extracted from the feed. If the author is required (for multi-user blogs, for example) then the appropriate code can be easily added or a "custom" display used (see below).
Since RSS is theoretically a standard, WBG should work with non-Warwick-Blogs feeds but may need some tweaking.
As of version Foxtrot it is now possible to use the script more than once on a single page.
Example
The examples with their own page do not include the CSS for the rest of this site.
Normal display
The "Normal" example his its own page.
List display
- Not to blow my own party blower... by - 10 Nov 2008
- Google App Engine is quite easy to use by - 26 Jun 2008
- Parking Fail by - 25 Jun 2008
- Hmmm... that's disappointing by - 18 Jun 2008
- It's Firefox 3 Download Day by - 17 Jun 2008
- There's this Nigerian prince I know that needs to get some money out of the country... by - 16 Jun 2008
- Up Up Down Down Left Right Left Right B A by - 15 Jun 2008
- It would be nice if Gmail could tell me itself... by - 15 Jun 2008
- I restarted about 10 times, but I got there in the end... by - 14 Jun 2008
- I have more spam than emails... by - 13 Jun 2008
Raw display
The "Raw" example his its own page.
The CSS used for the colours is:
<style type="text/css">
.highlight {color: #00f;}
.highlight .variable {color: #000;}
.highlight .array {color: #060;}
.highlight .bracket {color: #666;}
.highlight .value {color: #000;}
.highlight .key {color: #f00;}
</style>
NOTE: The "Raw" display is not necesarily a valid PHP array; it is merely a means of presentation.
Custom display
If the "Custom" display is chosen, Warwick Blogs Grabber will not output anything.
By default it generates an array of the entries and then outputs the array; with the "custom" display it only generates the array, allowing you to output the results however you wish.
As an example, the "Normal" display is generated by:
<?php
echo '<h1><a href="'.$bloglink.$blogurlsuffix.'" title="'.$blogdesc.'">'.$blogtitle.'</a></h1>
';
foreach($blogentries as $blogentry){
echo '
<!-- '.$blogentry["title"].' -->
<div class="section">
<h2><a href="'.$blogentry["link"].'">'.$blogentry["title"].'</a></h2>
'.$blogentry["desc"].'
<div class="details">
<b>Time: '.date("H:i:s", $blogentry["time"]).'</b><br />
<b>Date: '.date("D, d M Y", $blogentry["time"]).'</b><br />
<b>Tags:</b> '.$blogentry["tags"].'<br />
<b>Comments:</b> <a href="'.$blogentry["commenturl"].'">'.$blogentry["commentnum"].'</a>
</div>
</div>
';
}
blognextprev($entrynum, $page, $displaynum, $firstlink, $prevlink, $nextlink);
?>
Using
Since the processing of the feeds is the same in each case, the 'engine' is a single file that's referenced by each page that needs it. The referencing page is also where the options are set.
Set up
<?php
$wbrssurl='http://blogs.warwick.ac.uk/richardwinskill/tag/
video/?rss=rss_2_0';
$wbmainfeed=0;
$zpagetitle='Entries tagged with "Video"';
$displaynum=10;
$firstlink='<< Newest entries'
$prevlink='< Newer entries'
$nextlink='Older entries >'
$blogsort="none"
$blogdisplay="normal"
include 'wbengine.php';
?>
Explanation
$wbrssurl- Required - This is the URL of the RSS feed; nothing can happen without it. Make sure you don't specify a normal page by mistake; WBG will still try its best to process it...$wbmainfeed- Required - Used to specify whether or not the feed is the main feed for the blog. If this is set to1the URL and title of the page will be taken from the feed (which always displays the main blog's details); if this is set to0the URL will be taken from the specified URL of the feed and the title will be taken from the$zpagetitlevariable.$zpagetitle- Used to set the page title to something other than the main blog's title. If it's missing the main blog's title from the feed will be used. This is only used if$wbmainfeedis set to0.$displaynum- The number of entries to show on one page. If this is not specified or is negative then the default of10will be used.$firstlink- The text for the link pointing to the first page (if necessary). Has a default if not specified.$prevlink- The text for the link pointing to the previous page (if necessary). Has a default if not specified.$nextlink- The text for the link pointing to the next page (if necessary). Has a default if not specified.$blogsort- Added in version Delta. Specifies how the entries are sorted. Can be set to "title" to sort by title, "reverse title" to reverse sort by title, "reverse" to reverse sort, or can be omitted to leave the entries in their original order.$blogdisplay- Added in version Delta. Specifies how the entries will be output. Can be set to "raw" (example "Raw" above), "list" (example "List" above), or "custom" (example "Custom" above). It will default to the "Normal" example above if nothing is specified.include 'wbengine.php';- Required - The line that actualy includes the engine. To be effective, all the options must be specified before this line. Remember to change this to reflect the location ofwbengine.phpon your server.
Custom Output
For custom output, with $blogdisplay set to "custom", Warwick Blogs Grabber will compile the $blogentries array but will not output it. This allows you to output the entries however you want. The best way to see the structure of the array is to first use the "raw" display option; this will output the array using HTML formatting (i.e. it will display correctly as a normal webpage). After that you can use your favourite method for looping through an array (such as foreach() in the example above) and then reference each item as you need it.
Most of the data is in its "raw" form; i.e. the link is the URL not an A tag, etc.
However:
- The "tags" are already links; they can just be output without futher work.
- The "time" is just a timecode; it will need formatting with
date().
Powered by WarwickBlogsGrabber
If you use Warwick Blogs Grabber, I'd be grateful if you could put this image in the root directory of your website (that's where the code looks):

Download
To download Warwick Blogs Grabber just right-click and choose "Save As" (or the equivalent for your Operating System/Web Browser).
The current version is Foxtrot (2008-07-06) - No changelog.
There's now an RSS feed for easy notification of the infrequent updates to all 6 times 9 projects.
Feedback
I'd like to hear what you have to say about Warwick Blogs Grabber; if you have any comments, compliments, problems, or suggestions feel free to email me and let me know.