You are here

function _imagepicker_image_delete in Image Picker 6.2

Same name and namespace in other branches
  1. 7 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 209
Imagepicker functions

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_delete($destination . $img['img_name']);
    file_delete($thumbsdir . $img['img_name']);
    file_delete($browserdir . $img['img_name']);
    file_delete($origdir . $img['img_name']);
    if (db_query("DELETE FROM {imagepicker} WHERE uid = %d AND img_id = %d", array(
      $user->uid,
      $img_id,
    ))) {

      // groups entries
      db_query("DELETE FROM {imagepicker_group_images} WHERE img_id = %d", array(
        $img_id,
      ));
      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;
}