aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCallum Macrae <callum@lynxphp.com>2011-08-24 12:25:54 +0100
committerIgor Wiedler <igor@wiedler.ch>2012-03-31 02:09:14 +0200
commit7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0 (patch)
tree67de4f7f19dbde414388b731fb64751fb0092fe3
parentc92b30d66cbb2839369c04172eb5ae9bacd27a16 (diff)
downloadforums-7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0.tar
forums-7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0.tar.gz
forums-7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0.tar.bz2
forums-7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0.tar.xz
forums-7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0.zip
[ticket/10328] Renamed the JSON class, also now using autoloading.
It is no longer static, and uses autoloading. It has also been renamed from JSON to phpbb_json_response. PHPBB3-10328
-rw-r--r--phpBB/common.php1
-rw-r--r--phpBB/includes/acp/acp_forums.php3
-rw-r--r--phpBB/includes/functions.php6
-rw-r--r--phpBB/includes/json_response.php (renamed from phpBB/includes/json.php)23
-rw-r--r--phpBB/includes/ucp/ucp_zebra.php24
-rw-r--r--phpBB/styles/script.js2
6 files changed, 28 insertions, 31 deletions
diff --git a/phpBB/common.php b/phpBB/common.php
index 2c90ccf76c..129f7e4881 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -74,7 +74,6 @@ if (!empty($load_extensions) && function_exists('dl'))
// Include files
require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
-require($phpbb_root_path . 'includes/json.' . $phpEx);
require($phpbb_root_path . 'includes/session.' . $phpEx);
require($phpbb_root_path . 'includes/auth.' . $phpEx);
diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php
index 6c05b1e108..3a3b2021eb 100644
--- a/phpBB/includes/acp/acp_forums.php
+++ b/phpBB/includes/acp/acp_forums.php
@@ -258,7 +258,8 @@ class acp_forums
if ($request->is_ajax())
{
- JSON::send(array('success' => ($move_forum_name !== false)));
+ $json_response = new phpbb_json_response;
+ $json_response->send(array('success' => ($move_forum_name !== false)));
}
break;
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index b9ca30279f..afd901a296 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -2713,7 +2713,8 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo
if ($request->is_ajax())
{
$u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id;
- JSON::send(array(
+ $json_response = new phpbb_json_response;
+ $json_response->send(array(
'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title],
'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'],
@@ -3950,7 +3951,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
{
global $refresh_data;
- JSON::send(array(
+ $json_response = new phpbb_json_response;
+ $json_response->send(array(
'MESSAGE_TITLE' => $msg_title,
'MESSAGE_TEXT' => $msg_text,
'S_USER_WARNING' => ($errno == E_USER_WARNING) ? true : false,
diff --git a/phpBB/includes/json.php b/phpBB/includes/json_response.php
index 04472080d9..95d02e3c0e 100644
--- a/phpBB/includes/json.php
+++ b/phpBB/includes/json_response.php
@@ -20,25 +20,18 @@ if (!defined('IN_PHPBB'))
* JSON class
* @package phpBB3
*/
-class JSON
+class phpbb_json_response
{
- private static $data = array();
-
/**
* Send the data to the client and exit the script.
*
* @param array $data Any additional data to send.
* @param bool $exit Will exit the script if true.
*/
- public static function send($data = false, $exit = true)
+ public function send($data, $exit = true)
{
- if ($data)
- {
- self::add($data);
- }
-
header('Content-type: application/json');
- echo json_encode(self::$data);
+ echo json_encode($data);
if ($exit)
{
@@ -46,14 +39,4 @@ class JSON
exit_handler();
}
}
-
- /**
- * Saves some data to be written when JSON::send() is called.
- *
- * @param array $data Data to save to be sent.
- */
- public static function add($data)
- {
- self::$data = array_merge(self::$data, $data);
- }
}
diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php
index 3f0e97b48a..efe928b387 100644
--- a/phpBB/includes/ucp/ucp_zebra.php
+++ b/phpBB/includes/ucp/ucp_zebra.php
@@ -25,7 +25,7 @@ class ucp_zebra
function main($id, $mode)
{
- global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
+ global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx, $request;
$submit = (isset($_POST['submit']) || isset($_GET['add']) || isset($_GET['remove'])) ? true : false;
$s_hidden_fields = '';
@@ -198,13 +198,25 @@ class ucp_zebra
}
}
}
-
- if ($updated)
+
+ if ($request->is_ajax())
{
- JSON::add(array(
- 'message' => $user->lang[$l_mode . '_UPDATED'],
- 'success' => true
+ $message = ($updated) ? $user->lang[$l_mode . '_UPDATED'] : implode('<br />', $error);
+
+ $json_response = new phpbb_json_response;
+ $json_response->send(array(
+ 'success' => $updated,
+
+ 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
+ 'MESSAGE_TEXT' => $message,
+ 'REFRESH_DATA' => array(
+ 'time' => 3,
+ 'url' => $this->u_action
+ )
));
+ }
+ else if ($updated)
+ {
meta_refresh(3, $this->u_action);
$message = $user->lang[$l_mode . '_UPDATED'] . '<br />' . implode('<br />', $error) . ((sizeof($error)) ? '<br />' : '') . '<br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
trigger_error($message);
diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js
index 1b9262f585..8814d105e1 100644
--- a/phpBB/styles/script.js
+++ b/phpBB/styles/script.js
@@ -365,7 +365,7 @@ phpbb.add_ajax_callback('post_delete', function(el) {
}
}).add_ajax_callback('zebra', function(el, res) {
if (res.success) {
- $('.zebra').html(res.message);
+ $('.zebra').html(res.MESSAGE_TEXT);
$($('.zebra').get(1)).remove();
}
});;