diff --git a/mod/chat/chatd.php b/mod/chat/chatd.php index 729e8dcfcc8..f8557eac401 100755 --- a/mod/chat/chatd.php +++ b/mod/chat/chatd.php @@ -23,8 +23,9 @@ echo 'Moodle chat daemon v1.0 on PHP '.$phpversion." (\$Id$)\n\n"; /// $CFG variables are now defined in database by chat/lib.php -$_SERVER['PHP_SELF'] = 'dummy'; -$_SERVER['SERVER_NAME'] = 'dummy'; +$_SERVER['PHP_SELF'] = 'dummy'; +$_SERVER['SERVER_NAME'] = 'dummy'; +$_SERVER['HTTP_USER_AGENT'] = 'dummy'; include('../../config.php'); include('lib.php'); @@ -221,7 +222,7 @@ class ChatDaemon { static $str; $info = &$this->sets_info[$sessionid]; - $oldlang = chat_language_override($info['lang']); + chat_force_language($info['lang']); $timenow = time(); @@ -274,7 +275,7 @@ class ChatDaemon { echo fullname($userinfo['user'])."
"; echo "$str->idle: ".format_time($lastping, $str)." "; echo ''.$str->beep."\n"; + '&chat_sid='.$sessionid.'">'.$str->beep."\n"; echo "

"; echo ""; } @@ -286,7 +287,6 @@ class ChatDaemon { echo "\n\n"; - chat_language_restore($oldlang); return ob_get_clean(); } @@ -373,7 +373,7 @@ class ChatDaemon { // The refresh value is 2 seconds higher than the configuration variable because we are doing JS refreshes all the time. // However, if the JS doesn't work for some reason, we still want to refresh once in a while. $header .= "Refresh: ".(intval($CFG->chat_refresh_userlist) + 2)."; url=http://$CFG->chat_serverhost:$CFG->chat_serverport/?win=users&". - "chat_sid=".$sessionid."&groupid=".$this->sets_info[$sessionid]['groupid']."\n"; + "chat_sid=".$sessionid."\n"; $header .= "\n"; // That's enough headers for one lousy dummy response @@ -458,7 +458,7 @@ class ChatDaemon { socket_close($handle); } - function promote_final($sessionid, $groupid, $customdata) { + function promote_final($sessionid, $customdata) { if(isset($this->conn_sets[$sessionid])) { $this->trace('Set cannot be finalized: Session '.$sessionid.' is already active'); return false; @@ -488,18 +488,6 @@ class ChatDaemon { global $CHAT_HTMLHEAD_JS, $CFG; - // A really sad thing, to have to do this by hand.... :-( - $lang = NULL; - if(empty($lang) && !empty($course->lang)) { - $lang = $course->lang; - } - if(empty($lang) && !empty($user->lang)) { - $lang = $user->lang; - } - if(empty($lang)) { - $lang = $CFG->lang; - } - $this->conn_sets[$sessionid] = $this->conn_half[$sessionid]; // This whole thing needs to be purged of redundant info, and the @@ -512,8 +500,8 @@ class ChatDaemon { 'chatid' => $chat->id, 'user' => $user, 'userid' => $user->id, - 'groupid' => $groupid, - 'lang' => $lang, + 'groupid' => $chatuser->groupid, + 'lang' => $chatuser->lang, 'quirks' => $customdata['quirks'] ); @@ -530,14 +518,14 @@ class ChatDaemon { $this->dismiss_half($sessionid, false); $this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL], $CHAT_HTMLHEAD_JS); - $this->trace('Connection accepted: '.$this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL].', SID: '.$sessionid.' UID: '.$chatuser->userid.' GID: '.intval($groupid), E_USER_WARNING); + $this->trace('Connection accepted: '.$this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL].', SID: '.$sessionid.' UID: '.$chatuser->userid.' GID: '.$chatuser->groupid, E_USER_WARNING); // Finally, broadcast the "entered the chat" message $msg = &New stdClass; $msg->chatid = $chatuser->chatid; $msg->userid = $chatuser->userid; - $msg->groupid = 0; + $msg->groupid = $chatuser->groupid; $msg->system = 1; $msg->message = 'enter'; $msg->timestamp = time(); @@ -548,7 +536,7 @@ class ChatDaemon { return true; } - function promote_ufo($handle, $type, $sessionid, $groupid, $customdata) { + function promote_ufo($handle, $type, $sessionid, $customdata) { if(empty($this->conn_ufo)) { return false; } @@ -590,7 +578,7 @@ class ChatDaemon { $this->conn_half[$sessionid][$type] = $handle; // Do the bookkeeping - $this->promote_final($sessionid, $groupid, $customdata); + $this->promote_final($sessionid, $customdata); // It's not an UFO anymore $this->dismiss_ufo($handle, false); @@ -712,7 +700,8 @@ class ChatDaemon { { // Simply give them the message - $output = chat_format_message_manually($message, $info['courseid'], $sender, $info['user'], $info['lang']); + chat_force_language($info['lang']); + $output = chat_format_message_manually($message, $info['courseid'], $sender, $info['user']); $this->trace('Delivering message "'.$output->text.'" to '.$this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL]); if($output->beep) { @@ -740,7 +729,7 @@ class ChatDaemon { $msg = &New stdClass; $msg->chatid = $info['chatid']; $msg->userid = $info['userid']; - $msg->groupid = 0; + $msg->groupid = $info['groupid']; $msg->system = 1; $msg->message = 'exit'; $msg->timestamp = time(); @@ -984,7 +973,7 @@ while(true) { continue; } - if(!ereg('win=(chat|users|message|beep).*&chat_sid=([a-zA-Z0-9]*)&groupid=([0-9]*) HTTP', $data, $info)) { + if(!ereg('win=(chat|users|message|beep).*&chat_sid=([a-zA-Z0-9]*) HTTP', $data, $info)) { // Malformed data $DAEMON->trace('UFO with '.$handle.': Request with malformed data; connection closed', E_USER_WARNING); $DAEMON->dismiss_ufo($handle, true, 'Request with malformed data; connection closed'); @@ -993,7 +982,6 @@ while(true) { $type = $info[1]; $sessionid = $info[2]; - $groupid = $info[3]; $customdata = array(); @@ -1039,7 +1027,7 @@ while(true) { } // OK, now we know it's something good... promote it and pass it all the data it needs - $DAEMON->promote_ufo($handle, $type, $sessionid, $groupid, $customdata); + $DAEMON->promote_ufo($handle, $type, $sessionid, $customdata); continue; } } diff --git a/mod/chat/gui_sockets/chatinput.php b/mod/chat/gui_sockets/chatinput.php index f5673d60bae..6cef94d8eaa 100644 --- a/mod/chat/gui_sockets/chatinput.php +++ b/mod/chat/gui_sockets/chatinput.php @@ -6,7 +6,6 @@ require('../lib.php'); $chat_sid = required_param('chat_sid', PARAM_ALPHANUM); - $groupid = optional_param('groupid', 0, PARAM_INT); if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) { error('Not logged in!'); @@ -14,19 +13,8 @@ chat_force_language($chatuser->lang); -?> - - - - - -Message Input - -javascript"); -?> - + ob_start(); + ?> - + body ?>" onload="document.getElementById('inputform').chat_message.focus(); prepareusers();"> + $meta = ob_get_clean(); + // TODO: there will be two onload in body tag, does it matter? + print_header('', '', '', 'inputform.chat_message', $meta, false, ' ', '', false, 'onload="setfocus(); prepareusers();"'); -
->> - -
+?> -
chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="sendform"> - - - - - -
+
+ >> + +
+ +
chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="sendform"> + + + + +
diff --git a/mod/chat/gui_sockets/index.php b/mod/chat/gui_sockets/index.php index 4173b79f1b2..8280f99d458 100644 --- a/mod/chat/gui_sockets/index.php +++ b/mod/chat/gui_sockets/index.php @@ -50,13 +50,14 @@ error('Could not log in to chat room!!'); } - $params = "chat_sid=$chat_sid&groupid=$groupid"; + $params = "chat_sid=$chat_sid"; ?> + <?php echo "$strchat: $course->shortname: $chat->name$groupname" ?> diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 7d5588efc15..f1a44bdd578 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -301,7 +301,7 @@ function chat_force_language($lang) { if(!empty($CFG->locale)) { unset($CFG->locale); } - $CFG->lang = clean_filename($lang); + $CFG->lang = $lang; moodle_setlocale(); } @@ -359,7 +359,7 @@ function chat_get_latest_message($chatid, $groupid=0) { function chat_login_user($chatid, $version, $groupid, $course) { global $USER; - if ($chatuser = get_record_select('chat_users', "chatid='$chatid' AND userid='$USER->id' AND groupid='$groupid'")) { + if (($version != 'sockets') and $chatuser = get_record_select('chat_users', "chatid='$chatid' AND userid='$USER->id' AND groupid='$groupid'")) { $chatuser->version = $version; $chatuser->ip = $USER->lastIP; $chatuser->lastping = time(); @@ -411,13 +411,7 @@ function chat_delete_old_users() { global $CFG; - if ($CFG->chat_method == 'sockets') { - // delete very outdated users not deleted by chatd, - // let normal deleting to chatd, because it needs to output the message - $timeold = time() - ($CFG->chat_old_ping * 3); - } else { - $timeold = time() - $CFG->chat_old_ping; - } + $timeold = time() - $CFG->chat_old_ping; $query = "lastping < '$timeold'"; @@ -479,41 +473,14 @@ function chat_update_chat_times($chatid=0) { } - -function chat_language_override($language) { - // Override the highest-ranking language variable from current_language() - // And save it so we can restore it again afterwards - global $CFG; - - $oldlang = empty($CFG->courselang) ? NULL : $CFG->courselang; - $CFG->courselang = $language; - - return $oldlang; -} - -function chat_language_restore($language = NULL) { - // Restore the highest-ranking language variable from current_language() - global $CFG; - - if(!empty($language)) { - $CFG->courselang = $language; - } -} - -function chat_format_message_manually($message, $courseid, $sender, $currentuser, $language = NULL) { +function chat_format_message_manually($message, $courseid, $sender, $currentuser) { global $CFG; $output = New stdClass; $output->beep = false; // by default $output->refreshusers = false; // by default - if(empty($language)) { - $language = current_language(); - } - - $oldcfglang = chat_language_override($language); - - // Get some additional info now that the language has been correctly set + // Get some additional info // But before that :-) let's override get_user_timezone() for this call... messy stuff... $tz = ($currentuser->timezone == 99) ? $CFG->timezone : $currentuser->timezone; @@ -536,10 +503,6 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser $output->refreshusers = true; //force user panel refresh ASAP } - // Don't forget to reset the language before returning!!! - if(!empty($oldcfglang)) { - $CFG->courselang = $oldcfglang; - } return $output; } @@ -602,9 +565,6 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser } $output->html .= ""; - // Don't forget to reset the language before returning!!! - chat_language_restore($oldcfglang); - return $output; }