Author Topic: [MOD] Automatically delete inactive pictures after some days  (Read 5195 times)

0 Members and 1 Guest are viewing this topic.

Offline senloel

  • Full Member
  • ***
  • Posts: 196
    • View Profile
[MOD] Automatically delete inactive pictures after some days
« on: January 06, 2014, 12:30:46 PM »
Add-on for: http://www.4homepages.de/forum/index.php?topic=8286.0

What?
This MOD will delete inactive pictures automatically after some days.

How?
Once somebody has opened the index.php (guest, admin, etc.), the code will check if there are inactive images older than X days.

Let's start:
 :arrow: Please make a backup of your index.php

1.) Open index.php

2.) Find
//-----------------------------------------------------
//--- SEO variables -----------------------------------
//-----------------------------------------------------
    
$site_template->register_vars(array(
      
"detail_meta_description"   => $lang['meta_description'],
      
"detail_meta_keywords"      => $lang['meta_keywords']
      ));


add below:

//-----------------------------------------------------
//--- Delete inactive pictures ------------------------
//-----------------------------------------------------

$inactive_cutoff time() - 60 60 24 XX;

$sql2 ="SELECT i.image_id, i.cat_id, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file FROM ".IMAGES_TABLE." i WHERE i.image_date <= '$inactive_cutoff' and i.image_active ='0'";
$result2 $site_db->query($sql2);

while (
$row $site_db->fetch_array($result2)){

	
$path "./data/media/".$row['cat_id']."/".$row['image_media_file']."";
	
$path_thumbs "./data/thumbnails/".$row['cat_id']."/".$row['image_thumb_file']."";

	
@
unlink($path);
	
@
unlink($path_thumbs);
	

	
$sql "DELETE FROM ".IMAGES_TABLE."
	
WHERE image_id = "
.$row['image_id']."";
  
$site_db->query($sql);

};


3.) Replace XX with a number after how many days the inactive pictures should be deleted.
Example: Inactive pictures should be deleted after 6 days: Replace XX with 6


4.) Enjoy! ;)

Regards,
Patrick