From ea798c23152bd11e69310067e55be7d3836a0c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 23 Apr 2015 23:29:31 +0200 Subject: [PATCH] Qual: deprecate dol_json_encode() and dol_json_decode() PHP > 5.3 supports json_encode() and json_decode() natively --- htdocs/comm/action/card.php | 24 ++++++++++++------------ htdocs/comm/action/document.php | 4 ++-- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/lib/json.lib.php | 2 ++ htdocs/filefunc.inc.php | 27 +++++++++++---------------- 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index fcb3444be10..0b75ea73e98 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -96,7 +96,7 @@ if (GETPOST('removedassigned') || GETPOST('removedassigned') == '0') { $idtoremove=GETPOST('removedassigned'); - if (! empty($_SESSION['assignedtouser'])) $tmpassigneduserids=dol_json_decode($_SESSION['assignedtouser'],1); + if (! empty($_SESSION['assignedtouser'])) $tmpassigneduserids=json_decode($_SESSION['assignedtouser'],1); else $tmpassigneduserids=array(); foreach ($tmpassigneduserids as $key => $val) @@ -104,7 +104,7 @@ if (GETPOST('removedassigned') || GETPOST('removedassigned') == '0') if ($val['id'] == $idtoremove || $val['id'] == -1) unset($tmpassigneduserids[$key]); } //var_dump($_POST['removedassigned']);exit; - $_SESSION['assignedtouser']=dol_json_encode($tmpassigneduserids); + $_SESSION['assignedtouser']=json_encode($tmpassigneduserids); $donotclearsession=1; if ($action == 'add') $action = 'create'; if ($action == 'update') $action = 'edit'; @@ -119,10 +119,10 @@ if (GETPOST('addassignedtouser') || GETPOST('updateassignedtouser')) $assignedtouser=array(); if (! empty($_SESSION['assignedtouser'])) { - $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); + $assignedtouser=json_decode($_SESSION['assignedtouser'], true); } $assignedtouser[GETPOST('assignedtouser')]=array('id'=>GETPOST('assignedtouser'), 'transparency'=>GETPOST('transparency'),'mandatory'=>1); - $_SESSION['assignedtouser']=dol_json_encode($assignedtouser); + $_SESSION['assignedtouser']=json_encode($assignedtouser); } $donotclearsession=1; if ($action == 'add') $action = 'create'; @@ -215,7 +215,7 @@ if ($action == 'add') $object->duree=((float) (GETPOST('dureehour') * 60) + (float) GETPOST('dureemin')) * 60; $listofuserid=array(); - if (! empty($_SESSION['assignedtouser'])) $listofuserid=dol_json_decode($_SESSION['assignedtouser']); + if (! empty($_SESSION['assignedtouser'])) $listofuserid=json_decode($_SESSION['assignedtouser']); $i=0; foreach($listofuserid as $key => $value) { @@ -387,7 +387,7 @@ if ($action == 'update') if (! empty($_SESSION['assignedtouser'])) // Now concat assigned users { // Restore array with key with same value than param 'id' - $tmplist1=dol_json_decode($_SESSION['assignedtouser'], true); $tmplist2=array(); + $tmplist1=json_decode($_SESSION['assignedtouser'], true); $tmplist2=array(); foreach($tmplist1 as $key => $val) { if ($val['id'] > 0 && $val['id'] != $assignedtouser) $listofuserid[$val['id']]=$val; @@ -677,13 +677,13 @@ if ($action == 'create') { $assignedtouser=GETPOST("assignedtouser")?GETPOST("assignedtouser"):(! empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : $user->id); if ($assignedtouser) $listofuserid[$assignedtouser]=array('id'=>$assignedtouser,'mandatory'=>0,'transparency'=>$object->transparency); // Owner first - $_SESSION['assignedtouser']=dol_json_encode($listofuserid); + $_SESSION['assignedtouser']=json_encode($listofuserid); } else { if (!empty($_SESSION['assignedtouser'])) { - $listofuserid=dol_json_decode($_SESSION['assignedtouser'], true); + $listofuserid=json_decode($_SESSION['assignedtouser'], true); } } print $form->select_dolusers_forevent(($action=='create'?'add':'update'), 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0'); @@ -929,13 +929,13 @@ if ($id > 0) if ($val['id'] && $val['id'] != $object->userownerid) $listofuserid[$val['id']]=$val; } } - $_SESSION['assignedtouser']=dol_json_encode($listofuserid); + $_SESSION['assignedtouser']=json_encode($listofuserid); } else { if (!empty($_SESSION['assignedtouser'])) { - $listofuserid=dol_json_decode($_SESSION['assignedtouser'], true); + $listofuserid=json_decode($_SESSION['assignedtouser'], true); } } print $form->select_dolusers_forevent(($action=='create'?'add':'update'), 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0'); @@ -1101,13 +1101,13 @@ if ($id > 0) if ($val['id'] && $val['id'] != $object->userownerid) $listofuserid[$val['id']]=$val; } } - $_SESSION['assignedtouser']=dol_json_encode($listofuserid); + $_SESSION['assignedtouser']=json_encode($listofuserid); } else { if (!empty($_SESSION['assignedtouser'])) { - $listofuserid=dol_json_decode($_SESSION['assignedtouser'], true); + $listofuserid=json_decode($_SESSION['assignedtouser'], true); } } print $form->select_dolusers_forevent('view','assignedtouser',1); diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php index 598b02ef0b8..d45a18e3e8c 100644 --- a/htdocs/comm/action/document.php +++ b/htdocs/comm/action/document.php @@ -186,13 +186,13 @@ if ($object->id > 0) if ($val['id'] && $val['id'] != $object->userownerid) $listofuserid[$val['id']]=$val; } } - $_SESSION['assignedtouser']=dol_json_encode($listofuserid); + $_SESSION['assignedtouser']=json_encode($listofuserid); } else { if (!empty($_SESSION['assignedtouser'])) { - $listofuserid=dol_json_decode($_SESSION['assignedtouser'], true); + $listofuserid=json_decode($_SESSION['assignedtouser'], true); } } print $form->select_dolusers_forevent('view','assignedtouser',1); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 3b1e9ce5630..66d2a5a3463 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1462,7 +1462,7 @@ class Form $assignedtouser=array(); if (!empty($_SESSION['assignedtouser'])) { - $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); + $assignedtouser=json_decode($_SESSION['assignedtouser'], true); } $nbassignetouser=count($assignedtouser); diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index 121e719bb6f..e3f00a064e5 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -42,6 +42,7 @@ if (! function_exists('json_encode')) * * @param mixed $elements PHP Object to json encode * @return string Json encoded string + * @deprecated PHP >= 5.3 supports native json_encode */ function dol_json_encode($elements) { @@ -219,6 +220,7 @@ if (! function_exists('json_decode')) * @param string $json Json encoded to PHP Object or Array * @param bool $assoc False return an object, true return an array. Try to always use it with true ! * @return mixed Object or Array or false on error + * @deprecated PHP >= 5.3 supports native json_decode */ function dol_json_decode($json, $assoc=false) { diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 7c0e9f14a0b..45ba2b24f8c 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -37,22 +37,17 @@ if (! defined('EURO')) define('EURO',chr(128)); // Define syslog constants if (! defined('LOG_DEBUG')) { - if (function_exists("define_syslog_variables")) - { - define_syslog_variables(); // Deprecated since php 5.3.0, syslog variables no longer need to be initialized - } - else - { - // Pour PHP sans syslog (comme sous Windows) - define('LOG_EMERG',0); - define('LOG_ALERT',1); - define('LOG_CRIT',2); - define('LOG_ERR',3); - define('LOG_WARNING',4); - define('LOG_NOTICE',5); - define('LOG_INFO',6); - define('LOG_DEBUG',7); - } + if (! function_exists("syslog")) { + // For PHP versions without syslog (like running on Windows OS) + define('LOG_EMERG',0); + define('LOG_ALERT',1); + define('LOG_CRIT',2); + define('LOG_ERR',3); + define('LOG_WARNING',4); + define('LOG_NOTICE',5); + define('LOG_INFO',6); + define('LOG_DEBUG',7); + } } // End of common declaration part