home *** CD-ROM | disk | FTP | other *** search
/ notepage.net / notepage.net.tar / notepage.net / dev / temp / FeedForAll_rss2html_pro.php next >
PHP Script  |  2015-09-23  |  9KB  |  222 lines

  1. <?PHP
  2. //
  3. // rss2html.php RSS feed to HTML webpage script
  4. //
  5. // Copyright 2006-2007 NotePage, Inc. all rights reserved
  6. // http://www.feedforall.com
  7. //
  8. // NotePage, Inc. grants registerd users of our FeedForAll and/or
  9. // FeedForAll Mac product(s) the right to install and use the
  10. // FeedForAll_rss2html_pro.php script free of charge.  
  11. // Please refer to the EULA included in the download for full license
  12. // terms and conditions.
  13. //
  14. // $Id: FeedForAll_rss2html_pro.php,v 3.2 2007/05/24 18:11:43 housley Exp $
  15. //
  16. // $Log: FeedForAll_rss2html_pro.php,v $
  17. // Revision 3.2  2007/05/24 18:11:43  housley
  18. // Don't use == for an assignment
  19. //
  20. // Revision 3.1  2007/04/24 18:29:55  housley
  21. // Parse the iTunes Music Store namespace
  22. //
  23. // Revision 3.0  2007/04/16 14:23:03  housley
  24. // Release version 3.0 of the scripts
  25. //
  26. // Revision 1.18  2007/04/09 01:25:50  housley
  27. // Fix the commented out code for enabling the extensions
  28. //
  29. // Revision 1.17  2007/04/06 11:08:58  housley
  30. // Add support for the Dublin Core (dc) namespace
  31. //
  32. // Revision 1.16  2007/03/07 03:01:22  housley
  33. // Add the flag to not parse TrackBack
  34. //
  35. // Revision 1.15  2007/03/05 17:29:45  housley
  36. // Add a simple way to block parsing extensions
  37. //
  38. // Revision 1.14  2007/03/03 21:10:09  housley
  39. // * Make the item a full class object
  40. // * Support parsing the iTunes(R) extension
  41. //
  42. // Revision 1.13  2007/02/21 20:24:20  housley
  43. // Remove unused function
  44. //
  45. // Revision 1.12  2007/02/14 01:31:09  housley
  46. // Encode the '#' in GUID URLs
  47. //
  48. // Revision 1.11  2006/11/29 12:04:38  housley
  49. // When checking a GUID that is a complex URL, there needs to be some conversions done.
  50. //
  51. // Revision 1.10  2006/11/05 17:23:00  housley
  52. // Work arond a bug in PHP related to large strings an preg_replace_callback()
  53. //
  54. // Revision 1.9  2006/09/29 19:07:15  housley
  55. // Allow rss2html.php not to show an identity when used with any of the
  56. // pay scripts.
  57. //
  58. // Revision 1.8  2006/09/04 12:31:24  housley
  59. // If the template is remote, converting the ~~~QUOTE~~~ back to \" still needs to be done.
  60. //
  61. // Revision 1.7  2006/08/26 11:30:19  housley
  62. // Comment the code
  63. //
  64. // Revision 1.6  2006/08/25 19:15:13  housley
  65. // Prevent remote templates with rss2html-pro
  66. //
  67. // Revision 1.5  2006/08/25 18:00:30  housley
  68. // Use a better eval function to allow spanning fo the PHP code
  69. //
  70. // Revision 1.4  2006/08/25 15:08:57  housley
  71. // The ~~~ItemUniqueLink=X~~~ is part for Pro now
  72. //
  73. // Revision 1.3  2006/08/21 20:19:32  housley
  74. // Use special routines so that rss2html-pro will work with RSS fields that
  75. // have quotes in them.
  76. //
  77. // Revision 1.1  2006/08/14 21:25:02  housley
  78. // Initial version of a post processing module that would allow PHP to be
  79. // used in the template to preform logic.
  80. //
  81.  
  82. //
  83. // ==========================================================================
  84. // Configuration options
  85. // ==========================================================================
  86. //
  87. // To prevent parsing of the iTunes(R) XML namespace extension, uncomment the
  88. // following line.
  89. $Dont_Parse_iTunes = TRUE;
  90. //
  91. // To prevent parsing of the TrackBack XML namespace extension, uncomment the
  92. // following line.
  93. $Dont_Parse_TrackBack = TRUE;
  94. //
  95. // To prevent parsing of the DublinCore XML namespace extension, uncomment the
  96. // following line.
  97. $Dont_Parse_DublinCore = TRUE;
  98. //
  99. // To prevent parsing of the ITMS XML namespace extension, uncomment the
  100. // following line.
  101. //$Dont_Parse_ITMS = TRUE;
  102.  
  103. if (function_exists('FeedForAll_rss2html_AddIdentity') === FALSE) {
  104.   Function FeedForAll_rss2html_AddIdentity($itemString) {
  105.     return $itemString;
  106.   }
  107. }
  108.  
  109. if (function_exists('FeedForAll_rss2html_pro') === FALSE) {
  110.   Function FeedForAll_rss2html_pro($string) {
  111.     //
  112.     //
  113.     // IMPORTANT:  Since allowing remote templates to use PHP is a HUGE
  114.     //             security violation, on the order of the IE exploits.
  115.     //             Therefore if the template is remote, then no processing
  116.     //             will be done
  117.     //
  118.     GLOBAL $TEMPLATEfilename;
  119.     
  120.     if (strstr($TEMPLATEfilename, '://') !== FALSE) {
  121.       // Return our special ~~~QUOTE~~~ back into  and ~~~SQUOTE~~~ back into '
  122.       return str_replace('~~~QUOTE~~~', '"', str_replace('~~~SQUOTE~~~', '\'', $string));
  123.     }
  124.  
  125.     // Put markers to enter and then exit PHP at the front a back of the
  126.     // string, this will make it look like PHP has ended before the string
  127.     $string = "<?php ?>".$string."<?php ?>";
  128.     // Convert shortcut echo into a full echo command
  129.     $string = preg_replace('/<\?=\s+(.*?)\s+\?>/', '<?php echo $1; ?>', $string);
  130.     // Setup for parsing the string. converting HTML into PHP echo commands
  131.  
  132.     $result = '';
  133.     while (($startLoc = strpos($string, '?>')) !== FALSE) {
  134.       $result .= substr($string, 0, $startLoc);
  135.       $after = substr($string, $startLoc+2);
  136.       if (($endLoc = strpos($after, '<?')) === FALSE) {
  137.         $result .= $string;
  138.         break;
  139.       } else {
  140.         $replaceStr = substr($after, 0, $endLoc);
  141.         $result .= "echo stripslashes(\"".addslashes($replaceStr)."\");";
  142.         if ((($startLoc = strpos(strtolower(substr($after, $endLoc)), '<?php')) !== FALSE) && ($startLoc == 0)) {
  143.           // Fake the advance
  144.           $endLoc += 3;
  145.         }
  146.         $string = substr($after, $endLoc+2);
  147.       }
  148.     }
  149.     $string = str_replace('?>', '', str_replace(array('<?php', '<?'), '', $result));
  150.     $result = '';
  151.     
  152.     //
  153.     // Use output buffering around the eval()
  154.     ob_start();
  155.     eval($string);
  156.     $result = ob_get_contents();
  157.     ob_end_clean();
  158.  
  159.     // Return our special ~~~QUOTE~~~ back into  and ~~~SQUOTE~~~ back into '
  160.     return str_replace('~~~QUOTE~~~', '"', str_replace('~~~SQUOTE~~~', '\'', $result));
  161.   }
  162.   
  163.   Function FeedForAll_rss2html_str_replace($search, $replace, $subject) {
  164.     // Convert " to ~~~QUOTE~~~ and ' to ~~~SQUOTE~~~ so we can work with abritarty
  165.     // strings from the RSS feed
  166.     $replace = str_replace('"', '~~~QUOTE~~~', str_replace('\'', '~~~SQUOTE~~~', $replace));
  167.     return str_replace($search, $replace, $subject);
  168.   }
  169.   
  170.   Function FeedForAll_rss2html_CreateUniqueLink($title, $description, $link, $guid, $XMLfilename, $itemTemplate) {
  171.     $match = Array();
  172.     
  173.     while (preg_match('/~~~ItemUniqueLinkWithTemplate=.*~~~/', $itemTemplate, $match) !== FALSE) {
  174.       if ((count($match) == 0) || ($match[0] == '')) {
  175.         // All done
  176.         return $itemTemplate;
  177.       }
  178.       
  179.       // Get the filename of the template to be used
  180.       $template = str_replace('ItemUniqueLinkWithTemplate=', '', str_replace('~~~', '', $match[0]));
  181.       if (($title == '') && ($description == '') && ($guid == '')) {
  182.         // There is on information that a link can be made of
  183.         $itemTemplate = str_replace($match[0], '', $itemTemplate);
  184.       }
  185.       elseif ($guid != '') {
  186.         // We have a GUID, good feed creator
  187.         $replace = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'].'?XMLFILE='.FeedForAll_rss2html_encodeURL($XMLfilename).'&TEMPLATE='.FeedForAll_rss2html_encodeURL($template).'&GUID='.FeedForAll_rss2html_encodeURL($guid, 1).'&MAXITEMS=1';
  188.         $itemTemplate = FeedForAll_rss2html_str_replace($match[0], $replace, $itemTemplate);
  189.       } else {
  190.         // No GUID, bad feed creator, use a hash of the title and description
  191.         $replace = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'].'?XMLFILE='.FeedForAll_rss2html_encodeURL($XMLfilename).'&TEMPLATE='.FeedForAll_rss2html_encodeURL($template).'&ITEMHASH='.md5($title.$description).'&MAXITEMS=1';
  192.         $itemTemplate = FeedForAll_rss2html_str_replace($match[0], $replace, $itemTemplate);
  193.       }
  194.     }
  195.     if ($link);
  196.     return $itemTemplate;
  197.   }
  198.   
  199.   Function FeedForAll_rss2html_UseUniqueLink($title, $description, $link, $guid) {
  200.     // Look for either GUID or ITEMHASH to find the unique items
  201.     if (isset($_REQUEST['GUID'])) {
  202.       if (($_REQUEST['GUID'] == $guid) || ($_REQUEST['GUID'] == str_replace('&', '&', $guid))) {
  203.         return 1;
  204.       }
  205.       return 0;
  206.     }
  207.     elseif (isset($_REQUEST['ITEMHASH'])) {
  208.       if ($_REQUEST['ITEMHASH'] == md5(trim($title).trim($description))) {
  209.         return 1;
  210.       }
  211.       return 0;
  212.     }
  213.     if ($link);
  214.     // Neither GUID or ITEMHASH was specified
  215.     return -1;
  216.   }
  217. }
  218.  
  219. @include('FeedForAll_parse_Extensions.inc.php');
  220.  
  221. ?>
  222.