From: moodler Date: Wed, 9 Jul 2003 12:53:26 +0000 (+0000) Subject: Simple beeping is now added ... users can now beep each other X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7d79236935f23996d35d075e10d92c2b636ad3d8;p=moodle.git Simple beeping is now added ... users can now beep each other 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 --- diff --git a/lang/en/chat.php b/lang/en/chat.php index 6d00940bf1..ed309e9a00 100644 --- a/lang/en/chat.php +++ b/lang/en/chat.php @@ -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"; diff --git a/mod/chat/gui_header_js/jsupdate.php b/mod/chat/gui_header_js/jsupdate.php index ef76ee8ca5..41c9ffee55 100644 --- a/mod/chat/gui_header_js/jsupdate.php +++ b/mod/chat/gui_header_js/jsupdate.php @@ -40,16 +40,18 @@ header("Refresh: 4; URL=jsupdate.php?chat_sid=".$chat_sid."&chat_lasttime=".$cha + + + diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 691125bbb1..6320a5ed72 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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 = "
$picture"; - $output .= "$strtime $message"; - $output .= "
"; + $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 = "
$picture"; + $output->html .= "$output->text"; + $output->html .= "
"; 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 = "
$picture"; - $output .= "$outinfo: $outmain"; - $output .= "
"; + $output->text = strip_tags("$outinfo: $outmain"); + + $output->html = "
$picture"; + $output->html .= "$outinfo"; + if ($outmain) { + $output->html .= ": $outmain"; + } + $output->html .= "
"; - return addslashes($output); + return $output; } - ?> diff --git a/mod/chat/users.php b/mod/chat/users.php index fc19c1c2eb..ff8de208d9 100644 --- a/mod/chat/users.php +++ b/mod/chat/users.php @@ -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 "

"; echo "$chatuser->firstname $chatuser->lastname
"; echo "$stridle: ".format_time($lastping, $str).""; + echo " id\">$strbeep"; echo "

"; echo ""; }