OK- just a ‘heads up’ that I’ve started a private beta on the Download lock pro extension- it integrates the Download lock module with the simple commerce module. Meaning- it checks whether the file has been purchased before allowing the download.
The extension will be a ‘pro’ extension, the module stays free. I’m looking for beta testers- and folks who already use the module are probably the best qualified. Drop me an email if you want in on the beta (I’m only taking 4-5 folks).
Trying to install this module fails for me with:
Parse error: parse error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /usr/www/users/ingmar/system/modules/download_lock/mcp.download_lock.php on line 26
This is 1.5.1. I will try on a different install tomorrow, I’d really like to test the Pro Extension, going to sell E-books with the simple e-commerce module.
If you have a file browser setup and you upload a file via the regular EE file upload, it’s going to automatically stick in a url that looks like:So- that’s all you’d have in whatever custom field(s) hold your download. Say I put that in a custom field with a shortname of ‘download’. Then, in my template- if I want the module to automatically figure out the path, it will. (Be sure to use full paths in your file browser settings.) So basically- that’s what the ‘download’ field holds if I look at it in the ‘edit’ page- and on the template, I just put:<a href="https://ellislab.com/asset/images/ent-partner-logo/download_lock_1_0.zip">download_lock_1_0.zip</a>
<a href="http://{exp:download_lock:link">Download</a>
This looks very much like a setup I’d want to use. Just need some advice. The link created points to an invalid URI. I suppose it shouldn’t look like this:
http://www.mydomain.com/index.php??ACT=32&ID=33&FID=download
With the two question marks? I’m sure there’s a way around it, but seeing how I’m PHP-crippled, I’d appreciate any pointers as to what needs to be changed.
ETA: While I’m at it; would there be a way to change what the hyperlink says? To clarify; in the above example the link would say ‘Download’. I’d like it if I could instead get the name of the file to show up. No such thing as {file_name} is available, eh? Feels like it should be possible to make this happen dynamically, but can’t think of a way ATM… Have been staring at this for a while now, so forgive me if the solution is obvious. :red: (Build: 20061128)
[EDIT] Better approach.
If anyone is interested in making this great module work with Mark’s file module, I have found a simple but ugly workaround. In mod.download_lock.php create a new variable.
var $marks_file_upload = TRUE;
Then right after $field = ‘field_id_’.$query->row[‘field_id’]; insert the following:
if ($this->marks_file_upload == FALSE)
{
$temp_filename = $query->row[$field];
}
if ($this->marks_file_upload == TRUE)
{
$temp_filename = $IN->GBL('FNAME', 'GET');
}
Then after $field_name = ( ! $TMPL->fetch_param(‘field_name’)) ? ” : ‘&FID;=’.$TMPL->fetch_param(‘field_name’); insert the following:
$file_name = ( ! $TMPL->fetch_param('file_name')) ? '' : '&FNAME;='.$TMPL->fetch_param('file_name');
Then after if ($link_url_only == ‘yes’) insert the following:
<
pre>{
$link = $FNS->fetch_site_index(0, 0).'?ACT='.$insert_action.'&ID;='.$entry_id.$field_name.$file_name;<br />
return $link;
}
else
{
$link = '<a href="http://{exp:download_lock:link">Wild Garden's EDIT</a> approach. Change the echo to resemble $result[0].'.'.$result[1] Then put the following in the a record.</p>
<pre><code>{if article_image}
{article_images}
<a name="article_image"name="<?php get_file3('{article_image}'); ?>"]Download[/url]
{/article_images}
{/if}
It is an ugly workaround but it seems to work. Does this introduce any new secuirty flaws?
is there a way to combine this module with the image gallery so the big images cannot be downloaded without protection?
This is a nice module, but I have a few questions and suggestions.
First, let me second pctje’s request/question as to whether or not this will work with the gallery to protect images.
Second, I’d really like to have stats on each individual entry. I did see there are instructions for adding stats to custom fields over at media-cow, but I don’t think they’re totally clear - at least to me! I don’t see those lines in the module already - do I just add the variables, put in my field id’s and uncomment the lines? Is it that simple?
Third, I just want to confirm a couple things, in comparison to another download script I already use. I use Simon Stenhouse’s Download 1.5 (we’ll call it SSDL) over at masugadesign.com to keep track of downloads (most notably on the Star Rater page). My site is currently in Wordpress, but I’m converting it to EE - and figuring out the download tracking is something I need to do - and I stumbled upon Download Lock. There are some things SSDL does that I’m wondering if DLock does, or could be easily tweaked to do:
Prevents the leeching of your files; Logs all downloads as well as leech and hack attempts Does DLock do this? Ensure that requests for the file come only from my domain?
Hides the actual location of your files I know DLock does this, but is it be possible to alter DLock’s URL to read something like: http://www.site.com/?download=ajaxstarrater.zip ? Just curious how flexible the URL for this module is, and whether or not the ACT is necessary here.
Show the size of a file in a user friendly way I’m pretty certain this wouldn’t be hard to add to DLock. Could this be inserted into a custom field, then, like the other stats?
One last thing (whew…). SSDL also only logs completed downloads, so if someone clicks “Download” and then cancels it, that attempt doesn’t get logged. Is that how DLock operates as well?
Thanks for bearing with all the questions. I’ve been real happy with Simon’s script on my existing WordPress install, and I’d like to think the Download Lock module will take its place when I migrate everything to EE in the coming weeks. I think either converting Simpon’s script to a module, or integrating some of the things it does into the Download Lock module would be great.
Sorry for ignoring you guys- I don’t venture down to modules as often as I should. Let’s see if I can break it down. The core module keeps some basic stats- but they’re based on starting the download rather than sucessfully completed downloads. This wasn’t hi priority enough to dig into checking for completion prior to ‘counting’ it. So a start ‘counts’. Then it should keep basic stats- each time a member downloads a file- it records the entry id associated with the file, the number of times they downloaded that particular file, and the date of the last time they downloaded the file. It also basically ‘duplicates’ the number of times the file has been downloaded - that’s in case you wanted to do ‘monthly download’ counts or something. You set up a cron job to reset the monthly count to 0. (Or set it to weekly or basically- whatever. It just gives the option of only counting the latest ‘x’ downloads.)
Let’s see- it does hide the file name- basically, the action id is required. When invoked it takes the entry id associated with the link and uses that to grab the file name. Then, based on your settings, it figures out where the file actually is and serves it up. It doesn’t count hack attempts. I’m not entirely sure how it could- I suppose if someone access the action id without being logged in/having proper permissions, it could be counted. That wouldn’t be all that hard to do- right now it will trigger a ‘no permission’ error. So adding in a db query wouldn’t be hard. I’d probably make a new table for it, though. But in truth- not high on my list.
Changing the url wouldn’t be too doable- in part because the action id is required and I believe the entry id is passed as get data. In some cases, there’s additional get data.
The module basically uses an htaccess file to prevent leeching. It’s included with the module- should go in the folder with your files. It prevents browser access- even from your domain. If it’s in there, try to pull up a file directly- you’ll get a forbidden message. I wouldn’t count on it to keep my banking data safe- not without a lot more thought. But it’s pretty standard. It’s even possible to put the file folder above the public domain- the script could still access it. I generall don’t though, as it’s easier to upload files via the EE interface. IIRC, EE refuses to accept settings to upload above the public folders. But it’s doable if you want that ‘extra’ protection.
Let’s see- as to stats, the core module keeps the stuff mentioned above. If I want to display summary data, I just do it via the query module:
<table>
{exp:query sql="SELECT title, screen_name as sname, total_down FROM exp_weblog_titles t, exp_members m, exp_d_lock_stats s WHERE s.entry_id = t.entry_id AND s.member_id = m.member_id ORDER BY title"}
<tr><td>{title}</td><td>{sname}</td><td>{total_down}</td></tr>
{/exp:query}
</table>
Shows who downloaded which titles.
<table>
{exp:query sql="SELECT SUM(total_down) as total, title FROM exp_weblog_titles t, exp_d_lock_stats s WHERE s.entry_id = t.entry_id GROUP BY s.entry_id ORDER BY title"}
<tr><td>{title}</td><td>{total}</td></tr>
{/exp:query}
</table>
Shows how many times a given title- by that I mean entry title- has been downloaded.
Now if you want to display this for each entry as part of the weblog tag? That’s where the extension comes in. It will basically allow you to have the ‘count’ of downloads added to a custom weblog field. So to set that up, install the extension and go to the extension control panel. It will give you a dropdown of custom fields in each field group. You can select one of those fields to hold download count info for that entry. Actually- you can select to use up to 4 fields- total downloads, total unique downloads (if a member has already downloaded, they don’t count in subsequent downloads, and then dupliaces of each field- in case you want to do that cron job thing and reset the field to 0 every month- or whatever.) Then you just use that custom field to show the count in the regular way- using the weblog tag.
Oh crud- and the gallery thing. At one point? I meant to include it But I just took a look and there’s no check in there for it. And no field in the database to record weblog/gallery. Probably should add that- it would be a handy feature. Ah- but the problem with the gallery- the large image, thumbs, etc all go into the same folder. So no way to really ‘hide’ the large one. That’s the problem with doing it for the gallery- unless you wanted to lock down the whole thing, which seems unlikely.
Oh- and the last big- the file size. Hm- it doesn’t do that- and in truth, I’d probably figure out file size and add it to a custom field when publishing. Would be my preference- less resource intensive than figuring it out on the fly. The way the module is designed, it really couldn’t check the file size until they click on the link to download it- at that point, would be easy to display. But that doesn’t strike me as massively useful. Like I say- I’d handle that at publication time via an extension.
But- hope that clears things up a wee bit. It’s a fairly solid module- I use it on live sites. But it is a little confusing in setup, in part because there are a lot of ways you might need to configure it. Lot of room for improvement, too. But right now, it’s solid for what I need it to do so I haven’t been mucking with it.
Robin -
Thanks for taking the time to reply and clear some things up for us. For example, I didn’t know ACT was necessary, but I was reading the docs this morning and now know what it is and how the actions table works.
I’m fairly certain I can add the file size option myself - so I’ll work on that when I have spare time. I can see how Simon S. did it in his PHP Download script and I think I can apply that here. I’m certain I can get this to only count completed downloads (as opposed to counting a false positive) as well, based on some PHP I saw in Simon’s script. There are a couple other things that would be groovy, but I just want this to work for my purposes now, and I’ll see if I can get the other things going on when I have a “slow month”…yeah right!
But I guess for now the one thing I’d like to get working (which I can’t seem to get working) is updating the stats in the weblog fields. There are some instructions on your site with a little code example, and then, in addition, the extension. Do they work together? I’ve created two fields in the weblog to hold download stats (one for unique, one for total). Do those fields need a particular field type?
From Media Cow (emphasis mine in the following paragraphs):
Add stats to weblog custom fields I personally like to be able to show how many times a file has been downloaded using our friend the weblog tag. When the stats are adding to the download count in the download_lock table, I just ask it to increment the weblog_data table as well. For this to work, you have to do two things. First- create a custom field to hold your ‘download count’. If you want to know both the total downloads and the unique downloads- make two custom fields. Now add the custom field id number(s) in place of the example numbers in the file, uncomment the code, and you’re done. If you want to display the number of downloads, you now have a custom field to do it with.
The code in question looks like this:
// Optional - you can specify a custom weblog field id to hold the total number of downloads.
// var $total_field_id = '';
// Optional - you can specify a custom field id to hold the total number of unique downloads.
// var $unique_total_field_id = '';
I couldn’t find these lines in the file to begin with! And where is the incrementing of the weblog_data table taking place? So I added that block of code to the top of the module file, where one sets some other variables, entered the field id’s of the two fields I made to hold the download stats, and uncommented them. I’ve also enabled the extension, and have selected the correct fields from the dropdowns in the Control Panel. Downloading a file increments it (in the download lock table)- but the fields I created to hold the updated values in weblog_data don’t get incremented. Are there some other lines I’m missing or need to add to the module to get that to work?
I’ll look again to make sure I have the correct field ID’s in there, but right now it doesn’t appear to be updating the weblog_data table!
Hm- I’ll have to look at the docs- that’s old school. Basically? That bit I ripped out and made into an extension so folks wouldn’t have to edit the file much. Was too confusing. Try this- set your custom fields to ‘text’. Install the extension- go to ‘Utilities- Extension Manager’- go into the settings for the extension. You can just choose the fields from dropdowns in the extension settings.
Robin - One thing about the counter extension: there is the error that was brought up in this thread: Download Lock Counter Extension Error (and in the comments for the extension at media-cow.com 😝 ).
else
{
tdata = array($data['t'], $data['mt']);
$mid_sql = $data['t'].', '.$data['mt'];
$sql = "UPDATE exp_weblog_data SET ".$mid_sql." WHERE entry_id = $entry_id";
$DB->query($sql);
}
return;
We were wondering what ‘tdata’ on line 80 should actually be. Thanks for your help today, Robin!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.