MDL-23739 improved ajax headers - now using application/json with the exception of...
authorPetr Skoda <skodak@moodle.org>
Tue, 10 Aug 2010 08:50:08 +0000 (08:50 +0000)
committerPetr Skoda <skodak@moodle.org>
Tue, 10 Aug 2010 08:50:08 +0000 (08:50 +0000)
comment/comment_ajax.php
enrol/ajax.php
files/filebrowser_ajax.php
lib/outputrenderers.php
mod/glossary/showentry.php
repository/draftfiles_ajax.php
repository/repository_ajax.php

index 57dbcbe..bb69d80 100644 (file)
@@ -40,6 +40,8 @@ $content   = optional_param('content',   '', PARAM_RAW);
 $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;
index eca45ef..07fa5e4 100644 (file)
@@ -51,6 +51,8 @@ require_login($course);
 require_capability('moodle/course:enrolreview', $context);
 require_sesskey();
 
+echo $OUTPUT->header(); // send headers
+
 $manager = new course_enrolment_manager($course);
 
 $outcome = new stdClass;
index 659568c..e971517 100755 (executable)
@@ -33,6 +33,8 @@ $action = optional_param('action', 'list', PARAM_ALPHA);
 
 require_login();
 
+echo $OUTPUT->header(); // send headers
+
 $err = new stdclass;
 if (isguestuser()) {
     $err->error = get_string('noguest');
index f25972a..94a8bff 100644 (file)
@@ -2593,18 +2593,36 @@ class core_renderer_ajax extends core_renderer {
                 $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) {
     }
 }
index f6e0b27..ac0ae06 100644 (file)
@@ -10,6 +10,8 @@ $displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR);
 $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);
 }
@@ -78,6 +80,7 @@ if ($entries) {
 }
 
 if ($ajax) {
+    echo $OUTPUT->header(); // send headers
     $result = new stdClass;
     $result->success = true;
     $result->entries = $entries;
index 1ca56a6..bbd658e 100755 (executable)
@@ -42,6 +42,8 @@ $filepath = optional_param('filepath', '/', PARAM_PATH);
 
 $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!!
 //
index f437321..22397fe 100755 (executable)
@@ -56,9 +56,7 @@ list($context, $course, $cm) = get_context_info_array($contextid);
 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');