Some tidy up of some code and the information display in a discussion window.
The online status of the other user is now more accurate, and will not keep updating once the user has gone offline.
This commit is contained in:
@@ -29,7 +29,9 @@ $string['newsearch'] = 'New search';
|
||||
$string['nosearchresults'] = 'There were no results from your search';
|
||||
$string['nomessages'] = 'No messages waiting';
|
||||
$string['nomessagesfound'] = 'No messages were found';
|
||||
$string['offline'] = 'Offline';
|
||||
$string['offlinecontacts'] = 'Offline Contacts ($a)';
|
||||
$string['online'] = 'Online';
|
||||
$string['onlinecontacts'] = 'Online Contacts ($a)';
|
||||
$string['onlyfromme'] = 'Only messages from me';
|
||||
$string['onlymycourses'] = 'Only in my courses';
|
||||
|
||||
+16
-13
@@ -11,6 +11,9 @@ if (!isset($CFG->message_contacts_refresh)) { // Refresh the contacts list ever
|
||||
if (!isset($CFG->message_chat_refresh)) { // Look for new comments every 5 seconds
|
||||
$CFG->message_chat_refresh = 5;
|
||||
}
|
||||
if (!isset($CFG->message_offline_time)) {
|
||||
$CFG->message_offline_time = 300;
|
||||
}
|
||||
|
||||
|
||||
function message_print_contacts() {
|
||||
@@ -65,7 +68,7 @@ function message_print_contacts() {
|
||||
}
|
||||
/// link to remove from contact list
|
||||
$strcontact = message_contact_link($contact->id, 'remove', true);
|
||||
$strhistory = message_contact_link($contact->id, 'history', true);
|
||||
$strhistory = message_history_link($contact->id, 0, true, '', '', 'icon');
|
||||
|
||||
echo '<tr><td class="message_pix">';
|
||||
print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
|
||||
@@ -101,7 +104,7 @@ function message_print_contacts() {
|
||||
}
|
||||
/// link to remove from contact list
|
||||
$strcontact = message_contact_link($contact->id, 'remove', true);
|
||||
$strhistory = message_contact_link($contact->id, 'history', true);
|
||||
$strhistory = message_history_link($contact->id, 0, true, '', '', 'icon');
|
||||
|
||||
echo '<tr><td class="message_pix">';
|
||||
print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
|
||||
@@ -161,7 +164,7 @@ function message_print_contacts() {
|
||||
|
||||
$strcontact = message_contact_link($messageuser->useridfrom, 'add', true);
|
||||
$strblock = message_contact_link($messageuser->useridfrom, 'block', true);
|
||||
$strhistory = message_contact_link($messageuser->useridfrom, 'history', true);
|
||||
$strhistory = message_history_link($messageuser->useridfrom, 0, true, '', '', 'icon');
|
||||
|
||||
echo '<tr><td class="message_pix">';
|
||||
print_user_picture($messageuser->useridfrom, SITEID, $messageuser->picture, 20, false, true, 'userwindow');
|
||||
@@ -347,6 +350,7 @@ function message_print_search_results($frm) {
|
||||
$strcontact = message_contact_link($user->id, 'add', true);
|
||||
$strblock = message_contact_link($user->id, 'block', true);
|
||||
}
|
||||
$strhistory = message_history_link($user->id, 0, true, '', '', 'icon');
|
||||
|
||||
echo '<tr><td class="message_pix">';
|
||||
print_user_picture($user->id, SITEID, $user->picture, 20, false, true, 'userwindow');
|
||||
@@ -359,6 +363,7 @@ function message_print_search_results($frm) {
|
||||
|
||||
echo '<td class="message_link">'.$strcontact.'</td>';
|
||||
echo '<td class="message_link">'.$strblock.'</td>';
|
||||
echo '<td class="message_link">'.$strhistory.'</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
@@ -471,7 +476,9 @@ function message_print_search_results($frm) {
|
||||
message_print_user($userto, $tocontact, $toblocked);
|
||||
echo '</td>';
|
||||
echo '<td class="message_summary">'.message_get_fragment($message->message, $keywords);
|
||||
echo '<br /><div class="message_summary_link">'.message_history_link($message->useridto, $message->useridfrom, true, $keywordstring, $datestring, $strcontext).'</div>';
|
||||
echo '<br /><div class="message_summary_link">';
|
||||
message_history_link($message->useridto, $message->useridfrom, true, $keywordstring, $datestring, $strcontext);
|
||||
echo '</div>';
|
||||
echo '</td>';
|
||||
echo '<td class="message_date">'.userdate($message->timecreated, $dateformat).'</td>';
|
||||
echo "</tr>\n";
|
||||
@@ -527,7 +534,7 @@ function message_print_user ($user=false, $iscontact=false, $isblocked=false) {
|
||||
|
||||
|
||||
/// linktype can be: add, remove, block, unblock
|
||||
function message_contact_link($userid, $linktype='add', $return=false) {
|
||||
function message_contact_link($userid, $linktype='add', $return=false, $script="index.php?tab=contacts") {
|
||||
global $USER, $CFG;
|
||||
|
||||
static $str;
|
||||
@@ -537,31 +544,27 @@ function message_contact_link($userid, $linktype='add', $return=false) {
|
||||
$str->unblockcontact = get_string('unblockcontact', 'message');
|
||||
$str->removecontact = get_string('removecontact', 'message');
|
||||
$str->addcontact = get_string('addcontact', 'message');
|
||||
$str->messagehistory = get_string('messagehistory', 'message');
|
||||
}
|
||||
|
||||
switch ($linktype) {
|
||||
case 'history':
|
||||
$output = '<a target="message_history_'.$userid.'" title="'.$str->messagehistory.'" href="'.$CFG->wwwroot.'/message/history.php?user1='.$userid.'" onclick="return openpopup(\'/message/history.php?user1='.$userid.'\', \'message_history_'.$userid.'\', \'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500\', 0);"><img src="'.$CFG->pixpath.'/t/log.gif" height="11" width="11" border="0"></a>';
|
||||
break;
|
||||
case 'block':
|
||||
$output = '<a href="index.php?tab=contacts&blockcontact='.$userid.
|
||||
$output = '<a target="message" href="'.$script.'&blockcontact='.$userid.
|
||||
'&sesskey='.$USER->sesskey.'" title="'.$str->blockcontact.'">'.
|
||||
'<img src="'.$CFG->pixpath.'/t/go.gif" height="11" width="11" border="0"></a>';
|
||||
break;
|
||||
case 'unblock':
|
||||
$output = '<a href="index.php?tab=contacts&unblockcontact='.$userid.
|
||||
$output = '<a target="message" href="'.$script.'&unblockcontact='.$userid.
|
||||
'&sesskey='.$USER->sesskey.'" title="'.$str->unblockcontact.'">'.
|
||||
'<img src="'.$CFG->pixpath.'/t/stop.gif" height="11" width="11" border="0"></a>';
|
||||
break;
|
||||
case 'remove':
|
||||
$output = '<a href="index.php?tab=contacts&removecontact='.$userid.
|
||||
$output = '<a target="message" href="'.$script.'&removecontact='.$userid.
|
||||
'&sesskey='.$USER->sesskey.'" title="'.$str->removecontact.'">'.
|
||||
'<img src="'.$CFG->pixpath.'/t/user.gif" height="11" width="11" border="0"></a>';
|
||||
break;
|
||||
case 'add':
|
||||
default:
|
||||
$output = '<a href="index.php?tab=contacts&addcontact='.$userid.
|
||||
$output = '<a target="message" href="'.$script.'&addcontact='.$userid.
|
||||
'&sesskey='.$USER->sesskey.'" title="'.$str->addcontact.'">'.
|
||||
'<img src="'.$CFG->pixpath.'/t/usernot.gif" height="11" width="11" border="0"></a>';
|
||||
|
||||
|
||||
+70
-12
@@ -12,11 +12,35 @@
|
||||
$message = optional_param('message', '', PARAM_CLEAN);
|
||||
$format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
|
||||
|
||||
$addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a contact
|
||||
$removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact
|
||||
$blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact
|
||||
$unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact
|
||||
|
||||
/// Check the user we are talking to is valid
|
||||
if (! $user = get_record("user", "id", $userid)) {
|
||||
error("User ID was incorrect");
|
||||
}
|
||||
|
||||
/// Possibly change some contacts if requested
|
||||
|
||||
if ($addcontact and confirm_sesskey()) {
|
||||
add_to_log(SITEID, 'message', 'add contact', 'history.php?user1='.$addcontact.'&user2='.$USER->id, $addcontact);
|
||||
message_add_contact($addcontact);
|
||||
}
|
||||
if ($removecontact and confirm_sesskey()) {
|
||||
add_to_log(SITEID, 'message', 'remove contact', 'history.php?user1='.$removecontact.'&user2='.$USER->id, $removecontact);
|
||||
message_remove_contact($removecontact);
|
||||
}
|
||||
if ($blockcontact and confirm_sesskey()) {
|
||||
add_to_log(SITEID, 'message', 'block contact', 'history.php?user1='.$blockcontact.'&user2='.$USER->id, $blockcontact);
|
||||
message_block_contact($blockcontact);
|
||||
}
|
||||
if ($unblockcontact and confirm_sesskey()) {
|
||||
add_to_log(SITEID, 'message', 'unblock contact', 'history.php?user1='.$unblockcontact.'&user2='.$USER->id, $unblockcontact);
|
||||
message_unblock_contact($unblockcontact);
|
||||
}
|
||||
|
||||
/// By default, print frameset to contain all the various panes
|
||||
if (!$frame) {
|
||||
$USER->message_user_refresh[$user->id] = time();
|
||||
@@ -41,26 +65,47 @@
|
||||
switch ($frame) { /// Put data into all the frames
|
||||
|
||||
case 'info': /// Print the top frame with information and links
|
||||
print_header();
|
||||
$THEME->body = $THEME->cellcontent2;
|
||||
print_header('','','','','',false,'','',false,'leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"');
|
||||
echo '<table width="100%" cellpadding="0" cellspacing="0"><tr>';
|
||||
echo '<td>'.print_user_picture($user->id, SITEID, $user->picture, true, true, true, 'userwindow').'</td>';
|
||||
echo '<td>';
|
||||
echo '<td width="100">';
|
||||
echo print_user_picture($user->id, SITEID, $user->picture, true, true, true, 'userwindow').'</td>';
|
||||
echo '<td valign="middle" align="center">';
|
||||
|
||||
echo fullname($user);
|
||||
echo '<br /><font size="1">';
|
||||
echo '<br /><font size="1">'; /// Print login status of this user
|
||||
if ($user->lastaccess) {
|
||||
$datestring = get_string('ago', 'message', format_time(time() - $user->lastaccess));
|
||||
if (time() - $user->lastaccess > $CFG->message_offline_time) {
|
||||
echo get_string('offline', 'message');
|
||||
} else {
|
||||
echo get_string("lastaccess").":".get_string('ago', 'message', format_time(time() - $user->lastaccess));
|
||||
}
|
||||
} else {
|
||||
$datestring = get_string("never");
|
||||
echo get_string("lastaccess").":". get_string("never");
|
||||
}
|
||||
echo get_string("lastaccess").":", $datestring;
|
||||
echo '</font>';
|
||||
echo '<br />';
|
||||
message_history_link($user->id);
|
||||
echo '</td>';
|
||||
echo '</tr></table>';
|
||||
echo '<div class="message_users">';
|
||||
if ($contact = get_record('message_contacts', 'userid', $USER->id, 'contactid', $user->id)) {
|
||||
if ($contact->blocked) {
|
||||
message_contact_link($user->id, 'add', false, 'user.php?frame=info'); echo " ";
|
||||
message_contact_link($user->id, 'unblock', false, 'user.php?frame=info'); echo " ";
|
||||
} else {
|
||||
message_contact_link($user->id, 'remove', false, 'user.php?frame=info'); echo " ";
|
||||
message_contact_link($user->id, 'block', false, 'user.php?frame=info'); echo " ";
|
||||
}
|
||||
} else {
|
||||
message_contact_link($user->id, 'add', false, 'user.php?frame=info'); echo " ";
|
||||
message_contact_link($user->id, 'block', false, 'user.php?frame=info'); echo " ";
|
||||
}
|
||||
message_history_link($user->id, 0, false, '', '', 'icon');
|
||||
echo '</div>';
|
||||
|
||||
echo '</td></tr></table>';
|
||||
|
||||
echo '</table></table></body>'; // Close possible theme tables off
|
||||
|
||||
$USER->message_user_refresh[$user->id] = time();
|
||||
$USER->message_user_refresh[$user->id] = time(); // Remember this update
|
||||
break;
|
||||
|
||||
case 'messages': /// Print the main frame containing the current chat
|
||||
@@ -110,7 +155,20 @@
|
||||
echo "parent.messages.scroll(1,5000000);\n";
|
||||
echo "</script>\n\n";
|
||||
}
|
||||
if ($user->lastaccess > $USER->message_user_refresh[$user->id]) {
|
||||
|
||||
// Update the info pane, but only if the data there is getting too old
|
||||
$timenow = time();
|
||||
if ($timenow - $user->lastaccess > $CFG->message_offline_time) { // Offline
|
||||
if ($timenow - $USER->message_user_refresh[$user->id] < 30) { // It's just happened so refresh
|
||||
$refreshinfo = true;
|
||||
}
|
||||
|
||||
} else { // Online
|
||||
if ($timenow - $USER->message_user_refresh[$user->id] > 30) { // Been a while
|
||||
$refreshinfo = true;
|
||||
}
|
||||
}
|
||||
if (!empty($refreshinfo)) {
|
||||
echo '<script language="Javascript">';
|
||||
echo "parent.info.document.location.replace('$CFG->wwwroot/message/user.php?id=$user->id&frame=info');\n";
|
||||
echo "</script>\n\n";
|
||||
|
||||
Reference in New Issue
Block a user