Skip to content

Commit

Permalink
remove json lib. depriciate Tools::json function use php function
Browse files Browse the repository at this point in the history
  • Loading branch information
shreesh arora committed Mar 5, 2021
1 parent 82b30db commit 659d5b3
Show file tree
Hide file tree
Showing 94 changed files with 381 additions and 1,248 deletions.
8 changes: 4 additions & 4 deletions admin/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@

if (Tools::isSubmit('getChildrenCategories') && Tools::isSubmit('id_category_parent')) {
$children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat'), Context::getContext()->language->id, null, Tools::getValue('use_shop_context'));
die(Tools::jsonEncode($children_categories));
die(json_encode($children_categories));
}

if (Tools::isSubmit('getNotifications')) {
$notification = new Notification;
die(Tools::jsonEncode($notification->getLastElements()));
die(json_encode($notification->getLastElements()));
}

if (Tools::isSubmit('updateElementEmployee') && Tools::getValue('updateElementEmployeeType')) {
Expand Down Expand Up @@ -111,7 +111,7 @@
$output[] = $result;
}

die(Tools::jsonEncode($output));
die(json_encode($output));
}

if (Tools::isSubmit('getZones')) {
Expand All @@ -121,7 +121,7 @@
}
$html .= '</select>';
$array = array('hasError' => false, 'errors' => '', 'data' => $html);
die(Tools::jsonEncode($array));
die(json_encode($array));
}

if (Tools::isSubmit('getEmailHTML') && $email = Tools::getValue('email')) {
Expand Down
4 changes: 2 additions & 2 deletions admin/ajax_products_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
}
}
$results = array_values($results);
echo Tools::jsonEncode($results);
echo json_encode($results);
} else {
Tools::jsonEncode(new stdClass);
json_encode(new stdClass);
}
4 changes: 2 additions & 2 deletions admin/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ function runAdminTab($tab, $ajax_mode = false)
}

// we can display the correct url
// die(Tools::jsonEncode(array(Translate::getAdminTranslation('Invalid security token'),$url)));
die(Tools::jsonEncode(Translate::getAdminTranslation('Invalid security token')));
// die(json_encode(array(Translate::getAdminTranslation('Invalid security token'),$url)));
die(json_encode(Translate::getAdminTranslation('Invalid security token')));
} else {
// If this is an XSS attempt, then we should only display a simple, secure page
if (ob_get_level() && ob_get_length() > 0) {
Expand Down
10 changes: 5 additions & 5 deletions classes/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -4317,7 +4317,7 @@ public function addWs($autodate = true, $null_values = false)
$postData = trim(file_get_contents('php://input'));
libxml_use_internal_errors(true);
$xml = simplexml_load_string(utf8_decode($postData));
$cartData = Tools::jsonDecode(Tools::jsonEncode($xml, true));
$cartData = json_decode(json_encode($xml, true));

$this->id_address_delivery = $cartData->cart->id_address;
$this->id_address_invoice = $cartData->cart->id_address;
Expand All @@ -4344,7 +4344,7 @@ public function updateWs($autodate = true, $null_values = false)
$postData = trim(file_get_contents('php://input'));
libxml_use_internal_errors(true);
$xml = simplexml_load_string(utf8_decode($postData));
$cartData = Tools::jsonDecode(Tools::jsonEncode($xml, true));
$cartData = json_decode(json_encode($xml, true));

$this->id_address_delivery = $cartData->cart->id_address;
$this->id_address_invoice = $cartData->cart->id_address;
Expand Down Expand Up @@ -4384,14 +4384,14 @@ public function setWsCartRooms($bookingRows)

$extraDemands = null;
foreach ($bookingRows as $booking) {
$booking = Tools::jsonDecode(Tools::jsonEncode($booking, true), true);
$booking = json_decode(json_encode($booking, true), true);
if (isset($booking['extra_demands']['extra_demand'])) {
$extraDemands = $booking['extra_demands']['extra_demand'];
if (isset($extraDemands['id_global_demand'])) {
$extraDemands = array($extraDemands);
}
// $extraDemands = Tools::jsonDecode($extraDemands, true);
$extraDemands = Tools::jsonEncode($extraDemands);
// $extraDemands = json_decode($extraDemands, true);
$extraDemands = json_encode($extraDemands);
}

// get room booking info
Expand Down
4 changes: 2 additions & 2 deletions classes/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public static function checkAndAddLanguage($iso_code, $lang_pack = false, $only_

// If the language pack has not been provided, retrieve it from prestashop.com
if (!$lang_pack) {
$lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$iso_code));
$lang_pack = json_decode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$iso_code));
}

// If a language pack has been found or provided, prefill the language object with the value
Expand Down Expand Up @@ -914,7 +914,7 @@ public static function downloadAndInstallLanguagePack($iso, $version = null, $pa

if (!$lang_pack_link = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='.$version.'&iso_lang='.Tools::strtolower((string)$iso))) {
$errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
} elseif (!$lang_pack = Tools::jsonDecode($lang_pack_link)) {
} elseif (!$lang_pack = json_decode($lang_pack_link)) {
$errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
} elseif (empty($lang_pack->error) && ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/'.$lang_pack->version.'/'.Tools::strtolower($lang_pack->iso_code.'.gzip')))) {
if (!@file_put_contents($file, $content)) {
Expand Down
2 changes: 1 addition & 1 deletion classes/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -5776,7 +5776,7 @@ public function setWsRoomTypeInfo()
libxml_use_internal_errors(true);
$xml = simplexml_load_string(utf8_decode($postData));

$roomtypeData = Tools::jsonDecode(Tools::jsonEncode($xml), true);
$roomtypeData = json_decode(json_encode($xml), true);

// set room map info for the hotel from request
return Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'htl_room_type` (`id_product`, `id_hotel`, `adult`, `children`, `date_add`, `date_upd`) VALUES ('.(int)$this->id.', '.(int) $roomtypeData['room_type']['id_hotel'].', '.(int) $roomtypeData['room_type']['adults'].', '.(int) $roomtypeData['room_type']['children'].', \''.date('Y-m-d h:i:s').'\', \''.date('Y-m-d h:i:s').'\')');
Expand Down
2 changes: 1 addition & 1 deletion classes/Referrer.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,6 @@ public static function getAjaxProduct($id_referrer, $id_product, $employee = nul
'percent_fee' => Tools::displayPrice($stats_sales['sales'] * $referrer->percent_fee / 100, $currency),
);

die('['.Tools::jsonEncode($json_array).']');
die('['.json_encode($json_array).']');
}
}
30 changes: 13 additions & 17 deletions classes/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ public static function fd($object, $type = 'log')

echo '
<script type="text/javascript">
console.'.$type.'('.Tools::jsonEncode($object).');
console.'.$type.'('.json_encode($object).');
</script>
';
}
Expand Down Expand Up @@ -2660,19 +2660,15 @@ public static function getDefaultIndexContent()
/**
* jsonDecode convert json string to php array / object
*
* @param string $json
* @param string $data
* @param bool $assoc (since 1.4.2.4) if true, convert to associativ array
* @return array
*/
public static function jsonDecode($json, $assoc = false)
public static function jsonDecode($data, $assoc = false, $depth = 512, $options = 0
)
{
if (function_exists('json_decode')) {
return json_decode($json, $assoc);
} else {
include_once(_PS_TOOL_DIR_.'json/json.php');
$pear_json = new Services_JSON(($assoc) ? SERVICES_JSON_LOOSE_TYPE : 0);
return $pear_json->decode($json);
}
Tools::displayAsDeprecated();
return json_decode($data, $assoc, $depth, $options);
}

/**
Expand All @@ -2681,15 +2677,15 @@ public static function jsonDecode($json, $assoc = false)
* @param array $data
* @return string json
*/
public static function jsonEncode($data)
public static function jsonEncode($data, $options = 0, $depth = 512)
{
if (function_exists('json_encode')) {
return json_encode($data);
} else {
include_once(_PS_TOOL_DIR_.'json/json.php');
$pear_json = new Services_JSON();
return $pear_json->encode($data);
Tools::displayAsDeprecated();
if (PHP_VERSION_ID < 50500) { /* PHP version < 5.5.0 */
return json_encode($data, $options);
}

return json_encode($data, $options, $depth);

}

/**
Expand Down
6 changes: 3 additions & 3 deletions classes/controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1803,14 +1803,14 @@ public function display()
}

if ($conf = Tools::getValue('conf')) {
$this->context->smarty->assign('conf', $this->json ? Tools::jsonEncode($this->_conf[(int)$conf]) : $this->_conf[(int)$conf]);
$this->context->smarty->assign('conf', $this->json ? json_encode($this->_conf[(int)$conf]) : $this->_conf[(int)$conf]);
}

foreach (array('errors', 'warnings', 'informations', 'confirmations') as $type) {
if (!is_array($this->$type)) {
$this->$type = (array)$this->$type;
}
$this->context->smarty->assign($type, $this->json ? Tools::jsonEncode(array_unique($this->$type)) : array_unique($this->$type));
$this->context->smarty->assign($type, $this->json ? json_encode(array_unique($this->$type)) : array_unique($this->$type));
}

if ($this->show_page_header_toolbar && !$this->lite_display) {
Expand All @@ -1824,7 +1824,7 @@ public function display()

$this->context->smarty->assign(
array(
'page' => $this->json ? Tools::jsonEncode($page) : $page,
'page' => $this->json ? json_encode($page) : $page,
'header' => $this->context->smarty->fetch($header_tpl),
'footer' => $this->context->smarty->fetch($footer_tpl),
)
Expand Down
2 changes: 1 addition & 1 deletion classes/helper/HelperList.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public function displayDetailsLink($token = null, $id, $name = null)
'token' => $token != null ? $token : $this->token,
'action' => self::$cache_lang['Details'],
'params' => $ajax_params,
'json_params' => Tools::jsonEncode($ajax_params)
'json_params' => json_encode($ajax_params)
));
return $tpl->fetch();
}
Expand Down
4 changes: 2 additions & 2 deletions classes/pdf/HTMLTemplateInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ protected function computeLayout($params)
*/
public function getContent()
{
$invoiceAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_INVOICE_ADDR_RULES'), true);
$deliveryAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true);
$invoiceAddressPatternRules = json_decode(Configuration::get('PS_INVCE_INVOICE_ADDR_RULES'), true);
$deliveryAddressPatternRules = json_decode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true);

$invoice_address = new Address((int)$this->order->id_address_invoice);
$country = new Country((int)$invoice_address->id_country);
Expand Down
2 changes: 1 addition & 1 deletion classes/tree/TreeToolbarSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function _renderData($data)
$html = '';

foreach ($data as $item) {
$html .= Tools::jsonEncode($item).',';
$html .= json_encode($item).',';
if (array_key_exists('children', $item) && !empty($item['children'])) {
$html .= $this->_renderData($item['children']);
}
Expand Down
2 changes: 1 addition & 1 deletion classes/tree/TreeToolbarSearchCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function _renderData($data)
$html = '';

foreach ($data as $item) {
$html .= Tools::jsonEncode($item).',';
$html .= json_encode($item).',';
if (array_key_exists('children', $item) && !empty($item['children'])) {
$html .= $this->_renderData($item['children']);
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminAddressesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public function ajaxProcess()
$customer = Customer::searchByName($email);
if (!empty($customer)) {
$customer = $customer['0'];
echo Tools::jsonEncode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company'])));
echo json_encode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company'])));
}
}
die;
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminAttributesGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function renderFormAttributes()
$associations = array();
}

$this->fields_form['shop_associations'] = Tools::jsonEncode($associations);
$this->fields_form['shop_associations'] = json_encode($associations);

$this->fields_form['input'][] = array(
'type' => 'color',
Expand Down
4 changes: 2 additions & 2 deletions controllers/admin/AdminCarrierWizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ protected function validateForm($die = true)
$return['errors'] = $this->errors;
}
if (count($this->errors) || $die) {
die(Tools::jsonEncode($return));
die(json_encode($return));
}
}

Expand Down Expand Up @@ -870,7 +870,7 @@ public function ajaxProcessFinishStep()
$return['id_carrier'] = $carrier->id;
}
}
die(Tools::jsonEncode($return));
die(json_encode($return));
}

protected function changeGroups($id_carrier, $delete = true)
Expand Down
10 changes: 5 additions & 5 deletions controllers/admin/AdminCartRulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function ajaxProcessLoadCartRules()
}
}
}
echo Tools::jsonEncode(array('html' => $html, 'next_link' => $next_link));
echo json_encode(array('html' => $html, 'next_link' => $next_link));
}

public function setMedia()
Expand Down Expand Up @@ -589,7 +589,7 @@ public function ajaxProcess()
)
ORDER BY c.`firstname`, c.`lastname` ASC
LIMIT 50');
die(Tools::jsonEncode($customers));
die(json_encode($customers));
}
// Both product filter (free product and product discount) search for products
if (Tools::isSubmit('giftProductFilter') || Tools::isSubmit('reductionProductFilter')) {
Expand All @@ -599,7 +599,7 @@ public function ajaxProcess()
$products,
$this->context->employee->id_profile
);
die(Tools::jsonEncode($products));
die(json_encode($products));
}
}

Expand Down Expand Up @@ -642,7 +642,7 @@ protected function searchProducts($search)
public function ajaxProcessSearchProducts()
{
$array = $this->searchProducts(Tools::getValue('product_search'));
$this->content = trim(Tools::jsonEncode($array));
$this->content = trim(json_encode($array));
}

public function renderForm()
Expand Down Expand Up @@ -771,6 +771,6 @@ public function displayAjaxSearchCartRuleVouchers()
if ($vouchers = CartRule::getCartsRuleByCode(Tools::getValue('q'), (int)$this->context->language->id, true)) {
$found = true;
}
echo Tools::jsonEncode(array('found' => $found, 'vouchers' => $vouchers));
echo json_encode(array('found' => $found, 'vouchers' => $vouchers));
}
}
Loading

0 comments on commit 659d5b3

Please sign in to comment.