We've changed the cartoons displayed at the bottom of the forum page, the daily Dilbert cartoon was turned off and the Garfield daily was turned on. :bigteeth:
I edited the code that was originally posted on the TinyPortal site by Freddy and reused it for this Garfield feed. If you would like to see what the code looks like, here 'tis:
/*
A PHP block with code that accesses the Garfield RSS feed and returns
a set number of cartoons.
Original RSS feed code author unknown.
Adapted by freddy888 March 2010
@ Tiny Portal - http://www.tinyportal.net/index.php?topic=32155
NOTE: Freddys original code was set for the Dilbert cartoon; it was
edited to display the daily Garfield cartoon by Ken. July 2010.
@ Our FamilyForum - http://www.ourfamilyforum.org/FamilyForum/index.php?topic=2446.0
*/
global $cartoonCount, $cartoonLimit;
// Set this to how many cartoons you want to display.
$cartoonLimit = 1;
// Set the feed where Garfield is located.
$rssFeed = 'http://www.arcamax.com/garfield/channelfeed';
// Will count the number of cartoons found.
$cartoonCount = 0;
DIL_readFeeds($rssFeed);
function DIL_start_Element($xp, $name, $attributes)
{
global $item,$currentElement; $currentElement = $name;
//the other functions will always know which element we're parsing
if ($currentElement == 'ITEM')
{
//by default PHP converts everything to uppercase
$item = true;
// We're only interested in the contents of the item element.
// This flag keeps track of where we are
}
}
function DIL_end_Element($xp,$name)
{
global $item, $currentElement, $title, $description, $link, $pubdate, $cartoonCount, $cartoonLimit;
if ($name == 'ITEM')
{
// If we're at the end of the item element, display
// the data, and reset the globals
$title = strip_tags($title);
// Remove everything apart from images.
$description = strip_tags($description, '<img>');
// Find the end of the first image which is the cartoon.
$firstImageEnd = stripos($description, '>');
// Extract the cartoon image only, which happens to be first.
$cartoon = substr($description, 0, $firstImageEnd + 1);
// Insert alt and title attributes
$cartoon = str_replace('/>', 'alt="Dilbert ' . $title . '" title="Dilbert ' . $title . '" />', $cartoon);
// Are we up to our cartoon limit ? If not then display the cartoon.
if ($cartoonCount < $cartoonLimit)
echo '
<div style="margin: 15px; text-align: center">
<a href="' , $link , '" target="_blank">' , $cartoon , '</a>
</div>';
$title = '';
$description = '';
$link = '';
$pubdate = '';
$item = false;
$cartoonCount += 1;
}
}
function DIL_characterDataHandler($xp,$data)
{
global $item, $currentElement, $title, $description, $link, $pubdate;
if ($item)
{
//Only add to the globals if we're inside an item element.
switch($currentElement)
{
case "TITLE":
$title .= $data;
// We use .= because this function may be called multiple
// times for one element.
break;
case "DESCRIPTION":
$description.=$data;
break;
case "LINK":
$link.=$data;
break;
case "PUBDATE":
$pubdate.=$data;
break;
}
}
}
function DIL_readFeeds($feed)
{
$fh = fopen($feed,'r');
// open file for reading
$xp = xml_parser_create();
// Create an XML parser resource
xml_set_element_handler($xp, "DIL_start_Element", "DIL_end_Element");
// defines which functions to call when element started/ended
xml_set_character_data_handler($xp, "DIL_characterDataHandler");
while ($data = fread($fh, 4096))
{
if (!xml_parse($xp,$data))
{
return 'Error in the feed';
}
}
xml_parser_free($xp);
}