From 5c40037c8e2649201880cf9265c322075d18303b Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 15 Aug 2003 15:17:23 +0000 Subject: 1) Bugfix: changed INNER JOIN to LEFT JOIN to make forum topics with no comments show on the topic overview page. 2) Beautified the forum module views; rewritten to use the table() rendering functions, X HTML-ified the emitted code, added additional CSS tags, and removed hard-coded markup. This improves themeabality; it should be able to mimic the view and color scheme of, say, http://www.phpbb.com/. 3) Reorganized forms and links (interactive elements) to improve usability. Also ensured that the link names and page titles match. 4) Temporary removed container functionality: this simplified the work and eliminated some usability issues. --- modules/forum.module | 184 +++++++++++++++++++++++++++------------------------ 1 file changed, 96 insertions(+), 88 deletions(-) (limited to 'modules/forum.module') diff --git a/modules/forum.module b/modules/forum.module index 212256331..3b855574b 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -41,8 +41,6 @@ function forum_settings() { if ($voc) { $output .= form_textarea(t("Explanation or submission guidelines"), "forum_help", variable_get("forum_help", ""), 70, 5, t("This text will be displayed at the top of the forum submission form. Useful for helping or instructing your users.")); $output .= form_select(t("Forum vocabulary"), "forum_nav_vocabulary", variable_get("forum_nav_vocabulary", ""), $vocs, t("The taxonomy vocabulary that will be used as the navigation tree.")); - $output .= _taxonomy_term_select(t("Containers"), "forum_containers", variable_get("forum_containers", array()), variable_get("forum_nav_vocabulary", ""), t("You can choose forums which will not have topics, but will be just containers for other forums."), 1, t("")); - $output .= form_textfield(t("Topic icons path"), "forum_topic_icon_path", variable_get("forum_topic_icon_path", ""), 30, 255, t("The path to the topic icons. Leave blank to disable icons.")); $output .= form_textfield(t("Folder icons path"), "forum_folder_icon_path", variable_get("forum_folder_icon_path", ""), 30, 255,t( "The path to the default, hot, new, hot & new, and closed folder icons. Leave blank to disable icons.")); $number = array(5 => 5, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30, 35 => 35, 40 => 40, 50 => 50, 60 => 60, 80 => 80, 100 => 100, 10000=>10000); @@ -107,7 +105,7 @@ function forum_link($type, $node = 0, $main = 0) { $links = array(); if ($type == "page" && user_access("access content")) { - $links[] = l(t("forum"), "forum"); + $links[] = l(t("forums"), "forum"); } if (!$main && $type == "node" && $node->type == "forum") { @@ -157,7 +155,7 @@ function forum_view($node, $main = 0) { $voc = taxonomy_get_vocabulary($term_data->vid); if (!$main) { - $node->title = _forum_get_icon($node) ." ". l($voc->name, "forum") ." : ". l($term_data->name, "forum/$term_data->tid") ." / $node->title"; + $node->title = l($voc->name, "forum") ." » ". l($term_data->name, "forum/$term_data->tid") ." » $node->title"; } $node->teaser = check_output($node->teaser); @@ -193,7 +191,7 @@ function forum_form(&$node, &$help, &$error) { // outputs the compose guidelines $help = variable_get("forum_help", ""); - $output .= _taxonomy_term_select(t("Forum"), "tid", $tid, variable_get("forum_nav_vocabulary", ""), "", 0, "", variable_get("forum_containers", array())); + $output .= _taxonomy_term_select(t("Forum"), "tid", $tid, variable_get("forum_nav_vocabulary", ""), "", 0, ""); if ($node->nid) { // if editing, give option to leave shadows @@ -280,7 +278,7 @@ function _forum_last_reply($nid) { function _forum_format($topic) { if ($topic) { - return "". t("%date
by %author", array("%date" => format_date($topic->timestamp, "small"), "%author" => format_name($topic))) ."
"; + return t("%date
by %author", array("%date" => format_date($topic->timestamp, "small"), "%author" => format_name($topic))); } else { return message_na(); @@ -301,14 +299,9 @@ function forum_get_forums($tid = 0) { $_forums = taxonomy_get_tree(variable_get("forum_nav_vocabulary", ""), $tid); $n = 0; foreach ($_forums as $forum) { - if (in_array($forum->tid, variable_get("forum_containers", array()))) { - $forum->container = 1; - } - else { - $forum->num_topics = _forum_num_topics($forum->tid); - $forum->num_posts = _forum_num_replies($forum->tid) + $forum->num_topics; - $forum->last_post = _forum_last_post($forum->tid); - } + $forum->num_topics = _forum_num_topics($forum->tid); + $forum->num_posts = _forum_num_replies($forum->tid) + $forum->num_topics; + $forum->last_post = _forum_last_post($forum->tid); $forums[$forum->tid] = $forum; $n++; } @@ -381,7 +374,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) { $sql_sortby = _forum_get_topic_order($sortby); // 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, f.icon, 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 INNER 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, f.icon 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, f.icon, 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, f.icon ORDER BY $sql_sortby"; $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'"; @@ -472,11 +465,8 @@ function forum_page() { $offset = ($from / $forum_per_page) + 1; $forums = forum_get_forums($tid); - $parents = forum_get_parents($tid); - if ($tid && !in_array($tid, variable_get("forum_containers", array()))) { - $topics = forum_get_topics($tid, $sortby, $forum_per_page); - } + $topics = forum_get_topics($tid, $sortby, $forum_per_page); theme("forum_theme_display", $forums, $topics, $parents, $tid, $sortby, $forum_per_page, $offset); } @@ -500,70 +490,90 @@ function forum_page() { function forum_theme_display($forums, $topics, $parents, $tid, $sortby, $forum_per_page, $offset) { // forum list, topics list, topic browser and "add new topic" link + theme("header"); - $output .= theme("forum_theme_list", $forums, $parents, $tid); - if ($tid && !in_array($tid, variable_get("forum_containers", array()))) { - $output .= theme("forum_theme_topic_list", $tid, $topics, $sortby, $forum_per_page, $offset); - } + /* + ** Breadcrumb navigation: + */ - theme("header"); - theme("box", t("Discussion forum"), $output); - if ($tid && !in_array($tid, variable_get("forum_containers", array()))) { - theme("box", t("Control panel"), theme("forum_theme_topic_browser", $sortby, $forum_per_page, $offset)); + if ($tid) { + $trail[] = l(t("Forums"), "forum"); + } + else { + $trail[] = t("Forums"); } - theme("footer"); -} -function forum_theme_list($forums, $parents, $tid) { - global $user; if ($parents) { - foreach($parents as $p) { + $parents = array_reverse($parents); + foreach ($parents as $p) { if ($tid != $p->tid) { - $t[] = l($p->name, "forum/$p->tid"); + $trail[] = l($p->name, "forum/$p->tid"); } else { - $t[] = $p->name; + $trail[] = $p->name; } } } - $t[] = l(t("Discussion forum"), "forum"); - $output .= "\n"; - $output .= " "; + $output = "
"; + $output .= theme("forum_theme_list", $forums, $parents, $tid); + + if ($tid) { + $output .= theme("forum_theme_topic_list", $tid, $topics, $sortby, $forum_per_page, $offset); + } + + $output .= "
"; + + theme("box", implode($trail, " » "), $output); + theme("footer"); +} + +function forum_theme_list($forums, $parents, $tid) { + global $user; + if ($forums) { - $output .= ""; + $header = array(array("data" => t("Forum"), "colspan" => "2"), t("Topics"), t("Posts"), t("Last post")); foreach ($forums as $forum) { - if ($forum->container) { - $output .= " "; + if ($user->uid) { + $new_topics = $forum->num_topics - $forum->old_topics; } - else { - if ($user->uid) $new_topics = $forum->num_topics - $forum->old_topics; - $icon = _forum_get_folder_icon($new_topics); - $output .= " "; - $output .= ""; - $output .= ""; + if ($new_topics) { + $links[] = l(t("the first new topic"), "forum/$forum->tid/new"); } + + $description = "
depth * 30) ."px;\">\n"; + $description .= "
". l($forum->name, "forum/$forum->tid") ."
\n"; + + if ($forum->description) { + $description .= "
$forum->description
\n"; + } + if ($links) { + $description .= "
". t("Jump to: %links", array("%links" => implode(", ", $links))) .".
\n"; + } + $description .="
\n"; + + //if ($icon = _forum_get_folder_icon($new_topics)) { + $rows[] = array( + array("data" => $icon, "class" => "icon"), + array("data" => $description, "class" => "description"), + array("data" => $forum->num_topics . ($new_topics ? "
(".t("%a new", array("%a" => $new_topics)).")" : ""), "class" => "topics"), + array("data" => $forum->num_posts, "class" => "posts"), + array("data" => _forum_format($forum->last_post), "class" => "last-post") + ); + } } - $output .= "
".implode(" : ", array_reverse($t)) ."". t("topics") ."". t("posts") ."". t("last post") ."
". l($forum->name, "forum/$forum->tid") ."
". ($forum->description ? check_output($forum->description) : "") ."
 $icon
depth * 20) ."px;\"> ". l($forum->name, "forum/$forum->tid") ."
". check_output($forum->description); - - $links = array(); - if ($forum->last_post) { - $links[] = l(t("the most recent topic"), "node/view/". $forum->last_post->nid); - } - if ($new_topics) { - $links[] = l(t("the first new topic"), "forum/$forum->tid/new"); - } - if ($links) { - $output .= "
". t("Jump to: %links", array("%links" => implode(", ", $links))); - } + $links = array(); + + if ($forum->last_post) { + $links[] = l(t("the most recent topic"), "node/view/". $forum->last_post->nid); + } - $output .= "
".$forum->num_topics.($new_topics ? "
(".t("%a new", array("%a" => $new_topics)).")" : "")."
".$forum->num_posts.""._forum_format($forum->last_post)."
\n"; - return $output; + return table($header, $rows); } function forum_theme_topic_browser() { @@ -592,52 +602,53 @@ function forum_theme_topic_browser() { $output .= "\n\n"; $output .= form_hidden("tid", $tid); $output .= form_submit(t("Update settings")); - return form(form_item(t("Topic viewing options"), $output, t("Select your preferred way to display the topics and click 'Update settings'."))); + return form($output); } function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset) { global $id, $status, $user, $pager_total; if ($topics) { - $output .= "\n"; - $output .= " "; + + $header = array(array("data" => t("Topic"), "colspan" => "3"), t("Replies"), t("Posted"), t("Last post")); foreach ($topics as $topic) { // folder is new if topic is new or there are new comments since last visit if ($topic->tid != $tid) { - $output .= " - - - - - - "; + $rows[] = array( + array("data" => _forum_get_folder_icon($topic->new, $topic->num_comments, $topic->comment_mode), "class" => "icon"), + array("data" =>_forum_get_icon($topic), "class" => "icon"), + array("data" => $topic->title, "class" => "title"), + array("data" => l(t("This topic has been moved"), "forum/$topic->tid"), "colspan" => 3) + ); } else { - $output .= " - - - - - - - - "; + $rows[] = array( + array("data" => _forum_get_folder_icon($topic->new, $topic->num_comments, $topic->comment_mode), "class" => "icon"), + array("data" => _forum_get_icon($topic), "class" => "icon"), + array("data" => l($topic->title, "node/view/$topic->nid"), "class" => "topic"), + array("data" => $topic->num_comments . ($topic->new_replies ? "
(".t("%a new", array("%a" => $topic->new_replies)).")" : ""), "class" => "replies"), + array("data" => _forum_format($topic), "class" => "posted"), + array("data" => _forum_format($topic->last_reply), "class" => "last-post") + ); } } - $output .= "
  ". t("topic") ."". t("replies") ."". t("posted") ."". t("last reply") ."
"._forum_get_folder_icon($topic->new, $topic->num_comments, $topic->comment_mode).""._forum_get_icon($topic)."$topic->title". l(t("This topic has been moved"), "forum/$topic->tid")."
"._forum_get_folder_icon($topic->new, $topic->num_comments, $topic->comment_mode).""._forum_get_icon($topic)."". l($topic->title, "node/view/$topic->nid") ."".$topic->num_comments.($topic->new_replies ? " (".t("%a new", array("%a" => $topic->new_replies)).")" : "").""._forum_format($topic).""._forum_format($topic->last_reply)."
\n"; - } - $output .= "
"; + $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" => "6", "class" => "statistics")); + $rows[] = array(array("data" => theme("forum_theme_topic_browser", $sortby, $forum_per_page, $offset), "colspan" => "6", "class" => "settings")); - $output .= "
" .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))) ."
"; + if ($pager = pager_display(NULL, $forum_per_page, 0, "default")) { + $rows[] = array(array("data" => $pager, "colspan" => "6", "class" => "pager")); + } + } - $output .= (($pager = pager_display(NULL, $forum_per_page, 0, "default")) ? "$pager" : ""); if (user_access("create forum topics")) { - $output .= "
". l(t("create new forum topic"), "node/add/forum/$tid") ."
"; + $output = l(t("create new forum topic"), "node/add/forum/$tid") ."

"; } + $output .= table($header, $rows); + return $output; } @@ -716,9 +727,6 @@ function forum_help($section = "admin/forum/help") { $output .= "

Creating a forum

"; $output .= strtr("

The forum module uses taxonomy to organize itself. To create a forum you first have to create a %taxonomy. When doing this, choose a sensible name for it (such as \"fora\") and make sure under \"Types\" that \"forum\" is selected. Once you have done this, %taxo-terms to it. Each term will become a forum. If you fill in the description field, users will be given additonal information about the forum on the main forum page. For example: \"troubleshooting\" - \"Please ask your questions here.\"

", array("%taxonomy" => l(t("taxonomy vocabulary"), "admin/taxonomy/add/vocabulary"), "%taxo-terms" => l(t("add some terms"), "admin/taxonomy" ) )); $output .= strtr("

When you are happy with your vocabulary, go to ". l("site configuration » modules » forum","admin/system/modules/forum") ." and set Forum vocabulary to the one you have just created. There will now be fora active on the site. For users to access them they must have the \"access content\" %permission and to create a topic they must have the \"create forum topics\" %permission. These permissions can be set in the %permission pages.

", array("%forums" => l(t("site configutation » modules » forum"), "admin/system/modules/forum"), "%permission" => l(t("permission"), "admin/user/permission") )); - $output .= "

Containers

If you designate a forum as a container, users will not be able to post to it. The forum will be visible on the forum listing page, so it acts as a section delimiter if you will. This is useful if you have a lots of forums which are nested. For example,

"; - $output .= "

Marketing
-- Market research
-- Brand management

Sales
-- Closing the deal
-- Avoiding ear and throat pain

"; - $output .= "

If you don't want people posting into the Marketing or Sales folders, you designate them as Containers.

"; $output .= "

Icons

"; $output .= strtr("

To disable icons, set the icon path as blank in %forums-icon.

",array("%forums-icon" => l(t("site configuration » modules » forums"), "admin/system/module/forum") )); $output .= "

All files in the icon directory are assumed to be images. You may use images of whatever size you wish, but it is customary to use 15x15 or 16x16.

"; -- cgit v1.2.3