]> git.mjollnir.org Git - moodle.git/commitdiff
Simple beeping is now added ... users can now beep each other
authormoodler <moodler>
Wed, 9 Jul 2003 12:53:26 +0000 (12:53 +0000)
committermoodler <moodler>
Wed, 9 Jul 2003 12:53:26 +0000 (12:53 +0000)
and also beep everyone using "beep all"

There are no controls as yet to disable beeping on a per-user
basis but this would come next

lang/en/chat.php
mod/chat/gui_header_js/jsupdate.php
mod/chat/lib.php
mod/chat/users.php

index 6d00940bf181589447c192b73668db6970d5f233..ed309e9a00f295ae53782310a3e624b2c7a96b9e 100644 (file)
@@ -5,10 +5,13 @@ $string['modulename'] = "Chat";
 $string['modulenameplural'] = "Chats";
 #------------------------------------------------------------
 
+$string['beep'] = "beep";
 $string['chatintro'] = "Introduction text";
 $string['chatname'] = "Name of this chat room";
 $string['enterchat'] = "Click here to enter the chat";
 $string['idle'] = "Idle";
+$string['messagebeepseveryone'] = "\$a beeps everyone!";
+$string['messagebeepsyou'] = "\$a has just beeped you!";
 $string['messageenter'] = "\$a has just entered this chat";
 $string['messageexit'] = "\$a has left this chat";
 $string['savemessages'] = "Number of messages to save";
index ef76ee8ca59eb0a3c8eeb8d8503916eeb9f0cea2..41c9ffee55584cfc6774095d33d7e5b40a396eb4 100644 (file)
@@ -40,16 +40,18 @@ header("Refresh: 4; URL=jsupdate.php?chat_sid=".$chat_sid."&chat_lasttime=".$cha
     <script language="Javascript">
     <!--
 <?php
+     $beep = false;
+
      if ($chat_lasttime) {
          if ($messages = get_records_select("chat_messages", 
                                             "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime'", 
                                             "timestamp ASC")) {
              foreach ($messages as $message) {
-                 $formatmessage = chat_format_message($message->userid, $message->chatid, 
-                                                      $message->timestamp, $message->message, $message->system);
-?>
-                 parent.msg.document.write('<?php echo $formatmessage ?>\n');
-<?php
+                 $formatmessage = chat_format_message($message);
+                 if ($formatmessage->beep) {
+                     $beep = $formatmessage->beep;
+                 }
+                 echo "parent.msg.document.write('".$formatmessage->html."\\n');";
              }
          }
      }
@@ -62,5 +64,8 @@ header("Refresh: 4; URL=jsupdate.php?chat_sid=".$chat_sid."&chat_lasttime=".$cha
     </script>
    </head>
    <body bgcolor="<?php echo $THEME->body ?>">
+   <?php if ($beep) { ?>
+           <embed src="../beep.wav" autostart="true" hidden="true" />
+   <?php } ?>
    </body>
   </html>
index 691125bbb1e056d0379a8012f67e2ee9591f879f..6320a5ed7200641c5d5613fbf8a1fe59d0cca94f 100644 (file)
@@ -109,6 +109,8 @@ function chat_cron () {
 
     global $CFG;
 
+    chat_delete_old_users();
+
     return true;
 }
 
@@ -168,7 +170,26 @@ function chat_login_user($chatid, $version="header_js") {
     return $chatuser->sid;
 }
 
-
+function chat_delete_old_users() {
+// Delete the old and in the way
+
+    $timeold = time() - CHAT_OLD_PING;
+
+    if ($oldusers = get_records_select("chat_users", "lastping < '$timeold'") ) {
+        delete_records_select("chat_users", "lastping < '$timeold'");
+        foreach ($oldusers as $olduser) {
+            $message->chatid = $olduser->chatid;
+            $message->userid = $olduser->userid;
+            $message->message = "exit";
+            $message->system = 1;
+            $message->timestamp = time();
+     
+            if (!insert_record("chat_messages", $message)) {
+                error("Could not insert a chat message!");
+            }
+        }
+    }
+}
 
 function chat_browser_detect($HTTP_USER_AGENT) {
 
@@ -348,61 +369,92 @@ function chat_display_version($version, $browser)
 }
 
 
-function chat_format_message($userid, $chatid, $timestamp, $message, $system=false) {
-/// Given a message and some information, this function formats it appropriately
-/// for displaying on the web, and returns the formatted string.
+function chat_format_message($message) {
+/// Given a message object full of information, this function 
+/// formats it appropriately into text and html, then 
+/// returns the formatted data.
 
     global $CFG, $USER;
 
-    if (!$user = get_record("user", "id", $userid)) {
-        return "Error finding user id = $userid";
+    $output = new object;
+
+    if (!$user = get_record("user", "id", $message->userid)) {
+        return "Error finding user id = $message->userid";
     }
 
     $picture = print_user_picture($user->id, 0, $user->picture, false, true, false);
 
-    $strtime = userdate($timestamp, get_string("strftimemessage", "chat"));
+    $strtime = userdate($message->timestamp, get_string("strftimemessage", "chat"));
+
+    $output->beep = false;   // by default
 
-    if ($system) {                                    /// It's a system message
-        $message = get_string("message$message", "chat", 
-                              "$user->firstname $user->lastname");
-        $message = addslashes($message);
-        $output  = "<table><tr><td valign=top>$picture</td><td>";
-        $output .= "<font size=2 color=\"#AAAAAA\">$strtime $message</font>";
-        $output .= "</td></tr></table>";
+    $text = $message->message;
+
+    if (!empty($message->system)) {             /// It's a system message
+        $output->text = get_string("message$text", "chat", 
+                                   "$user->firstname $user->lastname");
+        $output->text = "$strtime: $output->text";
+        $output->html  = "<table><tr><td valign=top>$picture</td><td>";
+        $output->html .= "<font size=2 color=\"#CCAAAA\">$output->text</font>";
+        $output->html .= "</td></tr></table>";
         return $output;
     }
 
-    convert_urls_into_links($message);
-    replace_smilies($message);
+    convert_urls_into_links($text);
+    replace_smilies($text);
+
+    if (substr($text, 0, 5) == "beep ") {          /// It's a beep!
+        $beepwho = trim(substr($text, 5));
 
-    if (substr($message, 0, 1) == ":") {              /// It's an MOO emote
+        if ($beepwho == "all") {   // everyone
+            $outinfo = "$strtime: ". get_string("messagebeepseveryone", "chat", 
+                       "$user->firstname $user->lastname");
+            $outmain = "";
+            $output->beep = true;  // (eventually this should be set to 
+                                   //  to a filename uploaded by the user)
+
+        } else if ($beepwho == $USER->id) {  // current user
+            $outinfo = "$strtime: ". get_string("messagebeepsyou", "chat", 
+                       "$user->firstname $user->lastname");
+            $outmain = "";
+            $output->beep = true;
+
+        } else {
+            return false;
+        }
+
+    } else if (substr($text, 0, 1) == ":") {              /// It's an MOO emote
         $outinfo = $strtime;
-        $outmain = "$user->firstname ".substr($message, 1);
+        $outmain = "$user->firstname ".substr($text, 1);
 
-    } else if (substr($message, 0, 1) == "/") {     /// It's a user command
+    } else if (substr($text, 0, 1) == "/") {     /// It's a user command
 
-        if (substr($message, 0, 4) == "/me ") {
+        if (substr($text, 0, 4) == "/me ") {
             $outinfo = $strtime;
-            $outmain = "$user->firstname ".substr($message, 4);
+            $outmain = "$user->firstname ".substr($text, 4);
         } else {
             $outinfo = $strtime;
-            $outmain = $message;
+            $outmain = $text;
         }
 
     } else {                                          /// It's a normal message
         $outinfo = "$strtime $user->firstname";
-        $outmain = $message;
+        $outmain = $text;
     }
 
     /// Format the message as a small table
 
-    $output  = "<table><tr><td valign=top>$picture</td><td>";
-    $output .= "<font size=2><font color=\"#888888\">$outinfo</font>: $outmain</font>";
-    $output .= "</td></tr></table>";
+    $output->text  = strip_tags("$outinfo: $outmain");
+
+    $output->html  = "<table><tr><td valign=top>$picture</td><td><font size=2>";
+    $output->html .= "<font color=\"#888888\">$outinfo</font>";
+    if ($outmain) {
+        $output->html .= ": $outmain";
+    }
+    $output->html .= "</font></td></tr></table>";
 
-    return addslashes($output);
+    return $output;
 
 }
 
-
 ?>
index fc19c1c2ebde16c0f01c233eb5a0417ed7f2bfac..ff8de208d957ea18f81cc4dc54acd122da6651d4 100644 (file)
@@ -21,7 +21,7 @@ if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
     error("Could not find chat! id = $chatuser->chatid");
 }
 
-if (isset($chat_enter)) {
+if (isset($_GET['chat_enter'])) {
     $message->chatid = $chatuser->chatid;
     $message->userid = $chatuser->userid;
     $message->message = "enter";
@@ -33,27 +33,22 @@ if (isset($chat_enter)) {
     }
 }
 
-/// Delete users who are using text version and are old
-
-$timeold = time() - CHAT_OLD_PING;
-
-if ($oldusers = get_records_select("chat_users", "lastping < '$timeold'") ) {
-    delete_records_select("chat_users", "lastping < '$timeold'");
-    foreach ($oldusers as $olduser) {
-        $message->chatid = $olduser->chatid;
-        $message->userid = $olduser->userid;
-        $message->message = "exit";
-        $message->system = 1;
-        $message->timestamp = time();
-     
-        if (!insert_record("chat_messages", $message)) {
-            error("Could not insert a chat message!");
-        }
+if (isset($_GET['beep'])) {
+    $message->chatid = $chatuser->chatid;
+    $message->userid = $chatuser->userid;
+    $message->message = "beep $beep";
+    $message->system = 0;
+    $message->timestamp = time();
+    if (!insert_record("chat_messages", $message)) {
+        error("Could not insert a chat message!");
     }
+}
 
 
-}
+/// Delete users who are using text version and are old
 
+chat_delete_old_users();
 
  
 /// Get list of users
@@ -70,13 +65,14 @@ header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
 header("Cache-Control: no-cache, must-revalidate");
 header("Pragma: no-cache");
 header("Content-Type: text/html");
-header("Refresh: ".CHAT_REFRESH_USERLIST."; URL=users.php?chat_sid=".$chat_sid);
+header("Refresh: ".CHAT_REFRESH_USERLIST."; URL=users.php?chat_sid=$chat_sid");
 
 print_header();
 
 $timenow = time();
 
 $stridle   = get_string("idle", "chat");
+$strbeep   = get_string("beep", "chat");
 $str->day   = get_string("day");
 $str->days  = get_string("days");
 $str->hour  = get_string("hour");
@@ -95,6 +91,7 @@ foreach ($chatusers as $chatuser) {
     echo "<p><font size=1>";
     echo "$chatuser->firstname $chatuser->lastname<br />";
     echo "<font color=\"#888888\">$stridle: ".format_time($lastping, $str)."</font>";
+    echo " <a href=\"users.php?chat_sid=$chat_sid&beep=$chatuser->id\">$strbeep</a>";
     echo "</font></p>";
     echo "<td></tr>";
 }