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