From 4a6c6de758960a2f98ba58f20a1c17c6ee67111c Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 10 Oct 2000 10:52:19 +0000 Subject: Huge update - I don't have time to write everything down but the directory structure changes, some sections are expanded. Take a look at the source code or ask me to elaborate on certain issues/topics. --- includes/admin.inc | 78 ++++++++++++++++ includes/backend.inc | 241 ++++++++++++++++++++++++++++++++++++++++++++++++ includes/ban.inc | 52 +++++++++++ includes/calendar.inc | 76 +++++++++++++++ includes/config.inc | 115 +++++++++++++++++++++++ includes/database.inc | 62 +++++++++++++ includes/function.inc | 106 +++++++++++++++++++++ includes/log.inc | 17 ++++ includes/submission.inc | 35 +++++++ includes/template.inc | 128 +++++++++++++++++++++++++ includes/theme.inc | 11 +++ includes/user.inc | 83 +++++++++++++++++ 12 files changed, 1004 insertions(+) create mode 100644 includes/admin.inc create mode 100644 includes/backend.inc create mode 100644 includes/ban.inc create mode 100644 includes/calendar.inc create mode 100644 includes/config.inc create mode 100644 includes/database.inc create mode 100644 includes/function.inc create mode 100644 includes/log.inc create mode 100644 includes/submission.inc create mode 100644 includes/template.inc create mode 100644 includes/theme.inc create mode 100644 includes/user.inc (limited to 'includes') diff --git a/includes/admin.inc b/includes/admin.inc new file mode 100644 index 000000000..4d0ed0dda --- /dev/null +++ b/includes/admin.inc @@ -0,0 +1,78 @@ +
$name\n"; + else print "
$name\n"; +} + +function admin_header() { + global $sitename, $section, $status; + + ?> + + + <? echo $sitename; ?> administration center + + + + + + + + + + + + + + + + \n"; + print " \n"; + print " \n"; + print " \n"; + print "

administration center

 
status:
 
+ \n"; + print "
$title
\"\"
 
$body
\n"; + print "

\n"; +} + +function admin_footer() { + ?> + + + + + + \ No newline at end of file diff --git a/includes/backend.inc b/includes/backend.inc new file mode 100644 index 000000000..30f39c942 --- /dev/null +++ b/includes/backend.inc @@ -0,0 +1,241 @@ +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
    "; + } +} + +?> diff --git a/includes/ban.inc b/includes/ban.inc new file mode 100644 index 000000000..1d9fa095e --- /dev/null +++ b/includes/ban.inc @@ -0,0 +1,52 @@ + 0x01, + "profanity" => 0x02, + "hostnames" => 0x03, + "usernames" => 0x04); +$index2type = array(0x01 => "addresses", + 0x02 => "profanity", + 0x03 => "hostnames", + 0x04 => "usernames"); + +function ban_match($mask, $category) { + ### Perform query: + $result = db_query("SELECT * FROM bans WHERE type = $category AND LOWER('$mask') LIKE LOWER(mask)"); + + ### Return result: + return db_fetch_object($result); +} + +function ban_add($mask, $category, $reason, $message = "") { + global $index2type; + + if (empty($mask)) { + $message = "Failed: empty banmasks are not allowed.

    \n"; + } + else if ($ban = db_fetch_object(db_query("SELECT * FROM bans WHERE type = $category AND '$mask' LIKE mask"))) { + $message = "Failed: ban is already matched by '$ban->mask'.

    \n"; + } + else { + $result = db_query("INSERT INTO bans (mask, type, reason, timestamp) VALUES ('$mask', '$category', '$reason', '". time() ."')"); + $message = "Added new ban with mask `$mask'.

    \n"; + + ### Add log entry: + watchdog(1, "added new ban `$mask' to category `". $index2type[$category] ."' with reason `$reason'."); + } +} + +function ban_delete($id) { + global $index2type; + + $result = db_query("SELECT * FROM bans WHERE id = $id"); + + if ($ban = db_fetch_object($result)) { + ### Perform query: + $result = db_query("DELETE FROM bans WHERE id = $id"); + + ### Deleted log entry: + watchdog(1, "removed ban `$ban->mask' from category `". $index2type[$ban->type] ."'."); + } +} + +?> diff --git a/includes/calendar.inc b/includes/calendar.inc new file mode 100644 index 000000000..561363c33 --- /dev/null +++ b/includes/calendar.inc @@ -0,0 +1,76 @@ +date = $date; + } + + function display() { + global $PHP_SELF; + + ### Extract information from the given date: + $month = date("n", $this->date); + $year = date("Y", $this->date); + $day = date("d", $this->date); + + ### Extract first day of the month: + $first = date("w", mktime(0, 0, 0, $month, 1, $year)); + + ### Extract last day of the month: + $last = date("t", mktime(0, 0, 0, $month, 1, $year)); + + ### Calculate previous and next months dates: + $prev = mktime(0, 0, 0, $month - 1, $day, $year); + $next = mktime(0, 0, 0, $month + 1, $day, $year); + + ### Generate calendar header: + $output .= "\n\n"; + $output .= "\n"; + $output .= " \n"; + $output .= " \n"; + + ### Initialize temporary variables: + $nday = 1; + $sday = $first; + + ### Loop through all the days of the month: + while ($nday <= $last) { + ### Set up blank days for first week of the month: + if ($first) { + $output .= " \n"; + $first = 0; + } + + ### Start every week on a new line: + if ($sday == 0) $output .= " \n"; + + ### Print one cell: + $date = mktime(24, 0, 0, $month, $nday, $year); + if ($nday == $day) $output .= " \n"; + else if ($date > time()) $output .= " \n"; + else $output .= " \n"; + + ### Start every week on a new line: + if ($sday == 6) $output .= " \n"; + + ### Update temporary variables: + $sday++; + $sday = $sday % 7; + $nday++; + } + + ### Complete the calendar: + if ($sday) { + $end = 7 - $sday; + $output .= " \n \n"; + } + $output .= "
    <   ". date("F Y", $this->date) ."   >
    SMTWTFS
     
    $nday$nday$nday
     
    \n\n"; + + ### Return calendar: + return $output; + } +} + +?> diff --git a/includes/config.inc b/includes/config.inc new file mode 100644 index 000000000..4d54bca98 --- /dev/null +++ b/includes/config.inc @@ -0,0 +1,115 @@ + "none", "-1" => "-1", "0" => "0", "+1" => "+ 1", "+2" => "+ 2", "+3" => "+ 3", "+4" => "+ 4", "+5" => "+ 5"); + +# +# Categories: +# +$categories = array("Announcements", + "Arts & Humanities", + "Business & Economy", + "Coding & Webdesign", + "Computers & Internet", + "Drop.org", + "Entertainment", + "Freedom", + "Government", + "News & Media", + "Science", + "Society & Culture"); + +# +# Allowed HTML tags: +# +$allowed_html = "