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)
------------------------
- added support for configurable URLs.
- added support for sortable table columns.
- database backend:
* added support for database table prefxing.
- 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") {
$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 .= "<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 .= "<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) {
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/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) {
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)) {
$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")) {
$rows[] = array(array("data" => $pager, "colspan" => 5));
if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) {
$rows[] = array(array("data" => $pager, "colspan" => 6));
}
return table($header, $rows);
......@@ -964,7 +973,7 @@ function comment_admin_overview($status = 0) {
function comment_mod_matrix($edit) {
$output .= "<h3>Moderators/vote values matrix</h3>";
$output .= "<h3>Moderation vote/value matrix</h3>";
if ($edit) {
db_query("DELETE FROM {moderation_roles} ");
......@@ -974,6 +983,7 @@ function comment_mod_matrix($edit) {
}
}
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%'");
......@@ -1009,6 +1019,7 @@ function comment_mod_roles($edit) {
if ($edit) {
variable_set("comment_roles", $edit);
$output = status("Comment scores saved");
}
$start_values = variable_get("comment_roles", array());
......@@ -1035,15 +1046,18 @@ function comment_mod_votes($edit) {
if ($op == t("Save vote")) {
db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid);
$mid = 0;
$output = status("Vote saved");
}
else if ($op == t("Delete vote")) {
db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid);
db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid);
$mid = 0;
$output = status("Vote deleted");
}
else if ($op == t("Add new vote")) {
db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]);
$mid = 0;
$output = status("Vote added");
}
$output .= "<h3>" . t("Moderation votes overview") . "</h3>";
......@@ -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));
}
$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("Weight"), "weight", $vote->weight, 32, 64, t("Used to order votes in the comment control box; heavier sink."));
if ($mid) {
......@@ -1083,14 +1097,17 @@ function comment_mod_filters($edit) {
if ($op == t("Save threshold")) {
db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid);
$fid = 0;
$output = status("Saved threshold");
}
else if ($op == t("Delete threshold")) {
db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid);
$fid = 0;
$output = status("Deleted threshold");
}
else if ($op == t("Add new threshold")) {
db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]);
$fid = 0;
$output = status("Added threshold");
}
$output .= "<h3>Comment threshold overview</h3>";
......
......@@ -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>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 .= "<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) {
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/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) {
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)) {
$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")) {
$rows[] = array(array("data" => $pager, "colspan" => 5));
if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) {
$rows[] = array(array("data" => $pager, "colspan" => 6));
}
return table($header, $rows);
......@@ -964,7 +973,7 @@ function comment_admin_overview($status = 0) {
function comment_mod_matrix($edit) {
$output .= "<h3>Moderators/vote values matrix</h3>";
$output .= "<h3>Moderation vote/value matrix</h3>";
if ($edit) {
db_query("DELETE FROM {moderation_roles} ");
......@@ -974,6 +983,7 @@ function comment_mod_matrix($edit) {
}
}
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%'");
......@@ -1009,6 +1019,7 @@ function comment_mod_roles($edit) {
if ($edit) {
variable_set("comment_roles", $edit);
$output = status("Comment scores saved");
}
$start_values = variable_get("comment_roles", array());
......@@ -1035,15 +1046,18 @@ function comment_mod_votes($edit) {
if ($op == t("Save vote")) {
db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid);
$mid = 0;
$output = status("Vote saved");
}
else if ($op == t("Delete vote")) {
db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid);
db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid);
$mid = 0;
$output = status("Vote deleted");
}
else if ($op == t("Add new vote")) {
db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]);
$mid = 0;
$output = status("Vote added");
}
$output .= "<h3>" . t("Moderation votes overview") . "</h3>";
......@@ -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));
}
$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("Weight"), "weight", $vote->weight, 32, 64, t("Used to order votes in the comment control box; heavier sink."));
if ($mid) {
......@@ -1083,14 +1097,17 @@ function comment_mod_filters($edit) {
if ($op == t("Save threshold")) {
db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid);
$fid = 0;
$output = status("Saved threshold");
}
else if ($op == t("Delete threshold")) {
db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid);
$fid = 0;
$output = status("Deleted threshold");
}
else if ($op == t("Add new threshold")) {
db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]);
$fid = 0;
$output = status("Added threshold");
}
$output .= "<h3>Comment threshold overview</h3>";
......
......@@ -145,7 +145,6 @@ function forum_link($type, $node = 0, $main = 0) {
function forum_view($node, $main = 0) {
$term_data = array_shift(taxonomy_node_get_terms($node->nid));
if (!$term_data) {
// we are previewing
......@@ -319,15 +318,28 @@ function _forum_last_post($term) {
}
function forum_get_topics($tid, $sortby, $forum_per_page) {
global $user;
global $user, $forum_topic_list_header;
$term = taxonomy_get_term($tid);
$voc = taxonomy_get_vocabulary($term->vid);
$forum_topic_list_header = array(
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);
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
$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'";
......@@ -527,42 +539,12 @@ function forum_theme_list($forums, $parents, $tid) {
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) {
global $id, $status, $user, $pager_total;
global $id, $status, $user, $pager_total, $forum_topic_list_header;
if ($topics) {
$header = array(array("data" => t("Topic"), "colspan" => "2"), t("Replies"), t("Created"), t("Last reply"));
foreach ($topics as $topic) {
// folder is new if topic is new or there are new comments since last visit
if ($topic->tid != $tid) {
......@@ -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"));
$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")) {
if ($pager = pager_display(NULL, $forum_per_page, 0, "default", tablesort_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
$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;
}
......
......@@ -145,7 +145,6 @@ function forum_link($type, $node = 0, $main = 0) {
function forum_view($node, $main = 0) {
$term_data = array_shift(taxonomy_node_get_terms($node->nid));
if (!$term_data) {
// we are previewing
......@@ -319,15 +318,28 @@ function _forum_last_post($term) {
}
function forum_get_topics($tid, $sortby, $forum_per_page) {
global $user;
global $user, $forum_topic_list_header;
$term = taxonomy_get_term($tid);
$voc = taxonomy_get_vocabulary($term->vid);
$forum_topic_list_header = array(
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);
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
$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'";
......@@ -527,42 +539,12 @@ function forum_theme_list($forums, $parents, $tid) {
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) {
global $id, $status, $user, $pager_total;
global $id, $status, $user, $pager_total, $forum_topic_list_header;
if ($topics) {
$header = array(array("data" => t("Topic"), "colspan" => "2"), t("Replies"), t("Created"), t("Last reply"));
foreach ($topics as $topic) {
// folder is new if topic is new or there are new comments since last visit
if ($topic->tid != $tid) {
......@@ -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"));
$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")) {
if ($pager = pager_display(NULL, $forum_per_page, 0, "default", tablesort_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
$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;
}
......
......@@ -241,6 +241,8 @@ function node_load($conditions, $revision = -1) {
** Unserialize the revisions field:
*/
print "wa: $node->title";
if ($node->revisions) {
$node->revisions = unserialize($node->revisions);
}
......@@ -676,7 +678,7 @@ function node_admin_nodes() {
*/
$result = pager_query("SELECT n.*, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid ". $filters[$filter][1], 50);
$header = array(NULL, t("title"), t("type"), t("author"), t("status"), t("operations"));
$header = array(t("title"), t("type"), t("author"), t("status"), array ("data" => t("operations"), "colspan" => 2));
while ($node = db_fetch_object($result)) {
$rows[] = array(l($node->title, node_url($node)) ." ". (node_is_new($node->nid, $node->changed) ? theme_mark() : ""), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid"));
......
......@@ -241,6 +241,8 @@ function node_load($conditions, $revision = -1) {
** Unserialize the revisions field:
*/
print "wa: $node->title";
if ($node->revisions) {
$node->revisions = unserialize($node->revisions);
}
......@@ -676,7 +678,7 @@ function node_admin_nodes() {
*/
$result = pager_query("SELECT n.*, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid ". $filters[$filter][1], 50);
$header = array(NULL, t("title"), t("type"), t("author"), t("status"), t("operations"));
$header = array(t("title"), t("type"), t("author"), t("status"), array ("data" => t("operations"), "colspan" => 2));
while ($node = db_fetch_object($result)) {
$rows[] = array(l($node->title, node_url($node)) ." ". (node_is_new($node->nid, $node->changed) ? theme_mark() : ""), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid"));
......
......@@ -34,7 +34,7 @@ function statistics_init() {
}
}
// Footer hook, runs at the end of every page request
// Exit hook, runs at the end of every page request
function statistics_exit() {
global $user;
......@@ -113,23 +113,22 @@ function statistics_link($type, $node = 0, $main = 0) {
if ($type == "admin" && (user_access("administer statistics module") || (user_access("administer statistics")))) {
$help["statistics"] = t("This page gives you an at-a-glance look at your top nodes. It is useful for understanding what content on your site is the most popular.");
$help["referrers"] = t("This page shows you site-wide referrer statistics. You can see 'all referrers', 'external referrers' or 'internal referrers'. Defaults to 'external'. Referrers are web sites, both your site, and other peoples, that point to your web site.");
$help["referrers"] = t("This page shows you site-wide referrer statistics. You can see 'all referrers', 'external referrers' or 'internal referrers'. Referrers are web sites, both your site, and other peoples, that point to your web site.");
$help["referrers-internal"] = t("This page shows you only 'internal referrers'. Links pointing to your web site, from within your web site.");
$help["referrers-external"] = t("This page shows you only 'external referrers'. Links pointing to your web site from outside your web site.");
$help["access"] = t("This pages shows you who is accessing your web site. You can see the hostnames, referrers. In particular, it is easy to inspect a user's navigation history/trail by clicking the username.");
$help["access"] = t("This pages shows you who is accessing your web site. You can see the hostnames, referrers. In particular, it is easy to inspect a user's navigation history/trail by clicking on <i>track user</i>.");
$help["top nodes page"] = t("The statistics module creates a user page that can display summaries of the day's top viewed nodes, the all time top nodes and the last nodes viewed. Each of these summaries can be enabled or disabled individually, and the number of nodes displayed for each can be configured with a drop down menu.");
$help["top nodes block"] = t("The statistics module exports a block that can display the top viewed nodes of the day, the all time top viewed nodes and the last nodes viewed. Each of these links can be enabled or disabled individually, and the number of nodes displayed for each can be configured with a drop down menu. If you disable all sections of this block, it will not appear.");
$help["who is online block"] = t("The statistics module exports a block that can display how many user's and guests are currently online. You can configure the name of the block, the name of a sub-block for displaying names of user's currently online, how recently a user must have been active to be considered online, the maximum characters to display from a user's name and the maximum number of user names to display.");
menu("admin/statistics", "site statistics", "statistics_admin", $help["statistics"], 6);
menu("admin/statistics/statistics", "most popular posts", "statistics_admin", $help["statistics"]);
menu("admin/statistics/referrers", "referrer log", "statistics_admin", $help["referrers"]);
menu("admin/statistics/referrers/internal", "internal referrers only", "statistics_admin", $help["referrers-internal"]);
menu("admin/statistics/referrers/external", "external referrers only", "statistics_admin", $help["referrers-external"]);
menu("admin/statistics/log", "access log", "statistics_admin", $help["access"]);
menu("admin/statistics/log/node", "track node", "statistics_admin", $help["access"], 0, 1);
menu("admin/statistics/log/user", "track user", "statistics_admin", $help["access"], 0, 1);
menu("admin/statistics/log/host", "track host", "statistics_admin", $help["access"], 0, 1);
menu("admin/statistics/log/node", "track node", "statistics_admin", $help["access"], 0, 1); //hidden
menu("admin/statistics/log/user", "track user", "statistics_admin", $help["access"], 0, 1); //hidden
menu("admin/statistics/log/host", "track host", "statistics_admin", $help["access"], 0, 1); //hidden
menu("admin/statistics/top nodes page", "configure 'top nodes' page", "statistics_admin", $help["top nodes page"], 5);
menu("admin/statistics/help", "help", "statistics_help", NULL, 9);
......@@ -204,9 +203,9 @@ function statistics_admin() {
/* non-configuration admin pages */
switch ($op) {
case "statistics":
return statistics_admin_displaycounts();
return statistics_admin_topnodes();
case "referrers":
return statistics_recent_refer() . statistics_top_refer();
return statistics_top_refer();
case "log":
return statistics_admin_displaylog();
}
......@@ -252,22 +251,32 @@ function statistics_admin() {
"statistics_userpage_last_cnt" => variable_get("statistics_userpage_last_cnt", 0)
));
default:
return statistics_admin_displaycounts();
return statistics_admin_topnodes();
}
}
}
}
/* Displays the various admin tables */
function statistics_admin_count_table($dbfield, $dbrows) {