source: trunk/ws.php @ 20815

Last change on this file since 20815 was 20815, checked in by mistic100, 11 years ago

completely rewrite the indentation of ws.php, no technical changes

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