[1698] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3046] | 5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1698] | 23 | |
---|
| 24 | function 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 | |
---|
| 63 | class 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> |
---|
| 89 | EOD; |
---|
| 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> |
---|
| 105 | EOD; |
---|
| 106 | return $ret; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | function getContentType() |
---|
| 110 | { |
---|
| 111 | return 'text/xml'; |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | ?> |
---|