From 66279e1a57b7d715f651c118637fdf257e2bf846 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 9 May 2015 20:48:14 +0200 Subject: [ticket/13827] Correctly return JSON instead of HTML when valled from AJAX PHPBB3-13827 --- phpBB/phpbb/controller/helper.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php index dc802751fb..8b86fb965d 100644 --- a/phpBB/phpbb/controller/helper.php +++ b/phpBB/phpbb/controller/helper.php @@ -212,12 +212,29 @@ class helper public function message($message, array $parameters = array(), $title = 'INFORMATION', $code = 200) { array_unshift($parameters, $message); + $message_text = call_user_func_array(array($this->user, 'lang'), $parameters); + $message_title = $this->user->lang($title); + + if ($this->request->is_ajax()) + { + global $refresh_data; + + $json_response = new \phpbb\json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $message_title, + 'MESSAGE_TEXT' => $message_text, + 'S_USER_WARNING' => false, + 'S_USER_NOTICE' => false, + 'REFRESH_DATA' => (!empty($refresh_data)) ? $refresh_data : null + )); + } + $this->template->assign_vars(array( - 'MESSAGE_TEXT' => call_user_func_array(array($this->user, 'lang'), $parameters), - 'MESSAGE_TITLE' => $this->user->lang($title), + 'MESSAGE_TEXT' => $message_text, + 'MESSAGE_TITLE' => $message_title, )); - return $this->render('message_body.html', $this->user->lang($title), $code); + return $this->render('message_body.html', $message_title, $code); } /** -- cgit v1.2.1 From 502214bf066237ac96009e727ab34ed4f4ddbbec Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 14 May 2015 17:13:47 +0200 Subject: [ticket/13827] Use JsonResponse instead of our hacky json_response with exit() PHPBB3-13827 --- phpBB/phpbb/controller/helper.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php index 8b86fb965d..a07a396e73 100644 --- a/phpBB/phpbb/controller/helper.php +++ b/phpBB/phpbb/controller/helper.php @@ -13,6 +13,7 @@ namespace phpbb\controller; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -219,14 +220,16 @@ class helper { global $refresh_data; - $json_response = new \phpbb\json_response; - $json_response->send(array( - 'MESSAGE_TITLE' => $message_title, - 'MESSAGE_TEXT' => $message_text, - 'S_USER_WARNING' => false, - 'S_USER_NOTICE' => false, - 'REFRESH_DATA' => (!empty($refresh_data)) ? $refresh_data : null - )); + return new JsonResponse( + array( + 'MESSAGE_TITLE' => $message_title, + 'MESSAGE_TEXT' => $message_text, + 'S_USER_WARNING' => false, + 'S_USER_NOTICE' => false, + 'REFRESH_DATA' => (!empty($refresh_data)) ? $refresh_data : null + ), + $code + ); } $this->template->assign_vars(array( -- cgit v1.2.1