ActionController: create postDispatchXhr

Moved XHR-specific stuff to a dedicated post-dispatch function
This commit is contained in:
Thomas Gelf 2014-06-22 15:15:32 +02:00
parent cf995b366b
commit 631603aba3

View File

@ -362,7 +362,6 @@ class ActionController extends Zend_Controller_Action
Benchmark::measure('Action::postDispatch()'); Benchmark::measure('Action::postDispatch()');
$req = $this->getRequest(); $req = $this->getRequest();
$resp = $this->getResponse();
$layout = $this->_helper->layout(); $layout = $this->_helper->layout();
$layout->moduleName = false; $layout->moduleName = false;
@ -382,45 +381,52 @@ class ActionController extends Zend_Controller_Action
} }
if ($req->isXmlHttpRequest()) { if ($req->isXmlHttpRequest()) {
$layout->setLayout('inline'); $this->postDispatchXhr();
}
}
$notifications = Notification::getInstance(); protected function postDispatchXhr()
if ($notifications->hasMessages()) { {
$notificationList = array(); $layout = $this->_helper->layout();
foreach ($notifications->getMessages() as $m) { $layout->setLayout('inline');
$notificationList[] = rawurlencode($m->type . ' ' . $m->message); $resp = $this->getResponse();
}
$resp->setHeader('X-Icinga-Notification: ' . implode('&', $notificationList));
}
if ($this->reloadCss || $this->getParam('_reload') === 'css') { $notifications = Notification::getInstance();
$resp->setHeader('X-Icinga-CssReload', 'now'); if ($notifications->hasMessages()) {
$notificationList = array();
foreach ($notifications->getMessages() as $m) {
$notificationList[] = rawurlencode($m->type . ' ' . $m->message);
} }
$resp->setHeader('X-Icinga-Notification: ' . implode('&', $notificationList));
}
if ($this->noXhrBody) { if ($this->reloadCss || $this->getParam('_reload') === 'css') {
$resp->setHeader('X-Icinga-Container', 'ignore'); $resp->setHeader('X-Icinga-CssReload', 'now');
return; }
}
if ($this->view->title) { if ($this->noXhrBody) {
if (preg_match('~[\r\n]~', $this->view->title)) { $resp->setHeader('X-Icinga-Container', 'ignore');
// TODO: Innocent exception and error log for hack attempts return;
throw new Exception('No way, guy'); }
}
$resp->setHeader(
'X-Icinga-Title',
rawurlencode($this->view->title . ' :: Icinga Web')
);
}
if ($this->getParam('_render') === 'layout') { if ($this->view->title) {
$layout->setLayout('body'); if (preg_match('~[\r\n]~', $this->view->title)) {
$resp->setHeader('X-Icinga-Container', 'layout'); // TODO: Innocent exception and error log for hack attempts
throw new Exception('No way, guy');
} }
$resp->setHeader(
'X-Icinga-Title',
rawurlencode($this->view->title . ' :: Icinga Web')
);
}
if ($this->autorefreshInterval !== null) { if ($this->getParam('_render') === 'layout') {
$resp->header('X-Icinga-Refresh', $this->autorefreshInterval); $layout->setLayout('body');
} $resp->setHeader('X-Icinga-Container', 'layout');
}
if ($this->autorefreshInterval !== null) {
$resp->setHeader('X-Icinga-Refresh', $this->autorefreshInterval);
} }
} }