[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 define('NO_MOODLE_COOKIES', true); // Session not used here. 18 19 require('../../../config.php'); 20 require ('../lib.php'); 21 22 $chatsid = required_param('chat_sid', PARAM_ALPHANUM); 23 $chatlasttime = optional_param('chat_lasttime', 0, PARAM_INT); 24 $chatlastrow = optional_param('chat_lastrow', 1, PARAM_INT); 25 26 $url = new moodle_url('/mod/chat/gui_header_js/jsupdate.php', array('chat_sid' => $chatsid)); 27 if ($chatlasttime !== 0) { 28 $url->param('chat_lasttime', $chatlasttime); 29 } 30 if ($chatlastrow !== 1) { 31 $url->param('chat_lastrow', $chatlastrow); 32 } 33 $PAGE->set_url($url); 34 35 36 if (!$chatuser = $DB->get_record('chat_users', array('sid' => $chatsid))) { 37 print_error('notlogged', 'chat'); 38 } 39 40 // Get the minimal course. 41 if (!$course = $DB->get_record('course', array('id' => $chatuser->course))) { 42 print_error('invalidcourseid'); 43 } 44 45 // Get the user theme and enough info to be used in chat_format_message() which passes it along to. 46 // No optimisation here, it would break again in future! 47 if (!$user = $DB->get_record('user', array('id' => $chatuser->userid, 'deleted' => 0, 'suspended' => 0))) { 48 print_error('invaliduser'); 49 } 50 \core\session\manager::set_user($user); 51 52 // Setup course, lang and theme. 53 $PAGE->set_course($course); 54 55 // Force deleting of timed out users if there is a silence in room or just entering. 56 if ((time() - $chatlasttime) > $CFG->chat_old_ping) { 57 // Must be done before chat_get_latest_message! 58 chat_delete_old_users(); 59 } 60 61 if ($message = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) { 62 $chatnewlasttime = $message->timestamp; 63 } else { 64 $chatnewlasttime = 0; 65 } 66 67 if ($chatlasttime == 0) { // Display some previous messages. 68 $chatlasttime = time() - $CFG->chat_old_ping; // TO DO - any better value? 69 } 70 71 $timenow = time(); 72 73 $params = array('groupid' => $chatuser->groupid, 'chatid' => $chatuser->chatid, 'lasttime' => $chatlasttime); 74 75 $groupselect = $chatuser->groupid ? " AND (groupid=:groupid OR groupid=0) " : ""; 76 77 $messages = $DB->get_records_select("chat_messages_current", 78 "chatid = :chatid AND timestamp > :lasttime $groupselect", $params, 79 "timestamp ASC"); 80 81 if ($messages) { 82 $num = count($messages); 83 } else { 84 $num = 0; 85 } 86 87 $chatnewrow = ($chatlastrow + $num) % 2; 88 89 // No & in url, does not work in header! 90 $baseurl = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?"; 91 $refreshurl = $baseurl . "chat_sid=$chatsid&chat_lasttime=$chatnewlasttime&chat_lastrow=$chatnewrow"; 92 $refreshurlamp = $baseurl . "chat_sid=$chatsid&chat_lasttime=$chatnewlasttime&chat_lastrow=$chatnewrow"; 93 94 header('Expires: Sun, 28 Dec 1997 09:32:45 GMT'); 95 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 96 header('Cache-Control: no-cache, must-revalidate'); 97 header('Pragma: no-cache'); 98 header('Content-Type: text/html; charset=utf-8'); 99 header("Refresh: $CFG->chat_refresh_room; url=$refreshurl"); 100 101 // Required stylesheets. 102 $stylesheetshtml = ''; 103 /*foreach ($CFG->stylesheets as $stylesheet) { 104 //TODO: MDL-21120 105 $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />'; 106 }*/ 107 108 // Use ob to be able to send Content-Length headers. 109 // Needed for Keep-Alive to work. 110 ob_start(); 111 112 ?> 113 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 114 <html> 115 <head> 116 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 117 <script type="text/javascript"> 118 //<![CDATA[ 119 function safari_refresh() { 120 self.location.href= '<?php echo $refreshurl;?>'; 121 } 122 var issafari = false; 123 if (window.devicePixelRatio) { 124 issafari = true; 125 setTimeout('safari_refresh()', <?php echo $CFG->chat_refresh_room * 1000;?>); 126 } 127 if (parent.msg && parent.msg.document.getElementById("msgStarted") == null) { 128 parent.msg.document.close(); 129 parent.msg.document.open("text/html","replace"); 130 parent.msg.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); 131 parent.msg.document.write("<html><head>"); 132 parent.msg.document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"); 133 parent.msg.document.write("<base target=\"_blank\" />"); 134 parent.msg.document.write("<?php echo addslashes_js($stylesheetshtml) ?>"); 135 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\"> <\/div>"); 136 } 137 <?php 138 $beep = false; 139 $refreshusers = false; 140 $us = array (); 141 if (($chatlasttime != $chatnewlasttime) and $messages) { 142 143 foreach ($messages as $message) { 144 $chatlastrow = ($chatlastrow + 1) % 2; 145 $formatmessage = chat_format_message($message, $chatuser->course, $USER, $chatlastrow); 146 if ($formatmessage->beep) { 147 $beep = true; 148 } 149 if ($formatmessage->refreshusers) { 150 $refreshusers = true; 151 } 152 $us[$message->userid] = $timenow - $message->timestamp; 153 echo "if(parent.msg)"; 154 echo "parent.msg.document.write('".addslashes_js($formatmessage->html)."\\n');\n"; 155 } 156 } 157 158 $chatuser->lastping = time(); 159 $DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id' => $chatuser->id)); 160 161 if ($refreshusers) { 162 ?> 163 var link = parent.users.document.getElementById('refreshLink'); 164 if (link != null) { 165 parent.users.location.href = link.href; 166 } 167 <?php 168 } else { 169 foreach ($us as $uid => $lastping) { 170 $min = (int) ($lastping / 60); 171 $sec = $lastping - ($min * 60); 172 $min = $min < 10 ? '0'.$min : $min; 173 $sec = $sec < 10 ? '0'.$sec : $sec; 174 $idle = $min.':'.$sec; 175 echo "if (parent.users && parent.users.document.getElementById('uidle{$uid}') != null) {". 176 "parent.users.document.getElementById('uidle{$uid}').innerHTML = '$idle';}\n"; 177 } 178 } 179 ?> 180 if (parent.input) { 181 var autoscroll = parent.input.document.getElementById('auto'); 182 if (parent.msg && autoscroll && autoscroll.checked) { 183 parent.msg.scroll(1,5000000); 184 } 185 } 186 //]]> 187 </script> 188 </head> 189 <body> 190 <?php 191 if ($beep) { 192 echo '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />'; 193 } 194 ?> 195 <a href="<?php echo $refreshurlamp ?>" name="refreshLink">Refresh link</a> 196 </body> 197 </html> 198 <?php 199 200 // Support HTTP Keep-Alive. 201 header("Content-Length: " . ob_get_length() ); 202 ob_end_flush(); 203 exit; 204
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |