source: trunk/ws.php @ 22633

Last change on this file since 22633 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
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(
107      'pwg.getVersion',
108      'ws_getVersion',
109      null,
110      'retrieves the PWG version'
111    );
112         
113  $service->addMethod(
114      'pwg.getInfos',
115      'ws_getInfos',
116      null,
117      'retrieves general informations'
118    );
119
120  $service->addMethod(
121      'pwg.caddie.add',
122      'ws_caddie_add',
123      array(
124        'image_id'=> array('flags'=>WS_PARAM_FORCE_ARRAY),
125        ),
126      'adds the elements to the caddie'
127    );
128
129  $service->addMethod(
130      'pwg.categories.getImages',
131      'ws_categories_getImages',
132      array(
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        ),
152      'Returns elements for the corresponding categories.
153<br><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array.
154<br><b>order</b> comma separated fields for sorting (file,id, rating_score,...)'
155    );
156
157  $service->addMethod(
158      'pwg.categories.getList',
159      'ws_categories_getList',
160      array(
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    );
169
170  $service->addMethod(
171      'pwg.getMissingDerivatives',
172      'ws_getMissingDerivatives',
173      array(
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    );
194
195  $service->addMethod(
196      'pwg.images.addComment',
197      'ws_images_addComment',
198      array(
199        'image_id' => array(),
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    );
206
207  $service->addMethod(
208      'pwg.images.getInfo',
209      'ws_images_getInfo',
210      array(
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    );
218
219  $service->addMethod(
220      'pwg.images.rate',
221      'ws_images_rate',
222      array('image_id', 'rate'),
223      'rate the image'
224    );
225
226  $service->addMethod(
227      'pwg.images.search',
228      'ws_images_search',
229      array(
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        ),
247      'Returns elements for the corresponding query search.'
248    );
249
250  $service->addMethod(
251      'pwg.images.setPrivacyLevel',
252      'ws_images_setPrivacyLevel',
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)'
258    );
259
260  $service->addMethod(
261      'pwg.images.setRank',
262      'ws_images_setRank',
263      array('image_id', 'category_id', 'rank'),
264      'sets the rank of a photo for a given album (POST method only, for admins)'
265    );
266
267  $service->addMethod(
268      'pwg.rates.delete',
269      'ws_rates_delete',
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)'
275    );
276
277  $service->addMethod(
278      'pwg.session.getStatus',
279      'ws_session_getStatus',
280      null,
281      null
282    );
283
284  $service->addMethod(
285      'pwg.session.login',
286      'ws_session_login',
287      array('username', 'password'),
288      'POST method only'
289    );
290
291  $service->addMethod(
292      'pwg.session.logout',
293      'ws_session_logout',
294      null,
295      null
296    );
297
298  $service->addMethod(
299      'pwg.tags.getList',
300      'ws_tags_getList',
301      array(
302        'sort_by_counter' => array('default' =>false),
303        ),
304      'retrieves a list of available tags'
305    );
306
307  $service->addMethod(
308      'pwg.tags.getImages',
309      'ws_tags_getImages',
310      array(
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        ),
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    );
336
337  $service->addMethod(
338      'pwg.images.addChunk',
339      'ws_images_add_chunk',
340      array('data', 'original_sum', 'type', 'position'),
341      'POST method only. For admin only.'
342    );
343
344  $service->addMethod(
345      'pwg.images.addFile',
346      'ws_images_addFile',
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)'
349    );
350
351
352  $service->addMethod(
353      'pwg.images.add',
354      'ws_images_add',
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),
371        ),
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.'
375    );
376
377  $service->addMethod(
378      'pwg.images.addSimple',
379      'ws_images_addSimple',
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),
390        ),
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.'
394    );
395
396  $service->addMethod(
397      'pwg.images.delete',
398      'ws_images_delete',
399      array(
400        'image_id' =>   array('default'=>0),
401        'pwg_token' =>  array(),
402        ),
403      'Delete photos. You can give several image_ids, comma separated'
404    );
405
406  $service->addMethod(
407      'pwg.categories.getAdminList',
408      'ws_categories_getAdminList',
409      null,
410      'administration method only'
411    );
412
413  $service->addMethod(
414      'pwg.categories.add',
415      'ws_categories_add',
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'
425    );
426
427  $service->addMethod(
428      'pwg.categories.delete',
429      'ws_categories_delete',
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)'
438    );
439
440  $service->addMethod(
441      'pwg.categories.move',
442      'ws_categories_move',
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.'
449    );
450
451  $service->addMethod(
452      'pwg.categories.setRepresentative',
453      'ws_categories_setRepresentative',
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.'
459    );
460
461  $service->addMethod(
462      'pwg.tags.getAdminList',
463      'ws_tags_getAdminList',
464      null,
465      'administration method only'
466    );
467
468  $service->addMethod(
469      'pwg.tags.add',
470      'ws_tags_add',
471      array('name'),
472      'administration method only'
473    );
474
475  $service->addMethod(
476      'pwg.images.exist',
477      'ws_images_exist',
478      array(
479        'md5sum_list' =>    array('default'=>null),
480        'filename_list' =>  array('default'=>null),
481        ),
482      'check existence of a photo list'
483    );
484
485  $service->addMethod(
486      'pwg.images.checkFiles',
487      'ws_images_checkFiles',
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"'
495    );
496
497  $service->addMethod(
498      'pwg.images.checkUpload',
499      'ws_images_checkUpload',
500      null,
501      'check if Piwigo is ready for upload'
502    );
503
504  $service->addMethod(
505      'pwg.images.setInfo',
506      'ws_images_setInfo',
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'),
520        ),
521      'POST method only. Admin only
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.
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
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'
526    );
527
528  $service->addMethod(
529      'pwg.categories.setInfo',
530      'ws_categories_setInfo',
531      array(
532        'category_id' =>  array(),
533        'name' =>         array('default'=>null),
534        'comment' =>      array('default'=>null),
535        ),
536      'POST method only.'
537    );
538 
539  $service->addMethod(
540      'pwg.plugins.getList',
541      'ws_plugins_getList',
542      null,
543      'Admin only
544<br>get the list of plugin with id, name, version, state and description'
545    );
546
547  $service->addMethod(
548      'pwg.plugins.performAction',
549      'ws_plugins_performAction',
550      array('action', 'plugin', 'pwg_token'),
551      'Admin only
552<br>install/activate/deactivate/uninstall/delete a plugin'
553    );
554
555  $service->addMethod(
556      'pwg.themes.performAction',
557      'ws_themes_performAction',
558      array('action', 'theme', 'pwg_token'),
559      'activate/deactivate/delete/set_default a theme<br>administration status required'
560    );
561
562  $service->addMethod(
563      'pwg.extensions.update',
564      'ws_extensions_update',
565      array('type', 'id', 'revision', 'pwg_token'),
566      'Update an extension. Webmaster only.
567<br>Parameter type must be "plugins", "languages" or "themes".'
568  );
569
570  $service->addMethod(
571      'pwg.extensions.ignoreUpdate',
572      'ws_extensions_ignoreupdate',
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.
580<br>Parameter type must be "plugins", "languages" or "themes".
581<br>If reset parameter is true, all ignored extensions will be reinitilized.'
582  );
583
584  $service->addMethod(
585      'pwg.extensions.checkUpdates',
586      'ws_extensions_checkupdates',
587      null,
588      'Check if piwigo or extensions are up to date.'
589  );
590}
591
592?>
Note: See TracBrowser for help on using the repository browser.