From 375802d5942c84693a888d260c2d2923b1f6b6c1 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Thu, 19 Sep 2019 09:30:58 +0300 Subject: [PATCH 1/2] + ddTools::encodedStringToArray: Can take an array too (sometimes it's convenient to not think about it). --- modx.ddtools.class.php | 87 ++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 1dc2bc9..6bb4887 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -667,62 +667,67 @@ public static function escapeForJS($str){ /** * encodedStringToArray - * @version 1.0.3 (2018-06-26) + * @version 1.1 (2019-09-19) * * @desc Converts encoded strings to arrays. * Supported formats: * — JSON (https://en.wikipedia.org/wiki/JSON); * — Query string (https://en.wikipedia.org/wiki/Query_string). * - * @param $inputString {string} — Input string. @required + * @param $inputString {string_json|string_queryFormated} — Input string. @required * * @return {array} */ public static function encodedStringToArray($inputString){ $result = []; - if (!empty($inputString)){ - //JSON (first letter is “{” or “[”) - if (in_array( - substr( - $inputString, - 0, - 1 - ), - [ - '{', - '[' - ] - )){ - try { - $result = json_decode( + //If array is passed, just return it (sometimes it's convenient to not think about it) + if (is_array($inputString)){ + $result = $inputString; + }else{ + if (!empty($inputString)){ + //JSON (first letter is “{” or “[”) + if (in_array( + substr( $inputString, - true - ); - }catch (\Exception $e){ - //Flag - $result = []; + 0, + 1 + ), + [ + '{', + '[' + ] + )){ + try { + $result = json_decode( + $inputString, + true + ); + }catch (\Exception $e){ + //Flag + $result = []; + } } - } - - //Not JSON - if (empty($result)){ - //Query string (has the “=” sign) - if (strpos( - $inputString, - '=' - ) !== false){ - parse_str( + + //Not JSON + if (empty($result)){ + //Query string (has the “=” sign) + if (strpos( $inputString, - $result - ); - //The old deprecated format where string is separated by '||' and '::' - }else{ - $result = self::explodeAssoc($inputString); - - self::logEvent([ - 'message' => '

Strings separated by “::” && “||” in parameters are deprecated. Use JSON or Query string instead.

' - ]); + '=' + ) !== false){ + parse_str( + $inputString, + $result + ); + //The old deprecated format where string is separated by '||' and '::' + }else{ + $result = self::explodeAssoc($inputString); + + self::logEvent([ + 'message' => '

Strings separated by “::” && “||” in parameters are deprecated. Use JSON or Query string instead.

' + ]); + } } } } From 0c446b59be73b5ebd05b2da2de70133d9327c791 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Thu, 19 Sep 2019 09:38:12 +0300 Subject: [PATCH 2/2] Prerelease --- README.md | 1 + composer.json | 2 +- modx.ddtools.class.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e201072..07fd31a 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,6 @@ A library with various tools facilitating your work. * [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.0.10 * [PHP.libraries.phpThumb](http://phpthumb.sourceforge.net) 1.7.13-201406261000 (included) + ___ Visit the following [link](http://code.divandesign.biz/modx/ddtools) to read the documentation, instructions & changelog. \ No newline at end of file diff --git a/composer.json b/composer.json index d1f8f7e..be5923a 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "dd/modxevo-library-ddtools", "type": "modxevo-library-ddtools", - "version": "0.26.0", + "version": "0.27.0", "description": "A library with various tools facilitating your work.", "keywords": [ "modx", diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 6bb4887..297dda4 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -1,7 +1,7 @@