Skip to content
Browse files

Chatd cleanup finished, from now on only bug fixing.

  • Loading branch information...
1 parent 21ccc31 commit e7fbd0b3f200d675a0fb07c4f29ab063514587db skodak committed
Showing with 45 additions and 104 deletions.
  1. +18 −30 mod/chat/chatd.php
  2. +20 −28 mod/chat/gui_sockets/chatinput.php
  3. +2 −1 mod/chat/gui_sockets/index.php
  4. +5 −45 mod/chat/lib.php
View
48 mod/chat/chatd.php
@@ -23,8 +23,9 @@
/// $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 @@ function get_user_window($sessionid) {
static $str;
$info = &$this->sets_info[$sessionid];
- $oldlang = chat_language_override($info['lang']);
+ chat_force_language($info['lang']);
$timenow = time();
@@ -274,7 +275,7 @@ function get_user_window($sessionid) {
echo fullname($userinfo['user'])."<br />";
echo "<font color=\"#888888\">$str->idle: ".format_time($lastping, $str)."</font> ";
echo '<a target="empty" href="http://'.$CFG->chat_serverhost.':'.$CFG->chat_serverport.'/?win=beep&amp;beep='.$userinfo['user']->id.
- '&chat_sid='.$sessionid.'&amp;groupid='.$this->sets_info[$sessionid]['groupid'].'">'.$str->beep."</a>\n";
+ '&chat_sid='.$sessionid.'">'.$str->beep."</a>\n";
echo "</font></p>";
echo "<td></tr>";
}
@@ -286,7 +287,6 @@ function get_user_window($sessionid) {
echo "</body>\n</html>\n";
- chat_language_restore($oldlang);
return ob_get_clean();
}
@@ -373,7 +373,7 @@ function dispatch_sidekick($handle, $type, $sessionid, $customdata) {
// 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 @@ function dispatch_sidekick($handle, $type, $sessionid, $customdata) {
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 @@ function promote_final($sessionid, $groupid, $customdata) {
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 @@ function promote_final($sessionid, $groupid, $customdata) {
'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 @@ function promote_final($sessionid, $groupid, $customdata) {
$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 @@ function promote_final($sessionid, $groupid, $customdata) {
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 @@ function promote_ufo($handle, $type, $sessionid, $groupid, $customdata) {
$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 @@ function message_broadcast($message, $sender) {
{
// 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 @@ function disconnect_session($sessionid) {
$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 @@ function cli_switch($switch, $param = NULL) {
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 @@ function cli_switch($switch, $param = NULL) {
$type = $info[1];
$sessionid = $info[2];
- $groupid = $info[3];
$customdata = array();
@@ -1039,7 +1027,7 @@ function cli_switch($switch, $param = NULL) {
}
// 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;
}
}
View
48 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);
-?>
-
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
-<html>
-<head>
-<meta http-equiv="content-type" content="text/html; charset=<?php echo get_string('thischarset'); ?>" />
-<title>Message Input</title>
-
-<?php
- $focus = '';
- include("$CFG->javascript");
-?>
-
+ ob_start();
+ ?>
<script type="text/javascript">
<!--
@@ -36,8 +24,8 @@ function empty_field_and_submit() {
var inpf = document.getElementById('inputform');
cf.chat_msgidnr.value = parseInt(cf.chat_msgidnr.value) + 1;
cf.chat_message.value = inpf.chat_message.value;
- cf.submit();
inpf.chat_message.value='';
+ cf.submit();
inpf.chat_message.focus();
return false;
}
@@ -59,22 +47,26 @@ function reloadusers() {
}
// -->
</script>
-</head>
+ <?php
-<body bgcolor="<?php echo $THEME->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, '&nbsp;', '', false, 'onload="setfocus(); prepareusers();"');
-<form action="../empty.php" method="get" target="empty" id="inputform" onsubmit="return empty_field_and_submit();">
-&gt;&gt; <input type="text" name="chat_message" size="60" value="" />
-<?php helpbutton("chatting", get_string("helpchatting", "chat"), "chat", true, false); ?>
-</form>
+?>
-<form action="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="sendform">
- <input type="hidden" name="win" value="message" />
- <input type="hidden" name="chat_message" value="" />
- <input type="hidden" name="chat_msgidnr" value="0" />
- <input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>" />
- <input type="hidden" name="groupid" value="<?php echo $groupid ?>" />
-</form>
+ <form action="../empty.php" method="get" target="empty" id="inputform"
+ onsubmit="return empty_field_and_submit();">
+ &gt;&gt;<input type="text" name="chat_message" size="60" value="" />
+ <?php helpbutton("chatting", get_string("helpchatting", "chat"), "chat", true, false); ?>
+ </form>
+
+ <form action="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="sendform">
+ <input type="hidden" name="win" value="message" />
+ <input type="hidden" name="chat_message" value="" />
+ <input type="hidden" name="chat_msgidnr" value="0" />
+ <input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>" />
+ </form>
</body>
</html>
View
3 mod/chat/gui_sockets/index.php
@@ -50,13 +50,14 @@
error('Could not log in to chat room!!');
}
- $params = "chat_sid=$chat_sid&amp;groupid=$groupid";
+ $params = "chat_sid=$chat_sid";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
+ <meta http-equiv="content-type" content="text/html; charset=<?php echo get_string('thischarset'); ?>" />
<title>
<?php echo "$strchat: $course->shortname: $chat->name$groupname" ?>
</title>
View
50 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 .= "</font></td></tr></table>";
- // Don't forget to reset the language before returning!!!
- chat_language_restore($oldcfglang);
-
return $output;
}

0 comments on commit e7fbd0b

Please sign in to comment.
Something went wrong with that request. Please try again.