Browse files

[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
  • Loading branch information...
1 parent c92b30d commit 7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0 @callumacrae callumacrae committed with igorw Aug 24, 2011
View
1 phpBB/common.php
@@ -74,7 +74,6 @@
// 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);
View
3 phpBB/includes/acp/acp_forums.php
@@ -258,7 +258,8 @@ function main($id, $mode)
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;
View
6 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,
View
23 phpBB/includes/json.php → phpBB/includes/json_response.php
@@ -20,40 +20,23 @@
* 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)
{
garbage_collection();
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);
- }
}
View
24 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 @@ function main($id, $mode)
}
}
}
-
- 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);
View
2 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();
}
});;

0 comments on commit 7a933bd

Please sign in to comment.