• [MOD] Recycle Bin for images v1.1 5 0 5 1
Currently:  

Author Topic: [MOD] Recycle Bin for images v1.1  (Read 43404 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Recycle Bin for images v1.1
« 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, [MOD] Multi-Language support for any text 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:
Code: [Select]
if ($action == "deleteimage") {Insert above:
Code: [Select]
/*
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:
Quote
//  $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:
Code: [Select]
$config['user_delete_image'] != 1(note, this is a part of a line!)
Replace both with:
Code: [Select]
!$config['user_delete_image']


Step 3
Open details.php
Find:
Code: [Select]
$config['user_delete_image'] != 1(note, this is a part of a line!)
Replace it with:
Code: [Select]
!$config['user_delete_image']


Step 4
Open admin/settings.php
Find:
Code: [Select]
  show_setting_row("user_delete_image", "radio");Replace it with:
Code: [Select]
/*
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:
Code: [Select]
$setting['user_delete_image'] = "Allow users to delete their own images";Insert below:
English:
Code: [Select]
/*
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):
Code: [Select]
/*
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
*/

Русский:
Code: [Select]
/*
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):
Code: [Select]
ALTER TABLE 4images_images ADD delete_reason VARCHAR( 255 ) NOT NULL

Step 7
Open member.php
Find:
Code: [Select]
  $control_panel = $lang['image_delete'];
Insert below:
Code: [Select]
  $delete_reason = isset($HTTP_POST_VARS['delete_reason']) ? addslashes($HTTP_POST_VARS['delete_reason']) : "";


Step 7.1
Find:
Code: [Select]
                SET image_media_file = '".addslashes($new_media_name)."', image_thumb_file = '".addslashes($new_thumb_name)."', cat_id = ".$recycle_bin_cat."
Replace with:
Code: [Select]
                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:
Code: [Select]
                SET image_active = 0
Replace with:
Code: [Select]
                SET image_active = 0, delete_reason = '".$delete_reason."'


Step 7.3
Find:
Code: [Select]
    "lang_delete_image_confirm" => $lang['image_delete_confirm'],
Insert below:
Code: [Select]
/*
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:
Code: [Select]
/*
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:
English:
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$lang['delete_reason'] = "Reason for deletion";
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/

Русский:
Code: [Select]
/*
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 ;)):
Code: [Select]
{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]
« Last Edit: April 18, 2006, 04:17:13 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [MOD] Recycle Bin for images v1.0
« Reply #1 on: January 26, 2006, 12:12:43 PM »
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?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Recycle Bin for images v1.0
« Reply #2 on: January 26, 2006, 02:42:52 PM »
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
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [MOD] Recycle Bin for images v1.0
« Reply #3 on: January 26, 2006, 03:06:17 PM »
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!

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: [MOD] Recycle Bin for images v1.0
« Reply #4 on: January 26, 2006, 03:08:24 PM »
Now, THAT'S interesting !!! 8)

However, is there a screenshot for this MOD ?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Recycle Bin for images v1.0
« Reply #5 on: January 26, 2006, 03:11:06 PM »
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 ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: [MOD] Recycle Bin for images v1.0
« Reply #6 on: January 26, 2006, 03:14:50 PM »
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 :

Quote

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 !!!)

Quote

/*
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 ? ;)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Recycle Bin for images v1.0
« Reply #7 on: January 26, 2006, 03:23:48 PM »
Its for simplyfying installation process. The original "deleteimage" part is still being used if "Permanent delete" option is selected.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Re: [MOD] Recycle Bin for images v1.0
« Reply #8 on: January 26, 2006, 04:11:36 PM »
Hi,

thanks to V@no for this Great Mod. Now it works fine.....
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: [MOD] Recycle Bin for images v1.0
« Reply #9 on: February 06, 2006, 03:18:27 PM »
@ 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
Code: [Select]
//--- 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 ---

Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Recycle Bin for images v1.0
« Reply #10 on: February 07, 2006, 02:07:00 AM »
Thank you. I added it into the tutorial ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: [MOD] Recycle Bin for images v1.0
« Reply #11 on: February 13, 2006, 10:52:16 PM »
Perfect... thank you!    :D

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Re: [MOD] Recycle Bin for images v1.0
« Reply #12 on: February 16, 2006, 10:57:39 AM »
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...
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: [MOD] Recycle Bin for images v1.0
« Reply #13 on: February 17, 2006, 08:02:20 AM »
Good point, JensF!

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: [MOD] Recycle Bin for images v1.0
« Reply #14 on: February 24, 2006, 12:59:43 PM »
Saidly this mod is not compatible with User upload limit:
http://www.4homepages.de/forum/index.php?topic=3607.0