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

"; if (strstr($data, "200 OK")) { ### Remove existing entries: $result = mysql_query("DELETE FROM headlines WHERE id = $channel->id"); ### Strip all 'junk': $data = ereg_replace("", "", $data); $data = ereg_replace("", $data); $number = 0; for (reset($items); $item = current($items); next($items)) { ### Extract data: $link = ereg_replace(".*", "", $item); $link = ereg_replace(".*", "", $link); $title = ereg_replace(".*", "", $item); $title = ereg_replace(".*", "", $title); ### Clean headlines: $title = stripslashes(fixquotes($title)); ### Count the number of stories: $number += 1; ### Insert item in database: $result = mysql_query("INSERT INTO headlines (id, title, link, number) VALUES('$channel->id', '$title', '$link', '$number')"); } ### Mark channels as being updated: $result = mysql_query("UPDATE channel SET timestamp = '". time() ."' WHERE id = $channel->id"); } else print "
RDF parser: 404 error?

$data

"; } } } function displayHeadlines($site, $timout = 1800) { global $theme; ### Connect to database: dbconnect(); ### Get channel info: $result = mysql_query("SELECT * FROM channel WHERE site = '$site'"); if ($channel = mysql_fetch_object($result)) { ### Check to see whether we have to update our headlines first: if (time() - $channel->timestamp > $timout) $this->url2sql($site); ### Grab headlines from database: $result = mysql_query("SELECT * FROM headlines WHERE id = $channel->id ORDER BY number"); while ($headline = mysql_fetch_object($result)) { $content .= "
  • link\">$headline->title
  • "; } ### Add timestamp: $update = round((time() - $channel->timestamp) / 60); $content .= "

    [ 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() { ?>

    Site name:

    URL:

    RDF file:

    "; while ($channel = mysql_fetch_object($result)) { if ($state % 3 == 0) print " "; print " "; $rdf = new rdf(); $rdf->displayHeadlines($channel->site); print " "; if ($state % 3 == 2) print " "; $state += 1; } print ""; } function adminDisplayInfo() { ?>

    Headlines

    Concept

    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.

    Features

    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!

    Status

    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.


    header(); switch($op) { case "reset": $channel = new rdf(); $channel->resetChannel($id); print "

    channel has been reset

    "; print "back"; break; case "Add RDF channel": $channel = new rdf(); $channel->addChannel($site, $url, $rdf); // fall through: default: adminDisplayInfo(); adminDisplayAll(); adminAddChannel(); } $theme->footer(); ?>