mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 05:43:55 -07:00
ZF JSON
Убираем местные костыли по работе с JSON.
This commit is contained in:
parent
c69eec1b41
commit
067528b2d7
7 changed files with 9 additions and 89 deletions
2
ajax.php
2
ajax.php
|
@ -249,7 +249,7 @@ class ajax_common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$response_js = bb_json_encode($this->response);
|
$response_js = Zend\Json\Json::encode($this->response);
|
||||||
|
|
||||||
if (GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP'))
|
if (GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP'))
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,7 @@ if (!defined('IN_AJAX')) die(basename(__FILE__));
|
||||||
global $bf, $lang;
|
global $bf, $lang;
|
||||||
|
|
||||||
$user_id = (int) $this->request['user_id'];
|
$user_id = (int) $this->request['user_id'];
|
||||||
$new_opt = bb_json_decode($this->request['user_opt']);
|
$new_opt = Zend\Json\Json::decode($this->request['user_opt']);
|
||||||
|
|
||||||
if (!$user_id OR !$u_data = get_userdata($user_id))
|
if (!$user_id OR !$u_data = get_userdata($user_id))
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,8 +72,8 @@ $domain_name = 'torrentpier.me'; // enter here your primary domain name of your
|
||||||
$domain_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $domain_name;
|
$domain_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $domain_name;
|
||||||
|
|
||||||
// Version info
|
// Version info
|
||||||
$bb_cfg['tp_version'] = '2.1.4';
|
$bb_cfg['tp_version'] = '2.1.5';
|
||||||
$bb_cfg['tp_release_date'] = '26-11-2014';
|
$bb_cfg['tp_release_date'] = '**-12-2014';
|
||||||
$bb_cfg['tp_release_state'] = 'ALPHA';
|
$bb_cfg['tp_release_state'] = 'ALPHA';
|
||||||
$bb_cfg['tp_zf_version'] = '2.3.3';
|
$bb_cfg['tp_zf_version'] = '2.3.3';
|
||||||
|
|
||||||
|
|
|
@ -2287,7 +2287,7 @@ function get_poll_data_items_js ($topic_id)
|
||||||
}
|
}
|
||||||
foreach ($items as $k => $v)
|
foreach ($items as $k => $v)
|
||||||
{
|
{
|
||||||
$items[$k] = php2js($v);
|
$items[$k] = Zend\Json\Json::encode($v);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_array($topic_id) ? $items : $items[$topic_id];
|
return is_array($topic_id) ? $items : $items[$topic_id];
|
||||||
|
@ -2296,7 +2296,7 @@ function get_poll_data_items_js ($topic_id)
|
||||||
function poll_is_active ($t_data)
|
function poll_is_active ($t_data)
|
||||||
{
|
{
|
||||||
global $bb_cfg;
|
global $bb_cfg;
|
||||||
return ($t_data['topic_vote'] == 1 && $t_data['topic_time'] > TIMENOW - $bb_cfg['poll_max_days']*86400);
|
return ($t_data['topic_vote'] == 1 && $t_data['topic_time'] > TIMENOW - $bb_cfg['poll_max_days'] * 86400);
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_confirmation ($tpl_vars)
|
function print_confirmation ($tpl_vars)
|
||||||
|
@ -2373,86 +2373,6 @@ function caching_output ($enabled, $mode, $cache_var_name, $ttl = 300)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Ajax
|
|
||||||
//
|
|
||||||
/**
|
|
||||||
* Encode PHP var to JSON (PHP -> JS)
|
|
||||||
*/
|
|
||||||
function bb_json_encode ($data)
|
|
||||||
{
|
|
||||||
return json_encode($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decode JSON to PHP (JS -> PHP)
|
|
||||||
*/
|
|
||||||
function bb_json_decode ($data)
|
|
||||||
{
|
|
||||||
if (!is_string($data)) trigger_error('invalid argument for '. __FUNCTION__, E_USER_ERROR);
|
|
||||||
return json_decode($data, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -- from JsHttpRequest --
|
|
||||||
* Convert a PHP scalar, array or hash to JS scalar/array/hash. This function is
|
|
||||||
* an analog of json_encode(), but it can work with a non-UTF8 input and does not
|
|
||||||
* analyze the passed data. Output format must be fully JSON compatible.
|
|
||||||
*
|
|
||||||
* @param mixed $a Any structure to convert to JS.
|
|
||||||
* @return string JavaScript equivalent structure.
|
|
||||||
*/
|
|
||||||
function php2js ($a = false)
|
|
||||||
{
|
|
||||||
if (is_null($a)) return 'null';
|
|
||||||
if ($a === false) return 'false';
|
|
||||||
if ($a === true) return 'true';
|
|
||||||
if (is_scalar($a))
|
|
||||||
{
|
|
||||||
if (is_float($a))
|
|
||||||
{
|
|
||||||
// Always use "." for floats.
|
|
||||||
$a = str_replace(",", ".", strval($a));
|
|
||||||
}
|
|
||||||
// All scalars are converted to strings to avoid indeterminism.
|
|
||||||
// PHP's "1" and 1 are equal for all PHP operators, but
|
|
||||||
// JS's "1" and 1 are not. So if we pass "1" or 1 from the PHP backend,
|
|
||||||
// we should get the same result in the JS frontend (string).
|
|
||||||
// Character replacements for JSON.
|
|
||||||
static $jsonReplaces = array(
|
|
||||||
array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'),
|
|
||||||
array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'),
|
|
||||||
);
|
|
||||||
return '"'. str_replace($jsonReplaces[0], $jsonReplaces[1], $a) .'"';
|
|
||||||
}
|
|
||||||
$isList = true;
|
|
||||||
for ($i = 0, reset($a); $i < count($a); $i++, next($a))
|
|
||||||
{
|
|
||||||
if (key($a) !== $i)
|
|
||||||
{
|
|
||||||
$isList = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$result = array();
|
|
||||||
if ($isList)
|
|
||||||
{
|
|
||||||
foreach ($a as $v)
|
|
||||||
{
|
|
||||||
$result[] = php2js($v);
|
|
||||||
}
|
|
||||||
return '[ '. join(', ', $result) .' ]';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach ($a as $k => $v)
|
|
||||||
{
|
|
||||||
$result[] = php2js($k) .': '. php2js($v);
|
|
||||||
}
|
|
||||||
return '{ '. join(', ', $result) .' }';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function clean_title ($str, $replace_underscore = false)
|
function clean_title ($str, $replace_underscore = false)
|
||||||
{
|
{
|
||||||
$str = ($replace_underscore) ? str_replace('_', ' ', $str) : $str;
|
$str = ($replace_underscore) ? str_replace('_', ' ', $str) : $str;
|
||||||
|
|
|
@ -118,7 +118,7 @@ $template->assign_vars(array(
|
||||||
'USER_LANG' => $userdata['user_lang'],
|
'USER_LANG' => $userdata['user_lang'],
|
||||||
|
|
||||||
'INCLUDE_BBCODE_JS' => !empty($page_cfg['include_bbcode_js']),
|
'INCLUDE_BBCODE_JS' => !empty($page_cfg['include_bbcode_js']),
|
||||||
'USER_OPTIONS_JS' => (IS_GUEST) ? '{}' : bb_json_encode($user->opt_js),
|
'USER_OPTIONS_JS' => (IS_GUEST) ? '{}' : Zend\Json\Json::encode($user->opt_js),
|
||||||
|
|
||||||
'USE_TABLESORTER' => !empty($page_cfg['use_tablesorter']),
|
'USE_TABLESORTER' => !empty($page_cfg['use_tablesorter']),
|
||||||
|
|
||||||
|
|
|
@ -671,7 +671,7 @@ class user_common
|
||||||
}
|
}
|
||||||
else if (!empty($_COOKIE['opt_js']))
|
else if (!empty($_COOKIE['opt_js']))
|
||||||
{
|
{
|
||||||
$opt_js = bb_json_decode($_COOKIE['opt_js']);
|
$opt_js = Zend\Json\Json::decode($_COOKIE['opt_js']);
|
||||||
|
|
||||||
if (is_array($opt_js))
|
if (is_array($opt_js))
|
||||||
{
|
{
|
||||||
|
|
|
@ -190,7 +190,7 @@ else
|
||||||
|
|
||||||
if (IS_ADMIN)
|
if (IS_ADMIN)
|
||||||
{
|
{
|
||||||
$ajax_user_opt = bb_json_encode(array(
|
$ajax_user_opt = Zend\Json\Json::encode(array(
|
||||||
'dis_avatar' => bf($profiledata['user_opt'], 'user_opt', 'dis_avatar'),
|
'dis_avatar' => bf($profiledata['user_opt'], 'user_opt', 'dis_avatar'),
|
||||||
'dis_sig' => bf($profiledata['user_opt'], 'user_opt', 'dis_sig'),
|
'dis_sig' => bf($profiledata['user_opt'], 'user_opt', 'dis_sig'),
|
||||||
'dis_passkey' => bf($profiledata['user_opt'], 'user_opt', 'dis_passkey'),
|
'dis_passkey' => bf($profiledata['user_opt'], 'user_opt', 'dis_passkey'),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue