* Fixed a small bugs, integrated the database abstraction layer and
shortened the code.3-00
parent
0f5a60e109
commit
8720cbf69e
|
@ -24,13 +24,10 @@ class backend {
|
||||||
# Description..: Constructor - initializes the internal variables.
|
# Description..: Constructor - initializes the internal variables.
|
||||||
#
|
#
|
||||||
function backend($id, $site, $url, $file, $contact, $timout = 1800) {
|
function backend($id, $site, $url, $file, $contact, $timout = 1800) {
|
||||||
### Connect to database:
|
|
||||||
dbconnect();
|
|
||||||
|
|
||||||
### Get channel info:
|
### Get channel info:
|
||||||
$result = mysql_query("SELECT * FROM channel WHERE id = '$id' OR site = '$site'");
|
$result = db_query("SELECT * FROM channel WHERE id = '$id' OR site = '$site'");
|
||||||
|
|
||||||
if ($channel = mysql_fetch_object($result)) {
|
if ($channel = db_fetch_object($result)) {
|
||||||
### Initialize internal variables:
|
### Initialize internal variables:
|
||||||
$this->id = $channel->id;
|
$this->id = $channel->id;
|
||||||
$this->site = $channel->site;
|
$this->site = $channel->site;
|
||||||
|
@ -43,8 +40,8 @@ class backend {
|
||||||
if (time() - $this->timestamp > $timout) $this->url2sql();
|
if (time() - $this->timestamp > $timout) $this->url2sql();
|
||||||
|
|
||||||
### Read headlines:
|
### Read headlines:
|
||||||
$result = mysql_query("SELECT * FROM headlines WHERE id = $this->id ORDER BY number");
|
$result = db_query("SELECT * FROM headlines WHERE id = $this->id ORDER BY number");
|
||||||
while ($headline = mysql_fetch_object($result)) {
|
while ($headline = db_fetch_object($result)) {
|
||||||
array_push($this->headlines, "<A HREF=\"$headline->link\">$headline->title</A>");
|
array_push($this->headlines, "<A HREF=\"$headline->link\">$headline->title</A>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +67,7 @@ class backend {
|
||||||
$port = $url[port] ? $url[port] : 80;
|
$port = $url[port] ? $url[port] : 80;
|
||||||
$path = $url[path];
|
$path = $url[path];
|
||||||
|
|
||||||
// print "<PRE>$url - $host - $port - $path</PRE>";
|
// print "<PRE><B>Debug:</B> $url - $host - $port - $path</PRE>";
|
||||||
|
|
||||||
### Retrieve data from website:
|
### Retrieve data from website:
|
||||||
$fp = fsockopen($host, $port, &$errno, &$errstr, $timout);
|
$fp = fsockopen($host, $port, &$errno, &$errstr, $timout);
|
||||||
|
@ -89,7 +86,7 @@ class backend {
|
||||||
if (strstr($data, "200 OK")) {
|
if (strstr($data, "200 OK")) {
|
||||||
|
|
||||||
### Remove existing entries:
|
### Remove existing entries:
|
||||||
$result = mysql_query("DELETE FROM headlines WHERE id = $this->id");
|
$result = db_query("DELETE FROM headlines WHERE id = $this->id");
|
||||||
|
|
||||||
### Strip all 'junk':
|
### Strip all 'junk':
|
||||||
$data = ereg_replace("<?xml.*/image>", "", $data);
|
$data = ereg_replace("<?xml.*/image>", "", $data);
|
||||||
|
@ -114,11 +111,11 @@ class backend {
|
||||||
$number += 1;
|
$number += 1;
|
||||||
|
|
||||||
### Insert item in database:
|
### Insert item in database:
|
||||||
$result = mysql_query("INSERT INTO headlines (id, title, link, number) VALUES('$this->id', '$title', '$link', '$number')");
|
$result = db_query("INSERT INTO headlines (id, title, link, number) VALUES('$this->id', '$title', '$link', '$number')");
|
||||||
}
|
}
|
||||||
|
|
||||||
### Mark channels as being updated:
|
### Mark channels as being updated:
|
||||||
$result = mysql_query("UPDATE channel SET timestamp = '". time() ."' WHERE id = $this->id");
|
$result = db_query("UPDATE channel SET timestamp = '". time() ."' WHERE id = $this->id");
|
||||||
$this->timestamp = time();
|
$this->timestamp = time();
|
||||||
}
|
}
|
||||||
else print "<HR>RDF parser: 404 error?<BR><BR><PRE>$data</PRE><HR>";
|
else print "<HR>RDF parser: 404 error?<BR><BR><PRE>$data</PRE><HR>";
|
||||||
|
@ -169,11 +166,8 @@ class backend {
|
||||||
function displayHeadlines($timout = 1800) {
|
function displayHeadlines($timout = 1800) {
|
||||||
global $theme;
|
global $theme;
|
||||||
|
|
||||||
### Connect to database:
|
|
||||||
dbconnect();
|
|
||||||
|
|
||||||
### Get channel info:
|
### Get channel info:
|
||||||
$result = mysql_query("SELECT * FROM channel WHERE site = '$this->site'");
|
$result = db_query("SELECT * FROM channel WHERE site = '$this->site'");
|
||||||
|
|
||||||
if ($this->id) {
|
if ($this->id) {
|
||||||
|
|
||||||
|
@ -181,8 +175,8 @@ class backend {
|
||||||
if (time() - $this->timestamp > $timout) $this->url2sql();
|
if (time() - $this->timestamp > $timout) $this->url2sql();
|
||||||
|
|
||||||
### Grab headlines from database:
|
### Grab headlines from database:
|
||||||
$result = mysql_query("SELECT * FROM headlines WHERE id = $this->id ORDER BY number");
|
$result = db_query("SELECT * FROM headlines WHERE id = $this->id ORDER BY number");
|
||||||
while ($headline = mysql_fetch_object($result)) {
|
while ($headline = db_fetch_object($result)) {
|
||||||
$content .= "<LI><A HREF=\"$headline->link\">$headline->title</A></LI>";
|
$content .= "<LI><A HREF=\"$headline->link\">$headline->title</A></LI>";
|
||||||
}
|
}
|
||||||
### Add timestamp:
|
### Add timestamp:
|
||||||
|
@ -201,11 +195,8 @@ class backend {
|
||||||
# Description..: Adds this backend to the database.
|
# Description..: Adds this backend to the database.
|
||||||
#
|
#
|
||||||
function add() {
|
function add() {
|
||||||
### Connect to database:
|
|
||||||
dbconnect();
|
|
||||||
|
|
||||||
### Add channel:
|
### Add channel:
|
||||||
$result = mysql_query("INSERT INTO channel (site, file, url, contact, timestamp) VALUES ('$this->site', '$this->file', '$this->url', '$this->contact', 42)");
|
$result = db_query("INSERT INTO channel (site, file, url, contact, timestamp) VALUES ('$this->site', '$this->file', '$this->url', '$this->contact', 42)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -214,14 +205,11 @@ class backend {
|
||||||
# Description..: Deletes this backend
|
# Description..: Deletes this backend
|
||||||
#
|
#
|
||||||
function delete() {
|
function delete() {
|
||||||
### Connect to database:
|
|
||||||
dbconnect();
|
|
||||||
|
|
||||||
### Delete channel:
|
### Delete channel:
|
||||||
$result = mysql_query("DELETE FROM channel WHERE id = $this->id");
|
$result = db_query("DELETE FROM channel WHERE id = $this->id");
|
||||||
|
|
||||||
### Delete headlines:
|
### Delete headlines:
|
||||||
$result = mysql_query("DELETE FROM headlines WHERE id = $this->id");
|
$result = db_query("DELETE FROM headlines WHERE id = $this->id");
|
||||||
}
|
}
|
||||||
|
|
||||||
#####
|
#####
|
||||||
|
@ -229,14 +217,11 @@ class backend {
|
||||||
# Description..: Deletes all headlines associated with this backend.
|
# Description..: Deletes all headlines associated with this backend.
|
||||||
#
|
#
|
||||||
function refresh() {
|
function refresh() {
|
||||||
### Connect to database:
|
|
||||||
dbconnect();
|
|
||||||
|
|
||||||
### Delete headlines:
|
### Delete headlines:
|
||||||
$result = mysql_query("DELETE FROM headlines WHERE id = $this->id");
|
$result = db_query("DELETE FROM headlines WHERE id = $this->id");
|
||||||
|
|
||||||
### Mark channel as invalid to enforce an update:
|
### Mark channel as invalid to enforce an update:
|
||||||
$result = mysql_query("UPDATE channel SET timestamp = 42 WHERE id = $this->id");
|
$result = db_query("UPDATE channel SET timestamp = 42 WHERE id = $this->id");
|
||||||
}
|
}
|
||||||
|
|
||||||
#####
|
#####
|
||||||
|
|
36
backend.php
36
backend.php
|
@ -1,7 +1,5 @@
|
||||||
<?
|
<?
|
||||||
|
|
||||||
include "theme.inc";
|
|
||||||
include "backend.class.php";
|
|
||||||
|
|
||||||
function adminAddChannel() {
|
function adminAddChannel() {
|
||||||
?>
|
?>
|
||||||
|
@ -34,18 +32,15 @@ function adminAddChannel() {
|
||||||
function displayAll() {
|
function displayAll() {
|
||||||
global $theme;
|
global $theme;
|
||||||
|
|
||||||
### Connect to database:
|
|
||||||
dbconnect();
|
|
||||||
|
|
||||||
### Get channel info:
|
### Get channel info:
|
||||||
$result = mysql_query("SELECT * FROM channel ORDER BY id");
|
$result = db_query("SELECT * FROM channel ORDER BY id");
|
||||||
|
|
||||||
print "<HR>";
|
print "<HR>\n";
|
||||||
print "<TABLE BORDER=\"0\">";
|
print "<TABLE BORDER=\"0\">\n";
|
||||||
while ($channel = mysql_fetch_object($result)) {
|
while ($channel = db_fetch_object($result)) {
|
||||||
if ($state % 3 == 0) print " <TR>";
|
if ($state % 3 == 0) print " <TR>\n";
|
||||||
|
|
||||||
print " <TD ALIGN=\"center\" VALIGN=\"top\" WIDTH=\"33%\">";
|
print " <TD ALIGN=\"center\" VALIGN=\"top\" WIDTH=\"33%\">\n";
|
||||||
|
|
||||||
### Load backend from database:
|
### Load backend from database:
|
||||||
$backend = new backend($channel->id);
|
$backend = new backend($channel->id);
|
||||||
|
@ -53,33 +48,30 @@ function displayAll() {
|
||||||
### Read headlines from backend class:
|
### Read headlines from backend class:
|
||||||
$content = "";
|
$content = "";
|
||||||
for (reset($backend->headlines); $headline = current($backend->headlines); next($backend->headlines)) {
|
for (reset($backend->headlines); $headline = current($backend->headlines); next($backend->headlines)) {
|
||||||
$content .= "<LI>$headline</LI>";
|
$content .= "<LI>$headline</LI>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
### Print backend box to screen:
|
### Print backend box to screen:
|
||||||
$theme->box($backend->site, "$content<P ALIGN=\"right\">[ <A HREF=\"$backend->url\">more</A> ]");
|
$theme->box($backend->site, "$content<P ALIGN=\"right\">[ <A HREF=\"$backend->url\">more</A> ]\n");
|
||||||
print " </TD>";
|
print " </TD>\n";
|
||||||
|
|
||||||
if ($state % 3 == 2) print " </TR>";
|
if ($state % 3 == 2) print " </TR>\n";
|
||||||
|
|
||||||
$state += 1;
|
$state += 1;
|
||||||
}
|
}
|
||||||
print "</TABLE>";
|
print "</TABLE>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminMain() {
|
function adminMain() {
|
||||||
global $theme, $PHP_SELF;
|
global $theme, $PHP_SELF;
|
||||||
|
|
||||||
### Connect to database:
|
|
||||||
dbconnect();
|
|
||||||
|
|
||||||
### Get channel info:
|
### Get channel info:
|
||||||
$result = mysql_query("SELECT * FROM channel ORDER BY id");
|
$result = db_query("SELECT * FROM channel ORDER BY id");
|
||||||
|
|
||||||
print "<TABLE BORDER=\"0\" WIDTH=\"100%\" CELLSPACING=\"2\" CELLPADDING=\"4\">";
|
print "<TABLE BORDER=\"0\" WIDTH=\"100%\" CELLSPACING=\"2\" CELLPADDING=\"4\">";
|
||||||
print "
|
print "
|
||||||
<TR BGCOLOR=\"$theme->bgcolor1\"><TD ALIGN=\"center\"><B><FONT COLOR=\"$theme->fgcolor1\">Site</FONT></B></TD><TD ALIGN=\"center\"><B><FONT COLOR=\"$theme->fgcolor1\">Contact</FONT></B></TD><TD ALIGN=\"center\"><B><FONT COLOR=\"$theme->fgcolor1\">Last updated</FONT></B></TD><TD ALIGN=\"center\" COLSPAN=\"2\"><B><FONT COLOR=\"$theme->fgcolor1\">Operations</FONT></B></TD></TR>";
|
<TR BGCOLOR=\"$theme->bgcolor1\"><TD ALIGN=\"center\"><B><FONT COLOR=\"$theme->fgcolor1\">Site</FONT></B></TD><TD ALIGN=\"center\"><B><FONT COLOR=\"$theme->fgcolor1\">Contact</FONT></B></TD><TD ALIGN=\"center\"><B><FONT COLOR=\"$theme->fgcolor1\">Last updated</FONT></B></TD><TD ALIGN=\"center\" COLSPAN=\"2\"><B><FONT COLOR=\"$theme->fgcolor1\">Operations</FONT></B></TD></TR>";
|
||||||
while ($channel = mysql_fetch_object($result)) {
|
while ($channel = db_fetch_object($result)) {
|
||||||
### Load backend from database:
|
### Load backend from database:
|
||||||
$backend = new backend($channel->id);
|
$backend = new backend($channel->id);
|
||||||
|
|
||||||
|
@ -95,6 +87,8 @@ function adminMain() {
|
||||||
print "<BR><BR>";
|
print "<BR><BR>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include "backend.class.php";
|
||||||
|
include "theme.inc";
|
||||||
|
|
||||||
$theme->header();
|
$theme->header();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue