You are not logged in.
After a brief techie discussion on ways in which I could achieve integration between remote URLs and local files, the omnipotent Ruud pointed me in a particular direction with a cunning and neat hack.
Never one to let an opportunity slip by for making someone’s life easier I took the idea, ran with it, modified it and came up with this plugin.
In a nutshell, you can upload large files to third party file sharing sites such as fileden, tell TextPattern’s Files tab about them (via a new field in the admin interface) and then manage their properties as if they were local files in your
/files directory. This means you can use the standard
file_download_* TXP tags/forms for filtering and displaying files. Uploading more than one version of the same file to multiple providers allows for random load balancing of content, spreading bandwidth usage.
You can use
<txp:smd_file_download_link> instead of the native
<txp:file_download_link> to take advantage of a couple of minor enhancements.
One tiny caveat is that the download counters won’t work for remote files at the moment. There’s details on that in the help and if anyone can offer suggestions on how I can implement it, I’m all eyes. I’ve had several semi-successful trials but have yet to find a good solution that doesn’t cripple other functionality of the plugin. Download counters work in v0.2 and up.
An extra tag
smd_file_download_image allows you to display an image within your files form, based on the filename of the download. Very handy if you’re offering videos or mp3s for download because the images can be relevant stills or artwork.
Take the plugin away for a spin, report any goodness, badness or improvement ideas here and, above all, happy downloading.
show_linkattribute. Improved error handling code. Download count only increases if file sizes match
Last edited by Bloke (2009-04-11 21:20:12)
Yum ! Looks very interesting ! Thank you.
It’s great Stef. Tks lot.
This is one of the most useful plugins to come along since I have been using Textpattern, much appreciated. I have been wanting to use a plugin like this with Amazon S3 for a while now. I have donated for your effort, Stef. Please keep trying to get the download counter to work!
I have donated for your effort, Stef. Please keep trying to get the download counter to work!
Many thanks Andrew. And believe me, I’m trying: it’s driving me mad! There has to be a way of intercepting the call to download_file so I can adjust the database and credit the download. It’s probably staring me in the face, as usual ;-) Will keep you posted.
There has to be a way of intercepting the call to download_file so I can adjust the database and credit the download.
There’s an event hook at the start of a download.
There’s an event hook at the start of a download
Thanks wet, yeah, I saw that and tried to use it without much success before I released the plugin. I managed to hook into the event alright, but because the page is essentially “new” at that point, pretty much the only global thing I could find available was
$pretext. No matter what I tried I couldn’t get my filename variable or value of the
choose parameter from the previous page into the global scope so I could use it in the callback. I think the only avenue might be a cookie :-(
What intrigued me was that, two lines further on from that in publish.php is the line:
$fullpath = build_file_path($file_base_path,$filename);
I cannot see how or where $filename comes from (it just “appears” and has the correct filename in it) so I was trying to figure out if I could somehow “inject” the chosen remote filename into wherever that $filename variable magically appears. My initial idea was to update the database in the callback and then replace that variable with my ‘remote’ filename. But of course the download then fails when it returns from the callback (‘file not found’).
Having been unsuccessful with pretty much every trick I had, I gave up and released the plugin in the hope someone far cleverer could point me in the right direction for v0.2.
The fallback is this, if you think it would work:
chooseoption from smd_file_download. Via a cookie if I must, but any other way would be preferable
choosevariable from wherever it’s hiding, selects either a random or specific file from the list depending on what the smd_download_file tag said, updates the download_count and serves the file, then exits, i.e. never reaching the “official” download part of publish.php for remote files
Annoyingly it’d mean duplicating a lot of code from lines 130-178 of publish.php in my callback, but I can’t see another way of “switching” filenames and letting the callback return so the rest of the download process can begin. I was trying to reuse the code already in TXP to serve the download to the browser.
[ Incidentally, the advantage of handling everything in the callback is that smd_file_download becomes optional. If people don’t care about the random option, they can use the built-in file_download tag instead. The callback would still be called, any non-.link file would be served as normal (the callback would do nothing) but any .link file would be processed. If $choose is not set, the callback would simply pick the 1st entry in the file. ]
So, should I let the callback do everything and duplicate the core code, or do you think there’s a better way of letting the callback “do something” that the remaining part of publish.php can work with?
Thanks in advance for any input.
Last edited by Bloke (2007-11-28 09:09:42)