Index: extensions/UserCollections/include/ws_functions.inc.php
===================================================================
--- extensions/UserCollections/include/ws_functions.inc.php	(revision 23719)
+++ extensions/UserCollections/include/ws_functions.inc.php	(revision 24421)
@@ -14,5 +14,4 @@
       'comment' => array('default' => null),
       'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'),
-      'public' => array('default' => 0),
       ),
     'Create a new User Collection.'
@@ -34,6 +33,8 @@
       'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'),
       'name' => array('default' => null),
-      'public' => array('default' => null),
-      'per_page' => array('default'=>100, 'maxValue'=>ceil($conf['ws_max_images_per_page']/10)),
+      'per_page' => array(
+        'default'=>min(100,ceil($conf['ws_max_images_per_page']/10)),
+        'maxValue'=>ceil($conf['ws_max_images_per_page']/10)
+      ),
       'page' => array('default'=>0),
       'order' => array('default'=>'username ASC, name ASC'),
@@ -67,5 +68,5 @@
     array(
       'col_id' => array(),
-      'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
+      'per_page' => array('default'=>min(100,$conf['ws_max_images_per_page']), 'maxValue'=>$conf['ws_max_images_per_page']),
       'page' => array('default'=>0),
       'order' => array('default'=>null),
@@ -135,17 +136,7 @@
   }
   
-  // check public
-  if ($params['public'] != 0 and $params['public'] != 1)
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid "public" value, 0 or 1.');
-  }
-  if (!$conf['user_collections']['allow_public'])
-  {
-    $params['public'] = 0;
-  }
-  
-  $UserCollection = new UserCollection('new', $params['name'], $params['comment'], $params['public'], $params['user_id']);
-  
-  return array_change_key_case($UserCollection->getCollectionInfo(), CASE_LOWER);
+  $collection = new UserCollection('new', $params['name'], $params['comment'], $params['user_id']);
+  
+  return array_change_key_case($collection->getCollectionInfo(), CASE_LOWER);
 }
 
@@ -163,42 +154,13 @@
   }
   
-  // check collection id
-  if (!preg_match('#^[0-9]+$#', $params['col_id']))
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
-  }
-  
-  $query = '
-SELECT user_id
-  FROM '.COLLECTIONS_TABLE.'
-  WHERE id = '.$params['col_id'].'
-;';
-  $result = pwg_query($query);
-  
-  if (!pwg_db_num_rows($result))
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
-  }
-  else
-  {
-    // check owner
-    list($user_id) = pwg_db_fetch_row($result);
-    
-    if (!is_admin() and $user_id != $user['id'])
-    {
-      return new PwgError(403, 'Forbidden');
-    }
-    
-    // delete
-    $query = '
-DELETE ci, c
-  FROM '.COLLECTION_IMAGES_TABLE.' AS ci
-    RIGHT JOIN '.COLLECTIONS_TABLE.' AS c 
-    ON ci.col_id = c.id
-  WHERE
-    c.user_id = '.$user_id.'
-    AND c.id = '.$params['col_id'].'
-;';
-    pwg_query($query);
+  try {
+    $collection = new UserCollection($params['col_id']);
+    $collection->checkUser();
+    
+    $collection->delete();
+  }
+  catch (Exception $e)
+  {
+    return new PwgError($e->getCode(), $e->getMessage());
   }
 }
@@ -235,10 +197,4 @@
   }
   
-  // check public
-  if ( !empty($params['public']) and $params['public'] != 0 and $params['public'] != 1 )
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid "public" value, 0 or 1.');
-  }
-  
   // search
   $where_clauses = array('1=1');
@@ -246,8 +202,4 @@
   {
     $where_clauses[] = 'user_id = '.$params['user_id'];
-  }
-  if (!empty($params['public']))
-  {
-    $where_clauses[] = 'public = '.$params['public'];
   }
   if (!empty($params['name']))
@@ -280,8 +232,6 @@
       'comment' => $row['comment'],
       'nb_images' => $row['nb_images'],
-      'public' => (bool)$row['public'],
       'date_creation' => $row['date_creation'],
       'is_temp' => $row['name'] == 'temp',
-      'u_public' => USER_COLLEC_PUBLIC . 'view/'.$row['public_id'],
       'user_id' => $row['user_id'],
       'username' => $row['username'],
@@ -316,21 +266,16 @@
     return new PwgError(403, 'Forbidden');
   }
-  
-  // check collection id
-  if (!preg_match('#^[0-9]+$#', $params['col_id']))
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
-  }
-
-  try {
-    $UserCollection = new UserCollection($params['col_id']);
-    
-    $UserCollection->addImages($params['image_ids']);
-    
-    return array('nb_images' => $UserCollection->getParam('nb_images'));
-  }
-  catch (Exception $e)
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
+
+  try {
+    $collection = new UserCollection($params['col_id']);
+    $collection->checkUser();
+    
+    $collection->addImages($params['image_ids']);
+    
+    return array('nb_images' => $collection->getParam('nb_images'));
+  }
+  catch (Exception $e)
+  {
+    return new PwgError($e->getCode(), $e->getMessage());
   }
 }
@@ -349,20 +294,15 @@
   }
   
-  // check collection id
-  if (!preg_match('#^[0-9]+$#', $params['col_id']))
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
-  }
-
-  try {
-    $UserCollection = new UserCollection($params['col_id']);
-    
-    $UserCollection->removeImages($params['image_ids']);
-    
-    return array('nb_images' => $UserCollection->getParam('nb_images'));
-  }
-  catch (Exception $e)
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
+  try {
+    $collection = new UserCollection($params['col_id']);
+    $collection->checkUser();
+    
+    $collection->removeImages($params['image_ids']);
+    
+    return array('nb_images' => $collection->getParam('nb_images'));
+  }
+  catch (Exception $e)
+  {
+    return new PwgError($e->getCode(), $e->getMessage());
   }
 }
@@ -380,15 +320,10 @@
     return new PwgError(403, 'Forbidden');
   }
-  
-  // check collection id
-  if (!preg_match('#^[0-9]+$#', $params['col_id']))
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
-  }
-
-  try {
-    $UserCollection = new UserCollection($params['col_id']);
-    
-    $image_ids = $UserCollection->getImages();
+
+  try {
+    $collection = new UserCollection($params['col_id']);
+    $collection->checkUser();
+    
+    $image_ids = $collection->getImages();
     $images = array();
     
@@ -451,5 +386,5 @@
   catch (Exception $e)
   {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
+    return new PwgError($e->getCode(), $e->getMessage());
   }
 }
@@ -467,13 +402,8 @@
     return new PwgError(403, 'Forbidden');
   }
-  
-  // check collection id
-  if (!preg_match('#^[0-9]+$#', $params['col_id']))
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
-  }
-
-  try {
-    $UserCollection = new UserCollection($params['col_id']);
+
+  try {
+    $collection = new UserCollection($params['col_id']);
+    $collection->checkUser();
     
     // change encoder to plain text
@@ -482,9 +412,9 @@
     $service->setEncoder('plain', $encoder);
   
-    return $UserCollection->serialize($params['content']);
-  }
-  catch (Exception $e)
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
+    return $collection->serialize($params['content']);
+  }
+  catch (Exception $e)
+  {
+    return new PwgError($e->getCode(), $e->getMessage());
   }
 }
@@ -502,19 +432,14 @@
     return new PwgError(403, 'Forbidden');
   }
-  
-  // check collection id
-  if (!preg_match('#^[0-9]+$#', $params['col_id']))
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
-  }
-
-  try {
-    $UserCollection = new UserCollection($params['col_id']);
-  
-    return array_change_key_case($UserCollection->getCollectionInfo(), CASE_LOWER);
-  }
-  catch (Exception $e)
-  {
-    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
+
+  try {
+    $collection = new UserCollection($params['col_id']);
+    $collection->checkUser();
+  
+    return array_change_key_case($collection->getCollectionInfo(), CASE_LOWER);
+  }
+  catch (Exception $e)
+  {
+    return new PwgError($e->getCode(), $e->getMessage());
   }
 }
