From 1aff2c0fa5904987487ce0e48774250766771533 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Thu, 12 Feb 2009 19:19:48 +0100 Subject: [PATCH] Moved sendHTTPResponse() and prepareResponse() to Horde. --- imp/ajax.php | 4 ++-- imp/compose-dimp.php | 4 ++-- imp/imple.php | 6 +++--- imp/lib/DIMP.php | 27 -------------------------- imp/lib/IMP.php | 55 ---------------------------------------------------- imp/lib/base.php | 2 +- 6 files changed, 8 insertions(+), 90 deletions(-) diff --git a/imp/ajax.php b/imp/ajax.php index 098d04f7a..6bbf92246 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -1,6 +1,6 @@ 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; } diff --git a/imp/imple.php b/imp/imple.php index c820c896b..3285ff6e8 100644 --- a/imp/imple.php +++ b/imp/imple.php @@ -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); diff --git a/imp/lib/DIMP.php b/imp/lib/DIMP.php index e36c4557d..f2e110772 100644 --- a/imp/lib/DIMP.php +++ b/imp/lib/DIMP.php @@ -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. diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index e2378eee1..9dc917731 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -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. */ diff --git a/imp/lib/base.php b/imp/lib/base.php index 1d354863e..de46fb298 100644 --- a/imp/lib/base.php +++ b/imp/lib/base.php @@ -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; -- 2.11.0