Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Extended theme support to the chat window. Bug 3376.

  • Loading branch information...
commit bcfdf5f0e62584d6f6262d7f6fd344ca6e0ceee1 1 parent 84fdfff
stronk7 authored
12 mod/chat/gui_header_js/chatinput.php
@@ -11,6 +11,18 @@
11 11 error('Not logged in!');
12 12 }
13 13
  14 + //Get the course theme
  15 + $course = get_record('course','id',$chatuser->course,'','','','','id,theme');
  16 + //Set the global course if necessary
  17 + if (!empty($course->theme)) {
  18 + global $course;
  19 + }
  20 + //Get the user theme
  21 + $USER = get_record('user','id',$chatuser->userid,'','','','','id, theme');
  22 +
  23 + //Adjust the prefered theme (main, course, user)
  24 + theme_setup();
  25 +
14 26 chat_force_language($chatuser->lang);
15 27
16 28 ob_start();
43 mod/chat/gui_header_js/jsupdate.php
@@ -7,11 +7,26 @@
7 7
8 8 $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
9 9 $chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
  10 + $chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT);
10 11
11 12 if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
12 13 error('Not logged in!');
13 14 }
14 15
  16 + //Get the course theme
  17 + $course = get_record('course','id',$chatuser->course,'','','','','id,theme');
  18 + //Set the course theme if necessary
  19 + if (!empty($course->theme)) {
  20 + if (!empty($CFG->allowcoursethemes)) {
  21 + $CFG->coursetheme = $course->theme;
  22 + }
  23 + }
  24 + //Get the user theme
  25 + $USER = get_record('user','id',$chatuser->userid,'','','','','id, theme');
  26 +
  27 + //Adjust the prefered theme (main, course, user)
  28 + theme_setup();
  29 +
15 30 chat_force_language($chatuser->lang);
16 31
17 32 // force deleting of timed out users if there is a silence in room or just entering
@@ -30,11 +45,24 @@
30 45 $chat_lasttime = time() - $CFG->chat_old_ping; //TO DO - any better value??
31 46 }
32 47
33   - $refreshurl = "jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime"; // no & in url, does not work in header!
34 48 $timenow = time();
35 49
36 50 $groupselect = $chatuser->groupid ? " AND (groupid='".$chatuser->groupid."' OR groupid='0') " : "";
37 51
  52 + $messages = get_records_select("chat_messages",
  53 + "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
  54 + "timestamp ASC");
  55 +
  56 + if ($messages) {
  57 + $num = count($messages);
  58 + } else {
  59 + $num = 0;
  60 + }
  61 +
  62 + $chat_newrow = ($chat_lastrow + $num) % 2;
  63 +
  64 + $refreshurl = "jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow"; // no & in url, does not work in header!
  65 +
38 66 header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
39 67 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
40 68 header('Cache-Control: no-cache, must-revalidate');
@@ -49,7 +77,7 @@
49 77 }
50 78
51 79 ?>
52   -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
  80 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
53 81 <html>
54 82 <head>
55 83 <meta http-equiv="content-type" content="text/html; charset=<?php echo get_string('thischarset'); ?>" />
@@ -58,20 +86,18 @@
58 86 if (parent.msg.document.getElementById("msgStarted") == null) {
59 87 parent.msg.document.close();
60 88 parent.msg.document.open("text/html","replace");
  89 + parent.msg.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
61 90 parent.msg.document.write("<html><head>");
62 91 parent.msg.document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=<?php echo get_string('thischarset'); ?>\" />");
63 92 parent.msg.document.write("<base target=\"_blank\" />");
64 93 parent.msg.document.write("<?php echo $stylesheetshtml ?>");
65   - parent.msg.document.write("</head><body><div style=\"display: none\" id=\"msgStarted\">&nbsp;</div>");
  94 + 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>");
66 95 }
67 96 <?php
68 97 $beep = false;
69 98 $refreshusers = false;
70 99 $us = array ();
71   - if (($chat_lasttime != $chat_newlasttime)
72   - and $messages = get_records_select("chat_messages",
73   - "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
74   - "timestamp ASC")) {
  100 + if (($chat_lasttime != $chat_newlasttime) and $messages) {
75 101
76 102 if (!$currentuser = get_record('user', 'id', $chatuser->userid)) {
77 103 error('User does not exist!');
@@ -79,7 +105,8 @@
79 105 $currentuser->description = '';
80 106
81 107 foreach ($messages as $message) {
82   - $formatmessage = chat_format_message($message, $chatuser->course, $currentuser);
  108 + $chat_lastrow = ($chat_lastrow + 1) % 2;
  109 + $formatmessage = chat_format_message($message, $chatuser->course, $currentuser, $chat_lastrow);
83 110 if ($formatmessage->beep) {
84 111 $beep = true;
85 112 }
14 mod/chat/gui_header_js/users.php
@@ -12,6 +12,20 @@
12 12 error('Not logged in!');
13 13 }
14 14
  15 + //Get the course theme
  16 + $course = get_record('course','id',$chatuser->course,'','','','','id,theme');
  17 + //Set the course theme if necessary
  18 + if (!empty($course->theme)) {
  19 + if (!empty($CFG->allowcoursethemes)) {
  20 + $CFG->coursetheme = $course->theme;
  21 + }
  22 + }
  23 + //Get the user theme
  24 + $USER = get_record('user','id',$chatuser->userid,'','','','','id, theme');
  25 +
  26 + //Adjust the prefered theme (main, course, user)
  27 + theme_setup();
  28 +
15 29 chat_force_language($chatuser->lang);
16 30
17 31 $courseid = $chatuser->course;
23 mod/chat/lib.php
@@ -493,7 +493,7 @@ function chat_update_chat_times($chatid=0) {
493 493 }
494 494
495 495
496   -function chat_format_message_manually($message, $courseid, $sender, $currentuser) {
  496 +function chat_format_message_manually($message, $courseid, $sender, $currentuser, $chat_lastrow=NULL) {
497 497 global $CFG;
498 498
499 499 $output = New stdClass;
@@ -512,13 +512,20 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser
512 512 $message->picture = "<a target=\"_new\" href=\"$CFG->wwwroot/user/view.php?id=$sender->id&amp;course=$courseid\">$message->picture</a>";
513 513 }
514 514
  515 + //Calculate the row class
  516 + if ($chat_lastrow !== NULL) {
  517 + $rowclass = ' class="r'.$chat_lastrow.'" ';
  518 + } else {
  519 + $rowclass = '';
  520 + }
  521 +
515 522 // Start processing the message
516 523
517 524 if(!empty($message->system)) {
518 525 // System event
519 526 $output->text = $message->strtime.': '.get_string('message'.$message->message, 'chat', fullname($sender));
520   - $output->html = '<table><tr><td style="vertical-align: top;">'.$message->picture.'</td><td>';
521   - $output->html .= '<font size="2" color="#ccaaaa">'.$output->text.'</font></td></tr></table>';
  527 + $output->html = '<table class="chat-event"><tr'.$rowclass.'><td class="picture">'.$message->picture.'</td><td class="text">';
  528 + $output->html .= '<span class="event">'.$output->text.'</span></td></tr></table>';
522 529
523 530 if($message->message == 'exit' or $message->message == 'enter') {
524 531 $output->refreshusers = true; //force user panel refresh ASAP
@@ -579,17 +586,17 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser
579 586
580 587 $output->text = strip_tags($outinfo.': '.$outmain);
581 588
582   - $output->html = "<table><tr><td valign=\"top\">$message->picture</td><td><font size=\"2\">";
583   - $output->html .= "<font color=\"#888888\">$outinfo</font>";
  589 + $output->html = "<table class=\"chat-message\"><tr$rowclass><td class=\"picture\">$message->picture</td><td class=\"text\">";
  590 + $output->html .= "<span class=\"title\">$outinfo</span>";
584 591 if ($outmain) {
585 592 $output->html .= ": $outmain";
586 593 }
587   - $output->html .= "</font></td></tr></table>";
  594 + $output->html .= "</td></tr></table>";
588 595
589 596 return $output;
590 597 }
591 598
592   -function chat_format_message($message, $courseid, $currentuser) {
  599 +function chat_format_message($message, $courseid, $currentuser, $chat_lastrow=NULL) {
593 600 /// Given a message object full of information, this function
594 601 /// formats it appropriately into text and html, then
595 602 /// returns the formatted data.
@@ -598,7 +605,7 @@ function chat_format_message($message, $courseid, $currentuser) {
598 605 return "Error finding user id = $message->userid";
599 606 }
600 607
601   - return chat_format_message_manually($message, $courseid, $user, $currentuser);
  608 + return chat_format_message_manually($message, $courseid, $user, $currentuser, $chat_lastrow);
602 609
603 610 }
604 611

0 comments on commit bcfdf5f

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