From 7fac91c2cc4ca3dedf4459f9cdf9955e33be0f42 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 4 Apr 2001 21:09:24 +0000 Subject: - various smaller improvements --- modules/account.module | 11 ++----- modules/book.module | 69 +++++++++++++++++------------------------- modules/book/book.module | 69 +++++++++++++++++------------------------- modules/comment.module | 11 ++----- modules/comment/comment.module | 11 ++----- modules/diary.module | 11 ++----- modules/rating.module | 33 ++------------------ modules/story.module | 11 ++----- modules/story/story.module | 11 ++----- 9 files changed, 77 insertions(+), 160 deletions(-) (limited to 'modules') diff --git a/modules/account.module b/modules/account.module index 5fd8f85ad..e893726a1 100644 --- a/modules/account.module +++ b/modules/account.module @@ -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 " access control | search account | overview | help
\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": diff --git a/modules/book.module b/modules/book.module index ed0972bd0..62662ee8f 100644 --- a/modules/book.module +++ b/modules/book.module @@ -17,21 +17,6 @@ class Book { } } -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 .= "
"; - $output .= "\n"; - $output .= " \n"; - $output .= " \n"; - $output .= "
". ($prev ? "nid\">". t("previous") ."" : t("previous")) ."index". ($next ? "nid\">". t("next") ."" : t("next")) ."
". ($prev ? "". check_output($prev->title) ."" : "") ."". ($node->parent ? "parent\">". t("up") ."" : t("up")) ."". ($next ? "". check_output($next->title) ."" : "") ."
\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 .= " ". ($prev ? "". check_output($prev->title) ."" : " ") ."". ($node->parent ? "parent\">". t("up") ."" : t("up")) ."". ($next ? "". check_output($next->title) ."" : " ") ."\n"; $output .= "\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 "add new page | search book | list overview | tree overview
\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()); } } diff --git a/modules/book/book.module b/modules/book/book.module index ed0972bd0..62662ee8f 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -17,21 +17,6 @@ class Book { } } -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 .= "
"; - $output .= "\n"; - $output .= " \n"; - $output .= " \n"; - $output .= "
". ($prev ? "nid\">". t("previous") ."" : t("previous")) ."index". ($next ? "nid\">". t("next") ."" : t("next")) ."
". ($prev ? "". check_output($prev->title) ."" : "") ."". ($node->parent ? "parent\">". t("up") ."" : t("up")) ."". ($next ? "". check_output($next->title) ."" : "") ."
\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 .= " ". ($prev ? "". check_output($prev->title) ."" : " ") ."". ($node->parent ? "parent\">". t("up") ."" : t("up")) ."". ($next ? "". check_output($next->title) ."" : " ") ."\n"; $output .= "\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 "add new page | search book | list overview | tree overview
\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()); } } diff --git a/modules/comment.module b/modules/comment.module index 26e7e5aab..cee88f998 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -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 "overview | search comment
\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)); diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 26e7e5aab..cee88f998 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -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 "overview | search comment
\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)); diff --git a/modules/diary.module b/modules/diary.module index 75210c839..a706a106f 100644 --- a/modules/diary.module +++ b/modules/diary.module @@ -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 "overview | search diary | help
\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)); diff --git a/modules/rating.module b/modules/rating.module index eadf1483c..a78df4ce3 100644 --- a/modules/rating.module +++ b/modules/rating.module @@ -6,37 +6,10 @@ $module = array("cron" => "rating_cron", "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'"); } } diff --git a/modules/story.module b/modules/story.module index 82254440b..fbe8a12f4 100644 --- a/modules/story.module +++ b/modules/story.module @@ -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() { ?>

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.

@@ -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 "add new story | overview | search story | help
\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); diff --git a/modules/story/story.module b/modules/story/story.module index 82254440b..fbe8a12f4 100644 --- a/modules/story/story.module +++ b/modules/story/story.module @@ -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() { ?>

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.

@@ -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 "add new story | overview | search story | help
\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); -- cgit v1.2.3