From 11ee95dadc408e16e9832af9fd0b41495e78b0a6 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 19 Oct 2000 13:31:23 +0000 Subject: A big, fat commit with a shitload of internal changes. Not that much visual changes: - removed redundant files user.class.php, calendar.class.php and backend.class.php. - converted *all* mysql queries to queries supported by the database abstraction layer. - expanded the watchdog to record more information on what actually happened. - bugfix: anonymous readers where not able to view comments. - bugfix: anonymous readers could gain read-only access to the submission queue. - bugfix: invalid includes in backend.php - bugfix: invalid use of '$user->block' and last but not least: - redid 50% of the user account system --- includes/backend.class.php | 241 --------------------------------------------- 1 file changed, 241 deletions(-) delete mode 100644 includes/backend.class.php (limited to 'includes/backend.class.php') diff --git a/includes/backend.class.php b/includes/backend.class.php deleted file mode 100644 index 865ec2e77..000000000 --- a/includes/backend.class.php +++ /dev/null @@ -1,241 +0,0 @@ -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; - } - } - - ##### - # Syntax.......: rdf2sql(optional timout value in seconds); - # Description..: Reads a RDF file from a server, parses it and inserts - # the fresh data in a MySQL table. - # - 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

"; - - if (strstr($data, "200 OK")) { - - ### Remove existing entries: - $result = db_query("DELETE FROM headlines WHERE id = $this->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 = db_query("INSERT INTO headlines (id, title, link, number) VALUES('$this->id', '$title', '$link', '$number')"); - } - - ### Mark channels as being updated: - $result = db_query("UPDATE channel SET timestamp = '". time() ."' WHERE id = $this->id"); - $this->timestamp = time(); - } - else print "
RDF parser: 404 error?

$data

"; - } - } - } - - - ##### - # Syntax.......: rss2sql(optional timout value in seconds); - # Description..: Reads a RSS file from a server, parses it and inserts - # the fresh data in a MySQL table. - # - function rss2sql($timout = 10) { - print "backend->rss2sql : TODO
"; - } - - - ##### - # Syntax.......: xml2sql(optional timout value in seconds); - # Description..: Reads a XML file from a server, parses it and inserts - # the fresh data in a MySQL table. - # - function xml2sql($timout = 10) { - print "backend->xml2sql : TODO
"; - } - - - ##### - # Syntax.......: url2sql(optional timout value in seconds); - # Description..: Generic function to fetch fresh headlines. It checks whether - # we are dealing with a remote RDF, RSS or XML file and calls - # the appropriate function to fetch the headline. The function - # is an abstraction towards the programmer as he doesn't need - # to know with what file extension we are dealing. - # - function url2sql($timout = 10) { - if (strstr($this->file, ".rdf")) $this->rdf2sql($timout); - if (strstr($this->file, ".rss")) $this->rss2sql($timout); - if (strstr($this->file, ".xml")) $this->xml2sql($timout); - } - - - ##### - # Syntax.......: - # Description..: - # - function displayHeadlines($timout = 1800) { - global $theme; - - ### Get channel info: - $result = db_query("SELECT * FROM channel WHERE site = '$this->site'"); - - if ($this->id) { - - ### Check to see whether we have to update our headlines first: - if (time() - $this->timestamp > $timout) $this->url2sql(); - - ### Grab headlines from database: - $result = db_query("SELECT * FROM headlines WHERE id = $this->id ORDER BY number"); - while ($headline = db_fetch_object($result)) { - $content .= "
  • link\">$headline->title
  • "; - } - ### Add timestamp: - $update = round((time() - $this->timestamp) / 60); - $content .= "

    [ 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.

    "; - } - - - ##### - # Syntax.......: add() - # Description..: Adds this backend to the database. - # - function add() { - ### Add channel: - $result = db_query("INSERT INTO channel (site, file, url, contact, timestamp) VALUES ('$this->site', '$this->file', '$this->url', '$this->contact', 42)"); - } - - - ##### - # Syntax.......: delete() - # Description..: Deletes this backend - # - 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"); - } - - ##### - # Syntax.......: refresh() - # Description..: Deletes all headlines associated with this backend. - # - 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 = 42 WHERE id = $this->id"); - } - - ##### - # Syntax.......: dump() - # Description..: Dumps the content of this class to screen. - # - function dump() { - print "Dump backend:
    "; - print "Id: $this->id
    "; - print "Site: $this->site
    "; - print "URL: $this->url
    "; - print "File: $this->file
    "; - print "Contact: $this->contact
    "; - } -} - -?> -- cgit v1.2.3