You are here

function photos_file_del in Album Photos 6.2

Same name and namespace in other branches
  1. 7.3 photos.module \photos_file_del()
3 calls to photos_file_del()
photos_editlist_submit in inc/photos.edit.inc
photos_edit_delete in inc/photos.edit.inc
photos_nodeapi in ./photos.module

File

./photos.module, line 843

Code

function photos_file_del($fid, $filepath = 0, $count = 0) {
  if (!$filepath) {
    if ($count) {
      $file = db_fetch_object(db_query('SELECT f.uid, f.filepath, p.pid FROM {files} f INNER JOIN {x_image} p ON f.fid = p.fid WHERE f.fid = %d', $fid));
      $filepath = $file->filepath;
    }
    else {
      $filepath = db_result(db_query('SELECT filepath FROM {files} WHERE fid = %d', $fid));
    }
  }
  if ($filepath) {
    $filename = end(explode('/', $filepath));
    $thumb = str_replace($filename, 'thumb_' . $fid, $filepath);
    if (is_dir($thumb)) {
      if ($objs = glob($thumb . '/*')) {
        foreach ($objs as $obj) {
          is_dir($obj) ? @rmdir($obj) : @unlink($obj);
        }
      }
      @rmdir($thumb);
    }
    @unlink($filepath);
    if (variable_get('photos_comment', 0)) {
      db_query('DELETE FROM {comments} WHERE cid IN (SELECT cid FROM {x_vote} WHERE fid = %d)', $fid);
    }
    db_query('DELETE FROM {x_image} WHERE fid = %d', $fid);
    db_query('DELETE FROM {x_node} WHERE fid = %d', $fid);
    db_query('DELETE FROM {x_vote} WHERE fid = %d', $fid);
    if ($count) {
      photos_set_count('node_album', $file->pid);
      photos_set_count('user_image', $file->uid);
      _comment_update_node_statistics($file->pid);
    }
    return db_query('DELETE FROM {files} WHERE fid = %d', $fid);
  }
  else {
    return false;
  }
}