forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh.php
91 lines (75 loc) · 3.26 KB
/
refresh.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @author Luis Rodrigues and Martin Dougiamas
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package message
*/
require('../config.php');
require('lib.php');
define('MESSAGE_DEFAULT_REFRESH', 5);
require_login();
if (isguestuser()) {
redirect($CFG->wwwroot);
}
if (empty($CFG->messaging)) {
print_error('disabled', 'message');
}
$PAGE->set_pagelayout('popup');
$PAGE->set_title(get_string('messages', 'message').' - '.format_string($SITE->fullname));
$PAGE->set_url('/message/refresh.php');
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');
header('Pragma: no-cache');
header('Content-Type: text/html; charset=utf-8');
/// Script parameters
$userid = required_param('id', PARAM_INT);
$userfullname = strip_tags(required_param('name', PARAM_RAW));
$wait = optional_param('wait', MESSAGE_DEFAULT_REFRESH, PARAM_INT);
/*Get still to be read message, use message/lib.php function*/
$messages = message_get_popup_messages($USER->id, $userid);
$jsmessages = Array();
if ($messages ) {
foreach ($messages as $message) {
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
$options = new stdClass();
$options->para = false;
$options->newlines = true;
$printmessage = format_text($message->fullmessage, $message->fullmessageformat, $options, 0);
$printmessage = '<div class="message other"><span class="author">'.s($userfullname).'</span> '.
'<span class="time">['.$time.']</span>: '.
'<span class="content">'.$printmessage.'</span></div>';
$jsmessages[count($jsmessages)] = $printmessage;
}
if (get_user_preferences('message_beepnewmessage', 0)) {
$playbeep = true;
}
$wait = MESSAGE_DEFAULT_REFRESH;
} else {
if ($wait < 300) { // Until the wait is five minutes
$wait = ceil(1.2 * (float)$wait); // Exponential growth
}
}
$PAGE->requires->js_init_call('M.core_message.init_refresh_parent_frame', array(count($jsmessages), $jsmessages));
echo $OUTPUT->header();
if (!empty($playbeep)) {
echo '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
$PAGE->requires->js_function_call('parent.send.focus');
}
// Javascript for Mozilla to cope with the redirect bug from editor being on in this page
$PAGE->requires->js_init_call('M.core_message.init_refresh_page', array(($wait*1000), "refresh.php?id=$userid&name=".urlencode($userfullname)."&wait=$wait"));
echo $OUTPUT->footer();