Welcome, Guest. Please login or register.

ShoutBox!

 

Skhilled

2024-08-09, 18:19:29
Awww! Poor thing! LOL
 

Ken

2024-08-09, 09:20:52
 

Skhilled

2024-07-06, 10:33:18
 :D
 

Ken

2024-07-06, 06:40:47
Happy Saturday after the 4th of July!
 :fireworks:
 

Skhilled

2024-07-04, 20:27:02
Happy Day Off From Work!  :D
 

Ken

2024-06-25, 06:23:12
84... who knew?  laughing7
...2013 was my *magic* year
 

Skhilled

2024-06-14, 22:09:12
I hope so! LOL
 

Ken

2024-06-14, 21:41:30
My B-Day is forthcoming and maybe it will be far enough along so that I can be a regular Dancing Fool for that day!!! :banana: :2funny:
 

Ken

2024-06-14, 21:38:38
Happy Friday everyone! I'm  SOOO glad to see Friday and not just because it's the weekend, but because it marks one more day in the recovery of my foot!  laughing7

Scrubmeister

2024-04-19, 10:32:40
Good to see the site back faster than ever. :)

Recent Topics

TP Articles


Search in titles
Search in article texts

Author Topic: Garfield & Dilbert Cartoons  (Read 3041 times)

0 Members and 2 Guests are viewing this topic.

Online Ken (OP)

  • Vietnam Era Veteran
  • Administrator
  • *
  • Posts: 11942
  • Gender: Male
  • View Gallery
Garfield & Dilbert Cartoons
« on: July 05, 2010, 07:29:08 PM »
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:
Code: [Select]
/*
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);
}
"Not all who wander are lost."-Tolkien
Yesterday When I was Young.