summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/backend.class.php241
-rw-r--r--includes/calendar.class.php76
-rw-r--r--includes/config.inc16
-rw-r--r--includes/database.inc5
-rw-r--r--includes/function.inc25
-rw-r--r--includes/submission.inc14
-rw-r--r--includes/template.inc8
-rw-r--r--includes/user.inc41
8 files changed, 40 insertions, 386 deletions
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 @@
-<?
-
-include "function.inc";
-
-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
-
-
- #####
- # Syntax.......: backend(...);
- # Description..: Constructor - initializes the internal variables.
- #
- function backend($id, $site, $url, $file, $contact, $timout = 1800) {
- ### 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, "<A HREF=\"$headline->link\">$headline->title</A>");
- }
-
- }
- 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 "<PRE><B>Debug:</B> $url - $host - $port - $path</PRE>";
-
- ### 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 "<PRE>$data</PRE><HR>";
-
- if (strstr($data, "200 OK")) {
-
- ### Remove existing entries:
- $result = db_query("DELETE FROM headlines WHERE id = $this->id");
-
- ### Strip all 'junk':
- $data = ereg_replace("<?xml.*/image>", "", $data);
- $data = ereg_replace("</rdf.*", "", $data);
- $data = chop($data);
-
- ### Iterating through our data processing each entry/item:
- $items = explode("</item>", $data);
- $number = 0;
-
- for (reset($items); $item = current($items); next($items)) {
- ### Extract data:
- $link = ereg_replace(".*<link>", "", $item);
- $link = ereg_replace("</link>.*", "", $link);
- $title = ereg_replace(".*<title>", "", $item);
- $title = ereg_replace("</title>.*", "", $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 "<HR>RDF parser: 404 error?<BR><BR><PRE>$data</PRE><HR>";
- }
- }
- }
-
-
- #####
- # 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<BR>";
- }
-
-
- #####
- # 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<BR>";
- }
-
-
- #####
- # 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 .= "<LI><A HREF=\"$headline->link\">$headline->title</A></LI>";
- }
- ### Add timestamp:
- $update = round((time() - $this->timestamp) / 60);
- $content .= "<P ALIGN=\"right\">[ <A HREF=\"backend.php?op=reset&site=$this->site\"><FONT COLOR=\"$theme->hlcolor2\">reset</FONT></A> | updated $update min. ago ]</P>";
-
- ### Display box:
- $theme->box("$this->site", $content);
- }
- else print "<P>Warning: something whiched happened: specified channel could not be found in database.</P>";
- }
-
-
- #####
- # 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 "<B>Dump backend:</B><BR>";
- print "Id: $this->id<BR>";
- print "Site: $this->site<BR>";
- print "URL: $this->url<BR>";
- print "File: $this->file<BR>";
- print "Contact: $this->contact<BR>";
- }
-}
-
-?>
diff --git a/includes/calendar.class.php b/includes/calendar.class.php
deleted file mode 100644
index 561363c33..000000000
--- a/includes/calendar.class.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?
-
-class calendar {
- var $date;
-
- function calendar($date) {
- $this->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<!-- calendar -->\n";
- $output .= "<TABLE WIDTH=\"100%\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
- $output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"7\"><SMALL><A HREF=\"$PHP_SELF?date=$prev\">&lt;</A> &nbsp; ". date("F Y", $this->date) ." &nbsp; <A HREF=\"$PHP_SELF?date=$next\">&gt;</A></SMALL></TD></TR>\n";
- $output .= " <TR><TD ALIGN=\"center\"><SMALL>S</SMALL></TD><TD ALIGN=\"center\"><SMALL>M</SMALL></TD><TD ALIGN=\"center\"><SMALL>T</SMALL></TD><TD ALIGN=\"center\"><SMALL>W</SMALL></TD><TD ALIGN=\"center\"><SMALL>T</SMALL></TD><TD ALIGN=\"center\"><SMALL>F</SMALL></TD><TD ALIGN=\"center\"><SMALL>S</SMALL></TD></TR>\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 .= " <TR><TD COLSPAN=\"$first\">&nbsp</TD>\n";
- $first = 0;
- }
-
- ### Start every week on a new line:
- if ($sday == 0) $output .= " <TR>\n";
-
- ### Print one cell:
- $date = mktime(24, 0, 0, $month, $nday, $year);
- if ($nday == $day) $output .= " <TD ALIGN=\"center\"><SMALL><B>$nday</B></SMALL></TD>\n";
- else if ($date > time()) $output .= " <TD ALIGN=\"center\"><SMALL>$nday</SMALL></TD>\n";
- else $output .= " <TD ALIGN=\"center\"><SMALL><A HREF=\"$PHP_SELF?date=$date\" STYLE=\"text-decoration: none;\">$nday</A></SMALL></TD>\n";
-
- ### Start every week on a new line:
- if ($sday == 6) $output .= " </TR>\n";
-
- ### Update temporary variables:
- $sday++;
- $sday = $sday % 7;
- $nday++;
- }
-
- ### Complete the calendar:
- if ($sday) {
- $end = 7 - $sday;
- $output .= " <TD COLSPAN=\"$end\">&nbsp;</TD>\n </TR>\n";
- }
- $output .= "</TABLE>\n\n";
-
- ### Return calendar:
- return $output;
- }
-}
-
-?>
diff --git a/includes/config.inc b/includes/config.inc
index 4d54bca98..d4f535919 100644
--- a/includes/config.inc
+++ b/includes/config.inc
@@ -9,7 +9,7 @@ $dbuname = "dries";
$dbpass = "Abc123";
$dbname = "dries";
-#$dbhost = "localhost";
+#$dbhost = "";
#$dbuname = "dries";
#$dbpass = "oakley";
#$dbname = "dries";
@@ -24,7 +24,6 @@ $sitename = "drop.org";
# The contact information will be used to send out automated mails
# to users, account holders or visitors.
$contact_email = "droppies@zind.net";
-$contact_signature = "Kind regards,\n\n-- the drop.org crew\nhttp://beta.drop.org/";
#
# Notify:
@@ -80,13 +79,13 @@ $anonymous = "Anonymous Chicken";
#
$themes = array("Marvin" => array(
"themes/marvin/marvin.theme",
- "white, simple"),
+ "classic theme, white, basic design with a fresh look"),
"Zaphod" => array(
"themes/zaphod/zaphod.theme",
- "yellow, simple"),
+ "classis theme, yellow, structured, advanced navigation"),
"UnConeD" => array(
"themes/unconed/unconed.theme",
- "gray, flashy"));
+ "modern theme, gray and blue, high coolness factor"));
#
# Submission moderation votes:
@@ -105,11 +104,4 @@ $submission_votes = array("neutral (+0)" => "+ 0",
$submission_post_threshold = "2";
$submission_dump_threshold = "-2";
-#
-# Debug flag:
-# Set to '1' if you are using Windows so the engine won't try
-# to send out mails and such. When using Unix or Linux, set
-# to '0'
-$mail = 0;
-
?> \ No newline at end of file
diff --git a/includes/database.inc b/includes/database.inc
index 3721fbd65..843cb270a 100644
--- a/includes/database.inc
+++ b/includes/database.inc
@@ -26,9 +26,8 @@ function db_query($query, $debug = false) {
$qid = mysql_query($query);
### debug output (if required):
- if ($debug || empty($qid)) {
- print "<PRE>query: ". htmlspecialchars($query) ."<BR>error message: ". mysql_error() ."</PRE>";
- }
+ if ($debug || empty($qid)) print "<PRE>query: ". htmlspecialchars($query) ."<BR>error message: ". mysql_error() ."</PRE>";
+ if (empty($qid)) watchdog(3, "error: ". mysql_error() ."<BR>query: ". htmlspecialchars($query) ."");
### return result from query:
return $qid;
diff --git a/includes/function.inc b/includes/function.inc
index 281eb0358..5c1a3615a 100644
--- a/includes/function.inc
+++ b/includes/function.inc
@@ -1,7 +1,7 @@
<?
include "includes/database.inc";
-include "includes/log.inc";
+include "includes/watchdog.inc";
function id2story($id) {
### Perform query:
@@ -9,17 +9,6 @@ function id2story($id) {
return db_fetch_object($result);
}
-function dbsave($dbase, $data, $id=0) {
- foreach ($data as $key=>$value) {
- if ($key == "passwd") { $query .= "$key=PASSWORD('". addslashes($value) ."'), "; }
- else { $query .= "$key='". addslashes($value) ."', "; }
- }
- $query = substr($query, 0, -2);
-
- if (!empty($id)) { db_query("UPDATE $dbase SET $query WHERE id=$id") or die(mysql_error()); return $id; }
- else { db_query("INSERT INTO $dbase SET $query") or die(mysql_error()); return mysql_insert_id(); }
-}
-
function load_theme() {
global $user, $themes;
@@ -44,7 +33,7 @@ function check_output($message) {
function discussion_num_replies($id, $count = 0) {
$result = db_query("SELECT COUNT(cid) FROM comments WHERE pid = $id");
- return ($result) ? mysql_result($result, 0) : 0;
+ return ($result) ? db_result($result, 0) : 0;
}
function format_plural($count, $one, $more) {
@@ -93,14 +82,4 @@ function format_url($address, $description = "") {
return ($address) ? "<A HREF=\"$address\">$description</A>" : format_data($address);
}
-function format_story_link($story, $subject = "") {
- global $user;
- $output .= "<A HREF=\"discussion.php?id=$story->id";
- $output .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded";
- $output .= ($user->uorder) ? "&order=$user->uorder" : "&order=0";
- $output .= ($user->thold) ? "&thold=$user->thold" : "&thold=0";
- $output .= ($subject) ? "\">$subject</A>" : "\">$story->subject</A>";
- return $output;
-}
-
?>
diff --git a/includes/submission.inc b/includes/submission.inc
index 376c84059..23f608f7d 100644
--- a/includes/submission.inc
+++ b/includes/submission.inc
@@ -2,12 +2,12 @@
function submission_count() {
$result = db_query("SELECT COUNT(id) FROM stories WHERE status = 1");
- return ($result) ? mysql_result($result, 0) : 0;
+ return ($result) ? db_result($result, 0) : 0;
}
function submission_score($id) {
$result = db_query("SELECT score FROM stories WHERE id = $id");
- return ($result) ? mysql_result($result, 0) : 0;
+ return ($result) ? db_result($result, 0) : 0;
}
function submission_vote($id, $vote, $comment) {
@@ -26,8 +26,14 @@ function submission_vote($id, $vote, $comment) {
### Update story table (if required):
$result = db_query("SELECT * FROM stories WHERE id = $id");
if ($submission = db_fetch_object($result)) {
- if ($submission->score >= $submission_post_threshold) db_query("UPDATE stories SET status = 2, timestamp = '". time() ."' WHERE id = $id");
- if ($submission->score <= $submission_dump_threshold) db_query("UPDATE stories SET status = 0, timestamp = '". time() ."' WHERE id = $id");
+ if ($submission->score >= $submission_post_threshold) {
+ db_query("UPDATE stories SET status = 2, timestamp = '". time() ."' WHERE id = $id");
+ watchdog(1, "posted story `$submission->subject'");
+ }
+ if ($submission->score <= $submission_dump_threshold) {
+ db_query("UPDATE stories SET status = 0, timestamp = '". time() ."' WHERE id = $id");
+ watchdog(1, "dumped story `$submission->subject'");
+ }
}
}
}
diff --git a/includes/template.inc b/includes/template.inc
index 8e86620a0..5cb6c84d1 100644
--- a/includes/template.inc
+++ b/includes/template.inc
@@ -43,7 +43,7 @@ function display_related_links($theme, $story) {
function display_old_headlines($theme, $num = 10) {
global $user;
- if ($user->storynum) $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $user->storynum, $num");
+ if ($user->stories) $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $user->stories, $num");
else $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $num, $num");
while ($story = db_fetch_object($result)) {
@@ -51,7 +51,7 @@ function display_old_headlines($theme, $num = 10) {
$content .= "<P><B>". date("l, M jS", $story->timestamp) ."</B></P>\n";
$time = date("F jS", $story->timestamp);
}
- $content .= "<LI>". format_story_link($story) ."</LI>\n";
+ $content .= "<LI><A HREF=\"discussion.php?id=$story->id\">$story->subject</A></LI>\n";
}
$content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
@@ -92,7 +92,7 @@ function display_new_headlines($theme, $num = 10) {
$content = "";
$result = db_query("SELECT id, subject FROM stories WHERE status = 2 ORDER BY id DESC LIMIT $num");
- while ($story = db_fetch_object($result)) $content .= "<LI>". format_story_link($story) ."</LI>\n";
+ while ($story = db_fetch_object($result)) $content .= "<LI><A HREF=\"discussion.php?id=$story->id\">$story->subject</A></LI>\n";
$content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
$theme->box("Latest headlines", $content);
}
@@ -109,7 +109,7 @@ function display_account($theme) {
if ($user && $user->userid) {
function submission_number() {
$result = db_query("SELECT COUNT(id) FROM stories WHERE status = 1");
- return ($result) ? mysql_result($result, 0) : 0;
+ return ($result) ? db_result($result, 0) : 0;
}
### Display account settings:
diff --git a/includes/user.inc b/includes/user.inc
index 115c940c0..62e5547be 100644
--- a/includes/user.inc
+++ b/includes/user.inc
@@ -1,41 +1,36 @@
<?
-$access = array("Administrator" => 0x00000001,
+$permissions = array("Administrator" => 0x00000001,
"User manager" => 0x00000002,
"News manager" => 0x00000004);
class User {
- function User($userid, $passwd="") {
- $result = db_query("SELECT * FROM users WHERE LOWER(userid) = LOWER('$userid') && passwd = PASSWORD('$passwd') && STATUS = 0");
+ function User($userid, $passwd = "") {
+ $result = db_query("SELECT * FROM users WHERE LOWER(userid) = LOWER('$userid') && passwd = PASSWORD('$passwd') && STATUS = 2");
if (db_num_rows($result) == 1) {
foreach (db_fetch_row($result) as $key=>$value) { $field = mysql_field_name($result, $key); $this->$field = stripslashes($value); $this->field[] = $field; }
+ db_query("UPDATE users SET last_access = '". time() ."', last_host = '$GLOBALS[REMOTE_HOST]' WHERE id = $this->id");
}
}
}
-function user_save() {
+function user_save($data, $id = 0) {
global $user;
- ### Compose query to update user record:
-}
-
-function user_rehash() {
- global $user;
- $result = db_query("SELECT * FROM users WHERE id=$user->id");
- if (db_num_rows($result) == 1) {
- foreach (db_fetch_array($result) as $key=>$value) { $user->$key = stripslashes($value); }
+
+ foreach ($data as $key=>$value) {
+ if ($key == "passwd") $query .= "$key = PASSWORD('". addslashes($value) ."'), ";
+ else $query .= "$key='". addslashes($value) ."', ";
}
-}
-
-function user_valid($access = 0) {
- global $user;
- if ($user->userid) {
- user_rehash(); // synchronisation purpose
- $user->last_access = time();
- $user->last_host = ($GLOBALS[REMOTE_HOST]) ? $GLOBALS[REMOTE_HOST] : $GLOBALS[REMOTE_ADDR];
- db_query("UPDATE users SET last_access = '$user->last_access', last_host = '$user->last_host' WHERE id = $user->id");
- if ($user->access & $access || $access == 0) return 1;
+
+ if (empty($id)) {
+ db_query("INSERT INTO users SET $query last_access = '". time() ."', last_host = '$GLOBALS[REMOTE_HOST]'");
+ }
+ else {
+ db_query("UPDATE users SET $query last_access = '". time() ."', last_host = '$GLOBALS[REMOTE_HOST]' WHERE id = $id");
+ $result = db_query("SELECT * FROM users WHERE id = $id AND status = 2");
+ if (db_num_rows($result) == 1) foreach (db_fetch_array($result) as $key=>$value) { $user->$key = stripslashes($value); }
+ else $user = 0;
}
- return 0;
}
function user_getHistory($history, $field) {