Location: PHPKode > projects > Pindorama > pindorama/active/components/xmlrpc/server.php
<?php
/************************************************************
 *                                                          *
 *      Pindorama Core Configuration v. 0.11                *
 *      Guilherme Capilé <hide@address.com>           *
 *                                                          *
 ************************************************************/
/* construção de um servidor XML-RPC simples para a publicação de documentos e 
   comunicação com outros serviços/servidores. Leva em conta apenas o conteúdo 
   bruto em $HTTP_RAW_POST_DATA e retorna uma resposta XML-RPC 
   
   os métodos são definidos por [nome do arquivo sem extensão].[função]
   */
global $HTTP_RAW_POST_DATA;
require_once("common.php");

function xmlrpc_server()
{
    global $HTTP_RAW_POST_DATA, $c, $l;

    if ($_SERVER["CONTENT_TYPE"] == "text/xml" && @in_array($_SERVER["REMOTE_ADDR"], $c["xmlrpc_s"]["permit"])) {
        xmlrpc_s($HTTP_RAW_POST_DATA);
    } else {
        header("WWW-Authenticate: Basic realm=\"XML-RPC Pindorama\"");
        header("HTTP/1.0 401 Unauthorized");
    }
}

function xmlrpc_s ($data)
{
    /* configurações básicas */
    global $xmlrpc_r, $xmlrpc_t, $c, $l, $xmlrpc_err;
    /*
    $d["scheme"]     = "http";
    $d["user"]       = "";
    $s["pass"]       = "";
    $s["host"]       = "pindorama";
    $s["port"]       = ":80";
    $s["path"]       = "/xrpc-server";
    $d["server"]     = "xml-rpc at pindorama v0.11";
    $d["logfile"]    = $c["xmlrpc"]["logfile"];
    */
    $d = $c["xmlrpc_s"];
    if (!headers_sent()) {
        header("HTTP/1.1 200 OK", TRUE);
        header("Connection: close", TRUE);
        header("Content-Type: text/xml", TRUE);
        header("Server: ".$d["server"], TRUE);
    }
    if (is_writable($d["logfile"])) { 
        $tmp = @fopen($d["logfile"], 'w');
        @fwrite($tmp, $data);
        @fclose($tmp); 
    } 
    $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:variable name="filename"><xsl:if test="contains(/methodCall/methodName, '.')"><xsl:value-of select="concat(\$base, substring-before(/methodCall/methodName, '.'))"/>.php</xsl:if></xsl:variable>
<xsl:variable name="method"><xsl:choose><xsl:when test="contains(/methodCall/methodName, '.')"><xsl:value-of select="substring-after(/methodCall/methodName, '.')"/></xsl:when><xsl:otherwise><xsl:value-of select="/methodCall/methodName"/></xsl:otherwise></xsl:choose></xsl:variable>
<xsl:output encoding="iso-8859-1" indent="no" method="text" />
<xsl:template match="/methodCall"><xsl:if test="\$filename != ''">if (!is_file("<xsl:value-of select="\$filename"/>")) { \$xmlrpc_err = xmlrpc_error(1, "{$l['xmlrpc']['methodfile']}<xsl:value-of select="\$filename"/>{$l['xmlrpc']['notfound']}"); } else  { require_once("<xsl:value-of select="\$filename"/>");</xsl:if>
if (function_exists('<xsl:value-of select="\$method"/>')) { \$xmlrpc_res = <xsl:value-of select="\$method"/>(<xsl:for-each select="params/param/value/*"><xsl:if test="position() &gt; 1">,</xsl:if><xsl:apply-templates select="." mode="values"/></xsl:for-each>);}else { \$xmlrpc_err = xmlrpc_error(1, "{$l['xmlrpc']['methodname']}<xsl:value-of select="\$method"/>{$l['xmlrpc']['notfound']}"); }<xsl:if test="\$filename != ''">}</xsl:if>
</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;
    unset($xslo);
    $xh = xslt_create();
    $param = $d;
    $param["base"] = $d["modules_root"];
    $arg["message"] = $data;
    $arg["xsl"]     = $xsl;
    $xslo = xslt_process($xh, "arg:message", "arg:xsl", $xslo, $arg, $param);
    //error_log($xslo, 3, $c["xmlrpc_s"]["logfile"]);
    @xslt_free($xh);
    ob_start();
    eval ($xslo);
    /*if ($xmlrpc_r == "" && !is_array($xmlrpc_r)) {
        $xmlrpc_r = ob_get_contents();
    }*/
    $contents = ob_get_contents();
    if ($xmlrpc_res) {
        if ($xmlrpc_r == "" && $contents != "") {
            $xmlrpc_r = $contents;
        }
    } else if ($xmlrpc_err == "") {
        $xmlrpc_err = xmlrpc_error(1, $xmlrpc_r);
    }
    ob_end_clean();
    if ($xmlrpc_err == "") {
        $result = xmlrpc_encode($xmlrpc_r, $xmlrpc_t);
    } else {
        $result = $xmlrpc_err;
    }
    if (!headers_sent()) {
        header("Content-Length: ".strlen($result), TRUE);
    }
    echo $result;
}
?>
Return current item: Pindorama