Download Manager

Theming the Download Nodes

If you've been going in order, the "Downloads" node is up and essentially working.  It just doesn't look like you might expect it to just yet.  This next section will delve into how to theme the downloads, allowing you to essentially duplicate the DOCman appearance.

Since we want the download nodes to have their own styling, we will need to make some changes to the template files to allow specific templates for a view.

Setting up the Downloads Node and View

The most important thing to do in order to create the download manager is to create a node and view for the download content type.  This section will cover the technical aspects of the setup, and is essential to having this work.  In fact, this section alone will create a working download manager, but it won't have the visual appearance of DOCman yet.

Module Installation

Disclaimers

Modifying Code Template Files

By default, any styling we try to perform on the download nodes will affect all other nodes as well.  This probably isn't what we had in mind, so let's correct that.

Note: In this tutorial, I am using the standard Garland theme, but the process should be the same for others.

Layout the Node's Fields

We are coming along.  So far, we can theme the download nodes as we like, but the layout isn't quite how I'd want it.  We need to create a new template file named views-view-fields--<view_tag_name>.tpl.php, or views-view-fields--downloads.tpl.php.  Note that I changed the name for the view tag to "downloads" as opposed to the singular "download" that we used for the node type.  This isn't necessary, and you may keep them consistent.  This file is actually a copy of views-view-fields.tpl.php, which is located in the modules/views/theme

Customizing the CSS

All that's left to do now is to create CSS styles to control to look of the download nodes.  This is where a browser add-on, such as "Web Developer" for Firefox comes in quite handy.

Creating the Document Content Type

Once the necessary modules are installed, it is time to setup the content type for the documents.  This is how we will add files to the download manager.

Basic Settings

Go to Administer->Content Management->Content Types and choose "Add Content Type."  Enter a name for the content type (for this tutorial, I will use "Downloads" for the name, and "downloads" for the type, but you can use anything.)  If desired, enter a description for the type to assist you or other users in the future.

Creating a download manager in Drupal

It seems as though when it comes to providing a decent download manager in Drupal, there just isn't much there.  Joomla has DOCman, which is truly excellent.  Drupal has... ummm... yeah.  There are modules such as dbFM and WebFM, which are very nice, but they are more like an OS's file manager than what I consider a download manager to be.  I guess I should explain what I consider a download manager to consist of:

  • Categorization of files -- When added, a file can be tagged with one or more keywords to make it possible to group them together.
  • User-friendly information about the file in the listing -- When viewing a list of files, it should provide more than just a file name (which doesn't need to be shown at all, really.)  Ideally, it will have a brief name for the file as a title and a description of the file that explains more in depth as to what the file is.  It might also show the file size, date it was added, date of last modification, and a download count.  It could also display a file-type icon, as the following example of DOCman from http://www.joomlapolis.com shows:

     
     

  • Distinguish the files -- This could be as simple as having a space or line between file entries, or there could be different colors for the even and odd entries.

These are some of my requirements.  The big thing for me is to have a nice layout which uses user-friendly names and descriptions.  The idea is that the general public needs to be able to know what they are getting, and filenames (usually) aren't the best way to express that.

While Drupal does not have an immediate "set-it-and-forget-it" module to do this, the beauty of Drupal is that it is quite customizeable, and can be made to do just about anything we want.  In this document, I will attempt to walk through how to mimic much of DOCman's behavior in Drupal, using common modules.

Create the Download View and Add to Menu

Assuming we want to have the download manager accessible from the menu, we need to setup a view for the content type.  Go to Administer->Site Building->Views, and click "Add" at the top of the page.  Enter a name (ie. "downloads") and (optionally) a description ("Collection of files available for download") and a tag ("downloads") for this view.  Leave the type as "Node" and click "Next."

We now have a fairly complicated looking page.  Don't despair, we'll get through this.

Copy page.tpl.php to page-downloads.tpl.php

We need to specify a custom template for download pages.  Make a copy of the template file "page.tpl.php" and rename it to "page-<node_type>.tpl.php," where <node-type> is the name we gave to the node type when we created the content type.  In our case, we would name the file page-download.tpl.php.

Open the new file in a text editor.  Around line 69 (just after the mission) add a new line and add

Syndicate content