Commit 8a2d5bed authored by Dries's avatar Dries

- Rewrote handling of forum icons and added default icons made by Steven
  Wittens.

- Renamed some column titles in the forum module as per Moshe's suggestion.

- Introduced a 'more-link' class to position the 'more' links.  Removed
  hard-coded markup from the modules.

- Fixed bug in import module: the theme functions called a non-existing
  function.
parent db8c3edc
......@@ -127,7 +127,7 @@ th {
font-size: 0.9em;
margin: 0.5em;
}
#forum td.posts, #forum td.topics, #forum td.last-post, #forum td.posted, #forum td.replies, #forum td.statistics, #forum td.settings, #forum td.pager {
#forum td.created, #forum td.posts, #forum td.topics, #forum td.last-reply, #forum td.replies, #forum td.statistics, #forum td.settings, #forum td.pager {
text-align: center;
white-space: nowrap;
}
......@@ -197,6 +197,9 @@ th {
margin: 0 auto;
display: table;
}
.more-link {
text-align: right;
}
.node-form .form-text {
display: block;
width: 95%;
......
......@@ -108,7 +108,7 @@ function import_update() {
}
}
function import_format_item($item, $feed = 0) {
function import_theme_format_item($item, $feed = 0) {
global $user;
if ($user->uid && module_exist("blog") && user_access("maintain personal blog")) {
......@@ -132,7 +132,7 @@ function import_bundle_block($attributes) {
$items = array();
while ($item = db_fetch_object($result)) {
$items[] = theme("import_theme_format_item",$item);
$items[] = theme("import_theme_format_item", $item);
}
$output = "<div class=\"import-block\"><div class=\"bundle\">";
......@@ -177,13 +177,13 @@ function import_block($op, $delta) {
case "feed":
$feed = db_fetch_object(db_query("SELECT * FROM {feed} WHERE fid = %d", $id));
$block["subject"] = $feed->title;
$block["content"] .= import_feed_block($feed) ."<div style=\"text-align: right;\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
$block["content"] .= import_feed_block($feed) ."<div class=\"more-link\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
break;
case "bundle":
$bundle = db_fetch_object(db_query("SELECT * FROM {bundle} WHERE bid = %d", $id));
$block["subject"] = $bundle->title;
$block["content"] .= import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
$block["content"] .= import_bundle_block($bundle->attributes) ."<div class=\"more-link\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
break;
}
......@@ -198,9 +198,7 @@ function import_get_bundles($attributes = 0) {
$result = db_query("SELECT * FROM {bundle} ORDER BY title");
while ($bundle = db_fetch_object($result)) {
$block["bundle:$bundle->bid"]["subject"] = $bundle->title;
$block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">".
l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news.")))
."</div>";
$block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div class=\"more-link\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
$block["bundle:$bundle->bid"]["info"] = "$bundle->title bundle";
}
......@@ -214,9 +212,7 @@ function import_get_feeds($attributes = 0) {
$result = db_query("SELECT * FROM {feed} ORDER BY fid");
while ($feed = db_fetch_object($result)) {
$block["feed:$feed->fid"]["subject"] = $feed->title;
$block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div style=\"text-align: right;\">".
l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news.")))
."</div>";
$block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div class=\"more-link\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
$block["feed:$feed->fid"]["info"] = "$feed->title feed";
}
......
......@@ -108,7 +108,7 @@ function import_update() {
}
}
function import_format_item($item, $feed = 0) {
function import_theme_format_item($item, $feed = 0) {
global $user;
if ($user->uid && module_exist("blog") && user_access("maintain personal blog")) {
......@@ -132,7 +132,7 @@ function import_bundle_block($attributes) {
$items = array();
while ($item = db_fetch_object($result)) {
$items[] = theme("import_theme_format_item",$item);
$items[] = theme("import_theme_format_item", $item);
}
$output = "<div class=\"import-block\"><div class=\"bundle\">";
......@@ -177,13 +177,13 @@ function import_block($op, $delta) {
case "feed":
$feed = db_fetch_object(db_query("SELECT * FROM {feed} WHERE fid = %d", $id));
$block["subject"] = $feed->title;
$block["content"] .= import_feed_block($feed) ."<div style=\"text-align: right;\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
$block["content"] .= import_feed_block($feed) ."<div class=\"more-link\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
break;
case "bundle":
$bundle = db_fetch_object(db_query("SELECT * FROM {bundle} WHERE bid = %d", $id));
$block["subject"] = $bundle->title;
$block["content"] .= import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
$block["content"] .= import_bundle_block($bundle->attributes) ."<div class=\"more-link\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
break;
}
......@@ -198,9 +198,7 @@ function import_get_bundles($attributes = 0) {
$result = db_query("SELECT * FROM {bundle} ORDER BY title");
while ($bundle = db_fetch_object($result)) {
$block["bundle:$bundle->bid"]["subject"] = $bundle->title;
$block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">".
l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news.")))
."</div>";
$block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div class=\"more-link\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
$block["bundle:$bundle->bid"]["info"] = "$bundle->title bundle";
}
......@@ -214,9 +212,7 @@ function import_get_feeds($attributes = 0) {
$result = db_query("SELECT * FROM {feed} ORDER BY fid");
while ($feed = db_fetch_object($result)) {
$block["feed:$feed->fid"]["subject"] = $feed->title;
$block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div style=\"text-align: right;\">".
l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news.")))
."</div>";
$block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div class=\"more-link\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
$block["feed:$feed->fid"]["info"] = "$feed->title feed";
}
......
......@@ -266,7 +266,7 @@ function blog_block($op = "list", $delta = 0) {
else {
if (user_access("access content")) {
$block["content"] = node_title_list(db_query_range("SELECT n.title, n.nid FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 10));
$block["content"] .= "<div align=\"right\" id=\"blog_more\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["content"] .= "<div class=\"more-link\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["subject"] = t("Blogs");
}
return $block;
......
......@@ -266,7 +266,7 @@ function blog_block($op = "list", $delta = 0) {
else {
if (user_access("access content")) {
$block["content"] = node_title_list(db_query_range("SELECT n.title, n.nid FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 10));
$block["content"] .= "<div align=\"right\" id=\"blog_more\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["content"] .= "<div class=\"more-link\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["subject"] = t("Blogs");
}
return $block;
......
......@@ -212,7 +212,7 @@ function cloud_block($op = "list", $delta = 0) {
}
else {
$block["subject"] = t("Site cloud");
$block["content"] = cloud_list(20) ."<div style=\"text-align: right;\">". l(t("more"), "cloud", array("title" => t("Monitor other sites in the cloud."))) ."</div>";
$block["content"] = cloud_list(20) ."<div class=\"more-link\">". l(t("more"), "cloud", array("title" => t("Monitor other sites in the cloud."))) ."</div>";
return $block;
}
}
......
......@@ -41,8 +41,7 @@ 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 .= 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 <b>default</b>, <b>hot</b>, <b>new</b>, <b>hot & new</b>, and <b>closed</b> folder icons. Leave blank to disable icons."));
$output .= form_textfield(t("Forum icon path"), "forum_icon_path", variable_get("forum_icon_path", ""), 30, 255, t("The path to the forum icons. Leave blank to disable icons. Don't add a trailing slash. Default icons are available in the 'misc' directory."));
$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);
$output .= form_select(t("Hot topic threshold"), "forum_hot_topic", variable_get("forum_hot_topic", 15), $number, t("The number of posts a topic must have to be considered <b>hot</b>."));
$number = array(10 => 10, 25 => 25, 50 => 50, 75 => 75, 100 => 100);
......@@ -88,7 +87,7 @@ function forum_block($op = "list", $delta = 0) {
$content .= node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' ORDER BY n.nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:"));
if ($content) {
$content .= "<div id=\"forum_more\" style=\"text-align: right;\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>";
$content .= "<div class=\"more-link\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>";
}
$blocks["subject"] = t("Forum topics");
......@@ -198,63 +197,17 @@ function forum_form(&$node, &$help, &$error) {
$output .= form_checkbox(t("Leave shadow copy"), "shadow", 1, $node->shadow, t("If you move this topic, you can leave a link in the old forum to the new forum."));
}
if ($icon_path = variable_get("forum_topic_icon_path", "")) {
if ($node->icon) {
// we are editing post
if ($dir = @opendir($icon_path)) {
$icon_num = 0;
while($icon = readdir($dir)) {
if ($icon == '.' || $icon == '..') {continue;}
if ($node->icon == $icon) {$checked = "checked";} else {$checked = "";}
$radio .= "<input type=\"radio\" name=\"edit[icon_num]\" value=\"$icon_num\" $checked /><img src=\"$icon_path$icon\" alt=\"\" title=\"\" /> \n";
$icon_num++;
}
closedir($dir);
}
}
else {
if ($dir = @opendir($icon_path)) {
$icon_num = 0;
while($icon = readdir($dir)) {
if ($icon == '.' || $icon == '..') {continue;}
if ($node->icon_num == $icon_num) {$checked = "checked";} else {$checked = "";}
$radio .= "<input type=\"radio\" name=\"edit[icon_num]\" value=\"$icon_num\" $checked /><img src=\"$icon_path$icon\" alt=\"\" title=\"\" /> \n";
$icon_num++;
}
closedir($dir);
}
}
$output .= form_item(t("Topic icon"), $radio);
}
$output .= form_textarea(t("Body"), "body", $node->body, 60, 10);
return $output;
}
function forum_insert($node) {
$node->icon = _forum_decode_icon($node);
db_query("INSERT INTO {forum} (nid, icon, shadow, tid) VALUES (%d, '%s', %d, %d)", $node->nid, $node->icon, $node->shadow, $node->tid[0]);
db_query("INSERT INTO {forum} (nid, shadow, tid) VALUES (%d, %d, %d)", $node->nid, $node->shadow, $node->tid[0]);
}
function forum_update($node) {
$node->icon = _forum_decode_icon($node);
db_query("UPDATE {forum} SET icon = '%s', shadow = %d, tid = %d WHERE nid = %d", $node->icon, $node->shadow, $node->tid[0], $node->nid);
}
function _forum_decode_icon($node) {
// to prevent malicious users
if ($icon_path = variable_get("forum_topic_icon_path", "")) {
if ($dir = @opendir($icon_path)) {
$icon_num = 0;
while($icon = readdir($dir)) {
if ($icon == '.' || $icon == '..') {continue;}
if ($icon_num == $node->icon_num) {$myicon = $icon;}
$icon_num++;
}
closedir($dir);
}
}
return $myicon;
db_query("UPDATE {forum} SET shadow = %d, tid = %d WHERE nid = %d", $node->shadow, $node->tid[0], $node->nid);
}
function forum_delete(&$node) {
......@@ -374,7 +327,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 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 = "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_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'";
......@@ -533,7 +486,7 @@ function forum_theme_list($forums, $parents, $tid) {
if ($forums) {
$header = array(array("data" => t("Forum"), "colspan" => "2"), t("Topics"), t("Posts"), t("Last post"));
$header = array(t("Forum"), t("Topics"), t("Posts"), t("Last post"));
foreach ($forums as $forum) {
if ($user->uid) {
......@@ -561,13 +514,11 @@ function forum_theme_list($forums, $parents, $tid) {
}
$description .="</div>\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 ? "<br />(".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")
array("data" => _forum_format($forum->last_post), "class" => "last-reply")
);
}
......@@ -610,35 +561,33 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset
if ($topics) {
$header = array(array("data" => t("Topic"), "colspan" => "3"), t("Replies"), t("Posted"), t("Last post"));
$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) {
$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" => _forum_icon($topic->new, $topic->num_comments, $topic->comment_mode), "class" => "icon"),
array("data" => $topic->title, "class" => "title"),
array("data" => l(t("This topic has been moved"), "forum/$topic->tid"), "colspan" => 3)
array("data" => l(t("This topic has been moved"), "forum/$topic->tid"), "colspan" => "3")
);
}
else {
$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" => _forum_icon($topic->new, $topic->num_comments, $topic->comment_mode), "class" => "icon"),
array("data" => l($topic->title, "node/view/$topic->nid"), "class" => "topic"),
array("data" => $topic->num_comments . ($topic->new_replies ? "<br />(".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")
array("data" => _forum_format($topic), "class" => "created"),
array("data" => _forum_format($topic->last_reply), "class" => "last-reply")
);
}
}
$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"));
$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")) {
$rows[] = array(array("data" => $pager, "colspan" => "6", "class" => "pager"));
$rows[] = array(array("data" => $pager, "colspan" => "5", "class" => "pager"));
}
}
......@@ -647,29 +596,17 @@ 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($header, $rows);
return $output;
}
function _forum_icon($new_posts, $num_posts = 0, $comment_mode = 0) {
function _forum_get_icon($node) {
if (variable_get("forum_topic_icon_path", "") && $node->icon) {
return "<img src=\"". variable_get("forum_topic_icon_path", "") ."$node->icon\" />";
}
else {
return "&nbsp;";
}
}
function _forum_get_folder_icon($new_posts, $num_posts = 0, $comment_mode = 0) {
// "folder" icon because it's generally rendered as a folder
$base_path = variable_get("forum_folder_icon_path", "");
$base_path = variable_get("forum_icon_path", "");
if ($base_path) {
if ($num_posts > variable_get("forum_hot_topic", 15)) {
$icon = $new_posts ? "hot_new" : "hot";
$icon = $new_posts ? "hot-new" : "hot";
}
else {
$icon = $new_posts ? "new" : "default";
......@@ -680,7 +617,7 @@ function _forum_get_folder_icon($new_posts, $num_posts = 0, $comment_mode = 0) {
}
// default
$file = $base_path."/".$icon.".gif";
$file = $base_path."/forum-$icon.gif";
return "<img src=\"$file\" alt=\"\" title=\"\" />";
}
......@@ -728,8 +665,8 @@ function forum_help($section = "admin/forum/help") {
$output .= strtr("<p>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.\"</p>", array("%taxonomy" => l(t("taxonomy vocabulary"), "admin/taxonomy/add/vocabulary"), "%taxo-terms" => l(t("add some terms"), "admin/taxonomy" ) ));
$output .= strtr("<p>When you are happy with your vocabulary, go to ". l("site configuration &raquo; modules &raquo; forum","admin/system/modules/forum") ." and set <b>Forum vocabulary</b> 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.</p>", array("%forums" => l(t("site configutation &raquo; modules &raquo; forum"), "admin/system/modules/forum"), "%permission" => l(t("permission"), "admin/user/permission") ));
$output .= "<h4>Icons</h4>";
$output .= strtr("<p>To disable icons, set the icon path as blank in %forums-icon.</p>",array("%forums-icon" => l(t("site configuration &raquo; modules &raquo; forums"), "admin/system/module/forum") ));
$output .= "<p>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.</p>";
$output .= strtr("<p>To disable icons, set the icon path as blank in %forums-icon.</p>", array("%forums-icon" => l(t("site configuration &raquo; modules &raquo; forums"), "admin/system/module/forum") ));
$output .= "<p>All files in the icon directory are assumed to be images. You may use images of whatever size you wish, but it is recommended to use 15x15 or 16x16.</p>";
break;
case 'admin/system/modules':
$output = "Enable threaded discussions about general topics.";
......
......@@ -41,8 +41,7 @@ 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 .= 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 <b>default</b>, <b>hot</b>, <b>new</b>, <b>hot & new</b>, and <b>closed</b> folder icons. Leave blank to disable icons."));
$output .= form_textfield(t("Forum icon path"), "forum_icon_path", variable_get("forum_icon_path", ""), 30, 255, t("The path to the forum icons. Leave blank to disable icons. Don't add a trailing slash. Default icons are available in the 'misc' directory."));
$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);
$output .= form_select(t("Hot topic threshold"), "forum_hot_topic", variable_get("forum_hot_topic", 15), $number, t("The number of posts a topic must have to be considered <b>hot</b>."));
$number = array(10 => 10, 25 => 25, 50 => 50, 75 => 75, 100 => 100);
......@@ -88,7 +87,7 @@ function forum_block($op = "list", $delta = 0) {
$content .= node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' ORDER BY n.nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:"));
if ($content) {
$content .= "<div id=\"forum_more\" style=\"text-align: right;\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>";
$content .= "<div class=\"more-link\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>";
}
$blocks["subject"] = t("Forum topics");
......@@ -198,63 +197,17 @@ function forum_form(&$node, &$help, &$error) {
$output .= form_checkbox(t("Leave shadow copy"), "shadow", 1, $node->shadow, t("If you move this topic, you can leave a link in the old forum to the new forum."));
}
if ($icon_path = variable_get("forum_topic_icon_path", "")) {
if ($node->icon) {
// we are editing post
if ($dir = @opendir($icon_path)) {
$icon_num = 0;
while($icon = readdir($dir)) {
if ($icon == '.' || $icon == '..') {continue;}
if ($node->icon == $icon) {$checked = "checked";} else {$checked = "";}
$radio .= "<input type=\"radio\" name=\"edit[icon_num]\" value=\"$icon_num\" $checked /><img src=\"$icon_path$icon\" alt=\"\" title=\"\" /> \n";
$icon_num++;
}
closedir($dir);
}
}
else {
if ($dir = @opendir($icon_path)) {
$icon_num = 0;
while($icon = readdir($dir)) {
if ($icon == '.' || $icon == '..') {continue;}
if ($node->icon_num == $icon_num) {$checked = "checked";} else {$checked = "";}
$radio .= "<input type=\"radio\" name=\"edit[icon_num]\" value=\"$icon_num\" $checked /><img src=\"$icon_path$icon\" alt=\"\" title=\"\" /> \n";
$icon_num++;
}
closedir($dir);
}
}
$output .= form_item(t("Topic icon"), $radio);
}
$output .= form_textarea(t("Body"), "body", $node->body, 60, 10);
return $output;
}
function forum_insert($node) {
$node->icon = _forum_decode_icon($node);
db_query("INSERT INTO {forum} (nid, icon, shadow, tid) VALUES (%d, '%s', %d, %d)", $node->nid, $node->icon, $node->shadow, $node->tid[0]);
db_query("INSERT INTO {forum} (nid, shadow, tid) VALUES (%d, %d, %d)", $node->nid, $node->shadow, $node->tid[0]);
}
function forum_update($node) {
$node->icon = _forum_decode_icon($node);
db_query("UPDATE {forum} SET icon = '%s', shadow = %d, tid = %d WHERE nid = %d", $node->icon, $node->shadow, $node->tid[0], $node->nid);
}
function _forum_decode_icon($node) {
// to prevent malicious users
if ($icon_path = variable_get("forum_topic_icon_path", "")) {
if ($dir = @opendir($icon_path)) {
$icon_num = 0;
while($icon = readdir($dir)) {
if ($icon == '.' || $icon == '..') {continue;}
if ($icon_num == $node->icon_num) {$myicon = $icon;}
$icon_num++;
}
closedir($dir);
}
}
return $myicon;
db_query("UPDATE {forum} SET shadow = %d, tid = %d WHERE nid = %d", $node->shadow, $node->tid[0], $node->nid);
}
function forum_delete(&$node) {
......@@ -374,7 +327,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 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 = "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_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'";
......@@ -533,7 +486,7 @@ function forum_theme_list($forums, $parents, $tid) {
if ($forums) {
$header = array(array("data" => t("Forum"), "colspan" => "2"), t("Topics"), t("Posts"), t("Last post"));
$header = array(t("Forum"), t("Topics"), t("Posts"), t("Last post"));
foreach ($forums as $forum) {
if ($user->uid) {
......@@ -561,13 +514,11 @@ function forum_theme_list($forums, $parents, $tid) {
}
$description .="</div>\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 ? "<br />(".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")
array("data" => _forum_format($forum->last_post), "class" => "last-reply")
);
}
......@@ -610,35 +561,33 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset
if ($topics) {
$header = array(array("data" => t("Topic"), "colspan" => "3"), t("Replies"), t("Posted"), t("Last post"));
$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) {
$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" => _forum_icon($topic->new, $topic->num_comments, $topic->comment_mode), "class" => "icon"),
array("data" => $topic->title, "class" => "title"),
array("data" => l(t("This topic has been moved"), "forum/$topic->tid"), "colspan" => 3)
array("data" => l(t("This topic has been moved"), "forum/$topic->tid"), "colspan" => "3")
);
}
else {
$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" => _forum_icon($topic->new, $topic->num_comments, $topic->comment_mode), "class" => "icon"),
array("data" => l($topic->title, "node/view/$topic->nid"), "class" => "topic"),
array("data" => $topic->num_comments . ($topic->new_replies ? "<br />(".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")
array("data" => _forum_format($topic), "class" => "created"),
array("data" => _forum_format($topic->last_reply), "class" => "last-reply")
);
}
}
$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"));
$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")) {
$rows[] = array(array("data" => $pager, "colspan" => "6", "class" => "pager"));
$rows[] = array(array("data" => $pager, "colspan" => "5", "class" => "pager"));
}
}
......@@ -647,29 +596,17 @@ 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($header, $rows);
return $output;
}
function _forum_icon($new_posts, $num_posts = 0, $comment_mode = 0) {
function _forum_get_icon($node) {
if (variable_get("forum_topic_icon_path", "") && $node->icon) {
return "<img src=\"". variable_get("forum_topic_icon_path", "") ."$node->icon\" />";
}
else {
return "&nbsp;";
}
}
function _forum_get_folder_icon($new_posts, $num_posts = 0, $comment_mode = 0) {
// "folder" icon because it's generally rendered as a folder
$base_path = variable_get("forum_folder_icon_path", "");