/** * Delete an image * * @global array $UNC_GALLERY */ function unc_tools_image_delete() { global $UNC_GALLERY; if ($UNC_GALLERY['debug']) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); } if (!is_admin() === true) { ob_clean(); echo "You are not admin!"; wp_die(); } $file_name_raw = filter_input(INPUT_GET, 'file_name', FILTER_SANITIZE_STRING); if (!($file_name = unc_tools_filename_validate($file_name_raw))) { ob_clean(); echo "File name {$file_name_raw} is not allowed!"; wp_die(); } $date_wrong = filter_input(INPUT_GET, 'date', FILTER_SANITIZE_STRING); $date_str = str_replace("-", "/", $date_wrong); $paths = array($UNC_GALLERY['photos'] => $file_name, $UNC_GALLERY['thumbnails'] => $file_name); foreach ($paths as $path => $del_file_name) { $full_path = $UNC_GALLERY['upload_path'] . "/" . $path . "/" . $date_str . "/" . $del_file_name; unc_image_info_exiftool($full_path); wp_die(); if (file_exists($full_path)) { $check = unlink($full_path); if ($check) { ob_clean(); echo "File Deleted!"; } else { ob_clean(); echo "File delete failed!"; wp_die(); } } else { // we cannot stop at an error so there are no leftover files echo "File name {$full_path} could not be found!"; } } // delete file data $check = unc_image_info_delete($file_name, $date_str); if (!$check) { ob_clean(); echo "File data could not be deleted: {$file_name} {$date_str}"; wp_die(); } unc_tools_folder_delete_empty($UNC_GALLERY['upload_path']); unc_display_ajax_folder(); }
/** * function to re-build all thumbnails * @global type $UNC_GALLERY */ function unc_gallery_admin_rebuild_thumbs() { global $UNC_GALLERY; if ($UNC_GALLERY['debug']) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); } ob_clean(); if (!current_user_can('manage_options') || !is_admin()) { echo "Cannot rebuild Thumbs, you are not admin!"; wp_die(); } $dirPath = $UNC_GALLERY['upload_path']; // cleanup empty folders first unc_tools_folder_delete_empty($dirPath); $thumb_root = $dirPath . "/" . $UNC_GALLERY['thumbnails']; // iterate all image folders $photo_folder = $dirPath . "/" . $UNC_GALLERY['photos']; // delete all thumbnails unc_tools_recurse_files($thumb_root, 'unlink', 'rmdir'); $process_id = filter_input(INPUT_POST, 'process_id'); unc_tools_progress_update($process_id, "Cleared existing thumbnails"); $target_folders = unc_tools_recurse_folders($photo_folder); unc_tools_progress_update($process_id, "Got a list of all folders"); if ($UNC_GALLERY['debug']) { XMPP_ERROR_trace('target folders:', $target_folders); } // create thumbnaisl foreach ($target_folders as $date => $folder) { // construct the thumb folder where we put the thumbnails $thumb_folder = $thumb_root . "/" . $date; $text = "Processing {$date}: "; unc_date_folder_create($date); // enumerate all the files in the source folder foreach (glob($folder . "/*") as $image_file) { if (!is_dir($image_file)) { $filename = basename($image_file); $thumb_filename = $thumb_folder . "/" . $filename; unc_import_image_resize($image_file, $thumb_filename, $UNC_GALLERY['thumbnail_height'], $UNC_GALLERY['thumbnail_ext'], $UNC_GALLERY['thumbnail_quality'], $UNC_GALLERY['thumbnail_format']); $text .= "."; } } unc_tools_progress_update($process_id, $text); } unc_tools_progress_update($process_id, "Done!"); wp_die(); }