jidd

Jim Isaacs Design & Development

WP File-Tree

Posted by: Jim Isaacs
July
14th
2008

Using shortcode and templates, post any file from a secure web directory with mod_rewrite enabled links to view and download.

Plugin URI: http://wordpress.org/extend/plugins/wp-file-tree/
Latest version: Download

WP File-Tree is something that I have been working on to help in my own development.

There are tons of code-snippet, formatting, and coloring plugins out there. There are even a few file management plugins. What there is not, is something that combines them into one useful tool. I am talking about something like a script library manager, but also something that can be used to post ANY file. With this major goal in mind I started from the basics to build something on top of. What would be very useful from a developer standpoint, is getting my scripts out of their multiple locations and backups into one centralized location. Then post them to the world, all while using WordPress. The shortcode that WP File-Tree uses is the basis of how it streamlines this process.

So far, there are 4 plugin options:

Base Directory
The most important, and is exactly what it says, the root directory for WP File-Tree. It can be an absolute server path, or a relative path from your WordPress root directory. The important thing to note is that it can, and actually should be, outside of your web accessable ‘htdocs’ directory on your web space. That is one of the points of this plugin, to be able to post files from a secure location on your web server.

There are 2 links to files the plugin uses. One is a URL to the file itself which loads it as your browser supports the mimetype. The second is a forced download link, which is almost the same as the first with additional headers.

The remaining 3 options control how these links work, similar to how WordPress sets permalinks. There are 2 choices for the option of link type, ‘default’, and ‘mod_rewrite’. Default simply uses query variables, while mod_rewrite actually modifies your .htaccess file independantly of WordPress rewrite rules which may have already been added.

Important note: For the rewrite rules, I found it was best to keep things separate from WordPress, because there is not much documentation on controlling the rewrite rules as far as .htaccess level, and there are still of view bugs on the WordPress side of this functionality. For the future releases, my plugin’s mod_rewrite rules will most likely change by becoming completely integrated with WordPress hooks, actions, and filters. For now, just for safety, make sure you activate your WordPress permalinks before activating the plugin’s.

Finally, the last two options are the link slugs, which are the base of the URL’s if the mod_rewrite type is active.

That about covers the options, now onto the shortcode.

The shortcode is fairly simple, but powerful.
It is all based around 2 tags – [ file ] and [ vfile ]

The ‘file’ tag is a simple file link using attributes for the functionality:

[file path="php/wordpress/plugins/wp-file-tree/example.txt" tpl="text" /]

When parsed, it would look like this:

This is an example text file.
Hello World!!!

Here is what is going on:
First the plugin uses the ‘path’ attribute as a file path relative to the base directory to read the contents of the file example.txt into a variable, and then those contents are sent to the chosen display template named ‘text’.

Templates are how all files are displayed within posts. There is no limit to how many you can have, and there is virtually no limit as to what you can do with them. Their format is similar to how WordPress themes are dealt with and edited. The ‘tpl’ attribute is optional because the the plugin will attempt to choose the appropriate template based on the file’s extension given in the ‘path’ attribute.

The ‘vfile’ tag uses inline content:

[vfile path="inline_example.txt" tpl="text"]This is example inline content typed directly into the post. Hello World!!!
[/vfile]

When parsed, it would look like this:

This is example inline content typed directly into the post.
Hello World!!!

In this example, the exact same attributes are used as in the first example, but instead of the plugin using the ‘path’ as a reference to read the contents of the file, instead this it is an arbitrary value to name a virtual file, and the content of the tag is substituted as the content of the virtual file. So in the end, the content is displayed in the exact same way the content of the previous real file was displayed within ‘text’ template.

Yes you can even link to, and force download virtual files, but this requires special inline templates to safely post the contents of virtual files. Posting content is the only way to download and link to virtual files.

Something also important to note is a shortcut within the shortcode. The ‘tpl’ attribute may actually be a list of templates in order to string multiple templates together for the same content. An example would be something like this:

[file path="php/wordpress/plugins/wp-file-tree/example.txt" tpl="link,text,download" /]

When parsed, it would look like this:

example.txt
This is an example text file.
Hello World!!!
example.txt » download

Notice that first a link is generated by the ‘link’ template, then the content is displayed in the ‘text’ template, and then a download link is generated by the ‘download’ template. Stringing together templates like this not only saves you time, but most importantly server resources. It allows the plugin to use the data already gathered by parsing the shortcode and simply inserts that data into multiple template objects.

There is much more you can do with the attributes of these tags, possibilities go on and on. I don’t want to post everything here, but I will instead insist that you download the plugin and check it out yourself. While not forgetting to give me any comments or suggestions. You may download the latest version of WP File-Tree here.

DOWNLOAD LATEST VERSION »

Hopefully you will find as much use for it as I have.

There really is more to come!
I would like to:
Create a media tab with an intuitive interface to aid in automatically generating the shortcode while writing posts.
Give more options to control the links to files.
Integrating the mod_rewrite rules with WordPress using the already defined hooks.
Provide more and more templates for all sorts of different uses.

Happy happy joy joy!

5 Responses to “WP File-Tree”

  1. best wordpress themes…

    I have seen lots of article directories running on wordpress. Is there a special plugin for this?…

  2. I am going to make believe this isn’t spam because sites linking to each other is what the web is for right?

    Anyway, if this is a legit question. I hope you are talking about Categories, these are your “Article Virtual Directories”.

    You can name your Categories anything you want, and actually rename “Categories” to “Articles” if you prefer.

  3. You should realy make a installation manual and a description of this plugin which is more understandable for people. After I red lots of text, I don't even understand what this plugn in does :(

  4. Oscar

    I have downloaded the plugin but then I have not idea how to set it up. Honestly, I don't understand your installation process and plugin dashboard.

  5. I have stopped development on this plugin because well…
    It was even too complicated for me to continue. I still like the ideas and techniques I used for this plugin initially, but yes I got overwhelmed and development just stopped.
    I want to thank even still if you downloaded it, I promise any other plugins I write will have a much more focused goal in mind. ;)

Leave a Reply

info@jimisaacs.com
Bear