| 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 | |
|---|
| 24 | define ('PHPWG_ROOT_PATH', './'); |
|---|
| 25 | |
|---|
| 26 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
|---|
| 27 | check_status(ACCESS_FREE); |
|---|
| 28 | include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php'); |
|---|
| 29 | |
|---|
| 30 | if ( !$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 | */ |
|---|
| 38 | function 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_max_level' => array( 'default'=> null ), |
|---|
| 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.getMissingDerivatives', 'ws_getMissingDerivatives', |
|---|
| 90 | array( |
|---|
| 91 | 'types' => array( 'default'=>array(), 'flags'=>WS_PARAM_FORCE_ARRAY), |
|---|
| 92 | 'max_urls' => array( 'default' => 200 ), |
|---|
| 93 | 'prev_page' => array( 'default'=> null), |
|---|
| 94 | 'f_min_rate' => array( 'default'=> null ), |
|---|
| 95 | 'f_max_rate' => array( 'default'=> null ), |
|---|
| 96 | 'f_min_hit' => array( 'default'=> null ), |
|---|
| 97 | 'f_max_hit' => array( 'default'=> null ), |
|---|
| 98 | 'f_min_date_available' => array( 'default'=> null ), |
|---|
| 99 | 'f_max_date_available' => array( 'default'=> null ), |
|---|
| 100 | 'f_min_date_created' => array( 'default'=> null ), |
|---|
| 101 | 'f_max_date_created' => array( 'default'=> null ), |
|---|
| 102 | 'f_min_ratio' => array( 'default'=> null ), |
|---|
| 103 | 'f_max_ratio' => array( 'default'=> null ), |
|---|
| 104 | 'f_max_level' => array( 'default'=> null ), |
|---|
| 105 | ), |
|---|
| 106 | 'retrieves a list of derivatives to build' ); |
|---|
| 107 | |
|---|
| 108 | $service->addMethod('pwg.images.addComment', 'ws_images_addComment', |
|---|
| 109 | array( |
|---|
| 110 | 'image_id' => array(), |
|---|
| 111 | 'author' => array( 'default' => is_a_guest()? 'guest':$user['username']), |
|---|
| 112 | 'content' => array(), |
|---|
| 113 | 'key' => array(), |
|---|
| 114 | ), |
|---|
| 115 | 'add a comment to an image' ); |
|---|
| 116 | |
|---|
| 117 | $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo', |
|---|
| 118 | array( |
|---|
| 119 | 'image_id' => array(), |
|---|
| 120 | 'comments_page' => array('default'=>0 ), |
|---|
| 121 | 'comments_per_page' => array( |
|---|
| 122 | 'default' => $conf['nb_comment_page'], |
|---|
| 123 | 'maxValue' => 2*$conf['nb_comment_page'], |
|---|
| 124 | ), |
|---|
| 125 | ), |
|---|
| 126 | 'retrieves information about the given photo' ); |
|---|
| 127 | |
|---|
| 128 | $service->addMethod('pwg.images.rate', 'ws_images_rate', |
|---|
| 129 | array( |
|---|
| 130 | 'image_id' => array(), |
|---|
| 131 | 'rate' => array(), |
|---|
| 132 | ), |
|---|
| 133 | 'rate the image' ); |
|---|
| 134 | |
|---|
| 135 | $service->addMethod('pwg.images.search', 'ws_images_search', |
|---|
| 136 | array( |
|---|
| 137 | 'query'=>array(), |
|---|
| 138 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
|---|
| 139 | 'page' => array('default'=>0), |
|---|
| 140 | 'order' => array('default'=>null), |
|---|
| 141 | 'f_min_rate' => array( 'default'=> null ), |
|---|
| 142 | 'f_max_rate' => array( 'default'=> null ), |
|---|
| 143 | 'f_min_hit' => array( 'default'=> null ), |
|---|
| 144 | 'f_max_hit' => array( 'default'=> null ), |
|---|
| 145 | 'f_min_date_available' => array( 'default'=> null ), |
|---|
| 146 | 'f_max_date_available' => array( 'default'=> null ), |
|---|
| 147 | 'f_min_date_created' => array( 'default'=> null ), |
|---|
| 148 | 'f_max_date_created' => array( 'default'=> null ), |
|---|
| 149 | 'f_min_ratio' => array( 'default'=> null ), |
|---|
| 150 | 'f_max_ratio' => array( 'default'=> null ), |
|---|
| 151 | 'f_max_level' => array( 'default'=> null ), |
|---|
| 152 | ), |
|---|
| 153 | 'Returns elements for the corresponding query search.' |
|---|
| 154 | ); |
|---|
| 155 | |
|---|
| 156 | $service->addMethod( |
|---|
| 157 | 'pwg.images.setPrivacyLevel', |
|---|
| 158 | 'ws_images_setPrivacyLevel', |
|---|
| 159 | array( |
|---|
| 160 | 'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY), |
|---|
| 161 | 'level' => array('maxValue'=>$conf['available_permission_levels']), |
|---|
| 162 | ), |
|---|
| 163 | 'sets the privacy levels for the images (POST method only)' |
|---|
| 164 | ); |
|---|
| 165 | |
|---|
| 166 | $service->addMethod( |
|---|
| 167 | 'pwg.images.setRank', |
|---|
| 168 | 'ws_images_setRank', |
|---|
| 169 | array( |
|---|
| 170 | 'image_id' => array(), |
|---|
| 171 | 'category_id' => array(), |
|---|
| 172 | 'rank' => array(), |
|---|
| 173 | ), |
|---|
| 174 | 'sets the rank of a photo for a given album (POST method only, for admins)' |
|---|
| 175 | ); |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | $service->addMethod('pwg.rates.delete', 'ws_rates_delete', |
|---|
| 179 | array( |
|---|
| 180 | 'user_id' => array(), |
|---|
| 181 | 'anonymous_id' => array( 'default'=>'' ), |
|---|
| 182 | ), |
|---|
| 183 | 'deletes all rates for a user (POST method only, admins only)' |
|---|
| 184 | ); |
|---|
| 185 | |
|---|
| 186 | $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' ); |
|---|
| 187 | $service->addMethod('pwg.session.login', 'ws_session_login', |
|---|
| 188 | array('username', 'password'), |
|---|
| 189 | 'POST method only' ); |
|---|
| 190 | $service->addMethod('pwg.session.logout', 'ws_session_logout', null, ''); |
|---|
| 191 | |
|---|
| 192 | $service->addMethod('pwg.tags.getList', 'ws_tags_getList', |
|---|
| 193 | array('sort_by_counter' => array('default' =>false) ), |
|---|
| 194 | 'retrieves a list of available tags'); |
|---|
| 195 | $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages', |
|---|
| 196 | array( |
|---|
| 197 | 'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
|---|
| 198 | 'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
|---|
| 199 | 'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
|---|
| 200 | 'tag_mode_and'=>array('default'=>false), |
|---|
| 201 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
|---|
| 202 | 'page' => array('default'=>0), |
|---|
| 203 | 'order' => array('default'=>null), |
|---|
| 204 | 'f_min_rate' => array( 'default'=> null ), |
|---|
| 205 | 'f_max_rate' => array( 'default'=> null ), |
|---|
| 206 | 'f_min_hit' => array( 'default'=> null ), |
|---|
| 207 | 'f_max_hit' => array( 'default'=> null ), |
|---|
| 208 | 'f_min_date_available' => array( 'default'=> null ), |
|---|
| 209 | 'f_max_date_available' => array( 'default'=> null ), |
|---|
| 210 | 'f_min_date_created' => array( 'default'=> null ), |
|---|
| 211 | 'f_max_date_created' => array( 'default'=> null ), |
|---|
| 212 | 'f_min_ratio' => array( 'default'=> null ), |
|---|
| 213 | 'f_max_ratio' => array( 'default'=> null ), |
|---|
| 214 | 'f_max_level' => array( 'default'=> null ), |
|---|
| 215 | ), |
|---|
| 216 | 'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. ' |
|---|
| 217 | ); |
|---|
| 218 | |
|---|
| 219 | $service->addMethod( |
|---|
| 220 | 'pwg.images.addChunk', |
|---|
| 221 | 'ws_images_add_chunk', |
|---|
| 222 | array( |
|---|
| 223 | 'data' => array(), |
|---|
| 224 | 'original_sum' => array(), |
|---|
| 225 | 'type' => array(), |
|---|
| 226 | 'position' => array(), |
|---|
| 227 | ), |
|---|
| 228 | 'POST method only. For admin only.' |
|---|
| 229 | ); |
|---|
| 230 | |
|---|
| 231 | $service->addMethod( |
|---|
| 232 | 'pwg.images.addFile', |
|---|
| 233 | 'ws_images_addFile', |
|---|
| 234 | array( |
|---|
| 235 | 'image_id' => array(), |
|---|
| 236 | 'type' => array(), |
|---|
| 237 | 'sum' => array(), |
|---|
| 238 | ), |
|---|
| 239 | 'Add or update a file for an existing photo. pwg.images.addChunk must have been called before (maybe several times)' |
|---|
| 240 | ); |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | $service->addMethod( |
|---|
| 244 | 'pwg.images.add', |
|---|
| 245 | 'ws_images_add', |
|---|
| 246 | array( |
|---|
| 247 | 'file_sum' => array(), |
|---|
| 248 | 'thumbnail_sum' => array('default' => null), |
|---|
| 249 | 'high_sum' => array('default' => null), |
|---|
| 250 | 'original_sum' => array(), |
|---|
| 251 | 'original_filename' => array('default' => null), |
|---|
| 252 | 'name' => array('default' => null), |
|---|
| 253 | 'author' => array('default' => null), |
|---|
| 254 | 'date_creation' => array('default' => null), |
|---|
| 255 | 'comment' => array('default' => null), |
|---|
| 256 | 'categories' => array('default' => null), |
|---|
| 257 | 'tag_ids' => array('default' => null), |
|---|
| 258 | 'level' => array( |
|---|
| 259 | 'default' => 0, |
|---|
| 260 | 'maxValue' => $conf['available_permission_levels'] |
|---|
| 261 | ), |
|---|
| 262 | 'resize' => array('default' => false), |
|---|
| 263 | 'check_uniqueness' => array('default' => true), |
|---|
| 264 | ), |
|---|
| 265 | 'POST method only. |
|---|
| 266 | <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.' |
|---|
| 267 | ); |
|---|
| 268 | |
|---|
| 269 | $service->addMethod( |
|---|
| 270 | 'pwg.images.addSimple', |
|---|
| 271 | 'ws_images_addSimple', |
|---|
| 272 | array( |
|---|
| 273 | 'category' => array('default' => null), |
|---|
| 274 | 'name' => array('default' => null), |
|---|
| 275 | 'author' => array('default' => null), |
|---|
| 276 | 'comment' => array('default' => null), |
|---|
| 277 | 'level' => array( |
|---|
| 278 | 'default' => 0, |
|---|
| 279 | 'maxValue' => $conf['available_permission_levels'] |
|---|
| 280 | ), |
|---|
| 281 | 'tags' => array('default' => null), |
|---|
| 282 | 'image_id' => array('default' => null), |
|---|
| 283 | ), |
|---|
| 284 | '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.' |
|---|
| 285 | ); |
|---|
| 286 | |
|---|
| 287 | $service->addMethod( |
|---|
| 288 | 'pwg.images.delete', |
|---|
| 289 | 'ws_images_delete', |
|---|
| 290 | array( |
|---|
| 291 | 'image_id'=>array('default'=>0), |
|---|
| 292 | 'pwg_token' => array(), |
|---|
| 293 | ), |
|---|
| 294 | 'Delete photos. You can give several image_ids, comma separated' |
|---|
| 295 | ); |
|---|
| 296 | |
|---|
| 297 | $service->addMethod( |
|---|
| 298 | 'pwg.categories.getAdminList', |
|---|
| 299 | 'ws_categories_getAdminList', |
|---|
| 300 | array(), |
|---|
| 301 | 'administration method only' |
|---|
| 302 | ); |
|---|
| 303 | |
|---|
| 304 | $service->addMethod( |
|---|
| 305 | 'pwg.categories.add', |
|---|
| 306 | 'ws_categories_add', |
|---|
| 307 | array( |
|---|
| 308 | 'name' => array(), |
|---|
| 309 | 'parent' => array('default' => null), |
|---|
| 310 | ), |
|---|
| 311 | 'administration method only' |
|---|
| 312 | ); |
|---|
| 313 | |
|---|
| 314 | $service->addMethod( |
|---|
| 315 | 'pwg.categories.delete', |
|---|
| 316 | 'ws_categories_delete', |
|---|
| 317 | array( |
|---|
| 318 | 'category_id'=>array('default'=>0), |
|---|
| 319 | 'pwg_token' => array(), |
|---|
| 320 | 'photo_deletion_mode' => array('default' => 'delete_orphans'), |
|---|
| 321 | ), |
|---|
| 322 | 'Delete categories. You can give several category_ids, comma separated. |
|---|
| 323 | <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)' |
|---|
| 324 | ); |
|---|
| 325 | |
|---|
| 326 | $service->addMethod( |
|---|
| 327 | 'pwg.categories.move', |
|---|
| 328 | 'ws_categories_move', |
|---|
| 329 | array( |
|---|
| 330 | 'category_id'=>array('default'=>0), |
|---|
| 331 | 'parent'=>array('default'=>0), |
|---|
| 332 | 'pwg_token' => array(), |
|---|
| 333 | ), |
|---|
| 334 | '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.' |
|---|
| 335 | ); |
|---|
| 336 | |
|---|
| 337 | $service->addMethod( |
|---|
| 338 | 'pwg.categories.setRepresentative', |
|---|
| 339 | 'ws_categories_setRepresentative', |
|---|
| 340 | array( |
|---|
| 341 | 'category_id'=>array('default'=>0), |
|---|
| 342 | 'image_id'=>array('default'=>0), |
|---|
| 343 | ), |
|---|
| 344 | 'Set the representative photo for an album. The photo doesn\'t have to belong to the album. POST method only. Administration method only.' |
|---|
| 345 | ); |
|---|
| 346 | |
|---|
| 347 | $service->addMethod( |
|---|
| 348 | 'pwg.tags.getAdminList', |
|---|
| 349 | 'ws_tags_getAdminList', |
|---|
| 350 | array(), |
|---|
| 351 | 'administration method only' |
|---|
| 352 | ); |
|---|
| 353 | |
|---|
| 354 | $service->addMethod( |
|---|
| 355 | 'pwg.tags.add', |
|---|
| 356 | 'ws_tags_add', |
|---|
| 357 | array( |
|---|
| 358 | 'name' => array(), |
|---|
| 359 | ), |
|---|
| 360 | 'administration method only' |
|---|
| 361 | ); |
|---|
| 362 | |
|---|
| 363 | $service->addMethod( |
|---|
| 364 | 'pwg.images.exist', |
|---|
| 365 | 'ws_images_exist', |
|---|
| 366 | array( |
|---|
| 367 | 'md5sum_list'=> array('default' => null), |
|---|
| 368 | 'filename_list' => array('default' => null), |
|---|
| 369 | ), |
|---|
| 370 | 'check existence of a photo list' |
|---|
| 371 | ); |
|---|
| 372 | |
|---|
| 373 | $service->addMethod( |
|---|
| 374 | 'pwg.images.checkFiles', |
|---|
| 375 | 'ws_images_checkFiles', |
|---|
| 376 | array( |
|---|
| 377 | 'image_id' => array(), |
|---|
| 378 | 'thumbnail_sum' => array('default' => null), |
|---|
| 379 | 'file_sum' => array('default' => null), |
|---|
| 380 | 'high_sum' => array('default' => null), |
|---|
| 381 | ), |
|---|
| 382 | '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"' |
|---|
| 383 | ); |
|---|
| 384 | |
|---|
| 385 | $service->addMethod( |
|---|
| 386 | 'pwg.images.checkUpload', |
|---|
| 387 | 'ws_images_checkUpload', |
|---|
| 388 | null, |
|---|
| 389 | 'check if Piwigo is ready for upload' |
|---|
| 390 | ); |
|---|
| 391 | |
|---|
| 392 | $service->addMethod( |
|---|
| 393 | 'pwg.images.setInfo', |
|---|
| 394 | 'ws_images_setInfo', |
|---|
| 395 | array( |
|---|
| 396 | 'image_id' => array(), |
|---|
| 397 | |
|---|
| 398 | 'file' => array('default' => null), |
|---|
| 399 | 'name' => array('default' => null), |
|---|
| 400 | 'author' => array('default' => null), |
|---|
| 401 | 'date_creation' => array('default' => null), |
|---|
| 402 | 'comment' => array('default' => null), |
|---|
| 403 | 'categories' => array('default' => null), |
|---|
| 404 | 'tag_ids' => array('default' => null), |
|---|
| 405 | 'level' => array( |
|---|
| 406 | 'default' => null, |
|---|
| 407 | 'maxValue' => $conf['available_permission_levels'] |
|---|
| 408 | ), |
|---|
| 409 | 'single_value_mode' => array('default' => 'fill_if_empty'), |
|---|
| 410 | 'multiple_value_mode' => array('default' => 'append'), |
|---|
| 411 | ), |
|---|
| 412 | 'POST method only. Admin only |
|---|
| 413 | <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. |
|---|
| 414 | <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 |
|---|
| 415 | <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' |
|---|
| 416 | ); |
|---|
| 417 | |
|---|
| 418 | $service->addMethod( |
|---|
| 419 | 'pwg.categories.setInfo', |
|---|
| 420 | 'ws_categories_setInfo', |
|---|
| 421 | array( |
|---|
| 422 | 'category_id' => array(), |
|---|
| 423 | |
|---|
| 424 | 'name' => array('default' => null), |
|---|
| 425 | 'comment' => array('default' => null), |
|---|
| 426 | ), |
|---|
| 427 | 'POST method only.' |
|---|
| 428 | ); |
|---|
| 429 | |
|---|
| 430 | $service->addMethod( |
|---|
| 431 | 'pwg.plugins.getList', |
|---|
| 432 | 'ws_plugins_getList', |
|---|
| 433 | array(), |
|---|
| 434 | 'get the list of plugin with id, name, version, state and description |
|---|
| 435 | <br>administration status required' |
|---|
| 436 | ); |
|---|
| 437 | |
|---|
| 438 | $service->addMethod( |
|---|
| 439 | 'pwg.plugins.performAction', |
|---|
| 440 | 'ws_plugins_performAction', |
|---|
| 441 | array( |
|---|
| 442 | 'action' => array(), |
|---|
| 443 | 'plugin' => array(), |
|---|
| 444 | 'pwg_token' => array(), |
|---|
| 445 | ), |
|---|
| 446 | 'install/activate/deactivate/uninstall/delete a plugin |
|---|
| 447 | <br>administration status required' |
|---|
| 448 | ); |
|---|
| 449 | |
|---|
| 450 | $service->addMethod( |
|---|
| 451 | 'pwg.themes.performAction', |
|---|
| 452 | 'ws_themes_performAction', |
|---|
| 453 | array( |
|---|
| 454 | 'action' => array(), |
|---|
| 455 | 'theme' => array(), |
|---|
| 456 | 'pwg_token' => array(), |
|---|
| 457 | ), |
|---|
| 458 | 'activate/deactivate/delete/set_default a theme<br>administration status required' |
|---|
| 459 | ); |
|---|
| 460 | |
|---|
| 461 | $service->addMethod( |
|---|
| 462 | 'pwg.images.resizeThumbnail', |
|---|
| 463 | 'ws_images_resizethumbnail', |
|---|
| 464 | array( |
|---|
| 465 | 'image_id' => array('default' => null), |
|---|
| 466 | 'image_path' => array('default' => null), |
|---|
| 467 | 'maxwidth' => array('default' => $conf['upload_form_thumb_maxwidth']), |
|---|
| 468 | 'maxheight' => array('default' => $conf['upload_form_thumb_maxheight']), |
|---|
| 469 | 'quality' => array('default' => $conf['upload_form_thumb_quality']), |
|---|
| 470 | 'crop' => array('default' => $conf['upload_form_thumb_crop']), |
|---|
| 471 | 'follow_orientation' => array('default' => $conf['upload_form_thumb_follow_orientation']), |
|---|
| 472 | 'library' => array('default' => $conf['graphics_library']), |
|---|
| 473 | ), |
|---|
| 474 | 'Create/Regenerate thumbnails photo with given arguments. |
|---|
| 475 | <br>One of arguments "image_id" or "image_path" must be sent.' |
|---|
| 476 | ); |
|---|
| 477 | |
|---|
| 478 | $service->addMethod( |
|---|
| 479 | 'pwg.images.resizeWebsize', |
|---|
| 480 | 'ws_images_resizewebsize', |
|---|
| 481 | array( |
|---|
| 482 | 'image_id' => array(), |
|---|
| 483 | 'maxwidth' => array('default' => $conf['upload_form_websize_maxwidth']), |
|---|
| 484 | 'maxheight' => array('default' => $conf['upload_form_websize_maxheight']), |
|---|
| 485 | 'quality' => array('default' => $conf['upload_form_websize_quality']), |
|---|
| 486 | 'automatic_rotation' => array('default' => $conf['upload_form_automatic_rotation']), |
|---|
| 487 | 'library' => array('default' => $conf['graphics_library']), |
|---|
| 488 | ), |
|---|
| 489 | 'Regenerate websize photo with given arguments.' |
|---|
| 490 | ); |
|---|
| 491 | |
|---|
| 492 | $service->addMethod( |
|---|
| 493 | 'pwg.extensions.update', |
|---|
| 494 | 'ws_extensions_update', |
|---|
| 495 | array( |
|---|
| 496 | 'type' => array(), |
|---|
| 497 | 'id' => array(), |
|---|
| 498 | 'revision'=> array(), |
|---|
| 499 | 'pwg_token' => array(), |
|---|
| 500 | ), |
|---|
| 501 | 'Update an extension. Webmaster only. |
|---|
| 502 | <br>Parameter type must be "plugins", "languages" or "themes".' |
|---|
| 503 | ); |
|---|
| 504 | |
|---|
| 505 | $service->addMethod( |
|---|
| 506 | 'pwg.extensions.ignoreUpdate', |
|---|
| 507 | 'ws_extensions_ignoreupdate', |
|---|
| 508 | array( |
|---|
| 509 | 'type' => array('default'=>null), |
|---|
| 510 | 'id' => array('default'=>null), |
|---|
| 511 | 'reset' => array('default'=>null), |
|---|
| 512 | 'pwg_token' => array(), |
|---|
| 513 | ), |
|---|
| 514 | 'Ignore an extension if it need update. |
|---|
| 515 | <br>Parameter type must be "plugins", "languages" or "themes". |
|---|
| 516 | <br>If reset parameter is true, all ignored extensions will be reinitilized.' |
|---|
| 517 | ); |
|---|
| 518 | |
|---|
| 519 | $service->addMethod( |
|---|
| 520 | 'pwg.extensions.checkUpdates', |
|---|
| 521 | 'ws_extensions_checkupdates', |
|---|
| 522 | array(), |
|---|
| 523 | 'Check if piwigo or extensions are up to date.' |
|---|
| 524 | ); |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | add_event_handler('ws_add_methods', 'ws_addDefaultMethods'); |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
|---|
| 531 | |
|---|
| 532 | $requestFormat = 'rest'; |
|---|
| 533 | $responseFormat = null; |
|---|
| 534 | |
|---|
| 535 | if ( isset($_GET['format']) ) |
|---|
| 536 | { |
|---|
| 537 | $responseFormat = $_GET['format']; |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | if ( !isset($responseFormat) and isset($requestFormat) ) |
|---|
| 541 | { |
|---|
| 542 | $responseFormat = $requestFormat; |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | $service = new PwgServer(); |
|---|
| 546 | |
|---|
| 547 | if (!is_null($requestFormat)) |
|---|
| 548 | { |
|---|
| 549 | $handler = null; |
|---|
| 550 | switch ($requestFormat) |
|---|
| 551 | { |
|---|
| 552 | case 'rest': |
|---|
| 553 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php'); |
|---|
| 554 | $handler = new PwgRestRequestHandler(); |
|---|
| 555 | break; |
|---|
| 556 | } |
|---|
| 557 | $service->setHandler($requestFormat, $handler); |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | if (!is_null($responseFormat)) |
|---|
| 561 | { |
|---|
| 562 | $encoder = null; |
|---|
| 563 | switch ($responseFormat) |
|---|
| 564 | { |
|---|
| 565 | case 'rest': |
|---|
| 566 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php'); |
|---|
| 567 | $encoder = new PwgRestEncoder(); |
|---|
| 568 | break; |
|---|
| 569 | case 'php': |
|---|
| 570 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php'); |
|---|
| 571 | $encoder = new PwgSerialPhpEncoder(); |
|---|
| 572 | break; |
|---|
| 573 | case 'json': |
|---|
| 574 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php'); |
|---|
| 575 | $encoder = new PwgJsonEncoder(); |
|---|
| 576 | break; |
|---|
| 577 | case 'xmlrpc': |
|---|
| 578 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php'); |
|---|
| 579 | $encoder = new PwgXmlRpcEncoder(); |
|---|
| 580 | break; |
|---|
| 581 | } |
|---|
| 582 | $service->setEncoder($responseFormat, $encoder); |
|---|
| 583 | } |
|---|
| 584 | |
|---|
| 585 | set_make_full_url(); |
|---|
| 586 | $service->run(); |
|---|
| 587 | |
|---|
| 588 | ?> |
|---|