[1698] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 5 | // | Copyright(C) 2008-2011 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 | |
---|
| 24 | define ('PHPWG_ROOT_PATH', './'); |
---|
| 25 | |
---|
| 26 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
[2325] | 27 | check_status(ACCESS_FREE); |
---|
[1698] | 28 | include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php'); |
---|
| 29 | |
---|
[1781] | 30 | if ( !$conf['allow_web_services'] ) |
---|
| 31 | { |
---|
| 32 | page_forbidden('Web services are disabled'); |
---|
| 33 | } |
---|
| 34 | |
---|
[1768] | 35 | /** |
---|
| 36 | * event handler that registers standard methods with the web service |
---|
| 37 | */ |
---|
[1698] | 38 | function ws_addDefaultMethods( $arr ) |
---|
| 39 | { |
---|
| 40 | include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php'); |
---|
[1849] | 41 | global $conf, $user; |
---|
[1698] | 42 | $service = &$arr[0]; |
---|
| 43 | $service->addMethod('pwg.getVersion', 'ws_getVersion', null, |
---|
| 44 | 'retrieves the PWG version'); |
---|
[10022] | 45 | |
---|
| 46 | $service->addMethod('pwg.getInfos', 'ws_getInfos', null, |
---|
| 47 | 'retrieves general informations'); |
---|
[1698] | 48 | |
---|
[2435] | 49 | $service->addMethod('pwg.caddie.add', 'ws_caddie_add', |
---|
[2429] | 50 | array( |
---|
| 51 | 'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
| 52 | ), |
---|
| 53 | 'adds the elements to the caddie'); |
---|
| 54 | |
---|
[1698] | 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), |
---|
[1781] | 59 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
[1698] | 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. |
---|
[3185] | 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, average_rate,...)' |
---|
[1698] | 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), |
---|
[11152] | 84 | 'tree_output' => array('default'=>false), |
---|
[1698] | 85 | ), |
---|
[11152] | 86 | 'retrieves a list of categories (tree_output option only compatible with json/php output format' ); |
---|
[1698] | 87 | |
---|
[1849] | 88 | $service->addMethod('pwg.images.addComment', 'ws_images_addComment', |
---|
| 89 | array( |
---|
| 90 | 'image_id' => array(), |
---|
[2029] | 91 | 'author' => array( 'default' => is_a_guest()? 'guest':$user['username']), |
---|
[1849] | 92 | 'content' => array(), |
---|
| 93 | 'key' => array(), |
---|
| 94 | ), |
---|
| 95 | 'add a comment to an image' ); |
---|
| 96 | |
---|
[1698] | 97 | $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo', |
---|
[1849] | 98 | array( |
---|
| 99 | 'image_id' => array(), |
---|
| 100 | 'comments_page' => array('default'=>0 ), |
---|
[2435] | 101 | 'comments_per_page' => array( |
---|
| 102 | 'default' => $conf['nb_comment_page'], |
---|
[1849] | 103 | 'maxValue' => 2*$conf['nb_comment_page'], |
---|
| 104 | ), |
---|
| 105 | ), |
---|
[1698] | 106 | 'retrieves information about the given photo' ); |
---|
| 107 | |
---|
[2435] | 108 | $service->addMethod('pwg.images.rate', 'ws_images_rate', |
---|
| 109 | array( |
---|
| 110 | 'image_id' => array(), |
---|
| 111 | 'rate' => array(), |
---|
| 112 | ), |
---|
| 113 | 'rate the image' ); |
---|
| 114 | |
---|
[1837] | 115 | $service->addMethod('pwg.images.search', 'ws_images_search', |
---|
| 116 | array( |
---|
| 117 | 'query'=>array(), |
---|
| 118 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
| 119 | 'page' => array('default'=>0), |
---|
| 120 | 'order' => array('default'=>null), |
---|
| 121 | 'f_min_rate' => array( 'default'=> null ), |
---|
| 122 | 'f_max_rate' => array( 'default'=> null ), |
---|
| 123 | 'f_min_hit' => array( 'default'=> null ), |
---|
| 124 | 'f_max_hit' => array( 'default'=> null ), |
---|
| 125 | 'f_min_date_available' => array( 'default'=> null ), |
---|
| 126 | 'f_max_date_available' => array( 'default'=> null ), |
---|
| 127 | 'f_min_date_created' => array( 'default'=> null ), |
---|
| 128 | 'f_max_date_created' => array( 'default'=> null ), |
---|
| 129 | 'f_min_ratio' => array( 'default'=> null ), |
---|
| 130 | 'f_max_ratio' => array( 'default'=> null ), |
---|
| 131 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
| 132 | ), |
---|
| 133 | 'Returns elements for the corresponding query search.' |
---|
| 134 | ); |
---|
[2516] | 135 | |
---|
[2463] | 136 | $service->addMethod( |
---|
| 137 | 'pwg.images.setPrivacyLevel', |
---|
| 138 | 'ws_images_setPrivacyLevel', |
---|
| 139 | array( |
---|
| 140 | 'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY), |
---|
| 141 | 'level' => array('maxValue'=>$conf['available_permission_levels']), |
---|
[2413] | 142 | ), |
---|
[4513] | 143 | 'sets the privacy levels for the images (POST method only)' |
---|
[2463] | 144 | ); |
---|
[1837] | 145 | |
---|
[11371] | 146 | $service->addMethod( |
---|
| 147 | 'pwg.images.setRank', |
---|
| 148 | 'ws_images_setRank', |
---|
| 149 | array( |
---|
| 150 | 'image_id' => array(), |
---|
| 151 | 'category_id' => array(), |
---|
| 152 | 'rank' => array(), |
---|
| 153 | ), |
---|
| 154 | 'sets the rank of a photo for a given album (POST method only, for admins)' |
---|
| 155 | ); |
---|
| 156 | |
---|
[1698] | 157 | $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' ); |
---|
| 158 | $service->addMethod('pwg.session.login', 'ws_session_login', |
---|
| 159 | array('username', 'password'), |
---|
| 160 | 'POST method only' ); |
---|
| 161 | $service->addMethod('pwg.session.logout', 'ws_session_logout', null, ''); |
---|
| 162 | |
---|
| 163 | $service->addMethod('pwg.tags.getList', 'ws_tags_getList', |
---|
| 164 | array('sort_by_counter' => array('default' =>false) ), |
---|
| 165 | 'retrieves a list of available tags'); |
---|
| 166 | $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages', |
---|
| 167 | array( |
---|
| 168 | 'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
| 169 | 'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
| 170 | 'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
| 171 | 'tag_mode_and'=>array('default'=>false), |
---|
[1781] | 172 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
[1698] | 173 | 'page' => array('default'=>0), |
---|
| 174 | 'order' => array('default'=>null), |
---|
| 175 | 'f_min_rate' => array( 'default'=> null ), |
---|
| 176 | 'f_max_rate' => array( 'default'=> null ), |
---|
| 177 | 'f_min_hit' => array( 'default'=> null ), |
---|
| 178 | 'f_max_hit' => array( 'default'=> null ), |
---|
| 179 | 'f_min_date_available' => array( 'default'=> null ), |
---|
| 180 | 'f_max_date_available' => array( 'default'=> null ), |
---|
| 181 | 'f_min_date_created' => array( 'default'=> null ), |
---|
| 182 | 'f_max_date_created' => array( 'default'=> null ), |
---|
| 183 | 'f_min_ratio' => array( 'default'=> null ), |
---|
| 184 | 'f_max_ratio' => array( 'default'=> null ), |
---|
| 185 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
| 186 | ), |
---|
| 187 | 'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. ' |
---|
| 188 | ); |
---|
[2463] | 189 | |
---|
| 190 | $service->addMethod( |
---|
[3193] | 191 | 'pwg.images.addChunk', |
---|
| 192 | 'ws_images_add_chunk', |
---|
| 193 | array( |
---|
| 194 | 'data' => array(), |
---|
| 195 | 'original_sum' => array(), |
---|
| 196 | 'type' => array(), |
---|
| 197 | 'position' => array(), |
---|
| 198 | ), |
---|
| 199 | 'POST method only. For admin only.' |
---|
| 200 | ); |
---|
| 201 | |
---|
| 202 | $service->addMethod( |
---|
[4348] | 203 | 'pwg.images.addFile', |
---|
| 204 | 'ws_images_addFile', |
---|
| 205 | array( |
---|
| 206 | 'image_id' => array(), |
---|
| 207 | 'type' => array(), |
---|
| 208 | 'sum' => array(), |
---|
| 209 | ), |
---|
| 210 | 'Add or update a file for an existing photo. pwg.images.addChunk must have been called before (maybe several times)' |
---|
| 211 | ); |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | $service->addMethod( |
---|
[2463] | 215 | 'pwg.images.add', |
---|
| 216 | 'ws_images_add', |
---|
| 217 | array( |
---|
[2569] | 218 | 'file_sum' => array(), |
---|
| 219 | 'thumbnail_sum' => array(), |
---|
[2670] | 220 | 'high_sum' => array('default' => null), |
---|
[3065] | 221 | 'original_sum' => array(), |
---|
[4911] | 222 | 'original_filename' => array('default' => null), |
---|
[2569] | 223 | 'name' => array('default' => null), |
---|
| 224 | 'author' => array('default' => null), |
---|
| 225 | 'date_creation' => array('default' => null), |
---|
| 226 | 'comment' => array('default' => null), |
---|
| 227 | 'categories' => array('default' => null), |
---|
| 228 | 'tag_ids' => array('default' => null), |
---|
| 229 | 'level' => array( |
---|
| 230 | 'default' => 0, |
---|
| 231 | 'maxValue' => $conf['available_permission_levels'] |
---|
| 232 | ), |
---|
[2463] | 233 | ), |
---|
[2569] | 234 | 'POST method only. |
---|
[3185] | 235 | <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.' |
---|
[2463] | 236 | ); |
---|
[2563] | 237 | |
---|
| 238 | $service->addMethod( |
---|
[8249] | 239 | 'pwg.images.addSimple', |
---|
| 240 | 'ws_images_addSimple', |
---|
| 241 | array( |
---|
| 242 | 'category' => array('default' => null), |
---|
| 243 | 'name' => array('default' => null), |
---|
| 244 | 'author' => array('default' => null), |
---|
| 245 | 'comment' => array('default' => null), |
---|
| 246 | 'level' => array( |
---|
| 247 | 'default' => 0, |
---|
| 248 | 'maxValue' => $conf['available_permission_levels'] |
---|
| 249 | ), |
---|
| 250 | 'tags' => array('default' => null), |
---|
[9191] | 251 | 'image_id' => array('default' => null), |
---|
[8249] | 252 | ), |
---|
[9191] | 253 | '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.' |
---|
[8249] | 254 | ); |
---|
[8266] | 255 | |
---|
[8249] | 256 | $service->addMethod( |
---|
[8266] | 257 | 'pwg.images.delete', |
---|
| 258 | 'ws_images_delete', |
---|
| 259 | array( |
---|
| 260 | 'image_id'=>array('default'=>0), |
---|
| 261 | 'pwg_token' => array('default' => null), |
---|
| 262 | ), |
---|
| 263 | 'Delete photos. You can give several image_ids, comma separated' |
---|
| 264 | ); |
---|
| 265 | |
---|
| 266 | $service->addMethod( |
---|
[2563] | 267 | 'pwg.categories.getAdminList', |
---|
| 268 | 'ws_categories_getAdminList', |
---|
| 269 | array(), |
---|
| 270 | 'administration method only' |
---|
| 271 | ); |
---|
[2583] | 272 | |
---|
| 273 | $service->addMethod( |
---|
| 274 | 'pwg.categories.add', |
---|
| 275 | 'ws_categories_add', |
---|
| 276 | array( |
---|
| 277 | 'name' => array(), |
---|
| 278 | 'parent' => array('default' => null), |
---|
| 279 | ), |
---|
| 280 | 'administration method only' |
---|
| 281 | ); |
---|
[2584] | 282 | |
---|
| 283 | $service->addMethod( |
---|
[8266] | 284 | 'pwg.categories.delete', |
---|
| 285 | 'ws_categories_delete', |
---|
| 286 | array( |
---|
| 287 | 'category_id'=>array('default'=>0), |
---|
| 288 | 'pwg_token' => array('default' => null), |
---|
| 289 | 'photo_deletion_mode' => array('default' => 'delete_orphans'), |
---|
| 290 | ), |
---|
| 291 | 'Delete categories. You can give several category_ids, comma separated. |
---|
| 292 | <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)' |
---|
| 293 | ); |
---|
| 294 | |
---|
| 295 | $service->addMethod( |
---|
[8272] | 296 | 'pwg.categories.move', |
---|
| 297 | 'ws_categories_move', |
---|
| 298 | array( |
---|
| 299 | 'category_id'=>array('default'=>0), |
---|
| 300 | 'parent'=>array('default'=>0), |
---|
| 301 | 'pwg_token' => array('default' => null), |
---|
| 302 | ), |
---|
| 303 | '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.' |
---|
| 304 | ); |
---|
[11745] | 305 | |
---|
[8272] | 306 | $service->addMethod( |
---|
[11745] | 307 | 'pwg.categories.setRepresentative', |
---|
| 308 | 'ws_categories_setRepresentative', |
---|
| 309 | array( |
---|
| 310 | 'category_id'=>array('default'=>0), |
---|
| 311 | 'image_id'=>array('default'=>0), |
---|
| 312 | ), |
---|
| 313 | 'Set the representative photo for an album. The photo doesn\'t have to belong to the album. POST method only. Administration method only.' |
---|
| 314 | ); |
---|
| 315 | |
---|
| 316 | $service->addMethod( |
---|
[2584] | 317 | 'pwg.tags.getAdminList', |
---|
| 318 | 'ws_tags_getAdminList', |
---|
| 319 | array(), |
---|
| 320 | 'administration method only' |
---|
| 321 | ); |
---|
[2634] | 322 | |
---|
| 323 | $service->addMethod( |
---|
| 324 | 'pwg.tags.add', |
---|
| 325 | 'ws_tags_add', |
---|
| 326 | array( |
---|
| 327 | 'name' => array(), |
---|
| 328 | ), |
---|
| 329 | 'administration method only' |
---|
| 330 | ); |
---|
[2683] | 331 | |
---|
| 332 | $service->addMethod( |
---|
| 333 | 'pwg.images.exist', |
---|
| 334 | 'ws_images_exist', |
---|
| 335 | array( |
---|
[4954] | 336 | 'md5sum_list'=> array('default' => null), |
---|
| 337 | 'filename_list' => array('default' => null), |
---|
[2683] | 338 | ), |
---|
| 339 | 'check existence of a photo list' |
---|
| 340 | ); |
---|
[2919] | 341 | |
---|
| 342 | $service->addMethod( |
---|
[4347] | 343 | 'pwg.images.checkFiles', |
---|
| 344 | 'ws_images_checkFiles', |
---|
| 345 | array( |
---|
| 346 | 'image_id' => array(), |
---|
| 347 | 'thumbnail_sum' => array('default' => null), |
---|
| 348 | 'file_sum' => array('default' => null), |
---|
| 349 | 'high_sum' => array('default' => null), |
---|
| 350 | ), |
---|
| 351 | '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"' |
---|
| 352 | ); |
---|
| 353 | |
---|
| 354 | $service->addMethod( |
---|
[6049] | 355 | 'pwg.images.checkUpload', |
---|
| 356 | 'ws_images_checkUpload', |
---|
| 357 | null, |
---|
| 358 | 'check if Piwigo is ready for upload' |
---|
| 359 | ); |
---|
| 360 | |
---|
| 361 | $service->addMethod( |
---|
[2919] | 362 | 'pwg.images.setInfo', |
---|
| 363 | 'ws_images_setInfo', |
---|
| 364 | array( |
---|
| 365 | 'image_id' => array(), |
---|
[4513] | 366 | |
---|
[2919] | 367 | 'name' => array('default' => null), |
---|
| 368 | 'author' => array('default' => null), |
---|
| 369 | 'date_creation' => array('default' => null), |
---|
| 370 | 'comment' => array('default' => null), |
---|
| 371 | 'categories' => array('default' => null), |
---|
| 372 | 'tag_ids' => array('default' => null), |
---|
| 373 | 'level' => array( |
---|
[11365] | 374 | 'default' => null, |
---|
[2919] | 375 | 'maxValue' => $conf['available_permission_levels'] |
---|
| 376 | ), |
---|
[4460] | 377 | 'single_value_mode' => array('default' => 'fill_if_empty'), |
---|
| 378 | 'multiple_value_mode' => array('default' => 'append'), |
---|
[2919] | 379 | ), |
---|
| 380 | 'POST method only. Admin only |
---|
[4460] | 381 | <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. |
---|
| 382 | <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 |
---|
| 383 | <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' |
---|
[2919] | 384 | ); |
---|
[4513] | 385 | |
---|
[3454] | 386 | $service->addMethod( |
---|
| 387 | 'pwg.categories.setInfo', |
---|
| 388 | 'ws_categories_setInfo', |
---|
| 389 | array( |
---|
| 390 | 'category_id' => array(), |
---|
[4513] | 391 | |
---|
[3454] | 392 | 'name' => array('default' => null), |
---|
| 393 | 'comment' => array('default' => null), |
---|
| 394 | ), |
---|
| 395 | 'POST method only.' |
---|
| 396 | ); |
---|
[8273] | 397 | |
---|
| 398 | $service->addMethod( |
---|
| 399 | 'pwg.plugins.getList', |
---|
| 400 | 'ws_plugins_getList', |
---|
| 401 | array(), |
---|
| 402 | 'get the list of plugin with id, name, version, state and description |
---|
| 403 | <br>administration status required' |
---|
| 404 | ); |
---|
| 405 | |
---|
| 406 | $service->addMethod( |
---|
| 407 | 'pwg.plugins.performAction', |
---|
| 408 | 'ws_plugins_performAction', |
---|
| 409 | array( |
---|
| 410 | 'action' => array('default' => null), |
---|
| 411 | 'plugin' => array('default' => null), |
---|
| 412 | 'pwg_token' => array('default' => null), |
---|
| 413 | ), |
---|
| 414 | 'install/activate/deactivate/uninstall/delete a plugin |
---|
| 415 | <br>administration status required' |
---|
| 416 | ); |
---|
[8309] | 417 | |
---|
| 418 | $service->addMethod( |
---|
| 419 | 'pwg.themes.performAction', |
---|
| 420 | 'ws_themes_performAction', |
---|
| 421 | array( |
---|
| 422 | 'action' => array('default' => null), |
---|
| 423 | 'themes' => array('default' => null), |
---|
| 424 | 'pwg_token' => array('default' => null), |
---|
| 425 | ), |
---|
| 426 | 'activate/deactivate/delete/set_default a theme<br>administration status required' |
---|
| 427 | ); |
---|
[1698] | 428 | } |
---|
| 429 | |
---|
[1768] | 430 | add_event_handler('ws_add_methods', 'ws_addDefaultMethods'); |
---|
[1698] | 431 | |
---|
[1768] | 432 | |
---|
| 433 | add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
| 434 | |
---|
[1698] | 435 | $requestFormat = null; |
---|
| 436 | $responseFormat = null; |
---|
| 437 | |
---|
| 438 | if ( isset($_GET['format']) ) |
---|
| 439 | { |
---|
| 440 | $responseFormat = $_GET['format']; |
---|
| 441 | } |
---|
| 442 | |
---|
| 443 | if ( isset($HTTP_RAW_POST_DATA) ) |
---|
| 444 | { |
---|
| 445 | $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); |
---|
| 446 | if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 ) |
---|
| 447 | { |
---|
| 448 | } |
---|
| 449 | else |
---|
| 450 | { |
---|
| 451 | $requestFormat = "json"; |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | else |
---|
| 455 | { |
---|
| 456 | $requestFormat = "rest"; |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | if ( !isset($responseFormat) and isset($requestFormat) ) |
---|
| 460 | { |
---|
| 461 | $responseFormat = $requestFormat; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | $service = new PwgServer(); |
---|
| 465 | |
---|
| 466 | if (!is_null($requestFormat)) |
---|
| 467 | { |
---|
| 468 | $handler = null; |
---|
| 469 | switch ($requestFormat) |
---|
| 470 | { |
---|
| 471 | case 'rest': |
---|
| 472 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php'); |
---|
| 473 | $handler = new PwgRestRequestHandler(); |
---|
| 474 | break; |
---|
| 475 | } |
---|
| 476 | $service->setHandler($requestFormat, $handler); |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | if (!is_null($responseFormat)) |
---|
| 480 | { |
---|
| 481 | $encoder = null; |
---|
| 482 | switch ($responseFormat) |
---|
| 483 | { |
---|
| 484 | case 'rest': |
---|
| 485 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php'); |
---|
| 486 | $encoder = new PwgRestEncoder(); |
---|
| 487 | break; |
---|
| 488 | case 'php': |
---|
| 489 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php'); |
---|
| 490 | $encoder = new PwgSerialPhpEncoder(); |
---|
| 491 | break; |
---|
| 492 | case 'json': |
---|
| 493 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php'); |
---|
| 494 | $encoder = new PwgJsonEncoder(); |
---|
| 495 | break; |
---|
| 496 | case 'xmlrpc': |
---|
| 497 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php'); |
---|
| 498 | $encoder = new PwgXmlRpcEncoder(); |
---|
| 499 | break; |
---|
| 500 | } |
---|
| 501 | $service->setEncoder($responseFormat, $encoder); |
---|
| 502 | } |
---|
| 503 | |
---|
[1750] | 504 | set_make_full_url(); |
---|
[1698] | 505 | $service->run(); |
---|
| 506 | |
---|
| 507 | ?> |
---|