PageRenderTime 94ms CodeModel.GetById 15ms app.highlight 67ms RepoModel.GetById 1ms app.codeStats 1ms

/admin/inc/rss2html.php

http://winn-guestbook.googlecode.com/
PHP | 1254 lines | 767 code | 51 blank | 436 comment | 124 complexity | 33e857ca5bedf0079f1b98630ea5b07c MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?PHP
   2//
   3// rss2html.php RSS feed to HTML webpage script
   4//
   5// Copyright 2004-2007 NotePage, Inc.
   6// http://www.feedforall.com
   7//
   8// This script may be used and modified freely for business or personal use
   9// This script may not be resold in any form
  10// This script may only be redistributed in its original form
  11//
  12//
  13// $Id: rss2html.php,v 3.10 2007/07/16 16:48:48 housley Exp $
  14//
  15
  16//
  17// ==========================================================================
  18// Configuration options
  19// ==========================================================================
  20//
  21// Set the following variable useFopenURL to one if you want/need to use
  22// fopen() instead of CURL or FeedForAll_fopen()
  23$useFopenURL = 0;
  24
  25//
  26// If XLMFILE is passed as part of the URL, XMLFILE=, then it will be used
  27// otherwise the the file below is used.
  28//$XMLfilename = "http://examlple.com/sample.xml";
  29$XMLfilename = "http://feeds.feedburner.com/GregWinn-Design";
  30
  31//
  32// If TEMPLATE is passed as part of the URL. TEMPLATE=, then it will be used
  33// otherwise the the file below is used.
  34//$TEMPLATEfilename = "http://examlple.com/sample-template.html";
  35$TEMPLATEfilename = "inc/sample-template.html";
  36
  37//
  38// Since some feeds may have titles or descriptins in the feed or items that
  39// are longer then want fits in your HTML page it is possible to trim them
  40// with the following 4 variables.  A values of 0 (ZERO) displays the full
  41// length.
  42// CAUTION:  Do not limit a title or description that has HTML in it, the
  43//           will not produce a valid HTML page.
  44$limitFeedTitleLength = 0;        // Not limited, in the URL as FeedTitleLength=
  45$limitFeedDescriptionLength = 0;  // Not limited, in the URL as FeedDescriptionLength=
  46$limitItemTitleLength = 0;        // Not limited, in the URL as ItemTitleLength=
  47$limitItemDescriptionLength = 0;  // Not limited, in the URL as ItemDescriptionLength=
  48
  49//
  50// date() function documented http://www.php.net/manual/en/function.date.php
  51$LongDateFormat = "F jS, Y";    // ie, "Jan 21st, 2004"
  52$ShortDateFormat = "m/d/Y";     // ie, "1/21/2004"
  53//$ShortDateFormat = "d/m/Y";     // ie, "21/1/2004"
  54$LongTimeFormat = "H:i:s T O";  // ie, "13:24:30 EDT -0400"
  55$ShortTimeFormat = "h:i A";     // ie, "1:24 PM"
  56
  57//
  58// Timezone - If your server is not in the same timezone as you are the timezone
  59// of the times and dates produced in the above from can be controlled with the
  60// below code.  Just uncomment the following line and change to the correct
  61// zonename.  A full list is available here, http://www.php.net/manual/en/timezones.php
  62// You town.city probably isn't listed, so look for a neighboring major city
  63// putenv("TZ=America/New_York");
  64
  65//
  66// Registered user of FeedForAll and FeedForAll Mac product(s) have access
  67// to a caching module.  This enables it's use if it is installed.
  68$allowCachingXMLFiles = 0;
  69
  70//
  71// File access level:  The variable $fileAccessLevel can be used limit what files
  72// and type of files (local or remote) can be used with rss2html.php
  73// -1 = Remote files are NOT allowed, only local files allowed for template
  74//      and feed which have filenames ending in extensions in the
  75//      $allowedTemplateExtensions and $allowedFeedExtensions lists below
  76//  0 = Remote files and any local files allowed for template and feed
  77//  1 = Remote files and only local files allowed for template and feed
  78//      which have filenames ending in extensions in the
  79//      $allowedTemplateExtensions and $allowedFeedExtensions lists below
  80//  2 = No local files allowed, remote files only.
  81$fileAccessLevel = 1;
  82
  83//
  84// Allowed file extensions is a list of the allowable extensions for local for
  85// the template and the feed.  New entries can be added by following the example
  86// below.
  87$allowedTemplateExtensions = Array(".html", ".htm", ".shtml");
  88$allowedFeedExtensions = Array(".xml", ".rss", ".php", "");
  89
  90//
  91// Destination Encoding:  By default rss2html.php converts all feeds to UTF-8
  92// and then produces webpages in UTF-8 because UTF-8 is capable of displaying
  93// all possible characters.
  94$destinationEncoding = "UTF-8";
  95
  96//
  97// Missing Encoding Default:  Some feeds do not specify the character set 
  98// they are encoded in.  The XML specification states that if there is no
  99// encoding specified the XML file, all RSS feeds are XML, must be encoded
 100// in UTF-8, but experience has show differently.  This specifies the 
 101// encoding that will be used for feeds that don't specify the encoding.
 102//$missingEncodingDefault = "UTF-8";
 103$missingEncodingDefault = "ISO-8859-1";
 104
 105//
 106// Escape Ampersand In Links:  Proper HTML requires that a link with an
 107// apersand in while inside of an HTML page have that '&' converted to
 108// '&amp;'.
 109$escapeAmpInLinks = 1;
 110
 111//
 112// $connectTimeoutLimit allows the limiting the amount of time cURL will
 113// wait to successfully connect to a remote server.  Use with caution,
 114// a value too small will cause all connections to fail.
 115//$connectTimeoutLimit = 30;
 116
 117//
 118// $hideErrors: This will prevent all error messages from being displayed.
 119// CAUTION enabling this will cause rss2html.php to fail silently with
 120// no indication to why there was no output
 121// $hideErrors = 1;
 122
 123// ==========================================================================
 124// Below this point of the file there are no user editable options.  Your
 125// are welcome to make any modifications that you wish to any of the code
 126// below, but that is not necessary for normal use.
 127// ==========================================================================
 128
 129// $Log: rss2html.php,v $
 130// Revision 3.10  2007/07/16 16:48:48  housley
 131// On some systems the exit statements in here was terminating all PHP
 132// processing.
 133//
 134// Revision 3.9  2007/07/16 13:06:37  housley
 135// Add ~~~NumberOfFeedItems~~~ to allow access to the number of items that
 136// will be processed for display.
 137//
 138// Revision 3.8  2007/07/08 13:42:39  housley
 139// Create my own version of fopen() to try and get files when cURL is not
 140// available.  FeedForAll_fopen() is based on just connecting to the server
 141// and reading the results.
 142//
 143// Revision 3.7  2007/06/25 13:55:10  housley
 144// Fix mistake where ?buildURL would falsely say a file could be opened,
 145// when in reality it could not be opened
 146//
 147// Revision 3.6  2007/06/05 13:39:38  housley
 148// Enable access to output caching in rss2html.php
 149//
 150// Revision 3.5  2007/05/27 14:32:05  housley
 151// Add a debug message when switching to fopen() because curl_init() does
 152// not exist
 153//
 154// Revision 3.4  2007/05/04 11:54:19  housley
 155// When checking for caching, check a function only in the caching module
 156//
 157// Revision 3.3  2007/05/03 18:52:16  housley
 158// Fix typo in debug statement
 159//
 160// Revision 3.2  2007/05/03 16:14:07  housley
 161// * It seems the XML parser doesn't like most of the HTML entities, process them by hand
 162// * The check to display errors was backwards
 163//
 164// Revision 3.1  2007/04/24 11:36:09  housley
 165// Fix an error that prevented using PHP includes to display more then one
 166// feed on a page
 167//
 168// Revision 3.0  2007/04/16 14:23:03  housley
 169// Release version 3.0 of the scripts
 170//
 171// Revision 2.76  2007/04/13 18:30:10  housley
 172// * Atom:content might need whole string so always make it available
 173// * atom:content of type xhtml is in a div that needs to be stripped and
 174//   then used as is.
 175//
 176// Revision 2.75  2007/04/11 19:59:43  housley
 177// Add an option to hide error messages
 178//
 179// Revision 2.74  2007/04/11 18:38:08  housley
 180// Update the user agent to be 3.0
 181//
 182// Revision 2.73  2007/04/11 12:13:12  housley
 183// * Fix the code to limit the number of items
 184// * Add some debug messages
 185//
 186// Revision 2.72  2007/04/11 10:40:38  housley
 187// Add some debug messages
 188//
 189// Revision 2.71  2007/04/10 17:16:45  housley
 190// Allow the input caching to be set during buildURL, only for one PHP include
 191// type
 192//
 193// Revision 2.70  2007/04/10 15:19:28  housley
 194// Allow for the caching for the HTML output of rss2html.php
 195//
 196// Revision 2.69  2007/04/04 20:55:46  housley
 197// Add the ability to set CURLOPT_CONNECTTIMEOUT
 198//
 199// Revision 2.68  2007/03/30 13:18:33  housley
 200// Use getArrayOfFields() and getValueOf() to simplfy tag replacement, except
 201// where special processing needs to be done
 202//
 203// Revision 2.67  2007/03/05 18:23:58  housley
 204// Don't abort processing on XML parse error, just don't do anything else
 205//
 206// Revision 2.66  2007/03/05 01:33:44  housley
 207// Use a command convert and readFile routines
 208//
 209// Revision 2.65  2007/03/05 01:19:45  housley
 210// Rename FeedForAll_rss2html_readFile() to FeedForAll_scripts_readFile()
 211//
 212// Revision 2.64  2007/03/04 13:41:53  housley
 213// * Pass the parsing mode to the item class
 214// * Cleanup the feed level processing
 215// * rss2html uses the separate parser too
 216//
 217// Revision 2.63  2007/03/03 21:10:09  housley
 218// * Make the item a full class object
 219// * Support parsing the iTunes(R) extension
 220//
 221// Revision 2.62  2007/02/26 00:33:53  housley
 222// Fix assignment in comparison
 223//
 224// Revision 2.61  2007/02/14 01:05:52  housley
 225// Add the option of encoding the '#' in URLs in some conditions
 226//
 227// Revision 2.60  2007/01/26 14:08:46  housley
 228// Show a better method to change timezone
 229//
 230// Revision 2.59  2007/01/04 19:01:51  housley
 231// Parse the new rssMesh.php fields:
 232//
 233// <rssMesh:feedImageTitle> => ~~~ItemRssMeshFeedImageTitle~~~
 234// <rssMesh:feedImageUrl> =>  ~~~ItemRssMeshFeedImageUrl~~~
 235// <rssMesh:feedImageLink> =>  ~~~ItemRssMeshFeedImageLink~~~
 236// <rssMesh:feedImageDescription> =>  ~~~ItemRssMeshFeedImageDescription~~~
 237// <rssMesh:feedImageHeight> =>  ~~~ItemRssMeshFeedImageHeight~~~
 238// <rssMesh:feedImageWidth> =>  ~~~ItemRssMeshFeedImageWidth~~~
 239//
 240// Revision 2.58  2006/12/22 16:30:21  housley
 241// Add a check to see if cURL is allowed to follow redirects
 242//
 243// Revision 2.57  2006/11/06 14:59:22  housley
 244// Minor text changes in buildURL
 245//
 246// Revision 2.56  2006/11/06 14:39:24  housley
 247// Create a new method of including rss2html.php that will work on servers
 248// with remote URL restrictions (allow_url_fopen) that many ISPs are currently
 249// using.
 250//
 251// Revision 2.55  2006/10/17 16:05:05  housley
 252// Since some of the newer versions of the XML parser look at the encoding
 253// in the feed and ignore the one passed in on the call, change the encoding
 254// in the feed before parsing.
 255//
 256// Revision 2.54  2006/09/29 19:50:33  housley
 257// Add a function to convert & in a certian RSS fields to &amp;, so it will be proper HTML
 258//
 259// Revision 2.53  2006/09/22 20:21:55  housley
 260// Fix the problem of displaying an invalid date with an odd number of items
 261//
 262// Revision 2.51  2006/09/04 12:33:17  housley
 263// Exit after a parser error.  The parser stopped, so should we.
 264//
 265// Revision 2.50  2006/08/29 18:58:38  housley
 266// Changes to handle when there are not string conversion modules
 267//
 268// Revision 2.49  2006/08/25 15:09:22  housley
 269// Add hooks for a new feature in rss2html-pro
 270//
 271// Revision 2.48  2006/08/25 11:36:37  housley
 272// * Add the capability to change the character set that feeds are converted to
 273// * Allow specifying the encoding to use for feeds that don't specify the encoding
 274//
 275// Revision 2.46  2006/08/24 20:23:56  housley
 276// Over come a well meaning, but very misguided ISP removing file:// from
 277// all scripts.  Not only did the remove it in a place that was doing good,
 278// it was extremely simple to bypass.
 279//
 280// Revision 2.45  2006/08/21 20:19:32  housley
 281// Use special routines so that rss2html-pro will work with RSS fields that
 282// have quotes in them.
 283//
 284// Revision 2.43  2006/08/18 23:42:16  housley
 285// Add hooks for rss2html-pro post processing
 286//
 287// Revision 2.42  2006/08/11 17:15:45  housley
 288// Add the ability to restrict the use of the rss2html.php script.
 289//
 290// Revision 2.41  2006/08/09 23:57:35  housley
 291// If <?xml ... is missing add it
 292//
 293// Revision 2.40  2006/08/09 15:32:58  housley
 294// If mb_string_convert fails, try iconv
 295//
 296// Revision 2.39  2006/08/04 19:59:02  housley
 297// Assuming 0xa9 is (c) was bad
 298//
 299// Revision 2.38  2006/08/03 11:06:45  housley
 300// * Don't change the encoding string in the header
 301// * Give access to the first category in a feed
 302//
 303// Revision 2.37  2006/07/29 14:29:40  housley
 304// Add support for <category> in items.  If there are more then one <category>
 305// element, only the first is accessable.  The 2 new tags are
 306// ~~~ItemCategory~~~ and ~~~ItemCategoryDomain~~~
 307//
 308// Revision 2.36  2006/07/29 13:19:23  housley
 309// Trim any leading BOM because some PHP5 installations have problems if it
 310// is there.
 311//
 312// Revision 2.35  2006/07/27 00:27:03  housley
 313// * Add support for <source> and <comments> in <item>
 314// * Add support for <rssMesh:extra>
 315//
 316// Revision 2.34  2006/07/21 12:23:36  housley
 317// * If there is no encoding, default to ISO-8859-1
 318// * Modify the XML to show the encoding we used
 319//
 320// Revision 2.33  2006/07/16 10:33:23  housley
 321// Force $useFopenURL if cURL is not installed
 322//
 323// Revision 2.32  2006/07/13 17:05:08  housley
 324// Remove space that causes problems
 325//
 326// Revision 2.31  2006/07/12 12:48:27  housley
 327// Try the iconv() conversion option if mb_string_encode() doesn't exist
 328//
 329// Revision 2.30  2006/05/28 17:52:10  housley
 330// Handle no encoding specified in the feed
 331//
 332// Revision 2.29  2006/05/28 17:51:28  housley
 333// Allow displaying of the Creative Commons License URL
 334//
 335// Revision 2.28  2006/05/28 14:21:47  housley
 336// Add additional capabilities to work with enclosures.  The 3 new fields are 
 337// ~~~ItemEnclosureType~~~, ~~~ItemEnclosureLength~~~ and ~~~ItemEnclosureLengthFormatted~~~
 338//
 339// Revision 2.27  2006/05/27 19:27:45  housley
 340// * Show a more universal TZ offset example
 341// * Make setting contentEncoded more robust
 342//
 343// Revision 2.26  2006/04/08 23:17:22  housley
 344// A "%" should not be encoded to "%2525", but to "%25"
 345//
 346// Revision 2.25  2006/04/08 23:16:17  housley
 347// Indicate that this is the last parse of XML
 348//
 349// Revision 2.24  2006/03/23 12:10:30  housley
 350// Add a simple way to change the timezone of produced times and dates
 351//
 352// Revision 2.23  2006/03/10 14:21:04  housley
 353// Update the licenses
 354//
 355// Revision 2.22  2006/03/06 15:01:57  housley
 356// Trim white space before and after the XML
 357//
 358// Revision 2.21  2006/03/05 15:15:11  housley
 359// Rename rss2html_CachingExtension.php to FeedForAll_Scripts_CachingExtension.php
 360//
 361// Revision 2.20  2006/03/05 14:43:59  housley
 362// Fix the testing for the character set conversion function
 363//
 364// Revision 2.19  2006/02/28 02:00:04  housley
 365// Add support for ~~~FeedXMLFilename~~~
 366//
 367// Revision 2.18  2006/02/26 15:24:15  housley
 368// Add the capability to limit the length of feed and item titles and descriptions
 369//
 370// Revision 2.17  2006/02/13 18:00:27  housley
 371// Fix the initialization of the item arrays
 372//
 373// Revision 2.16  2006/02/12 14:43:18  housley
 374// If possible convert the feed to UTF-8, for uniformity
 375//
 376// Revision 2.15  2006/02/12 00:21:13  housley
 377// Fix the offsetting of the time
 378//
 379// Revision 2.14  2006/01/26 15:52:37  housley
 380// Fix the error message for opening a feed, it was displaying the template filename.
 381//
 382// Revision 2.13  2006/01/08 23:25:44  housley
 383// Move all user configuration options at the top of the file to make them
 384// easier to find
 385//
 386// Revision 2.12  2005/12/12 16:27:26  housley
 387// Add an interface to allow FeedForAll_scripts_readFile() to be replaced
 388// by one that does caching of the XML files
 389//
 390// Revision 2.11  2005/12/09 19:08:26  housley
 391// Remove the first "banner" since IE barfs
 392//
 393// Revision 2.10  2005/10/22 18:51:47  housley
 394// Improve the formatting
 395//
 396// Revision 2.9  2005/10/22 14:27:57  housley
 397// Fix label in buildURL
 398//
 399// Revision 2.8  2005/10/22 14:20:31  housley
 400// Add buildURL to assist in creating properly encoded links.  Show proper
 401// include methods and contents of the files.
 402//
 403// Revision 2.7  2005/10/16 17:54:10  housley
 404// Improvements when using CURL:
 405// - Use the requested file as the REFERER, for sites that might require one
 406// - Allow to follow up to 10 redirects, some sites redirect to real content
 407//
 408// Revision 2.6  2005/10/16 17:32:27  housley
 409// Use lastBuildDate as another possible source if pubDate is empty at the
 410// <channel> level.
 411//
 412// Revision 2.5  2005/09/28 02:08:15  housley
 413// Fix the storage of pubDate at the feed level
 414//
 415// Revision 2.4  2005/09/12 18:56:31  housley
 416// Set a user agent for both fopen and curl transerfers
 417//
 418// Revision 2.3  2005/09/06 22:55:27  housley
 419// GUID doesn't need urlencode()
 420//
 421// Revision 2.2  2005/08/16 19:53:15  housley
 422// Add the ~~~ItemAuthor~~~ subsitution that uses first <author> and then
 423// <dc:creator> for its contents
 424//
 425// Revision 2.1  2005/08/15 14:49:24  housley
 426// Convert &apos; to ' since &apos; is not HTML
 427//
 428// Revision 2.0  2005/07/30 14:09:38  housley
 429// Allow "allow_url_fopen" to be sellected, incase CURL is not available.
 430//
 431//
 432
 433//
 434// If using cURL, make sure it exists
 435if (($useFopenURL == 0) && !function_exists("curl_init")) {
 436  $useFopenURL = -1;
 437  if (isset($debugLevel) && ($debugLevel >= 3)) {
 438    echo "DIAG: setting \$useFopenURL=-1 because curl_init() doesn't exist<br>\n";
 439  }
 440}
 441
 442if ($useFopenURL == 1) {
 443  ini_set("allow_url_fopen", "1");
 444  ini_set("user_agent", "FeedForAll rss2html scripts v3");
 445}
 446
 447$FeedMaxItems = 10000;
 448$NoFutureItems = FALSE;
 449
 450@include("FeedForAll_rss2html_pro.php");
 451
 452if (function_exists("FeedForAll_rss2html_pro") === FALSE) {
 453  Function FeedForAll_rss2html_pro($source) {
 454    //
 455    // This is the place to do any processing that is desired
 456    return $source;
 457  }
 458}
 459
 460if (function_exists("FeedForAll_parseExtensions") === FALSE) {
 461  Function FeedForAll_parseExtensions() {
 462    return FALSE;
 463  }
 464}
 465
 466@include("FeedForAll_Scripts_CachingExtension.php");
 467
 468@include_once("FeedForAll_XMLParser.inc.php");
 469
 470if (function_exists("FeedForAll_rss2html_limitLength") === FALSE) {
 471  Function FeedForAll_rss2html_limitLength($initialValue, $limit = 0) {
 472    if (($limit == 0) || (strlen($initialValue) <= $limit )) {
 473      // ZERO is for not limited
 474      return $initialValue;
 475    }
 476
 477    // Cut the text at the exact point, ignoring if it is in a word.
 478    $result = substr($initialValue, 0, $limit);
 479
 480    // Check to see if there are any space we can trim at and if it is not
 481    // too far from where we are
 482    $lastSpace = strrchr($result,' ');
 483    if (($lastSpace !== FALSE) && (strlen($lastSpace) < 20)) {
 484      // lose any incomplete word at the end
 485      $result = substr($result, 0, -(strlen($lastSpace)));
 486
 487      // Append elipses, ... , to show it was truncated
 488      $result .= " ...";
 489    }
 490
 491    return $result;
 492  }
 493}
 494
 495if (function_exists("FeedForAll_rss2html_sizeToString") === FALSE) {
 496  Function FeedForAll_rss2html_sizeToString($filesize) {
 497    if ($filesize == "") {
 498      return "";
 499    }
 500    elseif ($filesize >= 1073741824) {
 501      return number_format($filesize/1073741824, 1, ".", ",")." GBytes";
 502    }
 503    elseif ($filesize >= 1048576) {
 504      return number_format($filesize/1048576, 1, ".", ",")." MBytes";
 505    }
 506    elseif ($filesize >= 1024) {
 507      return number_format($filesize/1024, 1, ".", ",")." KBytes";
 508    }
 509    else {
 510      return $filesize." Bytes";
 511    }
 512  }
 513}
 514
 515if (function_exists("FeedForAll_rss2html_isTemplate") === FALSE) {
 516  Function FeedForAll_rss2html_isTemplate($templateData) {
 517    if ((strstr($templateData, "~~~Feed") !== FALSE) || (strstr($templateData, "~~~Item") !== FALSE)) {
 518      return TRUE;
 519    }
 520    return FALSE;
 521  }
 522}
 523
 524if (function_exists("FeedForAll_rss2html_validExtension") === FALSE) {
 525  Function FeedForAll_rss2html_validExtension($filename, $extensions) {
 526    $foundValid = FALSE;
 527    foreach ($extensions as $value) {
 528      if (strtolower($value) == strtolower(substr($filename, -strlen($value)))) {
 529        $foundValid = TRUE;
 530        break;
 531      }
 532    }
 533    return $foundValid;
 534  }
 535}
 536
 537if (function_exists("FeedForAll_rss2html_str_replace") === FALSE) {
 538  Function FeedForAll_rss2html_str_replace($search, $replace, $subject) {
 539    return str_replace($search, $replace, $subject);
 540  }
 541}
 542
 543if (function_exists("FeedForAll_rss2html_encodeURL") === FALSE) {
 544  Function FeedForAll_rss2html_encodeURL($URLstring, $includePND = 0) {
 545    $result = "";
 546    for ($x = 0; $x < strlen($URLstring); $x++) {
 547      if ($URLstring[$x] == '%') {
 548        $result = $result."%25";
 549      }
 550      elseif ($URLstring[$x] == '?') {
 551        $result = $result."%3f";
 552      }
 553      elseif ($URLstring[$x] == '&') {
 554        $result = $result."%26";
 555      }
 556      elseif ($URLstring[$x] == '=') {
 557        $result = $result."%3d";
 558      }
 559      elseif ($URLstring[$x] == '+') {
 560        $result = $result."%2b";
 561      }
 562      elseif ($URLstring[$x] == ' ') {
 563        $result = $result."%20";
 564      }
 565      elseif ($includePND && ($URLstring[$x] == '#')) {
 566        $result = $result."%23";
 567      }else {
 568        $result = $result.$URLstring[$x];
 569      }
 570    }
 571    return $result;
 572  }
 573}
 574
 575if (function_exists("FeedForAll_rss2html_CreateUniqueLink") === FALSE) {
 576  Function FeedForAll_rss2html_CreateUniqueLink($title, $description, $link, $guid, $XMLfilename, $itemTemplate) {
 577    GLOBAL $TEMPLATEfilename;
 578    $match = Array();
 579    
 580    while (preg_match("/~~~ItemUniqueLinkWithTemplate=.*~~~/", $itemTemplate, $match) !== FALSE) {
 581      if ((count($match) == 0) || ($match[0] == "")) {
 582        // All done
 583        return $itemTemplate;
 584      }
 585      
 586      $replace = "http://$_SERVER[SERVER_NAME]$_SERVER[SCRIPT_NAME]?XMLFILE=".FeedForAll_rss2html_encodeURL($XMLfilename)."&amp;TEMPLATE=".FeedForAll_rss2html_encodeURL($TEMPLATEfilename);
 587      $itemTemplate = FeedForAll_rss2html_str_replace($match[0], $replace, $itemTemplate);
 588    }
 589    if ($title);
 590    if ($description);
 591    if ($link);
 592    if ($guid);
 593    return $itemTemplate;
 594  }
 595}
 596
 597if (function_exists("FeedForAll_rss2html_UseUniqueLink") === FALSE) {
 598  Function FeedForAll_rss2html_UseUniqueLink($title, $description, $link, $guid) {
 599    if ($title);
 600    if ($description);
 601    if ($link);
 602    if ($guid);
 603    return -1;
 604  }
 605}
 606
 607if (function_exists("FeedForAll_rss2html_EscapeLink") === FALSE) {
 608  Function FeedForAll_rss2html_EscapeLink($link) {
 609    GLOBAL $escapeAmpInLinks;
 610    
 611    if ((strstr($link, "://") !== FALSE) && $escapeAmpInLinks) {
 612      // In HTML a link with an & must be converted to &amp;
 613      // And for here without :// it is not a link, since relative
 614      // URLs are not allowed
 615      $link = str_replace("&", "&amp;", $link);
 616    }
 617    return $link;
 618  }
 619}
 620
 621if (function_exists("FeedForAll_rss2html_AddIdentity") === FALSE) {
 622  Function FeedForAll_rss2html_AddIdentity($itemString) {
 623    return "<!-- HTML generated from an RSS Feed by rss2html.php, http://www.FeedForAll.com/ a NotePage, Inc. product (http://www.notepage.com/) -->".$itemString;
 624  }
 625}
 626
 627if (!isset($_REQUEST["buildURL"])) {
 628  //
 629  // Check variables that could be used if URL wrapper are disable or not working
 630  if (isset($GLOBALS["XMLFILE"])) {
 631    $XMLfilename = $GLOBALS["XMLFILE"];
 632  }
 633  if (isset($GLOBALS["TEMPLATE"])) {
 634    $TEMPLATEfilename = $GLOBALS["TEMPLATE"];
 635  }
 636  if (isset($GLOBALS["FeedTitleLength"])) {
 637    $limitFeedTitleLength = abs($GLOBALS["FeedTitleLength"]);
 638  }
 639  if (isset($GLOBALS["FeedDescriptionLength"])) {
 640    $limitFeedDescriptionLength = abs($GLOBALS["FeedDescriptionLength"]);
 641  }
 642  if (isset($GLOBALS["ItemTitleLength"])) {
 643    $limitItemTitleLength = abs($GLOBALS["ItemTitleLength"]);
 644  }
 645  if (isset($GLOBALS["ItemDescriptionLength"])) {
 646    $limitItemDescriptionLength = abs($GLOBALS["ItemDescriptionLength"]);
 647  }
 648  if (isset($GLOBALS["MAXITEMS"])) {
 649    $FeedMaxItems = $GLOBALS["MAXITEMS"];
 650  }
 651  if (isset($GLOBALS["NOFUTUREITEMS"])) {
 652    $NoFutureItems = TRUE;
 653  }
 654
 655  
 656  if (isset($_REQUEST["XMLFILE"])) {
 657    if (stristr($_REQUEST["XMLFILE"], "file"."://")) {
 658      // Not allowed
 659      ;
 660    }
 661    elseif (stristr($_REQUEST["XMLFILE"], "://")) {
 662      if ($fileAccessLevel == -1) {
 663        echo "Configuration setting prohibit using remote files, exiting\n";
 664        return;
 665      } else {
 666        // URL files are allowed
 667        $XMLfilename = $_REQUEST["XMLFILE"];
 668      }
 669    } else {
 670      if (($fileAccessLevel == 1) || ($fileAccessLevel == -1)) {
 671        if (FeedForAll_rss2html_validExtension(basename($_REQUEST["XMLFILE"]), $allowedFeedExtensions) === FALSE) {
 672          echo "Configuration setting prohibit using the specified feed file, exiting\n";
 673          return;
 674        }
 675        $XMLfilename = basename($_REQUEST["XMLFILE"]);
 676      }
 677      elseif ($fileAccessLevel == 2) {
 678        echo "Configuration setting prohibit using local files, exiting\n";
 679        return;
 680      } else {
 681        // It is local and must be in the same directory
 682        $XMLfilename = basename($_REQUEST["XMLFILE"]);
 683      }
 684    }
 685  }
 686
 687  if (isset($_REQUEST["TEMPLATE"])) {
 688    if (stristr($_REQUEST["TEMPLATE"], "file"."://")) {
 689      // Not allowed
 690      ;
 691    }
 692    elseif (stristr($_REQUEST["TEMPLATE"], "://")) {
 693      if ($fileAccessLevel == -1) {
 694        echo "Configuration setting prohibit using remote files, exiting\n";
 695        return;
 696      } else {
 697        // URL files are allowed
 698        $TEMPLATEfilename = $_REQUEST["TEMPLATE"];
 699      }
 700    } else {
 701      if (($fileAccessLevel == 1) || ($fileAccessLevel == -1)) {
 702        if (FeedForAll_rss2html_validExtension(basename($_REQUEST["TEMPLATE"]), $allowedTemplateExtensions) === FALSE) {
 703          echo "Configuration setting prohibit using the specified template file, exiting\n";
 704          return;
 705        }
 706        $TEMPLATEfilename = basename($_REQUEST["TEMPLATE"]);
 707      }
 708      elseif ($fileAccessLevel == 2) {
 709        echo "Configuration setting prohibit using local files, exiting\n";
 710        return;
 711      } else {
 712        // It is local and must be in the same directory
 713        $TEMPLATEfilename = basename($_REQUEST["TEMPLATE"]);
 714      }
 715    }
 716  }
 717
 718  if (isset($_REQUEST["FeedTitleLength"])) {
 719    $limitFeedTitleLength = abs($_REQUEST["FeedTitleLength"]);
 720  }
 721  if (isset($_REQUEST["FeedDescriptionLength"])) {
 722    $limitFeedDescriptionLength = abs($_REQUEST["FeedDescriptionLength"]);
 723  }
 724  if (isset($_REQUEST["ItemTitleLength"])) {
 725    $limitItemTitleLength = abs($_REQUEST["ItemTitleLength"]);
 726  }
 727  if (isset($_REQUEST["ItemDescriptionLength"])) {
 728    $limitItemDescriptionLength = abs($_REQUEST["ItemDescriptionLength"]);
 729  }
 730
 731  //
 732  // Maximum number of items to be displayed
 733  //
 734  if (isset($_REQUEST["MAXITEMS"])) {
 735    $FeedMaxItems = $_REQUEST["MAXITEMS"];
 736  }
 737  if (isset($_REQUEST["NOFUTUREITEMS"])) {
 738    $NoFutureItems = TRUE;
 739  }
 740
 741  if (isset($outputCacheTTL) && function_exists("FeedForAll_scripts_readOutputCacheFile") && (($cacheContents = FeedForAll_scripts_readOutputCacheFile($XMLfilename, $TEMPLATEfilename)) !== FALSE)) {
 742    if (!headers_sent()) {
 743      // Send the Content-Type to force $destinationEncoding
 744      header("Content-Type: text/html; charset=$destinationEncoding");
 745    }
 746    echo $cacheContents;
 747  } else {
 748    if (($template = FeedForAll_scripts_readFile($TEMPLATEfilename, $useFopenURL)) === FALSE) {
 749      if (!isset($hideErrors)) {
 750        if ($ReadErrorString == "") {
 751          echo "Unable to open template $TEMPLATEfilename, exiting\n";
 752        } else {
 753          echo "Unable to open template $TEMPLATEfilename with error <b>$ReadErrorString</b>, exiting\n";
 754        }
 755      }
 756      return;
 757    }
 758    if (FeedForAll_rss2html_isTemplate($template) === FALSE) {
 759      if (!isset($hideErrors)) {
 760        echo "$TEMPLATEfilename is not a valid rss2html.php template file, exiting\n";
 761      }
 762      return;
 763    }
 764
 765    if (strstr($template, "~~~NoFutureItems~~~")) {
 766      $NoFutureItems = TRUE;
 767    }
 768
 769    if (($XML = FeedForAll_scripts_readFile($XMLfilename, $useFopenURL, $allowCachingXMLFiles)) === FALSE) {
 770      if (!isset($hideErrors)) {
 771        if ($ReadErrorString == "") {
 772          echo "Unable to open RSS Feed $XMLfilename, exiting\n";
 773        } else {
 774          echo "Unable to open RSS Feed $XMLfilename with error <b>$ReadErrorString</b>, exiting\n";
 775        }
 776      }
 777      return;
 778    }
 779
 780    if (strstr(trim($XML), "<?xml") === FALSE) {
 781      $XML = "<?xml version=\"1.0\"?>\n$XML";
 782    }
 783    $XML = strstr(trim($XML), "<?xml");
 784    $XML = FeedForAll_preProcessXML($XML);
 785    if (($convertedXML = FeedForAll_scripts_convertEncoding($XML, $missingEncodingDefault, $destinationEncoding)) === FALSE) {
 786      // Conversions failed, probably becasue it was wrong or the routines were missing
 787      $convertedXML = $XML;
 788      $xml_parser = xml_parser_create();
 789    } else {
 790      $xml_parser = xml_parser_create($destinationEncoding);
 791    }
 792
 793    $rss_parser = new baseParserClass("rss2html");
 794    $rss_parser->noFutureItems = $NoFutureItems;
 795    $rss_parser->wholeString = $convertedXML;
 796    xml_set_object($xml_parser, $rss_parser);
 797    xml_set_element_handler($xml_parser, "startElement", "endElement");
 798    xml_set_character_data_handler($xml_parser, "characterData");
 799    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING,1);
 800    $parseResult = xml_parse($xml_parser, $convertedXML, TRUE);
 801    if ($parseResult == 0) {
 802      if (!isset($hideErrors)) {
 803        $errorCode = xml_get_error_code($xml_parser);
 804        echo "\$errorCode = $errorCode<br>\n";
 805        echo "xml_error_string() = ".xml_error_string($errorCode)."<br>\n";
 806        echo "xml_get_current_line_number() = ".xml_get_current_line_number($xml_parser)."<br>\n";
 807        echo "xml_get_current_column_number() = ".xml_get_current_column_number($xml_parser)."<br>\n";
 808        echo "xml_get_current_byte_index() = ".xml_get_current_byte_index($xml_parser)."<br>\n";
 809      }
 810    } else {
 811      xml_parser_free($xml_parser);
 812
 813      // make sure the channel contentEncoded is not blank
 814      if ($rss_parser->FeedContentEncoded == "") {
 815        $rss_parser->FeedContentEncoded = $rss_parser->FeedDescription;
 816      }
 817      $template = FeedForAll_rss2html_str_replace("~~~FeedXMLFilename~~~", FeedForAll_rss2html_EscapeLink($XMLfilename), $template);
 818      $template = FeedForAll_rss2html_str_replace("~~~FeedTitle~~~", FeedForAll_rss2html_limitLength($rss_parser->FeedTitle, $limitFeedTitleLength), $template);
 819      $template = FeedForAll_rss2html_str_replace("~~~FeedDescription~~~", FeedForAll_rss2html_limitLength($rss_parser->FeedDescription, $limitFeedDescriptionLength), $template);
 820      $template = FeedForAll_rss2html_str_replace("~~~FeedContentEncoded~~~", $rss_parser->FeedContentEncoded, $template);
 821      $template = FeedForAll_rss2html_str_replace("~~~FeedLink~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedLink), $template);
 822      $template = FeedForAll_rss2html_str_replace("~~~FeedPubDate~~~", $rss_parser->FeedPubDate, $template);
 823      $template = FeedForAll_rss2html_str_replace("~~~FeedPubLongDate~~~", date($LongDateFormat, $rss_parser->FeedPubDate_t), $template);
 824      $template = FeedForAll_rss2html_str_replace("~~~FeedPubShortDate~~~", date($ShortDateFormat, $rss_parser->FeedPubDate_t), $template);
 825      $template = FeedForAll_rss2html_str_replace("~~~FeedPubLongTime~~~", date($LongTimeFormat, $rss_parser->FeedPubDate_t), $template);
 826      $template = FeedForAll_rss2html_str_replace("~~~FeedPubShortTime~~~", date($ShortTimeFormat, $rss_parser->FeedPubDate_t), $template);
 827      $template = FeedForAll_rss2html_str_replace("~~~FeedImageUrl~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedImageURL), $template);
 828      $template = FeedForAll_rss2html_str_replace("~~~FeedImageTitle~~~", $rss_parser->FeedImageTitle, $template);
 829      $template = FeedForAll_rss2html_str_replace("~~~FeedImageLink~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedImageLink), $template);
 830      $template = FeedForAll_rss2html_str_replace("~~~FeedImageDescription~~~", $rss_parser->FeedImageDescription, $template);
 831      $template = FeedForAll_rss2html_str_replace("~~~FeedImageHeight~~~", $rss_parser->FeedImageWidth, $template);
 832      $template = FeedForAll_rss2html_str_replace("~~~FeedImageWidth~~~", $rss_parser->FeedImageWidth, $template);
 833      $template = FeedForAll_rss2html_str_replace("~~~FeedCreativeCommons~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedCreativeCommons), $template);
 834      if (FeedForAll_parseExtensions() === TRUE) {
 835        $template = FeedForAll_parseExtensions_replaceInChannel($rss_parser, $template);
 836      }
 837
 838      $match = NULL;
 839
 840      $template = str_replace("~~~NoFutureItems~~~", "", $template);
 841
 842      //
 843      // Sort by PubDate if requested
 844      if (strstr($template, "~~~SortByPubDate~~~")) {
 845        $template = str_replace("~~~SortByPubDate~~~", "", $template);
 846
 847        for ($x = 0; $x < count($rss_parser->Items)-1; $x++) {
 848          for ($y = $x+1; $y < count($rss_parser->Items); $y++) {
 849            if ($rss_parser->Items[$x]->pubDate_t < $rss_parser->Items[$y]->pubDate_t) {
 850              // Swap them
 851              $swapTemp = $rss_parser->Items[$x]; $rss_parser->Items[$x] = $rss_parser->Items[$y]; $rss_parser->Items[$y] = $swapTemp;
 852            }
 853          }
 854        }
 855      }
 856
 857      if (isset($debugLevel) && ($debugLevel >= 3)) {
 858        echo "DIAG: adding to items, count=".count($rss_parser->Items)."<br>\n";
 859      }
 860      
 861      // The the maximum items requested
 862      if (strstr($template, "~~~FeedMaxItems=")) {
 863        // Limit the maximun number of items displayed
 864        if (preg_match("/~~~FeedMaxItems=([0-9-]*)~~~/", $template, $match) !== FALSE) {
 865          if (($match[0] != "") && ($match[1] != "")) {
 866            $FeedMaxItems = $match[1];
 867            $template = str_replace("~~~FeedMaxItems=$match[1]~~~", "", $template);
 868            if (abs($FeedMaxItems) > count($rss_parser->Items)) {
 869              if ($FeedMaxItems > 0) {
 870                $FeedMaxItems = count($rss_parser->Items);
 871              } else {
 872                $FeedMaxItems = -count($rss_parser->Items);
 873              }
 874            }
 875          }
 876        }
 877      }
 878
 879      if (!function_exists("FeedForALL_rss2html_replaceInItem")) {
 880        Function FeedForALL_rss2html_replaceInItem($source, $currentItem) {
 881          GLOBAL $limitFeedTitleLength;
 882          GLOBAL $limitFeedDescriptionLength;
 883          GLOBAL $limitItemTitleLength;
 884          GLOBAL $limitItemDescriptionLength;
 885          GLOBAL $LongDateFormat;
 886          GLOBAL $ShortDateFormat;
 887          GLOBAL $LongTimeFormat;
 888          GLOBAL $ShortTimeFormat;
 889          GLOBAL $XMLfilename;
 890
 891          $item = FeedForAll_rss2html_str_replace("~~~ItemTitle~~~", FeedForAll_rss2html_limitLength($currentItem->title, $limitItemTitleLength), $source);
 892          $item = FeedForAll_rss2html_str_replace("~~~ItemDescription~~~", FeedForAll_rss2html_limitLength($currentItem->description, $limitItemDescriptionLength), $item);
 893          $item = FeedForAll_rss2html_str_replace("~~~ItemEnclosureLengthFormatted~~~", FeedForAll_rss2html_sizeToString($currentItem->enclosureLength), $item);
 894          $item = FeedForAll_rss2html_str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $currentItem->pubDate_t), $item);
 895          $item = FeedForAll_rss2html_str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $currentItem->pubDate_t), $item);
 896          $item = FeedForAll_rss2html_str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $currentItem->pubDate_t), $item);
 897          $item = FeedForAll_rss2html_str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $currentItem->pubDate_t), $item);
 898
 899          $knownFields = $currentItem->getArrayOfFields();
 900          foreach ($knownFields as $field) {
 901            $item = FeedForAll_rss2html_str_replace($field, $currentItem->getValueOf($field), $item);
 902          }
 903
 904          $item = FeedForAll_rss2html_CreateUniqueLink($currentItem->title, $currentItem->description, $currentItem->link, $currentItem->guid, $XMLfilename, $item);
 905          if (FeedForAll_parseExtensions() === TRUE) {
 906            $item = FeedForAll_parseExtensions_replaceInItem($currentItem, $item);
 907          }
 908          return FeedForAll_rss2html_AddIdentity($item);
 909        }
 910      }
 911
 912      //
 913      // Allow access to the number of times that will be processed in the feed
 914      $template = FeedForAll_rss2html_str_replace("~~~NumberOfFeedItems~~~", min(abs($FeedMaxItems), count($rss_parser->Items)), $template);
 915
 916      //
 917      // Find the string, if it exists, between the ~~~EndItemsRecord~~~ and ~~~BeginItemsRecord~~~
 918      //
 919      while ((strstr($template, "~~~BeginItemsRecord~~~")) !== FALSE) {
 920        $match = NULL;
 921        $allitems = NULL;
 922        $loop_limit = min(abs($FeedMaxItems), count($rss_parser->Items));
 923        if (($parts = split("~~~BeginItemsRecord~~~", $template)) !== FALSE) {
 924          if (($parts = split("~~~EndItemsRecord~~~", $parts[1])) !== FALSE) {
 925            $WholeBlock = $parts[0];
 926            //
 927            // Check for ~~~BeginAlternateItemsRecord~~~
 928            //
 929            if (strstr($WholeBlock, "~~~BeginAlternateItemsRecord~~~")) {
 930              $parts = split("~~~BeginAlternateItemsRecord~~~", $WholeBlock);
 931              $block1 = $parts[0];
 932              $block2 = $parts[1];
 933            } else {
 934              $block1 = $WholeBlock;
 935              $block2 = $WholeBlock;
 936            }
 937            if ($FeedMaxItems < 0) {
 938              for ($x = count($rss_parser->Items)-1; $x >= count($rss_parser->Items) + $FeedMaxItems; $x--) {
 939                $allitems .= FeedForALL_rss2html_replaceInItem($block1, $rss_parser->Items[$x]);
 940                $x--;
 941                if ($x >= count($rss_parser->Items) + $FeedMaxItems) {
 942                  //
 943                  // This is at least one more item so use the Alternate definition
 944                  //
 945                  $allitems .= FeedForALL_rss2html_replaceInItem($block2, $rss_parser->Items[$x]);
 946                }
 947              }
 948            } else {
 949              for ($x = 0; $x < $loop_limit; $x++) {
 950                if (isset($debugLevel) && ($debugLevel >= 2)) {
 951                  echo "DIAG: Doing item fillin, \$x = $x; \$loop_limit = $loop_limit<br>\n";
 952                }
 953
 954                $allitems .= FeedForALL_rss2html_replaceInItem($block1, $rss_parser->Items[$x]);
 955                $x++;
 956                if ($x < $loop_limit) {
 957                  //
 958                  // This is at least one more item so use the Alternate definition
 959                  //
 960                  if (isset($debugLevel) && ($debugLevel >= 2)) {
 961                    echo "DIAG: Doing item fillin, \$x = $x; \$loop_limit = $loop_limit<br>\n";
 962                  }
 963
 964                  $allitems .= FeedForALL_rss2html_replaceInItem($block2, $rss_parser->Items[$x]);
 965                }
 966              }
 967            }
 968            $template = str_replace("~~~BeginItemsRecord~~~".$WholeBlock."~~~EndItemsRecord~~~", $allitems, $template);
 969          }
 970        }
 971      }
 972
 973      // Since &apos; is not HTML, but is XML convert.
 974      $template = str_replace("&apos;", "'", $template);
 975
 976      if (!headers_sent()) {
 977        // Send the Content-Type to force $destinationEncoding
 978        header("Content-Type: text/html; charset=$destinationEncoding");
 979      }
 980      $resultHTML = FeedForAll_rss2html_pro($template);
 981      echo $resultHTML;
 982      if (isset($outputCacheTTL) && function_exists("FeedForAll_scripts_writeOutputCacheFile")) {
 983        FeedForAll_scripts_writeOutputCacheFile($XMLfilename, $TEMPLATEfilename, $resultHTML);
 984      }
 985    }
 986  }
 987} else {
 988  if (!headers_sent()) {
 989    // Send the Content-Type to force $destinationEncoding
 990    header("Content-Type: text/html; charset=$destinationEncoding");
 991  }
 992  echo "<html><head><title>rss2html.php URL tool</title><meta http-equiv=\"content-type\" content=\"text/html;charset=$destinationEncoding\"></head><body bgcolor=\"#EEEEFF\">\n";
 993  //
 994  // We are in "buildURL" mode to help create properly encoded URLs to pass to rss2html.php
 995
 996  $_xml = "";
 997  if (isset($_POST["XML"])) {
 998    $_xml = $_POST["XML"];
 999  }
1000  $_template = "";
1001  if (isset($_POST["TEMPLATE"])) {
1002    $_template = $_POST["TEMPLATE"];
1003  }
1004  $_maxitems = "";
1005  if (isset($_POST["MAXITEMS"])) {
1006    $_maxitems = $_POST["MAXITEMS"];
1007  }
1008  $_nofutureitems = "";
1009  if (isset($_POST["NOFUTUREITEMS"])) {
1010    $_nofutureitems = $_POST["NOFUTUREITEMS"];
1011  }
1012  if (function_exists("FeedForAll_scripts_contentOfCache")) {
1013    $_cacheTTL = "";
1014    if (isset($_POST["XMLCACHETTL"])) {
1015      $_cacheTTL = $_POST["XMLCACHETTL"];
1016    }
1017    $_allowCachingXMLFiles = "";
1018    if (isset($_POST["ALLOWXMLCACHE"])) {
1019      $_allowCachingXMLFiles = $_POST["ALLOWXMLCACHE"];
1020    }
1021    $_outputCacheTTL = "";
1022    if (isset($_POST["OUTCACHETTL"])) {
1023      $_outputCacheTTL = $_POST["OUTCACHETTL"];
1024    }
1025    $_outputCacheFileName = "";
1026    if (isset($_POST["OUTCACHENAME"])) {
1027      $_outputCacheFileName = $_POST["OUTCACHENAME"];
1028    }
1029  }
1030
1031  // Display the entry form
1032  echo "<center><h1>RSS2HTML.PHP LINK TOOL</h1></center>\n";
1033  echo "<p>To assist with the with the creation of properly encoded URLs for use with rss2html.php this tool has been created.  Fill in the URLs or file paths for both the XML file and your template file in the boxes below and then click &quot;Submit&quot;.  The program will then return the URLs properly encoded in a string that calls rss2html.php.  You can click on this link to test the results.  The program will also indicate if it was unable to open either of the URLs it was given.</p>\n";
1034  echo "<form action=\"$_SERVER[PHP_SELF]\" method=\"POST\">\n";
1035  echo "<input type=\"hidden\" name=\"buildURL\" value=\"1\">\n";
1036  echo "URL for the XML file: (ie. http://www.myserver.com/file.xml)<br><input type=\"text\" name=\"XML\" size=\"100\" value=\"$_xml\"><br>\n";
1037  echo "URL for the template file: (ie. http://www.myserver.com/template.html)<br><input type=\"text\" name=\"TEMPLATE\" size=\"100\" value=\"$_template\"><br>\n";
1038  echo "<b>Optional items:</b><br>\n";
1039  echo "Maximum items: <input type=\"text\" name=\"MAXITEMS\" size=\"5\" value=\"$_maxitems\"> (Use negative numbers for the last X items)<br>\n";
1040  echo "No future items: <input type=\"checkbox\" name=\"NOFUTUREITEMS\" ";
1041  if ($_nofutureitems == "on") {
1042    echo "CHECKED";
1043  }
1044  echo "><br>\n";
1045  if (function_exists("FeedForAll_scripts_contentOfCache")) {
1046    echo "<table cellpadding=\"2\" cellspacing=\"2\" width=\"100%\" border=\"1\"><tr><td>\n";
1047    echo "<strong>XML (input) Cache Settings</strong><br>\n";
1048    echo "Allow Caching of the feed: <input type=\"checkbox\" name=\"ALLOWXMLCACHE\" ";
1049    if ($_allowCachingXMLFiles == "on") {
1050      echo "CHECKED";
1051    }
1052    echo "><br>\n";
1053    echo "Cache Time: <input type=\"text\" name=\"XMLCACHETTL\" size=\"5\" value=\"$_cacheTTL\"> (The number of seconds a file may be cached for before being fetched again)<br>\n";
1054    echo "<hr>\n";
1055    echo "<strong>HTML (output) Cache Settings</strong><br>\n";
1056    echo "Output Cache Time: <input type=\"text\" name=\"OUTCACHETTL\" size=\"5\" value=\"$_outputCacheTTL\"> (The number of seconds the output may be cached for before being recreated)<br>\n";
1057    echo "Output Cache Name: <input type=\"text\" name=\"OUTCACHENAME\" size=\"40\" value=\"$_outputCacheFileName\"> (This should be a unique name to prevent conflicts)<br>\n";
1058    echo "</td></tr></table>\n";
1059  }
1060  echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">\n";
1061  echo "</form>\n";
1062
1063  $xmlContents = "";
1064  $templateContents = "";
1065
1066  if (isset($_POST["submit"])) {
1067    if ($_SERVER["REQUEST_METHOD"] != "POST") {
1068      return;
1069    }
1070    echo "<hr>\n";
1071
1072    $answer = "";
1073    $answerAlt = "";
1074    $ssi = "";
1075    $xmlurl = "";
1076    $templateurl = "";
1077    if ((isset($_POST["XML"]) && $_POST["XML"] != "") || (isset($_POST["TEMPLATE"]) && $_POST["TEMPLATE"] != "")) {
1078      $answer .= "http://$_SERVER[SERVER_NAME]$_SERVER[PHP_SELF]?";
1079    }
1080    if (isset($_POST["XML"]) && $_POST["XML"] != "") {
1081      $answer .= "XMLFILE=".FeedForAll_rss2html_encodeURL($_POST["XML"]);
1082      $answerAlt .= "\$XMLFILE = \"".str_replace("&", "&amp;", $_POST["XML"])."\";<br>";
1083      $ssi .= "XMLFILE=".FeedForAll_rss2html_encodeURL($_POST["XML"]);
1084      $xmlurl = FeedForAll_rss2html_encodeURL($_POST["XML"]);
1085    }
1086    if ((isset($_POST["XML"]) && $_POST["XML"] != "") && (isset($_POST["TEMPLATE"]) && $_POST["TEMPLATE"] != "")) {
1087      $answer .=  "&amp;";
1088      $ssi .=  "&amp;";
1089    }
1090    if (isset($_POST["TEMPLATE"]) && $_POST["TEMPLATE"] != "") {
1091      $answer .=  "TEMPLATE=".FeedForAll_rss2html_encodeURL($_POST["TEMPLATE"]);
1092      $answerAlt .= "\$TEMPLATE = \"".str_replace("&", "&amp;", $_POST["TEMPLATE"])."\";<br>";
1093      $ssi .=  "TEMPLATE=".FeedForAll_rss2html_encodeURL($_POST["TEMPLATE"]);
1094      $templateurl = FeedForAll_rss2html_encodeURL($_POST["TEMPLATE"]);
1095    }
1096    if (isset($_POST["MAXITEMS"]) && $_POST["MAXITEMS"] != "" && intval($_POST["MAXITEMS"] != 0)) {
1097      $answer .=  "&amp;MAXITEMS=$_POST[MAXITEMS]";
1098      $answerAlt .= "\$MAXITEMS = \"$_POST[MAXITEMS]\";<br>\n";
1099      $ssi .=  "&amp;MAXITEMS=$_POST[MAXITEMS]";
1100    }
1101    if (isset($_POST["NOFUTUREITEMS"]) && $_POST["NOFUTUREITEMS"] == "on") {
1102      $answer .=  "&amp;NOFUTUREITEMS=1";
1103      $answerAlt .= "\$NOFUTUREITEMS = \"1\";<br>\n";
1104      $ssi .=  "&amp;NOFUTUREITEMS=1";
1105    }
1106    if (function_exists("FeedForAll_scripts_contentOfCache")) {
1107      if (isset($_POST["ALLOWXMLCACHE"]) && $_POST["ALLOWXMLCACHE"] == "on") {
1108        $answerAlt .= "\$ALLOWXMLCACHE = \"1\";<br>\n";
1109      }
1110      if (isset($_POST["XMLCACHETTL"]) && ($_POST["XMLCACHETTL"] != "") && (intval($_POST["XMLCACHETTL"]) != 0)) {
1111        $answerAlt .= "\$XMLCACHETTL = \"$_POST[XMLCACHETTL]\";<br>\n";
1112      }
1113      if (isset($_POST["OUTCACHETTL"]) && isset($_POST["OUTCACHENAME"])) {
1114        if (($_POST["OUTCACHETTL"] != "") && (intval($_POST["OUTCACHETTL"]) != 0) && ($_POST["OUTCACHENAME"] != "")) {
1115          $answerAlt .= "\$OUTCACHETTL = \"$_POST[OUTCACHETTL]\";<br>\n";
1116          $answerAlt .= "\$OUTCACHENAME = \"$_POST[OUTCACHENAME]\";<br>\n";
1117        }
1118      }
1119    }
1120
1121    echo "<h1>Results</h1>\n";
1122
1123    if (isset($_POST["XML"]) && $_POST["XML"] != "") {
1124      $XMLfilename = "";
1125      if (stristr($_POST["XML"], "file"."://")) {
1126        // Not allowed
1127        ;
1128      }
1129      elseif (stristr($_POST["XML"], "://")) {
1130        if ($fileAccessLevel == -1) {
1131          echo "<p style=\"color: red;\">Configuration setting prohibit using remote files</p>\n";
1132        } else {
1133          // URL files are allowed
1134          $XMLfilename = $_POST["XML"];
1135        }
1136      } else {
1137        if (($fileAccessLevel == 1) || ($fileAccessLevel == -1)) {
1138          if (FeedForAll_rss2html_validExtension(basename($_POST["XML"]), $allowedFeedExtensions) === FALSE) {
1139            echo "<p style=\"color: red;\">Configuration setting prohibit using the specified feed file</p>\n";
1140          } else {
1141            $XMLfilename = basename($_POST["XML"]);
1142          }
1143        }
1144        elseif ($fileAccessLevel == 2) {
1145          echo "<p style=\"color: red;\">Configuration setting prohibit using local files</p>\n";
1146        } else {
1147          // It is local and must be in the same directory
1148          $XMLfilename = basename($_POST["XML"]);
1149        }
1150      }
1151      if ($XMLfilename != "") {
1152        if (($xmlContents = FeedForAll_scripts_readFile($XMLfilename, $useFopenURL)) === FALSE) {
1153          if ($ReadErrorString == "") {
1154            echo "<p>The XML file <b>$_POST[XML]</b> could not be opened.</p>\n";
1155          } else {
1156            echo "<p>The XML file <b>$_POST[XML]</b> could not be opened with the error <b>$ReadErrorString</b>.</p>\n";
1157          }
1158        } else {
1159          echo "<p>The XML file <b>$_POST[XML]</b> was SUCCESSFULLY opened</p>\n";
1160        }
1161      }
1162    }
1163
1164    if (isset($_POST["TEMPLATE"]) && $_POST["TEMPLATE"] != "") {
1165      $TEMPLATEfilename = "";
1166      if (stristr($_POST["TEMPLATE"], "file"."://")) {
1167        // Not allowed
1168        ;
1169      }
1170      elseif (stristr($_POST["TEMPLATE"], "://")) {
1171        if ($fileAccessLevel == -1) {
1172          echo "<p style=\"color: red;\">Configuration setting prohibit using remote files</p>\n";
1173        } else {
1174          // URL files are allowed
1175          $TEMPLATEfilename = $_POST["TEMPLATE"];
1176        }
1177      } else {
1178        if (($fileAccessLevel == 1) || ($fileAccessLevel == -1)) {
1179          if (FeedForAll_rss2html_validExtension(basename($_POST["TEMPLATE"]), $allowedTemplateExtensions) === FALSE) {
1180            echo "<p style=\"color: red;\">Configuration setting prohibit using the specified template file</p>\n";
1181          } else {
1182            $TEMPLATEfilename = basename($_POST["TEMPLATE"]);
1183          }
1184        }
1185        elseif ($fileAccessLevel == 2) {
1186          echo "<p style=\"color: red;\">Configuration setting prohibit using local files</p>\n";
1187        } else {
1188          // It is local and must be in the same directory
1189          $TEMPLATEfilename = basename($_POST["TEMPLATE"]);
1190        }
1191      }
1192      if ($TEMPLATEfilename != "") {
1193        if (($templateContents = FeedForAll_scripts_readFile($TEMPLATEfilename, $useFopenURL)) === FALSE) {
1194          if ($ReadErrorString == "") {
1195            echo "<p>The template file <b>$_POST[TEMPLATE]</b> could not be opened.</p>\n";
1196          } else {
1197            echo "<p>The template file <b>$_POST[TEMPLATE]</b> could not be opened with the error <b>$ReadErrorString</b>.</p>\n";
1198          }
1199        }
1200        elseif (FeedForAll_rss2html_isTemplate($templateContents) === FALSE) {
1201          echo "$_POST[TEMPLATE] is not a valid rss2html.php template file\n";
1202          $templateContents = "";
1203        } else {
1204          echo "<p>The template file <b>$_POST[TEMPLATE]</b> was SUCCESSFULLY opened</p>\n";
1205        }
1206      }
1207    }
1208
1209    if ($xmlurl != "") {
1210      echo "<p>URL for the XML file properly encoded:<br><pre>$xmlurl</pre></p>\n";
1211    }
1212
1213    if ($templateurl != "") {
1214      echo "<p>URL for the template file properly encoded:<br><pre>$templateurl</pre></p>\n";
1215    }
1216
1217    echo "<h2>Test Link</h2>\n";
1218
1219    echo "<p>Click on link to view results: <a href=\"$answer\" target=\"_blank\">$answer</a></p>\n";
1220
1221    echo "<h2>Example Usage</h2>\n";
1222
1223    echo "<p>Server Side Include:<br><nobr style=\"font-weight: bolder; color: red;\">&lt!--#INCLUDE VIRTUAL=&quot;".basename($_…

Large files files are truncated, but you can click here to view the full file