Ignore:
Timestamp:
Sep 11, 2013, 6:44:54 PM (11 years ago)
Author:
mistic100
Message:

new system for shares : password protection, link timeout, management popup + for mails
handle lightbox conflicts
menublock is visible by AMM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/UserCollections/include/ws_functions.inc.php

    r23719 r24421  
    1414      'comment' => array('default' => null),
    1515      'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'),
    16       'public' => array('default' => 0),
    1716      ),
    1817    'Create a new User Collection.'
     
    3433      'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'),
    3534      '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      ),
    3839      'page' => array('default'=>0),
    3940      'order' => array('default'=>'username ASC, name ASC'),
     
    6768    array(
    6869      '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']),
    7071      'page' => array('default'=>0),
    7172      'order' => array('default'=>null),
     
    135136  }
    136137 
    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);
    150141}
    151142
     
    163154  }
    164155 
    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());
    203165  }
    204166}
     
    235197  }
    236198 
    237   // check public
    238   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  
    243199  // search
    244200  $where_clauses = array('1=1');
     
    246202  {
    247203    $where_clauses[] = 'user_id = '.$params['user_id'];
    248   }
    249   if (!empty($params['public']))
    250   {
    251     $where_clauses[] = 'public = '.$params['public'];
    252204  }
    253205  if (!empty($params['name']))
     
    280232      'comment' => $row['comment'],
    281233      'nb_images' => $row['nb_images'],
    282       'public' => (bool)$row['public'],
    283234      'date_creation' => $row['date_creation'],
    284235      'is_temp' => $row['name'] == 'temp',
    285       'u_public' => USER_COLLEC_PUBLIC . 'view/'.$row['public_id'],
    286236      'user_id' => $row['user_id'],
    287237      'username' => $row['username'],
     
    316266    return new PwgError(403, 'Forbidden');
    317267  }
    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());
    335280  }
    336281}
     
    349294  }
    350295 
    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());
    367307  }
    368308}
     
    380320    return new PwgError(403, 'Forbidden');
    381321  }
    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();
    393328    $images = array();
    394329   
     
    451386  catch (Exception $e)
    452387  {
    453     return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');
     388    return new PwgError($e->getCode(), $e->getMessage());
    454389  }
    455390}
     
    467402    return new PwgError(403, 'Forbidden');
    468403  }
    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();
    478408   
    479409    // change encoder to plain text
     
    482412    $service->setEncoder('plain', $encoder);
    483413 
    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());
    489419  }
    490420}
     
    502432    return new PwgError(403, 'Forbidden');
    503433  }
    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());
    519444  }
    520445}
Note: See TracChangeset for help on using the changeset viewer.