source: trunk/include/ws_protocols/xmlrpc_encoder.php @ 8728

Last change on this file since 8728 was 8728, checked in by plg, 13 years ago

Happy new year 2011

Change "Piwigo - a PHP based picture gallery" into "Piwigo - a PHP based photo gallery"

  • Property svn:eol-style set to LF
File size: 3.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24function xmlrpc_encode($data)
25{
26  switch (gettype($data))
27  {
28    case 'boolean':
29      return '<boolean>'.($data ? '1' : '0').'</boolean>';
30    case 'integer':
31      return '<int>'.$data.'</int>';
32    case 'double':
33      return '<double>'.$data.'</double>';
34    case 'string':
35      return '<string>'.htmlspecialchars($data).'</string>';
36    case 'object':
37    case 'array':
38      $is_array = range(0, count($data) - 1) === array_keys($data);
39      if ($is_array)
40      {
41        $return = '<array><data>'."\n";
42        foreach ($data as $item)
43        {
44          $return .= '  <value>'.xmlrpc_encode($item)."</value>\n";
45        }
46        $return .= '</data></array>';
47      }
48      else
49      {
50        $return = '<struct>'."\n";
51        foreach ($data as $name => $value)
52        {
53                                        $name = htmlspecialchars($name);
54          $return .= "  <member><name>$name</name><value>";
55          $return .= xmlrpc_encode($value)."</value></member>\n";
56        }
57        $return .= '</struct>';
58      }
59      return $return;
60  }
61}
62
63class PwgXmlRpcEncoder extends PwgResponseEncoder
64{
65  function encodeResponse($response)
66  {
67    $respClass = strtolower( @get_class($response) );
68    if ($respClass=='pwgerror')
69    {
70      $code = $response->code();
71      $msg = htmlspecialchars($response->message());
72      $ret = <<<EOD
73<methodResponse>
74  <fault>
75    <value>
76      <struct>
77        <member>
78          <name>faultCode</name>
79          <value><int>{$code}</int></value>
80        </member>
81        <member>
82          <name>faultString</name>
83          <value><string>{$msg}</string></value>
84        </member>
85      </struct>
86    </value>
87  </fault>
88</methodResponse>
89EOD;
90      return $ret;
91    }
92
93    parent::flattenResponse($response);
94    $ret = xmlrpc_encode($response);
95    $ret = <<<EOD
96<methodResponse>
97  <params>
98    <param>
99      <value>
100        $ret
101      </value>
102    </param>
103  </params>
104</methodResponse>
105EOD;
106    return $ret;
107  }
108
109  function getContentType()
110  {
111    return 'text/xml';
112  }
113}
114
115?>
Note: See TracBrowser for help on using the repository browser.