2007-01-06 12:13:08 +01:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
2008-04-05 00:57:23 +02:00
|
|
|
// | Piwigo - a PHP based picture gallery |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Copyright(C) 2008 Piwigo Team http://piwigo.org |
|
|
|
|
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
|
|
|
|
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | This program is free software; you can redistribute it and/or modify |
|
|
|
|
// | it under the terms of the GNU General Public License as published by |
|
|
|
|
// | the Free Software Foundation |
|
2007-01-06 12:13:08 +01:00
|
|
|
// | |
|
|
|
|
// | This program is distributed in the hope that it will be useful, but |
|
|
|
|
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
|
// | General Public License for more details. |
|
|
|
|
// | |
|
|
|
|
// | You should have received a copy of the GNU General Public License |
|
|
|
|
// | along with this program; if not, write to the Free Software |
|
|
|
|
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
|
// | USA. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
define ('PHPWG_ROOT_PATH', './');
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
2008-05-02 23:56:21 +02:00
|
|
|
check_status(ACCESS_FREE);
|
2007-01-06 12:13:08 +01:00
|
|
|
include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');
|
|
|
|
|
2007-02-06 02:02:06 +01:00
|
|
|
if ( !$conf['allow_web_services'] )
|
|
|
|
{
|
|
|
|
page_forbidden('Web services are disabled');
|
|
|
|
}
|
|
|
|
|
2007-01-29 21:38:08 +01:00
|
|
|
/**
|
|
|
|
* event handler that registers standard methods with the web service
|
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_addDefaultMethods( $arr )
|
|
|
|
{
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
|
2007-02-22 02:12:32 +01:00
|
|
|
global $conf, $user;
|
2007-01-06 12:13:08 +01:00
|
|
|
$service = &$arr[0];
|
|
|
|
$service->addMethod('pwg.getVersion', 'ws_getVersion', null,
|
|
|
|
'retrieves the PWG version');
|
|
|
|
|
2008-07-15 03:29:23 +02:00
|
|
|
$service->addMethod('pwg.caddie.add', 'ws_caddie_add',
|
2008-07-12 02:30:27 +02:00
|
|
|
array(
|
|
|
|
'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ),
|
|
|
|
),
|
|
|
|
'adds the elements to the caddie');
|
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
$service->addMethod('pwg.categories.getImages', 'ws_categories_getImages',
|
|
|
|
array(
|
|
|
|
'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY),
|
|
|
|
'recursive'=>array('default'=>false),
|
2007-02-06 02:02:06 +01:00
|
|
|
'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
|
2007-01-06 12:13:08 +01:00
|
|
|
'page' => array('default'=>0),
|
|
|
|
'order' => array('default'=>null),
|
|
|
|
'f_min_rate' => array( 'default'=> null ),
|
|
|
|
'f_max_rate' => array( 'default'=> null ),
|
|
|
|
'f_min_hit' => array( 'default'=> null ),
|
|
|
|
'f_max_hit' => array( 'default'=> null ),
|
|
|
|
'f_min_date_available' => array( 'default'=> null ),
|
|
|
|
'f_max_date_available' => array( 'default'=> null ),
|
|
|
|
'f_min_date_created' => array( 'default'=> null ),
|
|
|
|
'f_max_date_created' => array( 'default'=> null ),
|
|
|
|
'f_min_ratio' => array( 'default'=> null ),
|
|
|
|
'f_max_ratio' => array( 'default'=> null ),
|
|
|
|
'f_with_thumbnail' => array( 'default'=> false ),
|
|
|
|
),
|
|
|
|
'Returns elements for the corresponding categories.
|
|
|
|
<br/><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array.
|
|
|
|
<br/><b>order</b> comma separated fields for sorting (file,id, average_rate,...)'
|
|
|
|
);
|
|
|
|
|
|
|
|
$service->addMethod('pwg.categories.getList', 'ws_categories_getList',
|
|
|
|
array(
|
|
|
|
'cat_id' => array('default'=>0),
|
|
|
|
'recursive' => array('default'=>false),
|
|
|
|
'public' => array('default'=>false),
|
|
|
|
),
|
|
|
|
'retrieves a list of categories' );
|
|
|
|
|
2007-02-22 02:12:32 +01:00
|
|
|
$service->addMethod('pwg.images.addComment', 'ws_images_addComment',
|
|
|
|
array(
|
|
|
|
'image_id' => array(),
|
2007-06-06 00:01:15 +02:00
|
|
|
'author' => array( 'default' => is_a_guest()? 'guest':$user['username']),
|
2007-02-22 02:12:32 +01:00
|
|
|
'content' => array(),
|
|
|
|
'key' => array(),
|
|
|
|
),
|
|
|
|
'add a comment to an image' );
|
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
$service->addMethod('pwg.images.getInfo', 'ws_images_getInfo',
|
2007-02-22 02:12:32 +01:00
|
|
|
array(
|
|
|
|
'image_id' => array(),
|
|
|
|
'comments_page' => array('default'=>0 ),
|
2008-07-15 03:29:23 +02:00
|
|
|
'comments_per_page' => array(
|
|
|
|
'default' => $conf['nb_comment_page'],
|
2007-02-22 02:12:32 +01:00
|
|
|
'maxValue' => 2*$conf['nb_comment_page'],
|
|
|
|
),
|
|
|
|
),
|
2007-01-06 12:13:08 +01:00
|
|
|
'retrieves information about the given photo' );
|
|
|
|
|
2008-07-15 03:29:23 +02:00
|
|
|
$service->addMethod('pwg.images.rate', 'ws_images_rate',
|
|
|
|
array(
|
|
|
|
'image_id' => array(),
|
|
|
|
'rate' => array(),
|
|
|
|
),
|
|
|
|
'rate the image' );
|
|
|
|
|
2007-02-19 17:25:47 +01:00
|
|
|
$service->addMethod('pwg.images.search', 'ws_images_search',
|
|
|
|
array(
|
|
|
|
'query'=>array(),
|
|
|
|
'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
|
|
|
|
'page' => array('default'=>0),
|
|
|
|
'order' => array('default'=>null),
|
|
|
|
'f_min_rate' => array( 'default'=> null ),
|
|
|
|
'f_max_rate' => array( 'default'=> null ),
|
|
|
|
'f_min_hit' => array( 'default'=> null ),
|
|
|
|
'f_max_hit' => array( 'default'=> null ),
|
|
|
|
'f_min_date_available' => array( 'default'=> null ),
|
|
|
|
'f_max_date_available' => array( 'default'=> null ),
|
|
|
|
'f_min_date_created' => array( 'default'=> null ),
|
|
|
|
'f_max_date_created' => array( 'default'=> null ),
|
|
|
|
'f_min_ratio' => array( 'default'=> null ),
|
|
|
|
'f_max_ratio' => array( 'default'=> null ),
|
|
|
|
'f_with_thumbnail' => array( 'default'=> false ),
|
|
|
|
),
|
|
|
|
'Returns elements for the corresponding query search.'
|
|
|
|
);
|
2008-07-30 23:53:00 +02:00
|
|
|
|
|
|
|
$service->addMethod(
|
|
|
|
'pwg.images.setPrivacyLevel',
|
|
|
|
'ws_images_setPrivacyLevel',
|
|
|
|
array(
|
|
|
|
'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY),
|
|
|
|
'level' => array('maxValue'=>$conf['available_permission_levels']),
|
2008-07-02 03:11:26 +02:00
|
|
|
),
|
2008-07-30 23:53:00 +02:00
|
|
|
'sets the privacy levels for the images'
|
|
|
|
);
|
2007-02-19 17:25:47 +01:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
$service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' );
|
|
|
|
$service->addMethod('pwg.session.login', 'ws_session_login',
|
|
|
|
array('username', 'password'),
|
|
|
|
'POST method only' );
|
|
|
|
$service->addMethod('pwg.session.logout', 'ws_session_logout', null, '');
|
|
|
|
|
|
|
|
$service->addMethod('pwg.tags.getList', 'ws_tags_getList',
|
|
|
|
array('sort_by_counter' => array('default' =>false) ),
|
|
|
|
'retrieves a list of available tags');
|
|
|
|
$service->addMethod('pwg.tags.getImages', 'ws_tags_getImages',
|
|
|
|
array(
|
|
|
|
'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
|
|
|
|
'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
|
|
|
|
'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
|
|
|
|
'tag_mode_and'=>array('default'=>false),
|
2007-02-06 02:02:06 +01:00
|
|
|
'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
|
2007-01-06 12:13:08 +01:00
|
|
|
'page' => array('default'=>0),
|
|
|
|
'order' => array('default'=>null),
|
|
|
|
'f_min_rate' => array( 'default'=> null ),
|
|
|
|
'f_max_rate' => array( 'default'=> null ),
|
|
|
|
'f_min_hit' => array( 'default'=> null ),
|
|
|
|
'f_max_hit' => array( 'default'=> null ),
|
|
|
|
'f_min_date_available' => array( 'default'=> null ),
|
|
|
|
'f_max_date_available' => array( 'default'=> null ),
|
|
|
|
'f_min_date_created' => array( 'default'=> null ),
|
|
|
|
'f_max_date_created' => array( 'default'=> null ),
|
|
|
|
'f_min_ratio' => array( 'default'=> null ),
|
|
|
|
'f_max_ratio' => array( 'default'=> null ),
|
|
|
|
'f_with_thumbnail' => array( 'default'=> false ),
|
|
|
|
),
|
|
|
|
'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
|
|
|
|
);
|
2008-07-30 23:53:00 +02:00
|
|
|
|
|
|
|
$service->addMethod(
|
|
|
|
'pwg.images.add',
|
|
|
|
'ws_images_add',
|
|
|
|
array(
|
|
|
|
'name',
|
|
|
|
'category_id',
|
|
|
|
'file_content',
|
|
|
|
'file_sum',
|
|
|
|
'thumbnail_content',
|
|
|
|
'thumbnail_sum'
|
|
|
|
),
|
|
|
|
'POST method only'
|
|
|
|
);
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
2007-01-29 21:38:08 +01:00
|
|
|
add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
|
2007-01-06 12:13:08 +01:00
|
|
|
|
2007-01-29 21:38:08 +01:00
|
|
|
|
|
|
|
add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
|
|
|
|
|
|
|
|
$calling_partner_id = '';
|
2007-01-06 12:13:08 +01:00
|
|
|
$requestFormat = null;
|
|
|
|
$responseFormat = null;
|
|
|
|
|
2007-01-29 21:38:08 +01:00
|
|
|
if ( isset($_GET['partner']) )
|
|
|
|
{
|
|
|
|
$calling_partner_id = $_GET['partner'];
|
|
|
|
}
|
2007-01-06 12:13:08 +01:00
|
|
|
if ( isset($_GET['format']) )
|
|
|
|
{
|
|
|
|
$responseFormat = $_GET['format'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset($HTTP_RAW_POST_DATA) )
|
|
|
|
{
|
|
|
|
$HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
|
|
|
|
if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$requestFormat = "json";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$requestFormat = "rest";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !isset($responseFormat) and isset($requestFormat) )
|
|
|
|
{
|
|
|
|
$responseFormat = $requestFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
$service = new PwgServer();
|
|
|
|
|
|
|
|
if (!is_null($requestFormat))
|
|
|
|
{
|
|
|
|
$handler = null;
|
|
|
|
switch ($requestFormat)
|
|
|
|
{
|
|
|
|
case 'rest':
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
|
|
|
|
$handler = new PwgRestRequestHandler();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$service->setHandler($requestFormat, $handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_null($responseFormat))
|
|
|
|
{
|
|
|
|
$encoder = null;
|
|
|
|
switch ($responseFormat)
|
|
|
|
{
|
|
|
|
case 'rest':
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
|
|
|
|
$encoder = new PwgRestEncoder();
|
|
|
|
break;
|
|
|
|
case 'php':
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
|
|
|
|
$encoder = new PwgSerialPhpEncoder();
|
|
|
|
break;
|
|
|
|
case 'json':
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
|
|
|
|
$encoder = new PwgJsonEncoder();
|
|
|
|
break;
|
|
|
|
case 'xmlrpc':
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
|
|
|
|
$encoder = new PwgXmlRpcEncoder();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$service->setEncoder($responseFormat, $encoder);
|
|
|
|
}
|
|
|
|
|
2007-01-24 06:07:08 +01:00
|
|
|
set_make_full_url();
|
2007-01-06 12:13:08 +01:00
|
|
|
$service->run();
|
|
|
|
|
|
|
|
?>
|