source: trunk/ws.php @ 1849

Last change on this file since 1849 was 1849, checked in by rvelices, 17 years ago
  • user comments are not saved in the database with htmlspecialchars anymore
  • web service: added the possibility to enter a user comment using the service...
  • new comment functions from picture_comment.inc.php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | file          : $Id: ws.php 1849 2007-02-22 01:12:32Z rvelices $
7// | last update   : $Date: 2007-02-22 01:12:32 +0000 (Thu, 22 Feb 2007) $
8// | last modifier : $Author: rvelices $
9// | revision      : $Rev: 1849 $
10// +-----------------------------------------------------------------------+
11// | This program is free software; you can redistribute it and/or modify  |
12// | it under the terms of the GNU General Public License as published by  |
13// | the Free Software Foundation                                          |
14// |                                                                       |
15// | This program is distributed in the hope that it will be useful, but   |
16// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
17// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
18// | General Public License for more details.                              |
19// |                                                                       |
20// | You should have received a copy of the GNU General Public License     |
21// | along with this program; if not, write to the Free Software           |
22// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
23// | USA.                                                                  |
24// +-----------------------------------------------------------------------+
25
26define ('PHPWG_ROOT_PATH', './');
27
28include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
29include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');
30
31if ( !$conf['allow_web_services'] )
32{
33  page_forbidden('Web services are disabled');
34}
35
36/**
37 * event handler that registers standard methods with the web service
38 */
39function ws_addDefaultMethods( $arr )
40{
41  include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
42  global $conf, $user;
43  $service = &$arr[0];
44  $service->addMethod('pwg.getVersion', 'ws_getVersion', null,
45      'retrieves the PWG version');
46
47  $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages',
48      array(
49        'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY),
50        'recursive'=>array('default'=>false),
51        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
52        'page' => array('default'=>0),
53        'order' => array('default'=>null),
54        'f_min_rate' => array( 'default'=> null ),
55        'f_max_rate' => array( 'default'=> null ),
56        'f_min_hit' => array( 'default'=> null ),
57        'f_max_hit' => array( 'default'=> null ),
58        'f_min_date_available' => array( 'default'=> null ),
59        'f_max_date_available' => array( 'default'=> null ),
60        'f_min_date_created' => array( 'default'=> null ),
61        'f_max_date_created' => array( 'default'=> null ),
62        'f_min_ratio' => array( 'default'=> null ),
63        'f_max_ratio' => array( 'default'=> null ),
64        'f_with_thumbnail' => array( 'default'=> false ),
65      ),
66      'Returns elements for the corresponding categories.
67<br/><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array.
68<br/><b>order</b> comma separated fields for sorting (file,id, average_rate,...)'
69    );
70
71  $service->addMethod('pwg.categories.getList', 'ws_categories_getList',
72      array(
73        'cat_id' => array('default'=>0),
74        'recursive' => array('default'=>false),
75        'public' => array('default'=>false),
76      ),
77      'retrieves a list of categories' );
78
79  $service->addMethod('pwg.images.addComment', 'ws_images_addComment',
80      array(
81        'image_id' => array(),
82        'author' => array( 'default' => $user['is_the_guest']? 'guest':$user['username']),
83        'content' => array(),
84        'key' => array(),
85      ),
86      'add a comment to an image' );
87
88  $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo',
89      array(
90        'image_id' => array(),
91        'comments_page' => array('default'=>0 ),
92        'comments_per_page' => array( 
93              'default' => $conf['nb_comment_page'], 
94              'maxValue' => 2*$conf['nb_comment_page'],
95            ),
96      ),
97      'retrieves information about the given photo' );
98
99  $service->addMethod('pwg.images.search', 'ws_images_search',
100      array(
101        'query'=>array(),
102        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
103        'page' => array('default'=>0),
104        'order' => array('default'=>null),
105        'f_min_rate' => array( 'default'=> null ),
106        'f_max_rate' => array( 'default'=> null ),
107        'f_min_hit' => array( 'default'=> null ),
108        'f_max_hit' => array( 'default'=> null ),
109        'f_min_date_available' => array( 'default'=> null ),
110        'f_max_date_available' => array( 'default'=> null ),
111        'f_min_date_created' => array( 'default'=> null ),
112        'f_max_date_created' => array( 'default'=> null ),
113        'f_min_ratio' => array( 'default'=> null ),
114        'f_max_ratio' => array( 'default'=> null ),
115        'f_with_thumbnail' => array( 'default'=> false ),
116      ),
117      'Returns elements for the corresponding query search.'
118    );
119
120  $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' );
121  $service->addMethod('pwg.session.login', 'ws_session_login',
122    array('username', 'password'),
123    'POST method only' );
124  $service->addMethod('pwg.session.logout', 'ws_session_logout', null, '');
125
126  $service->addMethod('pwg.tags.getList', 'ws_tags_getList',
127    array('sort_by_counter' => array('default' =>false) ),
128    'retrieves a list of available tags');
129  $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages',
130      array(
131        'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
132        'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
133        'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
134        'tag_mode_and'=>array('default'=>false),
135        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
136        'page' => array('default'=>0),
137        'order' => array('default'=>null),
138        'f_min_rate' => array( 'default'=> null ),
139        'f_max_rate' => array( 'default'=> null ),
140        'f_min_hit' => array( 'default'=> null ),
141        'f_max_hit' => array( 'default'=> null ),
142        'f_min_date_available' => array( 'default'=> null ),
143        'f_max_date_available' => array( 'default'=> null ),
144        'f_min_date_created' => array( 'default'=> null ),
145        'f_max_date_created' => array( 'default'=> null ),
146        'f_min_ratio' => array( 'default'=> null ),
147        'f_max_ratio' => array( 'default'=> null ),
148        'f_with_thumbnail' => array( 'default'=> false ),
149      ),
150      'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
151    );
152}
153
154add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
155
156
157add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
158
159$calling_partner_id = '';
160$requestFormat = null;
161$responseFormat = null;
162
163if ( isset($_GET['partner']) )
164{
165  $calling_partner_id = $_GET['partner'];
166}
167if ( isset($_GET['format']) )
168{
169  $responseFormat = $_GET['format'];
170}
171
172if ( isset($HTTP_RAW_POST_DATA) )
173{
174  $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
175  if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 )
176  {
177  }
178  else
179  {
180    $requestFormat = "json";
181  }
182}
183else
184{
185  $requestFormat = "rest";
186}
187
188if ( !isset($responseFormat) and isset($requestFormat) )
189{
190  $responseFormat = $requestFormat;
191}
192
193$service = new PwgServer();
194
195if (!is_null($requestFormat))
196{
197  $handler = null;
198  switch ($requestFormat)
199  {
200    case 'rest':
201      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
202      $handler = new PwgRestRequestHandler();
203      break;
204  }
205  $service->setHandler($requestFormat, $handler);
206}
207
208if (!is_null($responseFormat))
209{
210  $encoder = null;
211  switch ($responseFormat)
212  {
213    case 'rest':
214      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
215      $encoder = new PwgRestEncoder();
216      break;
217    case 'php':
218      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
219      $encoder = new PwgSerialPhpEncoder();
220      break;
221    case 'json':
222      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
223      $encoder = new PwgJsonEncoder();
224      break;
225    case 'xmlrpc':
226      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
227      $encoder = new PwgXmlRpcEncoder();
228      break;
229  }
230  $service->setEncoder($responseFormat, $encoder);
231}
232
233set_make_full_url();
234$service->run();
235
236?>
Note: See TracBrowser for help on using the repository browser.