source: branches/2.3/ws.php @ 27569

Last change on this file since 27569 was 13083, checked in by plg, 12 years ago

feature 2566 added: pwg.images.add can perform an update on an existing photo.
The additional parameter is image_id and it can be used only combined with
option resize=1.

  • Property svn:eol-style set to LF
File size: 19.5 KB
Line 
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
24define ('PHPWG_ROOT_PATH', './');
25
26include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
27check_status(ACCESS_FREE);
28include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');
29
30if ( !$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 */
38function 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.getInfos', 'ws_getInfos', null,
47      'retrieves general informations');
48
49  $service->addMethod('pwg.caddie.add', 'ws_caddie_add',
50      array(
51        'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ),
52      ),
53      'adds the elements to the caddie');
54
55  $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages',
56      array(
57        'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY),
58        'recursive'=>array('default'=>false),
59        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
60        'page' => array('default'=>0),
61        'order' => array('default'=>null),
62        'f_min_rate' => array( 'default'=> null ),
63        'f_max_rate' => array( 'default'=> null ),
64        'f_min_hit' => array( 'default'=> null ),
65        'f_max_hit' => array( 'default'=> null ),
66        'f_min_date_available' => array( 'default'=> null ),
67        'f_max_date_available' => array( 'default'=> null ),
68        'f_min_date_created' => array( 'default'=> null ),
69        'f_max_date_created' => array( 'default'=> null ),
70        'f_min_ratio' => array( 'default'=> null ),
71        'f_max_ratio' => array( 'default'=> null ),
72        'f_with_thumbnail' => array( 'default'=> false ),
73      ),
74      'Returns elements for the corresponding categories.
75<br><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array.
76<br><b>order</b> comma separated fields for sorting (file,id, rating_score,...)'
77    );
78
79  $service->addMethod('pwg.categories.getList', 'ws_categories_getList',
80      array(
81        'cat_id' => array('default'=>0),
82        'recursive' => array('default'=>false),
83        'public' => array('default'=>false),
84        'tree_output' => array('default'=>false),
85        'fullname' => array('default'=>false),
86      ),
87      'retrieves a list of categories (tree_output option only compatible with json/php output format' );
88
89  $service->addMethod('pwg.images.addComment', 'ws_images_addComment',
90      array(
91        'image_id' => array(),
92        'author' => array( 'default' => is_a_guest()? 'guest':$user['username']),
93        'content' => array(),
94        'key' => array(),
95      ),
96      'add a comment to an image' );
97
98  $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo',
99      array(
100        'image_id' => array(),
101        'comments_page' => array('default'=>0 ),
102        'comments_per_page' => array(
103              'default' => $conf['nb_comment_page'],
104              'maxValue' => 2*$conf['nb_comment_page'],
105            ),
106      ),
107      'retrieves information about the given photo' );
108
109  $service->addMethod('pwg.images.rate', 'ws_images_rate',
110      array(
111        'image_id' => array(),
112        'rate' =>     array(),
113      ),
114      'rate the image' );
115
116  $service->addMethod('pwg.images.search', 'ws_images_search',
117      array(
118        'query'=>array(),
119        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
120        'page' => array('default'=>0),
121        'order' => array('default'=>null),
122        'f_min_rate' => array( 'default'=> null ),
123        'f_max_rate' => array( 'default'=> null ),
124        'f_min_hit' => array( 'default'=> null ),
125        'f_max_hit' => array( 'default'=> null ),
126        'f_min_date_available' => array( 'default'=> null ),
127        'f_max_date_available' => array( 'default'=> null ),
128        'f_min_date_created' => array( 'default'=> null ),
129        'f_max_date_created' => array( 'default'=> null ),
130        'f_min_ratio' => array( 'default'=> null ),
131        'f_max_ratio' => array( 'default'=> null ),
132        'f_with_thumbnail' => array( 'default'=> false ),
133      ),
134      'Returns elements for the corresponding query search.'
135    );
136
137  $service->addMethod(
138    'pwg.images.setPrivacyLevel',
139    'ws_images_setPrivacyLevel',
140    array(
141      'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY),
142      'level' => array('maxValue'=>$conf['available_permission_levels']),
143      ),
144    'sets the privacy levels for the images (POST method only)'
145    );
146
147  $service->addMethod(
148    'pwg.images.setRank',
149    'ws_images_setRank',
150    array(
151      'image_id' => array(),
152      'category_id' => array(),
153      'rank' => array(),
154      ),
155    'sets the rank of a photo for a given album (POST method only, for admins)'
156    );
157
158
159  $service->addMethod('pwg.rates.delete', 'ws_rates_delete',
160    array(
161      'user_id' => array(),
162      'anonymous_id' => array( 'default'=>'' ),
163      ),
164    'deletes all rates for a user (POST method only, admins only)'
165    );
166   
167  $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' );
168  $service->addMethod('pwg.session.login', 'ws_session_login',
169    array('username', 'password'),
170    'POST method only' );
171  $service->addMethod('pwg.session.logout', 'ws_session_logout', null, '');
172
173  $service->addMethod('pwg.tags.getList', 'ws_tags_getList',
174    array('sort_by_counter' => array('default' =>false) ),
175    'retrieves a list of available tags');
176  $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages',
177      array(
178        'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
179        'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
180        'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
181        'tag_mode_and'=>array('default'=>false),
182        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
183        'page' => array('default'=>0),
184        'order' => array('default'=>null),
185        'f_min_rate' => array( 'default'=> null ),
186        'f_max_rate' => array( 'default'=> null ),
187        'f_min_hit' => array( 'default'=> null ),
188        'f_max_hit' => array( 'default'=> null ),
189        'f_min_date_available' => array( 'default'=> null ),
190        'f_max_date_available' => array( 'default'=> null ),
191        'f_min_date_created' => array( 'default'=> null ),
192        'f_max_date_created' => array( 'default'=> null ),
193        'f_min_ratio' => array( 'default'=> null ),
194        'f_max_ratio' => array( 'default'=> null ),
195        'f_with_thumbnail' => array( 'default'=> false ),
196      ),
197      'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
198    );
199
200  $service->addMethod(
201    'pwg.images.addChunk',
202    'ws_images_add_chunk',
203    array(
204      'data' => array(),
205      'original_sum' => array(),
206      'type' => array(),
207      'position' => array(),
208      ),
209    'POST method only. For admin only.'
210    );
211
212  $service->addMethod(
213    'pwg.images.addFile',
214    'ws_images_addFile',
215    array(
216      'image_id' => array(),
217      'type' => array(),
218      'sum' => array(),
219      ),
220    'Add or update a file for an existing photo. pwg.images.addChunk must have been called  before (maybe several times)'
221    );
222
223
224  $service->addMethod(
225    'pwg.images.add',
226    'ws_images_add',
227    array(
228      'file_sum' => array(),
229      'thumbnail_sum' => array('default' => null),
230      'high_sum' => array('default' => null),
231      'original_sum' => array(),
232      'original_filename' => array('default' => null),
233      'name' => array('default' => null),
234      'author' => array('default' => null),
235      'date_creation' => array('default' => null),
236      'comment' => array('default' => null),
237      'categories' => array('default' => null),
238      'tag_ids' => array('default' => null),
239      'level' => array(
240        'default' => 0,
241        'maxValue' => $conf['available_permission_levels']
242        ),
243      'resize' => array('default' => false),
244      'check_uniqueness' => array('default' => true),
245      'image_id' => array('default' => null),
246      ),
247    'POST method only.
248<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.'
249    );
250
251  $service->addMethod(
252    'pwg.images.addSimple',
253    'ws_images_addSimple',
254    array(
255      'category' => array('default' => null),
256      'name' => array('default' => null),
257      'author' => array('default' => null),
258      'comment' => array('default' => null),
259      'level' => array(
260        'default' => 0,
261        'maxValue' => $conf['available_permission_levels']
262        ),
263      'tags' => array('default' => null),
264      'image_id' => array('default' => null),
265      ),
266    '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.'
267    );
268
269  $service->addMethod(
270    'pwg.images.delete',
271    'ws_images_delete',
272    array(
273      'image_id'=>array('default'=>0),
274      'pwg_token' => array(),
275      ),
276    'Delete photos. You can give several image_ids, comma separated'
277    );
278
279  $service->addMethod(
280    'pwg.categories.getAdminList',
281    'ws_categories_getAdminList',
282    array(),
283    'administration method only'
284    );
285
286  $service->addMethod(
287    'pwg.categories.add',
288    'ws_categories_add',
289    array(
290      'name' => array(),
291      'parent' => array('default' => null),
292      ),
293    'administration method only'
294    );
295
296  $service->addMethod(
297    'pwg.categories.delete',
298    'ws_categories_delete',
299    array(
300      'category_id'=>array('default'=>0),
301      'pwg_token' => array(),
302      'photo_deletion_mode' => array('default' => 'delete_orphans'),
303      ),
304    'Delete categories. You can give several category_ids, comma separated.
305<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)'
306    );
307
308  $service->addMethod(
309    'pwg.categories.move',
310    'ws_categories_move',
311    array(
312      'category_id'=>array('default'=>0),
313      'parent'=>array('default'=>0),
314      'pwg_token' => array(),
315      ),
316    '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.'
317    );
318
319  $service->addMethod(
320    'pwg.categories.setRepresentative',
321    'ws_categories_setRepresentative',
322    array(
323      'category_id'=>array('default'=>0),
324      'image_id'=>array('default'=>0),
325      ),
326    'Set the representative photo for an album. The photo doesn\'t have to belong to the album. POST method only. Administration method only.'
327    );
328
329  $service->addMethod(
330    'pwg.tags.getAdminList',
331    'ws_tags_getAdminList',
332    array(),
333    'administration method only'
334    );
335
336  $service->addMethod(
337    'pwg.tags.add',
338    'ws_tags_add',
339    array(
340      'name' => array(),
341      ),
342    'administration method only'
343    );
344
345  $service->addMethod(
346    'pwg.images.exist',
347    'ws_images_exist',
348    array(
349      'md5sum_list'=> array('default' => null),
350      'filename_list' => array('default' => null),
351      ),
352    'check existence of a photo list'
353    );
354
355  $service->addMethod(
356    'pwg.images.checkFiles',
357    'ws_images_checkFiles',
358    array(
359      'image_id' => array(),
360      'thumbnail_sum' => array('default' => null),
361      'file_sum' => array('default' => null),
362      'high_sum' => array('default' => null),
363      ),
364    '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"'
365    );
366
367  $service->addMethod(
368    'pwg.images.checkUpload',
369    'ws_images_checkUpload',
370    null,
371    'check if Piwigo is ready for upload'
372    );
373
374  $service->addMethod(
375    'pwg.images.setInfo',
376    'ws_images_setInfo',
377    array(
378      'image_id' => array(),
379
380      'file' => array('default' => null),
381      'name' => array('default' => null),
382      'author' => array('default' => null),
383      'date_creation' => array('default' => null),
384      'comment' => array('default' => null),
385      'categories' => array('default' => null),
386      'tag_ids' => array('default' => null),
387      'level' => array(
388        'default' => null,
389        'maxValue' => $conf['available_permission_levels']
390        ),
391      'single_value_mode' => array('default' => 'fill_if_empty'),
392      'multiple_value_mode' => array('default' => 'append'),
393      ),
394    'POST method only. Admin only
395<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.
396<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
397<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'
398    );
399
400  $service->addMethod(
401    'pwg.categories.setInfo',
402    'ws_categories_setInfo',
403    array(
404      'category_id' => array(),
405
406      'name' => array('default' => null),
407      'comment' => array('default' => null),
408      ),
409    'POST method only.'
410    );
411 
412  $service->addMethod(
413    'pwg.plugins.getList',
414    'ws_plugins_getList',
415    array(),
416    'get the list of plugin with id, name, version, state and description
417<br>administration status required'
418    );
419
420  $service->addMethod(
421    'pwg.plugins.performAction',
422    'ws_plugins_performAction',
423    array(
424      'action' => array(),
425      'plugin' => array(),
426      'pwg_token' => array(),
427      ),
428    'install/activate/deactivate/uninstall/delete a plugin
429<br>administration status required'
430    );
431
432  $service->addMethod(
433    'pwg.themes.performAction',
434    'ws_themes_performAction',
435    array(
436      'action' => array(),
437      'theme' => array(),
438      'pwg_token' => array(),
439      ),
440    'activate/deactivate/delete/set_default a theme<br>administration status required'
441    );
442
443  $service->addMethod(
444    'pwg.images.resizeThumbnail',
445    'ws_images_resizethumbnail',
446    array(
447      'image_id' => array('default' => null),
448      'image_path' => array('default' => null),
449      'maxwidth' => array('default' => $conf['upload_form_thumb_maxwidth']),
450      'maxheight' => array('default' => $conf['upload_form_thumb_maxheight']),
451      'quality' => array('default' => $conf['upload_form_thumb_quality']),
452      'crop' => array('default' => $conf['upload_form_thumb_crop']),
453      'follow_orientation' => array('default' => $conf['upload_form_thumb_follow_orientation']),
454      'library' => array('default' => $conf['graphics_library']),
455    ),
456    'Create/Regenerate thumbnails photo with given arguments.
457<br>One of arguments "image_id" or "image_path" must be sent.'
458  );
459
460  $service->addMethod(
461    'pwg.images.resizeWebsize',
462    'ws_images_resizewebsize',
463    array(
464      'image_id' => array(),
465      'maxwidth' => array('default' => $conf['upload_form_websize_maxwidth']),
466      'maxheight' => array('default' => $conf['upload_form_websize_maxheight']),
467      'quality' => array('default' => $conf['upload_form_websize_quality']),
468      'automatic_rotation' => array('default' => $conf['upload_form_automatic_rotation']),
469      'library' => array('default' => $conf['graphics_library']),
470    ),
471    'Regenerate websize photo with given arguments.'
472  );
473
474  $service->addMethod(
475    'pwg.extensions.update',
476    'ws_extensions_update',
477    array(
478      'type' => array(),
479      'id' => array(),
480      'revision'=> array(),
481      'pwg_token' => array(),
482    ),
483    'Update an extension. Webmaster only.
484<br>Parameter type must be "plugins", "languages" or "themes".'
485  );
486
487  $service->addMethod(
488    'pwg.extensions.ignoreUpdate',
489    'ws_extensions_ignoreupdate',
490    array(
491      'type' => array('default'=>null),
492      'id' => array('default'=>null),
493      'reset' => array('default'=>null),
494      'pwg_token' => array(),
495    ),
496    'Ignore an extension if it need update.
497<br>Parameter type must be "plugins", "languages" or "themes".
498<br>If reset parameter is true, all ignored extensions will be reinitilized.'
499  );
500
501  $service->addMethod(
502    'pwg.extensions.checkUpdates',
503    'ws_extensions_checkupdates',
504    array(),
505    'Check if piwigo or extensions are up to date.'
506  );
507}
508
509add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
510
511
512add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
513
514$requestFormat = 'rest';
515$responseFormat = null;
516
517if ( isset($_GET['format']) )
518{
519  $responseFormat = $_GET['format'];
520}
521
522if ( !isset($responseFormat) and isset($requestFormat) )
523{
524  $responseFormat = $requestFormat;
525}
526
527$service = new PwgServer();
528
529if (!is_null($requestFormat))
530{
531  $handler = null;
532  switch ($requestFormat)
533  {
534    case 'rest':
535      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
536      $handler = new PwgRestRequestHandler();
537      break;
538  }
539  $service->setHandler($requestFormat, $handler);
540}
541
542if (!is_null($responseFormat))
543{
544  $encoder = null;
545  switch ($responseFormat)
546  {
547    case 'rest':
548      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
549      $encoder = new PwgRestEncoder();
550      break;
551    case 'php':
552      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
553      $encoder = new PwgSerialPhpEncoder();
554      break;
555    case 'json':
556      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
557      $encoder = new PwgJsonEncoder();
558      break;
559    case 'xmlrpc':
560      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
561      $encoder = new PwgXmlRpcEncoder();
562      break;
563  }
564  $service->setEncoder($responseFormat, $encoder);
565}
566
567set_make_full_url();
568$service->run();
569
570?>
Note: See TracBrowser for help on using the repository browser.