From 8c0d5378418b6011304e48069a3975583a54409a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Nov 2014 23:45:32 +0100 Subject: [PATCH] [ticket/416] Add method for handling ajax requests B3P-416 --- acp/portal_module.php | 3 +-- portal/modules/manager.php | 41 +++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/acp/portal_module.php b/acp/portal_module.php index 60460a02..3b8e669a 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -542,8 +542,7 @@ class portal_module $this->template->set_filenames(array( 'body' => 'portal/acp_portal_modules.html') ); - $json_response = new \phpbb\json_response; - $json_response->send(array( + $this->modules_manager->handle_ajax_request(array( 'MESSAGE_BODY' => $this->template->assign_display('body'), 'MESSAGE_TITLE' => $this->user->lang['ADD_MODULE'], 'MESSAGE_TEXT' => $this->user->lang['ADD_MODULE'], diff --git a/portal/modules/manager.php b/portal/modules/manager.php index e5e07eb8..133b55e8 100644 --- a/portal/modules/manager.php +++ b/portal/modules/manager.php @@ -113,6 +113,23 @@ class manager } } + /** + * Handle ajax request. + * Method will return supplied data if request is an ajax request + * + * @param array $data Data to send + * + * @return null + */ + public function handle_ajax_request($data) + { + if ($this->request->is_ajax()) + { + $json_response = new \phpbb\json_response; + $json_response->send($data); + } + } + /** * Reset module settings to default options * @@ -188,11 +205,9 @@ class manager $this->cache->destroy('portal_modules'); - if ($this->request->is_ajax()) - { - $json_response = new \phpbb\json_response; - $json_response->send(array('success' => true)); - } + // Handle ajax requests + $this->handle_ajax_request(array('success' => true)); + redirect($this->u_action); // redirect in order to get rid of excessive URL parameters } @@ -499,15 +514,13 @@ class manager $this->cache->purge(); // make sure we don't get errors after re-adding a module - if ($this->request->is_ajax()) - { - $json_response = new \phpbb\json_response; - $json_response->send(array( - 'success' => true, - 'MESSAGE_TITLE' => $this->user->lang['INFORMATION'], - 'MESSAGE_TEXT' => $this->user->lang['SUCCESS_DELETE'], - )); - } + // Handle ajax request + $this->handle_ajax_request(array( + 'success' => true, + 'MESSAGE_TITLE' => $this->user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $this->user->lang['SUCCESS_DELETE'], + )); + trigger_error($this->user->lang['SUCCESS_DELETE'] . adm_back_link($this->u_action)); } else