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

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
26// +-----------------------------------------------------------------------+
27// | branch        : BSF (Best So Far)
28// | file          : $URL: svn+ssh://rvelices@svn.gna.org/svn/phpwebgallery/trunk/action.php $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Rev: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48function xmlrpc_encode($data)
49{
50  switch (gettype($data))
51  {
52    case 'boolean':
53      return '<boolean>'.($data ? '1' : '0').'</boolean>';
54    case 'integer':
55      return '<int>'.$data.'</int>';
56    case 'double':
57      return '<double>'.$data.'</double>';
58    case 'string':
59      return '<string>'.htmlspecialchars($data).'</string>';
60    case 'object':
61    case 'array':
62      $is_array = range(0, count($data) - 1) === array_keys($data);
63      if ($is_array)
64      {
65        $return = '<array><data>'."\n";
66        foreach ($data as $item)
67        {
68          $return .= '  <value>'.xmlrpc_encode($item)."</value>\n";
69        }
70        $return .= '</data></array>';
71      }
72      else
73      {
74        $return = '<struct>'."\n";
75        foreach ($data as $name => $value)
76        {
77                                        $name = htmlspecialchars($name);
78          $return .= "  <member><name>$name</name><value>";
79          $return .= xmlrpc_encode($value)."</value></member>\n";
80        }
81        $return .= '</struct>';
82      }
83      return $return;
84  }
85}
86
87class PwgXmlRpcEncoder extends PwgResponseEncoder
88{
89  function encodeResponse($response)
90  {
91    $respClass = strtolower( get_class($response) );
92    if ($respClass=='pwgerror')
93    {
94      $code = $response->code();
95      $msg = htmlspecialchars($response->message());
96      $ret = <<<EOD
97<methodResponse>
98  <fault>
99    <value>
100      <struct>
101        <member>
102          <name>faultCode</name>
103          <value><int>{$code}</int></value>
104        </member>
105        <member>
106          <name>faultString</name>
107          <value><string>{$msg}</string></value>
108        </member>
109      </struct>
110    </value>
111  </fault>
112</methodResponse>
113EOD;
114      return $ret;
115    }
116
117    parent::flattenResponse($response);
118    $ret = xmlrpc_encode($response);
119    $ret = <<<EOD
120<methodResponse>
121  <params>
122    <param>
123      <value>
124        $ret
125      </value>
126    </param>
127  </params>
128</methodResponse>
129EOD;
130    return $ret;
131  }
132
133  function getContentType()
134  {
135    return 'text/xml';
136  }
137}
138
139?>
Note: See TracBrowser for help on using the repository browser.