/home/wpollock1/public_html/PHP/rssify.php
<?
if ($url) {
parse_html($url);
} else {
show_form();
}
function show_form() {
global $SERVER_NAME, $REQUEST_URI;
?>
<center><B>RSSify at VoidStar.com</B></center>
<p>This form takes your web page and turns it into RSS 0.92. This is especially useful for Blogger users.</p>
<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>
<ol>
<li>Put <span class="rss:item"> ... </span> round each item in your page.
<br />In Blogger you'd do this by going to your template in blogger and changing
<br /><b><$BlogItemBody$></b>
<br />to
<br /><b><span class="rss:item"><$BlogItemBody$></span></b>
<br />And then publish something to re-create the page with the new template
<li>Then put the URL of your new and modified page into the form below.
<li>Check that what you get back looks like RSS.
<li>Now you can make a link to this file like "http://www.voidstar.com/rssify.php?url=your_web_page_url"
<li>Finally add a link to it on your web page, something like this.
</ol>
<center><img src="../images/xml.gif" alt="This gif is freely copyable. Just right click, save">
<br /><font size=1>Powered by <br /><a href="http://www.voidstar.com/rssify.php">RSSify at VoidStar.com</A></font></center>
<form action="<? print "http://" . $SERVER_NAME . $REQUEST_URI; ?>">
The URL of your web page:
<br /><input type="text" name="url" size=50> Include a final "/" or a filename.
<br /><input type="submit" value="Create RSS">
</form>
<br /><b>Usage</b>: http://www.voidstar.com/rssify.php?your_web_page_url
<p><B>Notes:</B>
<ul>
<li>The item text is put in the description element.
<li>The first 40 characters of html stripped description are put in the title element.
<li>The first link in the description is put in the link element. If there isn't one, the web page url is used.
<li>All tags except <A> <B> <BR> <BLOCKQUOTE> <CENTER> <DD> <DL> <DT> <HR> <I> <IMG> <LI> <OL> <P> <PRE> <U> <UL> are stripped from the description.
<li>A maximum of 25 items are included in the rss.
<li>If you have any problems, send me an <a href="mailto:julian_bond@voidstar.com">email</a>
<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.
<li>If you want to run your own copy of this, the source is <a href="/downloads/rssify.php.txt">here</a>.
</ul>
<?
}
function parse_html($url){
$itemregexp = "%rss:item *\" *>(.+?)</span>%is";
$allowable_tags = '<A><B><BR><BLOCKQUOTE><CENTER><DD><DL><DT><HR><I><IMG><LI><OL><P><PRE><U><UL>';
$urlparts = parse_url($url);
if ($urlparts[path] == "") $url .= "/";
if ($fp = @fopen($url, "r")) {
while (!feof($fp)) {
$data .= fgets($fp, 128);
}
fclose($fp);
}
// print "<pre>";
// print htmlentities($data);
eregi("<title>(.*)</title>", $data, $title);
$channel_title = $title[1];
$match_count = preg_match_all($itemregexp, $data, $items);
$match_count = ($match_count > 25) ? 25 : $match_count;
header("Content-Type: text/xml");
$output .= "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
$output .= "<!-- generator=\"rssify/0.92\" -->\n";
$output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">\n";
$output .= "%HTMLlat1;]>\n";
$output .= "<rss version=\"0.92\">\n";
$output .= " <channel>\n";
$output .= " <title>". htmlentities(strip_tags($channel_title)) ."</title>\n";
$output .= " <link>". htmlentities($url) ."</link>\n";
$output .= " <description>". htmlentities($url) ." via voidstar.com</description>\n";
$output .= " <webmaster>". htmlentities("webmaster@voidstar.com") ."</webmaster>\n";
$output .= " <language>en-us</language>\n";
for ($i=0; $i < $match_count; $i++) {
$desc = $items[1][$i];
$title = substr(trim(strip_tags($desc)),0,50) . " ...";
$item_url = get_link($desc, $url);
$desc = strip_tags($desc, $allowable_tags);
$desc = htmlentities($desc);
$output .= " <item>\n";
$output .= " <title>". htmlentities($title) ."</title>\n";
$output .= " <link>". htmlentities($item_url) ."</link>\n";
$output .= " <description>". $desc ."</description>\n";
$output .= " </item>\n";
}
$output .= " </channel>\n";
$output .= "</rss>\n";
print "$output";
// print htmlentities($output);
// print "</pre>";
}
function get_link($desc, $url) {
if (stristr($desc, "href")) {
$linkurl = stristr($desc, "href");
$linkurl = substr($linkurl, strpos($linkurl, "\"")+1);
$linkurl = substr($linkurl, 0, strpos($linkurl, "\""));
$linkurl = trim($linkurl);
return $linkurl;
} else {
return $url;
}
}
?>