includes/comment.php
changeset 1016 6d32d80b2192
parent 1011 96119a79cf81
child 1081 745200a9cc2a
--- a/includes/comment.php	Sat May 30 14:46:57 2009 -0400
+++ b/includes/comment.php	Sun May 31 23:26:05 2009 -0400
@@ -65,7 +65,7 @@
   
   /**
    * Processes a command in JSON format.
-   * @param string The JSON-encoded input, probably something sent from the Javascript/AJAX frontend
+   * @param mixed Either the JSON-encoded input string, probably something sent from the Javascript/AJAX frontend, or an equivalent array
    */
    
   function process_json($json)
@@ -73,8 +73,17 @@
     global $db, $session, $paths, $template, $plugins; // Common objects
     global $lang;
     
-    $data = enano_json_decode($json);
-    $data = decode_unicode_array($data);
+    $is_json = !is_array($json);
+    
+    if ( $is_json )
+    {
+      $data = enano_json_decode($json);
+      $data = decode_unicode_array($data);
+    }
+    else
+    {
+      $data =& $json;
+    }
     if ( !isset($data['mode']) )
     {
       $ret = Array('mode'=>'error','error'=>'No mode defined!');
@@ -442,7 +451,9 @@
           );
         break;
     }
-    echo enano_json_encode($ret);
+    if ( $is_json )
+      echo enano_json_encode($ret);
+    
     return $ret;
   }