Location: PHPKode > projects > Pindorama > pindorama/active/components/xmlrpc/common.php
<?php
/* m├ętodos em comum ao servidor e cliente xml-rpc
   */

function xmlrpc_error ( $errno, $err )
{
    global $xmlrpc_err;
    $msg = <<<FIM
<?xml version="1.0" encoding="iso-8859-1" ?>
<methodResponse>
<fault>
  <value>
    <struct>
      <member>
        <name>faultCode</name>
        <value><int>$errno</int></value>
      </member>
      <member>
        <name>faultString</name>
        <value><string>$err</string></value>
      </member>
    </struct>
  </value>
</fault>
</methodResponse>
FIM;
    return $msg;
}

function xmlrpc_values ( $value, $type = "" )
{
    if (is_bool($value) || $type == "boolean") {
        $result = "<boolean>".(int)$value."</boolean>";
    } else if (is_int($value) || $type == "int") {
        $result = "<int>".(int)$value."</int>";
    } else if (is_float($value)) {
        $result = "<double>".(double)$value."</double>";
    } else if (is_array($value)) {
        //if ($type == "struct" || ($type != "array" && !array_key_exists(0, $value))) {
        if ($type != "array") {
            $result = "<struct>";
            foreach ($value as $k => $v) {
                $result .= "<member><name>".$k."</name><value>".xmlrpc_values($v)."</value></member>";
            }
            $result .= "</struct>";
        } else {
            $result = "<array><data>";
            foreach ($value as $temp) {
                $result .= "<value>".xmlrpc_values($temp)."</value>";
            }
            $result .= "</data></array>";
        }
    } else if ($type != "string") {
        $result = "<base64>".base64_encode($value)."</base64>";
    } else {
        $result = "<string>".htmlspecialchars((string)$value)."</string>";
    }
    return $result;
}

function xmlrpc_encode ( $result, $type = "" )
{
    if (!is_string($result) || !preg_match("/\<methodResponse/", $result)) {
        $result = xmlrpc_values ( $result, $type );
        $msg = <<<FIM
<?xml version="1.0" encoding="iso-8859-1" ?>
<methodResponse>
  <params>
    <param>
      <value>$result</value>
    </param>
  </params>
</methodResponse>
FIM;
    } else {
        $msg = $result;
    }
    return $msg;
}

function xmlrpc_decode($xml)
{
    global $xmlrpc_err;
    $xmlrpc_err = "";
    $xsl = <<<FIM
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="base"/>
<xsl:output encoding="iso-8859-1" indent="no" method="text" />
<xsl:template match="/methodResponse/fault/value">\$xmlrpc_err = <xsl:apply-templates select="*" mode="values"/>;</xsl:template>
<xsl:template match="/methodResponse/params/param/value">\$xmlrpc_m = <xsl:apply-templates select="*" mode="values"/>;</xsl:template>
<xsl:template match="int|i4|string|double|dateTime.iso8601" mode="values"><xsl:text disable-output-escaping="yes">&lt;&lt;&lt;EOF
</xsl:text><xsl:value-of select="."/><xsl:text>
EOF
</xsl:text></xsl:template>
<xsl:template match="base64"  mode="values">base64_decode(<xsl:text disable-output-escaping="yes">&lt;&lt;&lt;EOF
</xsl:text><xsl:value-of select="."/><xsl:text>
EOF
)</xsl:text></xsl:template>
<xsl:template match="boolean" mode="values"><xsl:choose><xsl:when test=". = 1">TRUE</xsl:when><xsl:otherwise>FALSE</xsl:otherwise></xsl:choose></xsl:template>
<xsl:template match="struct"  mode="values">array(<xsl:for-each select="member"><xsl:if test="position() &gt; 1">,</xsl:if>"<xsl:value-of select="name"/>"<xsl:text disable-output-escaping="yes">=&gt;</xsl:text><xsl:apply-templates mode="values" select="value/*"/></xsl:for-each>)</xsl:template>
<xsl:template match="array"   mode="values">array(<xsl:for-each select="data/value"><xsl:if test="position() &gt; 1">,</xsl:if><xsl:apply-templates mode="values" select="."/></xsl:for-each>)</xsl:template>
</xsl:stylesheet>
FIM;
    $xh = xslt_create();
    $param["base"] = ".";
    $arg["xml"] = $xml;
    $arg["xsl"] = $xsl;
    $xslo = @xslt_process($xh, "arg:xml", "arg:xsl", $xslo, $arg, $param);
    @xslt_free($xh);
    @eval ($xslo);
    if (is_array($xmlrpc_err) || $xmlrpc_err != "" || !isset($xmlrpc_m)) {
        return false;
    } else {
        return $xmlrpc_m;
    }
}
?>
Return current item: Pindorama