⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rpc.php

📁 中国源码站下载
💻 PHP
📖 第 1 页 / 共 3 页
字号:
            return 0;        }        $typeof=$XML_RPC_Types[$type];        if ($typeof!=1) {            echo "<B>XML_RPC_Value</B>: not a scalar type (${typeof})<BR>";            return 0;        }        if ($type==$XML_RPC_Boolean) {            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 XML_RPC_Value($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 $XML_RPC_Types;        if ($this->mytype!=0) {            echo "<B>XML_RPC_Value</B>: already initialized as a [" .                $this->kindOf() . "]<BR>";            return 0;        }        $this->mytype=$XML_RPC_Types["array"];        $this->me["array"]=$vals;        return 1;    }    function addStruct($vals)    {        global $XML_RPC_Types;        if ($this->mytype!=0) {            echo "<B>XML_RPC_Value</B>: already initialized as a [" .            $this->kindOf() . "]<BR>";            return 0;        }        $this->mytype=$XML_RPC_Types["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 $XML_RPC_Types, $XML_RPC_Base64, $XML_RPC_String, $XML_RPC_Boolean;        switch($XML_RPC_Types[$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 $XML_RPC_Base64:                        $rs.="<${typ}>" . base64_encode($val) . "</${typ}>";                        break;                    case $XML_RPC_Boolean:                        $rs.="<${typ}>" . ($val ? "1" : "0") . "</${typ}>";                        break;                    case $XML_RPC_String:                        $rs.="<${typ}>" . htmlspecialchars($val). "</${typ}>";                        break;                    default:                        $rs.="<${typ}>${val}</${typ}>";                }                break;            default:                break;        }        return $rs;    }    function serialize()    {        return $this->serializeval($this);    }    function serializeval($o)    {        global $XML_RPC_Types;        $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 $XML_RPC_BOOLEAN, $XML_RPC_Base64;        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))    {            foreach ($b as $id => $cont) {                $b[$id] = $cont->scalarval();            }        }        // add support for structures directly encoding php objects        if (is_object($b))  {            $t = get_object_vars($b);            foreach ($t as $id => $cont) {                $t[$id] = $cont->scalarval();            }            foreach ($t as $id => $cont) {                eval('$b->'.$id.' = $cont;');            }        }        // end contrib        return $b;    }    function scalarval()    {        global $XML_RPC_Boolean, $XML_RPC_Base64;        reset($this->me);        list($a,$b)=each($this->me);        return $b;    }    function scalartyp()    {        global $XML_RPC_I4, $XML_RPC_Int;        reset($this->me);        list($a,$b)=each($this->me);        if ($a==$XML_RPC_I4)            $a=$XML_RPC_Int;        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 XML_RPC_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 XML_RPC_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;}/******************************************************************* XML_RPC_decode takes a message in PHP XML_RPC object format and ** translates it into native PHP types.                            **                                                                 ** author: Dan Libby (dan@libby.com)                               *******************************************************************/function XML_RPC_decode($XML_RPC_val) {    $kind = $XML_RPC_val->kindOf();   if($kind == "scalar") {      return $XML_RPC_val->scalarval();   }   else if($kind == "array") {      $size = $XML_RPC_val->arraysize();      $arr = array();      for($i = 0; $i < $size; $i++) {         $arr[]=XML_RPC_decode($XML_RPC_val->arraymem($i));      }      return $arr;   }   else if($kind == "struct") {      $XML_RPC_val->structreset();      $arr = array();      while(list($key,$value)=$XML_RPC_val->structeach()) {         $arr[$key] = XML_RPC_decode($value);      }      return $arr;   }}/****************************************************************** XML_RPC_encode takes native php types and encodes them into    ** XML_RPC 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 XML_RPC_encode($php_val) {   global $XML_RPC_Boolean;   global $XML_RPC_Int;   global $XML_RPC_Double;   global $XML_RPC_String;   global $XML_RPC_Array;   global $XML_RPC_Struct;   $type = gettype($php_val);   $XML_RPC_val = new XML_RPC_Value;   switch($type) {      case "array":      case "object":         $arr = array();         while (list($k,$v) = each($php_val)) {            $arr[$k] = XML_RPC_encode($v);         }         $XML_RPC_val->addStruct($arr);         break;      case "integer":         $XML_RPC_val->addScalar($php_val, $XML_RPC_Int);         break;      case "double":         $XML_RPC_val->addScalar($php_val, $XML_RPC_Double);         break;      case "string":      case "NULL":         $XML_RPC_val->addScalar($php_val, $XML_RPC_String);         break;// <G_Giunta_2001-02-29>// Add support for encoding/decoding of booleans, since they are supported in PHP      case "boolean":         $XML_RPC_val->addScalar($php_val, $XML_RPC_Boolean);         break;// </G_Giunta_2001-02-29>      case "unknown type":      default:         $XML_RPC_val = false;         break;   }   return $XML_RPC_val;}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -