source: branches/2.6/ws.php @ 27810

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

bug 3055: add security pwg_token on API methods introduced in Piwigo 2.6
(pwg.groups.addUser, pwg.groups.deleteUser, pwg.groups.setInfo, pwg.users.add,
pwg.users.setInfo, pwg.permissions.add, pwg.permissions.remove)

  • Property svn:eol-style set to LF
File size: 36.3 KB
RevLine 
[1698]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[26461]5// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[1698]23
24define ('PHPWG_ROOT_PATH', './');
25
26include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
[2325]27check_status(ACCESS_FREE);
[1698]28
[1781]29if ( !$conf['allow_web_services'] )
30{
31  page_forbidden('Web services are disabled');
32}
33
[25281]34include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');
35
[20815]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
[1768]96/**
97 * event handler that registers standard methods with the web service
98 */
[1698]99function ws_addDefaultMethods( $arr )
100{
[1849]101  global $conf, $user;
[1698]102  $service = &$arr[0];
[20815]103 
104  include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
[25281]105  $ws_functions_root = PHPWG_ROOT_PATH.'include/ws_functions/';
[20815]106 
[25077]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 
[20817]128  $service->addMethod(
129      'pwg.getVersion',
130      'ws_getVersion',
[20815]131      null,
[25281]132      'Returns the Piwigo version.',
133      $ws_functions_root . 'pwg.php'
[20815]134    );
[10017]135         
[20817]136  $service->addMethod(
137      'pwg.getInfos',
138      'ws_getInfos',
[20815]139      null,
[25394]140      'Returns general informations.',
[25281]141      $ws_functions_root . 'pwg.php',
[25115]142      array('admin_only'=>true)
[20815]143    );
[1698]144
[20817]145  $service->addMethod(
146      'pwg.caddie.add',
147      'ws_caddie_add',
[2429]148      array(
[25077]149        'image_id'=> array('flags'=>WS_PARAM_FORCE_ARRAY,
150                           'type'=>WS_TYPE_ID),
[20815]151        ),
[25394]152      'Adds elements to the caddie. Returns the number of elements added.',
[25281]153      $ws_functions_root . 'pwg.php',
[25115]154      array('admin_only'=>true)
[20815]155    );
[2429]156
[20817]157  $service->addMethod(
158      'pwg.categories.getImages',
159      'ws_categories_getImages',
[25077]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),
[1698]174      'Returns elements for the corresponding categories.
[25077]175<br><b>cat_id</b> can be empty if <b>recursive</b> is true.
[25281]176<br><b>order</b> comma separated fields for sorting',
177      $ws_functions_root . 'pwg.categories.php'
[1698]178    );
179
[20817]180  $service->addMethod(
181      'pwg.categories.getList',
182      'ws_categories_getList',
[1698]183      array(
[25077]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),
[20815]195        ),
[25281]196      'Returns a list of categories.',
197      $ws_functions_root . 'pwg.categories.php'
[20815]198    );
[1698]199
[20817]200  $service->addMethod(
201      'pwg.getMissingDerivatives',
202      'ws_getMissingDerivatives',
[25077]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),
[25394]215      'Returns a list of derivatives to build.',
[25281]216      $ws_functions_root . 'pwg.php',
[25115]217      array('admin_only'=>true)
[20815]218    );
[12865]219
[20817]220  $service->addMethod(
221      'pwg.images.addComment',
222      'ws_images_addComment',
[1849]223      array(
[25077]224        'image_id' => array('type'=>WS_TYPE_ID),
[20815]225        'author' =>   array('default'=>is_a_guest()?'guest':$user['username']),
226        'content' =>  array(),
227        'key' =>      array(),
228        ),
[25394]229      'Adds a comment to an image.',
[25281]230      $ws_functions_root . 'pwg.images.php',
[25115]231      array('post_only'=>true)
[20815]232    );
[1849]233
[20817]234  $service->addMethod(
235      'pwg.images.getInfo',
236      'ws_images_getInfo',
[1849]237      array(
[25077]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),
[20815]244        ),
[25281]245      'Returns information about an image.',
246      $ws_functions_root . 'pwg.images.php'
[20815]247    );
[1698]248
[20817]249  $service->addMethod(
250      'pwg.images.rate',
251      'ws_images_rate',
[25077]252      array(
253        'image_id' => array('type'=>WS_TYPE_ID),
254        'rate' =>     array('type'=>WS_TYPE_FLOAT),
255      ),
[25281]256      'Rates an image.',
257      $ws_functions_root . 'pwg.images.php'
[20815]258    );
[2435]259
[20817]260  $service->addMethod(
261      'pwg.images.search',
262      'ws_images_search',
[25077]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),
[25281]273      'Returns elements for the corresponding query search.',
274      $ws_functions_root . 'pwg.images.php'
[1837]275    );
[2516]276
[20817]277  $service->addMethod(
278      'pwg.images.setPrivacyLevel',
279      'ws_images_setPrivacyLevel',
[20815]280      array(
[25077]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),
[20815]285        ),
[25394]286      'Sets the privacy levels for the images.',
[25281]287      $ws_functions_root . 'pwg.images.php',
[25115]288      array('admin_only'=>true, 'post_only'=>true)
[2463]289    );
[1837]290
[20817]291  $service->addMethod(
292      'pwg.images.setRank',
293      'ws_images_setRank',
[25077]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        ),
[25394]299      'Sets the rank of a photo for a given album.',
[25281]300      $ws_functions_root . 'pwg.images.php',
[25115]301      array('admin_only'=>true, 'post_only'=>true)
[11372]302    );
[12624]303
[20817]304  $service->addMethod(
305      'pwg.rates.delete',
306      'ws_rates_delete',
[20815]307      array(
[25077]308        'user_id' =>      array('type'=>WS_TYPE_ID),
[20815]309        'anonymous_id' => array('default'=>null),
[26838]310        'image_id' =>     array('flags'=>WS_PARAM_OPTIONAL, 'type'=>WS_TYPE_ID),
[20815]311        ),
[25394]312      'Deletes all rates for a user.',
[25281]313      $ws_functions_root . 'pwg.php',
[25115]314      array('admin_only'=>true, 'post_only'=>true)
[12624]315    );
[20815]316
[20817]317  $service->addMethod(
318      'pwg.session.getStatus',
319      'ws_session_getStatus',
320      null,
[25281]321      'Gets information about the current session. Also provides a token useable with admin methods.',
322      $ws_functions_root . 'pwg.php'
[20817]323    );
[20815]324
[20817]325  $service->addMethod(
326      'pwg.session.login',
327      'ws_session_login',
[20815]328      array('username', 'password'),
[25394]329      'Tries to login the user.',
[25281]330      $ws_functions_root . 'pwg.php',
[25115]331      array('post_only'=>true)
[20815]332    );
333
[20817]334  $service->addMethod(
335      'pwg.session.logout',
336      'ws_session_logout',
337      null,
[25281]338      'Ends the current session.',
339      $ws_functions_root . 'pwg.php'
[20817]340    );
[1698]341
[20817]342  $service->addMethod(
343      'pwg.tags.getList',
344      'ws_tags_getList',
[20815]345      array(
[25077]346        'sort_by_counter' => array('default'=>false,
347                                   'type'=>WS_TYPE_BOOL),
[20815]348        ),
[25281]349      'Retrieves a list of available tags.',
350      $ws_functions_root . 'pwg.tags.php'
[20815]351    );
352
[20817]353  $service->addMethod(
354      'pwg.tags.getImages',
355      'ws_tags_getImages',
[25077]356      array_merge(array(
[20815]357        'tag_id' =>       array('default'=>null,
[25077]358                                'flags'=>WS_PARAM_FORCE_ARRAY,
359                                'type'=>WS_TYPE_ID),
[20815]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),
[25077]364        'tag_mode_and' => array('default'=>false,
365                                'type'=>WS_TYPE_BOOL),
[20815]366        'per_page' =>     array('default'=>100,
[25077]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),
[25281]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'
[1698]376    );
[2463]377
[20817]378  $service->addMethod(
379      'pwg.images.addChunk',
380      'ws_images_add_chunk',
[25077]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        ),
[25394]388      'Add a chunk of a file.',
[25281]389      $ws_functions_root . 'pwg.images.php',
[25115]390      array('admin_only'=>true, 'post_only'=>true)
[3193]391    );
392
[20817]393  $service->addMethod(
394      'pwg.images.addFile',
395      'ws_images_addFile',
[25077]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        ),
[25394]402      'Add or update a file for an existing photo.
[25115]403<br>pwg.images.addChunk must have been called before (maybe several times).',
[25281]404      $ws_functions_root . 'pwg.images.php',
[25115]405      array('admin_only'=>true)
[4348]406    );
407
408
[20817]409  $service->addMethod(
410      'pwg.images.add',
411      'ws_images_add',
[20815]412      array(
413        'thumbnail_sum' =>      array('default'=>null),
414        'high_sum' =>           array('default'=>null),
415        'original_sum' =>       array(),
[25077]416        'original_filename' =>  array('default'=>null,
417                                      'Provide it if "check_uniqueness" is true and $conf["uniqueness_mode"] is "filename".'),
[20815]418        'name' =>               array('default'=>null),
419        'author' =>             array('default'=>null),
420        'date_creation' =>      array('default'=>null),
421        'comment' =>            array('default'=>null),
[25077]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'),
[20815]426        'level' =>              array('default'=>0,
[25077]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),
[2569]433        ),
[25394]434      'Add an image.
[25077]435<br>pwg.images.addChunk must have been called before (maybe several times).
[25115]436<br>Don\'t use "thumbnail_sum" and "high_sum", these parameters are here for backward compatibility.',
[25281]437      $ws_functions_root . 'pwg.images.php',
[25115]438      array('admin_only'=>true)
[2463]439    );
[2563]440
[20817]441  $service->addMethod(
442      'pwg.images.addSimple',
443      'ws_images_addSimple',
[20815]444      array(
[25077]445        'category' => array('default'=>null,
446                            'flags'=>WS_PARAM_FORCE_ARRAY,
447                            'type'=>WS_TYPE_ID),
[20815]448        'name' =>     array('default'=>null),
449        'author' =>   array('default'=>null),
450        'comment' =>  array('default'=>null),
451        'level' =>    array('default'=>0,
[25077]452                            'maxValue'=>max($conf['available_permission_levels']),
453                            'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
[20815]454        'tags' =>     array('default'=>null,
455                            'flags'=>WS_PARAM_ACCEPT_ARRAY),
[25077]456        'image_id' => array('default'=>null,
457                            'type'=>WS_TYPE_ID),
[8249]458        ),
[25394]459      'Add an image.
[25077]460<br>Use the <b>$_FILES[image]</b> field for uploading file.
461<br>Set the form encoding to "form-data".
[25115]462<br>You can update an existing photo if you define an existing image_id.',
[25281]463      $ws_functions_root . 'pwg.images.php',
[25115]464      array('admin_only'=>true, 'post_only'=>true)
[8249]465    );
[8266]466
[20817]467  $service->addMethod(
468      'pwg.images.delete',
469      'ws_images_delete',
[20815]470      array(
[25077]471        'image_id' =>   array('flags'=>WS_PARAM_ACCEPT_ARRAY),
[20815]472        'pwg_token' =>  array(),
473        ),
[25394]474      'Deletes image(s).',
[25281]475      $ws_functions_root . 'pwg.images.php',
[25115]476      array('admin_only'=>true, 'post_only'=>true)
[8266]477    );
478
[20817]479  $service->addMethod(
480      'pwg.categories.getAdminList',
481      'ws_categories_getAdminList',
[20815]482      null,
[25394]483      'Get albums list as displayed on admin page.',
[25281]484      $ws_functions_root . 'pwg.categories.php',
[25115]485      array('admin_only'=>true)
[2563]486    );
[2583]487
[20817]488  $service->addMethod(
489      'pwg.categories.add',
490      'ws_categories_add',
[20815]491      array(
492        'name' =>         array(),
[25077]493        'parent' =>       array('default'=>null,
[25264]494                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
[20815]495        'comment' =>      array('default'=>null),
[25077]496        'visible' =>      array('default'=>true,
497                                'type'=>WS_TYPE_BOOL),
498        'status' =>       array('default'=>null,
499                                'info'=>'public, private'),
500        'commentable' =>  array('default'=>true,
501                                'type'=>WS_TYPE_BOOL),
[20815]502        ),
[25394]503      'Adds an album.',
[25281]504      $ws_functions_root . 'pwg.categories.php',
505      array('admin_only'=>true)
[2583]506    );
[2584]507
[20817]508  $service->addMethod(
509      'pwg.categories.delete',
510      'ws_categories_delete',
[20815]511      array(
[25077]512        'category_id'=>           array('flags'=>WS_PARAM_ACCEPT_ARRAY),
513        'photo_deletion_mode' =>  array('default'=>'delete_orphans'),
[20815]514        'pwg_token' =>            array(),
515        ),
[25394]516      'Deletes album(s).
[20815]517<br><b>photo_deletion_mode</b> can be "no_delete" (may create orphan photos), "delete_orphans"
[25115]518(default mode, only deletes photos linked to no other album) or "force_delete" (delete all photos, even those linked to other albums)',
[25281]519      $ws_functions_root . 'pwg.categories.php',
[25115]520      array('admin_only'=>true, 'post_only'=>true)
[8266]521    );
522
[20817]523  $service->addMethod(
524      'pwg.categories.move',
525      'ws_categories_move',
[20815]526      array(
[25077]527        'category_id' =>  array('flags'=>WS_PARAM_ACCEPT_ARRAY),
528        'parent' =>       array('type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
[20815]529        'pwg_token' =>    array(),
530        ),
[25394]531      'Move album(s).
[25115]532<br>Set parent as 0 to move to gallery root. Only virtual categories can be moved.',
[25281]533      $ws_functions_root . 'pwg.categories.php',
[25115]534      array('admin_only'=>true, 'post_only'=>true)
[8272]535    );
[11746]536
[20817]537  $service->addMethod(
538      'pwg.categories.setRepresentative',
539      'ws_categories_setRepresentative',
[20815]540      array(
[25077]541        'category_id' =>  array('type'=>WS_TYPE_ID),
542        'image_id' =>     array('type'=>WS_TYPE_ID),
[20815]543        ),
[25394]544      'Sets the representative photo for an album. The photo doesn\'t have to belong to the album.',
[25281]545      $ws_functions_root . 'pwg.categories.php',
[25115]546      array('admin_only'=>true, 'post_only'=>true)
[11746]547    );
548
[20817]549  $service->addMethod(
550      'pwg.tags.getAdminList',
551      'ws_tags_getAdminList',
[20815]552      null,
[25115]553      '<b>Admin only.</b>',
[25281]554      $ws_functions_root . 'pwg.tags.php',
[25115]555      array('admin_only'=>true)
[2584]556    );
[2634]557
[25077]558  $service->addMethod( // TODO: create multiple tags
[20817]559      'pwg.tags.add',
560      'ws_tags_add',
[20815]561      array('name'),
[25394]562      'Adds a new tag.',
[25281]563      $ws_functions_root . 'pwg.tags.php',
[25115]564      array('admin_only'=>true)
[2634]565    );
[2683]566
[20817]567  $service->addMethod(
568      'pwg.images.exist',
569      'ws_images_exist',
[20815]570      array(
571        'md5sum_list' =>    array('default'=>null),
572        'filename_list' =>  array('default'=>null),
573        ),
[25394]574      'Checks existence of images.
[25115]575<br>Give <b>md5sum_list</b> if $conf[uniqueness_mode]==md5sum. Give <b>filename_list</b> if $conf[uniqueness_mode]==filename.',
[25281]576      $ws_functions_root . 'pwg.images.php',
[25115]577      array('admin_only'=>true)
[2683]578    );
[2919]579
[20817]580  $service->addMethod(
581      'pwg.images.checkFiles',
582      'ws_images_checkFiles',
[20815]583      array(
[25077]584        'image_id' =>       array('type'=>WS_TYPE_ID),
585        'file_sum' =>       array('default'=>null),
[20815]586        'thumbnail_sum' =>  array('default'=>null),
587        'high_sum' =>       array('default'=>null),
588        ),
[25394]589      'Checks if you have updated version of your files for a given photo, the answer can be "missing", "equals" or "differs".
[25115]590<br>Don\'t use "thumbnail_sum" and "high_sum", these parameters are here for backward compatibility.',
[25281]591      $ws_functions_root . 'pwg.images.php',
[25115]592      array('admin_only'=>true)
[4347]593    );
594
[20817]595  $service->addMethod(
596      'pwg.images.checkUpload',
597      'ws_images_checkUpload',
[20815]598      null,
[25394]599      'Checks if Piwigo is ready for upload.',
[25281]600      $ws_functions_root . 'pwg.images.php',
[25115]601      array('admin_only'=>true)
[6049]602    );
603
[20817]604  $service->addMethod(
605      'pwg.images.setInfo',
606      'ws_images_setInfo',
[20815]607      array(
[25077]608        'image_id' =>       array('type'=>WS_TYPE_ID),
[20815]609        'file' =>           array('default'=>null),
610        'name' =>           array('default'=>null),
611        'author' =>         array('default'=>null),
612        'date_creation' =>  array('default'=>null),
613        'comment' =>        array('default'=>null),
[25077]614        'categories' =>     array('default'=>null,
615                                  'info'=>'String list "category_id[,rank];category_id[,rank]".<br>The rank is optional and is equivalent to "auto" if not given.'),
616        'tag_ids' =>        array('default'=>null,
617                                  'info'=>'Comma separated ids'),
[20815]618        'level' =>          array('default'=>null,
[25077]619                                  'maxValue'=>max($conf['available_permission_levels']),
620                                  'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
[20815]621        'single_value_mode' =>    array('default'=>'fill_if_empty'),
622        'multiple_value_mode' =>  array('default'=>'append'),
[2919]623        ),
[25394]624      'Changes properties of an image.
[20815]625<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"
[25077]626(overwrite any existing value) and applies to single values properties like name/author/date_creation/comment.
[25115]627<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.',
[25281]628      $ws_functions_root . 'pwg.images.php',
[25115]629      array('admin_only'=>true, 'post_only'=>true)
[2919]630    );
[4513]631
[20817]632  $service->addMethod(
633      'pwg.categories.setInfo',
634      'ws_categories_setInfo',
[20815]635      array(
[25077]636        'category_id' =>  array('type'=>WS_TYPE_ID),
[20815]637        'name' =>         array('default'=>null),
638        'comment' =>      array('default'=>null),
639        ),
[25394]640      'Changes properties of an album.',
[25281]641      $ws_functions_root . 'pwg.categories.php',
[25115]642      array('admin_only'=>true, 'post_only'=>true)
[3454]643    );
[8273]644 
[20817]645  $service->addMethod(
646      'pwg.plugins.getList',
647      'ws_plugins_getList',
[20815]648      null,
[25394]649      'Gets the list of plugins with id, name, version, state and description.',
[25281]650      $ws_functions_root . 'pwg.extensions.php',
[25115]651      array('admin_only'=>true)
[8273]652    );
653
[20817]654  $service->addMethod(
655      'pwg.plugins.performAction',
656      'ws_plugins_performAction',
[25077]657      array(
658        'action'    => array('info'=>'install, activate, deactivate, uninstall, delete'),
659        'plugin'    => array(),
660        'pwg_token' => array(),
661        ),
[25394]662      null,
[25281]663      $ws_functions_root . 'pwg.extensions.php',
[25115]664      array('admin_only'=>true)
[8273]665    );
[8309]666
[20817]667  $service->addMethod(
668      'pwg.themes.performAction',
669      'ws_themes_performAction',
[25077]670      array(
671        'action'    => array('info'=>'activate, deactivate, delete, set_default'),
672        'theme'     => array(),
673        'pwg_token' => array(),
674        ),
[25394]675      null,
[25281]676      $ws_functions_root . 'pwg.extensions.php',
[25115]677      array('admin_only'=>true)
[8309]678    );
[10235]679
[20817]680  $service->addMethod(
681      'pwg.extensions.update',
682      'ws_extensions_update',
[25077]683      array(
684        'type' => array('info'=>'plugins, languages, themes'),
685        'id' => array(),
686        'revision' => array(),
687        'pwg_token' => array(),
688        ),
[25115]689      '<b>Webmaster only.</b>',
[25281]690      $ws_functions_root . 'pwg.extensions.php',
[25115]691      array('admin_only'=>true)
[25117]692    );
[10511]693
[20817]694  $service->addMethod(
695      'pwg.extensions.ignoreUpdate',
696      'ws_extensions_ignoreupdate',
[20815]697      array(
[25077]698        'type' =>       array('default'=>null,
699                              'info'=>'plugins, languages, themes'),
[20815]700        'id' =>         array('default'=>null),
[25077]701        'reset' =>      array('default'=>false,
702                              'type'=>WS_TYPE_BOOL,
703                              'info'=>'If true, all ignored extensions will be reinitilized.'),
[20815]704        'pwg_token' =>  array(),
705      ),
[25115]706      '<b>Webmaster only.</b> Ignores an extension if it needs update.',
[25281]707      $ws_functions_root . 'pwg.extensions.php',
[25115]708      array('admin_only'=>true)
[25117]709    );
[10538]710
[20817]711  $service->addMethod(
712      'pwg.extensions.checkUpdates',
713      'ws_extensions_checkupdates',
[20815]714      null,
[25394]715      'Checks if piwigo or extensions are up to date.',
[25281]716      $ws_functions_root . 'pwg.extensions.php',
[25115]717      array('admin_only'=>true)
[25117]718    );
719
720  $service->addMethod(
721      'pwg.groups.getList',
722      'ws_groups_getList',
723      array(
[25118]724        'group_id' => array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
[25117]725                            'type'=>WS_TYPE_ID),
[25118]726        'name' =>     array('flags'=>WS_PARAM_OPTIONAL,
[25117]727                            'info'=>'Use "%" as wildcard.'),
728        'per_page' => array('default'=>100,
729                            'maxValue'=>$conf['ws_max_users_per_page'],
730                            'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
731        'page' =>     array('default'=>0,
732                            'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
733        'order' =>    array('default'=>'name',
734                            'info'=>'id, name, nb_users, is_default'),
735        ),
[25394]736      'Retrieves a list of all groups. The list can be filtered.',
[25281]737      $ws_functions_root . 'pwg.groups.php',
[25117]738      array('admin_only'=>true)
739    );
740
741  $service->addMethod(
742      'pwg.groups.add',
743      'ws_groups_add',
744      array(
745        'name' =>       array(),
746        'is_default' => array('default'=>false,
747                              'type'=>WS_TYPE_BOOL),
748        ),
[25394]749      'Creates a group and returns the new group record.',
[25281]750      $ws_functions_root . 'pwg.groups.php',
[25117]751      array('admin_only'=>true, 'post_only'=>true)
752    );
753
754  $service->addMethod(
755      'pwg.groups.delete',
756      'ws_groups_delete',
757      array(
758        'group_id' => array('flags'=>WS_PARAM_FORCE_ARRAY,
759                            'type'=>WS_TYPE_ID),
[25281]760        'pwg_token' =>  array(),
[25117]761        ),
[25394]762      'Deletes a or more groups. Users and photos are not deleted.',
[25281]763      $ws_functions_root . 'pwg.groups.php',
[25117]764      array('admin_only'=>true, 'post_only'=>true)
765    );
766
767  $service->addMethod(
768      'pwg.groups.setInfo',
769      'ws_groups_setInfo',
770      array(
771        'group_id' =>   array('type'=>WS_TYPE_ID),
[25118]772        'name' =>       array('flags'=>WS_PARAM_OPTIONAL),
773        'is_default' => array('flags'=>WS_PARAM_OPTIONAL,
[25117]774                              'type'=>WS_TYPE_BOOL),
[27810]775        'pwg_token' => array(),
[25117]776        ),
[25394]777      'Updates a group. Leave a field blank to keep the current value.',
[25281]778      $ws_functions_root . 'pwg.groups.php',
[25117]779      array('admin_only'=>true, 'post_only'=>true)
780    );
781
782  $service->addMethod(
783      'pwg.groups.addUser',
784      'ws_groups_addUser',
785      array(
786        'group_id' => array('type'=>WS_TYPE_ID),
787        'user_id' =>  array('flags'=>WS_PARAM_FORCE_ARRAY,
788                            'type'=>WS_TYPE_ID),
[27810]789        'pwg_token' => array(),
[25117]790        ),
[25394]791      'Adds one or more users to a group.',
[25281]792      $ws_functions_root . 'pwg.groups.php',
[25382]793      array('admin_only'=>true, 'post_only'=>true)
[25117]794    );
795
796  $service->addMethod(
797      'pwg.groups.deleteUser',
798      'ws_groups_deleteUser',
799      array(
800        'group_id' => array('type'=>WS_TYPE_ID),
801        'user_id' =>  array('flags'=>WS_PARAM_FORCE_ARRAY,
802                            'type'=>WS_TYPE_ID),
[27810]803        'pwg_token' => array(),
[25117]804        ),
[25394]805      'Removes one or more users from a group.',
[25281]806      $ws_functions_root . 'pwg.groups.php',
[25117]807      array('admin_only'=>true, 'post_only'=>true)
808    );
809
810  $service->addMethod(
811      'pwg.users.getList',
812      'ws_users_getList',
813      array(
[25118]814        'user_id' =>    array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
[25117]815                              'type'=>WS_TYPE_ID),
[25118]816        'username' =>   array('flags'=>WS_PARAM_OPTIONAL,
[25117]817                              'info'=>'Use "%" as wildcard.'),
[25118]818        'status' =>     array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
[25117]819                              'info'=>'guest,generic,normal,admin,webmaster'),
820        'min_level' =>  array('default'=>0,
821                              'maxValue'=>max($conf['available_permission_levels']),
822                              'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
[25118]823        'group_id' =>   array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
[25117]824                              'type'=>WS_TYPE_ID),
825        'per_page' =>   array('default'=>100,
826                              'maxValue'=>$conf['ws_max_users_per_page'],
827                              'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
828        'page' =>       array('default'=>0,
829                              'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
830        'order' =>      array('default'=>'id',
831                              'info'=>'id, username, level, email'),
[25196]832        'display' =>    array('default'=>'basics',
[25472]833                              'info'=>'Comma saparated list (see method description)'),
[25117]834        ),
[25472]835      'Retrieves a list of all the users.<br>
836<br>
837<b>display</b> controls which data are returned, possible values are:<br>
838all, basics, none,<br>
839username, email, status, level, groups,<br>
840language, theme, nb_image_page, recent_period, expand, show_nb_comments, show_nb_hits,<br>
841enabled_high, registration_date, registration_date_string, registration_date_since, last_visit, last_visit_string, last_visit_since<br>
842<b>basics</b> stands for "username,email,status,level,groups"',
[25281]843      $ws_functions_root . 'pwg.users.php',
[25117]844      array('admin_only'=>true)
845    );
846
847  $service->addMethod(
848      'pwg.users.add',
849      'ws_users_add',
850      array(
851        'username' => array(),
852        'password' => array('default'=>null),
[25237]853        'password_confirm' => array('flags'=>WS_PARAM_OPTIONAL),
[25117]854        'email' =>    array('default'=>null),
[25237]855        'send_password_by_mail' => array('default'=>false, 'type'=>WS_TYPE_BOOL),
[27810]856        'pwg_token' => array(),
[25117]857        ),
[25394]858      'Registers a new user.',
[25281]859      $ws_functions_root . 'pwg.users.php',
[25117]860      array('admin_only'=>true, 'post_only'=>true)
861    );
862
863  $service->addMethod(
864      'pwg.users.delete',
865      'ws_users_delete',
866      array(
867        'user_id' =>  array('flags'=>WS_PARAM_FORCE_ARRAY,
868                            'type'=>WS_TYPE_ID),
[25281]869        'pwg_token' =>  array(),
[25117]870        ),
[25394]871      'Deletes on or more users. Photos owned by this user are not deleted.',
[25281]872      $ws_functions_root . 'pwg.users.php',
[25117]873      array('admin_only'=>true, 'post_only'=>true)
874    );
875
876  $service->addMethod(
877      'pwg.users.setInfo',
878      'ws_users_setInfo',
879      array(
[25195]880        'user_id' =>          array('flags'=>WS_PARAM_FORCE_ARRAY,
881                                    'type'=>WS_TYPE_ID),
882        'username' =>         array('flags'=>WS_PARAM_OPTIONAL),
883        'password' =>         array('flags'=>WS_PARAM_OPTIONAL),
884        'email' =>            array('flags'=>WS_PARAM_OPTIONAL),
885        'status' =>           array('flags'=>WS_PARAM_OPTIONAL,
[25196]886                                    'info'=>'guest,generic,normal,admin,webmaster'),
[25195]887        'level'=>             array('flags'=>WS_PARAM_OPTIONAL,
888                                    'maxValue'=>max($conf['available_permission_levels']),
889                                    'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
890        'language' =>         array('flags'=>WS_PARAM_OPTIONAL),
891        'theme' =>            array('flags'=>WS_PARAM_OPTIONAL),
[25474]892        'group_id' => array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY, 'type'=>WS_TYPE_INT),
[25195]893        // bellow are parameters removed in a future version
894        'nb_image_page' =>    array('flags'=>WS_PARAM_OPTIONAL,
895                                    'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE|WS_TYPE_NOTNULL),
896        'recent_period' =>    array('flags'=>WS_PARAM_OPTIONAL,
897                                    'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
898        'expand' =>           array('flags'=>WS_PARAM_OPTIONAL,
899                                    'type'=>WS_TYPE_BOOL),
900        'show_nb_comments' => array('flags'=>WS_PARAM_OPTIONAL,
901                                    'type'=>WS_TYPE_BOOL),
902        'show_nb_hits' =>     array('flags'=>WS_PARAM_OPTIONAL,
903                                    'type'=>WS_TYPE_BOOL),
904        'enabled_high' =>     array('flags'=>WS_PARAM_OPTIONAL,
905                                    'type'=>WS_TYPE_BOOL),
[27810]906        'pwg_token' => array(),
[25117]907        ),
[25394]908      'Updates a user. Leave a field blank to keep the current value.
[25474]909<br>"username", "password" and "email" are ignored if "user_id" is an array.
910<br>set "group_id" to -1 if you want to dissociate users from all groups',
[25281]911      $ws_functions_root . 'pwg.users.php',
[25117]912      array('admin_only'=>true, 'post_only'=>true)
913    );
[25245]914   
915  $service->addMethod(
916      'pwg.permissions.getList',
917      'ws_permissions_getList',
918      array(
919        'cat_id' =>     array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
920                              'type'=>WS_TYPE_ID),
921        'group_id' =>   array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
922                              'type'=>WS_TYPE_ID),
923        'user_id' =>    array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
924                              'type'=>WS_TYPE_ID),
925        ),
[25394]926      'Returns permissions: user ids and group ids having access to each album ; this list can be filtered.
[25246]927<br>Provide only one parameter!',
[25281]928      $ws_functions_root . 'pwg.permissions.php',
[25245]929      array('admin_only'=>true)
930    );
931   
932  $service->addMethod(
933      'pwg.permissions.add',
934      'ws_permissions_add',
935      array(
936        'cat_id' =>     array('flags'=>WS_PARAM_FORCE_ARRAY,
937                              'type'=>WS_TYPE_ID),
938        'group_id' =>   array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
939                              'type'=>WS_TYPE_ID),
940        'user_id' =>    array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
941                              'type'=>WS_TYPE_ID),
942        'recursive' =>  array('default'=>false,
943                              'type'=>WS_TYPE_BOOL),
[27810]944        'pwg_token' => array(),
[25245]945        ),
[25394]946      'Adds permissions to an album.',
[25281]947      $ws_functions_root . 'pwg.permissions.php',
[25382]948      array('admin_only'=>true, 'post_only'=>true)
[25245]949    );
950   
951  $service->addMethod(
952      'pwg.permissions.remove',
953      'ws_permissions_remove',
954      array(
955        'cat_id' =>   array('flags'=>WS_PARAM_FORCE_ARRAY,
956                            'type'=>WS_TYPE_ID),
957        'group_id' => array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
958                            'type'=>WS_TYPE_ID),
959        'user_id' =>  array('flags'=>WS_PARAM_FORCE_ARRAY|WS_PARAM_OPTIONAL,
960                            'type'=>WS_TYPE_ID),
[27810]961        'pwg_token' => array(),
[25245]962        ),
[25394]963      'Removes permissions from an album.',
[25281]964      $ws_functions_root . 'pwg.permissions.php',
[25245]965      array('admin_only'=>true, 'post_only'=>true)
966    );
[1698]967}
968
[25077]969?>
Note: See TracBrowser for help on using the repository browser.