diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 9e1bdcf6e4c..08042698d51 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -4,19 +4,19 @@ $FORUM_DEFAULT_DISPLAY_MODE = 3; -$FORUM_LAYOUT_MODES = array ( "1" => "Display replies flat, with oldest first", - "-1" => "Display replies flat, wth newest first", - "2" => "Display replies in threaded form", - "3" => "Display replies in nested form"); +$FORUM_LAYOUT_MODES = array ( "1" => get_string("modeflatoldestfirst", "forum"), + "-1" => get_string("modeflatnewestfirst", "forum"), + "2" => get_string("modethreaded", "forum"), + "3" => get_string("modenested", "forum") ); // These are course content forums that can be added to the course manually -$FORUM_TYPES = array ("general" => "General forum", - "eachuser" => "Each person posts one discussion", - "single" => "A single simple discussion"); +$FORUM_TYPES = array ("general" => get_string("generalforum", "forum"), + "eachuser" => get_string("eachuserforum", "forum"), + "single" => get_string("singleforum", "forum") ); -$FORUM_POST_RATINGS = array ("3" => "Shows a more connected approach", - "2" => "Shows a more separate approach", - "1" => "I can't decide between these two"); +$FORUM_POST_RATINGS = array ("3" => get_string("postrating3", "forum"), + "2" => get_string("postrating2", "forum"), + "1" => get_string("postrating1", "forum") ); $FORUM_LONG_POST = 600; @@ -28,29 +28,30 @@ function forum_get_course_forum($courseid, $type) { // How to set up special 1-per-course forums if ($forum = get_record_sql("SELECT * from forum WHERE course = '$courseid' AND type = '$type'")) { return $forum; + } else { // Doesn't exist, so create one now. $forum->course = $courseid; $forum->type = "$type"; switch ($forum->type) { case "news": - $forum->name = "News"; - $forum->intro= "General news about this course"; - $forum->open = 0; + $forum->name = get_string("namenews", "forum"); + $forum->intro = get_string("intronews", "forum"); + $forum->open = 0; $forum->assessed = 0; $forum->forcesubscribe = 1; break; case "social": - $forum->name = "Social"; - $forum->intro= "A forum for general socialising. Talk about anything you like!"; - $forum->open = 1; + $forum->name = get_string("namesocial", "forum"); + $forum->intro = get_string("introsocial", "forum"); + $forum->open = 1; $forum->assessed = 0; $forum->forcesubscribe = 0; break; case "teacher": - $forum->name = "Teacher Forum"; - $forum->intro= "For teacher-only notes and discussion"; - $forum->open = 0; + $forum->name = get_string("nameteacher", "forum"); + $forum->intro = get_string("introteacher", "forum"); + $forum->open = 0; $forum->assessed = 0; $forum->forcesubscribe = 0; break; @@ -95,8 +96,10 @@ function forum_make_mail_post(&$post, $user, $touser, $course, } $output .= "
";
$output .= "$post->subject
";
- $output .= "by wwwroot/user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname";
- $output .= " on ".userdate($post->created, "", $touser->timezone);
+ $output .= "";
+ $by->name = "wwwroot/user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname";
+ $by->date = userdate($post->created, "", $touser->timezone);
+ $output .= get_string("bynameondate", "forum", $by);
$output .= "
";
echo "$post->subject
";
- echo "by wwwroot/user/view.php?id=$post->userid&course=$courseid\">$post->firstname $post->lastname";
- echo " on ".userdate($post->created);
+ 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 "
No posts
"; + echo "".get_string("noposts", "forum")."
"; } } @@ -523,8 +506,6 @@ function forum_cron () { global $CFG; - echo "Processing posts...\n"; - $cutofftime = time() - $CFG->maxeditingtime; if ($posts = get_records_sql("SELECT p.*, d.course FROM forum_posts p, forum_discussions d @@ -534,18 +515,14 @@ function forum_cron () { foreach ($posts as $post) { - echo "Processing post $post->id\n"; + print_string("processingpost", "forum", $post->id); + echo " ... "; if (! $userfrom = get_record("user", "id", "$post->user")) { echo "Could not find user $post->user\n"; continue; } - if (! $course = get_record("course", "id", "$post->course")) { - echo "Could not find course $post->course\n"; - continue; - } - if (! $discussion = get_record("forum_discussions", "id", "$post->discussion")) { echo "Could not find discussion $post->discussion\n"; continue; @@ -556,44 +533,67 @@ function forum_cron () { continue; } + if (! $course = get_record("course", "id", "$forum->course")) { + echo "Could not find course $forum->course\n"; + continue; + } - if ($users = get_records_sql("SELECT u.* FROM user u, forum_subscriptions s - WHERE s.user = u.id AND s.forum = '$discussion->forum'")) { + if ($users = get_course_users($course->id)) { + $strforums = get_string("forums", "forum"); + $mailcount=0; foreach ($users as $userto) { - $postsubject = "$course->shortname: $post->subject"; - $posttext = "$course->shortname -> Forums -> $forum->name -> $discussion->name\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= "$post->subject\n"; - $posttext .= "by $userfrom->firstname $userfrom->lastname, on ".userdate($post->created, "", $userto->timezone)."\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= strip_tags($post->message); - $posttext .= "\n\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= "This is a copy of a message posted on the $course->shortname website.\n"; - $posttext .= "To add your reply via the website, click on this link:\n"; - $posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id"; + $by->name = "$userfrom->firstname $userfrom->lastname"; + $by->date = userdate($post->created, "", $userto->timezone); + $strbynameondate = get_string("bynameondate", "forum", $by); - if ($userto->mailformat == 1) { // HTML - $posthtml = "". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/forum/index.php?id=$course->id\">Forums ->". - "wwwroot/mod/forum/view.php?f=$forum->id\">$forum->name ->". - "wwwroot/mod/forum/discuss.php?d=$discussion->id\">$discussion->name
"; - $posthtml .= forum_make_mail_post($post, $userfrom, $userto, $course, false, true, false, false); - } else { - $posthtml = ""; - } - - if (! email_to_user($userto, $userfrom, $postsubject, $posttext, $posthtml)) { - echo "Error: mod/forum/cron.php: Could not send out mail for id $post->id to user $userto->id ($userto->email)\n"; + if (forum_is_subscribed($userto->id, $forum->id)) { + $postsubject = "$course->shortname: $post->subject"; + $posttext = "$course->shortname -> $strforums -> $forum->name"; + if ($discussion->name == $forum->name) { + $posttext .= "\n"; + } else { + $posttext .= " -> $discussion->name\n"; + } + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= "$post->subject\n"; + $posttext .= $strbynameondate."\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= strip_tags($post->message); + $posttext .= "\n\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= get_string("postmailinfo", "forum", $course->shortname)."\n"; + $posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id"; + + if ($userto->mailformat == 1) { // HTML + $posthtml = "". + "wwwroot/course/view.php?id=$course->id\">$course->shortname -> ". + "wwwroot/mod/forum/index.php?id=$course->id\">$strforums -> ". + "wwwroot/mod/forum/view.php?f=$forum->id\">$forum->name"; + if ($discussion->name == $forum->name) { + $posthtml .= "
"; + } else { + $posthtml .= " -> wwwroot/mod/forum/discuss.php?d=$discussion->id\">$discussion->name"; + } + $posthtml .= forum_make_mail_post($post, $userfrom, $userto, $course, false, true, false, false); + } else { + $posthtml = ""; + } + + if (! email_to_user($userto, $userfrom, $postsubject, $posttext, $posthtml)) { + echo "Error: mod/forum/cron.php: Could not send out mail for id $post->id to user $userto->id ($userto->email)\n"; + } else { + $mailcount++; + } } } + echo "mailed to $mailcount users ..."; } if (! set_field("forum_posts", "mailed", "1", "id", "$post->id")) { echo "Could not update the mailed field for id $post->id\n"; } + echo "\n"; } } @@ -694,12 +694,13 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $f if (forum_user_can_post_discussion($forum)) { echo ""; - echo "wwwroot/mod/forum/post.php?forum=$forum->id\">Add a new discussion topic..."; + echo "wwwroot/mod/forum/post.php?forum=$forum->id\">"; + echo get_string("addanewdiscussion", "forum")."..."; echo "
\n"; } if (! $discussions = forum_get_discussions($forum->id, $forum_sort) ) { - echo "There are no discussion topics yet in this forum.
"; + echo "(".get_string("nodiscussions", "forum").")
"; } else { @@ -711,7 +712,8 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $f $discussioncount++; if ($forum_numdiscussions && ($discussioncount > $forum_numdiscussions)) { - echo "wwwroot/mod/forum/view.php?f=$forum->id\">Older discussions ...
"; + echo "wwwroot/mod/forum/view.php?f=$forum->id\">"; + echo get_string("olderdiscussions", "forum")." ...
"; break; } if ($replies[$discussion->discussion]) { @@ -724,7 +726,8 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $f case "minimal": echo "".userdate($discussion->modified, "%e %b, %H:%M")." - $discussion->firstname";
echo "
$discussion->subject ";
- echo "wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">more...";
+ echo "wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">";
+ echo get_string("more", "forum")."...";
echo "