📄 lib-xmlrpc.inc.php
字号:
$r->hdrs = $_xh[$parser]['headers'];
return $r;
}
}
class xmlrpcval
{
var $me=array();
var $mytype=0;
function xmlrpcval($val=-1, $type='')
{
global $xmlrpcTypes;
$this->me=array();
$this->mytype=0;
if ($val!=-1 || !is_int($val) || $type!='')
{
if ($type=='')
{
$type='string';
}
if ($xmlrpcTypes[$type]==1)
{
$this->addScalar($val,$type);
}
elseif ($xmlrpcTypes[$type]==2)
{
$this->addArray($val);
}
elseif ($xmlrpcTypes[$type]==3)
{
$this->addStruct($val);
}
}
}
function addScalar($val, $type='string')
{
global $xmlrpcTypes, $xmlrpcBoolean;
if ($this->mytype==1)
{
echo '<B>xmlrpcval</B>: scalar can have only one value<BR>';
return 0;
}
$typeof=$xmlrpcTypes[$type];
if ($typeof!=1)
{
echo '<B>xmlrpcval</B>: not a scalar type (${typeof})<BR>';
return 0;
}
if ($type==$xmlrpcBoolean)
{
if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false')))
{
$val=1;
}
else
{
$val=0;
}
}
if ($this->mytype==2)
{
// we're adding to an array here
$ar=$this->me['array'];
$ar[]=new xmlrpcval($val, $type);
$this->me['array']=$ar;
}
else
{
// a scalar, so set the value and remember we're scalar
$this->me[$type]=$val;
$this->mytype=$typeof;
}
return 1;
}
function addArray($vals)
{
global $xmlrpcTypes;
if ($this->mytype!=0)
{
echo '<B>xmlrpcval</B>: already initialized as a [' . $this->kindOf() . ']<BR>';
return 0;
}
$this->mytype=$xmlrpcTypes['array'];
$this->me['array']=$vals;
return 1;
}
function addStruct($vals)
{
global $xmlrpcTypes;
if ($this->mytype!=0)
{
echo '<B>xmlrpcval</B>: already initialized as a [' . $this->kindOf() . ']<BR>';
return 0;
}
$this->mytype=$xmlrpcTypes['struct'];
$this->me['struct']=$vals;
return 1;
}
function dump($ar)
{
reset($ar);
while ( list( $key, $val ) = each( $ar ) )
{
echo "$key => $val<br>";
if ($key == 'array')
{
while ( list( $key2, $val2 ) = each( $val ) )
{
echo "-- $key2 => $val2<br>";
}
}
}
}
function kindOf()
{
switch($this->mytype)
{
case 3:
return 'struct';
break;
case 2:
return 'array';
break;
case 1:
return 'scalar';
break;
default:
return 'undef';
}
}
function serializedata($typ, $val)
{
$rs='';
global $xmlrpcTypes, $xmlrpcBase64, $xmlrpcString,
$xmlrpcBoolean;
switch(@$xmlrpcTypes[$typ])
{
case 3:
// struct
$rs.="<struct>\n";
reset($val);
while(list($key2, $val2)=each($val))
{
$rs.="<member><name>${key2}</name>\n";
$rs.=$this->serializeval($val2);
$rs.="</member>\n";
}
$rs.='</struct>';
break;
case 2:
// array
$rs.="<array>\n<data>\n";
for($i=0; $i<sizeof($val); $i++)
{
$rs.=$this->serializeval($val[$i]);
}
$rs.="</data>\n</array>";
break;
case 1:
switch ($typ)
{
case $xmlrpcBase64:
$rs.="<${typ}>" . base64_encode($val) . "</${typ}>";
break;
case $xmlrpcBoolean:
$rs.="<${typ}>" . ($val ? '1' : '0') . "</${typ}>";
break;
case $xmlrpcString:
// G. Giunta 2005/2/13: do NOT use htmlentities, since
// it will produce named html entities, which are invalid xml
$rs.="<${typ}>" . xmlrpc_encode_entitites($val). "</${typ}>";
// $rs.="<${typ}>" . htmlentities($val). "</${typ}>";
break;
default:
$rs.="<${typ}>${val}</${typ}>";
}
break;
default:
break;
}
return $rs;
}
function serialize()
{
return $this->serializeval($this);
}
function serializeval($o)
{
//global $xmlrpcTypes;
$rs='';
$ar=$o->me;
reset($ar);
list($typ, $val) = each($ar);
$rs.='<value>';
$rs.=$this->serializedata($typ, $val);
$rs.="</value>\n";
return $rs;
}
function structmem($m)
{
$nv=$this->me['struct'][$m];
return $nv;
}
function structreset()
{
reset($this->me['struct']);
}
function structeach()
{
return each($this->me['struct']);
}
function getval()
{
// UNSTABLE
global $xmlrpcBoolean, $xmlrpcBase64;
reset($this->me);
list($a,$b)=each($this->me);
// contributed by I Sofer, 2001-03-24
// add support for nested arrays to scalarval
// i've created a new method here, so as to
// preserve back compatibility
if (is_array($b))
{
@reset($b);
while(list($id,$cont) = @each($b))
{
$b[$id] = $cont->scalarval();
}
}
// add support for structures directly encoding php objects
if (is_object($b))
{
$t = get_object_vars($b);
@reset($t);
while(list($id,$cont) = @each($t))
{
$t[$id] = $cont->scalarval();
}
@reset($t);
while(list($id,$cont) = @each($t))
{
//eval('$b->'.$id.' = $cont;');
@$b->$id = $cont;
}
}
// end contrib
return $b;
}
function scalarval()
{
//global $xmlrpcBoolean, $xmlrpcBase64;
reset($this->me);
list($a,$b)=each($this->me);
return $b;
}
function scalartyp()
{
global $xmlrpcI4, $xmlrpcInt;
reset($this->me);
list($a,$b)=each($this->me);
if ($a==$xmlrpcI4)
{
$a=$xmlrpcInt;
}
return $a;
}
function arraymem($m)
{
$nv=$this->me['array'][$m];
return $nv;
}
function arraysize()
{
reset($this->me);
list($a,$b)=each($this->me);
return sizeof($b);
}
}
// date helpers
function iso8601_encode($timet, $utc=0)
{
// return an ISO8601 encoded string
// really, timezones ought to be supported
// but the XML-RPC spec says:
//
// "Don't assume a timezone. It should be specified by the server in its
// documentation what assumptions it makes about timezones."
//
// these routines always assume localtime unless
// $utc is set to 1, in which case UTC is assumed
// and an adjustment for locale is made when encoding
if (!$utc)
{
$t=strftime("%Y%m%dT%H:%M:%S", $timet);
}
else
{
if (function_exists('gmstrftime'))
{
// gmstrftime doesn't exist in some versions
// of PHP
$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
}
else
{
$t=strftime("%Y%m%dT%H:%M:%S", $timet-date('Z'));
}
}
return $t;
}
function iso8601_decode($idate, $utc=0)
{
// return a timet in the localtime, or UTC
$t=0;
if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $idate, $regs))
{
if ($utc)
{
$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
}
else
{
$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
}
}
return $t;
}
/****************************************************************
* xmlrpc_decode takes a message in PHP xmlrpc object format and *
* tranlates it into native PHP types. *
* *
* author: Dan Libby (dan@libby.com) *
****************************************************************/
function php_xmlrpc_decode($xmlrpc_val)
{
$kind = $xmlrpc_val->kindOf();
if($kind == 'scalar')
{
return $xmlrpc_val->scalarval();
}
elseif($kind == 'array')
{
$size = $xmlrpc_val->arraysize();
$arr = array();
for($i = 0; $i < $size; $i++)
{
$arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i));
}
return $arr;
}
elseif($kind == 'struct')
{
$xmlrpc_val->structreset();
$arr = array();
while(list($key,$value)=$xmlrpc_val->structeach())
{
$arr[$key] = php_xmlrpc_decode($value);
}
return $arr;
}
}
if(function_exists('xmlrpc_decode'))
{
define('XMLRPC_EPI_ENABLED','1');
}
else
{
define('XMLRPC_EPI_ENABLED','0');
function xmlrpc_decode($xmlrpc_val)
{
$kind = $xmlrpc_val->kindOf();
if($kind == 'scalar')
{
return $xmlrpc_val->scalarval();
}
elseif($kind == 'array')
{
$size = $xmlrpc_val->arraysize();
$arr = array();
for($i = 0; $i < $size; $i++)
{
$arr[]=xmlrpc_decode($xmlrpc_val->arraymem($i));
}
return $arr;
}
elseif($kind == 'struct')
{
$xmlrpc_val->structreset();
$arr = array();
while(list($key,$value)=$xmlrpc_val->structeach())
{
$arr[$key] = xmlrpc_decode($value);
}
return $arr;
}
}
}
/****************************************************************
* xmlrpc_encode takes native php types and encodes them into *
* xmlrpc PHP object format. *
* BUG: All sequential arrays are turned into structs. I don't *
* know of a good way to determine if an array is sequential *
* only. *
* *
* feature creep -- could support more types via optional type *
* argument. *
* *
* author: Dan Libby (dan@libby.com) *
****************************************************************/
function php_xmlrpc_encode($php_val)
{
global $xmlrpcInt;
global $xmlrpcDouble;
global $xmlrpcString;
global $xmlrpcArray;
global $xmlrpcStruct;
global $xmlrpcBoolean;
global $xmlrpcBase64;
$type = gettype($php_val);
$xmlrpc_val = new xmlrpcval;
switch($type)
{
case 'array':
case 'object':
$arr = array();
while (list($k,$v) = each($php_val))
{
$arr[$k] = php_xmlrpc_encode($v);
}
$xmlrpc_val->addStruct($arr);
break;
case 'integer':
$xmlrpc_val->addScalar($php_val, $xmlrpcInt);
break;
case 'double':
$xmlrpc_val->addScalar($php_val, $xmlrpcDouble);
break;
case 'string':
$xmlrpc_val->addScalar($php_val, $xmlrpcBase64); //$xmlrpcString);
break;
// <G_Giunta_2001-02-29>
// Add support for encoding/decoding of booleans, since they are supported in PHP
case 'boolean':
$xmlrpc_val->addScalar($php_val, $xmlrpcBoolean);
break;
// </G_Giunta_2001-02-29>
// catch "resource", "NULL", "user function", "unknown type"
//case 'unknown type':
default:
// giancarlo pinerolo <ping@alt.it>
// it has to return
// an empty object in case (which is already
// at this point), not a boolean.
break;
}
return $xmlrpc_val;
}
if(XMLRPC_EPI_ENABLED == '0')
{
function xmlrpc_encode($php_val)
{
global $xmlrpcInt;
global $xmlrpcDouble;
global $xmlrpcString;
global $xmlrpcArray;
global $xmlrpcStruct;
global $xmlrpcBoolean;
global $xmlrpcBase64;
$type = gettype($php_val);
$xmlrpc_val = new xmlrpcval;
switch($type)
{
case 'array':
case 'object':
$arr = array();
while (list($k,$v) = each($php_val))
{
$arr[$k] = xmlrpc_encode($v);
}
$xmlrpc_val->addStruct($arr);
break;
case 'integer':
$xmlrpc_val->addScalar($php_val, $xmlrpcInt);
break;
case 'double':
$xmlrpc_val->addScalar($php_val, $xmlrpcDouble);
break;
case 'string':
$xmlrpc_val->addScalar($php_val, $xmlrpcBase64); //$xmlrpcString);
break;
// <G_Giunta_2001-02-29>
// Add support for encoding/decoding of booleans, since they are supported in PHP
case 'boolean':
$xmlrpc_val->addScalar($php_val, $xmlrpcBoolean);
break;
// </G_Giunta_2001-02-29>
//case 'unknown type':
default:
// giancarlo pinerolo <ping@alt.it>
// it has to return
// an empty object in case (which is already
// at this point), not a boolean.
break;
}
return $xmlrpc_val;
}
}
// phpAdsNew backwards compatible wrappers - Matteo Beccati
function phpAds_xmlrpcDecode($v) { return php_xmlrpc_decode($v); }
function phpAds_xmlrpcEncode($v) { return php_xmlrpc_encode($v); }
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -