source: tags/2.7.0RC1/ws.php @ 29261

Last change on this file since 29261 was 29250, checked in by mistic100, 10 years ago

add IN_WS constant in ws.php

  • Property svn:eol-style set to LF
File size: 37.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 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', './');
25define ('IN_WS', true);
26
27include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
28check_status(ACCESS_FREE);
29
30if ( !$conf['allow_web_services'] )
31{
32  page_forbidden('Web services are disabled');
33}
34
35include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');
36
37add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
38add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
39
40$requestFormat = 'rest';
41$responseFormat = null;
42
43if ( isset($_GET['format']) )
44{
45  $responseFormat = $_GET['format'];
46}
47
48if ( !isset($responseFormat) and isset($requestFormat) )
49{
50  $responseFormat = $requestFormat;
51}
52
53$service = new PwgServer();
54
55if (!is_null($requestFormat))
56{
57  $handler = null;
58  switch ($requestFormat)
59  {
60    case 'rest':
61      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
62      $handler = new PwgRestRequestHandler();
63      break;
64  }
65  $service->setHandler($requestFormat, $handler);
66}
67
68if (!is_null($responseFormat))
69{
70  $encoder = null;
71  switch ($responseFormat)
72  {
73    case 'rest':
74      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
75      $encoder = new PwgRestEncoder();
76      break;
77    case 'php':
78      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
79      $encoder = new PwgSerialPhpEncoder();
80      break;
81    case 'json':
82      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
83      $encoder = new PwgJsonEncoder();
84      break;
85    case 'xmlrpc':
86      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
87      $encoder = new PwgXmlRpcEncoder();
88      break;
89  }
90  $service->setEncoder($responseFormat, $encoder);
91}
92
93set_make_full_url();
94$service->run();
95
96
97/**
98 * event handler that registers standard methods with the web service
99 */
100function ws_addDefaultMethods( $arr )
101{
102  global $conf, $user;
103  $service = &$arr[0];
104 
105  include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
106  $ws_functions_root = PHPWG_ROOT_PATH.'include/ws_functions/';
107 
108  $f_params = array(
109    'f_min_rate' => array('default'=>null,
110                          'type'=>WS_TYPE_FLOAT),
111    'f_max_rate' => array('default'=>null,
112                          'type'=>WS_TYPE_FLOAT),
113    'f_min_hit' =>  array('default'=>null,
114                          'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
115    'f_max_hit' =>  array('default'=>null,
116                          'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
117    'f_min_ratio' => array('default'=>null,
118                           'type'=>WS_TYPE_FLOAT|WS_TYPE_POSITIVE),
119    'f_max_ratio' => array('default'=>null,
120                           'type'=>WS_TYPE_FLOAT|WS_TYPE_POSITIVE),
121    'f_max_level' => array('default'=>null,
122                           'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
123    'f_min_date_available' => array('default'=>null),
124    'f_max_date_available' => array('default'=>null),
125    'f_min_date_created' =>   array('default'=>null),
126    'f_max_date_created' =>   array('default'=>null),
127    );
128 
129  $service->addMethod(
130      'pwg.getVersion',
131      'ws_getVersion',
132      null,
133      'Returns the Piwigo version.',
134      $ws_functions_root . 'pwg.php'
135    );
136         
137  $service->addMethod(
138      'pwg.getInfos',
139      'ws_getInfos',
140      null,
141      'Returns general informations.',
142      $ws_functions_root . 'pwg.php',
143      array('admin_only'=>true)
144    );
145
146  $service->addMethod(
147      'pwg.caddie.add',
148      'ws_caddie_add',
149      array(
150        'image_id'=> array('flags'=>WS_PARAM_FORCE_ARRAY,
151                           'type'=>WS_TYPE_ID),
152        ),
153      'Adds elements to the caddie. Returns the number of elements added.',
154      $ws_functions_root . 'pwg.php',
155      array('admin_only'=>true)
156    );
157
158  $service->addMethod(
159      'pwg.categories.getImages',
160      'ws_categories_getImages',
161      array_merge(array(
162        'cat_id' =>     array('default'=>null, 
163                              'flags'=>WS_PARAM_FORCE_ARRAY,
164                              'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
165        'recursive' =>  array('default'=>false,
166                              'type'=>WS_TYPE_BOOL),
167        'per_page' =>   array('default'=>100,
168                              'maxValue'=>$conf['ws_max_images_per_page'],
169                              'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
170        'page' =>       array('default'=>0,
171                              'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
172        'order' =>      array('default'=>null,
173                              'info'=>'id, file, name, hit, rating_score, date_creation, date_available, random'),
174        ), $f_params),
175      'Returns elements for the corresponding categories.
176<br><b>cat_id</b> can be empty if <b>recursive</b> is true.
177<br><b>order</b> comma separated fields for sorting',
178      $ws_functions_root . 'pwg.categories.php'
179    );
180
181  $service->addMethod(
182      'pwg.categories.getList',
183      'ws_categories_getList',
184      array(
185        'cat_id' =>       array('default'=>null,
186                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE,
187                                'info'=>'Parent category. "0" or empty for root.'),
188        'recursive' =>    array('default'=>false,
189                                'type'=>WS_TYPE_BOOL),
190        'public' =>       array('default'=>false,
191                                'type'=>WS_TYPE_BOOL),
192        'tree_output' =>  array('default'=>false,
193                                'type'=>WS_TYPE_BOOL),
194        'fullname' =>     array('default'=>false,
195                                'type'=>WS_TYPE_BOOL),
196        ),
197      'Returns a list of categories.',
198      $ws_functions_root . 'pwg.categories.php'
199    );
200
201  $service->addMethod(
202      'pwg.getMissingDerivatives',
203      'ws_getMissingDerivatives',
204      array_merge(array(
205        'types' =>        array('default'=>null,
206                                'flags'=>WS_PARAM_FORCE_ARRAY,
207                                'info'=>'square, thumb, 2small, xsmall, small, medium, large, xlarge, xxlarge'),
208        'ids' =>          array('default'=>null,
209                                'flags'=>WS_PARAM_FORCE_ARRAY,
210                                'type'=>WS_TYPE_ID),
211        'max_urls' =>     array('default'=>200,
212                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
213        'prev_page' =>    array('default'=>null,
214                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
215        ), $f_params),
216      'Returns a list of derivatives to build.',
217      $ws_functions_root . 'pwg.php',
218      array('admin_only'=>true)
219    );
220
221  $service->addMethod(
222      'pwg.images.addComment',
223      'ws_images_addComment',
224      array(
225        'image_id' => array('type'=>WS_TYPE_ID),
226        'author' =>   array('default'=>is_a_guest()?'guest':$user['username']),
227        'content' =>  array(),
228        'key' =>      array(),
229        ),
230      'Adds a comment to an image.',
231      $ws_functions_root . 'pwg.images.php',
232      array('post_only'=>true)
233    );
234
235  $service->addMethod(
236      'pwg.images.getInfo',
237      'ws_images_getInfo',
238      array(
239        'image_id' =>           array('type'=>WS_TYPE_ID),
240        'comments_page' =>      array('default'=>0,
241                                      'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
242        'comments_per_page' =>  array('default'=>$conf['nb_comment_page'],
243                                      'maxValue'=>2*$conf['nb_comment_page'],
244                                      'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
245        ),
246      'Returns information about an image.',
247      $ws_functions_root . 'pwg.images.php'
248    );
249
250  $service->addMethod(
251      'pwg.images.rate',
252      'ws_images_rate',
253      array(
254        'image_id' => array('type'=>WS_TYPE_ID),
255        'rate' =>     array('type'=>WS_TYPE_FLOAT),
256      ),
257      'Rates an image.',
258      $ws_functions_root . 'pwg.images.php'
259    );
260
261  $service->addMethod(
262      'pwg.images.search',
263      'ws_images_search',
264      array_merge(array(
265        'query' =>        array(),
266        'per_page' =>     array('default'=>100,
267                                'maxValue'=>$conf['ws_max_images_per_page'],
268                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
269        'page' =>         array('default'=>0,
270                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
271        'order' =>        array('default'=>null,
272                                'info'=>'id, file, name, hit, rating_score, date_creation, date_available, random'),
273        ), $f_params),
274      'Returns elements for the corresponding query search.',
275      $ws_functions_root . 'pwg.images.php'
276    );
277
278  $service->addMethod(
279      'pwg.images.setPrivacyLevel',
280      'ws_images_setPrivacyLevel',
281      array(
282        'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY,
283                            'type'=>WS_TYPE_ID),
284        'level' =>    array('maxValue'=>max($conf['available_permission_levels']),
285                            'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
286        ),
287      'Sets the privacy levels for the images.',
288      $ws_functions_root . 'pwg.images.php',
289      array('admin_only'=>true, 'post_only'=>true)
290    );
291
292  $service->addMethod(
293      'pwg.images.setRank',
294      'ws_images_setRank',
295      array(
296        'image_id'    => array('type'=>WS_TYPE_ID),
297        'category_id' => array('type'=>WS_TYPE_ID),
298        'rank'        => array('type'=>WS_TYPE_INT|WS_TYPE_POSITIVE|WS_TYPE_NOTNULL)
299        ),
300      'Sets the rank of a photo for a given album.',
301      $ws_functions_root . 'pwg.images.php',
302      array('admin_only'=>true, 'post_only'=>true)
303    );
304
305  $service->addMethod(
306      'pwg.rates.delete',
307      'ws_rates_delete',
308      array(
309        'user_id' =>      array('type'=>WS_TYPE_ID),
310        'anonymous_id' => array('default'=>null),
311        'image_id' =>     array('flags'=>WS_PARAM_OPTIONAL, 'type'=>WS_TYPE_ID),
312        ),
313      'Deletes all rates for a user.',
314      $ws_functions_root . 'pwg.php',
315      array('admin_only'=>true, 'post_only'=>true)
316    );
317
318  $service->addMethod(
319      'pwg.session.getStatus',
320      'ws_session_getStatus',
321      null,
322      'Gets information about the current session. Also provides a token useable with admin methods.',
323      $ws_functions_root . 'pwg.php'
324    );
325
326  $service->addMethod(
327      'pwg.session.login',
328      'ws_session_login',
329      array('username', 'password'),
330      'Tries to login the user.',
331      $ws_functions_root . 'pwg.php',
332      array('post_only'=>true)
333    );
334
335  $service->addMethod(
336      'pwg.session.logout',
337      'ws_session_logout',
338      null,
339      'Ends the current session.',
340      $ws_functions_root . 'pwg.php'
341    );
342
343  $service->addMethod(
344      'pwg.tags.getList',
345      'ws_tags_getList',
346      array(
347        'sort_by_counter' => array('default'=>false,
348                                   'type'=>WS_TYPE_BOOL),
349        ),
350      'Retrieves a list of available tags.',
351      $ws_functions_root . 'pwg.tags.php'
352    );
353
354  $service->addMethod(
355      'pwg.tags.getImages',
356      'ws_tags_getImages',
357      array_merge(array(
358        'tag_id' =>       array('default'=>null,
359                                'flags'=>WS_PARAM_FORCE_ARRAY,
360                                'type'=>WS_TYPE_ID),
361        'tag_url_name' => array('default'=>null,
362                                'flags'=>WS_PARAM_FORCE_ARRAY),
363        'tag_name' =>     array('default'=>null,
364                                'flags'=>WS_PARAM_FORCE_ARRAY),
365        'tag_mode_and' => array('default'=>false,
366                                'type'=>WS_TYPE_BOOL),
367        'per_page' =>     array('default'=>100,
368                                'maxValue'=>$conf['ws_max_images_per_page'],
369                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
370        'page' =>         array('default'=>0,
371                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
372        'order' =>        array('default'=>null,
373                                'info'=>'id, file, name, hit, rating_score, date_creation, date_available, random'),
374        ), $f_params),
375      'Returns elements for the corresponding tags. Fill at least tag_id, tag_url_name or tag_name.',
376      $ws_functions_root . 'pwg.tags.php'
377    );
378
379  $service->addMethod(
380      'pwg.images.addChunk',
381      'ws_images_add_chunk',
382      array(
383        'data' =>         array(),
384        'original_sum' => array(),
385        'type' =>         array('default'=>'file',
386                                'info'=>'Must be "file", for backward compatiblity "high" and "thumb" are allowed.'),
387        'position' =>     array()
388        ),
389      'Add a chunk of a file.',
390      $ws_functions_root . 'pwg.images.php',
391      array('admin_only'=>true, 'post_only'=>true)
392    );
393
394  $service->addMethod(
395      'pwg.images.addFile',
396      'ws_images_addFile',
397      array(
398        'image_id' => array('type'=>WS_TYPE_ID),
399        'type' =>     array('default'=>'file',
400                            'info'=>'Must be "file", for backward compatiblity "high" and "thumb" are allowed.'),
401        'sum' =>      array(),
402        ),
403      'Add or update a file for an existing photo.
404<br>pwg.images.addChunk must have been called before (maybe several times).',
405      $ws_functions_root . 'pwg.images.php',
406      array('admin_only'=>true)
407    );
408
409
410  $service->addMethod(
411      'pwg.images.add',
412      'ws_images_add',
413      array(
414        'thumbnail_sum' =>      array('default'=>null),
415        'high_sum' =>           array('default'=>null),
416        'original_sum' =>       array(),
417        'original_filename' =>  array('default'=>null,
418                                      'Provide it if "check_uniqueness" is true and $conf["uniqueness_mode"] is "filename".'),
419        'name' =>               array('default'=>null),
420        'author' =>             array('default'=>null),
421        'date_creation' =>      array('default'=>null),
422        'comment' =>            array('default'=>null),
423        'categories' =>         array('default'=>null,
424                                      'info'=>'String list "category_id[,rank];category_id[,rank]".<br>The rank is optional and is equivalent to "auto" if not given.'),
425        'tag_ids' =>            array('default'=>null,
426                                      'info'=>'Comma separated ids'),
427        'level' =>              array('default'=>0,
428                                      'maxValue'=>max($conf['available_permission_levels']),
429                                      'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
430        'check_uniqueness' =>   array('default'=>true,
431                                      'type'=>WS_TYPE_BOOL),
432        'image_id' =>           array('default'=>null,
433                                      'type'=>WS_TYPE_ID),
434        ),
435      'Add an image.
436<br>pwg.images.addChunk must have been called before (maybe several times).
437<br>Don\'t use "thumbnail_sum" and "high_sum", these parameters are here for backward compatibility.',
438      $ws_functions_root . 'pwg.images.php',
439      array('admin_only'=>true)
440    );
441
442  $service->addMethod(
443      'pwg.images.addSimple',
444      'ws_images_addSimple',
445      array(
446        'category' => array('default'=>null,
447                            'flags'=>WS_PARAM_FORCE_ARRAY,
448                            'type'=>WS_TYPE_ID),
449        'name' =>     array('default'=>null),
450        'author' =>   array('default'=>null),
451        'comment' =>  array('default'=>null),
452        'level' =>    array('default'=>0,
453                            'maxValue'=>max($conf['available_permission_levels']),
454                            'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
455        'tags' =>     array('default'=>null,
456                            'flags'=>WS_PARAM_ACCEPT_ARRAY),
457        'image_id' => array('default'=>null,
458                            'type'=>WS_TYPE_ID),
459        ),
460      'Add an image.
461<br>Use the <b>$_FILES[image]</b> field for uploading file.
462<br>Set the form encoding to "form-data".
463<br>You can update an existing photo if you define an existing image_id.',
464      $ws_functions_root . 'pwg.images.php',
465      array('admin_only'=>true, 'post_only'=>true)
466    );
467
468  $service->addMethod(
469      'pwg.images.upload',
470      'ws_images_upload',
471      array(
472        'name' => array('default' => null),
473        'category' => array(
474          'default'=>null,
475          'flags'=>WS_PARAM_FORCE_ARRAY,
476          'type'=>WS_TYPE_ID
477          ),
478        'level' => array(
479          'default' => 0,
480          'maxValue' => max($conf['available_permission_levels']),
481          'type' => WS_TYPE_INT|WS_TYPE_POSITIVE
482          ),
483        'pwg_token' => array(),
484        ),
485      'Add an image.
486<br>Use the <b>$_FILES[image]</b> field for uploading file.
487<br>Set the form encoding to "form-data".',
488      $ws_functions_root . 'pwg.images.php',
489      array('admin_only'=>true, 'post_only'=>true)
490    );
491 
492  $service->addMethod(
493      'pwg.images.delete',
494      'ws_images_delete',
495      array(
496        'image_id' =>   array('flags'=>WS_PARAM_ACCEPT_ARRAY),
497        'pwg_token' =>  array(),
498        ),
499      'Deletes image(s).',
500      $ws_functions_root . 'pwg.images.php',
501      array('admin_only'=>true, 'post_only'=>true)
502    );
503
504  $service->addMethod(
505      'pwg.categories.getAdminList',
506      'ws_categories_getAdminList',
507      null,
508      'Get albums list as displayed on admin page.',
509      $ws_functions_root . 'pwg.categories.php',
510      array('admin_only'=>true)
511    );
512
513  $service->addMethod(
514      'pwg.categories.add',
515      'ws_categories_add',
516      array(
517        'name' =>         array(),
518        'parent' =>       array('default'=>null,
519                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
520        'comment' =>      array('default'=>null),
521        'visible' =>      array('default'=>true,
522                                'type'=>WS_TYPE_BOOL),
523        'status' =>       array('default'=>null,
524                                'info'=>'public, private'),
525        'commentable' =>  array('default'=>true,
526                                'type'=>WS_TYPE_BOOL),
527        ),
528      'Adds an album.',
529      $ws_functions_root . 'pwg.categories.php',
530      array('admin_only'=>true)
531    );
532
533  $service->addMethod(
534      'pwg.categories.delete',
535      'ws_categories_delete',
536      array(
537        'category_id'=>           array('flags'=>WS_PARAM_ACCEPT_ARRAY),
538        'photo_deletion_mode' =>  array('default'=>'delete_orphans'),
539        'pwg_token' =>            array(),
540        ),
541      'Deletes album(s).
542<br><b>photo_deletion_mode</b> can be "no_delete" (may create orphan photos), "delete_orphans"
543(default mode, only deletes photos linked to no other album) or "force_delete" (delete all photos, even those linked to other albums)',
544      $ws_functions_root . 'pwg.categories.php',
545      array('admin_only'=>true, 'post_only'=>true)
546    );
547
548  $service->addMethod(
549      'pwg.categories.move',
550      'ws_categories_move',
551      array(
552        'category_id' =>  array('flags'=>WS_PARAM_ACCEPT_ARRAY),
553        'parent' =>       array('type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
554        'pwg_token' =>    array(),
555        ),
556      'Move album(s).
557<br>Set parent as 0 to move to gallery root. Only virtual categories can be moved.',
558      $ws_functions_root . 'pwg.categories.php',
559      array('admin_only'=>true, 'post_only'=>true)
560    );
561
562  $service->addMethod(
563      'pwg.categories.setRepresentative',
564      'ws_categories_setRepresentative',
565      array(
566        'category_id' =>  array('type'=>WS_TYPE_ID),
567        'image_id' =>     array('type'=>WS_TYPE_ID),
568        ),
569      'Sets the representative photo for an album. The photo doesn\'t have to belong to the album.',
570      $ws_functions_root . 'pwg.categories.php',
571      array('admin_only'=>true, 'post_only'=>true)
572    );
573
574  $service->addMethod(
575      'pwg.tags.getAdminList',
576      'ws_tags_getAdminList',
577      null,
578      '<b>Admin only.</b>',
579      $ws_functions_root . 'pwg.tags.php',
580      array('admin_only'=>true)
581    );
582
583  $service->addMethod( // TODO: create multiple tags
584      'pwg.tags.add',
585      'ws_tags_add',
586      array('name'),
587      'Adds a new tag.',
588      $ws_functions_root . 'pwg.tags.php',
589      array('admin_only'=>true)
590    );
591
592  $service->addMethod(
593      'pwg.images.exist',
594      'ws_images_exist',
595      array(
596        'md5sum_list' =>    array('default'=>null),
597        'filename_list' =>  array('default'=>null),
598        ),
599      'Checks existence of images.
600<br>Give <b>md5sum_list</b> if $conf[uniqueness_mode]==md5sum. Give <b>filename_list</b> if $conf[uniqueness_mode]==filename.',
601      $ws_functions_root . 'pwg.images.php',
602      array('admin_only'=>true)
603    );
604
605  $service->addMethod(
606      'pwg.images.checkFiles',
607      'ws_images_checkFiles',
608      array(
609        'image_id' =>       array('type'=>WS_TYPE_ID),
610        'file_sum' =>       array('default'=>null),
611        'thumbnail_sum' =>  array('default'=>null),
612        'high_sum' =>       array('default'=>null),
613        ),
614      'Checks if you have updated version of your files for a given photo, the answer can be "missing", "equals" or "differs".
615<br>Don\'t use "thumbnail_sum" and "high_sum", these parameters are here for backward compatibility.',
616      $ws_functions_root . 'pwg.images.php',
617      array('admin_only'=>true)
618    );
619
620  $service->addMethod(
621      'pwg.images.checkUpload',
622      'ws_images_checkUpload',
623      null,
624      'Checks if Piwigo is ready for upload.',
625      $ws_functions_root . 'pwg.images.php',
626      array('admin_only'=>true)
627    );
628
629  $service->addMethod(
630      'pwg.images.setInfo',
631      'ws_images_setInfo',
632      array(
633        'image_id' =>       array('type'=>WS_TYPE_ID),
634        'file' =>           array('default'=>null),
635        'name' =>           array('default'=>null),
636        'author' =>         array('default'=>null),
637        'date_creation' =>  array('default'=>null),
638        'comment' =>        array('default'=>null),
639        'categories' =>     array('default'=>null,
640                                  'info'=>'String list "category_id[,rank];category_id[,rank]".<br>The rank is optional and is equivalent to "auto" if not given.'),
641        'tag_ids' =>        array('default'=>null,
642                                  'info'=>'Comma separated ids'),
643        'level' =>          array('default'=>null,
644                                  'maxValue'=>max($conf['available_permission_levels']),
645                                  'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
646        'single_value_mode' =>    array('default'=>'fill_if_empty'),
647        'multiple_value_mode' =>  array('default'=>'append'),
648        ),
649      'Changes properties of an image.
650<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"
651(overwrite any existing value) and applies to single values properties like name/author/date_creation/comment.
652<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.',
653      $ws_functions_root . 'pwg.images.php',
654      array('admin_only'=>true, 'post_only'=>true)
655    );
656
657  $service->addMethod(
658      'pwg.categories.setInfo',
659      'ws_categories_setInfo',
660      array(
661        'category_id' =>  array('type'=>WS_TYPE_ID),
662        'name' =>         array('default'=>null),
663        'comment' =>      array('default'=>null),
664        ),
665      'Changes properties of an album.',
666      $ws_functions_root . 'pwg.categories.php',
667      array('admin_only'=>true, 'post_only'=>true)
668    );
669 
670  $service->addMethod(
671      'pwg.plugins.getList',
672      'ws_plugins_getList',
673      null,
674      'Gets the list of plugins with id, name, version, state and description.',
675      $ws_functions_root . 'pwg.extensions.php',
676      array('admin_only'=>true)
677    );
678
679  $service->addMethod(
680      'pwg.plugins.performAction',
681      'ws_plugins_performAction',
682      array(
683        'action'    => array('info'=>'install, activate, deactivate, uninstall, delete'),
684        'plugin'    => array(),
685        'pwg_token' => array(),
686        ),
687      null,
688      $ws_functions_root . 'pwg.extensions.php',
689      array('admin_only'=>true)
690    );
691
692  $service->addMethod(
693      'pwg.themes.performAction',
694      'ws_themes_performAction',
695      array(
696        'action'    => array('info'=>'activate, deactivate, delete, set_default'),
697        'theme'     => array(),
698        'pwg_token' => array(),
699        ),
700      null,
701      $ws_functions_root . 'pwg.extensions.php',
702      array('admin_only'=>true)
703    );
704
705  $service->addMethod(
706      'pwg.extensions.update',
707      'ws_extensions_update',
708      array(
709        'type' => array('info'=>'plugins, languages, themes'),
710        'id' => array(),
711        'revision' => array(),
712        'pwg_token' => array(),
713        ),
714      '<b>Webmaster only.</b>',
715      $ws_functions_root . 'pwg.extensions.php',
716      array('admin_only'=>true)
717    );
718
719  $service->addMethod(
720      'pwg.extensions.ignoreUpdate',
721      'ws_extensions_ignoreupdate',
722      array(
723        'type' =>       array('default'=>null,
724                              'info'=>'plugins, languages, themes'),
725        'id' =>         array('default'=>null),
726        'reset' =>      array('default'=>false,
727                              'type'=>WS_TYPE_BOOL,
728                              'info'=>'If true, all ignored extensions will be reinitilized.'),
729        'pwg_token' =>  array(),
730      ),
731      '<b>Webmaster only.</b> Ignores an extension if it needs update.',
732      $ws_functions_root . 'pwg.extensions.php',
733      array('admin_only'=>true)
734    );
735
736  $service->addMethod(
737      'pwg.extensions.checkUpdates',
738      'ws_extensions_checkupdates',
739      null,
740      'Checks if piwigo or extensions are up to date.',
741      $ws_functions_root . 'pwg.extensions.php',
742      array('admin_only'=>true)
743    );
744
745  $service->addMethod(
746      'pwg.groups.getList',
747      'ws_groups_getList',
748      array(
749        'group_id' => array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
750                            'type'=>WS_TYPE_ID),
751        'name' =>     array('flags'=>WS_PARAM_OPTIONAL,
752                            'info'=>'Use "%" as wildcard.'),
753        'per_page' => array('default'=>100,
754                            'maxValue'=>$conf['ws_max_users_per_page'],
755                            'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
756        'page' =>     array('default'=>0,
757                            'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
758        'order' =>    array('default'=>'name',
759                            'info'=>'id, name, nb_users, is_default'),
760        ),
761      'Retrieves a list of all groups. The list can be filtered.',
762      $ws_functions_root . 'pwg.groups.php',
763      array('admin_only'=>true)
764    );
765
766  $service->addMethod(
767      'pwg.groups.add',
768      'ws_groups_add',
769      array(
770        'name' =>       array(),
771        'is_default' => array('default'=>false,
772                              'type'=>WS_TYPE_BOOL),
773        ),
774      'Creates a group and returns the new group record.',
775      $ws_functions_root . 'pwg.groups.php',
776      array('admin_only'=>true, 'post_only'=>true)
777    );
778
779  $service->addMethod(
780      'pwg.groups.delete',
781      'ws_groups_delete',
782      array(
783        'group_id' => array('flags'=>WS_PARAM_FORCE_ARRAY,
784                            'type'=>WS_TYPE_ID),
785        'pwg_token' =>  array(),
786        ),
787      'Deletes a or more groups. Users and photos are not deleted.',
788      $ws_functions_root . 'pwg.groups.php',
789      array('admin_only'=>true, 'post_only'=>true)
790    );
791
792  $service->addMethod(
793      'pwg.groups.setInfo',
794      'ws_groups_setInfo',
795      array(
796        'group_id' =>   array('type'=>WS_TYPE_ID),
797        'name' =>       array('flags'=>WS_PARAM_OPTIONAL),
798        'is_default' => array('flags'=>WS_PARAM_OPTIONAL,
799                              'type'=>WS_TYPE_BOOL),
800        'pwg_token' => array(),
801        ),
802      'Updates a group. Leave a field blank to keep the current value.',
803      $ws_functions_root . 'pwg.groups.php',
804      array('admin_only'=>true, 'post_only'=>true)
805    );
806
807  $service->addMethod(
808      'pwg.groups.addUser',
809      'ws_groups_addUser',
810      array(
811        'group_id' => array('type'=>WS_TYPE_ID),
812        'user_id' =>  array('flags'=>WS_PARAM_FORCE_ARRAY,
813                            'type'=>WS_TYPE_ID),
814        'pwg_token' => array(),
815        ),
816      'Adds one or more users to a group.',
817      $ws_functions_root . 'pwg.groups.php',
818      array('admin_only'=>true, 'post_only'=>true)
819    );
820
821  $service->addMethod(
822      'pwg.groups.deleteUser',
823      'ws_groups_deleteUser',
824      array(
825        'group_id' => array('type'=>WS_TYPE_ID),
826        'user_id' =>  array('flags'=>WS_PARAM_FORCE_ARRAY,
827                            'type'=>WS_TYPE_ID),
828        'pwg_token' => array(),
829        ),
830      'Removes one or more users from a group.',
831      $ws_functions_root . 'pwg.groups.php',
832      array('admin_only'=>true, 'post_only'=>true)
833    );
834
835  $service->addMethod(
836      'pwg.users.getList',
837      'ws_users_getList',
838      array(
839        'user_id' =>    array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
840                              'type'=>WS_TYPE_ID),
841        'username' =>   array('flags'=>WS_PARAM_OPTIONAL,
842                              'info'=>'Use "%" as wildcard.'),
843        'status' =>     array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
844                              'info'=>'guest,generic,normal,admin,webmaster'),
845        'min_level' =>  array('default'=>0,
846                              'maxValue'=>max($conf['available_permission_levels']),
847                              'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
848        'group_id' =>   array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
849                              'type'=>WS_TYPE_ID),
850        'per_page' =>   array('default'=>100,
851                              'maxValue'=>$conf['ws_max_users_per_page'],
852                              'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
853        'page' =>       array('default'=>0,
854                              'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
855        'order' =>      array('default'=>'id',
856                              'info'=>'id, username, level, email'),
857        'display' =>    array('default'=>'basics',
858                              'info'=>'Comma saparated list (see method description)'),
859        ),
860      'Retrieves a list of all the users.<br>
861<br>
862<b>display</b> controls which data are returned, possible values are:<br>
863all, basics, none,<br>
864username, email, status, level, groups,<br>
865language, theme, nb_image_page, recent_period, expand, show_nb_comments, show_nb_hits,<br>
866enabled_high, registration_date, registration_date_string, registration_date_since, last_visit, last_visit_string, last_visit_since<br>
867<b>basics</b> stands for "username,email,status,level,groups"',
868      $ws_functions_root . 'pwg.users.php',
869      array('admin_only'=>true)
870    );
871
872  $service->addMethod(
873      'pwg.users.add',
874      'ws_users_add',
875      array(
876        'username' => array(),
877        'password' => array('default'=>null),
878        'password_confirm' => array('flags'=>WS_PARAM_OPTIONAL),
879        'email' =>    array('default'=>null),
880        'send_password_by_mail' => array('default'=>false, 'type'=>WS_TYPE_BOOL),
881        'pwg_token' => array(),
882        ),
883      'Registers a new user.',
884      $ws_functions_root . 'pwg.users.php',
885      array('admin_only'=>true, 'post_only'=>true)
886    );
887
888  $service->addMethod(
889      'pwg.users.delete',
890      'ws_users_delete',
891      array(
892        'user_id' =>  array('flags'=>WS_PARAM_FORCE_ARRAY,
893                            'type'=>WS_TYPE_ID),
894        'pwg_token' =>  array(),
895        ),
896      'Deletes on or more users. Photos owned by this user are not deleted.',
897      $ws_functions_root . 'pwg.users.php',
898      array('admin_only'=>true, 'post_only'=>true)
899    );
900
901  $service->addMethod(
902      'pwg.users.setInfo',
903      'ws_users_setInfo',
904      array(
905        'user_id' =>          array('flags'=>WS_PARAM_FORCE_ARRAY,
906                                    'type'=>WS_TYPE_ID),
907        'username' =>         array('flags'=>WS_PARAM_OPTIONAL),
908        'password' =>         array('flags'=>WS_PARAM_OPTIONAL),
909        'email' =>            array('flags'=>WS_PARAM_OPTIONAL),
910        'status' =>           array('flags'=>WS_PARAM_OPTIONAL,
911                                    'info'=>'guest,generic,normal,admin,webmaster'),
912        'level'=>             array('flags'=>WS_PARAM_OPTIONAL,
913                                    'maxValue'=>max($conf['available_permission_levels']),
914                                    'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
915        'language' =>         array('flags'=>WS_PARAM_OPTIONAL),
916        'theme' =>            array('flags'=>WS_PARAM_OPTIONAL),
917        'group_id' => array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY, 'type'=>WS_TYPE_INT),
918        // bellow are parameters removed in a future version
919        'nb_image_page' =>    array('flags'=>WS_PARAM_OPTIONAL,
920                                    'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE|WS_TYPE_NOTNULL),
921        'recent_period' =>    array('flags'=>WS_PARAM_OPTIONAL,
922                                    'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
923        'expand' =>           array('flags'=>WS_PARAM_OPTIONAL,
924                                    'type'=>WS_TYPE_BOOL),
925        'show_nb_comments' => array('flags'=>WS_PARAM_OPTIONAL,
926                                    'type'=>WS_TYPE_BOOL),
927        'show_nb_hits' =>     array('flags'=>WS_PARAM_OPTIONAL,
928                                    'type'=>WS_TYPE_BOOL),
929        'enabled_high' =>     array('flags'=>WS_PARAM_OPTIONAL,
930                                    'type'=>WS_TYPE_BOOL),
931        'pwg_token' => array(),
932        ),
933      'Updates a user. Leave a field blank to keep the current value.
934<br>"username", "password" and "email" are ignored if "user_id" is an array.
935<br>set "group_id" to -1 if you want to dissociate users from all groups',
936      $ws_functions_root . 'pwg.users.php',
937      array('admin_only'=>true, 'post_only'=>true)
938    );
939   
940  $service->addMethod(
941      'pwg.permissions.getList',
942      'ws_permissions_getList',
943      array(
944        'cat_id' =>     array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
945                              'type'=>WS_TYPE_ID),
946        'group_id' =>   array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
947                              'type'=>WS_TYPE_ID),
948        'user_id' =>    array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
949                              'type'=>WS_TYPE_ID),
950        ),
951      'Returns permissions: user ids and group ids having access to each album ; this list can be filtered.
952<br>Provide only one parameter!',
953      $ws_functions_root . 'pwg.permissions.php',
954      array('admin_only'=>true)
955    );
956   
957  $service->addMethod(
958      'pwg.permissions.add',
959      'ws_permissions_add',
960      array(
961        'cat_id' =>     array('flags'=>WS_PARAM_FORCE_ARRAY,
962                              'type'=>WS_TYPE_ID),
963        'group_id' =>   array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
964                              'type'=>WS_TYPE_ID),
965        'user_id' =>    array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
966                              'type'=>WS_TYPE_ID),
967        'recursive' =>  array('default'=>false,
968                              'type'=>WS_TYPE_BOOL),
969        'pwg_token' => array(),
970        ),
971      'Adds permissions to an album.',
972      $ws_functions_root . 'pwg.permissions.php',
973      array('admin_only'=>true, 'post_only'=>true)
974    );
975   
976  $service->addMethod(
977      'pwg.permissions.remove',
978      'ws_permissions_remove',
979      array(
980        'cat_id' =>   array('flags'=>WS_PARAM_FORCE_ARRAY,
981                            'type'=>WS_TYPE_ID),
982        'group_id' => array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
983                            'type'=>WS_TYPE_ID),
984        'user_id' =>  array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
985                            'type'=>WS_TYPE_ID),
986        'pwg_token' => array(),
987        ),
988      'Removes permissions from an album.',
989      $ws_functions_root . 'pwg.permissions.php',
990      array('admin_only'=>true, 'post_only'=>true)
991    );
992}
993
994?>
Note: See TracBrowser for help on using the repository browser.