includes/comment.php
changeset 1016 6d32d80b2192
parent 1011 96119a79cf81
child 1081 745200a9cc2a
equal deleted inserted replaced
1015:17721bad21df 1016:6d32d80b2192
    63     $this->namespace = $db->escape($namespace);
    63     $this->namespace = $db->escape($namespace);
    64   }
    64   }
    65   
    65   
    66   /**
    66   /**
    67    * Processes a command in JSON format.
    67    * Processes a command in JSON format.
    68    * @param string The JSON-encoded input, probably something sent from the Javascript/AJAX frontend
    68    * @param mixed Either the JSON-encoded input string, probably something sent from the Javascript/AJAX frontend, or an equivalent array
    69    */
    69    */
    70    
    70    
    71   function process_json($json)
    71   function process_json($json)
    72   {
    72   {
    73     global $db, $session, $paths, $template, $plugins; // Common objects
    73     global $db, $session, $paths, $template, $plugins; // Common objects
    74     global $lang;
    74     global $lang;
    75     
    75     
    76     $data = enano_json_decode($json);
    76     $is_json = !is_array($json);
    77     $data = decode_unicode_array($data);
    77     
       
    78     if ( $is_json )
       
    79     {
       
    80       $data = enano_json_decode($json);
       
    81       $data = decode_unicode_array($data);
       
    82     }
       
    83     else
       
    84     {
       
    85       $data =& $json;
       
    86     }
    78     if ( !isset($data['mode']) )
    87     if ( !isset($data['mode']) )
    79     {
    88     {
    80       $ret = Array('mode'=>'error','error'=>'No mode defined!');
    89       $ret = Array('mode'=>'error','error'=>'No mode defined!');
    81       echo enano_json_encode($ret);
    90       echo enano_json_encode($ret);
    82       return $ret;
    91       return $ret;
   440           'mode' => 'error', 
   449           'mode' => 'error', 
   441           'error' => $data['mode'] . ' is not a valid request mode'
   450           'error' => $data['mode'] . ' is not a valid request mode'
   442           );
   451           );
   443         break;
   452         break;
   444     }
   453     }
   445     echo enano_json_encode($ret);
   454     if ( $is_json )
       
   455       echo enano_json_encode($ret);
       
   456     
   446     return $ret;
   457     return $ret;
   447   }
   458   }
   448   
   459   
   449 } // class Comments
   460 } // class Comments
   450 
   461