From ffe116409077dd0c534ad5f11d1326b90d47f5cb Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 2 Aug 2002 17:34:26 +0000 Subject: [PATCH] SOme major bugfixes to forum_cron() and lots of translating --- mod/forum/lib.php | 253 +++++++++++++++++++++++----------------------- 1 file changed, 128 insertions(+), 125 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 9e1bdcf6e4c5c..08042698d5143 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 .= "

"; $output .= "body\" WIDTH=10>"; $output .= " "; @@ -108,14 +111,14 @@ function forum_make_mail_post(&$post, $user, $touser, $course, $age = time() - $post->created; if ($ownpost) { - $output .= "wwwroot/mod/forum/post.php?delete=$post->id\">Delete"; + $output .= "wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum").""; if ($reply) { - $output .= "| wwwroot/mod/forum/post.php?reply=$post->id\">Reply"; + $output .= "| wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum").""; } $output .= "  "; } else { if ($reply) { - $output .= "wwwroot/mod/forum/post.php?reply=$post->id\">Reply  "; + $output .= "wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."  "; } } @@ -123,11 +126,11 @@ function forum_make_mail_post(&$post, $user, $touser, $course, if ($link) { if ($post->replies == 1) { - $replystring = "reply"; + $replystring = get_string("repliesone", "forum", $post->replies); } else { - $replystring = "replies"; + $replystring = get_string("repliesmany", "forum", $post->replies); } - $output .= "wwwroot/mod/forum/discuss.php?d=$post->discussion\">Discuss this topic ($post->replies $replystring so far)  "; + $output .= "wwwroot/mod/forum/discuss.php?d=$post->discussion\">".get_string("discussthistopic", "forum")." ($replystring)  "; } $output .= "

"; if ($footer) { @@ -162,8 +165,10 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link } echo "

"; 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 "

"; echo "body\" WIDTH=10>"; echo " "; @@ -174,7 +179,8 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link echo text_to_html(forum_shorten_post($post->message)); $numwords = count_words($post->message); echo "wwwroot/mod/forum/discuss.php?d=$post->discussion\">"; - echo "Read the rest of this topic ($numwords words)..."; + echo get_string("readtherest", "forum"); + echo " (".get_string("numwords", "forum", $numwords).")..."; } else { // Print whole message echo text_to_html($post->message); @@ -185,16 +191,16 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link $age = time() - $post->created; if ($ownpost) { if ($age < $CFG->maxeditingtime) { - echo "wwwroot/mod/forum/post.php?edit=$post->id\">Edit | "; + echo "wwwroot/mod/forum/post.php?edit=$post->id\">".get_string("edit", "forum")." | "; } - echo "wwwroot/mod/forum/post.php?delete=$post->id\">Delete"; + echo "wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum").""; if ($reply) { - echo "| wwwroot/mod/forum/post.php?reply=$post->id\">Reply"; + echo "| wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum").""; } echo "  "; } else { if ($reply) { - echo "wwwroot/mod/forum/post.php?reply=$post->id\">Reply  "; + echo "wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."  "; } } @@ -210,11 +216,11 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link if ($link) { if ($post->replies == 1) { - $replystring = "reply"; + $replystring = get_string("repliesone", "forum", $post->replies); } else { - $replystring = "replies"; + $replystring = get_string("repliesmany", "forum", $post->replies); } - echo "wwwroot/mod/forum/discuss.php?d=$post->discussion\">Discuss this topic ($post->replies $replystring so far)  "; + echo "wwwroot/mod/forum/discuss.php?d=$post->discussion\">".get_string("discussthistopic", "forum")." ($replystring)  "; } echo "

"; if ($footer) { @@ -229,12 +235,12 @@ function forum_shorten_post($message) { global $FORUM_LONG_POST; if (strlen($message) > $FORUM_LONG_POST) { - // Look for the first return between 50 and $FORUM_LONG_POST - $shortmessage = substr($message, 50, $FORUM_LONG_POST); + // Look for the first return between 100 and $FORUM_LONG_POST + $shortmessage = substr($message, 100, $FORUM_LONG_POST); if ($pos = strpos($shortmessage, "\n")) { - return substr($message, 0, 50 + $pos). " ..."; + return substr($message, 0, 100 + $pos); } else { - return substr($message, 0, $FORUM_LONG_POST). "..."; + return substr($message, 0, $FORUM_LONG_POST)."..."; } } else { return $message; @@ -243,27 +249,17 @@ function forum_shorten_post($message) { function forum_print_ratings($post) { - - global $CFG, $PHPSESSID; - - $notsatisfactory = 0; - $satisfactory = 0; - $outstanding = 0; if ($ratings = get_records_sql("SELECT * from forum_ratings WHERE post='$post'")) { + $sumrating[1] = 0; + $sumrating[2] = 0; + $sumrating[3] = 0; foreach ($ratings as $rating) { - switch ($rating->rating) { - case 1: $notsatisfactory++; break; - case 2: $satisfactory++; break; - case 3: $outstanding++; break; - } + $sumrating[$rating->rating]++; } - $summary = "$outstanding/$satisfactory/$notsatisfactory"; + $summary = $sumrating[1]."s/".$sumrating[2]."/".$sumrating[3]."c"; - echo "Ratings: "; + echo get_string("ratings", "forum").": "; link_to_popup_window ("/mod/forum/report.php?id=$post", "ratings", $summary, 400, 550); - - } else { - echo ""; } } @@ -271,17 +267,14 @@ function forum_print_rating($post, $user) { global $FORUM_POST_RATINGS; if ($rs = get_record_sql("SELECT rating from forum_ratings WHERE user='$user' AND post='$post'")) { - echo "You rated this: "; if ($FORUM_POST_RATINGS[$rs->rating]) { + echo "".get_string("youratedthis", "forum").": "; echo $FORUM_POST_RATINGS[$rs->rating]; - } else { - echo "Error"; + echo ""; + return; } - echo ""; - - } else { - choose_from_menu($FORUM_POST_RATINGS, $post, "", "Rate..."); } + choose_from_menu($FORUM_POST_RATINGS, $post, "", get_string("rate", "forum")."..."); } function forum_print_mode_form($discussion, $mode) { @@ -347,23 +340,17 @@ function forum_get_post_full($postid) { function forum_add_new_post($post) { - $timenow = time(); - $post->created = $timenow; - $post->modified = $timenow; + $post->created = $post->modified = time(); $post->mailed = "0"; return insert_record("forum_posts", $post); } function forum_update_post($post) { - global $db; - $timenow = time(); + $post->modified = time(); - $rs = $db->Execute("UPDATE forum_posts - SET message='$post->message', subject='$post->subject', modified='$timenow' - WHERE id = '$post->id'"); - return $rs; + return update_record("forum_posts", $post); } function forum_add_discussion($discussion) { @@ -448,7 +435,7 @@ function forum_print_user_discussions($courseid, $userid) { if ($discussions) { $user = get_record("user", "id", $userid); echo "
"; - print_heading("Discussions started by $user->firstname $user->lastname"); + print_heading( get_string("discussionsstartedby", "forum", "$user->firstname $user->lastname") ); $replies = forum_count_discussion_replies(); foreach ($discussions as $discussion) { if (($discussion->forumtype == "teacher") and !isteacher($courseid)) { @@ -459,7 +446,8 @@ function forum_print_user_discussions($courseid, $userid) { } else { $discussion->replies = 0; } - $discussion->subject .= " (in wwwroot/mod/forum/view.php?f=$discussion->forumid\">$discussion->forumname)"; + $inforum = get_string("inforum", "forum", "wwwroot/mod/forum/view.php?f=$discussion->forumid\">$discussion->forumname"); + $discussion->subject .= " ($inforum)"; $ownpost = ($discussion->userid == $USER->id); forum_print_post($discussion, $course->id, $ownpost, $reply=0, $link=1, $assessed=false); echo "
\n"; @@ -468,21 +456,15 @@ function forum_print_user_discussions($courseid, $userid) { } -function forum_user_summary($course, $user, $mod, $forum) { - global $CFG; -} - - function forum_user_outline($course, $user, $mod, $forum) { - global $CFG; if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture FROM forum f, forum_discussions d, forum_posts p, user u WHERE f.id = '$forum->id' AND d.forum = f.id AND p.discussion = d.id AND p.user = '$user->id' AND p.user = u.id ORDER BY p.modified ASC")) { - $result->info = count($posts)." posts"; + $result->info = get_string("numposts", "forum", count($posts)); $lastpost = array_pop($posts); $result->time = $lastpost->modified; @@ -503,16 +485,17 @@ function forum_user_complete($course, $user, $mod, $forum) { foreach ($posts as $post) { if ($post->parent) { - $footer = "wwwroot/mod/forum/discuss.php?d=$post->discussion&parent=$post->parent\">Parent of this post"; + $footer = "wwwroot/mod/forum/discuss.php?d=$post->discussion&parent=$post->parent\">". + get_string("parentofthispost", "forum").""; } else { $footer = ""; } - pirint_post($post, $course->id, $ownpost=false, $reply=false, $link=false, $rate=false, $footer); + print_post($post, $course->id, $ownpost=false, $reply=false, $link=false, $rate=false, $footer); } } else { - 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"; - - 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"; + $by->name = "$userfrom->firstname $userfrom->lastname"; + $by->date = userdate($post->created, "", $userto->timezone); + $strbynameondate = get_string("bynameondate", "forum", $by); + + 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 "

\n"; break; default: