Example:     1 - Is the XML tag empty?
Level:       Simple
Description: This example template uses a very simple table to display a
             feed.  The PHP code is used to check if ~~~ItemLink~~~ is
             blank.  If it is blank only the title is display.  If it is
             not blank, the title is made into a link.

<<<<<<<<<<<<<<<<<<<<<<<<<<< START OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>~~~FeedTitle~~~</title>
  </head>
  <body>
    <h1>~~~FeedTitle~~~</h1>
    <p>~~~FeedDescription~~~</p>
    <hr>
    <table width="100%">
      ~~~BeginItemsRecord~~~
      <tr><td>~~~ItemPubShortDate~~~ ~~~ItemPubShortTime~~~</td></tr>
      <tr><td>
<?php
// Is the Item Link blank?
if ("~~~ItemLink~~~" != "") {
  // No it was not blank
  echo "<a href=\"~~~ItemLink~~~\">~~~ItemTitle~~~</a>";
} else {
  // Yes it was blank
  echo "~~~ItemTitle~~~";
}
?>
      </td></tr>
      <tr><td>~~~ItemDescription~~~</td></tr>
      <tr><td><hr></td></tr>
      ~~~EndItemsRecord~~~
    </table>
  </body>
</html>
<<<<<<<<<<<<<<<<<<<<<<<<<<<< END OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Example:     2 - How old is this item?
Level:       Medium
Description: This example template uses a very simple table to display a
             feed.  The PHP code will only display item that between 24
	     and 72 hours old.

<<<<<<<<<<<<<<<<<<<<<<<<<<< START OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>~~~FeedTitle~~~</title>
  </head>
  <body>
    <h1>~~~FeedTitle~~~</h1>
    <p>~~~FeedDescription~~~</p>
    <hr>
    <table width="100%">
      ~~~BeginItemsRecord~~~
<?php
$okayToDisplay = 0;

// Only find the time/date of an item if there was a PubDate
if ("~~~ItemPubDate~~~" != "" ){
  $pubDateTime = strtotime("~~~ItemPubDate~~~");
  $now = time();
  if ((24*60*60 <= ($now - $pubDateTime)) && (($now - $pubDateTime) <= 72*60*60)) {
    $okayToDisplay = 1;
  }
}

if ($okayToDisplay == 1) {
  echo "<tr><td>~~~ItemPubShortDate~~~ ~~~ItemPubShortTime~~~</td></tr>";
  echo "<tr><td>~~~ItemTitle~~~</td></tr>";
  echo "<tr><td>~~~ItemDescription~~~</td></tr>";
  echo "<tr><td><hr></td></tr>";
}
?>
      ~~~EndItemsRecord~~~
    </table>
  </body>
</html>
<<<<<<<<<<<<<<<<<<<<<<<<<<<< END OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Example:     3 - Does the title or description contain this word?
Level:       Medium
Description: This example template uses a very simple table to display a
             feed.  The PHP code will look for certian words in the title
	     or description of the items, and only those that have it.
	     NOTE: stristr() is use to prevent problems with captial letters

<<<<<<<<<<<<<<<<<<<<<<<<<<< START OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>~~~FeedTitle~~~</title>
  </head>
  <body>
    <h1>~~~FeedTitle~~~</h1>
    <p>~~~FeedDescription~~~</p>
    <hr>
    <table width="100%">
      ~~~BeginItemsRecord~~~
<?php
$okayToDisplay = 0;

// Look for the words "puppy" or "puppies"
if ((stristr("~~~ItemTitle~~~", "puppy") !== FALSE) || 
    (stristr("~~~ItemDescription~~~", "puppy") !== FALSE) ||
    (stristr("~~~ItemTitle~~~", "puppies") !== FALSE) || 
    (stristr("~~~ItemDescription~~~", "puppies") !== FALSE)) {
  $okayToDisplay = 1;
}

if ($okayToDisplay == 1) {
?>
      <tr><td>~~~ItemPubShortDate~~~ ~~~ItemPubShortTime~~~</td></tr>
      <tr><td>~~~ItemTitle~~~</td></tr>
      <tr><td>~~~ItemDescription~~~</td></tr>
      <tr><td><hr></td></tr>
<?php
}
?>
      ~~~EndItemsRecord~~~
    </table>
  </body>
</html>
<<<<<<<<<<<<<<<<<<<<<<<<<<<< END OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Example:     4 - Get the image embedded in the description
Level:       Advanced
Description: This example template uses a very simple table to display an 
	     items image embedded in the description.  The PHP code will extract
	     the image, if any and display it in a seperate column and
	     remove it from the description.

<<<<<<<<<<<<<<<<<<<<<<<<<<< START OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>~~~FeedTitle~~~</title>
  </head>
  <body>
    <h1>~~~FeedTitle~~~</h1>
    <p>~~~FeedDescription~~~</p>
    <hr>
    <table width="100%">
      ~~~BeginItemsRecord~~~
<?php
// Set initial values for our variables
$theImage = "&nbsp;"; // To ensure proper display with borders
$newDescription = "~~~ItemDescription~~~";
$match = Array();

// Use regular expressions to find <img ... >
if (preg_match("/<img[^>]*>/", $newDescription, $match) !== FALSE) {
  // Make sure it truely was a match
  if ((count($match) != 0) && ($match[0] != "")) {
    // Save the image
    $theImage = $match[0];
    // Remove the image from the description
    $newDescription = str_replace($match[0], "", $newDescription);
  }
}

echo "<tr><td>$theImage</td><td>~~~ItemPubShortDate~~~ ~~~ItemPubShortTime~~~<br>";
echo "~~~ItemTitle~~~<br>";
echo "$newDescription</td></tr>";
echo "<tr><td colspan=\"2\"><hr></td></tr>";
?>
      ~~~EndItemsRecord~~~
    </table>
  </body>
</html>
<<<<<<<<<<<<<<<<<<<<<<<<<<<< END OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Example:     5 - Don't display items with duplicate titles or links
Level:       Advanced
Description: This example builds an array of the titles and links of each 
       item.  It then check to make sure that they haven't been used before.

<<<<<<<<<<<<<<<<<<<<<<<<<<< START OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<?php
$titleArray = Array();
$linkArray = Array();
?>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>~~~FeedTitle~~~</title>
  </head>
  <body>
    <h1>~~~FeedTitle~~~</h1>
    <p>~~~FeedDescription~~~</p>
    <hr>
    <table width="100%">
      ~~~BeginItemsRecord~~~
<?php
$okayToDisplay = 1;

//
// Add the current item title and link to the arrays
$titleArray[] = "~~~ItemTitle~~~";
$linkArray[] = "~~~ItemLink~~~";

for ($x = 0; $x < count($titleArray)-1; $x++) {
  //
  // Look to see if there were previously used.
  if (("~~~ItemTitle~~~" == $titleArray[$x]) || ("~~~ItemLink~~~" == $linkArray[$x])) {
    $okayToDisplay = 0;
    break;
  }
}

if ($okayToDisplay == 1) {
?>
      <tr><td>~~~ItemPubShortDate~~~ ~~~ItemPubShortTime~~~</td></tr>
      <tr><td>~~~ItemTitle~~~</td></tr>
      <tr><td>~~~ItemDescription~~~</td></tr>
      <tr><td><hr></td></tr>
<?php
}
?>
      ~~~EndItemsRecord~~~
    </table>
  </body>
</html>
<<<<<<<<<<<<<<<<<<<<<<<<<<<< END OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Example:     6 - Convert any <img> tags to XHTML 1.0 compliant format 
Level:       Advanced
Description: XHTML 1.0 is much more strict about tags and attributes.  </img>
       is not part of XHTML, so remove it.  <img> requires the ending slash
       so make sure it is in the format <img ..... />.  Lastly make sure 
       there is a alt="" tag.

<<<<<<<<<<<<<<<<<<<<<<<<<<< START OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<?php
Function convertToXHTML_img($source) {
  // Since <img> has not closing tag, remove all
  $newDescription = str_replace("</img>", "", "There is no img tag");
  
  // Use regular expressions to find <img ... >
  if (preg_match_all("/<img[^>]*>/i", $newDescription, $match) !== FALSE) {
    // Make sure it truely was a match
    for ($x = 0; $x < count($match[0]); $x++) {
      if ($match[0][$x] != "") {
        // Save the image
        $theImage = $match[0][$x];
        
        // If the tag isn't closed with />, make it so
        if (stristr(str_replace(" ", "", $theImage), "/>") === FALSE) {
          $theImage = str_replace(">", "/>", $theImage);
        }
        
        // Check for the alt="" tag
        if (stristr(str_replace(" ", "", $theImage), "alt=") === FALSE) {
          $theImage = str_replace("/>", " alt=\"\" />", $theImage);
        }
        
        // Remove the image from the description
        $newDescription = str_replace($match[0][$x], $theImage, $newDescription);
      }
    }
  }
  
  return $newDescription;
}
?>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>~~~FeedTitle~~~</title>
  </head>
  <body>
    <h1>~~~FeedTitle~~~</h1>
    <p><?php echo convertToXHTML_img("~~~FeedDescription~~~"); ?></p>
    <hr>
    <table width="100%">
      ~~~BeginItemsRecord~~~
      <tr><td>~~~ItemPubShortDate~~~ ~~~ItemPubShortTime~~~</td></tr>
      <tr><td>~~~ItemTitle~~~</td></tr>
      <tr><td><?php echo convertToXHTML_img("~~~ItemDescription~~~"); ?></td></tr>
      <tr><td><hr></td></tr>
      ~~~EndItemsRecord~~~
    </table>
  </body>
</html>
<<<<<<<<<<<<<<<<<<<<<<<<<<<< END OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 


Example:     7 - Allow paging long feeds 
Level:       Advanced
Description: An example of how to limit the number of items displayed on 
       a page for long feeds 

<<<<<<<<<<<<<<<<<<<<<<<<<<< START OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<html>
<?php
$itemsPerPage = 10;
$numItems = "~~~NumberOfFeedItems~~~";

$onePage = 1;
$startNumber = 0;
if ($numItems > $itemsPerPage) {
  $onePage = 0;
  // Check for requested starting position
  if (isset($_REQUEST["ItemNumber"])) {
    $startNumber = $_REQUEST["ItemNumber"];
  }
  
  // Validate starting position
  if ($startNumber > $numItems) {
    $startNumber = 0;
  }
}

$pageString = "";
// Create the list of pages, if needed
if ($onePage == 0) {
  $Qparts = Array();
  $parts = explode("&", $_SERVER["QUERY_STRING"]);
  if (count($parts) > 0) {
    foreach ($parts as $value) {
      if (substr($value, 0, 10) != "ItemNumber") {
        $Qparts[] = $value;
      }
    }
    if (count($Qparts) == 0) {
      $Qstring = "";
    }
    elseif (count($Qparts) == 1) {
      $Qstring = $Qparts[0]."&amp;";
    } else {
      $Qstring = implode("&amp;", $Qparts)."&amp;";
    }
  }
  
  //
  // Previous Page
  $pageString = "<strong>";
  if ($startNumber > 0) {
    $newStartIndex = $startNumber - $itemsPerPage;
    if ($newStartIndex < 0) {
      $newStartIndex = 0;
    }
    $pageString .= "<a href=\"$_SERVER[PHP_SELF]?$Qstring"."ItemNumber=$newStartIndex\">Previous</a>&nbsp;&nbsp;&nbsp;&nbsp;";
  }

  //
  // The jump to page markers
  if ($numItems > $itemsPerPage) {
    $tempPages = (int)(($numItems / $itemsPerPage) + 1);
    $x = 1;
    if ($tempPages > 12) {
      // There are too many pages to fit across
      if ((($startNumber+1)/10) > 7) {
        $pageString .= "...&nbsp;&nbsp;&nbsp;&nbsp;";
        $x = 1 + (int)(($startNumber+1)/10) - 6;
      }
    }

    for ($y = 0; $x <= $tempPages; $x++, $y++) {
      $tempStart = ($itemsPerPage * ($x - 1));
      if (($tempStart <= $startNumber) && ($startNumber < ($tempStart + $itemsPerPage))) {
        $pageString .= "$x&nbsp;&nbsp;&nbsp;&nbsp;";
      } else {
        $pageString .= "<a href=\"$_SERVER[PHP_SELF]?$Qstring"."ItemNumber=$tempStart\">$x</a>&nbsp;&nbsp;&nbsp;&nbsp;";
      }
      if ($y >= 12) {
        $pageString .= "...&nbsp;&nbsp;&nbsp;&nbsp;";
        break;
      }
    }
  }

  //
  // Next Page
  if ($startNumber + $itemsPerPage <= $numItems) {
    $pageString .= "<a href=\"$_SERVER[PHP_SELF]?$Qstring"."ItemNumber=".($startNumber + $itemsPerPage)."\">Next</a>";
  }
  $pageString .= "</strong>";
}

?>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>~~~FeedTitle~~~</title>
  </head>
  <body>
    <h1>~~~FeedTitle~~~</h1>
    <p>~~~FeedDescription~~~</p>
    <hr>
<?php
echo "$pageString<br>\n";
$x = 0;
?>
    <table width="100%">
      ~~~BeginItemsRecord~~~
<?php
if ($onePage == 0) {
  if (($startNumber <= $x) && ($x < $startNumber+$itemsPerPage)) {
?>
      <tr><td>~~~ItemPubShortDate~~~ ~~~ItemPubShortTime~~~</td></tr>
      <tr><td><a href="~~~ItemLink~~~">~~~ItemTitle~~~</a></td></tr>
      <tr><td>~~~ItemDescription~~~</td></tr>
      <tr><td><hr></td></tr>
<?php
  }
  $x++;
}
?>
      ~~~EndItemsRecord~~~
    </table>
<?php
echo "$pageString<br>\n";
?>
  </body>
</html>
<<<<<<<<<<<<<<<<<<<<<<<<<<<< END OF FILE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
Copyright 2006-2007 NotePage, Inc. All rights reserved

$Id: rss2html-pro-examples.txt,v 3.1 2007/07/16 16:51:37 housley Exp $
