Moved sendHTTPResponse() and prepareResponse() to Horde.
authorJan Schneider <jan@horde.org>
Thu, 12 Feb 2009 18:19:48 +0000 (19:19 +0100)
committerJan Schneider <jan@horde.org>
Fri, 13 Feb 2009 00:47:55 +0000 (01:47 +0100)
imp/ajax.php
imp/compose-dimp.php
imp/imple.php
imp/lib/DIMP.php
imp/lib/IMP.php
imp/lib/base.php

index 098d04f..6bbf922 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * imp.php - performs the AJAX-requested action.
+ * Performs the AJAX-requested action.
  *
  * Copyright 2005-2009 The Horde Project (http://www.horde.org/)
  *
@@ -758,4 +758,4 @@ if ($errors) {
 }
 
 // Send the final result.
-IMP::sendHTTPResponse(DIMP::prepareResponse($result, $notify), 'json');
+Horde::sendHTTPResponse(Horde::prepareResponse($result, $notify ? $GLOBALS['imp_notify'] : null), 'json');
index d12fcbe..5b4f9c7 100644 (file)
@@ -69,7 +69,7 @@ if (count($_POST)) {
             $result->info = end($info);
             $result->imp_compose = $imp_compose->getCacheId();
         }
-        IMP::sendHTTPResponse(DIMP::prepareResponse($result, true, false), 'js-json');
+        Horde::sendHTTPResponse(Horde::prepareResponse($result, $GLOBALS['imp_notify'], false), 'js-json');
         exit;
     }
 
@@ -174,7 +174,7 @@ if (count($_POST)) {
         }
     }
 
-    IMP::sendHTTPResponse(DIMP::prepareResponse($result, !$result->success || !Util::getFormData('nonotify'), false), 'json');
+    Horde::sendHTTPResponse(Horde::prepareResponse($result, !$result->success || !Util::getFormData('nonotify')  ? $GLOBALS['imp_notify'] : null, false), 'json');
     exit;
 }
 
index c820c89..3285ff6 100644 (file)
@@ -20,7 +20,7 @@ $viewmode = $_SESSION['imp']['view'];
 
 if (!($path = Util::getFormData('imple'))) {
     if ($viewmode == 'dimp') {
-        IMP::sendHTTPResponse(new stdClass(), 'json');
+        Horde::sendHTTPResponse(new stdClass(), 'json');
     }
     exit;
 }
@@ -34,7 +34,7 @@ $impleName = reset($path);
 
 if (!($imple = IMP_Imple::factory($impleName))) {
     if ($viewmode == 'dimp') {
-        IMP::sendHTTPResponse(new stdClass(), 'json');
+        Horde::sendHTTPResponse(new stdClass(), 'json');
     }
     exit;
 }
@@ -55,4 +55,4 @@ $ct = empty($_SERVER['Content-Type'])
     ? (is_string($result) ? 'plain' : 'json')
     : $_SERVER['Content-Type'];
 
-IMP::sendHTTPResponse($result, $ct);
+Horde::sendHTTPResponse($result, $ct);
index e36c455..f2e1107 100644 (file)
@@ -434,33 +434,6 @@ class DIMP
     }
 
     /**
-     * Returns a stdClass response object with added notification information.
-     *
-     * @param string $data     The 'response' data.
-     * @param boolean $notify  If true, adds notification information to
-     *                         object.
-     * @param boolean $auto    If true, DimpCore will automatically display the
-     *                         notification.  If false, the callback handler
-     *                         is responsible for displaying the notification.
-     */
-    public function prepareResponse($data = null, $notify = true, $auto = true)
-    {
-        $response = new stdClass();
-        $response->response = $data;
-        if ($notify) {
-            $GLOBALS['notification']->notify(array('listeners' => 'status'));
-            $stack = $GLOBALS['imp_notify']->getStack();
-            if (!empty($stack)) {
-                $response->msgs = $GLOBALS['imp_notify']->getStack();
-                if (!(bool)$auto) {
-                    $response->msgs_noauto = true;
-                }
-            }
-        }
-        return $response;
-    }
-
-    /**
      * Return information about the current attachments for a message
      *
      * @param IMP_Compose $imp_compose  An IMP_Compose object.
index e2378ee..9dc9177 100644 (file)
@@ -1439,61 +1439,6 @@ class IMP
     }
 
     /**
-     * Send response data to browser.
-     *
-     * @param mixed $data  The data to serialize and send to the browser.
-     * @param string $ct   The content-type to send the data with.  Either
-     *                     'json', 'js-json', 'html', 'plain', and 'xml'.
-     */
-    static public function sendHTTPResponse($data, $ct)
-    {
-        $charset = NLS::getCharset();
-
-        // Output headers and encoded response.
-        switch ($ct) {
-        case 'json':
-        case 'js-json':
-            /* JSON responses are a structured object which always
-             * includes the response in a member named 'response', and an
-             * additional array of messages in 'msgs' which may be updates
-             * for the server or notification messages.
-             *
-             * Make sure no null bytes sneak into the JSON output stream.
-             * Null bytes cause IE to stop reading from the input stream,
-             * causing malformed JSON data and a failed request.  These
-             * bytes don't seem to break any other browser, but might as
-             * well remove them anyway.
-             *
-             * Finally, add prototypejs security delimiters to returned
-             * JSON. */
-            $s_data = '/*-secure-' .
-                String::convertCharset(str_replace("\00", '', Horde_Serialize::serialize($data, SERIALIZE_JSON, $charset)), 'UTF-8') .
-                '*/';
-
-            if ($ct == 'json') {
-                header('Content-Type: application/json');
-                echo $s_data;
-            } else {
-                header('Content-Type: text/html; charset=' . $charset);
-                echo htmlspecialchars($s_data);
-            }
-            break;
-
-        case 'html':
-        case 'plain':
-        case 'xml':
-            header('Content-Type: text/' . $ct . '; charset=' . $charset);
-            echo $data;
-            break;
-
-        default:
-            echo $data;
-        }
-
-        exit;
-    }
-
-    /**
      * Outputs the necessary script tags, honoring local configuration
      * choices as to script caching.
      */
index 1d35486..de46fb2 100644 (file)
@@ -146,7 +146,7 @@ if ($authentication !== 'none') {
             switch (Util::nonInputVar('session_timeout')) {
             case 'json':
                 $notification->push(null, 'dimp.timeout');
-                IMP::sendHTTPResponse(DIMP::prepareResponse(), 'json');
+                Horde::sendHTTPResponse(Horde::prepareResponse(), 'json');
 
             case 'none':
                 exit;