Having found Sigil's nifty New w/u -> RSS proxy, I soon realized that my life would not be complete without such a script on my own computer ;-) . Since I'm not really fond of ColdFusion (actually it's the second time I've encountered it in quite a long time), I've decided do something similar in PHP, which I'm more familiar with (OK, OK, I'm sure Perl would be more suited to the task and whatnot, but my experience with PHP is somewhat larger). I'm aware that the code is an ugly hack and that I should have used XML parser, but ... it works. I might rewrite it if I'm motivated enough.

Unfortunately, I don't have a hosting which would allow socket functions, therefore I'm unable to give you an URL:-(. I'm running it on Apache 1.3.24 with PHP 4.3.1, but it should run on about anything that supports socket functions.

So, here it is - comments and corrections are welcome.

BTW as far as copyright is concerned, I did ask for and did receive Sigil's permission to reverse-engineer and translate his code.

<?
/*
 * e4rss - Everything2.com New Writeups XML ticker to RSS converter 
 *  
 *  Version 1.0  January 24, 2005
 *  Written by solaraddict
 *  Inspired by Sigil's New Writeups RSS Feed for ColdFusion
 *
 */
 

// edit these if you're behind a proxy
$proxy = '';
$proxyPort = 0;



/* the following items will almost certainly need no tweaking */

// everything2 site stats
$address = 'www.everything2.org';
$port = 80;
$site = "http://$address/index.pl?node_id=";

// this is the node_id of New Writeups XML Ticker
$newWriteupsTicker = '1291781';
// connection timeout
$timeout = 30;


/* nothing needs to be changed below here */

// variable will be set to server time
$date = 0;
// where is this script running from?
$thisScript = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];

/* something actually starts happenning from now on*/
// load the node
list($date,$text) = readWeb($address, $port, $site . $newWriteupsTicker, $proxy, $proxyPort, $timeout);

// define XML to RSS transform regexp
$search = array(	
		"'<newwriteups>'si",
		"'</newwriteups>'si",
		
		"'<wu[^>]+>\s*<e2link node_id=\"(\d+)\">([^<]+)</e2link>\s*<author>\s*" .
			"<e2link node_id=\"(\d+)\">([^<]+)</e2link>\s*</author><parent>\s*" .
			"<e2link node_id=\"(\d+)(.*?)</wu>'si",
		);
$replace = array (
		"<!-- RSS generated by solaraddict's e4rss at $thisScript on $date e2 server time -->
		<rss version=\"2.0\">
		
		<channel>
		<title>Everything2 New Writeups</title>
		<description>All the newest additions to e2 - get them while they're fresh!</description>
		<language>en-us</language>
		<lastBuildDate>$date</lastBuildDate>",

		'</channel></rss>',
		
		"<item><title>\\2</title><description>&lt;a href=\"$site\\1\"&gt;\\2&lt;/a&gt;" .
			" &lt;small&gt;(&lt;a href=\"$site\\5\"&gt;full&lt;/a&gt;)&lt;/small&gt;" .
			" by &lt;a href=\"$site\\3\"&gt;\\4&lt;/a&gt;</description><link>$site\\1" .
			"</link><author>\\4</author></item>"
		);

if ($date > -1) { // download OK
	
	// regexp transform
	$newText = preg_replace($search, $replace, $text);
	
	// send the header, so the RSS reader knows what type of data to expect
	header("Content-type: text/xml");

	// send the transformed text to the RSS reader
	print $newText;
} else { // couldn't connect - don't send any data

}

function readWeb($address, $port, $url, $proxy, $proxyPort, $timeout) { // get the data
	$error = $errorMsg = '';
	
	if ($proxy != '' && $proxyPort != 0) { // we're behind a proxy
		$connectAddress = $proxy;
		$connectPort = $proxyPort;
	} else { // directly connected
		$connectAddress = $address;
		$connectPort = $port;
	}
	
	// connect to host
	$fh = fsockopen( $connectAddress, $connectPort, &$errno, &$errstr, $timeout);
	if (!$fh) { // not connected, go away.
	    return array(-1, "$errstr ($errno)<br>\n");
	} else { // connected, send the request
	    fputs ($fh, "GET $url HTTP/1.0\r\nHost: $address:$port\r\n\r\n");
		// we're not really interested in the headers
		while (!feof($fh)) {
			$line = fgets ($fh,128);
			if (chop($line) == '') { // the empty line which separates headers from data
				break;
			} else { // find the e2 server time
				if (substr($line, 0,5) == 'Date:') {
					$date = substr($line, 6);
				}
			}
		}
		$content = '';
		$buffer = '';
		// read data while there are any
		while ($buffer = fread ($fh, 128)) {
			$content .= $buffer;
		}
		// close connection
		fclose ($fh);
	}
	return array($date,$content);
}
?>