PageRenderTime 24ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 1ms

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