[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [16321] handling json values for database
From: |
sigurdne |
Subject: |
[Fmsystem-commits] [16321] handling json values for database |
Date: |
Thu, 16 Feb 2017 10:59:36 -0500 (EST) |
Revision: 16321
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=16321
Author: sigurdne
Date: 2017-02-16 10:59:36 -0500 (Thu, 16 Feb 2017)
Log Message:
-----------
handling json values for database
Modified Paths:
--------------
trunk/phpgwapi/inc/class.db.inc.php
trunk/phpgwapi/inc/class.db_pdo.inc.php
trunk/property/inc/class.soadmin_entity.inc.php
Modified: trunk/phpgwapi/inc/class.db.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.db.inc.php 2017-02-16 11:42:45 UTC (rev 16320)
+++ trunk/phpgwapi/inc/class.db.inc.php 2017-02-16 15:59:36 UTC (rev 16321)
@@ -408,8 +408,12 @@
$insert_value = array();
foreach ( $values as $value )
{
- if($value || (is_numeric($value) && $value ==
0) )
+ if($value && $this->isJson($value))
{
+ $insert_value[] = "'" .
$this->db_addslashes($value) . "'";
+ }
+ else if($value || (is_numeric($value) && $value
== 0) )
+ {
if ( is_numeric($value) )
{
$insert_value[] = "'{$value}'";
@@ -419,10 +423,6 @@
$insert_value[] = "'" .
$this->db_addslashes(stripslashes($value)) . "'"; //in case slashes are already
added.
}
}
- else if($value && $this->isJson($value))
- {
- $insert_value[] = "'{$value}'";
- }
else
{
$insert_value[] = 'NULL';
@@ -433,6 +433,10 @@
final public function isJson($string)
{
+ if(!preg_match('/^{/', $string))
+ {
+ return false;
+ }
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
@@ -453,8 +457,12 @@
$value_entry = array();
foreach ( $value_set as $field => $value )
{
- if($value || (is_numeric($value) && $value ==
0) )
+ if($value && $this->isJson($value))
{
+ $value_entry[]= "{$field}='" .
$this->db_addslashes($value) . "'";
+ }
+ else if($value || (is_numeric($value) && $value
== 0) )
+ {
if ( is_numeric($value) )
{
if((strlen($value) > 1 &&
strpos($value,'0') === 0))
@@ -468,13 +476,9 @@
}
else
{
- $value_entry[]=
"{$field}='{$value}'";
+ $value_entry[]= "{$field}='" .
$this->db_addslashes(stripslashes($value)) . "'"; //in case slashes are already
added.
}
}
- else if($value && $this->isJson($value))
- {
- $value_entry[]= "{$field}='{$value}'";
- }
else
{
$value_entry[]= "{$field}=NULL";
@@ -483,6 +487,15 @@
return implode(',', $value_entry);
}
+ final public function stripslashes( $value )
+ {
+ $str = preg_replace_callback('/u([0-9a-fA-F]{4})/',
function ($match)
+ {
+ return mb_convert_encoding(pack('H*',
$match[1]), 'UTF-8', 'UTF-16BE');
+ }, $value);
+
+ return
htmlspecialchars_decode(stripslashes(str_replace(array('&','(',
')', '=','−−',';'), array('&','(', ')', '=', '--',';'),
$str)),ENT_QUOTES);
+ }
/**
* Get the number of rows affected by last update
*
Modified: trunk/phpgwapi/inc/class.db_pdo.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.db_pdo.inc.php 2017-02-16 11:42:45 UTC (rev
16320)
+++ trunk/phpgwapi/inc/class.db_pdo.inc.php 2017-02-16 15:59:36 UTC (rev
16321)
@@ -831,11 +831,7 @@
{
if ($strip_slashes ||
($this->auto_stripslashes && ! $strip_slashes))
{
- // $str =
preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match){
- $str =
preg_replace_callback('/u([0-9a-fA-F]{4})/', function ($match){
- return
mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UTF-16BE');
- }, $this->Record[$name]);
- return
htmlspecialchars_decode(stripslashes(str_replace(array('&','(',
')', '=','−−',';'), array('&','(', ')', '=', '--',';'),
$str)),ENT_QUOTES);
+ return
parent::stripslashes($this->Record[$name]);
}
else
{
Modified: trunk/property/inc/class.soadmin_entity.inc.php
===================================================================
--- trunk/property/inc/class.soadmin_entity.inc.php 2017-02-16 11:42:45 UTC
(rev 16320)
+++ trunk/property/inc/class.soadmin_entity.inc.php 2017-02-16 15:59:36 UTC
(rev 16321)
@@ -1190,6 +1190,14 @@
{
$data =
$this->db2->Record;
+ if($data)
+ {
+ foreach ($data
as $key => &$value)
+ {
+ $value
= $value === null ? null : $this->db->stripslashes($value);
+ }
+ }
+
$p_location_id = '';
if ($data['p_cat_id'])
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [16321] handling json values for database,
sigurdne <=