class backend { // Channel properties: var $id; var $url; var $site; var $file; var $contact; var $timestamp; // Contains the raw rdf/rss/xml file: var $data; // Contains the parsed rdf/rss/xml file: var $headlines = array(); // latest headlines function backend($id, $site = "", $url = "", $file = "", $contact = "", $timout = 10800) { // Get channel info: $result = db_query("SELECT * FROM channel WHERE id = '$id' OR site = '$site'"); if ($channel = db_fetch_object($result)) { // Initialize internal variables: $this->id = $channel->id; $this->site = $channel->site; $this->file = $channel->file; $this->url = $channel->url; $this->contact = $channel->contact; $this->timestamp = $channel->timestamp; // Check to see whether we have to update our headlines first: if (time() - $this->timestamp > $timout) $this->url2sql(); // Read headlines: $result = db_query("SELECT * FROM headlines WHERE id = $this->id ORDER BY number"); while ($headline = db_fetch_object($result)) { array_push($this->headlines, "link\">$headline->title"); } } else { $this->site = $site; $this->url = $url; $this->file = $file; $this->contact = $contact; } } function rdf2sql($timout = 10) { if ($this->file) { // Decode URL: $url = parse_url($this->file); $host = $url[host]; $port = $url[port] ? $url[port] : 80; $path = $url[path]; // print "
Debug: $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
[ site\">hlcolor2\">reset | updated $update min. ago ]
"; // Display box: $theme->box("$this->site", $content); } else print "Warning: something whiched happened: specified channel could not be found in database.
"; } function add() { // Add channel: $result = db_query("INSERT INTO channel (site, file, url, contact, timestamp) VALUES ('". check_input($this->site) ."', '". check_input($this->file) ."', '". check_input($this->url) ."', '". check_input($this->contact) ."', 1)"); } function delete() { // Delete channel: $result = db_query("DELETE FROM channel WHERE id = $this->id"); // Delete headlines: $result = db_query("DELETE FROM headlines WHERE id = $this->id"); } function refresh() { // Delete headlines: $result = db_query("DELETE FROM headlines WHERE id = $this->id"); // Mark channel as invalid to enforce an update: $result = db_query("UPDATE channel SET timestamp = 1 WHERE id = $this->id"); } function dump() { print "Dump backend: