Changeset 24421 for extensions/UserCollections/include/ws_functions.inc.php
- Timestamp:
- Sep 11, 2013, 6:44:54 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/UserCollections/include/ws_functions.inc.php
r23719 r24421 14 14 'comment' => array('default' => null), 15 15 'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'), 16 'public' => array('default' => 0),17 16 ), 18 17 'Create a new User Collection.' … … 34 33 'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'), 35 34 'name' => array('default' => null), 36 'public' => array('default' => null), 37 'per_page' => array('default'=>100, 'maxValue'=>ceil($conf['ws_max_images_per_page']/10)), 35 'per_page' => array( 36 'default'=>min(100,ceil($conf['ws_max_images_per_page']/10)), 37 'maxValue'=>ceil($conf['ws_max_images_per_page']/10) 38 ), 38 39 'page' => array('default'=>0), 39 40 'order' => array('default'=>'username ASC, name ASC'), … … 67 68 array( 68 69 'col_id' => array(), 69 'per_page' => array('default'=> 100, 'maxValue'=>$conf['ws_max_images_per_page']),70 'per_page' => array('default'=>min(100,$conf['ws_max_images_per_page']), 'maxValue'=>$conf['ws_max_images_per_page']), 70 71 'page' => array('default'=>0), 71 72 'order' => array('default'=>null), … … 135 136 } 136 137 137 // check public 138 if ($params['public'] != 0 and $params['public'] != 1) 139 { 140 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid "public" value, 0 or 1.'); 141 } 142 if (!$conf['user_collections']['allow_public']) 143 { 144 $params['public'] = 0; 145 } 146 147 $UserCollection = new UserCollection('new', $params['name'], $params['comment'], $params['public'], $params['user_id']); 148 149 return array_change_key_case($UserCollection->getCollectionInfo(), CASE_LOWER); 138 $collection = new UserCollection('new', $params['name'], $params['comment'], $params['user_id']); 139 140 return array_change_key_case($collection->getCollectionInfo(), CASE_LOWER); 150 141 } 151 142 … … 163 154 } 164 155 165 // check collection id 166 if (!preg_match('#^[0-9]+$#', $params['col_id'])) 167 { 168 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 169 } 170 171 $query = ' 172 SELECT user_id 173 FROM '.COLLECTIONS_TABLE.' 174 WHERE id = '.$params['col_id'].' 175 ;'; 176 $result = pwg_query($query); 177 178 if (!pwg_db_num_rows($result)) 179 { 180 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 181 } 182 else 183 { 184 // check owner 185 list($user_id) = pwg_db_fetch_row($result); 186 187 if (!is_admin() and $user_id != $user['id']) 188 { 189 return new PwgError(403, 'Forbidden'); 190 } 191 192 // delete 193 $query = ' 194 DELETE ci, c 195 FROM '.COLLECTION_IMAGES_TABLE.' AS ci 196 RIGHT JOIN '.COLLECTIONS_TABLE.' AS c 197 ON ci.col_id = c.id 198 WHERE 199 c.user_id = '.$user_id.' 200 AND c.id = '.$params['col_id'].' 201 ;'; 202 pwg_query($query); 156 try { 157 $collection = new UserCollection($params['col_id']); 158 $collection->checkUser(); 159 160 $collection->delete(); 161 } 162 catch (Exception $e) 163 { 164 return new PwgError($e->getCode(), $e->getMessage()); 203 165 } 204 166 } … … 235 197 } 236 198 237 // check public238 if ( !empty($params['public']) and $params['public'] != 0 and $params['public'] != 1 )239 {240 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid "public" value, 0 or 1.');241 }242 243 199 // search 244 200 $where_clauses = array('1=1'); … … 246 202 { 247 203 $where_clauses[] = 'user_id = '.$params['user_id']; 248 }249 if (!empty($params['public']))250 {251 $where_clauses[] = 'public = '.$params['public'];252 204 } 253 205 if (!empty($params['name'])) … … 280 232 'comment' => $row['comment'], 281 233 'nb_images' => $row['nb_images'], 282 'public' => (bool)$row['public'],283 234 'date_creation' => $row['date_creation'], 284 235 'is_temp' => $row['name'] == 'temp', 285 'u_public' => USER_COLLEC_PUBLIC . 'view/'.$row['public_id'],286 236 'user_id' => $row['user_id'], 287 237 'username' => $row['username'], … … 316 266 return new PwgError(403, 'Forbidden'); 317 267 } 318 319 // check collection id 320 if (!preg_match('#^[0-9]+$#', $params['col_id'])) 321 { 322 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 323 } 324 325 try { 326 $UserCollection = new UserCollection($params['col_id']); 327 328 $UserCollection->addImages($params['image_ids']); 329 330 return array('nb_images' => $UserCollection->getParam('nb_images')); 331 } 332 catch (Exception $e) 333 { 334 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 268 269 try { 270 $collection = new UserCollection($params['col_id']); 271 $collection->checkUser(); 272 273 $collection->addImages($params['image_ids']); 274 275 return array('nb_images' => $collection->getParam('nb_images')); 276 } 277 catch (Exception $e) 278 { 279 return new PwgError($e->getCode(), $e->getMessage()); 335 280 } 336 281 } … … 349 294 } 350 295 351 // check collection id 352 if (!preg_match('#^[0-9]+$#', $params['col_id'])) 353 { 354 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 355 } 356 357 try { 358 $UserCollection = new UserCollection($params['col_id']); 359 360 $UserCollection->removeImages($params['image_ids']); 361 362 return array('nb_images' => $UserCollection->getParam('nb_images')); 363 } 364 catch (Exception $e) 365 { 366 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 296 try { 297 $collection = new UserCollection($params['col_id']); 298 $collection->checkUser(); 299 300 $collection->removeImages($params['image_ids']); 301 302 return array('nb_images' => $collection->getParam('nb_images')); 303 } 304 catch (Exception $e) 305 { 306 return new PwgError($e->getCode(), $e->getMessage()); 367 307 } 368 308 } … … 380 320 return new PwgError(403, 'Forbidden'); 381 321 } 382 383 // check collection id 384 if (!preg_match('#^[0-9]+$#', $params['col_id'])) 385 { 386 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 387 } 388 389 try { 390 $UserCollection = new UserCollection($params['col_id']); 391 392 $image_ids = $UserCollection->getImages(); 322 323 try { 324 $collection = new UserCollection($params['col_id']); 325 $collection->checkUser(); 326 327 $image_ids = $collection->getImages(); 393 328 $images = array(); 394 329 … … 451 386 catch (Exception $e) 452 387 { 453 return new PwgError( WS_ERR_INVALID_PARAM, 'Invalid collection id');388 return new PwgError($e->getCode(), $e->getMessage()); 454 389 } 455 390 } … … 467 402 return new PwgError(403, 'Forbidden'); 468 403 } 469 470 // check collection id 471 if (!preg_match('#^[0-9]+$#', $params['col_id'])) 472 { 473 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 474 } 475 476 try { 477 $UserCollection = new UserCollection($params['col_id']); 404 405 try { 406 $collection = new UserCollection($params['col_id']); 407 $collection->checkUser(); 478 408 479 409 // change encoder to plain text … … 482 412 $service->setEncoder('plain', $encoder); 483 413 484 return $ UserCollection->serialize($params['content']);485 } 486 catch (Exception $e) 487 { 488 return new PwgError( WS_ERR_INVALID_PARAM, 'Invalid collection id');414 return $collection->serialize($params['content']); 415 } 416 catch (Exception $e) 417 { 418 return new PwgError($e->getCode(), $e->getMessage()); 489 419 } 490 420 } … … 502 432 return new PwgError(403, 'Forbidden'); 503 433 } 504 505 // check collection id 506 if (!preg_match('#^[0-9]+$#', $params['col_id'])) 507 { 508 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 509 } 510 511 try { 512 $UserCollection = new UserCollection($params['col_id']); 513 514 return array_change_key_case($UserCollection->getCollectionInfo(), CASE_LOWER); 515 } 516 catch (Exception $e) 517 { 518 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 434 435 try { 436 $collection = new UserCollection($params['col_id']); 437 $collection->checkUser(); 438 439 return array_change_key_case($collection->getCollectionInfo(), CASE_LOWER); 440 } 441 catch (Exception $e) 442 { 443 return new PwgError($e->getCode(), $e->getMessage()); 519 444 } 520 445 }
Note: See TracChangeset
for help on using the changeset viewer.