include "functions.inc"; include "theme.inc"; class rdf { // Contains the raw rdf file: var $data; // Contains the parsed rdf file: var $title; // website name var $items; // latest headlines function url2sql($site, $timout = 10) { ### Connect to database: dbconnect(); ### Get channel info: $result = mysql_query("SELECT * FROM channel WHERE site = '$site'"); if ($channel = mysql_fetch_object($result)) { ### Decode URL: $url = parse_url($channel->rdf); $host = $url[host]; $port = $url[port] ? $url[port] : 80; $path = $url[path]; // print "
$url - $host - $port - $path"; ### Retrieve data from website: $fp = fsockopen($host, $port, &$errno, &$errstr, $timout); if ($fp) { ### Get data from URL: fputs($fp, "GET $path HTTP/1.0\n"); fputs($fp, "User-Agent: headline grabber\n"); fputs($fp, "Host: ". $host ."\n"); fputs($fp, "Accept: */*\n\n"); while(!feof($fp)) $data .= fgets($fp, 128); // print "
$data
$data
[ id\">hlcolor2\">reset | updated $update min. ago ]
"; ### Display box: $theme->box("$channel->site", $content); } else print "Warning: something whiched happened: specified channel could not be found in database.
"; } function addChannel($site, $url, $rdf) { ### Connect to database: dbconnect(); ### Add channel: $query = mysql_query("INSERT INTO channel (site, url, rdf, timestamp) VALUES ('$site', '$url', '$rdf', now())"); } function resetChannel($id) { ### Connect to database: dbconnect(); ### Delete headlines: $result = mysql_query("DELETE FROM headlines WHERE id = $id"); ### Mark channel as invalid to enforce an update: $result = mysql_query("UPDATE channel SET timestamp = 42 WHERE id = $id"); } } function adminAddChannel() { ?>"; $rdf = new rdf(); $rdf->displayHeadlines($channel->site); print " | "; if ($state % 3 == 2) print "
RDF support can change a portal in a significant way: third party websites can become channels in our portal without having to make 'real' deals and with a minimum of extra work. All they need to do is to publish an RDF, so we can include their latest updates in our portal. Yet another easy way to add content.
That in and of itself is interesting, but it's not half so interesting as the fact that other sites can include our headlines as well. Anyone can grab our RDF, anyone can parse it, and anyone can put a list of our headlines. Yet another way to generate more traffic.
One of the most important features (if not the most important) is chaching support. To avoid bogging down other portals with a continous stream of headline grabbing, all headlines are cached and refreshed once in a while. The 'while' can be costumized but is set to 30 minutes by default.
You can reset a channel, that is force to update a channels headlines and you can add new channels. If you don't know what channel to add, check http://www.xmltree.com/. Make sure you don't add anything except valid RDF files!
The RDF parser is still in beta and needs proper integration in the engine. Until then this test page generates nothing more then an overview off all subscribed channels along with their headlines: handy for news squatting. ;)
RDF files are non-proprietary and publically available. Unfortunatly, RDF is not the only standard: another commonly used format is RSS which would be nice to support as well.