Fixed bug #9286: Use native JSON-methods instead of 3rd party JSON script
authorOliver Hader <oliver.hader@typo3.org>
Mon, 3 Nov 2008 16:57:00 +0000 (16:57 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 3 Nov 2008 16:57:00 +0000 (16:57 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4413 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/class.t3lib_tceforms.php
t3lib/class.t3lib_tceforms_inline.php
typo3/alt_shortcut.php
typo3/class.browse_links.php
typo3/classes/class.typo3ajax.php
typo3/contrib/json/json.php
typo3/sysext/rtehtmlarea/class.tx_rtehtmlarea_base.php

index 2c95b82..d263d6f 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
        * Added feature #9654: Enable includeLibs also for USER and COA objects
        * Fixed bug #9724: Editing shortcuts does not work anymore
+       * Fixed bug #9286: Use native JSON-methods instead of 3rd party JSON script (thanks to Steffen Kamper)
 
 2008-11-01  Martin Kutschker  <masi@typo3.org>
 
index a6aa303..ebcf285 100755 (executable)
@@ -1863,19 +1863,16 @@ final class t3lib_div {
                return $str;
        }
 
-       /**
-        * Creates recursively a JSON literal from a mulidimensional associative array.
-        * Uses Services_JSON (http://mike.teczno.com/JSON/doc/)
+       /**
+        * Creates recursively a JSON literal from a multidimensional associative array.
+        * Uses native function of PHP >= 5.2.0
         *
         * @param       array           $jsonArray: The array to be transformed to JSON
         * @return      string          JSON string
+        * @deprecated since TYPO3 4.3, use PHP native function json_encode() instead, will be removed in TYPO3 4.5
         */
        public static function array2json(array $jsonArray) {
-               if (!$GLOBALS['JSON']) {
-                       require_once(PATH_typo3.'contrib/json/json.php');
-                       $GLOBALS['JSON'] = t3lib_div::makeInstance('Services_JSON');
-               }
-               return $GLOBALS['JSON']->encode($jsonArray);
+               return json_encode($jsonArray);
        }
 
        /**
index 533ac04..69f9b50 100755 (executable)
@@ -5189,19 +5189,19 @@ class t3lib_TCEforms    {
                        // add JS required for inline fields
                if (count($this->inline->inlineData)) {
                        $out .= '
-                       inline.addToDataArray('.t3lib_div::array2json($this->inline->inlineData).');
+                       inline.addToDataArray(' . json_encode($this->inline->inlineData) . ');
                        ';
                }
                        // Registered nested elements for tabs or inline levels:
                if (count($this->requiredNested)) {
                        $out .= '
-                       TBE_EDITOR.addNested('.t3lib_div::array2json($this->requiredNested).');
+                       TBE_EDITOR.addNested(' . json_encode($this->requiredNested) . ');
                        ';
                }
                        // elements which are required or have a range definition:
                if (count($elements)) {
                        $out .= '
-                       TBE_EDITOR.addElements('.t3lib_div::array2json($elements).');
+                       TBE_EDITOR.addElements(' . json_encode($elements) . ');
                        TBE_EDITOR.initRequired();
                        ';
                }
@@ -5973,7 +5973,7 @@ class t3lib_TCEforms      {
                if ($skipFirst) {
                        array_shift($result);
                }
-               return ($json ? t3lib_div::array2json($result) : $result);
+               return ($json ? json_encode($result) : $result);
        }
 
        /**
index 3c373f4..2ac751e 100755 (executable)
@@ -2245,10 +2245,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
+        * @deprecated                  Since TYPO3 4.2: Moved to t3lib_div::array2json, will be removed in TYPO3 4.4
         */
        function getJSON($jsonArray) {
-               return t3lib_div::array2json($jsonArray);
+               return json_encode($jsonArray);
        }
 
 
index 83a93fe..3da22c9 100755 (executable)
@@ -609,7 +609,6 @@ class SC_alt_shortcut {
                $this->content = $this->doc->insertStylesAndJS($this->content);
 
                if($this->editPage && $this->isAjaxCall) {
-                       require_once('contrib/json/json.php');
                        $data = array();
 
                                // edit page
@@ -634,8 +633,7 @@ class SC_alt_shortcut {
                                $data['searchFor']       = rawurlencode($this->searchFor);
                        }
 
-                       $json = new Services_JSON();
-                       $content = $json->encode($data);
+                       $content = json_encode($data);
 
                        header('Content-type: application/json; charset=utf-8');
                        header('X-JSON: '.$content);
index 4236c20..d36b885 100755 (executable)
@@ -1684,7 +1684,7 @@ class browse_links {
                $content.='<br /><br />';
 
                        // Setup indexed elements:
-               $this->doc->JScode.= $this->doc->wrapScriptTags('BrowseLinks.addElements('.t3lib_div::array2json($this->elements).');');
+               $this->doc->JScode.= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
                        // Ending page, returning content:
                $content.= $this->doc->endPage();
                $content = $this->doc->insertStylesAndJS($content);
index 3aecafc..3b865d3 100644 (file)
@@ -248,7 +248,7 @@ class TYPO3AJAX {
         * @return      void
         */
        protected function renderAsJSON() {
-               $content = t3lib_div::array2json($this->content);
+               $content = json_encode($this->content);
 
                header('Content-type: application/json; charset='.$this->charset);
                header('X-JSON: '.($this->contentFormat != 'jsonbody' ? $content : true));
index ebcd444..5799c17 100755 (executable)
@@ -54,6 +54,8 @@
  * @version     $Id$
  * @license     http://www.opensource.org/licenses/bsd-license.php
  * @link        http://pear.php.net/pepr/pepr-proposal-show.php?id=198
+ * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.5
+ *                             (applies to the whole package at typo3/contrib/json/)
  */
 
 /**
index 1afd3d1..fccceda 100644 (file)
@@ -968,7 +968,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                
                $configureRTEInJavascriptString .= '
                        RTEarea[editornumber].toolbar = ' . $this->getJSToolbarArray() . ';
-                       RTEarea[editornumber].convertButtonId = ' . t3lib_div::array2json(array_flip($this->convertToolbarForHtmlAreaArray)) .';
+                       RTEarea[editornumber].convertButtonId = ' . json_encode(array_flip($this->convertToolbarForHtmlAreaArray)) . ';
                        HTMLArea.initEditor(editornumber);' . (!$this->is_FE() ? '' : '
                        /*]]>*/');
                return $configureRTEInJavascriptString;