Changeset 9191 for trunk/admin/include
- Timestamp:
- Feb 11, 2011, 11:57:23 PM (13 years ago)
- Location:
- trunk/admin/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r8967 r9191 167 167 } 168 168 169 // The function delete_elements deletes the elements identified by the 170 // (numeric) values of the array $ids. It also deletes (in the database) : 171 // - all the comments related to elements 172 // - all the links between categories and elements 173 // - all the favorites associated to elements 174 // @return number of deleted elements 175 function delete_elements($ids, $physical_deletion=false) 169 // Deletes all files (on disk) related to given image ids 170 // @return image ids where files are deleted successfully 171 function delete_element_files($ids) 176 172 { 177 173 if (count($ids) == 0) … … 179 175 return 0; 180 176 } 181 trigger_action('begin_delete_elements', $ids); 182 183 if ($physical_deletion) 184 { 185 include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 186 $new_ids=array(); 187 188 $query = ' 177 178 include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 179 180 $new_ids = array(); 181 182 $query = ' 189 183 SELECT 190 184 id, … … 196 190 WHERE id IN ('.implode(',', $ids).') 197 191 ;'; 198 $result = pwg_query($query); 199 while ($row = pwg_db_fetch_assoc($result)) 200 { 201 if (url_is_remote($row['path'])) 202 continue; 203 $files = array(); 204 $files[] = get_element_path($row); 205 if (!empty($row['tn_ext'])) 206 $files[] = get_thumbnail_path($row); 207 if (!empty($row['has_high']) and get_boolean($row['has_high'])) 208 $files[] = get_high_path($row); 209 if (!empty($row['representative_ext'])) 192 $result = pwg_query($query); 193 while ($row = pwg_db_fetch_assoc($result)) 194 { 195 if (url_is_remote($row['path'])) 196 { 197 continue; 198 } 199 200 $files = array(); 201 $files[] = get_element_path($row); 202 203 if (!empty($row['tn_ext'])) 204 { 205 $files[] = get_thumbnail_path($row); 206 } 207 208 if (!empty($row['has_high']) and get_boolean($row['has_high'])) 209 { 210 $files[] = get_high_path($row); 211 } 212 213 if (!empty($row['representative_ext'])) 214 { 215 $pi = pathinfo($row['path']); 216 $file_wo_ext = get_filename_wo_extension($pi['basename']); 217 $files[] = PHPWG_ROOT_PATH.$pi['dirname'].'/pwg_representative/'.$file_wo_ext.'.'.$row['representative_ext']; 218 } 219 220 $ok = true; 221 foreach ($files as $path) 222 { 223 if (is_file($path) and !unlink($path)) 210 224 { 211 $ pi = pathinfo($row['path']);212 $file_wo_ext = get_filename_wo_extension($pi['basename']);213 $files[] = PHPWG_ROOT_PATH.$pi['dirname'].'/pwg_representative/'.$file_wo_ext.'.'.$element_info['representative_ext'];225 $ok = false; 226 trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING); 227 break; 214 228 } 215 216 $ok = true; 217 foreach ($files as $path) 218 { 219 if (is_file($path) and !unlink($path)) 220 { 221 $ok = false; 222 trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING); 223 break; 224 } 225 } 226 if ($ok) 227 $new_ids[] += $row['id']; 228 else 229 break; 230 } 231 $ids = $new_ids; 229 } 230 231 if ($ok) 232 { 233 $new_ids[] += $row['id']; 234 } 235 else 236 { 237 break; 238 } 239 } 240 return $new_ids; 241 } 242 243 // The function delete_elements deletes the elements identified by the 244 // (numeric) values of the array $ids. It also deletes (in the database) : 245 // - all the comments related to elements 246 // - all the links between categories and elements 247 // - all the favorites associated to elements 248 // @return number of deleted elements 249 function delete_elements($ids, $physical_deletion=false) 250 { 251 if (count($ids) == 0) 252 { 253 return 0; 254 } 255 trigger_action('begin_delete_elements', $ids); 256 257 if ($physical_deletion) 258 { 259 $ids = delete_element_files($ids); 232 260 if (count($ids)==0) 233 261 { -
trunk/admin/include/functions_upload.inc.php
r9022 r9191 169 169 } 170 170 171 function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null )171 function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null, $image_id=null) 172 172 { 173 173 // Here is the plan … … 186 186 187 187 global $conf, $user; 188 189 // current date 190 list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); 191 list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4); 192 193 // upload directory hierarchy 194 $upload_dir = sprintf( 195 PHPWG_ROOT_PATH.$conf['upload_dir'].'/%s/%s/%s', 196 $year, 197 $month, 198 $day 199 ); 200 201 // compute file path 188 202 189 $md5sum = md5_file($source_filepath); 203 $date_string = preg_replace('/[^\d]/', '', $dbnow); 204 $random_string = substr($md5sum, 0, 8); 205 $filename_wo_ext = $date_string.'-'.$random_string; 206 $file_path = $upload_dir.'/'.$filename_wo_ext.'.'; 207 208 list($width, $height, $type) = getimagesize($source_filepath); 209 if (IMAGETYPE_PNG == $type) 210 { 211 $file_path.= 'png'; 190 $file_path = null; 191 192 if (isset($image_id)) 193 { 194 // we are performing an update 195 $query = ' 196 SELECT 197 path 198 FROM '.IMAGES_TABLE.' 199 WHERE id = '.$image_id.' 200 ;'; 201 $result = pwg_query($query); 202 while ($row = pwg_db_fetch_assoc($result)) 203 { 204 $file_path = $row['path']; 205 } 206 207 if (!isset($file_path)) 208 { 209 die('['.__FUNCTION__.'] this photo does not exist in the database'); 210 } 211 212 // delete all physical files related to the photo (thumbnail, web site, HD) 213 delete_element_files(array($image_id)); 212 214 } 213 215 else 214 216 { 215 $file_path.= 'jpg'; 216 } 217 218 prepare_directory($upload_dir); 217 // this photo is new 218 219 // current date 220 list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); 221 list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4); 222 223 // upload directory hierarchy 224 $upload_dir = sprintf( 225 PHPWG_ROOT_PATH.$conf['upload_dir'].'/%s/%s/%s', 226 $year, 227 $month, 228 $day 229 ); 230 231 // compute file path 232 $date_string = preg_replace('/[^\d]/', '', $dbnow); 233 $random_string = substr($md5sum, 0, 8); 234 $filename_wo_ext = $date_string.'-'.$random_string; 235 $file_path = $upload_dir.'/'.$filename_wo_ext.'.'; 236 237 list($width, $height, $type) = getimagesize($source_filepath); 238 if (IMAGETYPE_PNG == $type) 239 { 240 $file_path.= 'png'; 241 } 242 else 243 { 244 $file_path.= 'jpg'; 245 } 246 247 prepare_directory($upload_dir); 248 } 249 219 250 if (is_uploaded_file($source_filepath)) 220 251 { … … 297 328 $thumb_infos = pwg_image_infos($thumb_path); 298 329 299 // database registration 300 $insert = array( 301 'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 302 'date_available' => $dbnow, 303 'tn_ext' => 'jpg', 304 'path' => preg_replace('#^'.preg_quote(PHPWG_ROOT_PATH).'#', '', $file_path), 305 'filesize' => $file_infos['filesize'], 306 'width' => $file_infos['width'], 307 'height' => $file_infos['height'], 308 'md5sum' => $md5sum, 309 'added_by' => $user['id'], 310 ); 311 312 if (isset($high_infos)) 313 { 314 $insert['has_high'] = 'true'; 315 $insert['high_filesize'] = $high_infos['filesize']; 316 } 317 318 if (isset($level)) 319 { 320 $insert['level'] = $level; 321 } 322 323 mass_inserts( 324 IMAGES_TABLE, 325 array_keys($insert), 326 array($insert) 327 ); 328 329 $image_id = pwg_db_insert_id(IMAGES_TABLE); 330 if (isset($image_id)) 331 { 332 $update = array( 333 'id' => $image_id, 334 'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 335 'filesize' => $file_infos['filesize'], 336 'width' => $file_infos['width'], 337 'height' => $file_infos['height'], 338 'md5sum' => $md5sum, 339 'added_by' => $user['id'], 340 ); 341 342 if (isset($high_infos)) 343 { 344 $update['has_high'] = 'true'; 345 $update['high_filesize'] = $high_infos['filesize']; 346 } 347 else 348 { 349 $update['has_high'] = 'false'; 350 $update['high_filesize'] = null; 351 } 352 353 if (isset($level)) 354 { 355 $update['level'] = $level; 356 } 357 358 mass_updates( 359 IMAGES_TABLE, 360 array( 361 'primary' => array('id'), 362 'update' => array_keys($update) 363 ), 364 array($update) 365 ); 366 } 367 else 368 { 369 // database registration 370 $insert = array( 371 'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 372 'date_available' => $dbnow, 373 'tn_ext' => 'jpg', 374 'path' => preg_replace('#^'.preg_quote(PHPWG_ROOT_PATH).'#', '', $file_path), 375 'filesize' => $file_infos['filesize'], 376 'width' => $file_infos['width'], 377 'height' => $file_infos['height'], 378 'md5sum' => $md5sum, 379 'added_by' => $user['id'], 380 ); 381 382 if (isset($high_infos)) 383 { 384 $insert['has_high'] = 'true'; 385 $insert['high_filesize'] = $high_infos['filesize']; 386 } 387 388 if (isset($level)) 389 { 390 $insert['level'] = $level; 391 } 392 393 mass_inserts( 394 IMAGES_TABLE, 395 array_keys($insert), 396 array($insert) 397 ); 398 399 $image_id = pwg_db_insert_id(IMAGES_TABLE); 400 } 330 401 331 402 if (isset($categories) and count($categories) > 0) … … 343 414 } 344 415 update_metadata(array($image_id=>$file_path)); 345 416 346 417 invalidate_user_cache(); 347 418
Note: See TracChangeset
for help on using the changeset viewer.