4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: V@no on January 26, 2006, 07:45:27 AM
-
------------- [ 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 (http://www.4homepages.de/forum/index.php?topic=3236.0), [MOD] Multi-Language support for any text (http://www.4homepages.de/forum/index.php?topic=6749.0) and can handle backup files.
------------- [ Installation ] -----------------
Step 1
Create a new category "Recycle Bin" (name is your choice)
Set View category and View images permissions to Administrator
Remmember the category ID, you will need it in next step.
Step 2
Open member.php
Find: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 (http://www.4homepages.de/forum/index.php?topic=3236.0) 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.1
Find two instances:$config['user_delete_image'] != 1
(note, this is a part of a line!)
Replace both with:!$config['user_delete_image']
Step 3
Open details.php
Find:$config['user_delete_image'] != 1
(note, this is a part of a line!)
Replace it with:!$config['user_delete_image']
Step 4
Open admin/settings.php
Find: 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 5
Open lang/<your language>/admin.php
Find:$setting['user_delete_image'] = "Allow users to delete their own images";
Insert below:
(http://img307.imageshack.us/img307/6874/gb3vq.gif) 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
*/
(http://img85.imageshack.us/img85/2867/de8ru.gif) 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
*/
(http://img307.imageshack.us/img307/682/ru0cy.gif) Русский:/*
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 6
Add 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 7
Open member.php
Find: $control_panel = $lang['image_delete'];
Insert below: $delete_reason = isset($HTTP_POST_VARS['delete_reason']) ? addslashes($HTTP_POST_VARS['delete_reason']) : "";
Step 7.1
Find: 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.2
Find: SET image_active = 0
Replace with: SET image_active = 0, delete_reason = '".$delete_reason."'
Step 7.3
Find: "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 8
Open includes/db_field_definitions.php
At 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 9
Open lang/<your language>/main.php
At the end, above closing ?> insert:
(http://img307.imageshack.us/img307/6874/gb3vq.gif) English:/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$lang['delete_reason'] = "Reason for deletion";
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
(http://img307.imageshack.us/img307/682/ru0cy.gif) Русский:/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$lang['delete_reason'] = "Причина удаления";
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/
Step 10
Open templates/<your template>/member_deleteimage.html
Insert (design is your task ;)):{lang_delete_reason} <textarea name="delete_reason"></textarea>
Step 11
This step needed only if you want to display the reason to admin (when used recycle bin method):
Open templates/<your template>/details.html
Add 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]
-
wow!
thank you very much for this mod!
a little question:
an admin can delete the images without the settings. is it possible to do the same things for an admin like this for a member?
-
Well, admin can always set images as inactive or move them to any category, so no point to add this feature to ACP, its already there ;)
Probably using this mod would be more usefull for this: http://www.4homepages.de/forum/index.php?topic=6759.0
-
Well, admin can always set images as inactive or move them to any category, so no point to add this feature to ACP, its already there ;)
Probably using this mod would be more usefull for this: http://www.4homepages.de/forum/index.php?topic=6759.0
yes, ok you're right. thank you!
-
Now, THAT'S interesting !!! 8)
However, is there a screenshot for this MOD ?
-
However, is there a screenshot for this MOD ?
The only screenshot I could possible make is a screenshot of a new dropdown option in the setting...thats all visualy different in this mod ;)
-
I see. Well, at least, it describes even more - in words - of what the MOD looks like.
Another thing ... may I ask why is there two same action name called : "delete_image" ?
In step 2, you stated -
find :
if ($action == "deleteimage") {
then add above (rather than replace) (note to other users : sample part will be demonstrated - do NOT follow the quote below as an official instruction !!!)
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
if ($action == "deleteimage")
{
$recycle_bin_cat = XXXXXXXX; //recycle bin category ID
There are two same action name ... won't that affect somehow ? ;)
-
Its for simplyfying installation process. The original "deleteimage" part is still being used if "Permanent delete" option is selected.
-
Hi,
thanks to V@no for this Great Mod. Now it works fine.....
-
@ V@no,
... thanks for this very useful MOD ...
... it works perfekt with all variations of settings ...
... and here still the German translation for admin.php ...
... Deutsche Übersetzung für lang/deutsch/admin.php
//--- MOD RECYCLE BIN FOR IMAGES --- BEGIN REPLACE ---
$setting['user_delete_image_array'] = array(
"Nein",
"Ja - Endgültig Löschen",
"Ja - Verschieben in den Papierkorb",
"Ja - Markieren als Inaktiv"
);
//--- MOD RECYCLE BIN FOR IMAGES --- END REPLACE ---
-
Thank you. I added it into the tutorial ;)
-
Perfect... thank you! :D
-
Hi there,
is there a way to give up a comment from the user why he delete the picture???
I mean the user clicks on delete and before the pic is delete or copy to the Recycle folder they must give a comment why delete and the admin becomes a mail...
-
Good point, JensF!
-
Saidly this mod is not compatible with User upload limit:
http://www.4homepages.de/forum/index.php?topic=3607.0
-
Lucifix,
i have both MODs installed and don't see any complications :idea:
-
Saidly this mod is not compatible with User upload limit:
http://www.4homepages.de/forum/index.php?topic=3607.0
Hows so?
These are two unrelated mods, and dont change the same code in member.php...
-
If you are using limit user mod... when user delete image it will go to recycle bin (still in one category). Then when he will try to upload one more image limit mod won't let him, becouse it will look for last image in all categories (even in Recycle bin).
-
Because the changes must be done in that mod, you should ask this question there ;)
but without letting you go empty handed, here is a hint on what should be done.
There must be a query that count how many images the member uploaded, in that query must be added condition to EXCLUDE your recycle bin's category ID. Like NOT IN CAT(xx)
-
Thanks, I was trying to do it by my self, but I couldn't remeber which code exclude category ID ;)
Great mod v@no - again and us usual :mrgreen:
-
The MOD is really very great, i didn't know that my users are deleting so much ... yesterday installed, i have allready about 50 pictures in the recycle bin.. hmm ;)
-
is there a way to give up a comment from the user why he delete the picture???
I mean the user clicks on delete and before the pic is delete or copy to the Recycle folder they must give a comment why delete and the admin becomes a mail...
Ok, I added Steps 6 - 11 for the comment thingie, but no email to admin.
-
Ok, I added Steps 6 - 11 for the comment thingie, but no email to admin.
Thanks for this, works great.....
-
Hi there,
is there a way to have a date when the image where delete in the recycle bin......
-
Hi when users are deleting images its getting deleted permanently how does it move to recycle bin infact i registered an regular account uploaded and image and than deleted it when i delete it just goes completly i dont see it gettin moved to recycle bin :(
-
Hi when users are deleting images its getting deleted permanently how does it move to recycle bin infact i registered an regular account uploaded and image and than deleted it when i delete it just goes completly i dont see it gettin moved to recycle bin :(
Have u looked your ACP settings, where does that picture go, when user delete? Under Session and User settings look for Allow users to delete their own images, change it to Move to Recycle Bin...