Ejemplo n.º 1
0
<?php

include_once "./_common.php";
function json_parse($str)
{
    // Damn pesky carriage returns...
    $str = str_replace("\r\n", "\n", $str);
    $str = str_replace("\r", "\n", $str);
    // JSON requires new line characters be escaped
    $str = str_replace("\n", "\\n", $str);
    $str = str_replace('"', '\\"', $str);
    return $str;
}
$wr_id = $_GET['comment_id'];
$sql = " select mb_id, wr_option, wr_content from {$write_table} where wr_id = '{$wr_id}' ";
$wr = sql_fetch($sql);
if ($is_admin || $member[mb_id] && $member[mb_id] == $wr[mb_id]) {
    $secret = strstr($wr[wr_option], "secret") ? "secret" : "";
    echo "{\"secret\": \"{$secret}\", \"wr_content\":\"" . json_parse($wr[wr_content]) . "\"}";
} else {
    echo "";
}
Ejemplo n.º 2
0
/**
 * Convert the json representation of a jsonrpc method call, jsonrpc method response
 * or single json value into the appropriate object (a.k.a. deserialize).
 * Please note that there is no way to distinguish the serialized representation
 * of a single json val of type object which has the 3 appropriate members from
 * the serialization of a method call or method response.
 * In such a case, the function will return a jsonrpcresp or jsonrpcmsg
 * @param string $json_val
 * @param array $options
 * @return mixed false on error, or an instance of jsonrpcval, jsonrpcresp or jsonrpcmsg
 * @access public
 * @todo add options controlling character set encodings
 */
function php_jsonrpc_decode_json($json_val, $options = array())
{
    $src_encoding = array_key_exists('src_encoding', $options) ? $options['src_encoding'] : $GLOBALS['xmlrpc_defencoding'];
    $dest_encoding = array_key_exists('dest_encoding', $options) ? $options['dest_encoding'] : $GLOBALS['xmlrpc_internalencoding'];
    // echo "#$json_val*";
    //$GLOBALS['_xh'] = array();
    $GLOBALS['_xh']['isf'] = 0;
    if (!json_parse($json_val, false, $src_encoding, $dest_encoding)) {
        error_log($GLOBALS['_xh']['isf_reason']);
        return false;
    } else {
        $val = $GLOBALS['_xh']['value'];
        // shortcut
        if ($GLOBALS['_xh']['value']->kindOf() == 'struct') {
            if ($GLOBALS['_xh']['value']->structSize() == 3) {
                if ($GLOBALS['_xh']['value']->structMemExists('method') && $GLOBALS['_xh']['value']->structMemExists('params') && $GLOBALS['_xh']['value']->structMemExists('id')) {
                    /// @todo we do not check for correct type of 'method', 'params' struct members...
                    $method = $GLOBALS['_xh']['value']->structMem('method');
                    $msg =& new jsonrpcmsg($method->scalarval(), null, php_jsonrpc_decode($GLOBALS['_xh']['value']->structMem('id')));
                    $params = $GLOBALS['_xh']['value']->structMem('params');
                    for ($i = 0; $i < $params->arraySize(); ++$i) {
                        $msg->addparam($params->arrayMem($i));
                    }
                    return $msg;
                } else {
                    if ($GLOBALS['_xh']['value']->structMemExists('result') && $GLOBALS['_xh']['value']->structMemExists('error') && $GLOBALS['_xh']['value']->structMemExists('id')) {
                        $id = php_jsonrpc_decode($GLOBALS['_xh']['value']->structMem('id'));
                        $err = php_jsonrpc_decode($GLOBALS['_xh']['value']->structMem('error'));
                        if ($err == null) {
                            $resp = new jsonrpcresp($GLOBALS['_xh']['value']->structMem('result'));
                        } else {
                            if (is_array($err) && array_key_exists('faultCode', $err) && array_key_exists('faultString', $err)) {
                                if ($err['faultCode'] == 0) {
                                    // FAULT returned, errno needs to reflect that
                                    $err['faultCode'] = -1;
                                }
                            } else {
                                $err = array('faultCode' => -1, 'faultString' => serialize_jsonrpcval($GLOBALS['_xh']['value']->structMem('error')));
                            }
                            $resp =& new jsonrpcresp(0, $err['faultCode'], $err['faultString']);
                        }
                        $resp->id = $id;
                        return $resp;
                    }
                }
            }
        }
        // not a request msg nor a response: a plain jsonrpcval obj
        return $GLOBALS['_xh']['value'];
    }
}
Ejemplo n.º 3
0
/**
 * Convert the json representation of a jsonrpc method call, jsonrpc method response
 * or single json value into the appropriate object (a.k.a. deserialize)
 * @param string $json_val
 * @param array $options
 * @return mixed false on error, or an instance of jsonrpcval
 * @access public
 * @todo add options controlling character set encodings
 */
function php_jsonrpc_decode_json($json_val, $options = array())
{
    $src_encoding = array_key_exists('src_encoding', $options) ? $options['src_encoding'] : $GLOBALS['xmlrpc_defencoding'];
    $dest_encoding = array_key_exists('dest_encoding', $options) ? $options['dest_encoding'] : $GLOBALS['xmlrpc_internalencoding'];
    //$GLOBALS['_xh'] = array();
    $GLOBALS['_xh']['isf'] = 0;
    if (!json_parse($json_val, false, $src_encoding, $dest_encoding)) {
        error_log($GLOBALS['_xh']['isf_reason']);
        return false;
    } else {
        return $GLOBALS['_xh']['value'];
    }
}