Changeset 8266


Ignore:
Timestamp:
12/23/10 21:51:33 (9 years ago)
Author:
plg
Message:

feature 2080 added: add methods pwg.images.delete and pwg.categories.delete from
pwg.images.addSimple plugin. pwg.categories.delete implements the new
photo_deletion_mode (see feature:2081) and set it to "delete_orphans" by default.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r8249 r8266  
    19901990} 
    19911991 
     1992function ws_images_delete($params, &$service) 
     1993{ 
     1994  global $conf; 
     1995  if (!is_admin() || is_adviser() ) 
     1996  { 
     1997    return new PwgError(401, 'Access denied'); 
     1998  } 
     1999 
     2000  if (!$service->isPost()) 
     2001  { 
     2002    return new PwgError(405, "This method requires HTTP POST"); 
     2003  } 
     2004 
     2005  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) 
     2006  { 
     2007    return new PwgError(403, 'Invalid security token'); 
     2008  } 
     2009 
     2010  $params['image_id'] = preg_split( 
     2011    '/[\s,;\|]/', 
     2012    $params['image_id'], 
     2013    -1, 
     2014    PREG_SPLIT_NO_EMPTY 
     2015    ); 
     2016  $params['image_id'] = array_map('intval', $params['image_id']); 
     2017 
     2018  $image_ids = array(); 
     2019  foreach ($params['image_id'] as $image_id) 
     2020  { 
     2021    if ($image_id > 0) 
     2022    { 
     2023      array_push($image_ids, $image_id); 
     2024    } 
     2025  } 
     2026 
     2027  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 
     2028  delete_elements($image_ids, true); 
     2029} 
     2030 
    19922031function ws_add_image_category_relations($image_id, $categories_string, $replace_mode=false) 
    19932032{ 
     
    22022241} 
    22032242 
     2243function ws_categories_delete($params, &$service) 
     2244{ 
     2245  global $conf; 
     2246  if (!is_admin() || is_adviser() ) 
     2247  { 
     2248    return new PwgError(401, 'Access denied'); 
     2249  } 
     2250 
     2251  if (!$service->isPost()) 
     2252  { 
     2253    return new PwgError(405, "This method requires HTTP POST"); 
     2254  } 
     2255 
     2256  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) 
     2257  { 
     2258    return new PwgError(403, 'Invalid security token'); 
     2259  } 
     2260 
     2261  $modes = array('no_delete', 'delete_orphans', 'force_delete'); 
     2262  if (!in_array($params['photo_deletion_mode'], $modes)) 
     2263  { 
     2264    return new PwgError( 
     2265      500, 
     2266      '[ws_categories_delete]' 
     2267      .' invalid parameter photo_deletion_mode "'.$params['photo_deletion_mode'].'"' 
     2268      .', possible values are {'.implode(', ', $modes).'}.' 
     2269      ); 
     2270  } 
     2271 
     2272  $params['category_id'] = preg_split( 
     2273    '/[\s,;\|]/', 
     2274    $params['category_id'], 
     2275    -1, 
     2276    PREG_SPLIT_NO_EMPTY 
     2277    ); 
     2278  $params['category_id'] = array_map('intval', $params['category_id']); 
     2279 
     2280  $category_ids = array(); 
     2281  foreach ($params['category_id'] as $category_id) 
     2282  { 
     2283    if ($category_id > 0) 
     2284    { 
     2285      array_push($category_ids, $category_id); 
     2286    } 
     2287  } 
     2288 
     2289  if (count($category_ids) == 0) 
     2290  { 
     2291    return; 
     2292  } 
     2293 
     2294  $query = ' 
     2295SELECT id 
     2296  FROM '.CATEGORIES_TABLE.' 
     2297  WHERE id IN ('.implode(',', $category_ids).') 
     2298;'; 
     2299  $category_ids = array_from_query($query, 'id'); 
     2300 
     2301  if (count($category_ids) == 0) 
     2302  { 
     2303    return; 
     2304  } 
     2305   
     2306  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 
     2307  delete_categories($category_ids, $params['photo_deletion_mode']); 
     2308  update_global_rank(); 
     2309} 
     2310 
    22042311function ws_logfile($string) 
    22052312{ 
  • trunk/ws.php

    r8249 r8266  
    237237    '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.' 
    238238    ); 
    239    
     239 
     240  $service->addMethod( 
     241    'pwg.images.delete', 
     242    'ws_images_delete', 
     243    array( 
     244      'image_id'=>array('default'=>0), 
     245      'pwg_token' => array('default' => null), 
     246      ), 
     247    'Delete photos. You can give several image_ids, comma separated' 
     248    ); 
     249 
    240250  $service->addMethod( 
    241251    'pwg.categories.getAdminList', 
     
    253263      ), 
    254264    'administration method only' 
     265    ); 
     266 
     267  $service->addMethod( 
     268    'pwg.categories.delete', 
     269    'ws_categories_delete', 
     270    array( 
     271      'category_id'=>array('default'=>0), 
     272      'pwg_token' => array('default' => null), 
     273      'photo_deletion_mode' => array('default' => 'delete_orphans'), 
     274      ), 
     275    'Delete categories. You can give several category_ids, comma separated. 
     276<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)' 
    255277    ); 
    256278 
Note: See TracChangeset for help on using the changeset viewer.