Commit 7fac91c2 authored by Dries's avatar Dries

- various smaller improvements

parent 8d249c5f
......@@ -16,6 +16,7 @@ drupal x.xx, xx/xx/xxxx
* improved account module:
+ added "acess control" to allow/deny certain usernames/e-mail addresses/hostnames
* improved comment module
* improved rating module
* improved story module:
+ added preview functionality for administrators
+ made it possible to permanently delete stories
......
......@@ -100,4 +100,33 @@ function user_ban($mask, $type) {
return db_fetch_object($result);
}
function user_gravity($id) {
global $status;
$period = 5184000; // maximum 60 days
$number = 30; // maximum 30 comments
$r1 = db_query("SELECT COUNT(nid) AS number FROM node WHERE author = '$id' AND (". time() ." - timestamp < $period) AND status = '$status[posted]'");
if ($story = db_fetch_object($r1)) {
$bonus += $story->number;
}
$r2 = db_query("SELECT COUNT(nid) AS number FROM node WHERE author = '$id' AND (". time() ." - timestamp < $period) AND status = '$status[dumped]'");
if ($story = db_fetch_object($r2)) {
$bonus -= $story->number;
}
$r3 = db_query("SELECT score, votes FROM comments WHERE author = '$id' AND (". time() ." - timestamp < $period) ORDER BY timestamp LIMIT $number");
while ($comment = db_fetch_object($r3)) {
$weight++;
$score += $weight * $comment->score;
$votes += $weight * $comment->votes;
}
$bonus += $weight / 5;
if ($votes > 0) return ($score + $weight) / $votes + $bonus;
else return 0;
}
?>
\ No newline at end of file
......@@ -46,12 +46,6 @@ function account_find($keys) {
return $find;
}
function account_search() {
global $keys, $mod;
print search_form($keys);
print search_data($keys, $mod);
}
function account_ac_add($edit) {
db_query("INSERT INTO access (mask, type, reason) VALUES ('". check_input($edit[mask]) ."', '". check_input($edit[type]) ."', '". check_input($edit[reason]) ."')", 1);
}
......@@ -225,7 +219,7 @@ function account_view($name) {
}
function account_admin() {
global $op, $edit, $id, $order, $name;
global $op, $edit, $id, $mod, $keys, $order, $name;
print "<SMALL> <A HREF=\"admin.php?mod=account&op=access\">access control</A> | <A HREF=\"admin.php?mod=account&op=search\">search account</A> | <A HREF=\"admin.php?mod=account\">overview</A> | <A HREF=\"admin.php?mod=account&op=help\">help</A></SMALL><HR>\n";
......@@ -258,7 +252,8 @@ function account_admin() {
print account_help();
break;
case "search":
print account_search();
print search_form($keys);
print search_data($keys, $mod);
break;
case "View account":
case "view":
......
......@@ -17,21 +17,6 @@ function Book($nid, $userid, $title, $body, $parent, $weight, $timestamp) {
}
}
function book_navigation($node) {
if ($node->nid && $node->parent && $node->weight) {
$next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE b.parent = '$node->parent' AND b.weight > $node->weight ORDER BY b.weight ASC"));
$prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE b.parent = '$node->parent' AND b.weight < $node->weight ORDER BY b.weight DESC"));
}
$output .= "<HR>";
$output .= "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">\n";
$output .= " <TR><TD ALIGN=\"left\" WIDTH=\"33%\">". ($prev ? "<A HREF=\"node.php?id=$prev->nid\">". t("previous") ."</A>" : t("previous")) ."</TD><TD ALIGN=\"center\" WIDTH=\"34%\"><A HREF=\"module.php?mod=book\">index</A></TD><TD ALIGN=\"right\" WIDTH=\"33%\">". ($next ? "<A HREF=\"node.php?id=$next->nid\">". t("next") ."</A>" : t("next")) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"left\" WIDTH=\"33%\">". ($prev ? "<SMALL>". check_output($prev->title) ."</SMALL>" : "") ."</TD><TD ALIGN=\"center\" WIDTH=\"34%\">". ($node->parent ? "<A HREF=\"node.php?id=$node->parent\">". t("up") ."</A>" : t("up")) ."</TD><TD ALIGN=\"right\" WIDTH=\"33%\">". ($next ? "<SMALL>". check_output($next->title) ."</SMALL>" : "") ."</TD></TR>\n";
$output .= "</TABLE>\n";
return $output;
}
function book_location($node, $nodes = array()) {
$parent = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.nid = '$node->parent'"));
if ($parent->title) {
......@@ -41,7 +26,7 @@ function book_location($node, $nodes = array()) {
return $nodes;
}
function theme_book($node) {
function book_view($node, $page = 1) {
global $theme;
if ($node->nid && $node->parent) {
......@@ -72,19 +57,9 @@ function theme_book($node) {
$output .= " <TR><TD ALIGN=\"left\" WIDTH=\"33%\">". ($prev ? "<SMALL>". check_output($prev->title) ."</SMALL>" : "&nbsp;") ."</TD><TD ALIGN=\"center\" WIDTH=\"34%\">". ($node->parent ? "<A HREF=\"node.php?id=$node->parent\">". t("up") ."</A>" : t("up")) ."</TD><TD ALIGN=\"right\" WIDTH=\"33%\">". ($next ? "<SMALL>". check_output($next->title) ."</SMALL>" : "&nbsp;") ."</TD></TR>\n";
$output .= "</TABLE>\n";
if ($page) $theme->header();
$theme->box(t("Handbook"), $output);
}
function book_view($node, $page = 1) {
if ($page) {
global $theme;
$theme->header();
theme_book($node);
$theme->footer();
}
else {
theme_book($node);
}
if ($page) $theme->footer();
}
function book_find($keys) {
......@@ -97,12 +72,6 @@ function book_find($keys) {
return $find;
}
function book_search() {
global $keys, $mod;
print search_form($keys);
print search_data($keys, $mod);
}
function book_toc($parent = 0, $indent = "", $toc = array()) {
global $status;
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight");
......@@ -203,7 +172,7 @@ function book_list() {
}
function book_admin() {
global $op, $id, $edit, $user;
global $op, $id, $edit, $mod, $keys, $user;
print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new page</A> | <A HREF=\"admin.php?mod=book&op=search\">search book</A> | <A HREF=\"admin.php?mod=book&op=list\">list overview</A> | <A HREF=\"admin.php?mod=book\">tree overview</A></SMALL><HR>\n";
......@@ -218,7 +187,8 @@ function book_admin() {
print book_form(node_get_array(nid, $id));
break;
case "search":
book_search();
print search_form($keys);
print search_data($keys, $mod);
break;
case t("Preview"):
book_view(new Book(($edit[nid] ? $edit[nid] : -1), ($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
......@@ -238,24 +208,41 @@ function book_page($id = 0) {
book_view(node_get_object("nid", $nid));
}
function book_update($id) {
global $status;
if ($node = node_get_object("nid", $id)) {
if ($node->status != $status[posted]) {
return t("You can only update accepted pages: pages that are still queued or already expired can not be updated.");
}
else if (db_result(db_query("SELECT COUNT(nid) FROM node WHERE pid = '$node->nid' AND status = '$status[queued]'"))) {
return t("There is already an update for this node queued: we can only process one update at the time.");
}
else {
return book_form(array(nid => -1, pid => $id, title => $node->title, body => $node->body, parent => $node->parent));
}
}
}
function book_user() {
global $edit, $id, $op, $theme, $user;
$title = t("Submit a book page");
switch($op) {
case "update":
$node = node_get_object("nid", $id);
$theme->box("Update a book page", book_form(array(nid => -1, pid => $id, title => $node->title, body => $node->body, parent => $node->parent)));
$theme->box($title, book_update($id));
break;
case t("Preview"):
book_view(new Book(($edit[nid] ? $edit[nid] : -1), $user->userid, $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
$theme->box("Submit a book page", book_form($edit));
$theme->box($title, book_form($edit));
break;
case t("Submit"):
book_save($edit);
$theme->box(t("Submit a book page"), t("Thank you for your submission."));
$theme->box($title, t("Thank you for your submission."));
break;
default:
$theme->box("Submit a book page", book_form());
$theme->box($title, book_form());
}
}
......
......@@ -17,21 +17,6 @@ function Book($nid, $userid, $title, $body, $parent, $weight, $timestamp) {
}
}
function book_navigation($node) {
if ($node->nid && $node->parent && $node->weight) {
$next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE b.parent = '$node->parent' AND b.weight > $node->weight ORDER BY b.weight ASC"));
$prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE b.parent = '$node->parent' AND b.weight < $node->weight ORDER BY b.weight DESC"));
}
$output .= "<HR>";
$output .= "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">\n";
$output .= " <TR><TD ALIGN=\"left\" WIDTH=\"33%\">". ($prev ? "<A HREF=\"node.php?id=$prev->nid\">". t("previous") ."</A>" : t("previous")) ."</TD><TD ALIGN=\"center\" WIDTH=\"34%\"><A HREF=\"module.php?mod=book\">index</A></TD><TD ALIGN=\"right\" WIDTH=\"33%\">". ($next ? "<A HREF=\"node.php?id=$next->nid\">". t("next") ."</A>" : t("next")) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"left\" WIDTH=\"33%\">". ($prev ? "<SMALL>". check_output($prev->title) ."</SMALL>" : "") ."</TD><TD ALIGN=\"center\" WIDTH=\"34%\">". ($node->parent ? "<A HREF=\"node.php?id=$node->parent\">". t("up") ."</A>" : t("up")) ."</TD><TD ALIGN=\"right\" WIDTH=\"33%\">". ($next ? "<SMALL>". check_output($next->title) ."</SMALL>" : "") ."</TD></TR>\n";
$output .= "</TABLE>\n";
return $output;
}
function book_location($node, $nodes = array()) {
$parent = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.nid = '$node->parent'"));
if ($parent->title) {
......@@ -41,7 +26,7 @@ function book_location($node, $nodes = array()) {
return $nodes;
}
function theme_book($node) {
function book_view($node, $page = 1) {
global $theme;
if ($node->nid && $node->parent) {
......@@ -72,19 +57,9 @@ function theme_book($node) {
$output .= " <TR><TD ALIGN=\"left\" WIDTH=\"33%\">". ($prev ? "<SMALL>". check_output($prev->title) ."</SMALL>" : "&nbsp;") ."</TD><TD ALIGN=\"center\" WIDTH=\"34%\">". ($node->parent ? "<A HREF=\"node.php?id=$node->parent\">". t("up") ."</A>" : t("up")) ."</TD><TD ALIGN=\"right\" WIDTH=\"33%\">". ($next ? "<SMALL>". check_output($next->title) ."</SMALL>" : "&nbsp;") ."</TD></TR>\n";
$output .= "</TABLE>\n";
if ($page) $theme->header();
$theme->box(t("Handbook"), $output);
}
function book_view($node, $page = 1) {
if ($page) {
global $theme;
$theme->header();
theme_book($node);
$theme->footer();
}
else {
theme_book($node);
}
if ($page) $theme->footer();
}
function book_find($keys) {
......@@ -97,12 +72,6 @@ function book_find($keys) {
return $find;
}
function book_search() {
global $keys, $mod;
print search_form($keys);
print search_data($keys, $mod);
}
function book_toc($parent = 0, $indent = "", $toc = array()) {
global $status;
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight");
......@@ -203,7 +172,7 @@ function book_list() {
}
function book_admin() {
global $op, $id, $edit, $user;
global $op, $id, $edit, $mod, $keys, $user;
print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new page</A> | <A HREF=\"admin.php?mod=book&op=search\">search book</A> | <A HREF=\"admin.php?mod=book&op=list\">list overview</A> | <A HREF=\"admin.php?mod=book\">tree overview</A></SMALL><HR>\n";
......@@ -218,7 +187,8 @@ function book_admin() {
print book_form(node_get_array(nid, $id));
break;
case "search":
book_search();
print search_form($keys);
print search_data($keys, $mod);
break;
case t("Preview"):
book_view(new Book(($edit[nid] ? $edit[nid] : -1), ($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
......@@ -238,24 +208,41 @@ function book_page($id = 0) {
book_view(node_get_object("nid", $nid));
}
function book_update($id) {
global $status;
if ($node = node_get_object("nid", $id)) {
if ($node->status != $status[posted]) {
return t("You can only update accepted pages: pages that are still queued or already expired can not be updated.");
}
else if (db_result(db_query("SELECT COUNT(nid) FROM node WHERE pid = '$node->nid' AND status = '$status[queued]'"))) {
return t("There is already an update for this node queued: we can only process one update at the time.");
}
else {
return book_form(array(nid => -1, pid => $id, title => $node->title, body => $node->body, parent => $node->parent));
}
}
}
function book_user() {
global $edit, $id, $op, $theme, $user;
$title = t("Submit a book page");
switch($op) {
case "update":
$node = node_get_object("nid", $id);
$theme->box("Update a book page", book_form(array(nid => -1, pid => $id, title => $node->title, body => $node->body, parent => $node->parent)));
$theme->box($title, book_update($id));
break;
case t("Preview"):
book_view(new Book(($edit[nid] ? $edit[nid] : -1), $user->userid, $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
$theme->box("Submit a book page", book_form($edit));
$theme->box($title, book_form($edit));
break;
case t("Submit"):
book_save($edit);
$theme->box(t("Submit a book page"), t("Thank you for your submission."));
$theme->box($title, t("Thank you for your submission."));
break;
default:
$theme->box("Submit a book page", book_form());
$theme->box($title, book_form());
}
}
......
......@@ -13,12 +13,6 @@ function comment_find($keys) {
return $find;
}
function comment_search() {
global $keys, $mod;
print search_form($keys);
print search_data($keys, $mod);
}
function comment_edit($id) {
$result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = '$id'");
......@@ -84,7 +78,7 @@ function comment_display($order = "date") {
}
function comment_admin() {
global $op, $id, $subject, $comment, $order;
global $op, $id, $mod, $keys, $subject, $comment, $order;
print "<SMALL><A HREF=\"admin.php?mod=comment\">overview</A> | <A HREF=\"admin.php?mod=comment&op=search\">search comment</A></SMALL><HR>\n";
......@@ -93,7 +87,8 @@ function comment_admin() {
comment_edit($id);
break;
case "search":
comment_search();
print search_form($keys);
print search_data($keys, $mod);
break;
case "Save comment":
comment_save(check_input($id), check_input($subject), check_input($comment));
......
......@@ -13,12 +13,6 @@ function comment_find($keys) {
return $find;
}
function comment_search() {
global $keys, $mod;
print search_form($keys);
print search_data($keys, $mod);
}
function comment_edit($id) {
$result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = '$id'");
......@@ -84,7 +78,7 @@ function comment_display($order = "date") {
}
function comment_admin() {
global $op, $id, $subject, $comment, $order;
global $op, $id, $mod, $keys, $subject, $comment, $order;
print "<SMALL><A HREF=\"admin.php?mod=comment\">overview</A> | <A HREF=\"admin.php?mod=comment&op=search\">search comment</A></SMALL><HR>\n";
......@@ -93,7 +87,8 @@ function comment_admin() {
comment_edit($id);
break;
case "search":
comment_search();
print search_form($keys);
print search_data($keys, $mod);
break;
case "Save comment":
comment_save(check_input($id), check_input($subject), check_input($comment));
......
......@@ -21,12 +21,6 @@ function diary_find($keys) {
}
function diary_search() {
global $keys, $mod;
print search_form($keys);
print search_data($keys, $mod);
}
function diary_page_overview($num = 20) {
global $theme, $user;
......@@ -316,7 +310,7 @@ function diary_admin_display($order = "date") {
function diary_admin() {
global $op, $id, $text, $order;
global $op, $id, $mod, $keys, $text, $order;
print "<SMALL><A HREF=\"admin.php?mod=diary\">overview</A> | <A HREF=\"admin.php?mod=diary&op=search\">search diary</A> | <A HREF=\"admin.php?mod=diary&op=help\">help</A></SMALL><HR>\n";
......@@ -332,7 +326,8 @@ function diary_admin() {
diary_help();
break;
case "search":
diary_search();
print search_form($keys);
print search_data($keys, $mod);
break;
case "Save diary entry":
diary_admin_save(check_input($id), check_input($text));
......
......@@ -6,37 +6,10 @@
"block" => "rating_block");
function rating_cron() {
global $status;
$result = db_query("SELECT id FROM users");
$period = 5184000; // 60 days
$number = 30; // 30 comments
$offset = 5; // 5 comments
$r1 = db_query("SELECT id, userid FROM users");
while ($rating = db_fetch_object($r1)) {
unset($bonus); unset($votes); unset($score); unset($value); unset($weight);
$r2 = db_query("SELECT COUNT(nid) AS number FROM node WHERE author = '$rating->id' AND (". time() ." - timestamp < $period) AND status = '$status[posted]'");
if ($story = db_fetch_object($r2)) {
$bonus += $story->number / 2;
}
$r3 = db_query("SELECT COUNT(nid) AS number FROM node WHERE author = '$rating->id' AND (". time() ." - timestamp < $period) AND status = '$status[dumped]'");
if ($story = db_fetch_object($r3)) {
$bonus -= $story->number / 2;
}
$r4 = db_query("SELECT score, votes FROM comments WHERE author = '$rating->id' AND (". time() ." - timestamp < $period) ORDER BY timestamp LIMIT $number");
while ($comment = db_fetch_object($r4)) {
$weight++;
$score += $weight * $comment->score;
$votes += $weight * $comment->votes;
}
if ($weight >= $offset && $votes > 0) {
$value = ($score + $weight) / $votes + $bonus;
db_query("UPDATE users SET rating = '$value' WHERE id = '$rating->id'");
}
while ($account = db_fetch_object($result)) {
db_query("UPDATE users SET rating = '". user_gravity($account->id) ."' WHERE id = '$account->id'");
}
}
......
......@@ -29,12 +29,6 @@ function story_find($keys) {
return $find;
}
function story_search() {
global $keys, $mod;
print search_form($keys);
print search_data($keys, $mod);
}
function story_help() {
?>
<P>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</P>
......@@ -194,7 +188,7 @@ function story_overview() {
}
function story_admin() {
global $id, $edit, $op, $theme, $user;
global $id, $edit, $mod, $keys, $op, $theme, $user;
print "<SMALL><A HREF=\"admin.php?mod=story&op=add\">add new story</A> | <A HREF=\"admin.php?mod=story\">overview</A> | <A HREF=\"admin.php?mod=story&op=search\">search story</A> | <A HREF=\"admin.php?mod=story&op=help\">help</A></SMALL><HR>\n";
......@@ -213,7 +207,8 @@ function story_admin() {
story_help();
break;
case "search":
story_search();
print search_form($keys);
print search_data($keys, $mod);
break;
case t("Preview"):
story_view(new Story(($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
......
......@@ -29,12 +29,6 @@ function story_find($keys) {
return $find;
}
function story_search() {
global $keys, $mod;
print search_form($keys);
print search_data($keys, $mod);
}
function story_help() {
?>
<P>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</P>
......@@ -194,7 +188,7 @@ function story_overview() {
}
function story_admin() {
global $id, $edit, $op, $theme, $user;
global $id, $edit, $mod, $keys, $op, $theme, $user;
print "<SMALL><A HREF=\"admin.php?mod=story&op=add\">add new story</A> | <A HREF=\"admin.php?mod=story\">overview</A> | <A HREF=\"admin.php?mod=story&op=search\">search story</A> | <A HREF=\"admin.php?mod=story&op=help\">help</A></SMALL><HR>\n";
......@@ -213,7 +207,8 @@ function story_admin() {
story_help();
break;
case "search":
story_search();
print search_form($keys);
print search_data($keys, $mod);
break;
case t("Preview"):
story_view(new Story(($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
......
......@@ -5,7 +5,7 @@
function node_failure() {
global $theme;
$theme->header();
$theme->box(t("Warning: not found"), t("The content or data you requested does not exist or is not accessible."));
$theme->box(t("Not found"), t("The node you are looking for does not exist yet or is no longer accessible:") ."<UL><LI><A HREF=\"search.php\">". t("search node") ."</A></LI><LI><A HREF=\"submit.php\">". t("add node") ."</A></LI></UL>\n");
$theme->footer();
}
......@@ -49,8 +49,12 @@ function node_history($node) {
node_view($node, 1);
}
}
else node_failure();
else {
node_failure();
}
}
else {
node_failure();
}
else node_failure();
?>
\ No newline at end of file
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