Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: Suki on March 14, 2014, 01:36:37 PM

Title: Expired Attachments
Post by: Suki on March 14, 2014, 01:36:37 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=3843)

The software is licensed under [MPL 1.1 license](http://www.mozilla.org/MPL/MPL-1.1.html).

######Expire Attachments:

A simple modification to allow users to set a predefined date for their attachments to be deleted. some features:

- There are 4 hard-coded expiration dates: 'Day', 'Week', 'Month', 'Year' and "NEVER".  The admin can enable/disable each specific date.
- You must enable at least 1 period, otherwise the mod will not store any expiration date. Each date period sets a unique permission, you can assign that permission to each membergroup.
Apply all permissions if you want the user to have all the possible option dates available.
- Each attachment will get its unique expiration date.
- After the attachment has been deleted, a text on its related message will be added stating the attachment has been deleted.
- This mod does not modify old attachments, it will only work with new attachments uploaded after the installation of this mod.
Title: Re: Expired Attachments
Post by: OCJ on April 23, 2014, 06:07:44 AM
I like the idea of this one... thanks.

To my surprise 2.0.7 is giving me few error in the log these days. But this mod  shows up.
I'm not sure if important or worth correcting though. Here are the details from smf error log.

Mod is set to expire attachments at 3 months.
   
Quote
   
/index.php?action=post2;start=0;board=39
Undefined index: expire_date
/public_html/Sources/Subs-Post.php Line: 2247
   

(int) $attachmentOptions['size'], (empty($attachmentOptions['width']) ? 0 : (int) $attachmentOptions['width']), (empty($attachmentOptions['height']) ? '0' : (int) $attachmentOptions['height']),
==>2247:    

(!empty($attachmentOptions['mime_type']) ? $attachmentOptions['mime_type'] : ''), (int) $attachmentOptions['approved'], (int) $attachmentOptions['expire_date'],
Title: Re: Expired Attachments
Post by: Suki on April 23, 2014, 04:03:51 PM
Attach that file here.
Title: Re: Expired Attachments
Post by: OCJ on May 09, 2014, 05:58:59 AM
Attached.
I guess it could also be an effect from another mod too.

Title: Re: Expired Attachments
Post by: Suki on May 09, 2014, 08:26:06 AM
The var shouldn't have to be null since I explicitly set it as an integer and only filled it if there is some data, make sure you have this code on your /Sources/Post.php file:


// Expire Attachments mod
if (!empty($modSettings['ExAt_setting_enable']) && !empty($_REQUEST['expire_date'. $n]))
{
// Set the var
$attachmentOptions['expire_date'] = 0;

// Do this only if the selected option wasn't "forever"
if ($_REQUEST['expire_date'. $n] != 'forever')
{
// One last extra check, just to be sure...
if (empty($modSettings['ExAt_setting_periods'. $_REQUEST['expire_date'. $n] .'_number']))
$modSettings['ExAt_setting_periods'. $_REQUEST['expire_date'. $n] .'_number'] = 1;

// Calculate the time ahead, strtotime() makes things easy, for me, not the server...
$expire_date = strtotime('+'. $modSettings['ExAt_setting_periods'. $_REQUEST['expire_date'. $n] .'_number'] .' '. strtolower($_REQUEST['expire_date'. $n]));

// Fill up the var
if (!empty($expire_date))
$attachmentOptions['expire_date'] = (int) $expire_date;
}
}
// Expire Attachments mod end

if (createAttachment($attachmentOptions))


where exactly does this happen?  is the user actually uploading an attachment?

Alternatively, you can just move the var declaration

$attachmentOptions['expire_date'] = 0;

outside the if conditional

// Set the var
$attachmentOptions['expire_date'] = 0;

if (!empty($modSettings['ExAt_setting_enable']) && !empty($_REQUEST['expire_date'. $n]))
         {
            
Title: Re: Expired Attachments
Post by: OCJ on May 11, 2014, 11:36:47 AM
Ok, thanks. Im not so bothered about the errors - not many. I just thought I would report it.
Title: Re: Expired Attachments
Post by: mnn2 on May 20, 2014, 01:12:41 PM
Feature request.  :)


Please add optional total download limit. I mean we limit a particular attachment to be available for certain number of downloads, e.g. free ebook for first 50 downloads.

Thankyou.
Title: Re: Expired Attachments
Post by: Suki on May 23, 2014, 11:24:59 AM
Sorry, thats beyond the scope of this mod.  I recall there are other mods that limit the amount of attachment downloads.
Title: Re: Expired Attachments
Post by: OCJ on October 22, 2014, 12:12:18 AM
On reinstalling my site and mods I get an error trying to install this mod again. It will not complete install.

Duplicate entry 'attachments_expire_date' for key 'task' File: /***/****/public_html/Packages/temp/install.php Line: 56

I do not want to go in the database and delete tables just to get it to install again. Would be better if fixed.

Andy
Title: Re: Expired Attachments
Post by: Suki on October 22, 2014, 10:14:32 AM
I've update the mod to fix that error and a few other ones.

But you still need to go to your scheduled_tasks table and manually delete the "attachments_expire_date" entry  before installing the mod again.

If you don't want to do that manually then download the mod, get the removeScheduledTask.php file, upload it to your forum's root folder and call it with your browser:  myforum/removeScheduledTask.php

Then install the mod.
Title: Re: Expired Attachments
Post by: OCJ on October 22, 2014, 10:18:40 AM
Ok, thanks very much, that was quick!

And it installed ok this time.
Title: Re: Expired Attachments
Post by: Snrj on April 09, 2016, 01:13:40 PM
very good mod thanks
turkish translate pack
Title: Re: Expired Attachments
Post by: -Rock Lee- on April 09, 2016, 02:33:25 PM
Very good modification @Suki Here I leave the Spanish translation Latin I hope you will be useful ;D


Regards!