Drain Hole Plugin

Jun 12, 2006 | Tags: , , , , | Written by Administrator

Drain Hole is a centralized download manager, with full monitoring and statistics, versioning, SVN support, and SEO download URLs (no more nasty query strings!).

In addition to it's monitoring abilities, Drain Hole has a run-time tag replacement feature that lets you embed special tags in your post which are replaced with information from Drain Hole. For example, you can embed download URLs, version information, last update times, and so on. Whenever you change a downloadable file it is automatically updated throughout your blog, without you needing to change anything else.

Features include:

  • SEO download URLs - a unique feature that allows files to look like real links
  • SVN support - attach a file directly to an SVN repository and have the contents automatically updated
  • Versioning - maintain multiple versions of a file, allowing users to download older files
  • Full download statistics, including number of downloads, access times, referrer, and download speed, available as CSV and Flash-based graphs
  • Download security - permissions can be assigned to downloads (including Flash files), restricting them to WordPress roles
  • Template tags - insert dynamic download data into posts, and into the sidebar as a Widget
  • Hot-link protection
  • Fully localized

Version History

  • 2.1.12 - Allow for sites with open_basedir restrictions
  • 2.1.11 - Update plugin base class
  • 2.1.10 - Add file modification time
  • 2.1.9 - Fix problem with truncated URLs on some sites
  • 2.1.8 - Fix typo in mime type
  • 2.1.7 - Fix spaces in version numbers
  • 2.1.5 - Better custom 2.6 support
  • 2.1.4 - Scanning fix

Installation

Installation is like any WordPress plugin:

  • Download drain-hole.zip
  • Unzip
  • Upload drain-hole directory to /wp-content/plugins on your server
  • Activate the plugin
  • Use Drain Hole from the Manage/Drain Hole menu

You can find full details of installing a plugin on the plugin installation page. SVN access to the plugin is provided at the SVN repository.

General Concepts

The Drain Hole plugin makes use of two fundamental concepts:

  • Drain hole - a base URL and associated directory where files are stored and downloaded from
  • Files - a file belongs to a particular Drain hole

It is important to understand the mapping between a Drain Hole's URL and its associated directory. To do this you need to know two pieces of information:

  1. Where files are to be downloaded from (i.e. http://urbangiraffe.com/download/)
  2. Where files are to be stored (i.e /users/john/download/)

This is a mapping from URL to directory:

http://urbangiraffe.com/download/ => /users/john/download/

All files inside the directory will be available at the Drain Hole URL. For example:

/users/john/download/myplugin.zip => http://urbangiraffe.com/download/myplugin.zip

It is preferable that your directory is not in a public location (i.e. in public_html) as Drain Hole may not then be able to function. Your URL must be part of your WordPress installation, but you should not create a directory for it.

Creating a Drain Hole

New Drain Holes require the following information:

New Drain Hole

The URL is the URL on your website at which to make the files available. The directory is the real directory in which the files exist. These two values do not have to match up and the files do not (and ideally should not) be publicly available.

Once a Drain Hole has been created you can then edit it from the list of Drain Holes:

Drain Holes

Editing a Drain Hole will allow you to set additional options:

Edit Hole

The Access Level is the minimum user level required to download files from the hole. This allows you to restrict download access to certain types of user. If a user does not meet the required access level then they will be returned a 404 error page or will be redirected to the configured URL.

The Stop Hot-links option allows you to stop external users from downloading files in the hole. This protection is achieved by analyzing the referring page for a given download - if the referrer is not from your site then the user is sent a 404 error page or redirect to the error URL.

Files

A Drain Hole can contain any number of files and sub-directories.

Files

As with the rest of the plugin, columns are sortable, and data can be searched.

Each file allows you to:

  • Edit the file configuration
  • Manage version history (by clicking on the version number)
  • View download statistics (by clicking on the number of hits or the charts link)
  • Create a new version or update from SVN (by clicking on the branch link)

When editing a file you will be shown additional configuration details:

Edit File

The filename is the actual name of the file and this may differ from the name, which is what will be shown in a download link. If no name is given then the filename will be used. As an extra function, you can insert $version$ into the name and it will be replaced with the file's current version.

The description is a free-form field allowing you to enter further details about the download. This can be shown when the file is displayed.

The SVN field allows you to enter an SVN repository. See the SVN section later.

When displaying a file to download, an icon can be shown. You can change which icon is shown when editing a file.

The MIME type allows you to specify a custom MIME type for the file. This may be useful if you want a file to open inside the browser. If set to 'automatic' then Drain Hole will try and decide what the file is.

Forcing a download allows you to override default browser behaviour and force the file to always be downloaded. This is useful if you have a file that a browser usually tries to open (for example, a PDF), but you want it to always be downloaded.

Forcing the access level is an advanced option that is useful if you are trying to restrict files that are used inside Flash. For example, you may have a video tutorial that you want to restrict to registered users only. The flash video player requires your video file to be available, but may not provide any restriction options. Storing the video inside Drain Hole and then forcing the access level will ensure that only allowed users can access the file, even inside Flash.

Adding new files

New files can be added by any of these methods:

  • Uploading a file directly into the Drain Hole directory and 'rescanning'
  • Uploading a file through the browser
  • Creating an empty file which can be uploaded later, or which requires an SVN repository
Add File

Versions

Drain Hole allows you to retain old versions of files, either for archiving purposes or for user downloads. To modify a file's version you need to create a new branch:

Branch

You can enter details about the reason for the new version, and this will be presented to the end user. To retain an old version you must check 'retain old version'. This old version can be downloaded as follows:

http://urbangiraffe.com/download/myplugin.zip?version=1.2

SVN

Drain Hole provides simple SVN functionality that allows you to associate a file with an SVN repository. A file that uses SVN can then be 'refreshed' directly from the SVN repository, rather than requiring you to manually update the file.

SVN functionality requires that you have SVN installed on your host. You must configure the Drain Hole options and provide the full path to the svn executable. If you are in doubt you should consult your host for details.

When an SVN-based file is refreshed, Drain Hole will use SVN to retrieve the latest copy of the files. If a repository contains multiple files they will be automatically zipped.

As additional functionality, Drain Hole will detect if the SVN repository is for a WordPress plugin, and will automatically set the version according to the version information inside the plugin.

Note that no direct capabilities are provided for username and passwords. However, you can pass a username and password to SVN by including it on the SVN field:

http://svn.mysite.com/plugin/trunk/ --username=john --password=thing

Download Tags

The following tags can be inserted inside posts and pages to embed Drain Hole information. This information is generated dynamically, and will change whenever the underlying information changes:

  • [drain hole ID hits] - Displays the total number of hits from the specified hole ID
  • [drain hole ID show] - Show a list of all files in the specified hole (change display code by copying view/drain-hole/show_hole.php from the Drain Hole plugin directory to the same directory path in your theme's directory and editing the file)
  • [drain file ID show template] - Displays the download template for the specified file ID. 'template' is optional and can be ignored (the default template will be used)
  • [drain file ID version] - Displays the version of the specified file
  • [drain file ID versions limit] - Displays the specified number of versions from the file's history
  • [drain file ID hits] - Displays the total downloads for the specified file
  • [drain file ID url name] - Displays a URL allowing the specified file to be downloaded. 'name' is optional and is the text that will appear inside the download link (if not specified then the filename is used)
  • [drain file ID updated] - Displays the update time of the specified file
  • [drain file ID size] - Displays the size of the specified file
  • [drain file ID icon] - Displays the download icon for the specified file
  • [drain file ID href] - Displays the URL of the file

Where ID refers to the ID of the file or hole, as shown in the Drain Hole administration pages.

Download Templates & File Icons

A download template is a section of HTML code that is used to display all the information for a file download. For example, on this page in the top right corner is the download for Drain Hole itself. The icon and file information are all part of a download template that is re-used on each of the other plugin pages available from this site.

A download template is a file that is stored in your theme directory and contains standard HTML as well as special Drain Hole template tags:

  • $icon$
  • $url$
  • $version$
  • $updated$
  • $size$
  • $href$

These template tags function similar to the post & page tags, but do not require an ID to be specified.

A default template is provided with Drain Hole. Custom templates are PHP files that are stored in view/drain-hole, inside your theme directory. For example, if you are using the default WordPress theme then:

  /wp-content/themes/default/view/drain-hole/mytemplate.php

To use this template in a post you would insert the tag:

  [drain file 5 show mytemplate]

This tells Drain Hole to use 'mytemplate.php' to display file 5.

Custom icons can be stored inside your theme:

  /wp-content/themes/default/view/drain-hole/icons/

Statistics

Drain Hole provides full download statistics:

Statistics

FAQ

If you have any questions or problems then please consult the Drainhole FAQ before posting here.

Support

Please direct all support questions to the Drain Hole support forum. Any support questions left on this page may not be answered.

Bugs & New Features

A full list of all bugs can be found in the Drain Hole issue tracker.

Date Current outstanding bugs Status
19 Nov 2008 Error 404 & Chart timeout

A full list of all requested features can be found in the Drain Hole feature tracker.

Date Current requested features
14 Sep 2008 Multi-stage download
07 Oct 2008 Paypal access
03 Nov 2008 limited access to drain hole(s)
08 Nov 2008 Link to Amazon S3
Share This

Comments (page 13 of 31)

  1. George Appiah :

    Nov 18, 2007 1:11 am

    I finally managed to get Drain Hole working (to some extent) on WordPress 2.3.1, after struggling with 404 errors for several hours. I think the sleep must have done the magic. I think I caught myself dreaming about how I was going to get Dream Hole working after I got up :-)
    For those of you still struggling with the dreaded 404 problem, try disabling the hot-link protection! This seem to be broken. If you've setup everything else properly, disable the hot-link protection and see if it works. That's what worked for me (even though this is something I really need).

    For Daniel (Author):

    I think you could save yourself the many repeated requests and problems being reported by updating the plugin's page above. You've done a great deal of work to incorporate many requests from users, but one has to read all the 130 comments down here to get to the "state of affairs".

    For instance, the Redirection plugin is not required at all, but I only found this all the way down in comment #52, and that was after installing the Redirection plugin and struggling unsuccessfully to configure it.

    Also the new template tags are not documented anywhere at all. By trial and error (I don't speak code!), I found I could display the description (with $desc$ tag) and the download counter (with $hits$ tag) directly in the CUSTOM TEMPLATE file... but these are not mentioned in your list of "special Drain Hole template tags" at all.

    Anyway, thanks a million times or this great plugin.

    And to everyone please forgive my poor grammar. English is my third language.

  2. Lee :

    Nov 17, 2007 7:10 pm

    Okay I've discovered what may be the problem:

    In WP 2.3.1 and version 2.0.10 of drain hole, it is only allowing for the "url" and the "directory" to be exactly the same in relation to its context. As Drew mentioned previously (with my minor modifications),

    Set "URL" --> relative to your wordpress install (i.e. http://www.example.com/wp/) so in the "URL" field, put /wp/downloads/ - where "downloads" is a folder you create.

    Set "Directory" --> relative to the server absolute path to the folder you created (i.e. /home/username/public_html/wp/downloads)

    Now, that that's established, it will work if you do that, BUT your files will become vulnerable and anyone can just copy and paste the location in any browser and start downloading your hidden files.

    If you change the "directory" location of the files, it fails to work again.

    What I have discovered is that the script is not REDIRECTING at all. It only provides the DIRECT link to the download.

    So with that said, is there anyway to fix the area of the script that's hindering redirection? If so, how?

    Trying to help,
    Lee

    P.S. - I'm not sure if this is happening to anyone else, but I know how frustrating it is if this is happening to you.

  3. Lee :

    Nov 17, 2007 4:14 pm

    I'm having the 404 error with WP 2.3.1 also. I have tried pretty much everything on this page to get it to work with 404 errors, but I still can't get it to work.

    Everything displays fine until I click on the link it creates, then its nothing but 404 errors.

    Has anyone having the 404 error with WP 2.3.1 got this to work? If so, what was your solution? This is really frustrating seeing how great this plugin is.

    I've spent several hours trying to figure out the problem with no solution.

    Please HELP!

    Lee

    P. S. - I use BLUEHOST as my webhost.

  4. Erik Ringmar :

    Nov 16, 2007 6:08 pm

    Hiya,

    Thanks for your hard work. I can't seem to activate the plugin. I get the following error message:

    Fatal error: Call to undefined function wp_enqueue_script() in /var/www/imbloggingthis/wp-content/plugins/drain-hole/drain-hole.php on line 79

    What to do?

    yours,

    Erik

  5. Rirath :

    Nov 13, 2007 11:12 pm

    Commenting out:
    DH_Access::finished ($id, $this->filesize ($hole, $version));

    Seems to solve the errors after using Open in IE, however it's obviously not desirable to do so. It does give a pretty good idea where the problem is, though.

  6. Rirath :

    Nov 13, 2007 11:05 pm

    Commenting out the following line in file.php:

    header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1

    Seems to solve the IE problem somewhat. However, force download will be broken on the next download attempt, and I get MySQL errors popping up rather than pages if I surf to another page, like so:

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
    SELECT *,NOW() AS now FROM wp_drainhole_access WHERE id=

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
    UPDATE wp_drainhole_access SET speed=13914, time_taken=0 WHERE id=

  7. Rirath :

    Nov 13, 2007 8:33 pm

    Whenever I use Internet Explorer 6 or 7 and choose Open rather than Save As, the file is corrupted. This happens on .wsz (winamp skins) as well as .jpg with force download. Firefox works fine in both cases.

  8. Tomsn :

    Nov 13, 2007 3:40 pm

    Hi John, so am i understod u right, the .htaccess has to be in /where/is/my/dlfile or has it to be in www root dir?

  9. John (author) :

    Nov 12, 2007 6:42 pm

    As per the documentation above, your download directory should not be in your public_html area. If it is in your public_html area then Drain Hole tries to create a .htaccess file to protect your files (they are publically available) and to record statistics. If Drain Hole cannot create this file (maybe due to write permissions) then no downloads will be recorded as Drain Hole is not being activated on a download. To add this file yourself create .htaccess in the download directory:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ /path/to/wordpress/index.php
    </IfModule>

  10. Paul :

    Nov 12, 2007 2:21 pm

    Two more questions:
    1) Drain Hole doesnt count the file download statistics, how can I make it work?
    2) The graph stats are not displaying any stats, how can I make them work?

    Thank you :)

Leave a comment


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Home | Software | Terms & Conditions | Sitemap | John Godley © 2008
Close
E-mail It