You are here

function _imagepicker_image_delete in Image Picker 7

Same name and namespace in other branches
  1. 6.2 imagepicker.functions.inc \_imagepicker_image_delete()
3 calls to _imagepicker_image_delete()
imagepicker_admin_orphans_do in ./imagepicker.admin.inc
imagepicker_image_delete in ./imagepicker.functions.inc
imagepicker_multitask_delete_form_submit in ./imagepicker.functions.inc
Submit form

File

./imagepicker.functions.inc, line 214
@author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function _imagepicker_image_delete($img_id, $account = FALSE, $src = 'iframe', $suppress = FALSE) {
  if ($account) {
    $user = $account;
    $userdir = array(
      'name' => $user->name,
      'uid' => $user->uid,
    );
  }
  else {
    global $user;
    $userdir = TRUE;
  }
  $img = _imagepicker_get_img($img_id, $src == 'admin' ? FALSE : TRUE, $account ? $user : FALSE);
  if ($img) {
    $destination = imagepicker_get_path(FALSE, $userdir);
    $thumbsdir = $destination . IMAGEPICKER_THUMBS_DIR . DIRECTORY_SEPARATOR;
    $browserdir = $destination . IMAGEPICKER_BROWSER_DIR . DIRECTORY_SEPARATOR;
    $origdir = $destination . IMAGEPICKER_ORIG_DIR . DIRECTORY_SEPARATOR;
    file_unmanaged_delete($destination . $img->img_name);
    file_unmanaged_delete($thumbsdir . $img->img_name);
    file_unmanaged_delete($browserdir . $img->img_name);
    file_unmanaged_delete($origdir . $img->img_name);
    if (db_delete('imagepicker')
      ->condition('uid', $user->uid)
      ->condition('img_id', $img_id)
      ->execute()) {

      // groups entries
      db_delete('imagepicker_group_images')
        ->condition('img_id', $img_id)
        ->execute();
      if (!$suppress) {
        drupal_set_message(t('Image was successfully deleted'));
      }
    }
    else {
      drupal_set_message(t('Error while trying to delete your image from database.'), 'error');
    }
  }
  else {
    drupal_set_message(t('Image not found.'), 'error');
  }
  return;
}