source: trunk/ws.php @ 28575

Last change on this file since 28575 was 28545, checked in by plg, 10 years ago

feature 2616: HTML5 upload (with plupload 2.1.2). First basic implementation. Needs customization.

Chunked upload + Drag & drop (no more Flash)

use a new specific API method pwg.images.upload

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