Moving t3lib_TCEforms_inline::getJSON() to t3lib_div::array2json()
authorOliver Hader <oliver.hader@typo3.org>
Mon, 3 Sep 2007 08:14:48 +0000 (08:14 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 3 Sep 2007 08:14:48 +0000 (08:14 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2478 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/class.t3lib_tceforms.php
t3lib/class.t3lib_tceforms_inline.php

index a1cff67..e0cda65 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-09-03  Oliver Hader  <oh@inpublica.de>
+
+       * (trivial) Moving t3lib_TCEforms_inline::getJSON() to t3lib_div::array2json()
+
 2007-08-31  Michael Stucki  <michael@typo3.org>
 
        * (trivial) Cleanup of NEWS.txt
index 4d1dacb..c5c19dd 100755 (executable)
@@ -1705,6 +1705,21 @@ class t3lib_div {
                return $str;
        }
 
+       /**
+        * Creates recursively a JSON literal from a mulidimensional associative array.
+        * Uses Services_JSON (http://mike.teczno.com/JSON/doc/)
+        *
+        * @param       array           $jsonArray: The array to be transformed to JSON
+        * @return      string          JSON string
+        */
+       function array2json($jsonArray) {
+               if (!$GLOBALS['JSON']) {
+                       require_once(PATH_typo3.'contrib/json.php');
+                       $GLOBALS['JSON'] = t3lib_div::makeInstance('Services_JSON');
+               }
+               return $GLOBALS['JSON']->encode($jsonArray);
+       }
+
        /**
         * Removes dots "." from end of a key identifier of TypoScript styled array.
         * array('key.' => array('property.' => 'value')) --> array('key' => array('property' => 'value'))
index 51c47e3..b669c35 100755 (executable)
@@ -4737,13 +4737,13 @@ class t3lib_TCEforms    {
                        // add JS required for inline fields
                if (count($this->inline->inlineData)) {
                        $out .= '
-                       inline.addToDataArray('.$this->inline->getJSON($this->inline->inlineData).');
+                       inline.addToDataArray('.t3lib_div::array2json($this->inline->inlineData).');
                        ';
                }
                        // elements which are required or have a range definition:
                if (count($elements)) {
                        $out .= '
-                       TBE_EDITOR.addElements('.$this->inline->getJSON($elements).');
+                       TBE_EDITOR.addElements('.t3lib_div::array2json($elements).');
                        TBE_EDITOR.initRequired()
                        ';
                }
@@ -5501,7 +5501,7 @@ class t3lib_TCEforms      {
                if ($skipFirst) {
                        array_shift($result);
                }
-               return ($json ? $this->inline->getJSON($result) : $result);
+               return ($json ? t3lib_div::array2json($result) : $result);
        }
 }
 
index e8423bd..49e21c6 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2006 Oliver Hader <oh@inpublica.de>
+*  (c) 2006-2007 Oliver Hader <oh@inpublica.de>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -858,7 +858,7 @@ class t3lib_TCEforms_inline {
                                        "alert('Access denied');",
                                )
                        );
-                       return $this->getJSON($jsonArray);
+                       return t3lib_div::array2json($jsonArray);
                }
 
                        // Encode TCEforms AJAX response with utf-8:
@@ -901,7 +901,7 @@ class t3lib_TCEforms_inline {
                $this->fObj->popFromDynNestedStack();
 
                        // return the JSON string
-               return $this->getJSON($jsonArray);
+               return t3lib_div::array2json($jsonArray);
        }
 
 
@@ -1714,13 +1714,10 @@ class t3lib_TCEforms_inline {
         *
         * @param       array           $jsonArray: The array (or part of) to be transformed to JSON
         * @return      string          If $level>0: part of JSON literal; if $level==0: whole JSON literal wrapped with <script> tags
+        * @deprecated                  Since TYPO3 4.2: Moved to t3lib_div::array2json
         */
        function getJSON($jsonArray) {
-               if (!$GLOBALS['JSON']) {
-                       require_once(PATH_typo3.'contrib/json.php');
-                       $GLOBALS['JSON'] = t3lib_div::makeInstance('Services_JSON');
-               }
-               return $GLOBALS['JSON']->encode($jsonArray);
+               return t3lib_div::array2json($jsonArray);
        }