Download Lock 1.0

Example:
You’re seeing the download module in action right here.  If you aren’t logged in, you’ll see a message instead of a download link.  If you are logged in, you’ll see a link to http://media-cow.com/?ACT=42&ID=2.  The url to the actual file is disguised and the ‘fake’ url will not serve up the file to anyone who isn’t logged in.  Feel free to click it and give it a try.

Installation/set-up
Download the zip file (you’ll need to be logged in to do this cool smile ).  For basic functionality you may need to set some configuration options in download_lock/mod.download_lock.php, so open up the file.  You’ll see:

//  $field_id -  Optional- you may specify a default field as the field holding your file- you'll need this if you don't specify a field_name parameter.
var $field_id '22';

//  $download_path - Optional- should be full path with trailing slash to a default directory holding your downloads.  This is needed if you are not using the standard EE file directory tag in your fields.
var $download_path '/home/me/public_html/secret_files/'

As of v. 1.0, these are optional fields- $field_id should be the field id number for whatever custom field you are going to use to hold the file name of your download.  The download path is- well, the download path.  There are lots of tweaks you can make to this module- but the basic set-up is done.  Now upload the lang.download_lock.php file to system/lang/english/ and the download_lock folder (containing two files) to your system/module/ folder.  Go to ‘Modules’ and ‘enable’ the module and you’re good to go.

Tags and variables
There are two tags available for this module:
{exp:download_lock:link} - Creates the link to your hidden file.
{exp:download_lock:stats}{/exp:download_lock:stats} - A basic overview of your download stats.

{exp:download_lock:link}
This tag creates your links for you and should be used inside your weblog tag a la:

{exp:weblog:entries}
<h3>{title}</h3>
{if logged_in}<a href="{exp:download_lock:link entry_id="{entry_id}" field_name="my_file"}">Download</a>
{if:else}You must be logged in to download.{/if} 
{
/exp:weblog:entries} 

Yes, I am cheating and using ExpressionEngine’s own conditionals to determine what the link shows.

Parameters and variables
There is one required parameter- you MUST include entry_id={entry_id} just like it’s shown above.

The field_name parameter is optional.  If you do NOT specify the name of the field holding the file, the module will use the $field_id specified in the configuration option.  However, this is more flexible and allows you to have multiple ‘locked’ files, each in its own custom field.

There are a couple of other parameters- mostly for debugging purposes:

It’s simpler and more flexible to just use EE’s standard conditionals- but if you’re wondering why the heck the url isn’t showing up, this will output an actual message telling you to login.

{exp:download_lock:stats}
If you’re keeping track of your download stats, you might actually want to SEE them- this tag handles that.  Basic usage:

{exp:download_lock:stats}
{title} 
Downloaded by{unique_downloads} members<br>
{/exp:download_lock:stats} 

Yep- that’s the code I’m using to generate the list of ‘Favorites’ over there in the top right corner.

Parameters and variables
You’ve got your basic parameters:

Variables:

Tweaking things out
Note that this module was created to fill a very specific need- handling my file downloads.  Version 1.0 saw considerable flexibility added, and tweaking is safer and easier than before.  If you want more from the module, or perhaps less, I’ve stuck the ‘tweak’ instructions on their own page- here

Simple tweaks include:

And that is pretty much that.