mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-16268 User-User send messages now use new messaging system.
This commit is contained in:
parent
70d91d90ab
commit
1c50df9f24
@ -165,6 +165,7 @@
|
||||
|
||||
// Install core message providers
|
||||
message_update_providers();
|
||||
message_update_providers('message');
|
||||
|
||||
/// This is used to handle any settings that must exist in $CFG but which do not exist in
|
||||
/// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
|
||||
@ -332,6 +333,7 @@
|
||||
|
||||
// Update core message providers
|
||||
message_update_providers();
|
||||
message_update_providers('message');
|
||||
|
||||
if (set_config("version", $version)) {
|
||||
remove_dir($CFG->dataroot . '/cache', true); // flush cache
|
||||
|
@ -83,6 +83,6 @@ $string['noframesjs'] = 'No frames and JavaScript';
|
||||
$string['providerstag'] = 'Source: ';
|
||||
$string['processortag'] = 'Destination: ';
|
||||
$string['cannotsavemessageprefs'] = 'Could not save user messaging preferences';
|
||||
|
||||
$string['messageprovider:instantmessage'] = 'User to User Instant Message';
|
||||
|
||||
?>
|
||||
|
@ -57,7 +57,7 @@ function message_send_handler($eventdata){
|
||||
} else {
|
||||
$userstate = 'loggedin';
|
||||
}
|
||||
|
||||
|
||||
/// Create the message object
|
||||
$savemessage = new object();
|
||||
$savemessage->useridfrom = $eventdata->userfrom->id;
|
||||
@ -95,9 +95,8 @@ function message_send_handler($eventdata){
|
||||
|
||||
} else { // Process the message
|
||||
/// Store unread message just in case we can not send it
|
||||
$savemessage->id = $DB->insert_record('message', $savemessage);
|
||||
|
||||
|
||||
$savemessage->id = $DB->insert_record('message', $savemessage);
|
||||
|
||||
/// Try to deliver the message to each processor
|
||||
$processorlist = explode(',', $processor);
|
||||
foreach ($processorlist as $procname) {
|
||||
|
@ -197,7 +197,7 @@
|
||||
$options = new object();
|
||||
$options->para = false;
|
||||
$options->newlines = true;
|
||||
|
||||
|
||||
$params = array('uid1'=>$USER->id ,'userid1'=>$userid, 'start1'=>$start, 'uid2'=>$USER->id ,'userid2'=>$userid, 'start2'=>$start);
|
||||
if ($newonly) {
|
||||
$lastsql1 = " AND timecreated > :last1";
|
||||
@ -209,6 +209,7 @@
|
||||
$lastsql2 = "";
|
||||
}
|
||||
|
||||
//LR: change here the way to
|
||||
if ($messages = $DB->get_records_select('message_read', "(useridto = :uid1 AND useridfrom = :userid1 AND timeread > :start1 $lastsql1) OR (useridto = :userid2 AND useridfrom = :uid2 AND timeread > :start2 $lastsql2)", $params)) {
|
||||
foreach ($messages as $message) {
|
||||
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
|
||||
@ -219,7 +220,11 @@
|
||||
$fullname = $userfullname;
|
||||
}
|
||||
|
||||
$printmessage = format_text($message->message, $message->format, $options, 0);
|
||||
if ($message->format == FORMAT_HTML){
|
||||
$printmessage = format_text($message->fullmessagehtml, $message->format, $options, 0);
|
||||
} else{
|
||||
$printmessage = format_text($message->fullmessage, $message->format, $options, 0);
|
||||
}
|
||||
$printmessage = '<div class="message other"><span class="author">'.$fullname.'</span> '.
|
||||
'<span class="time">['.$time.']</span>: '.
|
||||
'<span class="content">'.$printmessage.'</span></div>';
|
||||
@ -236,8 +241,12 @@
|
||||
if ($messages = $DB->get_records_select('message', "useridto = :userid1 AND useridfrom = :uid1 $lastsql1", $params)) {
|
||||
foreach ($messages as $message) {
|
||||
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
|
||||
|
||||
$printmessage = format_text($message->message, $message->format, $options, 0);
|
||||
|
||||
if ($message->format == FORMAT_HTML){
|
||||
$printmessage = format_text($message->fullmessagehtml, $message->format, $options, 0);
|
||||
} else{
|
||||
$printmessage = format_text($message->fullmessage, $message->format, $options, 0);
|
||||
}
|
||||
$printmessage = '<div class="message other"><span class="author">'.$mefullname.'</span> '.
|
||||
'<span class="time">['.$time.']</span>: '.
|
||||
'<span class="content">'.$printmessage.'</span></div>';
|
||||
@ -250,7 +259,35 @@
|
||||
$allmessages[$sortkey] = $printmessage;
|
||||
}
|
||||
}
|
||||
|
||||
/*Get still to be read message, use message/lib.php funtion*/
|
||||
$messages = message_get_popup_messages($USER->id, $userid);
|
||||
if ($messages) {
|
||||
foreach ($messages as $message) {
|
||||
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
|
||||
|
||||
if ($message->format == FORMAT_HTML){
|
||||
$printmessage = format_text($message->fullmessagehtml, $message->format, $options, 0);
|
||||
} else{
|
||||
$printmessage = format_text($message->fullmessage, $message->format, $options, 0);
|
||||
}
|
||||
$printmessage = '<div class="message other"><span class="author">'.$userfullname.'</span> '.
|
||||
'<span class="time">['.$time.']</span>: '.
|
||||
'<span class="content">'.$printmessage.'</span></div>';
|
||||
$i=0;
|
||||
$sortkey = $message->timecreated."$i"; // we need string bacause we would run out of int range
|
||||
while (array_key_exists($sortkey, $allmessages)) {
|
||||
$i++;
|
||||
$sortkey = $message->timecreated."$i";
|
||||
}
|
||||
$allmessages[$sortkey] = $printmessage;
|
||||
|
||||
if ($message->timecreated < $start) {
|
||||
$start = $message->timecreated; // move start back so that we see all current history
|
||||
}
|
||||
}
|
||||
$playbeep = true;
|
||||
}
|
||||
/* old code, to be deleted
|
||||
if ($messages = $DB->get_records_select('message', "useridto = :uid2 AND useridfrom = userid2 $lastsql2", $params)) {
|
||||
foreach ($messages as $message) {
|
||||
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
|
||||
@ -280,7 +317,7 @@
|
||||
}
|
||||
}
|
||||
$playbeep = true;
|
||||
}
|
||||
}*/
|
||||
|
||||
krsort($allmessages);
|
||||
|
||||
|
@ -142,7 +142,7 @@ if ( ($form = data_submitted()) && confirm_sesskey()) {
|
||||
$preferences = new object();
|
||||
|
||||
//get the message general preferences
|
||||
$preferences->showmessagewindow = get_user_preferences( 'message_showmessagewindow', '', $user->id);
|
||||
$preferences->showmessagewindow = get_user_preferences( 'message_showmessagewindow', 1, $user->id);
|
||||
$preferences->blocknoncontacts = get_user_preferences( 'message_blocknoncontacts', '', $user->id);
|
||||
$preferences->beepnewmessage = get_user_preferences( 'message_beepnewmessage', '', $user->id);
|
||||
$preferences->noframesjs = get_user_preferences( 'message_noframesjs', '', $user->id);
|
||||
|
114
message/lib.php
114
message/lib.php
@ -946,92 +946,19 @@ function message_format_message(&$message, &$user, $format='', $keywords='', $cl
|
||||
*/
|
||||
function message_post_message($userfrom, $userto, $message, $format, $messagetype) {
|
||||
global $CFG, $SITE, $USER, $DB;
|
||||
|
||||
/// Set up current language to suit the receiver of the message
|
||||
$savelang = $USER->lang;
|
||||
|
||||
if (!empty($userto->lang)) {
|
||||
$USER->lang = $userto->lang;
|
||||
}
|
||||
|
||||
$eventdata = new object();
|
||||
$eventdata->modulename = 'moodle';
|
||||
$eventdata->component = 'message';
|
||||
$eventdata->name = 'instantmessage';
|
||||
$eventdata->userfrom = $userfrom;
|
||||
$eventdata->userto = $userto;
|
||||
$eventdata->subject = "MESSAGE";
|
||||
$eventdata->subject = "IM";
|
||||
$eventdata->fullmessage = $message;
|
||||
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
||||
$eventdata->fullmessagehtml = '';
|
||||
$eventdata->smallmessage = '';
|
||||
events_trigger('message_send', $eventdata);
|
||||
return events_trigger('message_send', $eventdata);
|
||||
|
||||
|
||||
/// Save the new message in the database
|
||||
|
||||
$savemessage = NULL;
|
||||
$savemessage->useridfrom = $userfrom->id;
|
||||
$savemessage->useridto = $userto->id;
|
||||
$savemessage->message = $message;
|
||||
$savemessage->format = $format;
|
||||
$savemessage->timecreated = time();
|
||||
$savemessage->messagetype = 'direct';
|
||||
|
||||
if ($CFG->messaging) {
|
||||
//if (!$savemessage->id = $DB->insert_record('message', $savemessage)) {
|
||||
// return false;
|
||||
//}
|
||||
$emailforced = false;
|
||||
} else { // $CFG->messaging is not on, we need to force sending of emails
|
||||
$emailforced = true;
|
||||
$savemessage->id = true;
|
||||
}
|
||||
|
||||
/// Check to see if anything else needs to be done with it
|
||||
|
||||
$preference = (object)get_user_preferences(NULL, NULL, $userto->id);
|
||||
|
||||
if ($emailforced || (!isset($preference->message_emailmessages) || $preference->message_emailmessages)) { // Receiver wants mail forwarding
|
||||
if (!isset($preference->message_emailtimenosee)) {
|
||||
$preference->message_emailtimenosee = 10;
|
||||
}
|
||||
if (!isset($preference->message_emailformat)) {
|
||||
$preference->message_emailformat = FORMAT_HTML;
|
||||
}
|
||||
if ($emailforced || (time() - $userto->lastaccess) > ((int)$preference->message_emailtimenosee * 60)) { // Long enough
|
||||
|
||||
$tagline = get_string('emailtagline', 'message', $SITE->shortname);
|
||||
|
||||
$messagesubject = preg_replace('/\s+/', ' ', strip_tags($message)); // make sure it's all on one line
|
||||
$messagesubject = message_shorten_message($messagesubject, 30).'...';
|
||||
|
||||
$messagetext = format_text_email($message, $format).
|
||||
"\n\n--\n".$tagline."\n"."$CFG->wwwroot/message/index.php?popup=1";
|
||||
|
||||
if (isset($preference->message_emailformat) and $preference->message_emailformat == FORMAT_HTML) {
|
||||
$messagehtml = format_text($message, $format);
|
||||
// MDL-10294, do not print link if messaging is disabled
|
||||
if ($CFG->messaging) {
|
||||
$messagehtml .= '<hr /><p><a href="'.$CFG->wwwroot.'/message/index.php?popup=1">'.$tagline.'</a></p>';
|
||||
}
|
||||
} else {
|
||||
$messagehtml = NULL;
|
||||
}
|
||||
|
||||
if (!empty($preference->message_emailaddress)) {
|
||||
$userto->email = $preference->message_emailaddress; // Use custom messaging address
|
||||
}
|
||||
|
||||
if (email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml)) {
|
||||
$CFG->messagewasjustemailed = true;
|
||||
}
|
||||
|
||||
sleep(3);
|
||||
}
|
||||
}
|
||||
|
||||
$USER->lang = $savelang; // restore original language
|
||||
|
||||
return $savemessage->id;
|
||||
}
|
||||
|
||||
|
||||
@ -1091,4 +1018,37 @@ function message_print_contactlist_user($contact, $incontactlist = true){
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
function message_get_popup_messages($destuserid, $fromuserid=NULL){
|
||||
global $DB;
|
||||
|
||||
$processor = $DB->get_record('message_processors', array('name' => 'popup'));
|
||||
|
||||
$messagesproc = $DB->get_records('message_working', array('processorid'=>$processor->id));
|
||||
|
||||
//for every message to process check if it's for current user and process
|
||||
$messages = array();
|
||||
foreach ($messagesproc as $msgp){
|
||||
$query = array('id'=>$msgp->unreadmessageid, 'useridto'=>$destuserid);
|
||||
if ($fromuserid){
|
||||
$query['useridfrom'] = $fromuserid;
|
||||
}
|
||||
if ($message = $DB->get_record('message', $query)){
|
||||
$messages[] = $message;
|
||||
/// Move the entry to the other table
|
||||
$message->timeread = time();
|
||||
$messageid = $message->id;
|
||||
unset($message->id);
|
||||
|
||||
//delete what we've processed and check if can move message
|
||||
$DB->delete_records('message_working', array('id' => $msgp->id));
|
||||
if ( $DB->count_records('message_working', array('unreadmessageid'=>$messageid)) == 0){
|
||||
if ($DB->insert_record('message_read', $message)) {
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $messages;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* This script returns the popup messages that need to be shown.
|
||||
* FIXME: this is just a temp script to show how it could be done
|
||||
* (this should be integrated with my new YUI interface)
|
||||
*
|
||||
* @author Luis Rodrigues
|
||||
* @version $Id$
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package
|
||||
*/
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once($CFG->dirroot.'/user/profile/lib.php');
|
||||
|
||||
|
||||
$processor = $DB->get_record('message_processors', array('name' => 'popup'));
|
||||
|
||||
$messagesproc = $DB->get_records('message_working', array('processorid'=>$processor->id));
|
||||
|
||||
//for every message to process check if it's for current user and process
|
||||
foreach ($messagesproc as $msgp){
|
||||
$message = $DB->get_record('message', array('id'=>$msgp->unreadmessageid, 'useridto'=>$USER->id));
|
||||
if (!$message){
|
||||
continue;
|
||||
}
|
||||
|
||||
//this is the show for now --> SHOULD BE SOMETHING ELSE...
|
||||
echo "Usr from: ".$message->useridfrom." to: ".$message->useridto." subject:".$message->subject."<br>";
|
||||
|
||||
/// Move the entry to the other table
|
||||
$message->timeread = time();
|
||||
$messageid = $message->id;
|
||||
unset($message->id);
|
||||
|
||||
//delete what we've processed and check if can move message
|
||||
$DB->delete_records('message_working', array('id' => $msgp->id));
|
||||
if ( $DB->count_records('message_working', array('unreadmessageid'=>$messageid)) == 0){
|
||||
if ($DB->insert_record('message_read', $message)) {
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,6 +1,7 @@
|
||||
<?php // $Id$
|
||||
|
||||
require('../config.php');
|
||||
require('lib.php');
|
||||
|
||||
define('MESSAGE_DEFAULT_REFRESH', 5);
|
||||
|
||||
@ -47,6 +48,38 @@
|
||||
@ob_implicit_flush(true);
|
||||
@ob_end_flush();
|
||||
|
||||
/*Get still to be read message, use message/lib.php funtion*/
|
||||
$messages = message_get_popup_messages($USER->id, $userid);
|
||||
if ($messages ) {
|
||||
foreach ($messages as $message) {
|
||||
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
|
||||
|
||||
$options = new object();
|
||||
$options->para = false;
|
||||
$options->newlines = true;
|
||||
if ($message->format == FORMAT_HTML){
|
||||
$printmessage = format_text($message->fullmessagehtml, $message->format, $options, 0);
|
||||
} else{
|
||||
$printmessage = format_text($message->fullmessage, $message->format, $options, 0);
|
||||
}
|
||||
$printmessage = '<div class="message other"><span class="author">'.s($userfullname).'</span> '.
|
||||
'<span class="time">['.$time.']</span>: '.
|
||||
'<span class="content">'.$printmessage.'</span></div>';
|
||||
$printmessage = addslashes_js($printmessage); // So Javascript can write it
|
||||
echo "parent.messages.document.write('".$printmessage."');\n";
|
||||
}
|
||||
if (get_user_preferences('message_beepnewmessage', 0)) {
|
||||
$playbeep = true;
|
||||
}
|
||||
echo 'parent.messages.scroll(1,5000000);'."\n";
|
||||
echo 'parent.send.focus();'."\n";
|
||||
$wait = MESSAGE_DEFAULT_REFRESH;
|
||||
} else {
|
||||
if ($wait < 300) { // Until the wait is five minutes
|
||||
$wait = ceil(1.2 * (float)$wait); // Exponential growth
|
||||
}
|
||||
}
|
||||
/* old code to be deleted
|
||||
if ($messages = $DB->get_records('message', array('useridto'=>$USER->id, 'useridfrom'=>$userid), 'timecreated')) {
|
||||
foreach ($messages as $message) {
|
||||
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
|
||||
@ -80,7 +113,7 @@
|
||||
$wait = ceil(1.2 * (float)$wait); // Exponential growth
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
echo '-->'."\n";
|
||||
echo '</script>'."\n";
|
||||
echo '</head>'."\n";
|
||||
|
Loading…
x
Reference in New Issue
Block a user