Commit 8511d9fb authored by Dries's avatar Dries
Browse files

A batch of patches:

  - configuration:
    + renamed $db_name to $db_user
    + renamed $db_base to $db_name
  - fixed small diary glitch
  - fixed initial-comment-score problem
  - fixed comment rating bug: improved the API and updated the
    themes
  - removed some tabs from Steven ;)
  - fixed backend warnings and improved robustness
    I'm not happy yet with the headline grabber - it generates
    too many SQL errors.
  - some small cosmetic changes in comment.module
  - fixed minor glitch in format_interval()
parent b604c438
......@@ -265,7 +265,7 @@ function comment_post($pid, $sid, $subject, $comment) {
watchdog("comment", "discussion: added comment with subject '$subject'");
// Add comment to database:
db_query("INSERT INTO comments (pid, sid, author, subject, comment, hostname, timestamp) VALUES ($pid, $sid, '$user->id', '". check_input($subject) ."', '". check_input($comment) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."')");
db_query("INSERT INTO comments (pid, sid, author, subject, comment, hostname, timestamp, score) VALUES ($pid, $sid, '$user->id', '". check_input($subject) ."', '". check_input($comment) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."', '". ($user->userid ? 1 : 0) ."')");
// Compose header:
header("Location: discussion.php?id=$sid");
......
......@@ -7,9 +7,9 @@
* just adjust the handlers to your needs.
*/
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");
function db_connect($host, $user, $pass, $name) {
mysql_pconnect($host, $user, $pass) or die(mysql_Error());
mysql_select_db($name) or die ("unable to select database");
// NOTE: we are using a persistent connection!
}
......@@ -48,6 +48,6 @@ function db_result($qid, $field = 0) {
#
# Automatically connect to database:
#
db_connect($db_host, $db_name, $db_pass, $db_base);
db_connect($db_host, $db_user, $db_pass, $db_name);
?>
......@@ -68,7 +68,7 @@ function format_interval($timestamp) {
$output .= floor($timestamp / 60) ." min ";
$timestamp = $timestamp % 60;
}
if ($timestamp > 0) {
if ($timestamp >= 0) {
$output .= "$timestamp sec";
}
return $output;
......
......@@ -3,12 +3,10 @@
#
# Database settings:
#
### host: "http://localhost/":
$db_host = "localhost";
$db_name = "name";
$db_pass = "pass";
$db_base = "base";
$db_user = "username";
$db_pass = "password";
$db_name = "database";
#
......
......@@ -27,15 +27,18 @@ function menu($name, $module) {
$content .= "<LI><A HREF=\"account.php?op=edit&topic=user\">edit your information</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=edit&topic=site\">edit your preferences</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=edit&topic=content\">edit site content</A></LI>\n";
if (($user->id) && ($user->permissions == 1 || $user->id == 1)) {
$content .= "<P>\n";
$content .= "<LI><A HREF=\"admin.php\">administrate " . $site_name . "</A></LI>\n";
}
$content .= "<P>\n";
if (ksort($menu)) {
if (($user->id) && ($user->permissions == 1 || $user->id == 1)) {
$content .= "<LI><A HREF=\"admin.php\">administrate ". $site_name ."</A></LI>\n";
$content .= "<P>\n";
}
if ($menu && ksort($menu)) {
foreach ($menu as $link=>$url) $content .= "<LI><A HREF=\"$url\">$link</A></LI>\n";
$content .= "<P>\n";
}
$content .= "<LI><A HREF=\"account.php?op=logout\">logout</A></LI>\n";
$theme->box("$user->userid's configuration", "$content");
......@@ -127,16 +130,16 @@ function theme_related_links($theme, $story) {
$theme->box("Related links", $content);
}
function theme_comment_moderation($id, $author, $score, $votes) {
function theme_comment_moderation($comment) {
global $user, $comment_votes;
if ($user->id && $user->userid != $author && !user_getHistory($user->history, "c$id")) {
$output .= "<SELECT NAME=\"moderate[$id]\">\n";
if ($user->id && $user->userid != $comment->userid && !user_getHistory($user->history, "c$comment->cid")) {
$output .= "<SELECT NAME=\"moderate[$comment->cid]\">\n";
foreach ($comment_votes as $key=>$value) $output .= " <OPTION VALUE=\"$value\">$key</OPTION>\n";
$output .= "</SELECT>\n";
}
else {
$output .= "<TABLE BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"0\"><TR><TD>score:</TD><TD>". format_data($score) ."</TD></TR><TR><TD>votes:</TD><TD>". format_data($votes) ."</TR></TABLE>";
$output .= "<TABLE BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"1\"><TR><TD>score:</TD><TD>". format_data($comment->score) ."</TD></TR><TR><TD>votes:</TD><TD>". format_data($comment->votes) ."</TR></TABLE>";
}
return $output;
......
......@@ -16,7 +16,7 @@ class backend {
// Contains the parsed rdf/rss/xml file:
var $headlines = array(); // latest headlines
function backend($id, $site = "", $url = "", $file = "", $contact = "", $timout = 3600) {
function backend($id, $site = "", $url = "", $file = "", $contact = "", $timout = 10800) {
// Get channel info:
$result = db_query("SELECT * FROM channel WHERE id = '$id' OR site = '$site'");
......@@ -153,7 +153,7 @@ class backend {
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)");
$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) ."', 1)");
}
function delete() {
......@@ -169,7 +169,7 @@ class backend {
$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");
$result = db_query("UPDATE channel SET timestamp = 1 WHERE id = $this->id");
}
function dump() {
......
......@@ -16,12 +16,12 @@ function comment_edit($id) {
$output .= "<P>\n";
$output .= " <B>Subject:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" VALUE=\"". check_output(check_field($comment->subject)) ."\"><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" VALUE=\"". check_output(check_field($comment->subject)) ."\">\n";
$output .= "</P>\n";
$output .= "<P>\n";
$output .= "<B>Comment:</B><BR>\n";
$output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">". check_output($comment->comment) ."</TEXTAREA><BR>\n";
$output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">". check_output($comment->comment) ."</TEXTAREA>\n";
$output .= "</P>\n";
$output .= "<P>\n";
......
......@@ -16,12 +16,12 @@ function comment_edit($id) {
$output .= "<P>\n";
$output .= " <B>Subject:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" VALUE=\"". check_output(check_field($comment->subject)) ."\"><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" VALUE=\"". check_output(check_field($comment->subject)) ."\">\n";
$output .= "</P>\n";
$output .= "<P>\n";
$output .= "<B>Comment:</B><BR>\n";
$output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">". check_output($comment->comment) ."</TEXTAREA><BR>\n";
$output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">". check_output($comment->comment) ."</TEXTAREA>\n";
$output .= "</P>\n";
$output .= "<P>\n";
......
......@@ -220,7 +220,7 @@ function diary_user($username, $section, $operation) {
function diary_menu() {
global $user;
return array("edit your diary" => "module.php?mod=diary&op=edit", "view your diary" => "module.php?mod=diary&op=view");
return array("edit your diary" => "module.php?mod=diary&op=add", "view your diary" => "module.php?mod=diary&op=view");
}
function diary_block() {
......
......@@ -22,7 +22,7 @@ function drupal_page() {
";
$handle = opendir("drupal");
while ($file = readdir($handle)) if (ereg(".jpg", $file)) $output .= " <LI><SMALL><A HREF=\"drupal/$file\">$file</A></SMALL></LI>\n";
while ($file = readdir($handle)) if (ereg(".jpg", $file) || ereg(".gif", $file)) $output .= " <LI><SMALL><A HREF=\"drupal/$file\">$file</A></SMALL></LI>\n";
closedir($handle);
$theme->header();
......
......@@ -22,7 +22,7 @@ function drupal_page() {
";
$handle = opendir("drupal");
while ($file = readdir($handle)) if (ereg(".jpg", $file)) $output .= " <LI><SMALL><A HREF=\"drupal/$file\">$file</A></SMALL></LI>\n";
while ($file = readdir($handle)) if (ereg(".jpg", $file) || ereg(".gif", $file)) $output .= " <LI><SMALL><A HREF=\"drupal/$file\">$file</A></SMALL></LI>\n";
closedir($handle);
$theme->header();
......
......@@ -27,11 +27,13 @@ function headline_blocks() {
// Load backend from database:
$backend = new backend($channel->id);
// Read headline from backend class:
$content = "";
for (reset($backend->headline); $headline = current($backend->headline); next($backend->headline)) {
$content .= "<LI>$headline</LI>\n";
if ($backend->headlines) {
unset($content);
foreach ($backend->headlines as $headline) $content .= "<LI>$headline</LI>\n";
}
else {
$content = "no headlines available\n";
}
// Print backend box to screen:
......@@ -79,13 +81,16 @@ function headline_block() {
$result = db_query("SELECT * FROM channel");
while ($channel = db_fetch_object($result)) {
$backend = new Backend($channel->id);
$content = "";
if ($backend->headline) {
for (reset($backend->headline); $headline = current($backend->headline); next($backend->headline)) {
if ($backend->headlines) {
unset($content);
foreach ($backend->headlines as $headline) {
$content .= "<LI>$headline</LI>\n";
}
}
else {
$content = "no headlines available";
}
$blocks[$channel->id]["subject"] = $backend->site;
$blocks[$channel->id]["content"] = $content;
......@@ -111,7 +116,7 @@ function headline_admin_main() {
$output .= "<TR>\n";
$output .= " <TD><A HREF=\"$backend->url\">$backend->site</A></TD>\n";
$output .= " <TD><A HREF=\"mailto:$backend->contact\">$backend->contact</A></TD>\n";
$output .= " <TD ALIGN=\"center\">". format_interval(time() - $backend->timestamp) ." ago</TD>\n";
$output .= " <TD ALIGN=\"center\">". ($backend->timestamp == 1 ? "failed" : format_interval(time() - $backend->timestamp) ." ago") ."</TD>\n";
$output .= " <TD ALIGN=\"center\"><A HREF=\"admin.php?mod=headline&op=refresh&id=$backend->id\">refresh</A></TD>\n";
$output .= " <TD ALIGN=\"center\"><A HREF=\"admin.php?mod=headline&op=delete&id=$backend->id\">delete</A></TD>\n";
$output .= "</TR>\n";
......
......@@ -168,7 +168,7 @@ function comment($comment, $link, $thread = "") {
// Moderation:
print " <TD ALIGN=\"right\" ROWSPAN=\"3\" VALIGN=\"middle\" WIDTH=\"15%\">\n";
theme_comment_moderation($comment->cid, $comment->userid, $comment->score, $comment->votes);
print theme_comment_moderation($comment);
print " </TD>\n";
print " </TR>\n";
......
......@@ -224,7 +224,7 @@ function comment($comment, $link, $thread = "") {
// Moderation:
echo " <TD ALIGN=\"right\" ROWSPAN=\"3\" VALIGN=\"middle\" WIDTH=\"15%\">";
theme_comment_moderation($comment->cid, $comment->userid, $comment->score, $comment->votes);
print theme_comment_moderation($comment);
echo " </TD>";
echo " </TR>";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment