From 1306c5ea1c163123d1e0f063934d89d5e2be9471 Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 16 Mar 2007 21:00:06 +0000 Subject: [PATCH] MDL-8932 fix static cache in userdate() + wrong en.UTF-8 locale ; merged with other fixes from MOODLE_18_STABLE --- lang/en_utf8/langconfig.php | 2 +- lang/en_utf8/moodle.php | 2 +- lib/moodlelib.php | 20 +++-------- mod/forum/lib.php | 70 +++++++++++++++++++++++-------------- 4 files changed, 50 insertions(+), 44 deletions(-) diff --git a/lang/en_utf8/langconfig.php b/lang/en_utf8/langconfig.php index c1a307817f..a096cbddd0 100644 --- a/lang/en_utf8/langconfig.php +++ b/lang/en_utf8/langconfig.php @@ -5,7 +5,7 @@ $string['alphabet'] = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z'; $string['backupnameformat'] = '%%Y%%m%%d-%%H%%M'; $string['firstdayofweek'] = '0'; -$string['locale'] = 'en.UTF-8'; +$string['locale'] = 'en_AU.UTF-8'; $string['localewin'] = 'English_Australia.1252'; $string['localewincharset'] = ''; $string['oldcharset'] = 'ISO-8859-1'; diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 2d0b354b92..c26b52b7fb 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -786,7 +786,7 @@ $string['list'] = 'List'; $string['listfiles'] = 'List of files in $a'; $string['listofallpeople'] = 'List of all people'; $string['livelogs'] = 'Live logs from the past hour'; -$string['locale'] = 'en.UTF-8'; +$string['locale'] = 'en_AU.UTF-8'; $string['location'] = 'Location'; $string['log_excel_date_format'] = 'yyyy mmmm d h:mm'; $string['loggedinas'] = 'You are logged in as $a'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 0877dd8aa1..1e97ed01af 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1005,13 +1005,8 @@ function userdate($date, $format='', $timezone=99, $fixday = true) { global $CFG; - static $strftimedaydatetime; - - if ($format == '') { - if (empty($strftimedaydatetime)) { - $strftimedaydatetime = get_string('strftimedaydatetime'); - } - $format = $strftimedaydatetime; + if (empty($format)) { + $format = get_string('strftimedaydatetime'); } if (!empty($CFG->nofixday)) { // Config.php can force %d not to be fixed. @@ -1582,7 +1577,7 @@ function confirm_sesskey($sesskey=NULL) { * @param mixed $courseorid id of the course or course object */ function course_setup($courseorid=0) { - global $COURSE, $CFG, $SITE, $USER; + global $COURSE, $CFG, $SITE; /// Redefine global $COURSE if needed if (empty($courseorid)) { @@ -5477,19 +5472,14 @@ function notify_login_failures() { * moodle_setlocale * * @uses $CFG - * @uses $USER - * @uses $SESSION * @param string $locale ? * @todo Finish documenting this function */ function moodle_setlocale($locale='') { - global $SESSION, $USER, $CFG; + global $CFG; - static $currentlocale; // last locale caching - if (!isset($currentlocale)) { - $currentlocale = ''; - } + static $currentlocale = ''; // last locale caching $oldlocale = $currentlocale; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 770d2db1de..4f546d68e7 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -735,7 +735,6 @@ function forum_cron() { return true; } - function forum_make_mail_text($course, $forum, $discussion, $post, $userfrom, $userto, $bare = false) { global $CFG, $USER; @@ -743,7 +742,7 @@ function forum_make_mail_text($course, $forum, $discussion, $post, $userfrom, $u error('Course Module ID was incorrect'); } $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); - $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext); + $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id); $by = New stdClass; $by->name = fullname($userfrom, $viewfullnames); @@ -983,10 +982,12 @@ function forum_print_recent_activity($course, $isteacher, $timestart) { $mygroupid = mygroupid($course->id); $groupmode = array(); /// To cache group modes + $count = 0; foreach ($logs as $log) { //Get post info, I'll need it later if ($post = forum_get_post_from_log($log)) { //Create a temp valid module structure (course,id) + $tempmod = new object; $tempmod->course = $log->course; $tempmod->id = $post->forum; //Obtain the visible property from the instance @@ -1019,7 +1020,7 @@ function forum_print_recent_activity($course, $isteacher, $timestart) { } if (! $heading) { - print_headline(get_string('newforumposts', 'forum').':'); + print_headline(get_string('newforumposts', 'forum').':', 3); $heading = true; $content = true; } @@ -1027,7 +1028,12 @@ function forum_print_recent_activity($course, $isteacher, $timestart) { $subjectclass = ($log->action == 'add discussion') ? ' bold' : ''; - echo '
'. + //Accessibility: markup as a list. + if ($count < 1) { + echo "\n
'; + echo "\"\n"; } } + echo "\n"; return $content; } @@ -1852,7 +1859,7 @@ function forum_get_course_forum($courseid, $type) { $mod->instance = $forum->id; $mod->section = 0; if (! $mod->coursemodule = add_course_module($mod) ) { // assumes course/lib.php is loaded - notify("Could not add a new course module to the course '$course->fullname'"); + notify("Could not add a new course module to the course '" . format_string($course->fullname) . "'"); return false; } if (! $sectionid = add_mod_to_section($mod) ) { // assumes course/lib.php is loaded @@ -1878,8 +1885,7 @@ function forum_make_mail_post(&$post, $user, $touser, $course, global $CFG, $USER; - static $formattedtext; // Cached version of formatted text for a post - static $formattedtextid; // The ID number of the post + // the old caching was removed for now, because it did not work due to recent changes in cron $post->forum = get_field('forum_discussions', 'forum', 'id', $post->discussion); @@ -1888,13 +1894,10 @@ function forum_make_mail_post(&$post, $user, $touser, $course, } $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); - - if (empty($formattedtextid) or $formattedtextid != $post->id) { // Recalculate the formatting - $options = new Object; - $options->para = true; - $formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $course->id); - $formattedtextid = $post->id; - } + // format the post body + $options = new object(); + $options->para = true; + $formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $course->id); $output = ''; @@ -1910,6 +1913,7 @@ function forum_make_mail_post(&$post, $user, $touser, $course, $output .= '
'.format_string($post->subject).'
'; $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $modcontext)); + $by = new object(); $by->name = ''.$fullname.''; $by->date = userdate($post->modified, '', $touser->timezone); $output .= '
'.get_string('bynameondate', 'forum', $by).'
'; @@ -3045,11 +3049,17 @@ function forum_user_can_post_discussion($forum, $currentgroup=false, $groupmode= $context = get_context_instance(CONTEXT_MODULE, $cm->id); } - if (!has_capability('mod/forum:startdiscussion', $context)) { + if ($forum->type == 'news') { + $capname = 'mod/forum:addnews'; + } else { + $capname = 'mod/forum:startdiscussion'; + } + + if (!has_capability($capname, $context)) { return false; } - if ($forum->type == "eachuser") { + if ($forum->type == 'eachuser') { return (!forum_user_has_posted_discussion($forum->id, $USER->id)); } else if ($currentgroup) { return (has_capability('moodle/site:accessallgroups', $context) @@ -3083,11 +3093,17 @@ function forum_user_can_post($forum, $user=NULL, $cm=NULL, $context=NULL) { $context = get_context_instance(CONTEXT_MODULE, $cm->id); } - if (isset($user)) { - $canreply = has_capability('mod/forum:replypost', $context, $user->id, false) + if ($forum->type == 'news') { + $capname = 'mod/forum:replynews'; + } else { + $capname = 'mod/forum:replypost'; + } + + if (!empty($user)) { + $canreply = has_capability($capname, $context, $user->id, false) && !has_capability('moodle/legacy:guest', $context, $user->id, false); } else { - $canreply = has_capability('mod/forum:replypost', $context, NULL, false) + $canreply = has_capability($capname, $context, NULL, false) && !has_capability('moodle/legacy:guest', $context, NULL, false); } @@ -3111,9 +3127,9 @@ function forum_user_can_view_post($post, $course, $cm, $forum, $discussion, $use /// If it's a grouped discussion, make sure the user is a member if ($discussion->groupid > 0) { - if ($cm->groupmode == SEPARATEGROUPS) { - return ismember($discussion->groupid) || - has_capability('moodle/site:accessallgroups', $modcontext); + $groupmode = groupmode($course, $cm); + if ($groupmode == SEPARATEGROUPS) { + return ismember($discussion->groupid) || has_capability('moodle/site:accessallgroups', $modcontext); } } return true; @@ -3247,8 +3263,8 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $dis $currentgroup = get_current_group($course->id); } - if (!$currentgroup and ($groupmode != SEPARATEGROUPS or - has_capability('moodle/site:accessallgroups', $context)) ) { + if (!$currentgroup and + ($groupmode != SEPARATEGROUPS or has_capability('moodle/site:accessallgroups', $context)) ) { $visiblegroups = -1; } else { $visiblegroups = $currentgroup; @@ -3263,7 +3279,7 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $dis echo '
'; echo "
wwwroot/mod/forum/post.php\">"; - echo '
'; + echo '
'; echo "id\" />"; echo ''; - echo '
'; + echo '
'; echo ''; echo "\n"; } -- 2.39.5