[1698] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3049] | 5 | // | Copyright(C) 2008-2009 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'); |
---|
| 45 | |
---|
[2435] | 46 | $service->addMethod('pwg.caddie.add', 'ws_caddie_add', |
---|
[2429] | 47 | array( |
---|
| 48 | 'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
| 49 | ), |
---|
| 50 | 'adds the elements to the caddie'); |
---|
| 51 | |
---|
[1698] | 52 | $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages', |
---|
| 53 | array( |
---|
| 54 | 'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY), |
---|
| 55 | 'recursive'=>array('default'=>false), |
---|
[1781] | 56 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
[1698] | 57 | 'page' => array('default'=>0), |
---|
| 58 | 'order' => array('default'=>null), |
---|
| 59 | 'f_min_rate' => array( 'default'=> null ), |
---|
| 60 | 'f_max_rate' => array( 'default'=> null ), |
---|
| 61 | 'f_min_hit' => array( 'default'=> null ), |
---|
| 62 | 'f_max_hit' => array( 'default'=> null ), |
---|
| 63 | 'f_min_date_available' => array( 'default'=> null ), |
---|
| 64 | 'f_max_date_available' => array( 'default'=> null ), |
---|
| 65 | 'f_min_date_created' => array( 'default'=> null ), |
---|
| 66 | 'f_max_date_created' => array( 'default'=> null ), |
---|
| 67 | 'f_min_ratio' => array( 'default'=> null ), |
---|
| 68 | 'f_max_ratio' => array( 'default'=> null ), |
---|
| 69 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
| 70 | ), |
---|
| 71 | 'Returns elements for the corresponding categories. |
---|
[3185] | 72 | <br><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array. |
---|
| 73 | <br><b>order</b> comma separated fields for sorting (file,id, average_rate,...)' |
---|
[1698] | 74 | ); |
---|
| 75 | |
---|
| 76 | $service->addMethod('pwg.categories.getList', 'ws_categories_getList', |
---|
| 77 | array( |
---|
| 78 | 'cat_id' => array('default'=>0), |
---|
| 79 | 'recursive' => array('default'=>false), |
---|
| 80 | 'public' => array('default'=>false), |
---|
| 81 | ), |
---|
| 82 | 'retrieves a list of categories' ); |
---|
| 83 | |
---|
[1849] | 84 | $service->addMethod('pwg.images.addComment', 'ws_images_addComment', |
---|
| 85 | array( |
---|
| 86 | 'image_id' => array(), |
---|
[2029] | 87 | 'author' => array( 'default' => is_a_guest()? 'guest':$user['username']), |
---|
[1849] | 88 | 'content' => array(), |
---|
| 89 | 'key' => array(), |
---|
| 90 | ), |
---|
| 91 | 'add a comment to an image' ); |
---|
| 92 | |
---|
[1698] | 93 | $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo', |
---|
[1849] | 94 | array( |
---|
| 95 | 'image_id' => array(), |
---|
| 96 | 'comments_page' => array('default'=>0 ), |
---|
[2435] | 97 | 'comments_per_page' => array( |
---|
| 98 | 'default' => $conf['nb_comment_page'], |
---|
[1849] | 99 | 'maxValue' => 2*$conf['nb_comment_page'], |
---|
| 100 | ), |
---|
| 101 | ), |
---|
[1698] | 102 | 'retrieves information about the given photo' ); |
---|
| 103 | |
---|
[2435] | 104 | $service->addMethod('pwg.images.rate', 'ws_images_rate', |
---|
| 105 | array( |
---|
| 106 | 'image_id' => array(), |
---|
| 107 | 'rate' => array(), |
---|
| 108 | ), |
---|
| 109 | 'rate the image' ); |
---|
| 110 | |
---|
[1837] | 111 | $service->addMethod('pwg.images.search', 'ws_images_search', |
---|
| 112 | array( |
---|
| 113 | 'query'=>array(), |
---|
| 114 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
| 115 | 'page' => array('default'=>0), |
---|
| 116 | 'order' => array('default'=>null), |
---|
| 117 | 'f_min_rate' => array( 'default'=> null ), |
---|
| 118 | 'f_max_rate' => array( 'default'=> null ), |
---|
| 119 | 'f_min_hit' => array( 'default'=> null ), |
---|
| 120 | 'f_max_hit' => array( 'default'=> null ), |
---|
| 121 | 'f_min_date_available' => array( 'default'=> null ), |
---|
| 122 | 'f_max_date_available' => array( 'default'=> null ), |
---|
| 123 | 'f_min_date_created' => array( 'default'=> null ), |
---|
| 124 | 'f_max_date_created' => array( 'default'=> null ), |
---|
| 125 | 'f_min_ratio' => array( 'default'=> null ), |
---|
| 126 | 'f_max_ratio' => array( 'default'=> null ), |
---|
| 127 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
| 128 | ), |
---|
| 129 | 'Returns elements for the corresponding query search.' |
---|
| 130 | ); |
---|
[2516] | 131 | |
---|
[2463] | 132 | $service->addMethod( |
---|
| 133 | 'pwg.images.setPrivacyLevel', |
---|
| 134 | 'ws_images_setPrivacyLevel', |
---|
| 135 | array( |
---|
| 136 | 'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY), |
---|
| 137 | 'level' => array('maxValue'=>$conf['available_permission_levels']), |
---|
[2413] | 138 | ), |
---|
[2463] | 139 | 'sets the privacy levels for the images' |
---|
| 140 | ); |
---|
[1837] | 141 | |
---|
[1698] | 142 | $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' ); |
---|
| 143 | $service->addMethod('pwg.session.login', 'ws_session_login', |
---|
| 144 | array('username', 'password'), |
---|
| 145 | 'POST method only' ); |
---|
| 146 | $service->addMethod('pwg.session.logout', 'ws_session_logout', null, ''); |
---|
| 147 | |
---|
| 148 | $service->addMethod('pwg.tags.getList', 'ws_tags_getList', |
---|
| 149 | array('sort_by_counter' => array('default' =>false) ), |
---|
| 150 | 'retrieves a list of available tags'); |
---|
| 151 | $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages', |
---|
| 152 | array( |
---|
| 153 | 'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
| 154 | 'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
| 155 | 'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
| 156 | 'tag_mode_and'=>array('default'=>false), |
---|
[1781] | 157 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
[1698] | 158 | 'page' => array('default'=>0), |
---|
| 159 | 'order' => array('default'=>null), |
---|
| 160 | 'f_min_rate' => array( 'default'=> null ), |
---|
| 161 | 'f_max_rate' => array( 'default'=> null ), |
---|
| 162 | 'f_min_hit' => array( 'default'=> null ), |
---|
| 163 | 'f_max_hit' => array( 'default'=> null ), |
---|
| 164 | 'f_min_date_available' => array( 'default'=> null ), |
---|
| 165 | 'f_max_date_available' => array( 'default'=> null ), |
---|
| 166 | 'f_min_date_created' => array( 'default'=> null ), |
---|
| 167 | 'f_max_date_created' => array( 'default'=> null ), |
---|
| 168 | 'f_min_ratio' => array( 'default'=> null ), |
---|
| 169 | 'f_max_ratio' => array( 'default'=> null ), |
---|
| 170 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
| 171 | ), |
---|
| 172 | 'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. ' |
---|
| 173 | ); |
---|
[2463] | 174 | |
---|
| 175 | $service->addMethod( |
---|
[3193] | 176 | 'pwg.images.addChunk', |
---|
| 177 | 'ws_images_add_chunk', |
---|
| 178 | array( |
---|
| 179 | 'data' => array(), |
---|
| 180 | 'original_sum' => array(), |
---|
| 181 | 'type' => array(), |
---|
| 182 | 'position' => array(), |
---|
| 183 | ), |
---|
| 184 | 'POST method only. For admin only.' |
---|
| 185 | ); |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | $service->addMethod( |
---|
[2463] | 189 | 'pwg.images.add', |
---|
| 190 | 'ws_images_add', |
---|
| 191 | array( |
---|
[2569] | 192 | 'file_sum' => array(), |
---|
| 193 | 'thumbnail_sum' => array(), |
---|
[2670] | 194 | 'high_sum' => array('default' => null), |
---|
[3065] | 195 | 'original_sum' => array(), |
---|
[2569] | 196 | 'name' => array('default' => null), |
---|
| 197 | 'author' => array('default' => null), |
---|
| 198 | 'date_creation' => array('default' => null), |
---|
| 199 | 'comment' => array('default' => null), |
---|
| 200 | 'categories' => array('default' => null), |
---|
| 201 | 'tag_ids' => array('default' => null), |
---|
| 202 | 'level' => array( |
---|
| 203 | 'default' => 0, |
---|
| 204 | 'maxValue' => $conf['available_permission_levels'] |
---|
| 205 | ), |
---|
[2463] | 206 | ), |
---|
[2569] | 207 | 'POST method only. |
---|
[3185] | 208 | <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] | 209 | ); |
---|
[2563] | 210 | |
---|
| 211 | $service->addMethod( |
---|
| 212 | 'pwg.categories.getAdminList', |
---|
| 213 | 'ws_categories_getAdminList', |
---|
| 214 | array(), |
---|
| 215 | 'administration method only' |
---|
| 216 | ); |
---|
[2583] | 217 | |
---|
| 218 | $service->addMethod( |
---|
| 219 | 'pwg.categories.add', |
---|
| 220 | 'ws_categories_add', |
---|
| 221 | array( |
---|
| 222 | 'name' => array(), |
---|
| 223 | 'parent' => array('default' => null), |
---|
| 224 | ), |
---|
| 225 | 'administration method only' |
---|
| 226 | ); |
---|
[2584] | 227 | |
---|
| 228 | $service->addMethod( |
---|
| 229 | 'pwg.tags.getAdminList', |
---|
| 230 | 'ws_tags_getAdminList', |
---|
| 231 | array(), |
---|
| 232 | 'administration method only' |
---|
| 233 | ); |
---|
[2634] | 234 | |
---|
| 235 | $service->addMethod( |
---|
| 236 | 'pwg.tags.add', |
---|
| 237 | 'ws_tags_add', |
---|
| 238 | array( |
---|
| 239 | 'name' => array(), |
---|
| 240 | ), |
---|
| 241 | 'administration method only' |
---|
| 242 | ); |
---|
[2683] | 243 | |
---|
| 244 | $service->addMethod( |
---|
| 245 | 'pwg.images.exist', |
---|
| 246 | 'ws_images_exist', |
---|
| 247 | array( |
---|
| 248 | 'md5sum_list'=> array(), |
---|
| 249 | ), |
---|
| 250 | 'check existence of a photo list' |
---|
| 251 | ); |
---|
[2919] | 252 | |
---|
| 253 | $service->addMethod( |
---|
| 254 | 'pwg.images.setInfo', |
---|
| 255 | 'ws_images_setInfo', |
---|
| 256 | array( |
---|
| 257 | 'image_id' => array(), |
---|
| 258 | |
---|
| 259 | 'name' => array('default' => null), |
---|
| 260 | 'author' => array('default' => null), |
---|
| 261 | 'date_creation' => array('default' => null), |
---|
| 262 | 'comment' => array('default' => null), |
---|
| 263 | 'categories' => array('default' => null), |
---|
| 264 | 'tag_ids' => array('default' => null), |
---|
| 265 | 'level' => array( |
---|
| 266 | 'default' => 0, |
---|
| 267 | 'maxValue' => $conf['available_permission_levels'] |
---|
| 268 | ), |
---|
| 269 | ), |
---|
| 270 | 'POST method only. Admin only |
---|
[3185] | 271 | <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.' |
---|
[2919] | 272 | ); |
---|
[3454] | 273 | |
---|
| 274 | $service->addMethod( |
---|
| 275 | 'pwg.categories.setInfo', |
---|
| 276 | 'ws_categories_setInfo', |
---|
| 277 | array( |
---|
| 278 | 'category_id' => array(), |
---|
| 279 | |
---|
| 280 | 'name' => array('default' => null), |
---|
| 281 | 'comment' => array('default' => null), |
---|
| 282 | ), |
---|
| 283 | 'POST method only.' |
---|
| 284 | ); |
---|
[1698] | 285 | } |
---|
| 286 | |
---|
[1768] | 287 | add_event_handler('ws_add_methods', 'ws_addDefaultMethods'); |
---|
[1698] | 288 | |
---|
[1768] | 289 | |
---|
| 290 | add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
| 291 | |
---|
[1698] | 292 | $requestFormat = null; |
---|
| 293 | $responseFormat = null; |
---|
| 294 | |
---|
| 295 | if ( isset($_GET['format']) ) |
---|
| 296 | { |
---|
| 297 | $responseFormat = $_GET['format']; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | if ( isset($HTTP_RAW_POST_DATA) ) |
---|
| 301 | { |
---|
| 302 | $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); |
---|
| 303 | if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 ) |
---|
| 304 | { |
---|
| 305 | } |
---|
| 306 | else |
---|
| 307 | { |
---|
| 308 | $requestFormat = "json"; |
---|
| 309 | } |
---|
| 310 | } |
---|
| 311 | else |
---|
| 312 | { |
---|
| 313 | $requestFormat = "rest"; |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | if ( !isset($responseFormat) and isset($requestFormat) ) |
---|
| 317 | { |
---|
| 318 | $responseFormat = $requestFormat; |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | $service = new PwgServer(); |
---|
| 322 | |
---|
| 323 | if (!is_null($requestFormat)) |
---|
| 324 | { |
---|
| 325 | $handler = null; |
---|
| 326 | switch ($requestFormat) |
---|
| 327 | { |
---|
| 328 | case 'rest': |
---|
| 329 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php'); |
---|
| 330 | $handler = new PwgRestRequestHandler(); |
---|
| 331 | break; |
---|
| 332 | } |
---|
| 333 | $service->setHandler($requestFormat, $handler); |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | if (!is_null($responseFormat)) |
---|
| 337 | { |
---|
| 338 | $encoder = null; |
---|
| 339 | switch ($responseFormat) |
---|
| 340 | { |
---|
| 341 | case 'rest': |
---|
| 342 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php'); |
---|
| 343 | $encoder = new PwgRestEncoder(); |
---|
| 344 | break; |
---|
| 345 | case 'php': |
---|
| 346 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php'); |
---|
| 347 | $encoder = new PwgSerialPhpEncoder(); |
---|
| 348 | break; |
---|
| 349 | case 'json': |
---|
| 350 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php'); |
---|
| 351 | $encoder = new PwgJsonEncoder(); |
---|
| 352 | break; |
---|
| 353 | case 'xmlrpc': |
---|
| 354 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php'); |
---|
| 355 | $encoder = new PwgXmlRpcEncoder(); |
---|
| 356 | break; |
---|
| 357 | } |
---|
| 358 | $service->setEncoder($responseFormat, $encoder); |
---|
| 359 | } |
---|
| 360 | |
---|
[1750] | 361 | set_make_full_url(); |
---|
[1698] | 362 | $service->run(); |
---|
| 363 | |
---|
| 364 | ?> |
---|