Changeset 12917 for trunk/admin/include


Ignore:
Timestamp:
Jan 17, 2012, 10:02:16 PM (13 years ago)
Author:
rvelices
Message:

feature 2548 multisize - implement delete_element_derivatives

Location:
trunk/admin/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r12906 r12917  
    33// | Piwigo - a PHP based photo gallery                                    |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    176176  }
    177177
    178   include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    179  
    180178  $new_ids = array();
    181179
     
    184182    id,
    185183    path,
    186     tn_ext,
    187     has_high,
    188184    representative_ext
    189185  FROM '.IMAGES_TABLE.'
     
    197193      continue;
    198194    }
    199    
     195
    200196    $files = array();
    201197    $files[] = get_element_path($row);
     
    216212      }
    217213    }
    218    
     214
    219215    if ($ok)
    220216    {
     217      delete_element_derivatives($row);
    221218      $new_ids[] += $row['id'];
    222219    }
     
    389386{
    390387  $orphan_tags = get_orphan_tags();
    391  
     388
    392389  if (count($orphan_tags) > 0)
    393390  {
     
    413410{
    414411  $orphan_tags = array();
    415  
     412
    416413  $query = '
    417414SELECT
     
    13901387    return false;
    13911388  }
    1392  
     1389
    13931390  $query = '
    13941391DELETE
     
    13971394;';
    13981395  pwg_query($query);
    1399  
     1396
    14001397  $query = '
    14011398DELETE
     
    20392036{
    20402037  $result = pwg_query($query);
    2041  
     2038
    20422039  $taglist = array();
    20432040  while ($row = pwg_db_fetch_assoc($result))
     
    20582055      $row['name'] = preg_replace('#\[lang=(.*?)\](.*?)\[/lang\]#is', null, $row['name']);
    20592056    }
    2060    
     2057
    20612058    if (strlen($row['name']) > 0)
    20622059    {
     
    20702067    }
    20712068  }
    2072  
     2069
    20732070  $cmp = create_function('$a,$b', 'return strcasecmp($a["name"], $b["name"]);');
    20742071  usort($taglist, $cmp);
     
    21372134    return;
    21382135  }
    2139  
     2136
    21402137  // make sure categories are private and select uppercats or subcats
    21412138  $cat_ids = (isset($_POST['apply_on_sub'])) ? implode(',', get_subcat_ids($category_ids)).",".implode(',', get_uppercat_ids($category_ids)) : implode(',', get_uppercat_ids($category_ids));
     
    21532150    return;
    21542151  }
    2155  
     2152
    21562153  // We must not reinsert already existing lines in user_access table
    21572154  $granteds = array();
     
    21602157    $granteds[$cat_id] = array();
    21612158  }
    2162  
     2159
    21632160  $query = '
    21642161SELECT
     
    21762173
    21772174  $inserts = array();
    2178  
     2175
    21792176  foreach ($private_cats as $cat_id)
    21802177  {
    21812178    $grant_to_users = array_diff($user_ids, $granteds[$cat_id]);
    2182    
     2179
    21832180    foreach ($grant_to_users as $user_id)
    21842181    {
     
    22082205    $status_list[] = 'webmaster';
    22092206  }
    2210  
     2207
    22112208  $query = '
    22122209SELECT
     
    22462243    $pattern .= derivative_to_url($types[0]);
    22472244  }
    2248  
     2245
    22492246  $pattern.='(_[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{3,4}$#';
    22502247  if ($contents = opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR))
     
    22952292    }
    22962293    closedir($contents);
    2297    
     2294
    22982295    if ($rmdir)
    22992296    {
     
    23092306}
    23102307
    2311 function delete_element_derivatives($ids)
    2312 {
    2313   // todo
    2314   if (!is_array($ids))
    2315   {
    2316     $ids = array($ids);
    2317   }
    2318 
    2319   // for now I do a massive clear, to be removed once the function is
    2320   // properly implemented
    2321   clear_derivative_cache();
     2308function delete_element_derivatives($infos)
     2309{
     2310  $path = $infos['path'];
     2311  if (!empty($infos['representative_ext']))
     2312  {
     2313    $path = original_to_representative( $path, $infos['representative_ext']);
     2314  }
     2315  if (substr_compare($path, '../', 0, 3)==0)
     2316  {
     2317    $path = substr($path, 3);
     2318  }
     2319  $dot = strpos($path, '.');
     2320  $path = substr_replace($path, '-*', $dot, 0);
     2321  foreach( glob(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$path) as $file)
     2322  {
     2323    @unlink($file);
     2324  }
    23222325}
    23232326?>
  • trunk/admin/include/functions_upload.inc.php

    r12907 r12917  
    33// | Piwigo - a PHP based photo gallery                                    |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    3737      'can_be_null' => false,
    3838      ),
    39  
     39
    4040    'original_resize_maxwidth' => array(
    4141      'default' => 2000,
     
    4646      'error_message' => l10n('The original maximum width must be a number between %d and %d'),
    4747      ),
    48  
     48
    4949    'original_resize_maxheight' => array(
    5050      'default' => 2000,
     
    5555      'error_message' => l10n('The original maximum height must be a number between %d and %d'),
    5656      ),
    57  
     57
    5858    'original_resize_quality' => array(
    5959      'default' => 95,
     
    113113      $max = $upload_form_config[$field]['max'];
    114114      $pattern = $upload_form_config[$field]['pattern'];
    115      
     115
    116116      if (preg_match($pattern, $value) and $value >= $min and $value <= $max)
    117117      {
     
    158158  //
    159159  // 3) register in database
    160  
     160
    161161  // TODO
    162162  // * check md5sum (already exists?)
    163  
     163
    164164  global $conf, $user;
    165165
     
    172172    $md5sum = md5_file($source_filepath);
    173173  }
    174  
     174
    175175  $file_path = null;
    176  
     176
    177177  if (isset($image_id))
    178178  {
     
    189189      $file_path = $row['path'];
    190190    }
    191    
     191
    192192    if (!isset($file_path))
    193193    {
     
    201201  {
    202202    // this photo is new
    203    
     203
    204204    // current date
    205205    list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
    206206    list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
    207  
     207
    208208    // upload directory hierarchy
    209209    $upload_dir = sprintf(
     
    251251    {
    252252      $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']);
    253      
     253
    254254      if ($need_resize)
    255255      {
    256256        $img = new pwg_image($file_path);
    257            
     257
    258258        $img->pwg_resize(
    259259          $file_path,
     
    264264          false
    265265          );
    266        
     266
    267267        $img->destroy();
    268268      }
     
    271271
    272272  $file_infos = pwg_image_infos($file_path);
    273  
     273
    274274  if (isset($image_id))
    275275  {
     
    282282      'added_by' => $user['id'],
    283283      );
    284    
     284
    285285    if (isset($level))
    286286    {
     
    293293      array('id' => $image_id)
    294294      );
    295 
    296     delete_element_derivatives($image_id);
    297295  }
    298296  else
     
    309307      'added_by' => $user['id'],
    310308      );
    311    
     309
    312310    if (isset($level))
    313311    {
     
    316314
    317315    single_insert(IMAGES_TABLE, $insert);
    318  
     316
    319317    $image_id = pwg_db_insert_id(IMAGES_TABLE);
    320318  }
     
    327325      );
    328326  }
    329  
     327
    330328  // update metadata from the uploaded file (exif/iptc)
    331329  if ($conf['use_exif'] and !function_exists('read_exif_data'))
     
    375373  // invert width and height.
    376374  list($width, $height) = getimagesize($image_filepath);
    377  
     375
    378376  if ($width > $max_width or $height > $max_height)
    379377  {
     
    388386  list($width, $height) = getimagesize($path);
    389387  $filesize = floor(filesize($path)/1024);
    390  
     388
    391389  return array(
    392390    'width'  => $width,
     
    434432    $size = convert_shorthand_notation_to_bytes($size);
    435433  }
    436  
     434
    437435  return $size;
    438436}
     
    442440  $suffix = substr($value, -1);
    443441  $multiply_by = null;
    444  
     442
    445443  if ('K' == $suffix)
    446444  {
     
    455453    $multiply_by = 1024*1024*1024;
    456454  }
    457  
     455
    458456  if (isset($multiply_by))
    459457  {
     
    500498    {
    501499      @chmod($conf['upload_dir'], 0777);
    502      
     500
    503501      if (!is_writable($conf['upload_dir']))
    504502      {
Note: See TracChangeset for help on using the changeset viewer.