Browse files

Extended theme support to the chat window. Bug 3376.

  • Loading branch information...
1 parent 84fdfff commit bcfdf5f0e62584d6f6262d7f6fd344ca6e0ceee1 stronk7 committed Sep 10, 2005
Showing with 76 additions and 16 deletions.
  1. +12 −0 mod/chat/gui_header_js/chatinput.php
  2. +35 −8 mod/chat/gui_header_js/jsupdate.php
  3. +14 −0 mod/chat/gui_header_js/users.php
  4. +15 −8 mod/chat/lib.php
View
12 mod/chat/gui_header_js/chatinput.php
@@ -11,6 +11,18 @@
error('Not logged in!');
}
+ //Get the course theme
+ $course = get_record('course','id',$chatuser->course,'','','','','id,theme');
+ //Set the global course if necessary
+ if (!empty($course->theme)) {
+ global $course;
+ }
+ //Get the user theme
+ $USER = get_record('user','id',$chatuser->userid,'','','','','id, theme');
+
+ //Adjust the prefered theme (main, course, user)
+ theme_setup();
+
chat_force_language($chatuser->lang);
ob_start();
View
43 mod/chat/gui_header_js/jsupdate.php
@@ -7,11 +7,26 @@
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
+ $chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT);
if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
error('Not logged in!');
}
+ //Get the course theme
+ $course = get_record('course','id',$chatuser->course,'','','','','id,theme');
+ //Set the course theme if necessary
+ if (!empty($course->theme)) {
+ if (!empty($CFG->allowcoursethemes)) {
+ $CFG->coursetheme = $course->theme;
+ }
+ }
+ //Get the user theme
+ $USER = get_record('user','id',$chatuser->userid,'','','','','id, theme');
+
+ //Adjust the prefered theme (main, course, user)
+ theme_setup();
+
chat_force_language($chatuser->lang);
// force deleting of timed out users if there is a silence in room or just entering
@@ -30,11 +45,24 @@
$chat_lasttime = time() - $CFG->chat_old_ping; //TO DO - any better value??
}
- $refreshurl = "jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime"; // no & in url, does not work in header!
$timenow = time();
$groupselect = $chatuser->groupid ? " AND (groupid='".$chatuser->groupid."' OR groupid='0') " : "";
+ $messages = get_records_select("chat_messages",
+ "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
+ "timestamp ASC");
+
+ if ($messages) {
+ $num = count($messages);
+ } else {
+ $num = 0;
+ }
+
+ $chat_newrow = ($chat_lastrow + $num) % 2;
+
+ $refreshurl = "jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow"; // no & in url, does not work in header!
+
header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-cache, must-revalidate');
@@ -49,7 +77,7 @@
}
?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=<?php echo get_string('thischarset'); ?>" />
@@ -58,28 +86,27 @@
if (parent.msg.document.getElementById("msgStarted") == null) {
parent.msg.document.close();
parent.msg.document.open("text/html","replace");
+ parent.msg.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
parent.msg.document.write("<html><head>");
parent.msg.document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=<?php echo get_string('thischarset'); ?>\" />");
parent.msg.document.write("<base target=\"_blank\" />");
parent.msg.document.write("<?php echo $stylesheetshtml ?>");
- parent.msg.document.write("</head><body><div style=\"display: none\" id=\"msgStarted\">&nbsp;</div>");
+ parent.msg.document.write("</head><body class=\"mod-chat-gui_header_js course-<?php echo $chatuser->course ?>\" id=\"mod-chat-gui_header_js-jsupdate\"><div style=\"display: none\" id=\"msgStarted\">&nbsp;</div>");
}
<?php
$beep = false;
$refreshusers = false;
$us = array ();
- if (($chat_lasttime != $chat_newlasttime)
- and $messages = get_records_select("chat_messages",
- "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
- "timestamp ASC")) {
+ if (($chat_lasttime != $chat_newlasttime) and $messages) {
if (!$currentuser = get_record('user', 'id', $chatuser->userid)) {
error('User does not exist!');
}
$currentuser->description = '';
foreach ($messages as $message) {
- $formatmessage = chat_format_message($message, $chatuser->course, $currentuser);
+ $chat_lastrow = ($chat_lastrow + 1) % 2;
+ $formatmessage = chat_format_message($message, $chatuser->course, $currentuser, $chat_lastrow);
if ($formatmessage->beep) {
$beep = true;
}
View
14 mod/chat/gui_header_js/users.php
@@ -12,6 +12,20 @@
error('Not logged in!');
}
+ //Get the course theme
+ $course = get_record('course','id',$chatuser->course,'','','','','id,theme');
+ //Set the course theme if necessary
+ if (!empty($course->theme)) {
+ if (!empty($CFG->allowcoursethemes)) {
+ $CFG->coursetheme = $course->theme;
+ }
+ }
+ //Get the user theme
+ $USER = get_record('user','id',$chatuser->userid,'','','','','id, theme');
+
+ //Adjust the prefered theme (main, course, user)
+ theme_setup();
+
chat_force_language($chatuser->lang);
$courseid = $chatuser->course;
View
23 mod/chat/lib.php
@@ -493,7 +493,7 @@ function chat_update_chat_times($chatid=0) {
}
-function chat_format_message_manually($message, $courseid, $sender, $currentuser) {
+function chat_format_message_manually($message, $courseid, $sender, $currentuser, $chat_lastrow=NULL) {
global $CFG;
$output = New stdClass;
@@ -512,13 +512,20 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser
$message->picture = "<a target=\"_new\" href=\"$CFG->wwwroot/user/view.php?id=$sender->id&amp;course=$courseid\">$message->picture</a>";
}
+ //Calculate the row class
+ if ($chat_lastrow !== NULL) {
+ $rowclass = ' class="r'.$chat_lastrow.'" ';
+ } else {
+ $rowclass = '';
+ }
+
// Start processing the message
if(!empty($message->system)) {
// System event
$output->text = $message->strtime.': '.get_string('message'.$message->message, 'chat', fullname($sender));
- $output->html = '<table><tr><td style="vertical-align: top;">'.$message->picture.'</td><td>';
- $output->html .= '<font size="2" color="#ccaaaa">'.$output->text.'</font></td></tr></table>';
+ $output->html = '<table class="chat-event"><tr'.$rowclass.'><td class="picture">'.$message->picture.'</td><td class="text">';
+ $output->html .= '<span class="event">'.$output->text.'</span></td></tr></table>';
if($message->message == 'exit' or $message->message == 'enter') {
$output->refreshusers = true; //force user panel refresh ASAP
@@ -579,17 +586,17 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser
$output->text = strip_tags($outinfo.': '.$outmain);
- $output->html = "<table><tr><td valign=\"top\">$message->picture</td><td><font size=\"2\">";
- $output->html .= "<font color=\"#888888\">$outinfo</font>";
+ $output->html = "<table class=\"chat-message\"><tr$rowclass><td class=\"picture\">$message->picture</td><td class=\"text\">";
+ $output->html .= "<span class=\"title\">$outinfo</span>";
if ($outmain) {
$output->html .= ": $outmain";
}
- $output->html .= "</font></td></tr></table>";
+ $output->html .= "</td></tr></table>";
return $output;
}
-function chat_format_message($message, $courseid, $currentuser) {
+function chat_format_message($message, $courseid, $currentuser, $chat_lastrow=NULL) {
/// Given a message object full of information, this function
/// formats it appropriately into text and html, then
/// returns the formatted data.
@@ -598,7 +605,7 @@ function chat_format_message($message, $courseid, $currentuser) {
return "Error finding user id = $message->userid";
}
- return chat_format_message_manually($message, $courseid, $user, $currentuser);
+ return chat_format_message_manually($message, $courseid, $user, $currentuser, $chat_lastrow);
}

0 comments on commit bcfdf5f

Please sign in to comment.