"MDL-14651, update chat module to work in new API"
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
<?php
|
||||
|
||||
function microtime_float(){
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
return ((float)$usec+(float)$sec);
|
||||
}
|
||||
|
||||
function format_user_list($data, $course) {
|
||||
global $CFG, $DB;
|
||||
global $CFG, $DB, $COURSE;
|
||||
$users = array();
|
||||
foreach($data as $v){
|
||||
$user['name'] = fullname($v);
|
||||
$user['url'] = $CFG->wwwroot.'/user/view.php?id='.$v->id.'&course='.$course->id;
|
||||
$user['picture'] = print_user_picture($v->id, 0, $v->picture, false, true, false);
|
||||
$user['picture'] = print_user_picture($v->id, $COURSE->id, $v->picture, false, true, false);
|
||||
$user['id'] = $v->id;
|
||||
$users[] = $user;
|
||||
}
|
||||
|
||||
+14
-12
@@ -57,8 +57,6 @@ $str_userlist = get_string('userlist', 'chat');
|
||||
$PAGE->set_generaltype('popup');
|
||||
$PAGE->set_title('Chat');
|
||||
|
||||
$PAGE->requires->yui_lib('dom');
|
||||
$PAGE->requires->yui_lib('element');
|
||||
$PAGE->requires->yui_lib('dragdrop');
|
||||
$PAGE->requires->yui_lib('resize');
|
||||
$PAGE->requires->yui_lib('layout');
|
||||
@@ -72,13 +70,17 @@ $PAGE->requires->data_for_js('chat_lang', array('send'=>$str_send, 'sending'=>$s
|
||||
$PAGE->requires->js('mod/chat/gui_ajax/script.js');
|
||||
$PAGE->add_body_class('yui-skin-sam');
|
||||
|
||||
$PAGE->requires->css('lib/yui/reset-fonts-grids/reset-fonts-grids.css');
|
||||
$PAGE->requires->css('lib/yui/resize/assets/skins/sam/resize.css');
|
||||
$PAGE->requires->css('lib/yui/layout/assets/skins/sam/layout.css');
|
||||
$PAGE->requires->css('lib/yui/button/assets/skins/sam/button.css');
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo "<style type='text/css'> #listing a{text-decoration:none;color:gray} #listing a:hover {text-decoration:underline;color:white;background:blue} #listing{padding: .5em}</style>";
|
||||
echo <<<STY
|
||||
<style type='text/css'>
|
||||
#messageslist{list-style-type:none;padding:0;margin:0}
|
||||
#listing a{text-decoration:none;color:gray}
|
||||
#listing a:hover {text-decoration:underline;color:white;background:blue}
|
||||
#listing{padding: .5em}
|
||||
h2{margin:0}
|
||||
</style>
|
||||
STY;
|
||||
|
||||
echo $OUTPUT->heading($str_title,1);
|
||||
echo <<<DIVS
|
||||
<div id="chat_header">
|
||||
@@ -88,14 +90,14 @@ echo <<<DIVS
|
||||
<input type="button" id="btn_send" value="$str_send" />
|
||||
</div>
|
||||
<div id="chat_user_list">
|
||||
<ul id="listing">
|
||||
</ul>
|
||||
<ul id="listing">
|
||||
</ul>
|
||||
</div>
|
||||
<div id="chat_options">
|
||||
</div>
|
||||
<div id="chat_panel">
|
||||
<ul id="msg_list">
|
||||
<ul>
|
||||
<ul id="messageslist">
|
||||
<ul>
|
||||
</div>
|
||||
<div id="notify">
|
||||
</div>
|
||||
|
||||
+44
-42
@@ -25,7 +25,7 @@ Event.onDOMReady(function() {
|
||||
layout.render();
|
||||
Event.on('btn_send', 'click', function(ev) {
|
||||
Event.stopEvent(ev);
|
||||
send_msg();
|
||||
send_message();
|
||||
});
|
||||
Event.on('chat_panel', 'mouseover', function(ev) {
|
||||
Event.stopEvent(ev);
|
||||
@@ -35,15 +35,27 @@ Event.onDOMReady(function() {
|
||||
Event.stopEvent(ev);
|
||||
scrollable = true;
|
||||
});
|
||||
var key_send = new YAHOO.util.KeyListener(document, { keys:13 }, {fn:send_msg, correctScope:true });
|
||||
var key_send = new YAHOO.util.KeyListener(document, { keys:13 }, {fn:send_message, correctScope:true });
|
||||
key_send.enable();
|
||||
document.getElementById('input_msgbox').focus();
|
||||
document.title = chat_cfg.chatroom_name;
|
||||
|
||||
// done build layout
|
||||
var transaction = YAHOO.util.Connect.asyncRequest('POST', "update.php?chat_sid="+chat_cfg.sid+"&chat_init=1", init_cb, null);
|
||||
|
||||
this.cb = {
|
||||
success: function(o){
|
||||
if(o.responseText){
|
||||
var data = YAHOO.lang.JSON.parse(o.responseText);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (data.users) {
|
||||
update_users(data.users);
|
||||
}
|
||||
}
|
||||
}
|
||||
var transaction = YAHOO.util.Connect.asyncRequest('POST', "update.php?chat_sid="+chat_cfg.sid+"&chat_init=1", this.cb, null);
|
||||
interval = setInterval(function(){
|
||||
update_info();
|
||||
update_messages();
|
||||
}, chat_cfg.timer);
|
||||
});
|
||||
})();
|
||||
@@ -64,21 +76,38 @@ function talkto(name) {
|
||||
msg.value = "To "+name+": ";
|
||||
msg.focus();
|
||||
}
|
||||
function send_msg() {
|
||||
|
||||
function send_message() {
|
||||
var msg = document.getElementById('input_msgbox').value;
|
||||
var el_send = document.getElementById('btn_send');
|
||||
if (!msg) {
|
||||
alert('null?');
|
||||
alert('Empty message not allowed');
|
||||
return;
|
||||
}
|
||||
var url = 'post.php?chat_sid='+chat_cfg.sid;
|
||||
el_send.value = chat_lang.sending;
|
||||
var a = YAHOO.util.Connect.asyncRequest('POST', url, send_cb, "chat_message="+msg);
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', url, send_cb, "chat_message="+msg);
|
||||
}
|
||||
function send_beep(id){
|
||||
var url = 'post.php?chat_sid='+chat_cfg.sid;
|
||||
var a = YAHOO.util.Connect.asyncRequest('POST', url, send_cb, "beep="+id);
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', url, send_cb, "beep="+id);
|
||||
}
|
||||
|
||||
var send_cb = {
|
||||
success: function(o) {
|
||||
if(o.responseText == 200){
|
||||
document.getElementById('btn_send').value = chat_lang.send;
|
||||
document.getElementById('input_msgbox').value = '';
|
||||
}
|
||||
clearInterval(interval)
|
||||
update_messages();
|
||||
interval = setInterval(function(){
|
||||
update_messages();
|
||||
}, chat_cfg.timer);
|
||||
document.getElementById('input_msgbox').focus();
|
||||
}
|
||||
}
|
||||
|
||||
function update_users(users) {
|
||||
if(!users){
|
||||
return;
|
||||
@@ -97,7 +126,7 @@ function update_users(users) {
|
||||
list.appendChild(el);
|
||||
}
|
||||
}
|
||||
function update_info() {
|
||||
function update_messages() {
|
||||
if(!chat_cfg.req_count){
|
||||
chat_cfg.req_count = 1;
|
||||
} else {
|
||||
@@ -108,32 +137,17 @@ function update_info() {
|
||||
if(chat_cfg.chat_lastrow != null){
|
||||
url += "&chat_lastrow="+chat_cfg.chat_lastrow;
|
||||
}
|
||||
var a = YAHOO.util.Connect.asyncRequest('POST', url, update_cb, null);
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', url, update_cb, null);
|
||||
}
|
||||
function append_msg(msg) {
|
||||
var list = document.getElementById('msg_list');
|
||||
var el = document.createElement('li');
|
||||
var list = document.getElementById('messageslist');
|
||||
var item = document.createElement('li');
|
||||
console.info('New message:'+msg.msg);
|
||||
el.innerHTML = msg.msg;
|
||||
item.innerHTML = msg.msg;
|
||||
if(msg.type && msg.type == 'beep'){
|
||||
document.getElementById('notify').innerHTML = '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
|
||||
}
|
||||
list.appendChild(el);
|
||||
}
|
||||
|
||||
var send_cb = {
|
||||
success: function(o) {
|
||||
if(o.responseText == 200){
|
||||
document.getElementById('btn_send').value = chat_lang.send;
|
||||
document.getElementById('input_msgbox').value = '';
|
||||
}
|
||||
clearInterval(interval)
|
||||
update_info();
|
||||
interval = setInterval(function(){
|
||||
update_info();
|
||||
}, chat_cfg.timer);
|
||||
document.getElementById('input_msgbox').focus();
|
||||
}
|
||||
list.appendChild(item);
|
||||
}
|
||||
var update_cb = {
|
||||
success: function(o){
|
||||
@@ -173,18 +187,6 @@ success: function(o){
|
||||
}
|
||||
}
|
||||
}
|
||||
var init_cb = {
|
||||
success: function(o){
|
||||
if(o.responseText){
|
||||
var data = YAHOO.lang.JSON.parse(o.responseText);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (data.users) {
|
||||
update_users(data.users);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// debug code
|
||||
if(!console){
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
define('NO_MOODLE_COOKIES', true); // session not used here
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once('../lib.php');
|
||||
require_once('common.php');
|
||||
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/lib.php');
|
||||
require_once(dirname(__FILE__) . '/common.php');
|
||||
|
||||
ob_start();
|
||||
header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
|
||||
|
||||
+1
-1
@@ -777,7 +777,7 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser
|
||||
$USER->timezone = $tz;
|
||||
$message->strtime = userdate($message->timestamp, get_string('strftimemessage', 'chat'), $tz);
|
||||
|
||||
$message->picture = print_user_picture($sender->id, 0, $sender->picture, false, true, false);
|
||||
$message->picture = print_user_picture($sender->id, $courseid, $sender->picture, false, true, false);
|
||||
if ($courseid) {
|
||||
$message->picture = "<a onclick=\"window.open('$CFG->wwwroot/user/view.php?id=$sender->id&course=$courseid')\" href=\"$CFG->wwwroot/user/view.php?id=$sender->id&course=$courseid\">$message->picture</a>";
|
||||
}
|
||||
|
||||
+3
-3
@@ -165,14 +165,14 @@
|
||||
|
||||
if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
|
||||
$timenow = time();
|
||||
print_simple_box_start('center');
|
||||
$OUTPUT->box_start('generalbox');
|
||||
echo $OUTPUT->heading($strcurrentusers);
|
||||
echo '<table id="chatcurrentusers">';
|
||||
foreach ($chatusers as $chatuser) {
|
||||
$lastping = $timenow - $chatuser->lastmessageping;
|
||||
echo '<tr><td class="chatuserimage">';
|
||||
echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&course=$chat->course\">";
|
||||
print_user_picture($chatuser, 0, $chatuser->picture, false, false, false);
|
||||
print_user_picture($chatuser, $COURSE->id, $chatuser->picture, false, false, false);
|
||||
echo '</a></td><td class="chatuserdetails">';
|
||||
echo '<p>';
|
||||
echo fullname($chatuser).'<br />';
|
||||
@@ -181,7 +181,7 @@
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
print_simple_box_end();
|
||||
$OUTPUT->box_end();
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
Reference in New Issue
Block a user