From 0791d0034fae2699b616b27c307010a061b17b29 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 16 Mar 2011 18:53:46 -0400 Subject: [PATCH] return Ajax-y XML on exceptions --- lib/action.php | 5 +++++ lib/error.php | 29 ++++++++++++++++++++++++++++- lib/statusnet.php | 11 +++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/action.php b/lib/action.php index 51d7e8923e..20de71aec1 100644 --- a/lib/action.php +++ b/lib/action.php @@ -83,6 +83,11 @@ class Action extends HTMLOutputter // lawsuit function prepare($argarray) { $this->args =& common_copy_args($argarray); + + if ($this->boolean('ajax')) { + StatusNet::setAjax(true); + } + return true; } diff --git a/lib/error.php b/lib/error.php index d234ab92b2..4024a9affc 100644 --- a/lib/error.php +++ b/lib/error.php @@ -68,7 +68,11 @@ class ErrorAction extends InfoAction function showPage() { - if ($this->minimal) { + if (StatusNet::isAjax()) { + $this->extraHeaders(); + $this->ajaxErrorMsg(); + exit(); + } if ($this->minimal) { // Even more minimal -- we're in a machine API // and don't want to flood the output. $this->extraHeaders(); @@ -94,4 +98,27 @@ class ErrorAction extends InfoAction function showNoticeForm() { } + + /** + * Show an Ajax-y error message + * + * Goes back to the browser, where it's shown in a popup. + * + * @param string $msg Message to show + * + * @return void + */ + + function ajaxErrorMsg() + { + $this->startHTML('text/xml;charset=utf-8', true); + $this->elementStart('head'); + // TRANS: Page title after an AJAX error occurs on the send notice page. + $this->element('title', null, _('Ajax Error')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->element('p', array('id' => 'error'), $this->message); + $this->elementEnd('body'); + $this->elementEnd('html'); + } } diff --git a/lib/statusnet.php b/lib/statusnet.php index 4c2aacd8f7..648369ec44 100644 --- a/lib/statusnet.php +++ b/lib/statusnet.php @@ -31,6 +31,7 @@ class StatusNet { protected static $have_config; protected static $is_api; + protected static $is_ajax; protected static $plugins = array(); /** @@ -230,6 +231,16 @@ class StatusNet self::$is_api = $mode; } + public function isAjax() + { + return self::$is_ajax; + } + + public function setAjax($mode) + { + self::$is_ajax = $mode; + } + /** * Build default configuration array * @return array