source: trunk/ws.php @ 29268

Last change on this file since 29268 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
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', './');
[29250]25define ('IN_WS', true);
[1698]26
27include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
[2325]28check_status(ACCESS_FREE);
[1698]29
[1781]30if ( !$conf['allow_web_services'] )
31{
32  page_forbidden('Web services are disabled');
33}
34
[25281]35include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');
36
[20815]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
[1768]97/**
98 * event handler that registers standard methods with the web service
99 */
[1698]100function ws_addDefaultMethods( $arr )
101{
[1849]102  global $conf, $user;
[1698]103  $service = &$arr[0];
[20815]104 
105  include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
[25281]106  $ws_functions_root = PHPWG_ROOT_PATH.'include/ws_functions/';
[20815]107 
[25077]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 
[20817]129  $service->addMethod(
130      'pwg.getVersion',
131      'ws_getVersion',
[20815]132      null,
[25281]133      'Returns the Piwigo version.',
134      $ws_functions_root . 'pwg.php'
[20815]135    );
[10017]136         
[20817]137  $service->addMethod(
138      'pwg.getInfos',
139      'ws_getInfos',
[20815]140      null,
[25394]141      'Returns general informations.',
[25281]142      $ws_functions_root . 'pwg.php',
[25115]143      array('admin_only'=>true)
[20815]144    );
[1698]145
[20817]146  $service->addMethod(
147      'pwg.caddie.add',
148      'ws_caddie_add',
[2429]149      array(
[25077]150        'image_id'=> array('flags'=>WS_PARAM_FORCE_ARRAY,
151                           'type'=>WS_TYPE_ID),
[20815]152        ),
[25394]153      'Adds elements to the caddie. Returns the number of elements added.',
[25281]154      $ws_functions_root . 'pwg.php',
[25115]155      array('admin_only'=>true)
[20815]156    );
[2429]157
[20817]158  $service->addMethod(
159      'pwg.categories.getImages',
160      'ws_categories_getImages',
[25077]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),
[1698]175      'Returns elements for the corresponding categories.
[25077]176<br><b>cat_id</b> can be empty if <b>recursive</b> is true.
[25281]177<br><b>order</b> comma separated fields for sorting',
178      $ws_functions_root . 'pwg.categories.php'
[1698]179    );
180
[20817]181  $service->addMethod(
182      'pwg.categories.getList',
183      'ws_categories_getList',
[1698]184      array(
[25077]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),
[20815]196        ),
[25281]197      'Returns a list of categories.',
198      $ws_functions_root . 'pwg.categories.php'
[20815]199    );
[1698]200
[20817]201  $service->addMethod(
202      'pwg.getMissingDerivatives',
203      'ws_getMissingDerivatives',
[25077]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),
[25394]216      'Returns a list of derivatives to build.',
[25281]217      $ws_functions_root . 'pwg.php',
[25115]218      array('admin_only'=>true)
[20815]219    );
[12865]220
[20817]221  $service->addMethod(
222      'pwg.images.addComment',
223      'ws_images_addComment',
[1849]224      array(
[25077]225        'image_id' => array('type'=>WS_TYPE_ID),
[20815]226        'author' =>   array('default'=>is_a_guest()?'guest':$user['username']),
227        'content' =>  array(),
228        'key' =>      array(),
229        ),
[25394]230      'Adds a comment to an image.',
[25281]231      $ws_functions_root . 'pwg.images.php',
[25115]232      array('post_only'=>true)
[20815]233    );
[1849]234
[20817]235  $service->addMethod(
236      'pwg.images.getInfo',
237      'ws_images_getInfo',
[1849]238      array(
[25077]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),
[20815]245        ),
[25281]246      'Returns information about an image.',
247      $ws_functions_root . 'pwg.images.php'
[20815]248    );
[1698]249
[20817]250  $service->addMethod(
251      'pwg.images.rate',
252      'ws_images_rate',
[25077]253      array(
254        'image_id' => array('type'=>WS_TYPE_ID),
255        'rate' =>     array('type'=>WS_TYPE_FLOAT),
256      ),
[25281]257      'Rates an image.',
258      $ws_functions_root . 'pwg.images.php'
[20815]259    );
[2435]260
[20817]261  $service->addMethod(
262      'pwg.images.search',
263      'ws_images_search',
[25077]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),
[25281]274      'Returns elements for the corresponding query search.',
275      $ws_functions_root . 'pwg.images.php'
[1837]276    );
[2516]277
[20817]278  $service->addMethod(
279      'pwg.images.setPrivacyLevel',
280      'ws_images_setPrivacyLevel',
[20815]281      array(
[25077]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),
[20815]286        ),
[25394]287      'Sets the privacy levels for the images.',
[25281]288      $ws_functions_root . 'pwg.images.php',
[25115]289      array('admin_only'=>true, 'post_only'=>true)
[2463]290    );
[1837]291
[20817]292  $service->addMethod(
293      'pwg.images.setRank',
294      'ws_images_setRank',
[25077]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        ),
[25394]300      'Sets the rank of a photo for a given album.',
[25281]301      $ws_functions_root . 'pwg.images.php',
[25115]302      array('admin_only'=>true, 'post_only'=>true)
[11372]303    );
[12624]304
[20817]305  $service->addMethod(
306      'pwg.rates.delete',
307      'ws_rates_delete',
[20815]308      array(
[25077]309        'user_id' =>      array('type'=>WS_TYPE_ID),
[20815]310        'anonymous_id' => array('default'=>null),
[26837]311        'image_id' =>     array('flags'=>WS_PARAM_OPTIONAL, 'type'=>WS_TYPE_ID),
[20815]312        ),
[25394]313      'Deletes all rates for a user.',
[25281]314      $ws_functions_root . 'pwg.php',
[25115]315      array('admin_only'=>true, 'post_only'=>true)
[12624]316    );
[20815]317
[20817]318  $service->addMethod(
319      'pwg.session.getStatus',
320      'ws_session_getStatus',
321      null,
[25281]322      'Gets information about the current session. Also provides a token useable with admin methods.',
323      $ws_functions_root . 'pwg.php'
[20817]324    );
[20815]325
[20817]326  $service->addMethod(
327      'pwg.session.login',
328      'ws_session_login',
[20815]329      array('username', 'password'),
[25394]330      'Tries to login the user.',
[25281]331      $ws_functions_root . 'pwg.php',
[25115]332      array('post_only'=>true)
[20815]333    );
334
[20817]335  $service->addMethod(
336      'pwg.session.logout',
337      'ws_session_logout',
338      null,
[25281]339      'Ends the current session.',
340      $ws_functions_root . 'pwg.php'
[20817]341    );
[1698]342
[20817]343  $service->addMethod(
344      'pwg.tags.getList',
345      'ws_tags_getList',
[20815]346      array(
[25077]347        'sort_by_counter' => array('default'=>false,
348                                   'type'=>WS_TYPE_BOOL),
[20815]349        ),
[25281]350      'Retrieves a list of available tags.',
351      $ws_functions_root . 'pwg.tags.php'
[20815]352    );
353
[20817]354  $service->addMethod(
355      'pwg.tags.getImages',
356      'ws_tags_getImages',
[25077]357      array_merge(array(
[20815]358        'tag_id' =>       array('default'=>null,
[25077]359                                'flags'=>WS_PARAM_FORCE_ARRAY,
360                                'type'=>WS_TYPE_ID),
[20815]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),
[25077]365        'tag_mode_and' => array('default'=>false,
366                                'type'=>WS_TYPE_BOOL),
[20815]367        'per_page' =>     array('default'=>100,
[25077]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),
[25281]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'
[1698]377    );
[2463]378
[20817]379  $service->addMethod(
380      'pwg.images.addChunk',
381      'ws_images_add_chunk',
[25077]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        ),
[25394]389      'Add a chunk of a file.',
[25281]390      $ws_functions_root . 'pwg.images.php',
[25115]391      array('admin_only'=>true, 'post_only'=>true)
[3193]392    );
393
[20817]394  $service->addMethod(
395      'pwg.images.addFile',
396      'ws_images_addFile',
[25077]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        ),
[25394]403      'Add or update a file for an existing photo.
[25115]404<br>pwg.images.addChunk must have been called before (maybe several times).',
[25281]405      $ws_functions_root . 'pwg.images.php',
[25115]406      array('admin_only'=>true)
[4348]407    );
408
409
[20817]410  $service->addMethod(
411      'pwg.images.add',
412      'ws_images_add',
[20815]413      array(
414        'thumbnail_sum' =>      array('default'=>null),
415        'high_sum' =>           array('default'=>null),
416        'original_sum' =>       array(),
[25077]417        'original_filename' =>  array('default'=>null,
418                                      'Provide it if "check_uniqueness" is true and $conf["uniqueness_mode"] is "filename".'),
[20815]419        'name' =>               array('default'=>null),
420        'author' =>             array('default'=>null),
421        'date_creation' =>      array('default'=>null),
422        'comment' =>            array('default'=>null),
[25077]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'),
[20815]427        'level' =>              array('default'=>0,
[25077]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),
[2569]434        ),
[25394]435      'Add an image.
[25077]436<br>pwg.images.addChunk must have been called before (maybe several times).
[25115]437<br>Don\'t use "thumbnail_sum" and "high_sum", these parameters are here for backward compatibility.',
[25281]438      $ws_functions_root . 'pwg.images.php',
[25115]439      array('admin_only'=>true)
[2463]440    );
[2563]441
[20817]442  $service->addMethod(
443      'pwg.images.addSimple',
444      'ws_images_addSimple',
[20815]445      array(
[25077]446        'category' => array('default'=>null,
447                            'flags'=>WS_PARAM_FORCE_ARRAY,
448                            'type'=>WS_TYPE_ID),
[20815]449        'name' =>     array('default'=>null),
450        'author' =>   array('default'=>null),
451        'comment' =>  array('default'=>null),
452        'level' =>    array('default'=>0,
[25077]453                            'maxValue'=>max($conf['available_permission_levels']),
454                            'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
[20815]455        'tags' =>     array('default'=>null,
456                            'flags'=>WS_PARAM_ACCEPT_ARRAY),
[25077]457        'image_id' => array('default'=>null,
458                            'type'=>WS_TYPE_ID),
[8249]459        ),
[25394]460      'Add an image.
[25077]461<br>Use the <b>$_FILES[image]</b> field for uploading file.
462<br>Set the form encoding to "form-data".
[25115]463<br>You can update an existing photo if you define an existing image_id.',
[25281]464      $ws_functions_root . 'pwg.images.php',
[25115]465      array('admin_only'=>true, 'post_only'=>true)
[8249]466    );
[8266]467
[20817]468  $service->addMethod(
[28545]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(
[20817]493      'pwg.images.delete',
494      'ws_images_delete',
[20815]495      array(
[25077]496        'image_id' =>   array('flags'=>WS_PARAM_ACCEPT_ARRAY),
[20815]497        'pwg_token' =>  array(),
498        ),
[25394]499      'Deletes image(s).',
[25281]500      $ws_functions_root . 'pwg.images.php',
[25115]501      array('admin_only'=>true, 'post_only'=>true)
[8266]502    );
503
[20817]504  $service->addMethod(
505      'pwg.categories.getAdminList',
506      'ws_categories_getAdminList',
[20815]507      null,
[25394]508      'Get albums list as displayed on admin page.',
[25281]509      $ws_functions_root . 'pwg.categories.php',
[25115]510      array('admin_only'=>true)
[2563]511    );
[2583]512
[20817]513  $service->addMethod(
514      'pwg.categories.add',
515      'ws_categories_add',
[20815]516      array(
517        'name' =>         array(),
[25077]518        'parent' =>       array('default'=>null,
[25264]519                                'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
[20815]520        'comment' =>      array('default'=>null),
[25077]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),
[20815]527        ),
[25394]528      'Adds an album.',
[25281]529      $ws_functions_root . 'pwg.categories.php',
530      array('admin_only'=>true)
[2583]531    );
[2584]532
[20817]533  $service->addMethod(
534      'pwg.categories.delete',
535      'ws_categories_delete',
[20815]536      array(
[25077]537        'category_id'=>           array('flags'=>WS_PARAM_ACCEPT_ARRAY),
538        'photo_deletion_mode' =>  array('default'=>'delete_orphans'),
[20815]539        'pwg_token' =>            array(),
540        ),
[25394]541      'Deletes album(s).
[20815]542<br><b>photo_deletion_mode</b> can be "no_delete" (may create orphan photos), "delete_orphans"
[25115]543(default mode, only deletes photos linked to no other album) or "force_delete" (delete all photos, even those linked to other albums)',
[25281]544      $ws_functions_root . 'pwg.categories.php',
[25115]545      array('admin_only'=>true, 'post_only'=>true)
[8266]546    );
547
[20817]548  $service->addMethod(
549      'pwg.categories.move',
550      'ws_categories_move',
[20815]551      array(
[25077]552        'category_id' =>  array('flags'=>WS_PARAM_ACCEPT_ARRAY),
553        'parent' =>       array('type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
[20815]554        'pwg_token' =>    array(),
555        ),
[25394]556      'Move album(s).
[25115]557<br>Set parent as 0 to move to gallery root. Only virtual categories can be moved.',
[25281]558      $ws_functions_root . 'pwg.categories.php',
[25115]559      array('admin_only'=>true, 'post_only'=>true)
[8272]560    );
[11746]561
[20817]562  $service->addMethod(
563      'pwg.categories.setRepresentative',
564      'ws_categories_setRepresentative',
[20815]565      array(
[25077]566        'category_id' =>  array('type'=>WS_TYPE_ID),
567        'image_id' =>     array('type'=>WS_TYPE_ID),
[20815]568        ),
[25394]569      'Sets the representative photo for an album. The photo doesn\'t have to belong to the album.',
[25281]570      $ws_functions_root . 'pwg.categories.php',
[25115]571      array('admin_only'=>true, 'post_only'=>true)
[11746]572    );
573
[20817]574  $service->addMethod(
575      'pwg.tags.getAdminList',
576      'ws_tags_getAdminList',
[20815]577      null,
[25115]578      '<b>Admin only.</b>',
[25281]579      $ws_functions_root . 'pwg.tags.php',
[25115]580      array('admin_only'=>true)
[2584]581    );
[2634]582
[25077]583  $service->addMethod( // TODO: create multiple tags
[20817]584      'pwg.tags.add',
585      'ws_tags_add',
[20815]586      array('name'),
[25394]587      'Adds a new tag.',
[25281]588      $ws_functions_root . 'pwg.tags.php',
[25115]589      array('admin_only'=>true)
[2634]590    );
[2683]591
[20817]592  $service->addMethod(
593      'pwg.images.exist',
594      'ws_images_exist',
[20815]595      array(
596        'md5sum_list' =>    array('default'=>null),
597        'filename_list' =>  array('default'=>null),
598        ),
[25394]599      'Checks existence of images.
[25115]600<br>Give <b>md5sum_list</b> if $conf[uniqueness_mode]==md5sum. Give <b>filename_list</b> if $conf[uniqueness_mode]==filename.',
[25281]601      $ws_functions_root . 'pwg.images.php',
[25115]602      array('admin_only'=>true)
[2683]603    );
[2919]604
[20817]605  $service->addMethod(
606      'pwg.images.checkFiles',
607      'ws_images_checkFiles',
[20815]608      array(
[25077]609        'image_id' =>       array('type'=>WS_TYPE_ID),
610        'file_sum' =>       array('default'=>null),
[20815]611        'thumbnail_sum' =>  array('default'=>null),
612        'high_sum' =>       array('default'=>null),
613        ),
[25394]614      'Checks if you have updated version of your files for a given photo, the answer can be "missing", "equals" or "differs".
[25115]615<br>Don\'t use "thumbnail_sum" and "high_sum", these parameters are here for backward compatibility.',
[25281]616      $ws_functions_root . 'pwg.images.php',
[25115]617      array('admin_only'=>true)
[4347]618    );
619
[20817]620  $service->addMethod(
621      'pwg.images.checkUpload',
622      'ws_images_checkUpload',
[20815]623      null,
[25394]624      'Checks if Piwigo is ready for upload.',
[25281]625      $ws_functions_root . 'pwg.images.php',
[25115]626      array('admin_only'=>true)
[6049]627    );
628
[20817]629  $service->addMethod(
630      'pwg.images.setInfo',
631      'ws_images_setInfo',
[20815]632      array(
[25077]633        'image_id' =>       array('type'=>WS_TYPE_ID),
[20815]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),
[25077]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'),
[20815]643        'level' =>          array('default'=>null,
[25077]644                                  'maxValue'=>max($conf['available_permission_levels']),
645                                  'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
[20815]646        'single_value_mode' =>    array('default'=>'fill_if_empty'),
647        'multiple_value_mode' =>  array('default'=>'append'),
[2919]648        ),
[25394]649      'Changes properties of an image.
[20815]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"
[25077]651(overwrite any existing value) and applies to single values properties like name/author/date_creation/comment.
[25115]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.',
[25281]653      $ws_functions_root . 'pwg.images.php',
[25115]654      array('admin_only'=>true, 'post_only'=>true)
[2919]655    );
[4513]656
[20817]657  $service->addMethod(
658      'pwg.categories.setInfo',
659      'ws_categories_setInfo',
[20815]660      array(
[25077]661        'category_id' =>  array('type'=>WS_TYPE_ID),
[20815]662        'name' =>         array('default'=>null),
663        'comment' =>      array('default'=>null),
664        ),
[25394]665      'Changes properties of an album.',
[25281]666      $ws_functions_root . 'pwg.categories.php',
[25115]667      array('admin_only'=>true, 'post_only'=>true)
[3454]668    );
[8273]669 
[20817]670  $service->addMethod(
671      'pwg.plugins.getList',
672      'ws_plugins_getList',
[20815]673      null,
[25394]674      'Gets the list of plugins with id, name, version, state and description.',
[25281]675      $ws_functions_root . 'pwg.extensions.php',
[25115]676      array('admin_only'=>true)
[8273]677    );
678
[20817]679  $service->addMethod(
680      'pwg.plugins.performAction',
681      'ws_plugins_performAction',
[25077]682      array(
683        'action'    => array('info'=>'install, activate, deactivate, uninstall, delete'),
684        'plugin'    => array(),
685        'pwg_token' => array(),
686        ),
[25394]687      null,
[25281]688      $ws_functions_root . 'pwg.extensions.php',
[25115]689      array('admin_only'=>true)
[8273]690    );
[8309]691
[20817]692  $service->addMethod(
693      'pwg.themes.performAction',
694      'ws_themes_performAction',
[25077]695      array(
696        'action'    => array('info'=>'activate, deactivate, delete, set_default'),
697        'theme'     => array(),
698        'pwg_token' => array(),
699        ),
[25394]700      null,
[25281]701      $ws_functions_root . 'pwg.extensions.php',
[25115]702      array('admin_only'=>true)
[8309]703    );
[10235]704
[20817]705  $service->addMethod(
706      'pwg.extensions.update',
707      'ws_extensions_update',
[25077]708      array(
709        'type' => array('info'=>'plugins, languages, themes'),
710        'id' => array(),
711        'revision' => array(),
712        'pwg_token' => array(),
713        ),
[25115]714      '<b>Webmaster only.</b>',
[25281]715      $ws_functions_root . 'pwg.extensions.php',
[25115]716      array('admin_only'=>true)
[25117]717    );
[10511]718
[20817]719  $service->addMethod(
720      'pwg.extensions.ignoreUpdate',
721      'ws_extensions_ignoreupdate',
[20815]722      array(
[25077]723        'type' =>       array('default'=>null,
724                              'info'=>'plugins, languages, themes'),
[20815]725        'id' =>         array('default'=>null),
[25077]726        'reset' =>      array('default'=>false,
727                              'type'=>WS_TYPE_BOOL,
728                              'info'=>'If true, all ignored extensions will be reinitilized.'),
[20815]729        'pwg_token' =>  array(),
730      ),
[25115]731      '<b>Webmaster only.</b> Ignores an extension if it needs update.',
[25281]732      $ws_functions_root . 'pwg.extensions.php',
[25115]733      array('admin_only'=>true)
[25117]734    );
[10538]735
[20817]736  $service->addMethod(
737      'pwg.extensions.checkUpdates',
738      'ws_extensions_checkupdates',
[20815]739      null,
[25394]740      'Checks if piwigo or extensions are up to date.',
[25281]741      $ws_functions_root . 'pwg.extensions.php',
[25115]742      array('admin_only'=>true)
[25117]743    );
744
745  $service->addMethod(
746      'pwg.groups.getList',
747      'ws_groups_getList',
748      array(
[25118]749        'group_id' => array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
[25117]750                            'type'=>WS_TYPE_ID),
[25118]751        'name' =>     array('flags'=>WS_PARAM_OPTIONAL,
[25117]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        ),
[25394]761      'Retrieves a list of all groups. The list can be filtered.',
[25281]762      $ws_functions_root . 'pwg.groups.php',
[25117]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        ),
[25394]774      'Creates a group and returns the new group record.',
[25281]775      $ws_functions_root . 'pwg.groups.php',
[25117]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),
[25281]785        'pwg_token' =>  array(),
[25117]786        ),
[25394]787      'Deletes a or more groups. Users and photos are not deleted.',
[25281]788      $ws_functions_root . 'pwg.groups.php',
[25117]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),
[25118]797        'name' =>       array('flags'=>WS_PARAM_OPTIONAL),
798        'is_default' => array('flags'=>WS_PARAM_OPTIONAL,
[25117]799                              'type'=>WS_TYPE_BOOL),
[27811]800        'pwg_token' => array(),
[25117]801        ),
[25394]802      'Updates a group. Leave a field blank to keep the current value.',
[25281]803      $ws_functions_root . 'pwg.groups.php',
[25117]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),
[27811]814        'pwg_token' => array(),
[25117]815        ),
[25394]816      'Adds one or more users to a group.',
[25281]817      $ws_functions_root . 'pwg.groups.php',
[25382]818      array('admin_only'=>true, 'post_only'=>true)
[25117]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),
[27811]828        'pwg_token' => array(),
[25117]829        ),
[25394]830      'Removes one or more users from a group.',
[25281]831      $ws_functions_root . 'pwg.groups.php',
[25117]832      array('admin_only'=>true, 'post_only'=>true)
833    );
834
835  $service->addMethod(
836      'pwg.users.getList',
837      'ws_users_getList',
838      array(
[25118]839        'user_id' =>    array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
[25117]840                              'type'=>WS_TYPE_ID),
[25118]841        'username' =>   array('flags'=>WS_PARAM_OPTIONAL,
[25117]842                              'info'=>'Use "%" as wildcard.'),
[25118]843        'status' =>     array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
[25117]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),
[25118]848        'group_id' =>   array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
[25117]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'),
[25196]857        'display' =>    array('default'=>'basics',
[25472]858                              'info'=>'Comma saparated list (see method description)'),
[25117]859        ),
[25472]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"',
[25281]868      $ws_functions_root . 'pwg.users.php',
[25117]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),
[25237]878        'password_confirm' => array('flags'=>WS_PARAM_OPTIONAL),
[25117]879        'email' =>    array('default'=>null),
[25237]880        'send_password_by_mail' => array('default'=>false, 'type'=>WS_TYPE_BOOL),
[27811]881        'pwg_token' => array(),
[25117]882        ),
[25394]883      'Registers a new user.',
[25281]884      $ws_functions_root . 'pwg.users.php',
[25117]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),
[25281]894        'pwg_token' =>  array(),
[25117]895        ),
[25394]896      'Deletes on or more users. Photos owned by this user are not deleted.',
[25281]897      $ws_functions_root . 'pwg.users.php',
[25117]898      array('admin_only'=>true, 'post_only'=>true)
899    );
900
901  $service->addMethod(
902      'pwg.users.setInfo',
903      'ws_users_setInfo',
904      array(
[25195]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,
[25196]911                                    'info'=>'guest,generic,normal,admin,webmaster'),
[25195]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),
[25474]917        'group_id' => array('flags'=>WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY, 'type'=>WS_TYPE_INT),
[25195]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),
[27811]931        'pwg_token' => array(),
[25117]932        ),
[25394]933      'Updates a user. Leave a field blank to keep the current value.
[25474]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',
[25281]936      $ws_functions_root . 'pwg.users.php',
[25117]937      array('admin_only'=>true, 'post_only'=>true)
938    );
[25245]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        ),
[25394]951      'Returns permissions: user ids and group ids having access to each album ; this list can be filtered.
[25246]952<br>Provide only one parameter!',
[25281]953      $ws_functions_root . 'pwg.permissions.php',
[25245]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),
[27811]969        'pwg_token' => array(),
[25245]970        ),
[25394]971      'Adds permissions to an album.',
[25281]972      $ws_functions_root . 'pwg.permissions.php',
[25382]973      array('admin_only'=>true, 'post_only'=>true)
[25245]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),
[27811]986        'pwg_token' => array(),
[25245]987        ),
[25394]988      'Removes permissions from an album.',
[25281]989      $ws_functions_root . 'pwg.permissions.php',
[25245]990      array('admin_only'=>true, 'post_only'=>true)
991    );
[1698]992}
993
[25077]994?>
Note: See TracBrowser for help on using the repository browser.