Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-11-23 12:29:09

trenc
Plugin Author
From: Amsterdam
Registered: 2008-02-27
Posts: 571
Website GitHub

yab_download

I wrote a tiny textpattern plugin for a customer of mine. It’s nothing spectacular, but if someone need it, feel free to download.

What it does

This plugin allows you to offer a download of multiple files (per file id and/or category) with or without a confirmation button. Additionally you can offer an option to download all the files as zip archive on the fly. The names of the files are read from the files description. If no description is given the filenames are displayed.

Usage

This plugin has only one tag: <txp:yab_download />. You have to place it in an individual article.
The following attributes are available:

  • files: The IDs of the files, which are for download (seperated by comma). If no files assigned with an ID an error message will displayed in the option field.
  • label1: Label for select
  • label2: Label for confirmation checkbox
  • label3: Label for the submit input
  • label4: Label for zip download checkbox
  • notice: Error notice, if confirmation is not set but required
  • size: Display filesize additionally (values are B, KB, MB, GB, PB).
  • confirm : Form used with a confirmation checkbox (values: ‘1’ or some other string)
  • formid: html id of the element form, used for anchor, if you use more than one <txp:yab_download /> in a single site, make different entries here; (default yab_cd_download)
  • cats: File categories you will add to download (seperated by comma); will additional displayed with files from files attribute above
  • exclude: IDs of the files you will exclude; Does only work with cats attribute.
  • sort: Sort the files from cats; (defaul description asc)
  • zip: Offfers an checkbox with an option to download all offered files as zip instead (values: ‘1’ for zip creation; ‘2’ to force zip creation in memory)
  • zipname: the name of the offered zip (default all.zip)
  • hidelist: hides the select list of the files, usefull if you offer only one file or offer many files zipped without a seletion (values: ‘1’)
  • hidezip: hides the zip checkbox (download as zip is forced), useful if you offer only one file as zip or many files as zip wihtout a file selection; can be combined with ‘hidelist’, so only a download button will be displayed (values: ‘1’)

Example usage

simple
<txp:yab_download files="1,2,3,4" />

full
<txp:yab_download files="1,2,3,4" label1="Choose your download" label2="Accept Download at your own risk" label3="Klick here for download" label4="Yeah give me all as zip" notice="You have to accept the condition below" size="MB" formid="form-no-1" confirm="1" cats="category1, category2" exclude="5,7" sort="filename desc" zip="1" zipname="archive.zip" />

The full example above will show you a form with two checkboxes. First one offers an option to download all the files zipped. The second checkbox is a confirmation checkbox.
The offered files will be the files with the file id #1, #2, #3, #4 and all files of the categories category1 and category2. If in category1 or category2 a file with the file id #5 and #7 so these will be excluded from download. The zipped file will be named as archive.zip.

Note on zip creation

If you are running a php version 5.2.0 or above so the attribute zip="1" will try to create the zip on harddisk instead in memory. If you have php 5.2.0 or above and you have problems with some restrictions like safe_mode, open_basedir etc., so try the attribute zip="2". This will force the zip creation in memory.

Download

This download of the plugin shows you a real world example. So go to my plugin site, please!
Or you can grab it here: yab_download_v0.7.txt

Changelog

  • 08-11-23 – v0.1
    • release
  • 08-11-27 – v0.2
    • renamed the plugin to yab_download
    • added: confirmation is now optional
    • added: support files per categories
    • added: sort per category
    • added: files exclude
    • added: zip-on-the-fly
    • added: attribute formid for unique html ids for multiple plugin usage per page
  • 08-12-01 – v0.3
    • bugfix: filesize of category listing will now correctly calculated
    • bugfix: minor code improvement
  • 08-12-21 – v0.4
  • 09-01-08 – v0.5
    • bugfix: code improvement (Thanks to Geoffrey in my weblog comments); if a php 5.2.0 is running so zip creation will be on harddisk instead in memory
  • 09-11-16 – v0.6
    • bugfix: filenames and filedescriptions are now correctly escaped
    • added: new attribute ‘hidelist’ hides the file selection list
    • added: new attribute ‘hidezip’ hides the download-as-zip checkbox
  • 2017-02-10 – v0.7
    • TXP 4.6-ready

Last edited by trenc (2017-02-10 14:49:34)

Offline

#2 2008-11-23 13:10:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: yab_download

trenc wrote:

I wrote a tiny textpattern plugin for a customer of mine. It’s nothing spectacular, but if someone need it, feel free to download.

Excellent stuff, thanks. Your timing is perfect, I was just thinking I could do with something like this for a site I’m working on today.

A handful of possible feature requests if you ever get time to think about it:

  1. Option to jump down to the ‘notice’ anchor (like the way comment preview does), instead of jumping back to the top of the page (p.s. shoudn’t that be yab_notice to avoid name clashes, or perhaps an option to specify the class/id from the plugin?)
  2. Multiple yab_confirmed_download tags per page (e.g. on an Article List page). At the moment (from a DOM perspective) the id="yab_cd_files" prevents this. I’d like to offer an “all artists” page that lists each artist and a dropdown of their available downloads
  3. Category support so you can say: <txp:yab_confirmed_download categories="metallica_videos, metallica_audio" /> and it would offer you each of the corresponding downloads (probably in addition to the files attribute so any duplicate files would be ignored and/or extra (sticky!) ones could be added to the list?)
  4. EDIT: Ability to exclude files from a category on a file by file basis
  5. (an extension to #3; getting a bit wild here!) Some way of offering an on-the-fly zipped package of each category for download ;-)

That last one opens up the possibility of <txp:yab_confirmed_download categories="metallica_videos, metallica_audio" zipcats="metallica_videos, metallica_audio" />. That would list each of the files individually and add two pseudo entries (“All Metallica Videos” and “All Metallica Songs”) to the end of the select list, which would zip the corresponding files up and deliver the chosen package on confirmation.

I know, I know, I’m lazy and should really package them all up as a separate zipped download, but that takes up (almost) twice the space on the server :-/ I’m thinking of offering a download for an entire album of songs + cover art + standard “Thanks for downloading this album from blah.com; visit us again for more stuff soon” text file, if that helps. That text file (and maybe the cover art) I don’t want to offer for download separately (hence the exclude option) but I want it to be part of the zip package.

Anyway, they’re just random extensions I’d find useful; perhaps I’m alone here! As it stands, this plugin is going to be very handy; many thanks for creating it.

EDIT: if you do want to go down the zip route, I have a hunk of code you could use that does it. I integrated a class into my smd_skin admin theming plugin that handles the zipping of arbitrary lists of files on the fly. Shout if you want it.

Last edited by Bloke (2008-11-23 13:23:34)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Online

#3 2008-11-26 11:04:26

trenc
Plugin Author
From: Amsterdam
Registered: 2008-02-27
Posts: 571
Website GitHub

Re: yab_download

Hi Stef,

it’s a nice and usefull feature request. The first one I have noticed by myself — after the release. ;)
You can email me the zip route so I can have a look on it. I’ve PMed you with my email address.

But this won’t realised this week. ;)

Offline

#4 2008-11-26 18:35:42

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

Re: yab_download

Very useful plugin. Great work.


Kevin
(graphicpush)

Offline

#5 2008-11-27 13:45:14

trenc
Plugin Author
From: Amsterdam
Registered: 2008-02-27
Posts: 571
Website GitHub

Re: yab_download

It’s done, have fun!

Offline

#6 2008-11-27 18:31:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: yab_download

trenc wrote:

It’s done, have fun!

Holy moly that was tres rapide! Awesome job, will put it on my site next week. Many thanks.

Last edited by Bloke (2008-11-27 18:31:51)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Online

#7 2008-11-27 20:10:41

trenc
Plugin Author
From: Amsterdam
Registered: 2008-02-27
Posts: 571
Website GitHub

Re: yab_download

Bloke wrote:

Holy moly that was tres rapide!

Hm, yes. I’m flattened with a cold these days, so the only thing I can do is some programming. ;)

Offline

#8 2008-11-27 20:36:43

gerhard01
Plugin Author
Registered: 2006-12-07
Posts: 108

Re: yab_download

It’s done, have fun!

Thanks a bunch.

Maybe a bug: I have some files of 30 – 150 kB size. When I set size="MB", file size is displayed as [0.00] MB in the drop-down list. When I set size="KB", file size is displayed correct.

Offline

#9 2008-11-27 22:21:26

trenc
Plugin Author
From: Amsterdam
Registered: 2008-02-27
Posts: 571
Website GitHub

Re: yab_download

Hm, weird!

I’ve tested it on my local dev and the »real world example«-plugin-download. The math with MB works. Do you use a list of single files via ID or via cats attribute?

Offline

#10 2008-11-29 13:42:29

gerhard01
Plugin Author
Registered: 2006-12-07
Posts: 108

Re: yab_download

via the cats attribute – all files of one category without any exclusion.

Offline

#11 2008-12-01 12:20:39

trenc
Plugin Author
From: Amsterdam
Registered: 2008-02-27
Posts: 571
Website GitHub

Re: yab_download

Hi gerhard,

there was a miscalculation of the filesizes in the category listing. Try new version, please! It should works now.

Offline

#12 2008-12-01 21:14:02

gerhard01
Plugin Author
Registered: 2006-12-07
Posts: 108

Re: yab_download

there was a miscalculation of the filesizes in the category listing. Try new version, please! It should works now.

Thanks a lot for the quick fix! Filesizes in MB are calculated correct.

Bug or intended behaviour?: when you try to use <txp:yab_download .../> in the article’s excerpt field, the form is correctly displayed, but does not work for me; upon clicking on “Download”, I just get redirected to

http://article-page#yab_cd_download

Last edited by gerhard01 (2008-12-01 21:14:55)

Offline

Board footer

Powered by FluxBB