PageRenderTime 86ms CodeModel.GetById 15ms app.highlight 37ms RepoModel.GetById 25ms app.codeStats 0ms

/rss-gen/rss2html.php

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

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