summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/admin.inc47
-rw-r--r--includes/backend.inc240
-rw-r--r--includes/blob.inc22
-rw-r--r--includes/database.inc9
-rw-r--r--includes/droplet.inc22
-rw-r--r--includes/function.inc6
-rw-r--r--includes/theme.inc14
7 files changed, 38 insertions, 322 deletions
diff --git a/includes/admin.inc b/includes/admin.inc
index 2825d728f..27a30e9fb 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -1,15 +1,6 @@
<?
-
-function admin_icon($name) {
- global $section;
- if ($name == $section) print " <TD ALIGN=\"center\" BGCOLOR=\"#CCCCCC\"><A HREF=\"admin.php?section=$name\"><IMG SRC=\"images/admin-$name.png\" BORDER=\"0\"></A><BR>$name</TD>\n";
- else print " <TD ALIGN=\"center\" VALIGN=\"middle\"><A HREF=\"admin.php?section=$name\"><IMG SRC=\"images/admin-$name.png\" BORDER=\"0\"></A><BR>$name</TD>\n";
-}
-
function admin_header() {
- global $site_name, $section;
-
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
@@ -23,46 +14,12 @@ function admin_header() {
td { font-family: helvetica, arial; }
</STYLE>
<BODY BGCOLOR="#FFFFFF" LINK="#006699" VLINK="#004499" ALINK="#FF0000">
- <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="2">
- <TR><TD COLSPAN="10"><H1><? echo "$site_name"; ?> administration center</H1></TD></TR>
- <TR><TD BGCOLOR="#000000" COLSPAN="11" WIDTH="100%"><IMG SRC="images/pixel.gif" WIDTH="1" HEIGHT="1" ALT=""></TD></TR>
- <TR>
- <?
- admin_icon("stories");
- admin_icon("comments");
- admin_icon("diaries");
- admin_icon("accounts");
- admin_icon("watchdog");
- admin_icon("blobs");
- admin_icon("cron");
- admin_icon("bans");
- admin_icon("stats");
- admin_icon("info");
- admin_icon("home");
- ?>
- </TR>
- <TR><TD BGCOLOR="#000000" COLSPAN="11" WIDTH="100%"><IMG SRC="images/pixel.gif" WIDTH="1" HEIGHT="0" ALT=""></TD></TR>
- <TR><TD COLSPAN="10">&nbsp;</TD></TR>
- <TR>
- <TD COLSPAN="11">
- <?
-}
-
-function admin_box($title, $body) {
- print "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"2\" WIDTH=\"100%\">\n";
- print " <TR><TD><FONT COLOR=\"#83997A\"><B>$title</B></A></TD></TR>\n";
- print " <TR><TD BGCOLOR=\"#000000\" WIDTH=\"100%\"><IMG SRC=\"images/pixel.gif\" WIDTH=\"1\" HEIGHT=\"0\" ALT=\"\"></TD></TR>\n";
- print " <TR><TD>&nbsp;</TD></TR>\n";
- print " <TR><TD>$body</TD></TR>\n";
- print "</TABLE>\n";
- print "<BR><BR>\n";
+ <H1>Administration center</H1>
+ <?
}
function admin_footer() {
?>
- </TD>
- </TR>
- </TABLE>
</BODY>
</HTML>
<?
diff --git a/includes/backend.inc b/includes/backend.inc
deleted file mode 100644
index 9ceba3bf3..000000000
--- a/includes/backend.inc
+++ /dev/null
@@ -1,240 +0,0 @@
-<?
-
-
-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($title);
-
- ### Count the number of stories:
- $number += 1;
-
- ### Insert item in database:
- $result = db_query("INSERT INTO headlines (id, title, link, number) VALUES('". check_input($this->id) ."', '". check_input($title) ."', '". check_input($link) ."', '". check_input($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 ('". check_input($this->site) ."', '". check_input($this->file) ."', '". check_input($this->url) ."', '". check_input($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/blob.inc b/includes/blob.inc
deleted file mode 100644
index dab03ff5e..000000000
--- a/includes/blob.inc
+++ /dev/null
@@ -1,22 +0,0 @@
-<?
-
-function blob_get($name) {
- $result = db_query("SELECT * FROM blobs WHERE name = '$name'");
-
- if ($blob = db_fetch_object($result)) {
- return eval($blob->code);
- }
- else {
- watchdog("error", "blob '$name' does not exist");
- }
-}
-
-function blob_add($name, $help, $code, $message = "") {
- $result = db_query("INSERT INTO blobs (name, help, code) VALUES ('". check_input($name) ."', '". check_input($help) ."', '". check_code($code) ."')");
-}
-
-function blob_delete($id) {
- $result = db_query("DELETE FROM blobs WHERE id = $id");
-}
-
-?> \ No newline at end of file
diff --git a/includes/database.inc b/includes/database.inc
index 8e0183048..56e230003 100644
--- a/includes/database.inc
+++ b/includes/database.inc
@@ -7,10 +7,9 @@
* just adjust the handlers to your needs.
*/
-function db_connect() {
- global $db_host, $db_name, $db_pass, $db_name;
- mysql_pconnect($db_host, $db_name, $db_pass) or die(mysql_Error());
- mysql_select_db($db_name) or die ("Unable to select database");
+function db_connect($host, $name, $pass, $base) {
+ mysql_pconnect($host, $name, $pass) or die(mysql_Error());
+ mysql_select_db($base) or die ("unable to select database");
// NOTE: we are using a persistent connection!
}
@@ -49,6 +48,6 @@ function db_result($qid, $field) {
#
# Automatically connect to database:
#
-db_connect();
+db_connect($db_host, $db_name, $db_pass, $db_name);
?>
diff --git a/includes/droplet.inc b/includes/droplet.inc
new file mode 100644
index 000000000..3f1f3b209
--- /dev/null
+++ b/includes/droplet.inc
@@ -0,0 +1,22 @@
+<?
+
+function droplet_get($name) {
+ $result = db_query("SELECT * FROM droplets WHERE name = '$name'");
+
+ if ($droplet = db_fetch_object($result)) {
+ return eval($droplet->code);
+ }
+ else {
+ watchdog("error", "droplet '$name' does not exist");
+ }
+}
+
+function droplet_add($name, $help, $code, $message = "") {
+ $result = db_query("INSERT INTO droplets (name, help, code) VALUES ('". check_input($name) ."', '". check_input($help) ."', '". check_code($code) ."')");
+}
+
+function droplet_delete($id) {
+ $result = db_query("DELETE FROM droplets WHERE id = $id");
+}
+
+?>
diff --git a/includes/function.inc b/includes/function.inc
index 3d4f5253f..7c1afc7ae 100644
--- a/includes/function.inc
+++ b/includes/function.inc
@@ -10,10 +10,10 @@ function load_theme() {
global $user, $themes;
if ($user->theme && file_exists($themes[$user->theme][0])) {
- include $themes[$user->theme][0];
+ include_once $themes[$user->theme][0];
}
else {
- include $themes[key($themes)][0];
+ include_once $themes[key($themes)][0];
}
return new Theme();
}
@@ -90,7 +90,7 @@ function format_data($field, $replacement = "<I>na</I>") {
}
function format_username($username, $admin = 0) {
- if ($username) return ($admin) ? "<A HREF=\"admin.php?section=accounts&op=view&name=$username\">$username</A>" : "<A HREF=\"account.php?op=view&name=$username\">$username</A>";
+ if ($username) return ($admin) ? "<A HREF=\"admin.php?mod=account&op=view&name=$username\">$username</A>" : "<A HREF=\"account.php?op=view&name=$username\">$username</A>";
else { global $anonymous; return $anonymous; }
}
diff --git a/includes/theme.inc b/includes/theme.inc
index 70fa3ecc7..d1c3540e5 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -1,12 +1,12 @@
<?
-include "includes/config.inc";
-include "includes/database.inc";
-include "includes/watchdog.inc";
-include "includes/function.inc";
-include "includes/blob.inc";
-include "includes/widget.inc";
-include "includes/user.inc";
+include_once "includes/". getenv("HTTP_HOST") .".conf";
+include_once "includes/database.inc";
+include_once "includes/watchdog.inc";
+include_once "includes/function.inc";
+include_once "includes/droplet.inc";
+include_once "includes/widget.inc";
+include_once "includes/user.inc";
global $user;