blob: 04472080d95b8a34c1e537e96509f375ed4cdb44 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* JSON class
* @package phpBB3
*/
class JSON
{
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)
{
if ($data)
{
self::add($data);
}
header('Content-type: application/json');
echo json_encode(self::$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);
}
}
|