source: trunk/ws.php @ 21566

Last change on this file since 21566 was 20817, 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: 20.0 KB
RevLine 
[1698]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[19703]5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[1698]23
24define ('PHPWG_ROOT_PATH', './');
25
26include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
[2325]27check_status(ACCESS_FREE);
[1698]28include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');
29
[1781]30if ( !$conf['allow_web_services'] )
31{
32  page_forbidden('Web services are disabled');
33}
34
[20815]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
[1768]96/**
97 * event handler that registers standard methods with the web service
98 */
[1698]99function ws_addDefaultMethods( $arr )
100{
[1849]101  global $conf, $user;
[1698]102  $service = &$arr[0];
[20815]103 
104  include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
105 
[20817]106  $service->addMethod(
107      'pwg.getVersion',
108      'ws_getVersion',
[20815]109      null,
110      'retrieves the PWG version'
111    );
[10017]112         
[20817]113  $service->addMethod(
114      'pwg.getInfos',
115      'ws_getInfos',
[20815]116      null,
117      'retrieves general informations'
118    );
[1698]119
[20817]120  $service->addMethod(
121      'pwg.caddie.add',
122      'ws_caddie_add',
[2429]123      array(
[20815]124        'image_id'=> array('flags'=>WS_PARAM_FORCE_ARRAY),
125        ),
126      'adds the elements to the caddie'
127    );
[2429]128
[20817]129  $service->addMethod(
130      'pwg.categories.getImages',
131      'ws_categories_getImages',
[1698]132      array(
[20815]133        'cat_id' =>     array('default'=>0, 
134                              'flags'=>WS_PARAM_FORCE_ARRAY),
135        'recursive' =>  array('default'=>false ),
136        'per_page' =>   array('default'=>100, 
137                              'maxValue'=>$conf['ws_max_images_per_page']),
138        'page' =>       array('default'=>0),
139        'order' =>      array('default'=>null),
140        'f_min_rate' => array('default'=>null),
141        'f_max_rate' => array('default'=>null),
142        'f_min_hit' =>  array('default'=>null),
143        'f_max_hit' =>  array('default'=>null),
144        'f_min_date_available' => array('default'=>null),
145        'f_max_date_available' => array('default'=>null),
146        'f_min_date_created' =>   array('default'=>null),
147        'f_max_date_created' =>   array('default'=>null),
148        'f_min_ratio' => array('default'=>null),
149        'f_max_ratio' => array('default'=>null),
150        'f_max_level' => array('default'=>null),
151        ),
[1698]152      'Returns elements for the corresponding categories.
[3185]153<br><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array.
[11893]154<br><b>order</b> comma separated fields for sorting (file,id, rating_score,...)'
[1698]155    );
156
[20817]157  $service->addMethod(
158      'pwg.categories.getList',
159      'ws_categories_getList',
[1698]160      array(
[20815]161        'cat_id' =>       array('default'=>0),
162        'recursive' =>    array('default'=>false),
163        'public' =>       array('default'=>false),
164        'tree_output' =>  array('default'=>false),
165        'fullname' =>     array('default'=>false),
166        ),
167      'retrieves a list of categories (tree_output option only compatible with json/php output format'
168    );
[1698]169
[20817]170  $service->addMethod(
171      'pwg.getMissingDerivatives',
172      'ws_getMissingDerivatives',
[12865]173      array(
[20815]174        'types' =>      array('default'=>array(),
175                              'flags'=>WS_PARAM_FORCE_ARRAY),
176        'ids' =>        array('default'=>array(),
177                              'flags'=>WS_PARAM_FORCE_ARRAY),
178        'max_urls' =>   array('default'=>200),
179        'prev_page' =>  array('default'=>null),
180        'f_min_rate' => array('default'=>null),
181        'f_max_rate' => array('default'=>null),
182        'f_min_hit' =>  array('default'=>null),
183        'f_max_hit' =>  array('default'=>null),
184        'f_min_date_available' => array('default'=>null),
185        'f_max_date_available' => array('default'=>null),
186        'f_min_date_created' =>   array('default'=>null),
187        'f_max_date_created' =>   array('default'=>null),
188        'f_min_ratio' => array('default'=>null),
189        'f_max_ratio' => array('default'=>null),
190        'f_max_level' => array('default'=>null),
191        ),
192      'retrieves a list of derivatives to build'
193    );
[12865]194
[20817]195  $service->addMethod(
196      'pwg.images.addComment',
197      'ws_images_addComment',
[1849]198      array(
199        'image_id' => array(),
[20815]200        'author' =>   array('default'=>is_a_guest()?'guest':$user['username']),
201        'content' =>  array(),
202        'key' =>      array(),
203        ),
204      'add a comment to an image'
205    );
[1849]206
[20817]207  $service->addMethod(
208      'pwg.images.getInfo',
209      'ws_images_getInfo',
[1849]210      array(
[20815]211        'image_id' =>           array(),
212        'comments_page' =>      array('default'=>0 ),
213        'comments_per_page' =>  array('default' =>  $conf['nb_comment_page'],
214                                      'maxValue' => 2*$conf['nb_comment_page']),
215        ),
216      'retrieves information about the given photo'
217    );
[1698]218
[20817]219  $service->addMethod(
220      'pwg.images.rate',
221      'ws_images_rate',
[20815]222      array('image_id', 'rate'),
223      'rate the image'
224    );
[2435]225
[20817]226  $service->addMethod(
227      'pwg.images.search',
228      'ws_images_search',
[1837]229      array(
[20815]230        'query' =>      array(),
231        'per_page' =>   array('default'=>100, 
232                              'maxValue'=>$conf['ws_max_images_per_page']),
233        'page' =>       array('default'=>0),
234        'order' =>      array('default'=>null),
235        'f_min_rate' => array('default'=>null),
236        'f_max_rate' => array('default'=>null),
237        'f_min_hit' =>  array('default'=>null),
238        'f_max_hit' =>  array('default'=>null),
239        'f_min_date_available' => array('default'=>null),
240        'f_max_date_available' => array('default'=>null),
241        'f_min_date_created' =>   array('default'=>null),
242        'f_max_date_created' =>   array('default'=>null),
243        'f_min_ratio' => array('default'=>null),
244        'f_max_ratio' => array('default'=>null),
245        'f_max_level' => array('default'=>null),
246        ),
[1837]247      'Returns elements for the corresponding query search.'
248    );
[2516]249
[20817]250  $service->addMethod(
251      'pwg.images.setPrivacyLevel',
252      'ws_images_setPrivacyLevel',
[20815]253      array(
254        'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY),
255        'level' =>    array('maxValue'=>$conf['available_permission_levels']),
256        ),
257      'sets the privacy levels for the images (POST method only)'
[2463]258    );
[1837]259
[20817]260  $service->addMethod(
261      'pwg.images.setRank',
262      'ws_images_setRank',
[20815]263      array('image_id', 'category_id', 'rank'),
264      'sets the rank of a photo for a given album (POST method only, for admins)'
[11372]265    );
[12624]266
[20817]267  $service->addMethod(
268      'pwg.rates.delete',
269      'ws_rates_delete',
[20815]270      array(
271        'user_id' =>      array(),
272        'anonymous_id' => array('default'=>null),
273        ),
274      'deletes all rates for a user (POST method only, admins only)'
[12624]275    );
[20815]276
[20817]277  $service->addMethod(
278      'pwg.session.getStatus',
279      'ws_session_getStatus',
280      null,
281      null
282    );
[20815]283
[20817]284  $service->addMethod(
285      'pwg.session.login',
286      'ws_session_login',
[20815]287      array('username', 'password'),
288      'POST method only'
289    );
290
[20817]291  $service->addMethod(
292      'pwg.session.logout',
293      'ws_session_logout',
294      null,
295      null
296    );
[1698]297
[20817]298  $service->addMethod(
299      'pwg.tags.getList',
300      'ws_tags_getList',
[20815]301      array(
302        'sort_by_counter' => array('default' =>false),
303        ),
304      'retrieves a list of available tags'
305    );
306
[20817]307  $service->addMethod(
308      'pwg.tags.getImages',
309      'ws_tags_getImages',
[1698]310      array(
[20815]311        'tag_id' =>       array('default'=>null,
312                                'flags'=>WS_PARAM_FORCE_ARRAY),
313        'tag_url_name' => array('default'=>null,
314                                'flags'=>WS_PARAM_FORCE_ARRAY),
315        'tag_name' =>     array('default'=>null,
316                                'flags'=>WS_PARAM_FORCE_ARRAY),
317        'tag_mode_and' => array('default'=>false),
318        'per_page' =>     array('default'=>100,
319                                'maxValue'=>$conf['ws_max_images_per_page']),
320        'page' =>         array('default'=>0),
321        'order' =>        array('default'=>null),
322        'f_min_rate' =>   array('default'=>null),
323        'f_max_rate' =>   array('default'=>null),
324        'f_min_hit' =>    array('default'=>null),
325        'f_max_hit' =>    array('default'=>null),
326        'f_min_date_available' => array('default'=>null),
327        'f_max_date_available' => array('default'=>null),
328        'f_min_date_created' =>   array('default'=>null),
329        'f_max_date_created' =>   array('default'=>null),
330        'f_min_ratio' => array('default'=>null),
331        'f_max_ratio' => array('default'=>null),
332        'f_max_level' => array('default'=>null),
333        ),
[1698]334      'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
335    );
[2463]336
[20817]337  $service->addMethod(
338      'pwg.images.addChunk',
339      'ws_images_add_chunk',
[20815]340      array('data', 'original_sum', 'type', 'position'),
341      'POST method only. For admin only.'
[3193]342    );
343
[20817]344  $service->addMethod(
345      'pwg.images.addFile',
346      'ws_images_addFile',
[20815]347      array('image_id', 'type', 'sum'),
348      'Add or update a file for an existing photo. pwg.images.addChunk must have been called  before (maybe several times)'
[4348]349    );
350
351
[20817]352  $service->addMethod(
353      'pwg.images.add',
354      'ws_images_add',
[20815]355      array(
356        'file_sum' =>           array(),
357        'thumbnail_sum' =>      array('default'=>null),
358        'high_sum' =>           array('default'=>null),
359        'original_sum' =>       array(),
360        'original_filename' =>  array('default'=>null),
361        'name' =>               array('default'=>null),
362        'author' =>             array('default'=>null),
363        'date_creation' =>      array('default'=>null),
364        'comment' =>            array('default'=>null),
365        'categories' =>         array('default'=>null),
366        'tag_ids' =>            array('default'=>null),
367        'level' =>              array('default'=>0,
368                                      'maxValue'=>$conf['available_permission_levels']),
369        'check_uniqueness' =>   array('default'=>true),
370        'image_id' =>           array('default'=>null),
[2569]371        ),
[20815]372      'POST method only.
373<br><b>categories</b> is a string list "category_id[,rank];category_id[,rank]"
374The rank is optional and is equivalent to "auto" if not given.'
[2463]375    );
[2563]376
[20817]377  $service->addMethod(
378      'pwg.images.addSimple',
379      'ws_images_addSimple',
[20815]380      array(
381        'category' => array('default'=>null),
382        'name' =>     array('default'=>null),
383        'author' =>   array('default'=>null),
384        'comment' =>  array('default'=>null),
385        'level' =>    array('default'=>0,
386                            'maxValue'=>$conf['available_permission_levels']),
387        'tags' =>     array('default'=>null,
388                            'flags'=>WS_PARAM_ACCEPT_ARRAY),
389        'image_id' => array('default'=>null),
[8249]390        ),
[20815]391      'POST method only.<br>Use the <b>image</b> field for uploading file.
392<br>Set the form encoding to "form-data"<br><b>category</b> is the numeric identifier of the destination category.
393<br>You can update an existing photo if you define an existing image_id.'
[8249]394    );
[8266]395
[20817]396  $service->addMethod(
397      'pwg.images.delete',
398      'ws_images_delete',
[20815]399      array(
400        'image_id' =>   array('default'=>0),
401        'pwg_token' =>  array(),
402        ),
403      'Delete photos. You can give several image_ids, comma separated'
[8266]404    );
405
[20817]406  $service->addMethod(
407      'pwg.categories.getAdminList',
408      'ws_categories_getAdminList',
[20815]409      null,
410      'administration method only'
[2563]411    );
[2583]412
[20817]413  $service->addMethod(
414      'pwg.categories.add',
415      'ws_categories_add',
[20815]416      array(
417        'name' =>         array(),
418        'parent' =>       array('default'=>null),
419        'comment' =>      array('default'=>null),
420        'visible' =>      array('default'=>null),
421        'status' =>       array('default'=>null),
422        'commentable' =>  array('default'=>'true'),
423        ),
424      'administration method only'
[2583]425    );
[2584]426
[20817]427  $service->addMethod(
428      'pwg.categories.delete',
429      'ws_categories_delete',
[20815]430      array(
431        'category_id'=>           array('default'=>0),
432        'pwg_token' =>            array(),
433        'photo_deletion_mode' =>  array('default'=>'delete_orphans'),
434        ),
435      'Delete categories. You can give several category_ids, comma separated.
436<br><b>photo_deletion_mode</b> can be "no_delete" (may create orphan photos), "delete_orphans"
437(default mode, only deletes photos linked to no other album) or "force_delete" (delete all photos, even those linked to other albums)'
[8266]438    );
439
[20817]440  $service->addMethod(
441      'pwg.categories.move',
442      'ws_categories_move',
[20815]443      array(
444        'category_id' =>  array('default'=>0),
445        'parent' =>       array('default'=>0),
446        'pwg_token' =>    array(),
447        ),
448      '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.'
[8272]449    );
[11746]450
[20817]451  $service->addMethod(
452      'pwg.categories.setRepresentative',
453      'ws_categories_setRepresentative',
[20815]454      array(
455        'category_id' =>  array('default'=>0),
456        'image_id' =>     array('default'=>0),
457        ),
458      'Set the representative photo for an album. The photo doesn\'t have to belong to the album. POST method only. Administration method only.'
[11746]459    );
460
[20817]461  $service->addMethod(
462      'pwg.tags.getAdminList',
463      'ws_tags_getAdminList',
[20815]464      null,
465      'administration method only'
[2584]466    );
[2634]467
[20817]468  $service->addMethod(
469      'pwg.tags.add',
470      'ws_tags_add',
[20815]471      array('name'),
472      'administration method only'
[2634]473    );
[2683]474
[20817]475  $service->addMethod(
476      'pwg.images.exist',
477      'ws_images_exist',
[20815]478      array(
479        'md5sum_list' =>    array('default'=>null),
480        'filename_list' =>  array('default'=>null),
481        ),
482      'check existence of a photo list'
[2683]483    );
[2919]484
[20817]485  $service->addMethod(
486      'pwg.images.checkFiles',
487      'ws_images_checkFiles',
[20815]488      array(
489        'image_id' =>       array(),
490        'thumbnail_sum' =>  array('default'=>null),
491        'file_sum' =>       array('default'=>null),
492        'high_sum' =>       array('default'=>null),
493        ),
494      '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"'
[4347]495    );
496
[20817]497  $service->addMethod(
498      'pwg.images.checkUpload',
499      'ws_images_checkUpload',
[20815]500      null,
501      'check if Piwigo is ready for upload'
[6049]502    );
503
[20817]504  $service->addMethod(
505      'pwg.images.setInfo',
506      'ws_images_setInfo',
[20815]507      array(
508        'image_id' =>       array(),
509        'file' =>           array('default'=>null),
510        'name' =>           array('default'=>null),
511        'author' =>         array('default'=>null),
512        'date_creation' =>  array('default'=>null),
513        'comment' =>        array('default'=>null),
514        'categories' =>     array('default'=>null),
515        'tag_ids' =>        array('default'=>null),
516        'level' =>          array('default'=>null,
517                                  'maxValue'=>$conf['available_permission_levels']),
518        'single_value_mode' =>    array('default'=>'fill_if_empty'),
519        'multiple_value_mode' =>  array('default'=>'append'),
[2919]520        ),
[20815]521      'POST method only. Admin only
[4460]522<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.
[20815]523<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"
524(overwrite any existing value) and applies to single values properties like name/author/date_creation/comment
[4460]525<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'
[2919]526    );
[4513]527
[20817]528  $service->addMethod(
529      'pwg.categories.setInfo',
530      'ws_categories_setInfo',
[20815]531      array(
532        'category_id' =>  array(),
533        'name' =>         array('default'=>null),
534        'comment' =>      array('default'=>null),
535        ),
536      'POST method only.'
[3454]537    );
[8273]538 
[20817]539  $service->addMethod(
540      'pwg.plugins.getList',
541      'ws_plugins_getList',
[20815]542      null,
543      'Admin only
544<br>get the list of plugin with id, name, version, state and description'
[8273]545    );
546
[20817]547  $service->addMethod(
548      'pwg.plugins.performAction',
549      'ws_plugins_performAction',
[20815]550      array('action', 'plugin', 'pwg_token'),
551      'Admin only
552<br>install/activate/deactivate/uninstall/delete a plugin'
[8273]553    );
[8309]554
[20817]555  $service->addMethod(
556      'pwg.themes.performAction',
557      'ws_themes_performAction',
[20815]558      array('action', 'theme', 'pwg_token'),
559      'activate/deactivate/delete/set_default a theme<br>administration status required'
[8309]560    );
[10235]561
[20817]562  $service->addMethod(
563      'pwg.extensions.update',
564      'ws_extensions_update',
[20815]565      array('type', 'id', 'revision', 'pwg_token'),
566      'Update an extension. Webmaster only.
[10511]567<br>Parameter type must be "plugins", "languages" or "themes".'
568  );
569
[20817]570  $service->addMethod(
571      'pwg.extensions.ignoreUpdate',
572      'ws_extensions_ignoreupdate',
[20815]573      array(
574        'type' =>       array('default'=>null),
575        'id' =>         array('default'=>null),
576        'reset' =>      array('default'=>null),
577        'pwg_token' =>  array(),
578      ),
579      'Ignore an extension if it need update.
[10511]580<br>Parameter type must be "plugins", "languages" or "themes".
581<br>If reset parameter is true, all ignored extensions will be reinitilized.'
582  );
[10538]583
[20817]584  $service->addMethod(
585      'pwg.extensions.checkUpdates',
586      'ws_extensions_checkupdates',
[20815]587      null,
588      'Check if piwigo or extensions are up to date.'
[10538]589  );
[1698]590}
591
592?>
Note: See TracBrowser for help on using the repository browser.