Commit 8d013b16 authored by Dries's avatar Dries

- Applied Moshe's tablesort patch!  Note that I changed the arrow images
  because those of Moshe where not identical.
parent 0bbe5890
...@@ -2,6 +2,7 @@ Drupal x.x.x, xxxx-xx-xx (to be released) ...@@ -2,6 +2,7 @@ Drupal x.x.x, xxxx-xx-xx (to be released)
------------------------ ------------------------
- added support for configurable URLs. - added support for configurable URLs.
- added support for sortable table columns.
- database backend: - database backend:
* added support for database table prefxing. * added support for database table prefxing.
- performance improvements: - performance improvements:
......
<?php
function tablesort_init($header) {
static $ts;
if (!$ts) {
$ts["order"] = tablesort_get_order($header);
$ts["order_sql"] = tablesort_get_order_sql($header, $ts["order"]);
$ts["sort"] = tablesort_get_sort($header);
$ts["query_string"] = tablesort_get_querystring();
}
return $ts;
}
function tablesort_pager() {
return array ("order" => $_GET['order'], "sort" => $_GET['sort']);
}
function tablesort_sql($header) {
$ts = tablesort_init($header);
return " ORDER BY ". $ts["order_sql"]. " ". strtoupper($ts["sort"]);
}
function tablesort($cell, $header) {
global $theme;
$ts = tablesort_init($header);
// special formatting for the currently sorted column header
if ($cell["data"] == $ts["order"]) {
$cell["class"] = "cell-highlight";
$image = "&nbsp;<img src=\"". $theme->image("arrow-". $ts["sort"]. ".gif"). "\"></img>";
}
$cell["data"] = l($cell["data"], $_GET["q"], array(), "sort=". $ts["sort"]. "&order=". urlencode($cell["data"]). $ts["query_string"]). $image;
return $cell;
}
function tablesort_get_querystring() {
$cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST;
// reset ($cgi);
foreach ($cgi as $key => $val) {
if ($key != "order" && $key != "sort" && $key != "q") {
$query_string .= "&" . $key . "=" . $val;
}
}
return $query_string;
}
function tablesort_get_order($headers) {
if ($_GET['order'] != NULL) {
return $_GET['order'];
}
else {
foreach ($headers as $header) {
if ($header["sort"] == 'asc' || $header["sort"] == 'desc') {
return $header["data"];
}
elseif (!$first) {
// the first column specified is initial 'order by' field unless otherwise specified
$first = $header["data"];
}
}
return $first;
}
}
function tablesort_get_order_sql($header, $order) {
foreach ($header as $cell) {
if ($cell["data"] == $order) {
return $cell["field"];
}
}
}
function tablesort_get_sort($headers) {
if ($_GET['sort']) {
return ($_GET['sort'] == 'desc') ? 'asc' : 'desc';
}
// user has not specified a sort. check module for default and if none, use 'asc'
else {
foreach ($headers as $header) {
if (isset($header["sort"])) {
return $header["sort"];
}
}
}
return 'asc';
}
?>
...@@ -60,7 +60,7 @@ function comment_help($section = "admin/comment/help") { ...@@ -60,7 +60,7 @@ function comment_help($section = "admin/comment/help") {
$output .= "<p>So that users know how their votes affect the comment, these examples include the vote value as part of the label, although that is optional.</p>"; $output .= "<p>So that users know how their votes affect the comment, these examples include the vote value as part of the label, although that is optional.</p>";
$output .= "<p>Using the weight option, you can control the order in which the votes appear to users. Setting the weight heavier (positive numbers) will make the vote label appear at the bottom of the list. Lighter (a negative number) will push it to the top. To encourage positive voting, a useful order might be higher values, positive votes, at the top, with negative votes at the bottom.</p>"; $output .= "<p>Using the weight option, you can control the order in which the votes appear to users. Setting the weight heavier (positive numbers) will make the vote label appear at the bottom of the list. Lighter (a negative number) will push it to the top. To encourage positive voting, a useful order might be higher values, positive votes, at the top, with negative votes at the bottom.</p>";
$output .= "<h4>Moderators/vote values matrix</h4>"; $output .= "<h4>Moderator vote/values matrix</h4>";
$output .= strtr("<p>Next go to %comment-matrix. Enter the values for the vote labels for each permission role in the vote matrix. The values entered here will be used to create the rating for each comment.</p>", array("%comment-matrix" => l(t("comment management &raquo; comment moderation &raquo; matrix"), "admin/comment/moderation/,atrix") )); $output .= strtr("<p>Next go to %comment-matrix. Enter the values for the vote labels for each permission role in the vote matrix. The values entered here will be used to create the rating for each comment.</p>", array("%comment-matrix" => l(t("comment management &raquo; comment moderation &raquo; matrix"), "admin/comment/moderation/,atrix") ));
$output .= "<p>NOTE: Comment ratings are calculated by averaging user votes with the initial rating.</p>"; $output .= "<p>NOTE: Comment ratings are calculated by averaging user votes with the initial rating.</p>";
...@@ -814,7 +814,7 @@ function comment_link($type, $node = 0, $main = 0) { ...@@ -814,7 +814,7 @@ function comment_link($type, $node = 0, $main = 0) {
menu("admin/comment/moderation/votes", "votes", "comment_admin", comment_help("admin/comment/moderation/votes")); menu("admin/comment/moderation/votes", "votes", "comment_admin", comment_help("admin/comment/moderation/votes"));
menu("admin/comment/moderation/matrix", "matrix", "comment_admin", comment_help("admin/comment/moderation/matrix")); menu("admin/comment/moderation/matrix", "matrix", "comment_admin", comment_help("admin/comment/moderation/matrix"));
menu("admin/comment/moderation/filters", "thresholds", "comment_admin", comment_help("admin/comment/moderation/filters")); menu("admin/comment/moderation/filters", "thresholds", "comment_admin", comment_help("admin/comment/moderation/filters"));
menu("admin/comment/roles", "initial comment scores", "comment_admin", comment_help("admin/comment/roles"), 6); menu("admin/comment/moderation/roles", "initial comment scores", "comment_admin", comment_help("admin/comment/roles"), 6);
} }
} }
...@@ -948,15 +948,24 @@ function comment_save($id, $edit) { ...@@ -948,15 +948,24 @@ function comment_save($id, $edit) {
function comment_admin_overview($status = 0) { function comment_admin_overview($status = 0) {
$result = pager_query("SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = '". check_query($status). "' ORDER BY c.timestamp DESC", 50); $header = array(
array("data" => t("Subject"), "field" => "subject"),
array("data" => t("Author"), "field" => "u.name"),
array("data" => t("Status"), "field" => "status"),
array("data" => t("Time"), "field" => "timestamp", "sort" => "desc"),
array("data" => t("operations"), "colspan" => 2)
);
$sql = "SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = ". check_query($status);
$sql .= tablesort_sql($header);
$result = pager_query($sql, 50);
$header = array(t("subject"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2));
while ($comment = db_fetch_object($result)) { while ($comment = db_fetch_object($result)) {
$rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid")); $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". format_date($comment->timestamp, "small"). "</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid"));
} }
if ($pager = pager_display(NULL, 50, 0, "admin")) { if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) {
$rows[] = array(array("data" => $pager, "colspan" => 5)); $rows[] = array(array("data" => $pager, "colspan" => 6));
} }
return table($header, $rows); return table($header, $rows);
...@@ -964,7 +973,7 @@ function comment_admin_overview($status = 0) { ...@@ -964,7 +973,7 @@ function comment_admin_overview($status = 0) {
function comment_mod_matrix($edit) { function comment_mod_matrix($edit) {
$output .= "<h3>Moderators/vote values matrix</h3>"; $output .= "<h3>Moderation vote/value matrix</h3>";
if ($edit) { if ($edit) {
db_query("DELETE FROM {moderation_roles} "); db_query("DELETE FROM {moderation_roles} ");
...@@ -974,6 +983,7 @@ function comment_mod_matrix($edit) { ...@@ -974,6 +983,7 @@ function comment_mod_matrix($edit) {
} }
} }
db_query("INSERT INTO {moderation_roles} (mid, rid, value) VALUES ". implode(", ", $sql)); db_query("INSERT INTO {moderation_roles} (mid, rid, value) VALUES ". implode(", ", $sql));
$output = status("Vote values saved");
} }
$result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'"); $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'");
...@@ -1009,6 +1019,7 @@ function comment_mod_roles($edit) { ...@@ -1009,6 +1019,7 @@ function comment_mod_roles($edit) {
if ($edit) { if ($edit) {
variable_set("comment_roles", $edit); variable_set("comment_roles", $edit);
$output = status("Comment scores saved");
} }
$start_values = variable_get("comment_roles", array()); $start_values = variable_get("comment_roles", array());
...@@ -1035,15 +1046,18 @@ function comment_mod_votes($edit) { ...@@ -1035,15 +1046,18 @@ function comment_mod_votes($edit) {
if ($op == t("Save vote")) { if ($op == t("Save vote")) {
db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid); db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid);
$mid = 0; $mid = 0;
$output = status("Vote saved");
} }
else if ($op == t("Delete vote")) { else if ($op == t("Delete vote")) {
db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid);
db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid);
$mid = 0; $mid = 0;
$output = status("Vote deleted");
} }
else if ($op == t("Add new vote")) { else if ($op == t("Add new vote")) {
db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]); db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]);
$mid = 0; $mid = 0;
$output = status("Vote added");
} }
$output .= "<h3>" . t("Moderation votes overview") . "</h3>"; $output .= "<h3>" . t("Moderation votes overview") . "</h3>";
...@@ -1059,7 +1073,7 @@ function comment_mod_votes($edit) { ...@@ -1059,7 +1073,7 @@ function comment_mod_votes($edit) {
$vote = db_fetch_object(db_query("SELECT vote, weight FROM {moderation_votes} WHERE mid = %d", $mid)); $vote = db_fetch_object(db_query("SELECT vote, weight FROM {moderation_votes} WHERE mid = %d", $mid));
} }
$output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ."moderation option</h3>"; $output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ." moderation option</h3>";
$form .= form_textfield(t("Vote"), "vote", $vote->vote, 32, 64, t("The name of this vote. Example: 'off topic', 'excellent', 'sucky'.")); $form .= form_textfield(t("Vote"), "vote", $vote->vote, 32, 64, t("The name of this vote. Example: 'off topic', 'excellent', 'sucky'."));
$form .= form_textfield(t("Weight"), "weight", $vote->weight, 32, 64, t("Used to order votes in the comment control box; heavier sink.")); $form .= form_textfield(t("Weight"), "weight", $vote->weight, 32, 64, t("Used to order votes in the comment control box; heavier sink."));
if ($mid) { if ($mid) {
...@@ -1083,14 +1097,17 @@ function comment_mod_filters($edit) { ...@@ -1083,14 +1097,17 @@ function comment_mod_filters($edit) {
if ($op == t("Save threshold")) { if ($op == t("Save threshold")) {
db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid); db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid);
$fid = 0; $fid = 0;
$output = status("Saved threshold");
} }
else if ($op == t("Delete threshold")) { else if ($op == t("Delete threshold")) {
db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid); db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid);
$fid = 0; $fid = 0;
$output = status("Deleted threshold");
} }
else if ($op == t("Add new threshold")) { else if ($op == t("Add new threshold")) {
db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]); db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]);
$fid = 0; $fid = 0;
$output = status("Added threshold");
} }
$output .= "<h3>Comment threshold overview</h3>"; $output .= "<h3>Comment threshold overview</h3>";
......
...@@ -60,7 +60,7 @@ function comment_help($section = "admin/comment/help") { ...@@ -60,7 +60,7 @@ function comment_help($section = "admin/comment/help") {
$output .= "<p>So that users know how their votes affect the comment, these examples include the vote value as part of the label, although that is optional.</p>"; $output .= "<p>So that users know how their votes affect the comment, these examples include the vote value as part of the label, although that is optional.</p>";
$output .= "<p>Using the weight option, you can control the order in which the votes appear to users. Setting the weight heavier (positive numbers) will make the vote label appear at the bottom of the list. Lighter (a negative number) will push it to the top. To encourage positive voting, a useful order might be higher values, positive votes, at the top, with negative votes at the bottom.</p>"; $output .= "<p>Using the weight option, you can control the order in which the votes appear to users. Setting the weight heavier (positive numbers) will make the vote label appear at the bottom of the list. Lighter (a negative number) will push it to the top. To encourage positive voting, a useful order might be higher values, positive votes, at the top, with negative votes at the bottom.</p>";
$output .= "<h4>Moderators/vote values matrix</h4>"; $output .= "<h4>Moderator vote/values matrix</h4>";
$output .= strtr("<p>Next go to %comment-matrix. Enter the values for the vote labels for each permission role in the vote matrix. The values entered here will be used to create the rating for each comment.</p>", array("%comment-matrix" => l(t("comment management &raquo; comment moderation &raquo; matrix"), "admin/comment/moderation/,atrix") )); $output .= strtr("<p>Next go to %comment-matrix. Enter the values for the vote labels for each permission role in the vote matrix. The values entered here will be used to create the rating for each comment.</p>", array("%comment-matrix" => l(t("comment management &raquo; comment moderation &raquo; matrix"), "admin/comment/moderation/,atrix") ));
$output .= "<p>NOTE: Comment ratings are calculated by averaging user votes with the initial rating.</p>"; $output .= "<p>NOTE: Comment ratings are calculated by averaging user votes with the initial rating.</p>";
...@@ -814,7 +814,7 @@ function comment_link($type, $node = 0, $main = 0) { ...@@ -814,7 +814,7 @@ function comment_link($type, $node = 0, $main = 0) {
menu("admin/comment/moderation/votes", "votes", "comment_admin", comment_help("admin/comment/moderation/votes")); menu("admin/comment/moderation/votes", "votes", "comment_admin", comment_help("admin/comment/moderation/votes"));
menu("admin/comment/moderation/matrix", "matrix", "comment_admin", comment_help("admin/comment/moderation/matrix")); menu("admin/comment/moderation/matrix", "matrix", "comment_admin", comment_help("admin/comment/moderation/matrix"));
menu("admin/comment/moderation/filters", "thresholds", "comment_admin", comment_help("admin/comment/moderation/filters")); menu("admin/comment/moderation/filters", "thresholds", "comment_admin", comment_help("admin/comment/moderation/filters"));
menu("admin/comment/roles", "initial comment scores", "comment_admin", comment_help("admin/comment/roles"), 6); menu("admin/comment/moderation/roles", "initial comment scores", "comment_admin", comment_help("admin/comment/roles"), 6);
} }
} }
...@@ -948,15 +948,24 @@ function comment_save($id, $edit) { ...@@ -948,15 +948,24 @@ function comment_save($id, $edit) {
function comment_admin_overview($status = 0) { function comment_admin_overview($status = 0) {
$result = pager_query("SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = '". check_query($status). "' ORDER BY c.timestamp DESC", 50); $header = array(
array("data" => t("Subject"), "field" => "subject"),
array("data" => t("Author"), "field" => "u.name"),
array("data" => t("Status"), "field" => "status"),
array("data" => t("Time"), "field" => "timestamp", "sort" => "desc"),
array("data" => t("operations"), "colspan" => 2)
);
$sql = "SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = ". check_query($status);
$sql .= tablesort_sql($header);
$result = pager_query($sql, 50);
$header = array(t("subject"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2));
while ($comment = db_fetch_object($result)) { while ($comment = db_fetch_object($result)) {
$rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid")); $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". format_date($comment->timestamp, "small"). "</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid"));
} }
if ($pager = pager_display(NULL, 50, 0, "admin")) { if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) {
$rows[] = array(array("data" => $pager, "colspan" => 5)); $rows[] = array(array("data" => $pager, "colspan" => 6));
} }
return table($header, $rows); return table($header, $rows);
...@@ -964,7 +973,7 @@ function comment_admin_overview($status = 0) { ...@@ -964,7 +973,7 @@ function comment_admin_overview($status = 0) {
function comment_mod_matrix($edit) { function comment_mod_matrix($edit) {
$output .= "<h3>Moderators/vote values matrix</h3>"; $output .= "<h3>Moderation vote/value matrix</h3>";
if ($edit) { if ($edit) {
db_query("DELETE FROM {moderation_roles} "); db_query("DELETE FROM {moderation_roles} ");
...@@ -974,6 +983,7 @@ function comment_mod_matrix($edit) { ...@@ -974,6 +983,7 @@ function comment_mod_matrix($edit) {
} }
} }
db_query("INSERT INTO {moderation_roles} (mid, rid, value) VALUES ". implode(", ", $sql)); db_query("INSERT INTO {moderation_roles} (mid, rid, value) VALUES ". implode(", ", $sql));
$output = status("Vote values saved");
} }
$result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'"); $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'");
...@@ -1009,6 +1019,7 @@ function comment_mod_roles($edit) { ...@@ -1009,6 +1019,7 @@ function comment_mod_roles($edit) {
if ($edit) { if ($edit) {
variable_set("comment_roles", $edit); variable_set("comment_roles", $edit);
$output = status("Comment scores saved");
} }
$start_values = variable_get("comment_roles", array()); $start_values = variable_get("comment_roles", array());
...@@ -1035,15 +1046,18 @@ function comment_mod_votes($edit) { ...@@ -1035,15 +1046,18 @@ function comment_mod_votes($edit) {
if ($op == t("Save vote")) { if ($op == t("Save vote")) {
db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid); db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid);
$mid = 0; $mid = 0;
$output = status("Vote saved");
} }
else if ($op == t("Delete vote")) { else if ($op == t("Delete vote")) {
db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid);
db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid);
$mid = 0; $mid = 0;
$output = status("Vote deleted");
} }
else if ($op == t("Add new vote")) { else if ($op == t("Add new vote")) {
db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]); db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]);
$mid = 0; $mid = 0;
$output = status("Vote added");
} }
$output .= "<h3>" . t("Moderation votes overview") . "</h3>"; $output .= "<h3>" . t("Moderation votes overview") . "</h3>";
...@@ -1059,7 +1073,7 @@ function comment_mod_votes($edit) { ...@@ -1059,7 +1073,7 @@ function comment_mod_votes($edit) {
$vote = db_fetch_object(db_query("SELECT vote, weight FROM {moderation_votes} WHERE mid = %d", $mid)); $vote = db_fetch_object(db_query("SELECT vote, weight FROM {moderation_votes} WHERE mid = %d", $mid));
} }
$output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ."moderation option</h3>"; $output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ." moderation option</h3>";
$form .= form_textfield(t("Vote"), "vote", $vote->vote, 32, 64, t("The name of this vote. Example: 'off topic', 'excellent', 'sucky'.")); $form .= form_textfield(t("Vote"), "vote", $vote->vote, 32, 64, t("The name of this vote. Example: 'off topic', 'excellent', 'sucky'."));
$form .= form_textfield(t("Weight"), "weight", $vote->weight, 32, 64, t("Used to order votes in the comment control box; heavier sink.")); $form .= form_textfield(t("Weight"), "weight", $vote->weight, 32, 64, t("Used to order votes in the comment control box; heavier sink."));
if ($mid) { if ($mid) {
...@@ -1083,14 +1097,17 @@ function comment_mod_filters($edit) { ...@@ -1083,14 +1097,17 @@ function comment_mod_filters($edit) {
if ($op == t("Save threshold")) { if ($op == t("Save threshold")) {
db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid); db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid);
$fid = 0; $fid = 0;
$output = status("Saved threshold");
} }
else if ($op == t("Delete threshold")) { else if ($op == t("Delete threshold")) {
db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid); db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid);
$fid = 0; $fid = 0;
$output = status("Deleted threshold");
} }
else if ($op == t("Add new threshold")) { else if ($op == t("Add new threshold")) {
db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]); db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]);
$fid = 0; $fid = 0;
$output = status("Added threshold");
} }
$output .= "<h3>Comment threshold overview</h3>"; $output .= "<h3>Comment threshold overview</h3>";
......
...@@ -145,7 +145,6 @@ function forum_link($type, $node = 0, $main = 0) { ...@@ -145,7 +145,6 @@ function forum_link($type, $node = 0, $main = 0) {
function forum_view($node, $main = 0) { function forum_view($node, $main = 0) {
$term_data = array_shift(taxonomy_node_get_terms($node->nid)); $term_data = array_shift(taxonomy_node_get_terms($node->nid));
if (!$term_data) { if (!$term_data) {
// we are previewing // we are previewing
...@@ -319,15 +318,28 @@ function _forum_last_post($term) { ...@@ -319,15 +318,28 @@ function _forum_last_post($term) {
} }
function forum_get_topics($tid, $sortby, $forum_per_page) { function forum_get_topics($tid, $sortby, $forum_per_page) {
global $user; global $user, $forum_topic_list_header;
$term = taxonomy_get_term($tid); $forum_topic_list_header = array(
$voc = taxonomy_get_vocabulary($term->vid); array("data" => t("Topic"), "field" => "n.title", "colspan" => "2"),
array("data" => t("Replies"),"field" => "num_comments"),
array("data" => t("Created"), "field" => "n.created"),
array("data" => t("Last reply"), "field" => "date_sort", "sort" => "desc"),
);
$sql_sortby = _forum_get_topic_order($sortby); $sql_sortby = _forum_get_topic_order($sortby);
for ($i=0; $i < count($forum_topic_list_header); $i++) {
if ($forum_topic_list_header[$i]["field"] == $sql_sortby) {
$forum_topic_list_header[$i]["order"] = $sql_sortby;
}
}
$term = taxonomy_get_term($tid);
$voc = taxonomy_get_vocabulary($term->vid);
// show topics with the correct tid, or in the forum but with shadow = 1 // show topics with the correct tid, or in the forum but with shadow = 1
$sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid ORDER BY $sql_sortby"; $sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
$sql .= tablesort_sql($forum_topic_list_header);
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'"; $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'";
...@@ -527,42 +539,12 @@ function forum_theme_list($forums, $parents, $tid) { ...@@ -527,42 +539,12 @@ function forum_theme_list($forums, $parents, $tid) {
return table($header, $rows); return table($header, $rows);
} }
function forum_theme_topic_browser() {
global $tid, $sortby, $forum_per_page, $offset;
if (empty($sortby)) {
$sortby = variable_get("forum_order",1);
}
if (empty($forum_per_page)) {
$forum_per_page = variable_get("forum_per_page", 25);
}
$forum_per_page_options = array(10, 25, 50, 75, 100);
foreach ($forum_per_page_options as $value) {
$options .= " <option value=\"$value\"". ($forum_per_page == $value ? " selected=\"selected\"" : "") .">".t("%a topics per page", array("%a" => $value))."</option>\n";
}
$output .= "<select name=\"forum_per_page\">$options</select>\n";
$options = "";
$sortby_options = array(1 => t("Date - newest first"), 2 => t("Date - oldest first"), 3 => t("Posts - most active first"), 4=> t("Posts - least active first"));
foreach ($sortby_options as $key => $value) {
$options .= " <option value=\"$key\"". ($sortby == $key ? " selected=\"selected\"" : "") .">$value</option>\n";
}
$output .= "\n<select name=\"sortby\">$options</select>\n";
$output .= form_hidden("tid", $tid);
$output .= form_submit(t("Update settings"));
return form($output);
}
function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset) { function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset) {
global $id, $status, $user, $pager_total; global $id, $status, $user, $pager_total, $forum_topic_list_header;
if ($topics) { if ($topics) {
$header = array(array("data" => t("Topic"), "colspan" => "2"), t("Replies"), t("Created"), t("Last reply"));
foreach ($topics as $topic) { foreach ($topics as $topic) {
// folder is new if topic is new or there are new comments since last visit // folder is new if topic is new or there are new comments since last visit
if ($topic->tid != $tid) { if ($topic->tid != $tid) {
...@@ -583,10 +565,7 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset ...@@ -583,10 +565,7 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset
} }
} }
$rows[] = array(array("data" => t("%a topics, %b topics per page, page %c of %d", array("%a" => $pager_total[0], "%b" => $forum_per_page, "%c" => $offset, "%d" => ceil($pager_total[0]/$forum_per_page))), "colspan" => "5", "class" => "statistics")); if ($pager = pager_display(NULL, $forum_per_page, 0, "default", tablesort_pager())) {
$rows[] = array(array("data" => theme("forum_theme_topic_browser", $sortby, $forum_per_page, $offset), "colspan" => "5", "class" => "settings"));
if ($pager = pager_display(NULL, $forum_per_page, 0, "default")) {
$rows[] = array(array("data" => $pager, "colspan" => "5", "class" => "pager")); $rows[] = array(array("data" => $pager, "colspan" => "5", "class" => "pager"));
} }
} }
...@@ -596,7 +575,7 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset ...@@ -596,7 +575,7 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset
$output = l(t("create new forum topic"), "node/add/forum/$tid") ."<br /><br />"; $output = l(t("create new forum topic"), "node/add/forum/$tid") ."<br /><br />";
} }
$output .= table($header, $rows); $output .= table($forum_topic_list_header, $rows);
return $output; return $output;
} }
......
...@@ -145,7 +145,6 @@ function forum_link($type, $node = 0, $main = 0) { ...@@ -145,7 +145,6 @@ function forum_link($type, $node = 0, $main = 0) {
function forum_view($node, $main = 0) { function forum_view($node, $main = 0) {
$term_data = array_shift(taxonomy_node_get_terms($node->nid)); $term_data = array_shift(taxonomy_node_get_terms($node->nid));
if (!$term_data) { if (!$term_data) {
// we are previewing // we are previewing
...@@ -319,15 +318,28 @@ function _forum_last_post($term) { ...@@ -319,15 +318,28 @@ function _forum_last_post($term) {
} }
function forum_get_topics($tid, $sortby, $forum_per_page) { function forum_get_topics($tid, $sortby, $forum_per_page) {
global $user; global $user, $forum_topic_list_header;
$term = taxonomy_get_term($tid); $forum_topic_list_header = array(
$voc = taxonomy_get_vocabulary($term->vid); array("data" => t("Topic"), "field" => "n.title", "colspan" => "2"),
array("data" => t("Replies"),"field" => "num_comments"),
array("data" => t("Created"), "field" => "n.created"),
array("data" => t("Last reply"), "field" => "date_sort", "sort" => "desc"),
);
$sql_sortby = _forum_get_topic_order($sortby); $sql_sortby = _forum_get_topic_order($sortby);
for ($i=0; $i < count($forum_topic_list_header); $i++) {
if ($forum_topic_list_header[$i]["field"] == $sql_sortby) {
$forum_topic_list_header[$i]["order"] = $sql_sortby;
}
}
$term = taxonomy_get_term($tid);
$voc = taxonomy_get_vocabulary($term->vid);
// show topics with the correct tid, or in the forum but with shadow = 1 // show topics with the correct tid, or in the forum but with shadow = 1
$sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid ORDER BY $sql_sortby"; $sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
$sql .= tablesort_sql($forum_topic_list_header);
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'"; $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'";
...@@ -527,42 +539,12 @@ function forum_theme_list($forums, $parents, $tid) { ...@@ -527,42 +539,12 @@ function forum_theme_list($forums, $parents, $tid) {
return table($header, $rows); return table($header