From 5b0769db688782f60f2d1f365946f5a53da329e7 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 23 Sep 2016 14:00:50 +0800 Subject: [PATCH] MDL-54744 core_message: deprecated functions in message/lib.php Also - 1) Made note of the deprecation as well as the functions and files that were removed earlier in upgrade.txt. 2) Added new functions to api.php to replace the deprecated ones that were being used in unit tests. 3) Removed files that are no longer being used. --- lib/deprecatedlib.php | 708 +++++++++++++++++++++++++++++ message/bell.mp3 | Bin 5432 -> 0 bytes message/bell.ogg | Bin 4864 -> 0 bytes message/bell.wav | Bin 5272 -> 0 bytes message/classes/api.php | 118 +++++ message/discussion.php | 38 -- message/lib.php | 730 ------------------------------ message/settings.html | 26 -- message/tests/api_test.php | 22 + message/tests/events_test.php | 8 +- message/tests/messagelib_test.php | 275 +---------- message/upgrade.txt | 24 + 12 files changed, 881 insertions(+), 1068 deletions(-) delete mode 100644 message/bell.mp3 delete mode 100644 message/bell.ogg delete mode 100644 message/bell.wav delete mode 100644 message/discussion.php delete mode 100644 message/settings.html diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 89fc141c9c1..72dd359a92c 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -4910,3 +4910,711 @@ class css_optimiser { return $css; } } + +/** + * Load the course contexts for all of the users courses + * + * @deprecated since Moodle 3.2 + * @param array $courses array of course objects. The courses the user is enrolled in. + * @return array of course contexts + */ +function message_get_course_contexts($courses) { + debugging('message_get_course_contexts() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + $coursecontexts = array(); + + foreach($courses as $course) { + $coursecontexts[$course->id] = context_course::instance($course->id); + } + + return $coursecontexts; +} + +/** + * strip off action parameters like 'removecontact' + * + * @deprecated since Moodle 3.2 + * @param moodle_url/string $moodleurl a URL. Typically the current page URL. + * @return string the URL minus parameters that perform actions (like adding/removing/blocking a contact). + */ +function message_remove_url_params($moodleurl) { + debugging('message_remove_url_params() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + $newurl = new moodle_url($moodleurl); + $newurl->remove_params('addcontact','removecontact','blockcontact','unblockcontact'); + return $newurl->out(); +} + +/** + * Count the number of messages with a field having a specified value. + * if $field is empty then return count of the whole array + * if $field is non-existent then return 0 + * + * @deprecated since Moodle 3.2 + * @param array $messagearray array of message objects + * @param string $field the field to inspect on the message objects + * @param string $value the value to test the field against + */ +function message_count_messages($messagearray, $field='', $value='') { + debugging('message_count_messages() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + if (!is_array($messagearray)) return 0; + if ($field == '' or empty($messagearray)) return count($messagearray); + + $count = 0; + foreach ($messagearray as $message) { + $count += ($message->$field == $value) ? 1 : 0; + } + return $count; +} + +/** + * Count the number of users blocked by $user1 + * + * @deprecated since Moodle 3.2 + * @param object $user1 user object + * @return int the number of blocked users + */ +function message_count_blocked_users($user1=null) { + debugging('message_count_blocked_users() is deprecated, please use \core_message\api::count_blocked_users() instead.', + DEBUG_DEVELOPER); + + return \core_message\api::count_blocked_users($user1); +} + +/** + * Print a message contact link + * + * @deprecated since Moodle 3.2 + * @param int $userid the ID of the user to apply to action to + * @param string $linktype can be add, remove, block or unblock + * @param bool $return if true return the link as a string. If false echo the link. + * @param string $script the URL to send the user to when the link is clicked. If null, the current page. + * @param bool $text include text next to the icons? + * @param bool $icon include a graphical icon? + * @return string if $return is true otherwise bool + */ +function message_contact_link($userid, $linktype='add', $return=false, $script=null, $text=false, $icon=true) { + debugging('message_contact_link() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + global $OUTPUT, $PAGE; + + //hold onto the strings as we're probably creating a bunch of links + static $str; + + if (empty($script)) { + //strip off previous action params like 'removecontact' + $script = message_remove_url_params($PAGE->url); + } + + if (empty($str->blockcontact)) { + $str = new stdClass(); + $str->blockcontact = get_string('blockcontact', 'message'); + $str->unblockcontact = get_string('unblockcontact', 'message'); + $str->removecontact = get_string('removecontact', 'message'); + $str->addcontact = get_string('addcontact', 'message'); + } + + $command = $linktype.'contact'; + $string = $str->{$command}; + + $safealttext = s($string); + + $safestring = ''; + if (!empty($text)) { + $safestring = $safealttext; + } + + $img = ''; + if ($icon) { + $iconpath = null; + switch ($linktype) { + case 'block': + $iconpath = 't/block'; + break; + case 'unblock': + $iconpath = 't/unblock'; + break; + case 'remove': + $iconpath = 't/removecontact'; + break; + case 'add': + default: + $iconpath = 't/addcontact'; + } + + $img = ''.$safealttext.''; + } + + $output = ''. + ''. + $img. + $safestring.''; + + if ($return) { + return $output; + } else { + echo $output; + return true; + } +} + +/** + * Get the users recent event notifications + * + * @deprecated since Moodle 3.2 + * @param object $user the current user + * @param int $limitfrom can be used for paging + * @param int $limitto can be used for paging + * @return array + */ +function message_get_recent_notifications($user, $limitfrom=0, $limitto=100) { + debugging('message_get_recent_notifications() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + global $DB; + + $userfields = user_picture::fields('u', array('lastaccess')); + $sql = "SELECT mr.id AS message_read_id, $userfields, mr.notification, mr.smallmessage, mr.fullmessage, mr.fullmessagehtml, mr.fullmessageformat, mr.timecreated as timecreated, mr.contexturl, mr.contexturlname + FROM {message_read} mr + JOIN {user} u ON u.id=mr.useridfrom + WHERE mr.useridto = :userid1 AND u.deleted = '0' AND mr.notification = :notification + ORDER BY mr.timecreated DESC"; + $params = array('userid1' => $user->id, 'notification' => 1); + + $notifications = $DB->get_records_sql($sql, $params, $limitfrom, $limitto); + return $notifications; +} + +/** + * echo or return a link to take the user to the full message history between themselves and another user + * + * @deprecated since Moodle 3.2 + * @param int $userid1 the ID of the user displayed on the left (usually the current user) + * @param int $userid2 the ID of the other user + * @param bool $return true to return the link as a string. False to echo the link. + * @param string $keywords any keywords to highlight in the message history + * @param string $position anchor name to jump to within the message history + * @param string $linktext optionally specify the link text + * @return string|bool. Returns a string if $return is true. Otherwise returns a boolean. + */ +function message_history_link($userid1, $userid2, $return=false, $keywords='', $position='', $linktext='') { + debugging('message_history_link() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + global $OUTPUT, $PAGE; + static $strmessagehistory; + + if (empty($strmessagehistory)) { + $strmessagehistory = get_string('messagehistory', 'message'); + } + + if ($position) { + $position = "#$position"; + } + if ($keywords) { + $keywords = "&search=".urlencode($keywords); + } + + if ($linktext == 'icon') { // Icon only + $fulllink = ''.$strmessagehistory.''; + } else if ($linktext == 'both') { // Icon and standard name + $fulllink = ''; + $fulllink .= ' '.$strmessagehistory; + } else if ($linktext) { // Custom name + $fulllink = $linktext; + } else { // Standard name only + $fulllink = $strmessagehistory; + } + + $popupoptions = array( + 'height' => 500, + 'width' => 500, + 'menubar' => false, + 'location' => false, + 'status' => true, + 'scrollbars' => true, + 'resizable' => true); + + $link = new moodle_url('/message/index.php?history='.MESSAGE_HISTORY_ALL."&user1=$userid1&user2=$userid2$keywords$position"); + if ($PAGE->url && $PAGE->url->get_param('viewing')) { + $link->param('viewing', $PAGE->url->get_param('viewing')); + } + $action = null; + $str = $OUTPUT->action_link($link, $fulllink, $action, array('title' => $strmessagehistory)); + + $str = ''.$str.''; + + if ($return) { + return $str; + } else { + echo $str; + return true; + } +} + +/** + * Search a user's messages + * + * Returns a list of posts found using an array of search terms + * eg word +word -word + * + * @deprecated since Moodle 3.2 + * @param array $searchterms an array of search terms (strings) + * @param bool $fromme include messages from the user? + * @param bool $tome include messages to the user? + * @param mixed $courseid SITEID for admins searching all messages. Other behaviour not yet implemented + * @param int $userid the user ID of the current user + * @return mixed An array of messages or false if no matching messages were found + */ +function message_search($searchterms, $fromme=true, $tome=true, $courseid='none', $userid=0) { + debugging('message_search() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + global $CFG, $USER, $DB; + + // If user is searching all messages check they are allowed to before doing anything else. + if ($courseid == SITEID && !has_capability('moodle/site:readallmessages', context_system::instance())) { + print_error('accessdenied','admin'); + } + + // If no userid sent then assume current user. + if ($userid == 0) $userid = $USER->id; + + // Some differences in SQL syntax. + if ($DB->sql_regex_supported()) { + $REGEXP = $DB->sql_regex(true); + $NOTREGEXP = $DB->sql_regex(false); + } + + $searchcond = array(); + $params = array(); + $i = 0; + + // Preprocess search terms to check whether we have at least 1 eligible search term. + // If we do we can drop words around it like 'a'. + $dropshortwords = false; + foreach ($searchterms as $searchterm) { + if (strlen($searchterm) >= 2) { + $dropshortwords = true; + } + } + + foreach ($searchterms as $searchterm) { + $i++; + + $NOT = false; // Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle. + + if ($dropshortwords && strlen($searchterm) < 2) { + continue; + } + // Under Oracle and MSSQL, trim the + and - operators and perform simpler LIKE search. + if (!$DB->sql_regex_supported()) { + if (substr($searchterm, 0, 1) == '-') { + $NOT = true; + } + $searchterm = trim($searchterm, '+-'); + } + + if (substr($searchterm,0,1) == "+") { + $searchterm = substr($searchterm,1); + $searchterm = preg_quote($searchterm, '|'); + $searchcond[] = "m.fullmessage $REGEXP :ss$i"; + $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)"; + + } else if (substr($searchterm,0,1) == "-") { + $searchterm = substr($searchterm,1); + $searchterm = preg_quote($searchterm, '|'); + $searchcond[] = "m.fullmessage $NOTREGEXP :ss$i"; + $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)"; + + } else { + $searchcond[] = $DB->sql_like("m.fullmessage", ":ss$i", false, true, $NOT); + $params['ss'.$i] = "%$searchterm%"; + } + } + + if (empty($searchcond)) { + $searchcond = " ".$DB->sql_like('m.fullmessage', ':ss1', false); + $params['ss1'] = "%"; + } else { + $searchcond = implode(" AND ", $searchcond); + } + + // There are several possibilities + // 1. courseid = SITEID : The admin is searching messages by all users + // 2. courseid = ?? : A teacher is searching messages by users in + // one of their courses - currently disabled + // 3. courseid = none : User is searching their own messages; + // a. Messages from user + // b. Messages to user + // c. Messages to and from user + + if ($fromme && $tome) { + $searchcond .= " AND ((useridto = :useridto AND timeusertodeleted = 0) OR + (useridfrom = :useridfrom AND timeuserfromdeleted = 0))"; + $params['useridto'] = $userid; + $params['useridfrom'] = $userid; + } else if ($fromme) { + $searchcond .= " AND (useridfrom = :useridfrom AND timeuserfromdeleted = 0)"; + $params['useridfrom'] = $userid; + } else if ($tome) { + $searchcond .= " AND (useridto = :useridto AND timeusertodeleted = 0)"; + $params['useridto'] = $userid; + } + if ($courseid == SITEID) { // Admin is searching all messages. + $m_read = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.smallmessage, m.fullmessage, m.timecreated + FROM {message_read} m + WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS); + $m_unread = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.smallmessage, m.fullmessage, m.timecreated + FROM {message} m + WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS); + + } else if ($courseid !== 'none') { + // This has not been implemented due to security concerns. + $m_read = array(); + $m_unread = array(); + + } else { + + if ($fromme and $tome) { + $searchcond .= " AND (m.useridfrom=:userid1 OR m.useridto=:userid2)"; + $params['userid1'] = $userid; + $params['userid2'] = $userid; + + } else if ($fromme) { + $searchcond .= " AND m.useridfrom=:userid"; + $params['userid'] = $userid; + + } else if ($tome) { + $searchcond .= " AND m.useridto=:userid"; + $params['userid'] = $userid; + } + + $m_read = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.smallmessage, m.fullmessage, m.timecreated + FROM {message_read} m + WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS); + $m_unread = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.smallmessage, m.fullmessage, m.timecreated + FROM {message} m + WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS); + + } + + /// The keys may be duplicated in $m_read and $m_unread so we can't + /// do a simple concatenation + $messages = array(); + foreach ($m_read as $m) { + $messages[] = $m; + } + foreach ($m_unread as $m) { + $messages[] = $m; + } + + return (empty($messages)) ? false : $messages; +} + +/** + * Given a message object that we already know has a long message + * this function truncates the message nicely to the first + * sane place between $CFG->forum_longpost and $CFG->forum_shortpost + * + * @deprecated since Moodle 3.2 + * @param string $message the message + * @param int $minlength the minimum length to trim the message to + * @return string the shortened message + */ +function message_shorten_message($message, $minlength = 0) { + debugging('message_shorten_message() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + $i = 0; + $tag = false; + $length = strlen($message); + $count = 0; + $stopzone = false; + $truncate = 0; + if ($minlength == 0) $minlength = MESSAGE_SHORTLENGTH; + + + for ($i=0; $i<$length; $i++) { + $char = $message[$i]; + + switch ($char) { + case "<": + $tag = true; + break; + case ">": + $tag = false; + break; + default: + if (!$tag) { + if ($stopzone) { + if ($char == '.' or $char == ' ') { + $truncate = $i+1; + break 2; + } + } + $count++; + } + break; + } + if (!$stopzone) { + if ($count > $minlength) { + $stopzone = true; + } + } + } + + if (!$truncate) { + $truncate = $i; + } + + return substr($message, 0, $truncate); +} + +/** + * Given a string and an array of keywords, this function looks + * for the first keyword in the string, and then chops out a + * small section from the text that shows that word in context. + * + * @deprecated since Moodle 3.2 + * @param string $message the text to search + * @param array $keywords array of keywords to find + */ +function message_get_fragment($message, $keywords) { + debugging('message_get_fragment() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + $fullsize = 160; + $halfsize = (int)($fullsize/2); + + $message = strip_tags($message); + + foreach ($keywords as $keyword) { // Just get the first one + if ($keyword !== '') { + break; + } + } + if (empty($keyword)) { // None found, so just return start of message + return message_shorten_message($message, 30); + } + + $leadin = $leadout = ''; + +/// Find the start of the fragment + $start = 0; + $length = strlen($message); + + $pos = strpos($message, $keyword); + if ($pos > $halfsize) { + $start = $pos - $halfsize; + $leadin = '...'; + } +/// Find the end of the fragment + $end = $start + $fullsize; + if ($end > $length) { + $end = $length; + } else { + $leadout = '...'; + } + +/// Pull out the fragment and format it + + $fragment = substr($message, $start, $end - $start); + $fragment = $leadin.highlight(implode(' ',$keywords), $fragment).$leadout; + return $fragment; +} + +/** + * Retrieve the messages between two users + * + * @deprecated since Moodle 3.2 + * @param object $user1 the current user + * @param object $user2 the other user + * @param int $limitnum the maximum number of messages to retrieve + * @param bool $viewingnewmessages are we currently viewing new messages? + */ +function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=false) { + debugging('message_get_history() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + global $DB, $CFG; + + $messages = array(); + + //we want messages sorted oldest to newest but if getting a subset of messages we need to sort + //desc to get the last $limitnum messages then flip the order in php + $sort = 'asc'; + if ($limitnum>0) { + $sort = 'desc'; + } + + $notificationswhere = null; + //we have just moved new messages to read. If theyre here to see new messages dont hide notifications + if (!$viewingnewmessages && $CFG->messaginghidereadnotifications) { + $notificationswhere = 'AND notification=0'; + } + + //prevent notifications of your own actions appearing in your own message history + $ownnotificationwhere = ' AND NOT (useridfrom=? AND notification=1)'; + + $sql = "((useridto = ? AND useridfrom = ? AND timeusertodeleted = 0) OR + (useridto = ? AND useridfrom = ? AND timeuserfromdeleted = 0))"; + if ($messages_read = $DB->get_records_select('message_read', $sql . $notificationswhere . $ownnotificationwhere, + array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id), + "timecreated $sort", '*', 0, $limitnum)) { + foreach ($messages_read as $message) { + $messages[] = $message; + } + } + if ($messages_new = $DB->get_records_select('message', $sql . $ownnotificationwhere, + array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id), + "timecreated $sort", '*', 0, $limitnum)) { + foreach ($messages_new as $message) { + $messages[] = $message; + } + } + + $result = core_collator::asort_objects_by_property($messages, 'timecreated', core_collator::SORT_NUMERIC); + + //if we only want the last $limitnum messages + $messagecount = count($messages); + if ($limitnum > 0 && $messagecount > $limitnum) { + $messages = array_slice($messages, $messagecount - $limitnum, $limitnum, true); + } + + return $messages; +} + +/** + * Constructs the add/remove contact link to display next to other users + * + * @deprecated since Moodle 3.2 + * @param bool $incontactlist is the user a contact + * @param bool $isblocked is the user blocked + * @param stdClass $contact contact object + * @param string $script the URL to send the user to when the link is clicked. If null, the current page. + * @param bool $text include text next to the icons? + * @param bool $icon include a graphical icon? + * @return string + */ +function message_get_contact_add_remove_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) { + debugging('message_get_contact_add_remove_link() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + $strcontact = ''; + + if($incontactlist){ + $strcontact = message_contact_link($contact->id, 'remove', true, $script, $text, $icon); + } else if ($isblocked) { + $strcontact = message_contact_link($contact->id, 'add', true, $script, $text, $icon); + } else{ + $strcontact = message_contact_link($contact->id, 'add', true, $script, $text, $icon); + } + + return $strcontact; +} + +/** + * Constructs the block contact link to display next to other users + * + * @deprecated since Moodle 3.2 + * @param bool $incontactlist is the user a contact? + * @param bool $isblocked is the user blocked? + * @param stdClass $contact contact object + * @param string $script the URL to send the user to when the link is clicked. If null, the current page. + * @param bool $text include text next to the icons? + * @param bool $icon include a graphical icon? + * @return string + */ +function message_get_contact_block_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) { + debugging('message_get_contact_block_link() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + $strblock = ''; + + //commented out to allow the user to block a contact without having to remove them first + /*if ($incontactlist) { + //$strblock = ''; + } else*/ + if ($isblocked) { + $strblock = message_contact_link($contact->id, 'unblock', true, $script, $text, $icon); + } else{ + $strblock = message_contact_link($contact->id, 'block', true, $script, $text, $icon); + } + + return $strblock; +} + +/** + * marks ALL messages being sent from $fromuserid to $touserid as read + * + * @deprecated since Moodle 3.2 + * @param int $touserid the id of the message recipient + * @param int $fromuserid the id of the message sender + * @return void + */ +function message_mark_messages_read($touserid, $fromuserid) { + debugging('message_mark_messages_read() is deprecated and is no longer used, please use + \core_message\api::mark_all_read_for_user() instead.', DEBUG_DEVELOPER); + + \core_message\api::mark_all_read_for_user($touserid, $fromuserid); +} + +/** + * Return a list of page types + * + * @deprecated since Moodle 3.2 + * @param string $pagetype current page type + * @param stdClass $parentcontext Block's parent context + * @param stdClass $currentcontext Current context of block + */ +function message_page_type_list($pagetype, $parentcontext, $currentcontext) { + debugging('message_page_type_list() is deprecated and is no longer used.', DEBUG_DEVELOPER); + + return array('messages-*'=>get_string('page-message-x', 'message')); +} + +/** + * Determines if a user is permitted to send another user a private message. + * If no sender is provided then it defaults to the logged in user. + * + * @deprecated since Moodle 3.2 + * @param object $recipient User object. + * @param object $sender User object. + * @return bool true if user is permitted, false otherwise. + */ +function message_can_post_message($recipient, $sender = null) { + debugging('message_can_post_message() is deprecated and is no longer used, please use + \core_message\api::can_post_message() instead.', DEBUG_DEVELOPER); + + return \core_message\api::can_post_message($recipient, $sender); +} + +/** + * Checks if the recipient is allowing messages from users that aren't a + * contact. If not then it checks to make sure the sender is in the + * recipient's contacts. + * + * @deprecated since Moodle 3.2 + * @param object $recipient User object. + * @param object $sender User object. + * @return bool true if $sender is blocked, false otherwise. + */ +function message_is_user_non_contact_blocked($recipient, $sender = null) { + debugging('message_is_user_non_contact_blocked() is deprecated and is no longer used, please use + \core_message\api::is_user_non_contact_blocked() instead.', DEBUG_DEVELOPER); + + return \core_message\api::is_user_non_contact_blocked($recipient, $sender); +} + +/** + * Checks if the recipient has specifically blocked the sending user. + * + * Note: This function will always return false if the sender has the + * readallmessages capability at the system context level. + * + * @deprecated since Moodle 3.2 + * @param object $recipient User object. + * @param object $sender User object. + * @return bool true if $sender is blocked, false otherwise. + */ +function message_is_user_blocked($recipient, $sender = null) { + debugging('message_is_user_blocked() is deprecated and is no longer used, please use + \core_message\api::is_user_blocked() instead.', DEBUG_DEVELOPER); + + return \core_message\api::is_user_blocked($recipient, $sender); +} diff --git a/message/bell.mp3 b/message/bell.mp3 deleted file mode 100644 index 1aacdb82eaf72d4506d9755f9711e081fbc1b3d5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5432 zcmd^@X;72Nx`4kg2_Xpq5+;POCkU7X2oXU6Q4)v<0ty5$vQ5|*6%_=*aWFx^uqhx* zz%T|`1Ox;D1yKyEVNnAp2%-mtAc8tB;~9?|SMJq6x9a}Ab#C3~tFG>@?)v)edaB;8 z?$vo-KkyTm*ocGQ+p6CS8UWO-0rekHf57;G&rf20!23bb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;xFQilnudDP{yz3i{9TYj3s zb;knKq{Xa``bExM1J$9pAJEKk5hjb1h0zg((@##EUu@*tk zzH8M`?J?mO>3%HH@YNRChx+Cb3MVXMdzi0V_}YTGdTc}A?cwk>Lya69-jF#h1p;?{ z_;m9hCOa#4zyGRrlX^l_({{Hc?lmVOZlUjLLb04S(k8cYdvVm%qUQTwUf*454>e!; z^lhXzKpk{&IqDh`gzG608}{2x9$%@4~p^U{AyQ~zhXYlgl*bU~fhUc3H1cl+-d)&H9D F{{S*zY%Kr) diff --git a/message/bell.ogg b/message/bell.ogg deleted file mode 100644 index e3f1a5e2d1e76b336f9b0002bfd4a0ee59cf6406..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4864 zcmcIoc{r5a`#)pJVA2pms+pn;i4ldCuPyNmrDqaGD#m0PWG}SHR(VyEW@Ihfh+zg( zLr8C%sVGSqMf+P>hI(71-S0elzwdSZuIu;j@405q-1q%?&VBCf+|PMtV@L=cD1d*i zQ$Z^U7&-sov3jd5)g~M3(-9_~hoThac}y?=_4Aky>|DvgMEYTOeSXSDQ=Tt!Qxo;2teZ#o zpu6+XJV-IM>274YjLIsD)23y)s~SgmisE%?!v)Mds_Q&vHv=hQ%Bb)@6m>6))3e`c z9IS2c+A$oo*V3L>?qqW5##3~}JTu!ryS?9lE;rB6qlI0;2gZ#{`W_?U9eT_hs!`c-EVW~9QVZ(@7s3xvIz~l z*V@6os5Cz)XHz$aPM|7NvwA3*#0MMf_=JUcXSb5zZW3+H@bjP{TcUw@Avg?I%W=#h zOF3}_WCl6*nEOqVOSc`RgzJHr2+!xatD5s<3x|ri8<55P^SWqPC0FKTrVN0RE&Tf8 zGqdXOpd0{VItO*5T;~RDpdR9)$0#>A=xw`>{Ma1oFlqB`>P^E8H%f2w%|o~8%{kYx)5@@zqPS5@sm(}4bk%20TG-#-ighv`(7m< zZ5r)t6?KZ=4mOFti-qcK!>vuCPLZfqTqhTs%bOwwoo;>H+_&7bf5PK_f_J|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IfgPUg0~LyO1c=;UE)w?DnGL2D%$UmEOLA9ee>ofPUjK5q;GN`H@x`&OS2EATZ$e@hC^o}*fz&V+ zQVnP{#icquwpvx>@2aVGB6_}!g+ry&i_z!tA6~Eh*wd3)yvlX;y@+<>Co3h4A!Jd? zyS}mn(}6PIB@+on7T1WMu0Ji#*0;5c>m9w?8HJ0af!YEL|bvvx~-w|1nhDQC8Mo6qDh!9}yc$7>!fX>J3%MWR}sp*K1eGZA{>FWDBe z$UTy67cIv!w{8me{(D?e`#g7*1u8QUJESgN$pAPu^=26MgqT(|P`~!?+^expd0@^RM>&?>pxM}N5Egj~3o8UR4 z*V1W=?~LAc>GGQ3UO0APz(?uZ?w6lF~>-uXRMEM2^pZ98|wS%XYh{t uXL8~P^efKoBN!j2y4{@1FOMnQYw~PriAS;Z`_Fe%63<=sX02SyQTiXxq$<4t diff --git a/message/bell.wav b/message/bell.wav deleted file mode 100644 index cb19faca25a882c91fe7f2e8b220f5ab4deb38fd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5272 zcmZ8jNsk;?a^~E8v;kjy^WFc!fDazPfPsO>fX0$Vks{e^?OD0KJ>Hf}WoC6%^+K{K zQ6tTaJwEwp_}}@g?%DD8i)VlF?9I37w-d;4pM7f@|KZ(Yt*`W5#y8dGkS*0BiO#<_ZX7(c$EqgxD zdEA_tp{VS0fB$WPR-e@|d)rT?{noyf{ljeD&5Q3$Hl!C@n?2N5&Rq7p zS>2zN`;-o8wp(TQvb^Qft(fln#ily9?V{b!XqXoJl;5xCH^uzU&Ifb336s9PjKhR> zQ+-&n+hl#8Cl6+Jkk{L|ICNJY$M@@SdztT->LW`J%gcMpzw@tZeSUkN4E5InDt=mK z-Rs2%qrT6++2qrYH?vOuCTv%?kFVF^x&BemyVo!K75^`L*-!rcFytTFuS$Bk`)%s_ zFJ^a%|Bv<6=IrA8y7-=bQK`%C-e1-3U-kWJ`|*6Sc~$E525xtacBU3M2=*G~VmJ=g2!{ewJo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P|-{count_records_sql($sql, array('userid' => $user->id)); + } + + /** + * Determines if a user is permitted to send another user a private message. + * If no sender is provided then it defaults to the logged in user. + * + * @param \stdClass $recipient The user object. + * @param \stdClass|null $sender The user object. + * @return bool true if user is permitted, false otherwise. + */ + public static function can_post_message($recipient, $sender = null) { + global $USER; + + if (is_null($sender)) { + // The message is from the logged in user, unless otherwise specified. + $sender = $USER; + } + + if (!has_capability('moodle/site:sendmessage', \context_system::instance(), $sender)) { + return false; + } + + // The recipient blocks messages from non-contacts and the + // sender isn't a contact. + if (self::is_user_non_contact_blocked($recipient, $sender)) { + return false; + } + + // The recipient has specifically blocked this sender. + if (self::is_user_blocked($recipient, $sender)) { + return false; + } + + return true; + } + + /** + * Checks if the recipient is allowing messages from users that aren't a + * contact. If not then it checks to make sure the sender is in the + * recipient's contacts. + * + * @param \stdClass $recipient The user object. + * @param \stdClass|null $sender The user object. + * @return bool true if $sender is blocked, false otherwise. + */ + public static function is_user_non_contact_blocked($recipient, $sender = null) { + global $USER, $DB; + + if (is_null($sender)) { + // The message is from the logged in user, unless otherwise specified. + $sender = $USER; + } + + $blockednoncontacts = get_user_preferences('message_blocknoncontacts', '', $recipient->id); + if (!empty($blockednoncontacts)) { + // Confirm the sender is a contact of the recipient. + $exists = $DB->record_exists('message_contacts', array('userid' => $recipient->id, 'contactid' => $sender->id)); + if ($exists) { + // All good, the recipient is a contact of the sender. + return false; + } else { + // Oh no, the recipient is not a contact. Looks like we can't send the message. + return true; + } + } + + return false; + } + + /** + * Checks if the recipient has specifically blocked the sending user. + * + * Note: This function will always return false if the sender has the + * readallmessages capability at the system context level. + * + * @param object $recipient User object. + * @param object $sender User object. + * @return bool true if $sender is blocked, false otherwise. + */ + public static function is_user_blocked($recipient, $sender = null) { + global $USER, $DB; + + if (is_null($sender)) { + // The message is from the logged in user, unless otherwise specified. + $sender = $USER; + } + + $systemcontext = \context_system::instance(); + if (has_capability('moodle/site:readallmessages', $systemcontext, $sender)) { + return false; + } + + if ($contact = $DB->get_record('message_contacts', array('userid' => $recipient->id, 'contactid' => $sender->id))) { + if ($contact->blocked) { + return true; + } + } + + return false; + } } diff --git a/message/discussion.php b/message/discussion.php deleted file mode 100644 index ce6e892638f..00000000000 --- a/message/discussion.php +++ /dev/null @@ -1,38 +0,0 @@ -. - -/** - * This file was replaced by index.php in Moodle 2.0 and now simply redirects to index.php - * - * @package core_message - * @copyright 2005 Luis Rodrigues and Martin Dougiamas - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - require(__DIR__ . '/../config.php'); - require_once($CFG->dirroot . '/message/lib.php'); - - //the same URL params as in 1.9 - $userid = required_param('id', PARAM_INT); - $noframesjs = optional_param('noframesjs', 0, PARAM_BOOL); - - $params = array('user2'=>$userid); - if (!empty($noframesjs)) { - $params['noframesjs'] = $noframesjs; - } - $url = new moodle_url('/message/index.php', $params); - redirect($url); -?> diff --git a/message/lib.php b/message/lib.php index 3ed279c34f3..e8af2fcdedc 100644 --- a/message/lib.php +++ b/message/lib.php @@ -52,7 +52,6 @@ define('MESSAGE_READ', 'read'); define('MESSAGE_TYPE_NOTIFICATION', 'notification'); define('MESSAGE_TYPE_MESSAGE', 'message'); - /** * Define contants for messaging default settings population. For unambiguity of * plugin developer intentions we use 4-bit value (LSB numbering): @@ -218,54 +217,6 @@ function message_get_contacts($user1=null, $user2=null) { return array($onlinecontacts, $offlinecontacts, $strangers); } -/** - * Load the course contexts for all of the users courses - * - * @param array $courses array of course objects. The courses the user is enrolled in. - * @return array of course contexts - */ -function message_get_course_contexts($courses) { - $coursecontexts = array(); - - foreach($courses as $course) { - $coursecontexts[$course->id] = context_course::instance($course->id); - } - - return $coursecontexts; -} - -/** - * strip off action parameters like 'removecontact' - * - * @param moodle_url/string $moodleurl a URL. Typically the current page URL. - * @return string the URL minus parameters that perform actions (like adding/removing/blocking a contact). - */ -function message_remove_url_params($moodleurl) { - $newurl = new moodle_url($moodleurl); - $newurl->remove_params('addcontact','removecontact','blockcontact','unblockcontact'); - return $newurl->out(); -} - -/** - * Count the number of messages with a field having a specified value. - * if $field is empty then return count of the whole array - * if $field is non-existent then return 0 - * - * @param array $messagearray array of message objects - * @param string $field the field to inspect on the message objects - * @param string $value the value to test the field against - */ -function message_count_messages($messagearray, $field='', $value='') { - if (!is_array($messagearray)) return 0; - if ($field == '' or empty($messagearray)) return count($messagearray); - - $count = 0; - foreach ($messagearray as $message) { - $count += ($message->$field == $value) ? 1 : 0; - } - return $count; -} - /** * Returns the count of unread messages for user. Either from a specific user or from all users. * @@ -289,27 +240,6 @@ function message_count_unread_messages($user1=null, $user2=null) { } } -/** - * Count the number of users blocked by $user1 - * - * @param object $user1 user object - * @return int the number of blocked users - */ -function message_count_blocked_users($user1=null) { - global $USER, $DB; - - if (empty($user1)) { - $user1 = $USER; - } - - $sql = "SELECT count(mc.id) - FROM {message_contacts} mc - WHERE mc.userid = :userid AND mc.blocked = 1"; - $params = array('userid' => $user1->id); - - return $DB->count_records_sql($sql, $params); -} - /** * Get the users recent conversations meaning all the people they've recently * sent or received a message from plus the most recent message sent to or received from each other user @@ -447,29 +377,6 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) { return $conversations; } -/** - * Get the users recent event notifications - * - * @param object $user the current user - * @param int $limitfrom can be used for paging - * @param int $limitto can be used for paging - * @return array - */ -function message_get_recent_notifications($user, $limitfrom=0, $limitto=100) { - global $DB; - - $userfields = user_picture::fields('u', array('lastaccess')); - $sql = "SELECT mr.id AS message_read_id, $userfields, mr.notification, mr.smallmessage, mr.fullmessage, mr.fullmessagehtml, mr.fullmessageformat, mr.timecreated as timecreated, mr.contexturl, mr.contexturlname - FROM {message_read} mr - JOIN {user} u ON u.id=mr.useridfrom - WHERE mr.useridto = :userid1 AND u.deleted = '0' AND mr.notification = :notification - ORDER BY mr.timecreated DESC"; - $params = array('userid1' => $user->id, 'notification' => 1); - - $notifications = $DB->get_records_sql($sql, $params, $limitfrom, $limitto); - return $notifications; -} - /** * Try to guess how to convert the message to html. * @@ -752,145 +659,6 @@ function message_get_contact($contactid) { return $DB->get_record('message_contacts', array('userid' => $USER->id, 'contactid' => $contactid)); } -/** - * Print a message contact link - * - * @param int $userid the ID of the user to apply to action to - * @param string $linktype can be add, remove, block or unblock - * @param bool $return if true return the link as a string. If false echo the link. - * @param string $script the URL to send the user to when the link is clicked. If null, the current page. - * @param bool $text include text next to the icons? - * @param bool $icon include a graphical icon? - * @return string if $return is true otherwise bool - */ -function message_contact_link($userid, $linktype='add', $return=false, $script=null, $text=false, $icon=true) { - global $OUTPUT, $PAGE; - - //hold onto the strings as we're probably creating a bunch of links - static $str; - - if (empty($script)) { - //strip off previous action params like 'removecontact' - $script = message_remove_url_params($PAGE->url); - } - - if (empty($str->blockcontact)) { - $str = new stdClass(); - $str->blockcontact = get_string('blockcontact', 'message'); - $str->unblockcontact = get_string('unblockcontact', 'message'); - $str->removecontact = get_string('removecontact', 'message'); - $str->addcontact = get_string('addcontact', 'message'); - } - - $command = $linktype.'contact'; - $string = $str->{$command}; - - $safealttext = s($string); - - $safestring = ''; - if (!empty($text)) { - $safestring = $safealttext; - } - - $img = ''; - if ($icon) { - $iconpath = null; - switch ($linktype) { - case 'block': - $iconpath = 't/block'; - break; - case 'unblock': - $iconpath = 't/unblock'; - break; - case 'remove': - $iconpath = 't/removecontact'; - break; - case 'add': - default: - $iconpath = 't/addcontact'; - } - - $img = ''.$safealttext.''; - } - - $output = ''. - ''. - $img. - $safestring.''; - - if ($return) { - return $output; - } else { - echo $output; - return true; - } -} - -/** - * echo or return a link to take the user to the full message history between themselves and another user - * - * @param int $userid1 the ID of the user displayed on the left (usually the current user) - * @param int $userid2 the ID of the other user - * @param bool $return true to return the link as a string. False to echo the link. - * @param string $keywords any keywords to highlight in the message history - * @param string $position anchor name to jump to within the message history - * @param string $linktext optionally specify the link text - * @return string|bool. Returns a string if $return is true. Otherwise returns a boolean. - */ -function message_history_link($userid1, $userid2, $return=false, $keywords='', $position='', $linktext='') { - global $OUTPUT, $PAGE; - static $strmessagehistory; - - if (empty($strmessagehistory)) { - $strmessagehistory = get_string('messagehistory', 'message'); - } - - if ($position) { - $position = "#$position"; - } - if ($keywords) { - $keywords = "&search=".urlencode($keywords); - } - - if ($linktext == 'icon') { // Icon only - $fulllink = ''.$strmessagehistory.''; - } else if ($linktext == 'both') { // Icon and standard name - $fulllink = ''; - $fulllink .= ' '.$strmessagehistory; - } else if ($linktext) { // Custom name - $fulllink = $linktext; - } else { // Standard name only - $fulllink = $strmessagehistory; - } - - $popupoptions = array( - 'height' => 500, - 'width' => 500, - 'menubar' => false, - 'location' => false, - 'status' => true, - 'scrollbars' => true, - 'resizable' => true); - - $link = new moodle_url('/message/index.php?history='.MESSAGE_HISTORY_ALL."&user1=$userid1&user2=$userid2$keywords$position"); - if ($PAGE->url && $PAGE->url->get_param('viewing')) { - $link->param('viewing', $PAGE->url->get_param('viewing')); - } - $action = null; - $str = $OUTPUT->action_link($link, $fulllink, $action, array('title' => $strmessagehistory)); - - $str = ''.$str.''; - - if ($return) { - return $str; - } else { - echo $str; - return true; - } -} - - /** * Search through course users. * @@ -984,325 +752,6 @@ function message_search_users($courseids, $searchtext, $sort='', $exceptions='') } } -/** - * Search a user's messages - * - * Returns a list of posts found using an array of search terms - * eg word +word -word - * - * @param array $searchterms an array of search terms (strings) - * @param bool $fromme include messages from the user? - * @param bool $tome include messages to the user? - * @param mixed $courseid SITEID for admins searching all messages. Other behaviour not yet implemented - * @param int $userid the user ID of the current user - * @return mixed An array of messages or false if no matching messages were found - */ -function message_search($searchterms, $fromme=true, $tome=true, $courseid='none', $userid=0) { - global $CFG, $USER, $DB; - - // If user is searching all messages check they are allowed to before doing anything else. - if ($courseid == SITEID && !has_capability('moodle/site:readallmessages', context_system::instance())) { - print_error('accessdenied','admin'); - } - - // If no userid sent then assume current user. - if ($userid == 0) $userid = $USER->id; - - // Some differences in SQL syntax. - if ($DB->sql_regex_supported()) { - $REGEXP = $DB->sql_regex(true); - $NOTREGEXP = $DB->sql_regex(false); - } - - $searchcond = array(); - $params = array(); - $i = 0; - - // Preprocess search terms to check whether we have at least 1 eligible search term. - // If we do we can drop words around it like 'a'. - $dropshortwords = false; - foreach ($searchterms as $searchterm) { - if (strlen($searchterm) >= 2) { - $dropshortwords = true; - } - } - - foreach ($searchterms as $searchterm) { - $i++; - - $NOT = false; // Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle. - - if ($dropshortwords && strlen($searchterm) < 2) { - continue; - } - // Under Oracle and MSSQL, trim the + and - operators and perform simpler LIKE search. - if (!$DB->sql_regex_supported()) { - if (substr($searchterm, 0, 1) == '-') { - $NOT = true; - } - $searchterm = trim($searchterm, '+-'); - } - - if (substr($searchterm,0,1) == "+") { - $searchterm = substr($searchterm,1); - $searchterm = preg_quote($searchterm, '|'); - $searchcond[] = "m.fullmessage $REGEXP :ss$i"; - $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)"; - - } else if (substr($searchterm,0,1) == "-") { - $searchterm = substr($searchterm,1); - $searchterm = preg_quote($searchterm, '|'); - $searchcond[] = "m.fullmessage $NOTREGEXP :ss$i"; - $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)"; - - } else { - $searchcond[] = $DB->sql_like("m.fullmessage", ":ss$i", false, true, $NOT); - $params['ss'.$i] = "%$searchterm%"; - } - } - - if (empty($searchcond)) { - $searchcond = " ".$DB->sql_like('m.fullmessage', ':ss1', false); - $params['ss1'] = "%"; - } else { - $searchcond = implode(" AND ", $searchcond); - } - - // There are several possibilities - // 1. courseid = SITEID : The admin is searching messages by all users - // 2. courseid = ?? : A teacher is searching messages by users in - // one of their courses - currently disabled - // 3. courseid = none : User is searching their own messages; - // a. Messages from user - // b. Messages to user - // c. Messages to and from user - - if ($fromme && $tome) { - $searchcond .= " AND ((useridto = :useridto AND timeusertodeleted = 0) OR - (useridfrom = :useridfrom AND timeuserfromdeleted = 0))"; - $params['useridto'] = $userid; - $params['useridfrom'] = $userid; - } else if ($fromme) { - $searchcond .= " AND (useridfrom = :useridfrom AND timeuserfromdeleted = 0)"; - $params['useridfrom'] = $userid; - } else if ($tome) { - $searchcond .= " AND (useridto = :useridto AND timeusertodeleted = 0)"; - $params['useridto'] = $userid; - } - if ($courseid == SITEID) { // Admin is searching all messages. - $m_read = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.smallmessage, m.fullmessage, m.timecreated - FROM {message_read} m - WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS); - $m_unread = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.smallmessage, m.fullmessage, m.timecreated - FROM {message} m - WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS); - - } else if ($courseid !== 'none') { - // This has not been implemented due to security concerns. - $m_read = array(); - $m_unread = array(); - - } else { - - if ($fromme and $tome) { - $searchcond .= " AND (m.useridfrom=:userid1 OR m.useridto=:userid2)"; - $params['userid1'] = $userid; - $params['userid2'] = $userid; - - } else if ($fromme) { - $searchcond .= " AND m.useridfrom=:userid"; - $params['userid'] = $userid; - - } else if ($tome) { - $searchcond .= " AND m.useridto=:userid"; - $params['userid'] = $userid; - } - - $m_read = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.smallmessage, m.fullmessage, m.timecreated - FROM {message_read} m - WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS); - $m_unread = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.smallmessage, m.fullmessage, m.timecreated - FROM {message} m - WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS); - - } - - /// The keys may be duplicated in $m_read and $m_unread so we can't - /// do a simple concatenation - $messages = array(); - foreach ($m_read as $m) { - $messages[] = $m; - } - foreach ($m_unread as $m) { - $messages[] = $m; - } - - return (empty($messages)) ? false : $messages; -} - -/** - * Given a message object that we already know has a long message - * this function truncates the message nicely to the first - * sane place between $CFG->forum_longpost and $CFG->forum_shortpost - * - * @param string $message the message - * @param int $minlength the minimum length to trim the message to - * @return string the shortened message - */ -function message_shorten_message($message, $minlength = 0) { - $i = 0; - $tag = false; - $length = strlen($message); - $count = 0; - $stopzone = false; - $truncate = 0; - if ($minlength == 0) $minlength = MESSAGE_SHORTLENGTH; - - - for ($i=0; $i<$length; $i++) { - $char = $message[$i]; - - switch ($char) { - case "<": - $tag = true; - break; - case ">": - $tag = false; - break; - default: - if (!$tag) { - if ($stopzone) { - if ($char == '.' or $char == ' ') { - $truncate = $i+1; - break 2; - } - } - $count++; - } - break; - } - if (!$stopzone) { - if ($count > $minlength) { - $stopzone = true; - } - } - } - - if (!$truncate) { - $truncate = $i; - } - - return substr($message, 0, $truncate); -} - - -/** - * Given a string and an array of keywords, this function looks - * for the first keyword in the string, and then chops out a - * small section from the text that shows that word in context. - * - * @param string $message the text to search - * @param array $keywords array of keywords to find - */ -function message_get_fragment($message, $keywords) { - - $fullsize = 160; - $halfsize = (int)($fullsize/2); - - $message = strip_tags($message); - - foreach ($keywords as $keyword) { // Just get the first one - if ($keyword !== '') { - break; - } - } - if (empty($keyword)) { // None found, so just return start of message - return message_shorten_message($message, 30); - } - - $leadin = $leadout = ''; - -/// Find the start of the fragment - $start = 0; - $length = strlen($message); - - $pos = strpos($message, $keyword); - if ($pos > $halfsize) { - $start = $pos - $halfsize; - $leadin = '...'; - } -/// Find the end of the fragment - $end = $start + $fullsize; - if ($end > $length) { - $end = $length; - } else { - $leadout = '...'; - } - -/// Pull out the fragment and format it - - $fragment = substr($message, $start, $end - $start); - $fragment = $leadin.highlight(implode(' ',$keywords), $fragment).$leadout; - return $fragment; -} - -/** - * Retrieve the messages between two users - * - * @param object $user1 the current user - * @param object $user2 the other user - * @param int $limitnum the maximum number of messages to retrieve - * @param bool $viewingnewmessages are we currently viewing new messages? - */ -function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=false) { - global $DB, $CFG; - - $messages = array(); - - //we want messages sorted oldest to newest but if getting a subset of messages we need to sort - //desc to get the last $limitnum messages then flip the order in php - $sort = 'asc'; - if ($limitnum>0) { - $sort = 'desc'; - } - - $notificationswhere = null; - //we have just moved new messages to read. If theyre here to see new messages dont hide notifications - if (!$viewingnewmessages && $CFG->messaginghidereadnotifications) { - $notificationswhere = 'AND notification=0'; - } - - //prevent notifications of your own actions appearing in your own message history - $ownnotificationwhere = ' AND NOT (useridfrom=? AND notification=1)'; - - $sql = "((useridto = ? AND useridfrom = ? AND timeusertodeleted = 0) OR - (useridto = ? AND useridfrom = ? AND timeuserfromdeleted = 0))"; - if ($messages_read = $DB->get_records_select('message_read', $sql . $notificationswhere . $ownnotificationwhere, - array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id), - "timecreated $sort", '*', 0, $limitnum)) { - foreach ($messages_read as $message) { - $messages[] = $message; - } - } - if ($messages_new = $DB->get_records_select('message', $sql . $ownnotificationwhere, - array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id), - "timecreated $sort", '*', 0, $limitnum)) { - foreach ($messages_new as $message) { - $messages[] = $message; - } - } - - $result = core_collator::asort_objects_by_property($messages, 'timecreated', core_collator::SORT_NUMERIC); - - //if we only want the last $limitnum messages - $messagecount = count($messages); - if ($limitnum > 0 && $messagecount > $limitnum) { - $messages = array_slice($messages, $messagecount - $limitnum, $limitnum, true); - } - - return $messages; -} - /** * Format a message for display in the message history * @@ -1419,58 +868,6 @@ function message_post_message($userfrom, $userto, $message, $format) { return message_send($eventdata); } -/** - * Constructs the add/remove contact link to display next to other users - * - * @param bool $incontactlist is the user a contact - * @param bool $isblocked is the user blocked - * @param stdClass $contact contact object - * @param string $script the URL to send the user to when the link is clicked. If null, the current page. - * @param bool $text include text next to the icons? - * @param bool $icon include a graphical icon? - * @return string - */ -function message_get_contact_add_remove_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) { - $strcontact = ''; - - if($incontactlist){ - $strcontact = message_contact_link($contact->id, 'remove', true, $script, $text, $icon); - } else if ($isblocked) { - $strcontact = message_contact_link($contact->id, 'add', true, $script, $text, $icon); - } else{ - $strcontact = message_contact_link($contact->id, 'add', true, $script, $text, $icon); - } - - return $strcontact; -} - -/** - * Constructs the block contact link to display next to other users - * - * @param bool $incontactlist is the user a contact? - * @param bool $isblocked is the user blocked? - * @param stdClass $contact contact object - * @param string $script the URL to send the user to when the link is clicked. If null, the current page. - * @param bool $text include text next to the icons? - * @param bool $icon include a graphical icon? - * @return string - */ -function message_get_contact_block_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) { - $strblock = ''; - - //commented out to allow the user to block a contact without having to remove them first - /*if ($incontactlist) { - //$strblock = ''; - } else*/ - if ($isblocked) { - $strblock = message_contact_link($contact->id, 'unblock', true, $script, $text, $icon); - } else{ - $strblock = message_contact_link($contact->id, 'block', true, $script, $text, $icon); - } - - return $strblock; -} - /** * Moves messages from a particular user from the message table (unread messages) to message_read * This is typically only used when a user is deleted @@ -1490,18 +887,6 @@ function message_move_userfrom_unread2read($userid) { return true; } -/** - * marks ALL messages being sent from $fromuserid to $touserid as read - * - * @param int $touserid the id of the message recipient - * @param int $fromuserid the id of the message sender - * @return void - */ -function message_mark_messages_read($touserid, $fromuserid) { - return \core_message\api::mark_all_read_for_user($touserid, $fromuserid); -} - - /** * Mark a single message as read * @@ -1726,16 +1111,6 @@ function translate_message_default_setting($plugindefault, $processorname) { return array($permitted, $loggedin, $loggedoff); } -/** - * Return a list of page types - * @param string $pagetype current page type - * @param stdClass $parentcontext Block's parent context - * @param stdClass $currentcontext Current context of block - */ -function message_page_type_list($pagetype, $parentcontext, $currentcontext) { - return array('messages-*'=>get_string('page-message-x', 'message')); -} - /** * Get messages sent or/and received by the specified users. * Please note that this function return deleted messages too. @@ -1793,111 +1168,6 @@ function message_get_messages($useridto, $useridfrom = 0, $notifications = -1, $ return $messages; } - - - - - - -/** - * Determines if a user is permitted to send another user a private message. - * If no sender is provided then it defaults to the logged in user. - * - * @param object $recipient User object. - * @param object $sender User object. - * @return bool true if user is permitted, false otherwise. - */ -function message_can_post_message($recipient, $sender = null) { - global $USER, $DB; - - if (is_null($sender)) { - // The message is from the logged in user, unless otherwise specified. - $sender = $USER; - } - - if (!has_capability('moodle/site:sendmessage', context_system::instance(), $sender)) { - return false; - } - - // The recipient blocks messages from non-contacts and the - // sender isn't a contact. - if (message_is_user_non_contact_blocked($recipient, $sender)) { - return false; - } - - // The recipient has specifically blocked this sender. - if (message_is_user_blocked($recipient, $sender)) { - return false; - } - - return true; -} - -/** - * Checks if the recipient is allowing messages from users that aren't a - * contact. If not then it checks to make sure the sender is in the - * recipient's contacts. - * - * @param object $recipient User object. - * @param object $sender User object. - * @return bool true if $sender is blocked, false otherwise. - */ -function message_is_user_non_contact_blocked($recipient, $sender = null) { - global $USER, $DB; - - if (is_null($sender)) { - // The message is from the logged in user, unless otherwise specified. - $sender = $USER; - } - - $blockednoncontacts = get_user_preferences('message_blocknoncontacts', '', $recipient->id); - if (!empty($blockednoncontacts)) { - // Confirm the sender is a contact of the recipient. - $exists = $DB->record_exists('message_contacts', array('userid' => $recipient->id, 'contactid' => $sender->id)); - if ($exists) { - // All good, the recipient is a contact of the sender. - return false; - } else { - // Oh no, the recipient is not a contact. Looks like we can't send the message. - return true; - } - } - - return false; -} - -/** - * Checks if the recipient has specifically blocked the sending user. - * - * Note: This function will always return false if the sender has the - * readallmessages capability at the system context level. - * - * @param object $recipient User object. - * @param object $sender User object. - * @return bool true if $sender is blocked, false otherwise. - */ -function message_is_user_blocked($recipient, $sender = null) { - global $USER, $DB; - - if (is_null($sender)) { - // The message is from the logged in user, unless otherwise specified. - $sender = $USER; - } - - $systemcontext = context_system::instance(); - if (has_capability('moodle/site:readallmessages', $systemcontext, $sender)) { - return false; - } - - if ($contact = $DB->get_record('message_contacts', array('userid' => $recipient->id, 'contactid' => $sender->id))) { - if ($contact->blocked) { - return true; - } - } - - return false; -} - /** * Handles displaying processor settings in a fragment. * diff --git a/message/settings.html b/message/settings.html deleted file mode 100644 index 1f75ddb3c8d..00000000000 --- a/message/settings.html +++ /dev/null @@ -1,26 +0,0 @@ -
-
- - -
- - - - - - - - - - - - - - - - - - -
/>
/>

- -
diff --git a/message/tests/api_test.php b/message/tests/api_test.php index 32ab2b2bef8..5b7b0d8e192 100644 --- a/message/tests/api_test.php +++ b/message/tests/api_test.php @@ -331,4 +331,26 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->assertEquals(\core_message\api::count_unread_popup_notifications($recipient1->id), 3); $this->assertEquals(\core_message\api::count_unread_popup_notifications($recipient2->id), 5); } + + /** + * Test count_blocked_users. + * + */ + public function test_message_count_blocked_users() { + // Set this user as the admin. + $this->setAdminUser(); + + // Create users to add to the admin's contact list. + $user1 = $this->getDataGenerator()->create_user(); + $user2 = $this->getDataGenerator()->create_user(); + + $this->assertEquals(0, \core_message\api::count_blocked_users()); + + // Add 1 blocked and 1 normal contact to admin's contact list. + message_add_contact($user1->id); + message_add_contact($user2->id, 1); + + $this->assertEquals(0, \core_message\api::count_blocked_users($user2)); + $this->assertEquals(1, \core_message\api::count_blocked_users()); + } } \ No newline at end of file diff --git a/message/tests/events_test.php b/message/tests/events_test.php index 5a6843de43d..5fb32340106 100644 --- a/message/tests/events_test.php +++ b/message/tests/events_test.php @@ -126,7 +126,7 @@ class core_message_events_testcase extends advanced_testcase { $event = reset($events); $this->assertEmpty($event); // Make sure that we still have 1 blocked user. - $this->assertEquals(1, message_count_blocked_users()); + $this->assertEquals(1, \core_message\api::count_blocked_users()); // Now blocking a user that is not a contact. $sink->clear(); @@ -159,7 +159,7 @@ class core_message_events_testcase extends advanced_testcase { // Block the user. message_block_contact($user->id); // Make sure that we have 1 blocked user. - $this->assertEquals(1, message_count_blocked_users()); + $this->assertEquals(1, \core_message\api::count_blocked_users()); // Trigger and capture the event when unblocking a contact. $sink = $this->redirectEvents(); @@ -176,7 +176,7 @@ class core_message_events_testcase extends advanced_testcase { $this->assertEquals($url, $event->get_url()); // Make sure that we have no blocked users. - $this->assertEmpty(message_count_blocked_users()); + $this->assertEmpty(\core_message\api::count_blocked_users()); // Make sure that the contact unblocked event is not triggered again. $sink->clear(); @@ -186,7 +186,7 @@ class core_message_events_testcase extends advanced_testcase { $this->assertEmpty($event); // Make sure that we still have no blocked users. - $this->assertEmpty(message_count_blocked_users()); + $this->assertEmpty(\core_message\api::count_blocked_users()); } /** diff --git a/message/tests/messagelib_test.php b/message/tests/messagelib_test.php index cf50693078e..a03f5b78858 100644 --- a/message/tests/messagelib_test.php +++ b/message/tests/messagelib_test.php @@ -244,30 +244,6 @@ class core_message_messagelib_testcase extends advanced_testcase { $this->assertCount(1, $strangers); } - /** - * Test message_count_messages. - */ - public function test_message_count_messages() { - global $DB; - - // Create users to send and receive message. - $userfrom = $this->getDataGenerator()->create_user(); - $userto = $this->getDataGenerator()->create_user(); - - message_post_message($userfrom, $userto, 'Message 1', FORMAT_PLAIN); - message_post_message($userfrom, $userto, 'Message 2', FORMAT_PLAIN); - message_post_message($userto, $userfrom, 'Message 3', FORMAT_PLAIN); - - // Return 0 when no message. - $messages = array(); - $this->assertEquals(0, message_count_messages($messages, 'Test', 'Test')); - - // Check number of messages from userfrom and userto. - $messages = $this->messagesink->get_messages(); - $this->assertEquals(2, message_count_messages($messages, 'useridfrom', $userfrom->id)); - $this->assertEquals(1, message_count_messages($messages, 'useridfrom', $userto->id)); - } - /** * Test message_count_unread_messages. */ @@ -287,27 +263,6 @@ class core_message_messagelib_testcase extends advanced_testcase { $this->assertEquals(1, message_count_unread_messages($userto, $userfrom1)); } - /** - * Test message_count_blocked_users. - * - */ - public function test_message_count_blocked_users() { - // Set this user as the admin. - $this->setAdminUser(); - - // Create users to add to the admin's contact list. - $user1 = $this->getDataGenerator()->create_user(); - $user2 = $this->getDataGenerator()->create_user(); - - $this->assertEquals(0, message_count_blocked_users()); - - // Add 1 blocked and 1 normal contact to admin's contact list. - message_add_contact($user1->id); - message_add_contact($user2->id, 1); - - $this->assertEquals(0, message_count_blocked_users($user2)); - $this->assertEquals(1, message_count_blocked_users()); - } /** * Test message_add_contact. @@ -329,7 +284,7 @@ class core_message_messagelib_testcase extends advanced_testcase { $this->assertNotEmpty(message_get_contact($user1->id)); $this->assertNotEmpty(message_get_contact($user2->id)); $this->assertEquals(false, message_get_contact($user3->id)); - $this->assertEquals(1, message_count_blocked_users()); + $this->assertEquals(1, \core_message\api::count_blocked_users()); } /** @@ -366,11 +321,11 @@ class core_message_messagelib_testcase extends advanced_testcase { message_add_contact($user1->id); message_add_contact($user2->id); - $this->assertEquals(0, message_count_blocked_users()); + $this->assertEquals(0, \core_message\api::count_blocked_users()); // Block 1 user. message_block_contact($user2->id); - $this->assertEquals(1, message_count_blocked_users()); + $this->assertEquals(1, \core_message\api::count_blocked_users()); } @@ -389,11 +344,11 @@ class core_message_messagelib_testcase extends advanced_testcase { message_add_contact($user1->id); message_add_contact($user2->id, 1); // Add blocked contact. - $this->assertEquals(1, message_count_blocked_users()); + $this->assertEquals(1, \core_message\api::count_blocked_users()); // Unblock user. message_unblock_contact($user2->id); - $this->assertEquals(0, message_count_blocked_users()); + $this->assertEquals(0, \core_message\api::count_blocked_users()); } /** @@ -417,39 +372,6 @@ class core_message_messagelib_testcase extends advanced_testcase { $this->assertCount(2, message_search_users(0, 'user')); } - /** - * Test message_search. - */ - public function test_message_search() { - global $USER; - - // Set this user as the admin. - $this->setAdminUser(); - - // Create a user to add to the admin's contact list. - $user1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'user1')); - $user2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'user2')); - - // Send few messages, real (read). - message_post_message($user1, $USER, 'Message 1', FORMAT_PLAIN); - message_post_message($USER, $user1, 'Message 2', FORMAT_PLAIN); - message_post_message($USER, $user2, 'Message 3', FORMAT_PLAIN); - - $this->assertCount(2, message_search(array('Message'), true, false)); - $this->assertCount(3, message_search(array('Message'), true, true)); - - // Send fake message (not-read). - $this->send_fake_message($USER, $user1, 'Message 4'); - $this->send_fake_message($user1, $USER, 'Message 5'); - $this->assertCount(3, message_search(array('Message'), true, false)); - $this->assertCount(5, message_search(array('Message'), true, true)); - - // If courseid given then should be 0. - $this->assertEquals(false, message_search(array('Message'), true, true, '')); - $this->assertEquals(false, message_search(array('Message'), true, true, 2)); - $this->assertCount(5, message_search(array('Message'), true, true, SITEID)); - } - /** * The data provider for message_get_recent_conversations. * @@ -760,191 +682,4 @@ class core_message_messagelib_testcase extends advanced_testcase { } } } - - /** - * Test message_get_recent_notifications. - */ - public function test_message_get_recent_notifications() { - global $DB, $USER; - - // Set this user as the admin. - $this->setAdminUser(); - - // Create a user to send messages from. - $user1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'user1')); - - // Add two messages - will mark them as notifications later. - $m1 = message_post_message($user1, $USER, 'Message 1', FORMAT_PLAIN); - $m2 = message_post_message($user1, $USER, 'Message 2', FORMAT_PLAIN); - - // Mark the second message as a notification. - $updatemessage = new stdClass(); - $updatemessage->id = $m2; - $updatemessage->notification = 1; - $DB->update_record('message_read', $updatemessage); - - // Mark the first message as a notification and change the timecreated to 0. - $updatemessage->id = $m1; - $updatemessage->notification = 1; - $updatemessage->timecreated = 0; - $DB->update_record('message_read', $updatemessage); - - $notifications = message_get_recent_notifications($USER); - - // Get the messages. - $firstmessage = array_shift($notifications); - $secondmessage = array_shift($notifications); - - // Confirm that we have received the notifications with the maximum timecreated, rather than the max id. - $this->assertEquals('Message 2', $firstmessage->smallmessage); - $this->assertEquals('Message 1', $secondmessage->smallmessage); - } - - /** - * Test that message_can_post_message returns false if the sender does not have the - * moode/site:sendmessage capability. - */ - public function test_message_can_post_message_returns_false_without_capability() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - $context = context_system::instance(); - $roleid = $this->getDataGenerator()->create_role(); - $this->getDataGenerator()->role_assign($roleid, $sender->id, $context->id); - - assign_capability('moodle/site:sendmessage', CAP_PROHIBIT, $roleid, $context); - - $this->assertFalse(message_can_post_message($recipient, $sender)); - } - - /** - * Test that message_can_post_message returns false if the receiver only accepts - * messages from contacts and the sender isn't a contact. - */ - public function test_message_can_post_message_returns_false_non_contact_blocked() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - - set_user_preference('message_blocknoncontacts', true, $recipient); - - $this->assertFalse(message_can_post_message($recipient, $sender)); - } - - /** - * Test that message_can_post_message returns false if the receiver has blocked the - * sender from messaging them. - */ - public function test_message_can_post_message_returns_false_if_blocked() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - - $this->setUser($recipient); - message_block_contact($sender->id); - - $this->assertFalse(message_can_post_message($recipient, $sender)); - } - - /** - * Test that message_can_post_message returns false if the receiver has blocked the - * sender from messaging them. - */ - public function test_message_can_post_message_returns_true() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - - $this->assertTrue(message_can_post_message($recipient, $sender)); - } - - /** - * Test that message_is_user_non_contact_blocked returns false if the recipient allows - * messages from non-contacts. - */ - public function test_message_is_user_non_contact_blocked_false_without_preference() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - - set_user_preference('message_blocknoncontacts', false, $recipient); - - $this->assertFalse(message_is_user_non_contact_blocked($recipient, $sender)); - } - - /** - * Test that message_is_user_non_contact_blocked returns true if the recipient doesn't - * allow messages from non-contacts and the sender isn't a contact. - */ - public function test_message_is_user_non_contact_blocked_true_with_preference() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - - set_user_preference('message_blocknoncontacts', true, $recipient); - - $this->assertTrue(message_is_user_non_contact_blocked($recipient, $sender)); - } - - /** - * Test that message_is_user_non_contact_blocked returns false if the recipient doesn't - * allow messages from non-contacts but the sender is a contact. - */ - public function test_message_is_user_non_contact_blocked_false_with_if_contact() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - - $this->setUser($recipient); - set_user_preference('message_blocknoncontacts', true, $recipient); - message_add_contact($sender->id); - - $this->assertFalse(message_is_user_non_contact_blocked($recipient, $sender)); - } - - /** - * Test that message_is_user_blocked returns false if the sender is not a contact of - * the recipient. - */ - public function test_message_is_user_blocked_false_no_contact() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - - $this->assertFalse(message_is_user_blocked($recipient, $sender)); - } - - /** - * Test that message_is_user_blocked returns false if the sender is a contact that is - * blocked by the recipient but has the moodle/site:readallmessages capability. - */ - public function test_message_is_user_blocked_false_if_readallmessages() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - - $this->setUser($recipient); - message_block_contact($sender->id); - - $context = context_system::instance(); - $roleid = $this->getDataGenerator()->create_role(); - $this->getDataGenerator()->role_assign($roleid, $sender->id, $context->id); - - assign_capability('moodle/site:readallmessages', CAP_ALLOW, $roleid, $context); - - $this->assertFalse(message_is_user_blocked($recipient, $sender)); - } - - /** - * Test that message_is_user_blocked returns true if the sender is a contact that is - * blocked by the recipient and does not have the moodle/site:readallmessages capability. - */ - public function test_message_is_user_blocked_true_if_blocked() { - $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); - $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2')); - - $this->setUser($recipient); - message_block_contact($sender->id); - - $context = context_system::instance(); - $roleid = $this->getDataGenerator()->create_role(); - $this->getDataGenerator()->role_assign($roleid, $sender->id, $context->id); - - assign_capability('moodle/site:readallmessages', CAP_PROHIBIT, $roleid, $context); - - $this->assertTrue(message_is_user_blocked($recipient, $sender)); - } - - } diff --git a/message/upgrade.txt b/message/upgrade.txt index 8d46bab61db..98915ee5727 100644 --- a/message/upgrade.txt +++ b/message/upgrade.txt @@ -1,6 +1,30 @@ This files describes API changes in /message/ messaging system, information provided here is intended especially for developers. +=== 3.2 === + +* Removed all message_print_* functions as well as the files search.html, search_advanced.html and + send_form.php due to messaging UI rehaul. +* Deprecated the following functions as they are no longer used. + - message_get_course_contexts + - message_remove_url_params + - message_count_messages + - message_count_blocked_users + - message_contact_link + - message_get_recent_notifications + - message_history_link + - message_search + - message_shorten_message + - message_get_fragment + - message_get_history + - message_get_contact_add_remove_link + - message_get_contact_block_link + - message_mark_messages_read + - message_page_type_list + - message_can_post_message + - message_is_user_non_contact_blocked + - message_is_user_blocked + === 3.1 === * get_message_processors accepts an addition parameter for testing, which will just reset processor and exit. * Deprecated method message_current_user_is_involved() has been removed. -- 2.43.0