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