DokuWiki DLCount plugin

DokuWiki entry: plugin:dlcount

Installation

Download and install the plugin using the Plugin Manager using the following URL. Refer to :Plugins on how to install plugins manually.

  • Latest version: http://wiki.birth-online.de/_media/software/php/dlcount.tar.gz

Manual download:

How it works

The plugin registers hooks for some events. It creates the meta-files below data/meta/_media/ in the same way DokuWiki does create its meta-data for normal pages.

MEDIA_SENDFILE

This event is triggered when someone downloads a file. First it is checked whether this is a real download or a browser fetching an embedded image. In the latter case, it does nothing.

If this is a real download, it calculates the path to the meta-file. E.g. if someone is downloading http://wiki.birth-online.de/_media/software/php/dlcount_2009-02-03.tar.bz2, the meta file would be:

data/meta/_media/software/php/dlcount_2009-02-03.tar.bz2.meta

This contains a serialized structure which currently only holds an array containing a dlcount key with the actual download count. Maybe later this holds a complete log of all downloads of the file or at least the last 10 IPs downloading it…

The download counter is incremented by 1 and the new data is serialized and written back to the meta file.

If the file doesn't exist, it is created.

TPL_CONTENT_DISPLAY

This event is triggered when a page is displayed. The plugin then wanders all A (=anchor) elements of the page and checks them for the mediafile class which indicates that this link is pointing to a download. Then the path to the meta-file is calculated and the number of downloads read from it. (If this file doesn't exist, a count of “0” is assumed.) In the last step, the count is added after the anchor.

MEDIA_UPLOAD_FINISH

This event is triggered after a new file was uploaded to the media library. If you overwrite an already existing file, the download counts for this file get reset to 0 (because there's now a new file online).

MEDIA_DELETE_FILE

This event is triggered upon deletion of a file from the media library. This will also delete the associated meta data.

Problems

Please report problems on the plugin page of the DokuWiki homepage.

TODO

  • remove empty directories after cleaning up META
  • keep only N most recent entries so that the META file doesn't get bloated

History

2009-02-28, 00:46 CET

  • fixed bug with useslashes and colons instead of slashes
  • fixed bug with glob_recursive() sometimes returning false

2009-02-24, 17:46 CET

  • fixed bug with disabled rewrite but useslashes option, thanks to TMH

2009-02-14, 22:57 CET

  • added Admin interface with statistics (incl. translation for English)

2009-02-10, 00:14 CET

  • Bugfix for DW installations without mod_rewrite
  • noticed that the Plugin Manager doesn't like bz2 archives, so now everything is in gz

2009-02-09, 01:11 CET

  • added display of filemtime() (Last modified/uploaded time)
  • added configuration option

2009-02-06, 22:30 CET

  • added display of filesize
  • added configuration options of what to display

2009-02-06, 00:50 CET

  • added hooks to delete meta when neccessary
  • collect last download time and show it
  • collect some more data (IP, Referer, Browser) of downloading user; not shown for now
  • code cleanup

2009-02-03, 11:33 CET

  • changed DOMDocument parsing to simple preg_matches to fix UTF8 problems
  • small bugfix with substr() and offsets

 
software/php/dw-dlcount-plugin.txt · Last modified: 2009-02-28 00:53.31 by mbirth
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Contents powered by Club-Mate Contents powered by BassDrive.com Labelled with ICRA