source: trunk/ws.php @ 12860

Last change on this file since 12860 was 12730, checked in by plg, 12 years ago

merge r12729 from branch 2.3 to trunk

feature 2489 added: ability to update "file" info in pwg.images.setInfo

  • Property svn:eol-style set to LF
File size: 19.4 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      ),
246    'POST method only.
247<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.'
248    );
249
250  $service->addMethod(
251    'pwg.images.addSimple',
252    'ws_images_addSimple',
253    array(
254      'category' => array('default' => null),
255      'name' => array('default' => null),
256      'author' => array('default' => null),
257      'comment' => array('default' => null),
258      'level' => array(
259        'default' => 0,
260        'maxValue' => $conf['available_permission_levels']
261        ),
262      'tags' => array('default' => null),
263      'image_id' => array('default' => null),
264      ),
265    '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.'
266    );
267
268  $service->addMethod(
269    'pwg.images.delete',
270    'ws_images_delete',
271    array(
272      'image_id'=>array('default'=>0),
273      'pwg_token' => array(),
274      ),
275    'Delete photos. You can give several image_ids, comma separated'
276    );
277
278  $service->addMethod(
279    'pwg.categories.getAdminList',
280    'ws_categories_getAdminList',
281    array(),
282    'administration method only'
283    );
284
285  $service->addMethod(
286    'pwg.categories.add',
287    'ws_categories_add',
288    array(
289      'name' => array(),
290      'parent' => array('default' => null),
291      ),
292    'administration method only'
293    );
294
295  $service->addMethod(
296    'pwg.categories.delete',
297    'ws_categories_delete',
298    array(
299      'category_id'=>array('default'=>0),
300      'pwg_token' => array(),
301      'photo_deletion_mode' => array('default' => 'delete_orphans'),
302      ),
303    'Delete categories. You can give several category_ids, comma separated.
304<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)'
305    );
306
307  $service->addMethod(
308    'pwg.categories.move',
309    'ws_categories_move',
310    array(
311      'category_id'=>array('default'=>0),
312      'parent'=>array('default'=>0),
313      'pwg_token' => array(),
314      ),
315    '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.'
316    );
317
318  $service->addMethod(
319    'pwg.categories.setRepresentative',
320    'ws_categories_setRepresentative',
321    array(
322      'category_id'=>array('default'=>0),
323      'image_id'=>array('default'=>0),
324      ),
325    'Set the representative photo for an album. The photo doesn\'t have to belong to the album. POST method only. Administration method only.'
326    );
327
328  $service->addMethod(
329    'pwg.tags.getAdminList',
330    'ws_tags_getAdminList',
331    array(),
332    'administration method only'
333    );
334
335  $service->addMethod(
336    'pwg.tags.add',
337    'ws_tags_add',
338    array(
339      'name' => array(),
340      ),
341    'administration method only'
342    );
343
344  $service->addMethod(
345    'pwg.images.exist',
346    'ws_images_exist',
347    array(
348      'md5sum_list'=> array('default' => null),
349      'filename_list' => array('default' => null),
350      ),
351    'check existence of a photo list'
352    );
353
354  $service->addMethod(
355    'pwg.images.checkFiles',
356    'ws_images_checkFiles',
357    array(
358      'image_id' => array(),
359      'thumbnail_sum' => array('default' => null),
360      'file_sum' => array('default' => null),
361      'high_sum' => array('default' => null),
362      ),
363    '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"'
364    );
365
366  $service->addMethod(
367    'pwg.images.checkUpload',
368    'ws_images_checkUpload',
369    null,
370    'check if Piwigo is ready for upload'
371    );
372
373  $service->addMethod(
374    'pwg.images.setInfo',
375    'ws_images_setInfo',
376    array(
377      'image_id' => array(),
378
379      'file' => array('default' => null),
380      'name' => array('default' => null),
381      'author' => array('default' => null),
382      'date_creation' => array('default' => null),
383      'comment' => array('default' => null),
384      'categories' => array('default' => null),
385      'tag_ids' => array('default' => null),
386      'level' => array(
387        'default' => null,
388        'maxValue' => $conf['available_permission_levels']
389        ),
390      'single_value_mode' => array('default' => 'fill_if_empty'),
391      'multiple_value_mode' => array('default' => 'append'),
392      ),
393    'POST method only. Admin only
394<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.
395<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
396<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'
397    );
398
399  $service->addMethod(
400    'pwg.categories.setInfo',
401    'ws_categories_setInfo',
402    array(
403      'category_id' => array(),
404
405      'name' => array('default' => null),
406      'comment' => array('default' => null),
407      ),
408    'POST method only.'
409    );
410 
411  $service->addMethod(
412    'pwg.plugins.getList',
413    'ws_plugins_getList',
414    array(),
415    'get the list of plugin with id, name, version, state and description
416<br>administration status required'
417    );
418
419  $service->addMethod(
420    'pwg.plugins.performAction',
421    'ws_plugins_performAction',
422    array(
423      'action' => array(),
424      'plugin' => array(),
425      'pwg_token' => array(),
426      ),
427    'install/activate/deactivate/uninstall/delete a plugin
428<br>administration status required'
429    );
430
431  $service->addMethod(
432    'pwg.themes.performAction',
433    'ws_themes_performAction',
434    array(
435      'action' => array(),
436      'theme' => array(),
437      'pwg_token' => array(),
438      ),
439    'activate/deactivate/delete/set_default a theme<br>administration status required'
440    );
441
442  $service->addMethod(
443    'pwg.images.resizeThumbnail',
444    'ws_images_resizethumbnail',
445    array(
446      'image_id' => array('default' => null),
447      'image_path' => array('default' => null),
448      'maxwidth' => array('default' => $conf['upload_form_thumb_maxwidth']),
449      'maxheight' => array('default' => $conf['upload_form_thumb_maxheight']),
450      'quality' => array('default' => $conf['upload_form_thumb_quality']),
451      'crop' => array('default' => $conf['upload_form_thumb_crop']),
452      'follow_orientation' => array('default' => $conf['upload_form_thumb_follow_orientation']),
453      'library' => array('default' => $conf['graphics_library']),
454    ),
455    'Create/Regenerate thumbnails photo with given arguments.
456<br>One of arguments "image_id" or "image_path" must be sent.'
457  );
458
459  $service->addMethod(
460    'pwg.images.resizeWebsize',
461    'ws_images_resizewebsize',
462    array(
463      'image_id' => array(),
464      'maxwidth' => array('default' => $conf['upload_form_websize_maxwidth']),
465      'maxheight' => array('default' => $conf['upload_form_websize_maxheight']),
466      'quality' => array('default' => $conf['upload_form_websize_quality']),
467      'automatic_rotation' => array('default' => $conf['upload_form_automatic_rotation']),
468      'library' => array('default' => $conf['graphics_library']),
469    ),
470    'Regenerate websize photo with given arguments.'
471  );
472
473  $service->addMethod(
474    'pwg.extensions.update',
475    'ws_extensions_update',
476    array(
477      'type' => array(),
478      'id' => array(),
479      'revision'=> array(),
480      'pwg_token' => array(),
481    ),
482    'Update an extension. Webmaster only.
483<br>Parameter type must be "plugins", "languages" or "themes".'
484  );
485
486  $service->addMethod(
487    'pwg.extensions.ignoreUpdate',
488    'ws_extensions_ignoreupdate',
489    array(
490      'type' => array('default'=>null),
491      'id' => array('default'=>null),
492      'reset' => array('default'=>null),
493      'pwg_token' => array(),
494    ),
495    'Ignore an extension if it need update.
496<br>Parameter type must be "plugins", "languages" or "themes".
497<br>If reset parameter is true, all ignored extensions will be reinitilized.'
498  );
499
500  $service->addMethod(
501    'pwg.extensions.checkUpdates',
502    'ws_extensions_checkupdates',
503    array(),
504    'Check if piwigo or extensions are up to date.'
505  );
506}
507
508add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
509
510
511add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
512
513$requestFormat = 'rest';
514$responseFormat = null;
515
516if ( isset($_GET['format']) )
517{
518  $responseFormat = $_GET['format'];
519}
520
521if ( !isset($responseFormat) and isset($requestFormat) )
522{
523  $responseFormat = $requestFormat;
524}
525
526$service = new PwgServer();
527
528if (!is_null($requestFormat))
529{
530  $handler = null;
531  switch ($requestFormat)
532  {
533    case 'rest':
534      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
535      $handler = new PwgRestRequestHandler();
536      break;
537  }
538  $service->setHandler($requestFormat, $handler);
539}
540
541if (!is_null($responseFormat))
542{
543  $encoder = null;
544  switch ($responseFormat)
545  {
546    case 'rest':
547      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
548      $encoder = new PwgRestEncoder();
549      break;
550    case 'php':
551      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
552      $encoder = new PwgSerialPhpEncoder();
553      break;
554    case 'json':
555      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
556      $encoder = new PwgJsonEncoder();
557      break;
558    case 'xmlrpc':
559      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
560      $encoder = new PwgXmlRpcEncoder();
561      break;
562  }
563  $service->setEncoder($responseFormat, $encoder);
564}
565
566set_make_full_url();
567$service->run();
568
569?>
Note: See TracBrowser for help on using the repository browser.