source: trunk/ws.php @ 12137

Last change on this file since 12137 was 11962, checked in by plg, 13 years ago

feature 2406 added: if the user wants a new album in the upload form, the album
is created before the start of the upload. The ergonomy is now simpler, the
page is smaller and cleaner.

bug 2373 fixed: now that album is created before upload, uploadify.php gets the
category_id and the level: as soon as it is uploaded (function add_uploaded_file)
the photo gets its final privacy level and is directly associated to the album.
This way, we can have an error on a photo without making orphan all photos of
the same upload group.

feature 2405 added: as soon as a photo is uploaded, its thumbnail is displayed
in the "Uploaded Photos" fieldset, without waiting for other photos to be
uploaded. The latest photos comes first.

I have slighlty changed the integration of colorbox in core. Now we have 2
styles available and by default, we use style2 (overlay in black, title and
control icons outside the popup). It is also used for zooming on bulk manager
in unit mode.

display change: on each uploading photos, instead of showing the transfer
speed, we display the transfer progression in %

bug fixed: the color of the "Start Upload" button was not correct because the
button was not a submit button but a simple type=button.

language: "Upload" button becomes "Start Upload" button.

  • Property svn:eol-style set to LF
File size: 19.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24define ('PHPWG_ROOT_PATH', './');
25
26include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
27check_status(ACCESS_FREE);
28include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');
29
30if ( !$conf['allow_web_services'] )
31{
32  page_forbidden('Web services are disabled');
33}
34
35/**
36 * event handler that registers standard methods with the web service
37 */
38function ws_addDefaultMethods( $arr )
39{
40  include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
41  global $conf, $user;
42  $service = &$arr[0];
43  $service->addMethod('pwg.getVersion', 'ws_getVersion', null,
44      'retrieves the PWG version');
45         
46  $service->addMethod('pwg.getInfos', 'ws_getInfos', null,
47      'retrieves general informations');
48
49  $service->addMethod('pwg.caddie.add', 'ws_caddie_add',
50      array(
51        'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ),
52      ),
53      'adds the elements to the caddie');
54
55  $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages',
56      array(
57        'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY),
58        'recursive'=>array('default'=>false),
59        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
60        'page' => array('default'=>0),
61        'order' => array('default'=>null),
62        'f_min_rate' => array( 'default'=> null ),
63        'f_max_rate' => array( 'default'=> null ),
64        'f_min_hit' => array( 'default'=> null ),
65        'f_max_hit' => array( 'default'=> null ),
66        'f_min_date_available' => array( 'default'=> null ),
67        'f_max_date_available' => array( 'default'=> null ),
68        'f_min_date_created' => array( 'default'=> null ),
69        'f_max_date_created' => array( 'default'=> null ),
70        'f_min_ratio' => array( 'default'=> null ),
71        'f_max_ratio' => array( 'default'=> null ),
72        'f_with_thumbnail' => array( 'default'=> false ),
73      ),
74      'Returns elements for the corresponding categories.
75<br><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array.
76<br><b>order</b> comma separated fields for sorting (file,id, rating_score,...)'
77    );
78
79  $service->addMethod('pwg.categories.getList', 'ws_categories_getList',
80      array(
81        'cat_id' => array('default'=>0),
82        'recursive' => array('default'=>false),
83        'public' => array('default'=>false),
84        'tree_output' => array('default'=>false),
85        'fullname' => array('default'=>false),
86      ),
87      'retrieves a list of categories (tree_output option only compatible with json/php output format' );
88
89  $service->addMethod('pwg.images.addComment', 'ws_images_addComment',
90      array(
91        'image_id' => array(),
92        'author' => array( 'default' => is_a_guest()? 'guest':$user['username']),
93        'content' => array(),
94        'key' => array(),
95      ),
96      'add a comment to an image' );
97
98  $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo',
99      array(
100        'image_id' => array(),
101        'comments_page' => array('default'=>0 ),
102        'comments_per_page' => array(
103              'default' => $conf['nb_comment_page'],
104              'maxValue' => 2*$conf['nb_comment_page'],
105            ),
106      ),
107      'retrieves information about the given photo' );
108
109  $service->addMethod('pwg.images.rate', 'ws_images_rate',
110      array(
111        'image_id' => array(),
112        'rate' =>     array(),
113      ),
114      'rate the image' );
115
116  $service->addMethod('pwg.images.search', 'ws_images_search',
117      array(
118        'query'=>array(),
119        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
120        'page' => array('default'=>0),
121        'order' => array('default'=>null),
122        'f_min_rate' => array( 'default'=> null ),
123        'f_max_rate' => array( 'default'=> null ),
124        'f_min_hit' => array( 'default'=> null ),
125        'f_max_hit' => array( 'default'=> null ),
126        'f_min_date_available' => array( 'default'=> null ),
127        'f_max_date_available' => array( 'default'=> null ),
128        'f_min_date_created' => array( 'default'=> null ),
129        'f_max_date_created' => array( 'default'=> null ),
130        'f_min_ratio' => array( 'default'=> null ),
131        'f_max_ratio' => array( 'default'=> null ),
132        'f_with_thumbnail' => array( 'default'=> false ),
133      ),
134      'Returns elements for the corresponding query search.'
135    );
136
137  $service->addMethod(
138    'pwg.images.setPrivacyLevel',
139    'ws_images_setPrivacyLevel',
140    array(
141      'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY),
142      'level' => array('maxValue'=>$conf['available_permission_levels']),
143      ),
144    'sets the privacy levels for the images (POST method only)'
145    );
146
147  $service->addMethod(
148    'pwg.images.setRank',
149    'ws_images_setRank',
150    array(
151      'image_id' => array(),
152      'category_id' => array(),
153      'rank' => array(),
154      ),
155    'sets the rank of a photo for a given album (POST method only, for admins)'
156    );
157 
158  $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' );
159  $service->addMethod('pwg.session.login', 'ws_session_login',
160    array('username', 'password'),
161    'POST method only' );
162  $service->addMethod('pwg.session.logout', 'ws_session_logout', null, '');
163
164  $service->addMethod('pwg.tags.getList', 'ws_tags_getList',
165    array('sort_by_counter' => array('default' =>false) ),
166    'retrieves a list of available tags');
167  $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages',
168      array(
169        'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
170        'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
171        'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
172        'tag_mode_and'=>array('default'=>false),
173        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
174        'page' => array('default'=>0),
175        'order' => array('default'=>null),
176        'f_min_rate' => array( 'default'=> null ),
177        'f_max_rate' => array( 'default'=> null ),
178        'f_min_hit' => array( 'default'=> null ),
179        'f_max_hit' => array( 'default'=> null ),
180        'f_min_date_available' => array( 'default'=> null ),
181        'f_max_date_available' => array( 'default'=> null ),
182        'f_min_date_created' => array( 'default'=> null ),
183        'f_max_date_created' => array( 'default'=> null ),
184        'f_min_ratio' => array( 'default'=> null ),
185        'f_max_ratio' => array( 'default'=> null ),
186        'f_with_thumbnail' => array( 'default'=> false ),
187      ),
188      'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
189    );
190
191  $service->addMethod(
192    'pwg.images.addChunk',
193    'ws_images_add_chunk',
194    array(
195      'data' => array(),
196      'original_sum' => array(),
197      'type' => array(),
198      'position' => array(),
199      ),
200    'POST method only. For admin only.'
201    );
202
203  $service->addMethod(
204    'pwg.images.addFile',
205    'ws_images_addFile',
206    array(
207      'image_id' => array(),
208      'type' => array(),
209      'sum' => array(),
210      ),
211    'Add or update a file for an existing photo. pwg.images.addChunk must have been called  before (maybe several times)'
212    );
213
214
215  $service->addMethod(
216    'pwg.images.add',
217    'ws_images_add',
218    array(
219      'file_sum' => array(),
220      'thumbnail_sum' => array(),
221      'high_sum' => array('default' => null),
222      'original_sum' => array(),
223      'original_filename' => array('default' => null),
224      'name' => array('default' => null),
225      'author' => array('default' => null),
226      'date_creation' => array('default' => null),
227      'comment' => array('default' => null),
228      'categories' => array('default' => null),
229      'tag_ids' => array('default' => null),
230      'level' => array(
231        'default' => 0,
232        'maxValue' => $conf['available_permission_levels']
233        ),
234      ),
235    'POST method only.
236<br><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.'
237    );
238
239  $service->addMethod(
240    'pwg.images.addSimple',
241    'ws_images_addSimple',
242    array(
243      'category' => array('default' => null),
244      'name' => array('default' => null),
245      'author' => array('default' => null),
246      'comment' => array('default' => null),
247      'level' => array(
248        'default' => 0,
249        'maxValue' => $conf['available_permission_levels']
250        ),
251      'tags' => array('default' => null),
252      'image_id' => array('default' => null),
253      ),
254    'POST method only.<br>Use the <b>image</b> field for uploading file.<br>Set the form encoding to "form-data"<br><b>category</b> is the numeric identifier of the destination category.<br>You can update an existing photo if you define an existing image_id.'
255    );
256
257  $service->addMethod(
258    'pwg.images.delete',
259    'ws_images_delete',
260    array(
261      'image_id'=>array('default'=>0),
262      'pwg_token' => array(),
263      ),
264    'Delete photos. You can give several image_ids, comma separated'
265    );
266
267  $service->addMethod(
268    'pwg.categories.getAdminList',
269    'ws_categories_getAdminList',
270    array(),
271    'administration method only'
272    );
273
274  $service->addMethod(
275    'pwg.categories.add',
276    'ws_categories_add',
277    array(
278      'name' => array(),
279      'parent' => array('default' => null),
280      ),
281    'administration method only'
282    );
283
284  $service->addMethod(
285    'pwg.categories.delete',
286    'ws_categories_delete',
287    array(
288      'category_id'=>array('default'=>0),
289      'pwg_token' => array(),
290      'photo_deletion_mode' => array('default' => 'delete_orphans'),
291      ),
292    'Delete categories. You can give several category_ids, comma separated.
293<br><b>photo_deletion_mode</b> can be "no_delete" (may create orphan photos), "delete_orphans" (default mode, only deletes photos linked to no other album) or "force_delete" (delete all photos, even those linked to other albums)'
294    );
295
296  $service->addMethod(
297    'pwg.categories.move',
298    'ws_categories_move',
299    array(
300      'category_id'=>array('default'=>0),
301      'parent'=>array('default'=>0),
302      'pwg_token' => array(),
303      ),
304    'Move categories. You can give several category_ids, comma separated. Set parent as 0 to move to gallery root. Only virtual categories can be moved.'
305    );
306
307  $service->addMethod(
308    'pwg.categories.setRepresentative',
309    'ws_categories_setRepresentative',
310    array(
311      'category_id'=>array('default'=>0),
312      'image_id'=>array('default'=>0),
313      ),
314    'Set the representative photo for an album. The photo doesn\'t have to belong to the album. POST method only. Administration method only.'
315    );
316
317  $service->addMethod(
318    'pwg.tags.getAdminList',
319    'ws_tags_getAdminList',
320    array(),
321    'administration method only'
322    );
323
324  $service->addMethod(
325    'pwg.tags.add',
326    'ws_tags_add',
327    array(
328      'name' => array(),
329      ),
330    'administration method only'
331    );
332
333  $service->addMethod(
334    'pwg.images.exist',
335    'ws_images_exist',
336    array(
337      'md5sum_list'=> array('default' => null),
338      'filename_list' => array('default' => null),
339      ),
340    'check existence of a photo list'
341    );
342
343  $service->addMethod(
344    'pwg.images.checkFiles',
345    'ws_images_checkFiles',
346    array(
347      'image_id' => array(),
348      'thumbnail_sum' => array('default' => null),
349      'file_sum' => array('default' => null),
350      'high_sum' => array('default' => null),
351      ),
352    'check if you have updated version of your files for a given photo, for each requested file type, the answer can be "missing", "equals" or "differs"'
353    );
354
355  $service->addMethod(
356    'pwg.images.checkUpload',
357    'ws_images_checkUpload',
358    null,
359    'check if Piwigo is ready for upload'
360    );
361
362  $service->addMethod(
363    'pwg.images.setInfo',
364    'ws_images_setInfo',
365    array(
366      'image_id' => array(),
367
368      'name' => array('default' => null),
369      'author' => array('default' => null),
370      'date_creation' => array('default' => null),
371      'comment' => array('default' => null),
372      'categories' => array('default' => null),
373      'tag_ids' => array('default' => null),
374      'level' => array(
375        'default' => null,
376        'maxValue' => $conf['available_permission_levels']
377        ),
378      'single_value_mode' => array('default' => 'fill_if_empty'),
379      'multiple_value_mode' => array('default' => 'append'),
380      ),
381    'POST method only. Admin only
382<br><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.
383<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" (overwrite any existing value) and applies to single values properties like name/author/date_creation/comment
384<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'
385    );
386
387  $service->addMethod(
388    'pwg.categories.setInfo',
389    'ws_categories_setInfo',
390    array(
391      'category_id' => array(),
392
393      'name' => array('default' => null),
394      'comment' => array('default' => null),
395      ),
396    'POST method only.'
397    );
398 
399  $service->addMethod(
400    'pwg.plugins.getList',
401    'ws_plugins_getList',
402    array(),
403    'get the list of plugin with id, name, version, state and description
404<br>administration status required'
405    );
406
407  $service->addMethod(
408    'pwg.plugins.performAction',
409    'ws_plugins_performAction',
410    array(
411      'action' => array(),
412      'plugin' => array(),
413      'pwg_token' => array(),
414      ),
415    'install/activate/deactivate/uninstall/delete a plugin
416<br>administration status required'
417    );
418
419  $service->addMethod(
420    'pwg.themes.performAction',
421    'ws_themes_performAction',
422    array(
423      'action' => array(),
424      'theme' => array(),
425      'pwg_token' => array(),
426      ),
427    'activate/deactivate/delete/set_default a theme<br>administration status required'
428    );
429
430  $service->addMethod(
431    'pwg.images.resizeThumbnail',
432    'ws_images_resizethumbnail',
433    array(
434      'image_id' => array('default' => null),
435      'image_path' => array('default' => null),
436      'maxwidth' => array('default' => $conf['upload_form_thumb_maxwidth']),
437      'maxheight' => array('default' => $conf['upload_form_thumb_maxheight']),
438      'quality' => array('default' => $conf['upload_form_thumb_quality']),
439      'crop' => array('default' => $conf['upload_form_thumb_crop']),
440      'follow_orientation' => array('default' => $conf['upload_form_thumb_follow_orientation']),
441      'library' => array('default' => $conf['graphics_library']),
442    ),
443    'Create/Regenerate thumbnails photo with given arguments.
444<br>One of arguments "image_id" or "image_path" must be sent.'
445  );
446
447  $service->addMethod(
448    'pwg.images.resizeWebsize',
449    'ws_images_resizewebsize',
450    array(
451      'image_id' => array(),
452      'maxwidth' => array('default' => $conf['upload_form_websize_maxwidth']),
453      'maxheight' => array('default' => $conf['upload_form_websize_maxheight']),
454      'quality' => array('default' => $conf['upload_form_websize_quality']),
455      'automatic_rotation' => array('default' => $conf['upload_form_automatic_rotation']),
456      'library' => array('default' => $conf['graphics_library']),
457    ),
458    'Regenerate websize photo with given arguments.'
459  );
460
461  $service->addMethod(
462    'pwg.extensions.update',
463    'ws_extensions_update',
464    array(
465      'type' => array(),
466      'id' => array(),
467      'revision'=> array(),
468      'pwg_token' => array(),
469    ),
470    'Update an extension. Webmaster only.
471<br>Parameter type must be "plugins", "languages" or "themes".'
472  );
473
474  $service->addMethod(
475    'pwg.extensions.ignoreUpdate',
476    'ws_extensions_ignoreupdate',
477    array(
478      'type' => array('default'=>null),
479      'id' => array('default'=>null),
480      'reset' => array('default'=>null),
481      'pwg_token' => array(),
482    ),
483    'Ignore an extension if it need update.
484<br>Parameter type must be "plugins", "languages" or "themes".
485<br>If reset parameter is true, all ignored extensions will be reinitilized.'
486  );
487
488  $service->addMethod(
489    'pwg.extensions.checkUpdates',
490    'ws_extensions_checkupdates',
491    array(),
492    'Check if piwigo or extensions are up to date.'
493  );
494}
495
496add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
497
498
499add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
500
501$requestFormat = null;
502$responseFormat = null;
503
504if ( isset($_GET['format']) )
505{
506  $responseFormat = $_GET['format'];
507}
508
509if ( isset($HTTP_RAW_POST_DATA) )
510{
511  $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
512  if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 )
513  {
514  }
515  else
516  {
517    $requestFormat = "json";
518  }
519}
520else
521{
522  $requestFormat = "rest";
523}
524
525if ( !isset($responseFormat) and isset($requestFormat) )
526{
527  $responseFormat = $requestFormat;
528}
529
530$service = new PwgServer();
531
532if (!is_null($requestFormat))
533{
534  $handler = null;
535  switch ($requestFormat)
536  {
537    case 'rest':
538      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
539      $handler = new PwgRestRequestHandler();
540      break;
541  }
542  $service->setHandler($requestFormat, $handler);
543}
544
545if (!is_null($responseFormat))
546{
547  $encoder = null;
548  switch ($responseFormat)
549  {
550    case 'rest':
551      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
552      $encoder = new PwgRestEncoder();
553      break;
554    case 'php':
555      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
556      $encoder = new PwgSerialPhpEncoder();
557      break;
558    case 'json':
559      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
560      $encoder = new PwgJsonEncoder();
561      break;
562    case 'xmlrpc':
563      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
564      $encoder = new PwgXmlRpcEncoder();
565      break;
566  }
567  $service->setEncoder($responseFormat, $encoder);
568}
569
570set_make_full_url();
571$service->run();
572
573?>
Note: See TracBrowser for help on using the repository browser.