1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
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 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | define ('PHPWG_ROOT_PATH', './'); |
---|
25 | |
---|
26 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
27 | check_status(ACCESS_FREE); |
---|
28 | include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php'); |
---|
29 | |
---|
30 | if ( !$conf['allow_web_services'] ) |
---|
31 | { |
---|
32 | page_forbidden('Web services are disabled'); |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * event handler that registers standard methods with the web service |
---|
37 | */ |
---|
38 | function ws_addDefaultMethods( $arr ) |
---|
39 | { |
---|
40 | include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php'); |
---|
41 | global $conf, $user; |
---|
42 | $service = &$arr[0]; |
---|
43 | $service->addMethod('pwg.getVersion', 'ws_getVersion', null, |
---|
44 | 'retrieves the PWG version'); |
---|
45 | |
---|
46 | $service->addMethod('pwg.caddie.add', 'ws_caddie_add', |
---|
47 | array( |
---|
48 | 'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
49 | ), |
---|
50 | 'adds the elements to the caddie'); |
---|
51 | |
---|
52 | $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages', |
---|
53 | array( |
---|
54 | 'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY), |
---|
55 | 'recursive'=>array('default'=>false), |
---|
56 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
57 | 'page' => array('default'=>0), |
---|
58 | 'order' => array('default'=>null), |
---|
59 | 'f_min_rate' => array( 'default'=> null ), |
---|
60 | 'f_max_rate' => array( 'default'=> null ), |
---|
61 | 'f_min_hit' => array( 'default'=> null ), |
---|
62 | 'f_max_hit' => array( 'default'=> null ), |
---|
63 | 'f_min_date_available' => array( 'default'=> null ), |
---|
64 | 'f_max_date_available' => array( 'default'=> null ), |
---|
65 | 'f_min_date_created' => array( 'default'=> null ), |
---|
66 | 'f_max_date_created' => array( 'default'=> null ), |
---|
67 | 'f_min_ratio' => array( 'default'=> null ), |
---|
68 | 'f_max_ratio' => array( 'default'=> null ), |
---|
69 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
70 | ), |
---|
71 | 'Returns elements for the corresponding categories. |
---|
72 | <br><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array. |
---|
73 | <br><b>order</b> comma separated fields for sorting (file,id, average_rate,...)' |
---|
74 | ); |
---|
75 | |
---|
76 | $service->addMethod('pwg.categories.getList', 'ws_categories_getList', |
---|
77 | array( |
---|
78 | 'cat_id' => array('default'=>0), |
---|
79 | 'recursive' => array('default'=>false), |
---|
80 | 'public' => array('default'=>false), |
---|
81 | ), |
---|
82 | 'retrieves a list of categories' ); |
---|
83 | |
---|
84 | $service->addMethod('pwg.images.addComment', 'ws_images_addComment', |
---|
85 | array( |
---|
86 | 'image_id' => array(), |
---|
87 | 'author' => array( 'default' => is_a_guest()? 'guest':$user['username']), |
---|
88 | 'content' => array(), |
---|
89 | 'key' => array(), |
---|
90 | ), |
---|
91 | 'add a comment to an image' ); |
---|
92 | |
---|
93 | $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo', |
---|
94 | array( |
---|
95 | 'image_id' => array(), |
---|
96 | 'comments_page' => array('default'=>0 ), |
---|
97 | 'comments_per_page' => array( |
---|
98 | 'default' => $conf['nb_comment_page'], |
---|
99 | 'maxValue' => 2*$conf['nb_comment_page'], |
---|
100 | ), |
---|
101 | ), |
---|
102 | 'retrieves information about the given photo' ); |
---|
103 | |
---|
104 | $service->addMethod('pwg.images.rate', 'ws_images_rate', |
---|
105 | array( |
---|
106 | 'image_id' => array(), |
---|
107 | 'rate' => array(), |
---|
108 | ), |
---|
109 | 'rate the image' ); |
---|
110 | |
---|
111 | $service->addMethod('pwg.images.search', 'ws_images_search', |
---|
112 | array( |
---|
113 | 'query'=>array(), |
---|
114 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
115 | 'page' => array('default'=>0), |
---|
116 | 'order' => array('default'=>null), |
---|
117 | 'f_min_rate' => array( 'default'=> null ), |
---|
118 | 'f_max_rate' => array( 'default'=> null ), |
---|
119 | 'f_min_hit' => array( 'default'=> null ), |
---|
120 | 'f_max_hit' => array( 'default'=> null ), |
---|
121 | 'f_min_date_available' => array( 'default'=> null ), |
---|
122 | 'f_max_date_available' => array( 'default'=> null ), |
---|
123 | 'f_min_date_created' => array( 'default'=> null ), |
---|
124 | 'f_max_date_created' => array( 'default'=> null ), |
---|
125 | 'f_min_ratio' => array( 'default'=> null ), |
---|
126 | 'f_max_ratio' => array( 'default'=> null ), |
---|
127 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
128 | ), |
---|
129 | 'Returns elements for the corresponding query search.' |
---|
130 | ); |
---|
131 | |
---|
132 | $service->addMethod( |
---|
133 | 'pwg.images.setPrivacyLevel', |
---|
134 | 'ws_images_setPrivacyLevel', |
---|
135 | array( |
---|
136 | 'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY), |
---|
137 | 'level' => array('maxValue'=>$conf['available_permission_levels']), |
---|
138 | ), |
---|
139 | 'sets the privacy levels for the images (POST method only)' |
---|
140 | ); |
---|
141 | |
---|
142 | $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' ); |
---|
143 | $service->addMethod('pwg.session.login', 'ws_session_login', |
---|
144 | array('username', 'password'), |
---|
145 | 'POST method only' ); |
---|
146 | $service->addMethod('pwg.session.logout', 'ws_session_logout', null, ''); |
---|
147 | |
---|
148 | $service->addMethod('pwg.tags.getList', 'ws_tags_getList', |
---|
149 | array('sort_by_counter' => array('default' =>false) ), |
---|
150 | 'retrieves a list of available tags'); |
---|
151 | $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages', |
---|
152 | array( |
---|
153 | 'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
154 | 'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
155 | 'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
156 | 'tag_mode_and'=>array('default'=>false), |
---|
157 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
158 | 'page' => array('default'=>0), |
---|
159 | 'order' => array('default'=>null), |
---|
160 | 'f_min_rate' => array( 'default'=> null ), |
---|
161 | 'f_max_rate' => array( 'default'=> null ), |
---|
162 | 'f_min_hit' => array( 'default'=> null ), |
---|
163 | 'f_max_hit' => array( 'default'=> null ), |
---|
164 | 'f_min_date_available' => array( 'default'=> null ), |
---|
165 | 'f_max_date_available' => array( 'default'=> null ), |
---|
166 | 'f_min_date_created' => array( 'default'=> null ), |
---|
167 | 'f_max_date_created' => array( 'default'=> null ), |
---|
168 | 'f_min_ratio' => array( 'default'=> null ), |
---|
169 | 'f_max_ratio' => array( 'default'=> null ), |
---|
170 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
171 | ), |
---|
172 | 'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. ' |
---|
173 | ); |
---|
174 | |
---|
175 | $service->addMethod( |
---|
176 | 'pwg.images.addChunk', |
---|
177 | 'ws_images_add_chunk', |
---|
178 | array( |
---|
179 | 'data' => array(), |
---|
180 | 'original_sum' => array(), |
---|
181 | 'type' => array(), |
---|
182 | 'position' => array(), |
---|
183 | ), |
---|
184 | 'POST method only. For admin only.' |
---|
185 | ); |
---|
186 | |
---|
187 | $service->addMethod( |
---|
188 | 'pwg.images.addFile', |
---|
189 | 'ws_images_addFile', |
---|
190 | array( |
---|
191 | 'image_id' => array(), |
---|
192 | 'type' => array(), |
---|
193 | 'sum' => array(), |
---|
194 | ), |
---|
195 | 'Add or update a file for an existing photo. pwg.images.addChunk must have been called before (maybe several times)' |
---|
196 | ); |
---|
197 | |
---|
198 | |
---|
199 | $service->addMethod( |
---|
200 | 'pwg.images.add', |
---|
201 | 'ws_images_add', |
---|
202 | array( |
---|
203 | 'file_sum' => array(), |
---|
204 | 'thumbnail_sum' => array(), |
---|
205 | 'high_sum' => array('default' => null), |
---|
206 | 'original_sum' => array(), |
---|
207 | 'original_filename' => array('default' => null), |
---|
208 | 'name' => array('default' => null), |
---|
209 | 'author' => array('default' => null), |
---|
210 | 'date_creation' => array('default' => null), |
---|
211 | 'comment' => array('default' => null), |
---|
212 | 'categories' => array('default' => null), |
---|
213 | 'tag_ids' => array('default' => null), |
---|
214 | 'level' => array( |
---|
215 | 'default' => 0, |
---|
216 | 'maxValue' => $conf['available_permission_levels'] |
---|
217 | ), |
---|
218 | ), |
---|
219 | 'POST method only. |
---|
220 | <br><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.' |
---|
221 | ); |
---|
222 | |
---|
223 | $service->addMethod( |
---|
224 | 'pwg.images.addSimple', |
---|
225 | 'ws_images_addSimple', |
---|
226 | array( |
---|
227 | 'category' => array('default' => null), |
---|
228 | 'name' => array('default' => null), |
---|
229 | 'author' => array('default' => null), |
---|
230 | 'comment' => array('default' => null), |
---|
231 | 'level' => array( |
---|
232 | 'default' => 0, |
---|
233 | 'maxValue' => $conf['available_permission_levels'] |
---|
234 | ), |
---|
235 | 'tags' => array('default' => null), |
---|
236 | 'image_id' => array('default' => null), |
---|
237 | ), |
---|
238 | 'POST method only.<br>Use the <b>image</b> field for uploading file.<br>Set the form encoding to "form-data"<br><b>category</b> is the numeric identifier of the destination category.<br>You can update an existing photo if you define an existing image_id.' |
---|
239 | ); |
---|
240 | |
---|
241 | $service->addMethod( |
---|
242 | 'pwg.images.delete', |
---|
243 | 'ws_images_delete', |
---|
244 | array( |
---|
245 | 'image_id'=>array('default'=>0), |
---|
246 | 'pwg_token' => array('default' => null), |
---|
247 | ), |
---|
248 | 'Delete photos. You can give several image_ids, comma separated' |
---|
249 | ); |
---|
250 | |
---|
251 | $service->addMethod( |
---|
252 | 'pwg.categories.getAdminList', |
---|
253 | 'ws_categories_getAdminList', |
---|
254 | array(), |
---|
255 | 'administration method only' |
---|
256 | ); |
---|
257 | |
---|
258 | $service->addMethod( |
---|
259 | 'pwg.categories.add', |
---|
260 | 'ws_categories_add', |
---|
261 | array( |
---|
262 | 'name' => array(), |
---|
263 | 'parent' => array('default' => null), |
---|
264 | ), |
---|
265 | 'administration method only' |
---|
266 | ); |
---|
267 | |
---|
268 | $service->addMethod( |
---|
269 | 'pwg.categories.delete', |
---|
270 | 'ws_categories_delete', |
---|
271 | array( |
---|
272 | 'category_id'=>array('default'=>0), |
---|
273 | 'pwg_token' => array('default' => null), |
---|
274 | 'photo_deletion_mode' => array('default' => 'delete_orphans'), |
---|
275 | ), |
---|
276 | 'Delete categories. You can give several category_ids, comma separated. |
---|
277 | <br><b>photo_deletion_mode</b> can be "no_delete" (may create orphan photos), "delete_orphans" (default mode, only deletes photos linked to no other album) or "force_delete" (delete all photos, even those linked to other albums)' |
---|
278 | ); |
---|
279 | |
---|
280 | $service->addMethod( |
---|
281 | 'pwg.categories.move', |
---|
282 | 'ws_categories_move', |
---|
283 | array( |
---|
284 | 'category_id'=>array('default'=>0), |
---|
285 | 'parent'=>array('default'=>0), |
---|
286 | 'pwg_token' => array('default' => null), |
---|
287 | ), |
---|
288 | 'Move categories. You can give several category_ids, comma separated. Set parent as 0 to move to gallery root. Only virtual categories can be moved.' |
---|
289 | ); |
---|
290 | |
---|
291 | $service->addMethod( |
---|
292 | 'pwg.tags.getAdminList', |
---|
293 | 'ws_tags_getAdminList', |
---|
294 | array(), |
---|
295 | 'administration method only' |
---|
296 | ); |
---|
297 | |
---|
298 | $service->addMethod( |
---|
299 | 'pwg.tags.add', |
---|
300 | 'ws_tags_add', |
---|
301 | array( |
---|
302 | 'name' => array(), |
---|
303 | ), |
---|
304 | 'administration method only' |
---|
305 | ); |
---|
306 | |
---|
307 | $service->addMethod( |
---|
308 | 'pwg.images.exist', |
---|
309 | 'ws_images_exist', |
---|
310 | array( |
---|
311 | 'md5sum_list'=> array('default' => null), |
---|
312 | 'filename_list' => array('default' => null), |
---|
313 | ), |
---|
314 | 'check existence of a photo list' |
---|
315 | ); |
---|
316 | |
---|
317 | $service->addMethod( |
---|
318 | 'pwg.images.checkFiles', |
---|
319 | 'ws_images_checkFiles', |
---|
320 | array( |
---|
321 | 'image_id' => array(), |
---|
322 | 'thumbnail_sum' => array('default' => null), |
---|
323 | 'file_sum' => array('default' => null), |
---|
324 | 'high_sum' => array('default' => null), |
---|
325 | ), |
---|
326 | 'check if you have updated version of your files for a given photo, for each requested file type, the answer can be "missing", "equals" or "differs"' |
---|
327 | ); |
---|
328 | |
---|
329 | $service->addMethod( |
---|
330 | 'pwg.images.checkUpload', |
---|
331 | 'ws_images_checkUpload', |
---|
332 | null, |
---|
333 | 'check if Piwigo is ready for upload' |
---|
334 | ); |
---|
335 | |
---|
336 | $service->addMethod( |
---|
337 | 'pwg.images.setInfo', |
---|
338 | 'ws_images_setInfo', |
---|
339 | array( |
---|
340 | 'image_id' => array(), |
---|
341 | |
---|
342 | 'name' => array('default' => null), |
---|
343 | 'author' => array('default' => null), |
---|
344 | 'date_creation' => array('default' => null), |
---|
345 | 'comment' => array('default' => null), |
---|
346 | 'categories' => array('default' => null), |
---|
347 | 'tag_ids' => array('default' => null), |
---|
348 | 'level' => array( |
---|
349 | 'default' => 0, |
---|
350 | 'maxValue' => $conf['available_permission_levels'] |
---|
351 | ), |
---|
352 | 'single_value_mode' => array('default' => 'fill_if_empty'), |
---|
353 | 'multiple_value_mode' => array('default' => 'append'), |
---|
354 | ), |
---|
355 | 'POST method only. Admin only |
---|
356 | <br><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given. |
---|
357 | <br><b>single_value_mode</b> can be "fill_if_empty" (only use the input value if the corresponding values is currently empty) or "replace" (overwrite any existing value) and applies to single values properties like name/author/date_creation/comment |
---|
358 | <br><b>multiple_value_mode</b> can be "append" (no change on existing values, add the new values) or "replace" and applies to multiple values properties like tag_ids/categories' |
---|
359 | ); |
---|
360 | |
---|
361 | $service->addMethod( |
---|
362 | 'pwg.categories.setInfo', |
---|
363 | 'ws_categories_setInfo', |
---|
364 | array( |
---|
365 | 'category_id' => array(), |
---|
366 | |
---|
367 | 'name' => array('default' => null), |
---|
368 | 'comment' => array('default' => null), |
---|
369 | ), |
---|
370 | 'POST method only.' |
---|
371 | ); |
---|
372 | |
---|
373 | $service->addMethod( |
---|
374 | 'pwg.plugins.getList', |
---|
375 | 'ws_plugins_getList', |
---|
376 | array(), |
---|
377 | 'get the list of plugin with id, name, version, state and description |
---|
378 | <br>administration status required' |
---|
379 | ); |
---|
380 | |
---|
381 | $service->addMethod( |
---|
382 | 'pwg.plugins.performAction', |
---|
383 | 'ws_plugins_performAction', |
---|
384 | array( |
---|
385 | 'action' => array('default' => null), |
---|
386 | 'plugin' => array('default' => null), |
---|
387 | 'pwg_token' => array('default' => null), |
---|
388 | ), |
---|
389 | 'install/activate/deactivate/uninstall/delete a plugin |
---|
390 | <br>administration status required' |
---|
391 | ); |
---|
392 | |
---|
393 | $service->addMethod( |
---|
394 | 'pwg.themes.performAction', |
---|
395 | 'ws_themes_performAction', |
---|
396 | array( |
---|
397 | 'action' => array('default' => null), |
---|
398 | 'themes' => array('default' => null), |
---|
399 | 'pwg_token' => array('default' => null), |
---|
400 | ), |
---|
401 | 'activate/deactivate/delete/set_default a theme<br>administration status required' |
---|
402 | ); |
---|
403 | } |
---|
404 | |
---|
405 | add_event_handler('ws_add_methods', 'ws_addDefaultMethods'); |
---|
406 | |
---|
407 | |
---|
408 | add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
409 | |
---|
410 | $requestFormat = null; |
---|
411 | $responseFormat = null; |
---|
412 | |
---|
413 | if ( isset($_GET['format']) ) |
---|
414 | { |
---|
415 | $responseFormat = $_GET['format']; |
---|
416 | } |
---|
417 | |
---|
418 | if ( isset($HTTP_RAW_POST_DATA) ) |
---|
419 | { |
---|
420 | $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); |
---|
421 | if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 ) |
---|
422 | { |
---|
423 | } |
---|
424 | else |
---|
425 | { |
---|
426 | $requestFormat = "json"; |
---|
427 | } |
---|
428 | } |
---|
429 | else |
---|
430 | { |
---|
431 | $requestFormat = "rest"; |
---|
432 | } |
---|
433 | |
---|
434 | if ( !isset($responseFormat) and isset($requestFormat) ) |
---|
435 | { |
---|
436 | $responseFormat = $requestFormat; |
---|
437 | } |
---|
438 | |
---|
439 | $service = new PwgServer(); |
---|
440 | |
---|
441 | if (!is_null($requestFormat)) |
---|
442 | { |
---|
443 | $handler = null; |
---|
444 | switch ($requestFormat) |
---|
445 | { |
---|
446 | case 'rest': |
---|
447 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php'); |
---|
448 | $handler = new PwgRestRequestHandler(); |
---|
449 | break; |
---|
450 | } |
---|
451 | $service->setHandler($requestFormat, $handler); |
---|
452 | } |
---|
453 | |
---|
454 | if (!is_null($responseFormat)) |
---|
455 | { |
---|
456 | $encoder = null; |
---|
457 | switch ($responseFormat) |
---|
458 | { |
---|
459 | case 'rest': |
---|
460 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php'); |
---|
461 | $encoder = new PwgRestEncoder(); |
---|
462 | break; |
---|
463 | case 'php': |
---|
464 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php'); |
---|
465 | $encoder = new PwgSerialPhpEncoder(); |
---|
466 | break; |
---|
467 | case 'json': |
---|
468 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php'); |
---|
469 | $encoder = new PwgJsonEncoder(); |
---|
470 | break; |
---|
471 | case 'xmlrpc': |
---|
472 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php'); |
---|
473 | $encoder = new PwgXmlRpcEncoder(); |
---|
474 | break; |
---|
475 | } |
---|
476 | $service->setEncoder($responseFormat, $encoder); |
---|
477 | } |
---|
478 | |
---|
479 | set_make_full_url(); |
---|
480 | $service->run(); |
---|
481 | |
---|
482 | ?> |
---|