/home/wpollock1/public_html/PHP/rssify.php

  1: <?
  2: 
  3: if ($url) {
  4:   parse_html($url);
  5: } else {
  6:   show_form();
  7: }
  8: 
  9: function show_form() {
 10:   global $SERVER_NAME, $REQUEST_URI;
 11: ?>
 12: 
 13:    <center><B>RSSify at VoidStar.com</B></center>
 14:    <p>This form takes your web page and turns it into RSS 0.92. This is especially useful for Blogger users.</p>
 15:    <p>A tip of the hat to Aaron Swartz who came up with the idea and <a href="http://logicerror.com/blogifyYourPage">the first implementation.</a></p>
 16:    <ol>
 17:    <li>Put &lt;span class="rss:item"> ... &lt;/span> round each item in your page.
 18:    <br />In Blogger you'd do this by going to your template in blogger and changing
 19: <br /><b>&lt;$BlogItemBody$></b>
 20: <br />to
 21: <br /><b>&lt;span class="rss:item">&lt;$BlogItemBody$>&lt;/span></b>
 22: <br />And then publish something to re-create the page with the new template
 23: <li>Then put the URL of your new and modified page into the form below.
 24: <li>Check that what you get back looks like RSS.
 25: <li>Now you can make a link to this file like "http://www.voidstar.com/rssify.php?url=your_web_page_url"
 26: <li>Finally add a link to it on your web page, something like this.
 27: </ol>
 28: <center><img src="../images/xml.gif" alt="This gif is freely copyable. Just right click, save">
 29: <br /><font size=1>Powered by <br /><a href="http://www.voidstar.com/rssify.php">RSSify at VoidStar.com</A></font></center>
 30: 
 31: 
 32:    <form action="&lt;? print "http://" . $SERVER_NAME . $REQUEST_URI; ?&gt;">
 33:      The URL of your web page:
 34:      <br /><input type="text" name="url" size=50> Include a final "/" or a filename.
 35:      <br /><input type="submit" value="Create RSS">
 36:    </form>
 37:    <br /><b>Usage</b>: http://www.voidstar.com/rssify.php?your_web_page_url
 38:    <p><B>Notes:</B>
 39:    <ul>
 40:    <li>The item text is put in the description element.
 41:    <li>The first 40 characters of html stripped description are put in the title element.
 42:    <li>The first link in the description is put in the link element. If there isn't one, the web page url is used.
 43:    <li>All tags except &lt;A> &lt;B> &lt;BR> &lt;BLOCKQUOTE> &lt;CENTER> &lt;DD> &lt;DL> &lt;DT> &lt;HR> &lt;I> &lt;IMG> &lt;LI> &lt;OL> &lt;P> &lt;PRE> &lt;U> &lt;UL> are stripped from the description.
 44:    <li>A maximum of 25 items are included in the rss.
 45:    <li>If you have any problems, send me an <a href="mailto:julian_bond@voidstar.com">email</a>
 46:    <li>if you want more detail about RSS, take a look at the <a href="http://www.voidstar.com/rssfaq">FAQ</A> on this site.
 47:    <li>If you want to run your own copy of this, the source is <a href="/downloads/rssify.php.txt">here</a>.
 48:    </ul>
 49: <?
 50: }
 51: 
 52: function parse_html($url){
 53:   $itemregexp = "%rss:item *\" *>(.+?)</span>%is";
 54:   $allowable_tags = '<A><B><BR><BLOCKQUOTE><CENTER><DD><DL><DT><HR><I><IMG><LI><OL><P><PRE><U><UL>';
 55: 
 56:   $urlparts = parse_url($url);
 57:   if ($urlparts[path] == "") $url .= "/";
 58: 
 59:   if ($fp = @fopen($url, "r")) {
 60:     while (!feof($fp)) {
 61:       $data .= fgets($fp, 128);
 62:     }
 63:     fclose($fp);
 64:   }
 65: 
 66: //  print "<pre>";
 67: //  print htmlentities($data);
 68: 
 69:   eregi("<title>(.*)</title>", $data, $title);
 70:   $channel_title = $title[1];
 71: 
 72:   $match_count = preg_match_all($itemregexp, $data, $items);
 73:   $match_count = ($match_count > 25) ? 25 : $match_count;
 74: 
 75:   header("Content-Type: text/xml");
 76: 
 77:   $output .= "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
 78:   $output .= "<!-- generator=\"rssify/0.92\" -->\n";
 79:   $output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">\n";
 80:   $output .= "%HTMLlat1;]>\n";
 81: 
 82:   $output .= "<rss version=\"0.92\">\n";
 83:   $output .= "  <channel>\n";
 84:   $output .= "    <title>". htmlentities(strip_tags($channel_title)) ."</title>\n";
 85:   $output .= "    <link>". htmlentities($url) ."</link>\n";
 86:   $output .= "    <description>". htmlentities($url) ." via voidstar.com</description>\n";
 87:   $output .= "    <webmaster>". htmlentities("webmaster@voidstar.com") ."</webmaster>\n";
 88:   $output .= "    <language>en-us</language>\n";
 89: 
 90:   for ($i=0; $i < $match_count; $i++) {
 91: 
 92:     $desc = $items[1][$i];
 93:     $title = substr(trim(strip_tags($desc)),0,50) . " ...";
 94:     $item_url = get_link($desc, $url);
 95:     $desc = strip_tags($desc, $allowable_tags);
 96:     $desc = htmlentities($desc);
 97: 
 98:     $output .= "    <item>\n";
 99:     $output .= "      <title>". htmlentities($title) ."</title>\n";
100:     $output .= "      <link>". htmlentities($item_url) ."</link>\n";
101:     $output .= "      <description>". $desc ."</description>\n";
102:     $output .= "    </item>\n";
103:   }
104: 
105:   $output .= "  </channel>\n";
106:   $output .= "</rss>\n";
107: 
108:   print "$output";
109: //  print htmlentities($output);
110: //  print "</pre>";
111: }
112: 
113: function get_link($desc, $url) {
114:   if (stristr($desc, "href")) {
115:     $linkurl = stristr($desc, "href");
116:     $linkurl = substr($linkurl, strpos($linkurl, "\"")+1);
117:     $linkurl = substr($linkurl, 0, strpos($linkurl, "\""));
118:     $linkurl = trim($linkurl);
119:     return $linkurl;
120:   } else {
121:     return $url;
122:   }
123: }
124: 
125: ?>