Skip to content

Commit

Permalink
MDL-27823 messaging: preventing html tags from being output to the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjdavis committed Aug 19, 2011
1 parent 4f36324 commit 2a4d3c9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
19 changes: 14 additions & 5 deletions lib/moodlelib.php
Expand Up @@ -9335,11 +9335,13 @@ function message_popup_window() {
}

//got unread messages so now do another query that joins with the user table
$messagesql = "SELECT m.id, m.smallmessage, m.notification, u.firstname, u.lastname FROM {message} m
JOIN {message_working} mw ON m.id=mw.unreadmessageid
JOIN {message_processors} p ON mw.processorid=p.id
JOIN {user} u ON m.useridfrom=u.id
WHERE m.useridto = :userid AND p.name='popup'";
$messagesql = "SELECT m.id, m.smallmessage, m.fullmessageformat, m.notification, u.firstname, u.lastname
FROM {message} m
JOIN {message_working} mw ON m.id=mw.unreadmessageid
JOIN {message_processors} p ON mw.processorid=p.id
JOIN {user} u ON m.useridfrom=u.id
WHERE m.useridto = :userid
AND p.name='popup'";

//if the user was last notified over an hour ago we can renotify them of old messages
//so don't worry about when the new message was sent
Expand Down Expand Up @@ -9374,6 +9376,13 @@ function message_popup_window() {
} else {
$smallmessage = $message_users->smallmessage;
}

//prevent html symbols being displayed
if ($message_users->fullmessageformat == FORMAT_HTML) {
$smallmessage = html_to_text($smallmessage);
} else {
$smallmessage = s($smallmessage);
}
} else if ($message_users->notification) {
//its a notification with no smallmessage so just say they have a notification
$smallmessage = get_string('unreadnewnotification', 'message');
Expand Down
10 changes: 8 additions & 2 deletions message/lib.php
Expand Up @@ -1944,9 +1944,15 @@ function message_format_message($message, $format='', $keywords='', $class='othe

//if supplied display small messages as fullmessage may contain boilerplate text that shouldnt appear in the messaging UI
if (!empty($message->smallmessage)) {
$messagetext = format_text(s($message->smallmessage), FORMAT_MOODLE, $options);
$messagetext = $message->smallmessage;
} else {
$messagetext = format_text(s($message->fullmessage), $message->fullmessageformat, $options);
$messagetext = $message->fullmessage;
}
if ($message->fullmessageformat == FORMAT_HTML) {
//dont escape html tags by calling s() if html format or they will display in the UI
$messagetext = html_to_text(format_text($messagetext, $message->fullmessageformat, $options));
} else {
$messagetext = format_text(s($messagetext), $message->fullmessageformat, $options);
}

$messagetext .= message_format_contexturl($message);
Expand Down
2 changes: 1 addition & 1 deletion user/messageselect.php
Expand Up @@ -91,7 +91,7 @@

$count = 0;

if ($post = data_submitted()) {
if ($data = data_submitted()) {
foreach ($data as $k => $v) {
if (preg_match('/^(user|teacher)(\d+)$/',$k,$m)) {
if (!array_key_exists($m[2],$SESSION->emailto[$id])) {
Expand Down

0 comments on commit 2a4d3c9

Please sign in to comment.