set_filename('delete_hd', realpath(dirname(__FILE__).'/delete_hd.tpl')); $template->append( 'element_set_global_plugins_actions', array( 'ID' => 'delete_hd', 'NAME' => l10n('Delete High Definition Photos'), 'CONTENT' => $template->parse('delete_hd', true)) ); } function delete_hd_element_action($action, $collection) { global $template, $page; if ('delete_hd' == $action) { if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) { $deleted_ids = delete_hd_files($collection); if (count($deleted_ids) > 0) { array_push($page['infos'], l10n('High definition photos were deleted')); } else { array_push($page['errors'], l10n('No high definition photo can be deleted')); } } else { array_push($page['errors'], l10n('You need to confirm deletion')); } } } // Deletes all HD files (on disk) related to given image ids // @return image ids where HD files are deleted successfully // // code based on admin function delete_element_files function delete_hd_files($ids) { if (count($ids) == 0) { return array();; } include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); $new_ids = array(); $query = ' SELECT id, path, has_high FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $ids).') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { if (url_is_remote($row['path'])) { continue; } $files = array(); if (!empty($row['has_high']) and get_boolean($row['has_high'])) { $files[] = get_high_path($row); } $ok = true; foreach ($files as $path) { if (is_file($path) and !unlink($path)) { $ok = false; trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING); break; } } if ($ok) { $new_ids[] += $row['id']; } } if (count($new_ids) > 0) { $query = ' UPDATE '.IMAGES_TABLE.' SET has_high = NULL, high_filesize = NULL, high_width = NULL, high_height = NULL WHERE id IN ('.implode(',', $new_ids).') ;'; pwg_query($query); } return $new_ids; } ?>