This commit is contained in:
mingan666 2025-03-29 01:36:43 +00:00 committed by GitHub
commit 3fccfc39a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 2 deletions

View file

@ -58,6 +58,10 @@ if (!is_null($responseFormat))
include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
$encoder = new PwgJsonEncoder();
break;
case 'jsonalt':
include_once(PHPWG_ROOT_PATH.'include/ws_protocols/jsonalt_encoder.php');
$encoder = new PwgJsonAlternativeEncoder();
break;
case 'xmlrpc':
include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
$encoder = new PwgXmlRpcEncoder();

View file

@ -0,0 +1,38 @@
<?php
// +-----------------------------------------------------------------------+
// | This file is part of Piwigo. |
// | |
// | For copyright and license information, please view the COPYING.txt |
// | file that was distributed with this source code. |
// +-----------------------------------------------------------------------+
class PwgJsonAlternativeEncoder extends PwgResponseEncoder
{
function encodeResponse($response)
{
if ($response instanceof PwgError)
{
return json_encode(
array(
'stat' => 'fail',
'err' => $response->code(),
'message' => $response->message(),
)
);
}
parent::flattenResponse($response);
return json_encode(
array(
'stat' => 'ok',
'result' => $response,
)
);
}
function getContentType()
{
return 'application/json';
}
}
?>

View file

@ -133,7 +133,8 @@
<label for='responseFormat'>Response format</label>
<div class="select">
<select id="responseFormat">
<option value="json" selected>JSON</option>
<option value="json" selected>JSON (test/plain)</option>
<option value="jsonalt" selected>JSON (application/json)</option>
<option value="rest" selected>REST (xml)</option>
<option value="php">PHP serial</option>
<option value="xmlrpc">XML RPC</option>