------------- [ Introduction ] -----------------With this mod you will be able restore deleted,
by members, images.
In the settings under
Allow users to delete their own images setting you will be able choose one of the following:
- Not allow. With this option members can not delete their own images
- Allow permanent deletion. With this option images deleted from the server, no restoration is possible
- Move deleted images into "Recycle Bin" category.
- Make deleted images as inactive, which will prevent them from being showed on the site.
- When used "Recycle Bin" or image as inactive type of deletion, member can type a reason of deletion
This mod supports
[Mod] Show original image in new window by clicking on image,
[MOD] Multi-Language support for any text and can handle backup files.
------------- [ Installation ] -----------------Step 1Create a new category "Recycle Bin" (name is your choice)
Set
View category and
View images permissions to
AdministratorRemmember the category ID, you will need it in next step.
Step 2Open
member.phpFind:
if ($action == "deleteimage") {
Insert
above:
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
if ($action == "deleteimage")
{
$recycle_bin_cat = XXXXXXXX; //recycle bin category ID
$big = ""; //big folder name. leave empty if your are not using it
// $big = "big"; //big folder name. leave empty if your are not using it
$backup = (defined('BACKUPDIR')) ? BACKUPDIR : ""; //backup dir with trailing slash! leave empty if not using it
// $backup = "/www/4images_backup/"; //backup dir with trailing slash! leave empty if not using it
$control_panel = $lang['image_delete'];
if (!function_exists("multilang"))
{
function multilang($text)
{
return $text;
}
}
function movefiles($src, $dest)
{
$n = 2;
$copy = "";
$name = substr($dest,0,(strlen($dest)-strlen(strrchr($dest,"."))));
$ext = substr(strrchr($dest,"."), 1);
while (file_exists($name.$copy.".".$ext))
{
$copy = "_".$n;
$n++;
}
$dest = $name.$copy.".".$ext;
if ($ok = @copy($src, $dest))
{
@chmod($dest, CHMOD_FILES);
@unlink($src);
return basename($dest);
}
return false;
}
if ($config['user_delete_image'] > 1)
{
if (!$image_id)
{
show_error_page($lang['no_permission']);
exit;
}
$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_media_file, i.image_thumb_file".get_user_table_field(", u.", "user_level")."
FROM ".IMAGES_TABLE." i
LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
WHERE i.image_active = 1 AND i.image_id = $image_id AND i.cat_id NOT IN (".get_auth_cat_sql('auth_viewcat', 'NOTIN').",".$recycle_bin_cat.")";
$image_row = $site_db->query_firstrow($sql);
if (!$image_row || ($user_info['user_level'] != ADMIN && ($image_row['user_level'] <= USER_AWAITING || $user_info['user_id'] != $image_row['user_id'] || (!$config['user_delete_image'] && $user_info['user_cat'] != $image_row['cat_id']))))
{
show_error_page($lang['no_permission']);
exit;
}
$sql = "";
switch($config['user_delete_image'])
{
case 2: //recycle bin
$mime_type_match = array();
include(ROOT_PATH.'includes/upload_definitions.php');
$error = 0;
$media_moved = 0;
$new_media_name = $image_row['image_media_file'];
$new_thumb_name = $image_row['image_thumb_file'];
if (!$error && $image_row['image_media_file'] && !is_remote($image_row['image_media_file']))
{
if ($new_media_name = movefiles(MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'], MEDIA_PATH."/".$recycle_bin_cat."/".$image_row['image_media_file']))
{
$media_moved = 1;
}
else
{
$error = 1;
}
}
if (!$error && $image_row['image_thumb_file'] && !is_remote($image_row['image_thumb_file']))
{
if (!$new_thumb_name = movefiles(THUMB_PATH."/".$image_row['cat_id']."/".$image_row['image_thumb_file'], THUMB_PATH."/".$recycle_bin_cat."/".$image_row['image_thumb_file']))
{
$error = 1;
if ($media_moved)
{
movefiles(MEDIA_PATH."/".$recycle_bin_cat."/".$new_media_name, MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file']);
}
}
}
if (!$error && $big)
{
$file = MEDIA_PATH."/".$image_row['cat_id']."/".$big."/".$image_row['image_media_file'];
$new_file = MEDIA_PATH."/".$recycle_bin_cat."/".$big."/".$new_media_name;
if ($image_row['image_media_file'] && file_exists($file))
{
if (!@is_dir(MEDIA_PATH."/".$recycle_bin_cat."/".$big))
{
$oldumask = umask(0);
$result = @mkdir(MEDIA_PATH."/".$recycle_bin_cat."/".$big, CHMOD_DIRS);
umask($oldumask);
if (!is_dir(MEDIA_PATH."/".$recycle_bin_cat."/".$big) || !$result)
{
$result = @mkdir(MEDIA_PATH."/".$recycle_bin_cat."/".$big, 0755);
}
@chmod(MEDIA_PATH."/".$recycle_bin_cat."/".$big, CHMOD_DIRS);
}
if (file_exists($new_file))
{
@unlink($new_file);
}
if (@copy($file, $new_file))
{
@unlink($file);
@chmod($new_file, CHMOD_FILES);
}
}
}
if (!$error && $backup)
{
$file = $backup."/".$image_row['cat_id']."/".$image_row['image_media_file'];
$new_file = $backup."/".$recycle_bin_cat."/".$new_media_name;
if ($image_row['image_media_file'] && file_exists($file))
{
if (!@is_dir(MEDIA_PATH."/".$recycle_bin_cat."/".$backup))
{
$oldumask = umask(0);
$result = @mkdir($backup."/".$recycle_bin_cat, CHMOD_DIRS);
umask($oldumask);
if (!is_dir($backup."/".$recycle_bin_cat) || !$result)
{
$result = @mkdir($backup."/".$recycle_bin_cat, 0755);
}
@chmod($backup."/".$recycle_bin_cat, CHMOD_DIRS);
}
if (file_exists($new_file))
{
@unlink($new_file);
}
if (@copy($file, $new_file))
{
@unlink($file);
@chmod($new_file, CHMOD_FILES);
}
}
}
$sql = "UPDATE ".IMAGES_TABLE."
SET image_media_file = '".addslashes($new_media_name)."', image_thumb_file = '".addslashes($new_thumb_name)."', cat_id = ".$recycle_bin_cat."
WHERE image_id = ".$image_row['image_id'];
break;
case 3: //mark as inactive
$sql = "UPDATE ".IMAGES_TABLE."
SET image_active = 0
WHERE image_id = ".$image_row['image_id'];
break;
}
if (!$error && (!$sql || !$site_db->query($sql)))
{
$error = 1;
}
if (!$error)
{
$msg_color = 1;
}
$msg = "<meta http-equiv=\"refresh\" content=\"2; url=".$site_sess->url(ROOT_PATH.(($error) ? "details.php?".URL_IMAGE_ID."=".$image_id : "categories.php?cat_id=".$image_row['cat_id']))."\">".(($error) ? $lang['image_delete_error'] : $lang['image_delete_success']);
$txt_clickstream = get_category_path($image_row['cat_id'], 1, 0, 1).(($error) ? $config['category_separator']."<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id)."\" class=\"clickstream\">".multilang($image_row['image_name'])."</a>".$config['category_separator'] : "");
$action = "";
}
}
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
Replace
XXXXXXXX with your "Recycle Bin" category ID.
Also, if you are using
[Mod] Show original image in new window by clicking on image then uncomment (remove
//) from this line:
// $big = "big"; //big folder name. leave empty if your are not using it
Do the same thing to
$backup variable if you are storing backup images somewhere on your server.
Step 2.1Find two instances:
$config['user_delete_image'] != 1
(note, this is a part of a line!)
Replace both with:
!$config['user_delete_image']
Step 3Open
details.phpFind:
$config['user_delete_image'] != 1
(note, this is a part of a line!)
Replace it with:
!$config['user_delete_image']
Step 4Open
admin/settings.phpFind:
show_setting_row("user_delete_image", "radio");
Replace it with:
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN REPLACE
*/
echo "<tr class=\"".get_row_bg()."\">\n<td valign=\"top\"><p class=\"rowtitle\">".$setting['user_delete_image']."</p></td>\n";
echo "<td><p>";
echo "\n<select name=\"setting_item[user_delete_image]\" class=\"categoryselect\" onkeypress=\"if(window.event.keyCode==13)this.form.submit();\">\n";
for($i = 0; $i < count($setting['user_delete_image_array']); $i++)
{
echo "<option value=\"".$i."\"".(($i == $config['user_delete_image']) ? " selected" : "").">".$setting['user_delete_image_array'][$i]."</option>\n";
}
echo "</select>\n";
echo "</p></td>\n</tr>\n";
/*
MOD RECYCLE BIN FOR IMAGES
END REPLACE
*/
Step 5Open
lang/<your language>/admin.phpFind:
$setting['user_delete_image'] = "Allow users to delete their own images";
Insert
below:
English:
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$setting['user_delete_image_array'] = array(
"No",
"Permanent delete",
"Move to Recycle Bin",
"Mark as inactive"
);
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
Deutsch (thanks to mawenzi):
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$setting['user_delete_image_array'] = array(
"Nein",
"Ja - Endgultig Loschen",
"Ja - Verschieben in den Papierkorb",
"Ja - Markieren als Inaktiv"
);
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
Русский:
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$setting['user_delete_image_array'] = array(
"Нет",
"Да, полное удаление",
"Да, сохранять в мусорнике",
"Да, сделать не активными"
);
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
This is it. For those who would like to let members provide a reason why they deleted an image, you can follow these steps:
Step 6Add new field into
4images_images table (name:
delete_reason type:
VARCHAR(255))
Or you can run this MySQL query (you can use phpmyadmin or any other MySQL managers):
ALTER TABLE 4images_images ADD delete_reason VARCHAR( 255 ) NOT NULL
Step 7Open
member.phpFind:
$control_panel = $lang['image_delete'];
Insert
below:
$delete_reason = isset($HTTP_POST_VARS['delete_reason']) ? addslashes($HTTP_POST_VARS['delete_reason']) : "";
Step 7.1Find:
SET image_media_file = '".addslashes($new_media_name)."', image_thumb_file = '".addslashes($new_thumb_name)."', cat_id = ".$recycle_bin_cat."
Replace with:
SET image_media_file = '".addslashes($new_media_name)."', image_thumb_file = '".addslashes($new_thumb_name)."', cat_id = ".$recycle_bin_cat.", delete_reason = '".$delete_reason."'
Step 7.2Find:
SET image_active = 0
Replace with:
SET image_active = 0, delete_reason = '".$delete_reason."'
Step 7.3Find:
"lang_delete_image_confirm" => $lang['image_delete_confirm'],
Insert
below:
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
"lang_delete_reason" => $lang['delete_reason'],
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
Step 8Open
includes/db_field_definitions.phpAt the end,
above closing
?> insert:
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$additional_image_fields['delete_reason'] = array($lang['delete_reason'], "text", 0);
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
Step 9Open
lang/<your language>/main.phpAt the end,
above closing
?> insert:
English:
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$lang['delete_reason'] = "Reason for deletion";
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
Русский:
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$lang['delete_reason'] = "Причина удаления";
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
Step 10Open
templates/<your template>/member_deleteimage.htmlInsert (design is your task ;)):
{lang_delete_reason} <textarea name="delete_reason"></textarea>
Step 11This step needed only if you want to display the reason to admin (when used recycle bin method):
Open
templates/<your template>/details.htmlAdd the following tags (again, design is your task):[qcode]{if is_admin}{if delete_reason}
{lang_delete_reason}: {delete_reason}{endif delete_reason}{endif is_admin}[/qcode]