diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 39ed7ba019a..af7edf25853 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -22,6 +22,7 @@ $FORUM_SHORT_POST = 300; // Less than this is "short" $FORUM_LONG_POST = 600; // More than this is "long" +$FORUM_MANY_DISCUSSIONS = 10; /// FUNCTIONS /////////////////////////////////////////////////////////// @@ -237,6 +238,56 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link echo "\n\n\n"; } + +function forum_print_post_header(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $rate=false, $footer="") { + global $THEME, $USER, $CFG, $FORUM_LONG_POST; + + if ($post->parent) { + echo "
"; + echo ""; + } else { + echo "
\n
"; + echo ""; + } + + echo ""; + + if ($post->parent) { + echo ""; + + if ($post->parent) { + echo "
body\" WIDTH=35 VALIGN=TOP>"; + print_user_picture($post->userid, $courseid, $post->picture); + echo "cellheading\">"; + } else { + echo "cellheading2\">"; + } + echo "

"; + echo "$post->subject
"; + echo ""; + $by->name = "wwwroot/user/view.php?id=$post->userid&course=$courseid\">$post->firstname $post->lastname"; + $by->date = userdate($post->created); + print_string("bynameondate", "forum", $by); + echo "

cellheading\">"; + } else { + echo "cellheading2\">"; + } + echo "

"; + + if ($link) { + if ($post->replies == 1) { + $replystring = get_string("repliesone", "forum", $post->replies); + } else { + $replystring = get_string("repliesmany", "forum", $post->replies); + } + echo "wwwroot/mod/forum/discuss.php?d=$post->discussion\">".get_string("discussthistopic", "forum")." ($replystring)  "; + } + echo "

"; + echo "
"; + echo "
\n\n"; +} + + function forum_shorten_post($message) { global $FORUM_LONG_POST, $FORUM_SHORT_POST; @@ -837,7 +888,7 @@ function forum_get_discussions($forum="0", $forum_sort="DESC", $user=0) { function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $forum_style="plain", $forum_sort="DESC") { - global $CFG, $USER; + global $CFG, $USER, $FORUM_MANY_DISCUSSIONS; if ($forum_id) { if (! $forum = get_record("forum", "id", $forum_id)) { @@ -869,40 +920,47 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $f if (! $discussions = forum_get_discussions($forum->id, $forum_sort) ) { echo "

(".get_string("nodiscussions", "forum").")

"; + return; - } else { + } + + if ((!$forum_numdiscussions) && ($forum_style == "plain") && (count($discussions) > $FORUM_MANY_DISCUSSIONS) ) { + $forum_style = "header"; // Abbreviate display if it's going to be long. + } - $replies = forum_count_discussion_replies($forum->id); + $replies = forum_count_discussion_replies($forum->id); - $discussioncount = 0; + $discussioncount = 0; - foreach ($discussions as $discussion) { - $discussioncount++; + foreach ($discussions as $discussion) { + $discussioncount++; - if ($forum_numdiscussions && ($discussioncount > $forum_numdiscussions)) { - echo "

wwwroot/mod/forum/view.php?f=$forum->id\">"; - echo get_string("olderdiscussions", "forum")." ...

"; - break; - } - if ($replies[$discussion->discussion]) { - $discussion->replies = $replies[$discussion->discussion]->replies; - } else { - $discussion->replies = 0; - } - $ownpost = ($discussion->userid == $USER->id); - switch ($forum_style) { - case "minimal": - echo "

".userdate($discussion->modified, "%e %b, %H:%M")." - $discussion->firstname"; - echo "
$discussion->subject "; - echo "wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">"; - echo get_string("more", "forum")."..."; - echo "

\n"; - break; - default: - forum_print_post($discussion, $forum->course, $ownpost, $reply=0, $link=1, $assessed=false); - echo "
\n"; - break; - } + if ($forum_numdiscussions && ($discussioncount > $forum_numdiscussions)) { + echo "

wwwroot/mod/forum/view.php?f=$forum->id\">"; + echo get_string("olderdiscussions", "forum")." ...

"; + break; + } + if ($replies[$discussion->discussion]) { + $discussion->replies = $replies[$discussion->discussion]->replies; + } else { + $discussion->replies = 0; + } + $ownpost = ($discussion->userid == $USER->id); + switch ($forum_style) { + case "minimal": + echo "

".userdate($discussion->modified, "%e %b, %H:%M")." - $discussion->firstname"; + echo "
$discussion->subject "; + echo "wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">"; + echo get_string("more", "forum")."..."; + echo "

\n"; + break; + case "header": + forum_print_post_header($discussion, $forum->course, $ownpost, $reply=0, $link=1, $assessed=false); + break; + default: + forum_print_post($discussion, $forum->course, $ownpost, $reply=0, $link=1, $assessed=false); + echo "
\n"; + break; } } }