Skip to content

Commit

Permalink
MDL-23739 improved ajax headers - now using application/json with the…
Browse files Browse the repository at this point in the history
… exception of YUI upload
  • Loading branch information
skodak committed Aug 10, 2010
1 parent 09e8e6d commit bce08d9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions comment/comment_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
$itemid = optional_param('itemid', '', PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);

echo $OUTPUT->header(); // send headers

// initilising comment object
if (!empty($client_id)) {
$args = new stdclass;
Expand Down
2 changes: 2 additions & 0 deletions enrol/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
require_capability('moodle/course:enrolreview', $context);
require_sesskey();

echo $OUTPUT->header(); // send headers

$manager = new course_enrolment_manager($course);

$outcome = new stdClass;
Expand Down
2 changes: 2 additions & 0 deletions files/filebrowser_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

require_login();

echo $OUTPUT->header(); // send headers

$err = new stdclass;
if (isguestuser()) {
$err->error = get_string('noguest');
Expand Down
20 changes: 19 additions & 1 deletion lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2593,18 +2593,36 @@ public function fatal_error($message, $moreinfourl, $link, $backtrace, $debuginf
$e->stacktrace = format_backtrace($backtrace, true);
}
}
@header('Content-type: application/json');
$this->header();
return json_encode($e);
}

public function notification($message, $classes = 'notifyproblem') {
}

public function redirect_message($encodedurl, $message, $delay, $debugdisableredirect) {
}

public function header() {
// unfortunately YUI iframe upload does not support application/json
if (!empty($_FILES)) {
@header('Content-type: text/plain');
} else {
@header('Content-type: application/json');
}

/// Headers to make it not cacheable and json
@header('Cache-Control: no-store, no-cache, must-revalidate');
@header('Cache-Control: post-check=0, pre-check=0', false);
@header('Pragma: no-cache');
@header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
@header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
@header('Accept-Ranges: none');
}

public function footer() {
}

public function heading($text, $level = 2, $classes = 'main', $id = null) {
}
}
Expand Down
3 changes: 3 additions & 0 deletions mod/glossary/showentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
$popup = optional_param('popup',0, PARAM_INT);
$ajax = optional_param('ajax',0, PARAM_INT);

//TODO: do not make combined ajax+normal scripts (skodak)

if ($ajax && !defined('AJAX_SCRIPT')) {
define('AJAX_SCRIPT', true);
}
Expand Down Expand Up @@ -78,6 +80,7 @@
}

if ($ajax) {
echo $OUTPUT->header(); // send headers
$result = new stdClass;
$result->success = true;
$result->entries = $entries;
Expand Down
2 changes: 2 additions & 0 deletions repository/draftfiles_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

$user_context = get_context_instance(CONTEXT_USER, $USER->id);

echo $OUTPUT->header(); // send headers

//
//NOTE TO ALL DEVELOPERS: this script must deal only with draft area of current user, it has to use only file_storage and no file_browser!!
//
Expand Down
4 changes: 1 addition & 3 deletions repository/repository_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
require_login($course, false, $cm);
$PAGE->set_context($context);

/// Headers to make it not cacheable
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
echo $OUTPUT->header(); // send headers

if (!confirm_sesskey()) {
$err->error = get_string('invalidsesskey');
Expand Down

0 comments on commit bce08d9

Please sign in to comment.