| 1 |
efrain |
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 |
|
|
|
18 |
/**
|
|
|
19 |
* Library functions to facilitate the use of ajax JavaScript in Moodle.
|
|
|
20 |
*
|
|
|
21 |
* @package core
|
|
|
22 |
* @copyright 2009 Tim Hunt
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* @deprecated since Moodle 4.3
|
|
|
28 |
*/
|
| 1441 |
ariadna |
29 |
#[\core\attribute\deprecated('\'core_user/repository\' module', since: '4.3', mdl: 'MDL-76974', final: true)]
|
|
|
30 |
function user_preference_allow_ajax_update() {
|
|
|
31 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
| 1 |
efrain |
32 |
}
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Starts capturing output whilst processing an AJAX request.
|
|
|
36 |
*
|
|
|
37 |
* This should be used in combination with ajax_check_captured_output to
|
|
|
38 |
* report any captured output to the user.
|
|
|
39 |
*
|
|
|
40 |
* @return Boolean Returns true on success or false on failure.
|
|
|
41 |
*/
|
|
|
42 |
function ajax_capture_output() {
|
|
|
43 |
// Start capturing output in case of broken plugins.
|
|
|
44 |
return ob_start();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Check captured output for content. If the site has a debug level of
|
|
|
49 |
* debugdeveloper set, and the content is non-empty, then throw a coding
|
|
|
50 |
* exception which can be captured by the Y.IO request and displayed to the
|
|
|
51 |
* user.
|
|
|
52 |
*
|
|
|
53 |
* @return Any output that was captured.
|
|
|
54 |
*/
|
|
|
55 |
function ajax_check_captured_output() {
|
|
|
56 |
global $CFG;
|
|
|
57 |
|
|
|
58 |
// Retrieve the output - there should be none.
|
|
|
59 |
$output = ob_get_contents();
|
|
|
60 |
ob_end_clean();
|
|
|
61 |
|
|
|
62 |
if (!empty($output)) {
|
|
|
63 |
$message = 'Unexpected output whilst processing AJAX request. ' .
|
|
|
64 |
'This could be caused by trailing whitespace. Output received: ' .
|
|
|
65 |
var_export($output, true);
|
|
|
66 |
if ($CFG->debugdeveloper && !empty($output)) {
|
|
|
67 |
// Only throw an error if the site is in debugdeveloper.
|
|
|
68 |
throw new coding_exception($message);
|
|
|
69 |
}
|
|
|
70 |
error_log('Potential coding error: ' . $message);
|
|
|
71 |
}
|
|
|
72 |
return $output;
|
|
|
73 |
}
|