/** * 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(); }
/** * Analyse the shortcode vars relevant for the day type. * @global type $UNC_GALLERY * @param type $a * @return boolean */ function unc_day_var_init($a) { global $UNC_GALLERY; if ($UNC_GALLERY['debug']) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); } // we convert the start time and end time to unix timestamp for better // comparison $UNC_GALLERY['display']['range'] = array('start_time' => false, 'end_time' => false); foreach ($UNC_GALLERY['display']['range'] as $key => $value) { if ($a[$key]) { //re-name the variable $UNC_GALLERY['display']['date_range'][$key] = $a[$key]; // convert to UNIX timestamp $dtime = DateTime::createFromFormat("Y-m-d G:i:s", $a[$key]); // TODO: catch here if the date is invalid $UNC_GALLERY['display']['range'][$key] = $dtime->getTimestamp(); // get the date for the same $var_name = 'date_' . $key; ${$var_name} = substr($a[$key], 0, 10); } } if ($a['end_time']) { $date_end_time = substr(trim($a['end_time']), 0, 10); } if ($a['start_time']) { $date_start_time = substr(trim($a['start_time']), 0, 10); } $UNC_GALLERY['display']['date_description'] = false; // false by default, only true if not set explicitly (latest or random date) if ($a['end_time'] && $a['start_time']) { $date_arr = unc_day_date_span($date_start_time, $date_end_time); $UNC_GALLERY['display']['dates'] = $date_arr; } else { if ($a['end_time']) { $date_str = $date_end_time; $UNC_GALLERY['display']['dates'] = array($date_str); } else { if ($a['start_time']) { $date_str = $date_start_time; $UNC_GALLERY['display']['dates'] = array($date_str); } else { if ($a['date'] && in_array($a['date'], $UNC_GALLERY['keywords']['date'])) { // we have a latest or random date // get the latest or a random date if required if ($a['date'] == 'random') { $date_str = unc_day_date_random(); } else { if ($a['date'] == 'latest') { $date_str = unc_day_date_latest(); } } if (!$date_str) { // we have no images in the database $UNC_GALLERY['display']['files'] = array(); $UNC_GALLERY['display']['file'] = false; $UNC_GALLERY['display']['dates'] = array(); } else { $UNC_GALLERY['display']['date_description'] = true; $UNC_GALLERY['display']['dates'] = array($date_str); } } else { if ($a['date'] && strstr($a['date'], ",")) { // we have several dates in the string $dates = explode(",", $a['date']); if (count($dates) > 2) { echo unc_display_errormsg("You can only enter 2 dates!"); return false; } // validate both dates $date_str1 = unc_day_validate_date(trim($dates[0])); $date_str2 = unc_day_validate_date(trim($dates[1])); if (!$date_str1 || !$date_str2) { echo unc_display_errormsg("All dates needs to be in the format '2016-01-31'"); return false; } // create a list of dates between the 1st and the 2nd $date_arr = unc_day_date_span($dates[0], $dates[1]); $UNC_GALLERY['display']['dates'] = $date_arr; } else { if ($a['date']) { $date_str = unc_day_validate_date($a['date']); if (!$date_str) { echo unc_display_errormsg("All dates needs to be in the format '2016-01-31'"); return false; } $UNC_GALLERY['display']['dates'] = array($date_str); } } } } } } // get the actual images if ($a['file'] && $a['type'] == 'day') { $UNC_GALLERY['display']['file'] = unc_tools_filename_validate(trim($a['file'])); $UNC_GALLERY['display']['files'] = array(); } else { $UNC_GALLERY['display']['file'] = false; $UNC_GALLERY['display']['files'] = unc_day_images_list(); } $UNC_GALLERY['display']['date_selector'] = false; if (in_array('calendar', $UNC_GALLERY['display']['options'])) { $UNC_GALLERY['display']['date_selector'] = 'calendar'; } else { if (in_array('datelist', $UNC_GALLERY['display']['options'])) { $UNC_GALLERY['display']['date_selector'] = 'datelist'; } } if (count($UNC_GALLERY['display']['files']) == 0 && !$UNC_GALLERY['display']['file']) { if ($UNC_GALLERY['debug']) { XMPP_ERROR_trace("No files found in date range!"); } if ($UNC_GALLERY['no_image_alert'] == 'error') { $UNC_GALLERY['errors'][] = unc_display_errormsg("No images found for this date!"); } else { if ($UNC_GALLERY['no_image_alert'] == 'not_found') { $UNC_GALLERY['errors'][] = "No images available."; } } return false; } return true; }