Philip P. Ide

Author, programmer, science enthusiast, half-wit.
Life is sweet. Have you tasted it lately?

User Tools

Site Tools


blog:articles:software:doku_dlcounter

DLCounter Plugin

screenshot

Last updated 2019-05-15
Provides Syntax, Action
Author Phil Ide

This download-counter plugin for DokuWiki enables you to keep track of the number of downloads of media files such as zip, gzip, tarballs and pdf's (your choice of media formats). This plugin has been developed and tested on “Greebo”, it may not work with older versions of DokuWiki.

This page is the documentation for this plugin, describing configuration, the syntax for displaying the data (or parts of it) and the on-disk format of the data-store and how to access it from your own (possibly inline) code should you need to.

The data is stored in a folder named 'counts' off the data folder, so it gets backed up when you backup your data folder (you do do that, don't you?).

Installation

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

For manual installation, the latest version of the package can be downloaded hereplugin-autotooltip__default plugin-autotooltip_bigDownloads

Orbital Calculator Current Version This is a portable application, meaning there is no installer. Just unzip into a folder and run the executable. Since it is portable, it can be run from a USB stick.

A full description and a list of the features are available
.

Configuration

Configure the plugin in the admin screen. It's pretty much a doozy, just make a comma-separated list of the file extensions you want to capture download information for. The default is zip,gzip,tar, but you might want to add pdf and possibly a few others. Be careful not to include images and other media that get delivered as part of your web pages, else you'll end up gathering data on a whole bunch of stuff you never intended to.

The extensions should be named without a preceding period, so zip is correct, .zip will be an epic failure.

The plugin only collects information on files delivered from the media library. Super-user rights may be needed to upload large files into the media library. If you are unaware, the primary Admin for the wiki can usually ignore the 2Mb limit on uploads.

Syntax

Collecting all this data isn't much good if you can't use it. You can display the data in a number of ways.

Displaying a counter for a single file

If you just want to display the counter for a single file:

{{dlcounter>file?snow.zip}}

Command: file
Parameter: the name of the file you need data for

This returns a number (which could be zero if it hasn't gathered any data for the file yet). This allows you to bracket the data anyhow you like. The filename should include the list of namespaces, so you might want to check where it is stored in the media manager.

{{dlcounter>file?aardvark:mongoose:chainsaw:snow.zip}}

An example in a more realistic use-case:

..blah blah blah widget.zip (**{{dlcounter>file?software:downloads:widget.zip}}** downloads).

which might output:

..blah blah blah widget.zip (15 downloads).

Note that if you request data for a file that doesn't exist, the plugin returns zero and not an error. It only knows about files that have been downloaded since the plugin was installed, so assumes everything else hasn't been downloaded yet, whether it is a real file or you've typed the name incorrectly or provided the wrong path.

Displaying in Tables

You can also display the data in a table. For this, the command can either be name or count. There are a number of optional parameters to this command which affect the output:

SORTING
sort  => orders the data in ascending order
rsort => orders the data in descending order

FILENAME DISPLAY
left   => left-align the filenames
center => center the names
right  => right-align the filenames

strip => strip the path information to leave just the filename
nobold => do not highlight the filename

COUNTER DISPLAY
minwidth => minimum width of the column
cpad     => left-pad the column with spaces

HEADER DISPLAY
hleft   => left-align the header
hcenter => center the header
hright  => right-align the header

noheader => do not display a header
htext    => set alternate text for header

defaults:
sorting is in natural order (and may therefore change and is unpredictable)
alignment for filenames is right-justified
full path information is displayed
filename is emboldened (to help it stand out from path information)
header is displayed
header is centered
header text is Downloads
minwidth is 0 (meaning it is ignored)
cpad is 1

Note that if you use the strip parameter to remove path information, the filename will still be emboldened unless you use the nobold option.

Sorting is performed on the column named in the command, e.g. if you specify name?sort, the filenames will be sorted, and count?sort will result in the counters being sorted. Sorting on names uses the filename first and the path as a subsort.

Parameters should be separated from each other by a space.

{{dlcounter>name?sort}}        // sort by filename
{{dlcounter>count?rsort}}      // sort by counter in descending order
{{dlcounter>name?strip left}}  // natural order, no path info, left justified
{{dlcounter>name?rsort strip}} // names in descending order, no path info

If you specify contradicting parameters, the rightmost will take precedence. e.g.

{{dlcounter>name?sort rsort}}

…the list will be sorted in reverse alphanumeric order.

When displaying the data in natural order, it doesn't make any difference whether you specify name or count as the command.

An example of table output:

{{dlcounter>count?rsort strip left hleft}}

results in:

Downloads
widget.zip3
exoplanetdata.zip1
archive.zip1

Setting the width of the counter column

For aesthetic reasons, you may wish to set the minimum size of the counter column. To do this, use this syntax:

{{dlcounter>name?minwidth=3}}

It doesn't matter which command you use (name or count).

You can also use the cpad option to adjust the width of the column. Where minwidth only comes into force if no number is as large as minwidth, the cpad option always left-pads the column. Semantically, these two options are the same as:

<td style='min-width: 1em; padding-left: 1em;'>

…where the 1em would be replaced by the values you specify. The numbers are expressed in em, which equates to a full-width character.

To understand how these work together, imagine you have a counter with the value 99, and you have set minwidth=3 and cpad=2. The number is 2 characters wide, therefore minwidth will add a full-width blank space in front of the number. Since cpad is always enforced, it will add two more full-width spaces. This means the cell will in fact be 5 characters wide.

If the number was 1000, minwidth would be ignored, cpad would add two spaces and the cell would be 6 characters wide.

Changing the header text

To specify a different header, use the following syntax:

{{dlcounter>name?htext="This is the new text"}}

You must use double-quotes, not single-quotes, to encapsulate the new header text. There should be no spaces between htext and =, or between = and the text. Quotes are required, even when the new text is a single word.

Accessing Raw Data

If you want to format the data to your own liking, you can fetch the data from the file data/counts/download_counts.json off the root of the DokuWiki installation. You should use file_get_contents() to open, read and close the file as quickly as possible.

$fname = DOKU_INC."data/counts/download_counts.json";
$assoc = json_decode( file_get_contents($fname), TRUE ); // fetch data as an associative array
$json  = json_decode( file_get_contents($fname) );       // fetch the data as a json object

The data is stored in simple key/value pairs with (surprise!) the filename being the key. The filename includes the path information in colon-separated format: path:to:filename.zip

Caveats

Note the plugin can't actually tell if a file was downloaded. If someone clicks the link to download a file, and then clicks cancel on the Save As… dialog, the plugin will never know. All it can do is register the click that initiates the download (no event is generated for successful delivery).

This actually makes it easy to test. Click a link to download and cancel on the Save As dialog, and repeat this a few times to generate some stats for yourself. When you're done testing, navigate to the counts folder as outlined above and delete the download_counts.json file to reset.

Additional Information

The plugin will automatically create the data/counts folder if it doesn't exist. It sets the folder permissions to 0755 for operating systems that support it. If you want other permissions, you can either create the folder ahead of installing the plugin, or change the permissions using your favourite tool after it has been created. Just make sure you don't deny DokuWiki access or read/write permission to it, else there will be tears.

The folder is created when it is needed, so won't be created until someone downloads something.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
blog/articles/software/doku_dlcounter.txt · Last modified: 2019/05/20 15:55 by Phil Ide

Except where otherwise noted, content on this wiki is licensed under the following license: Copyright © Phil Ide
Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki
  • ISSplugin-autotooltip__default plugin-autotooltip_bigInternational Space Station

    This page has a portal through which you can view the current location of the International Space Station, updating in real-time. The tracker itself comes from the European Space Agency (ESA).

    There is also a handy link to get email notifications direct from NASA when the ISS is visible in your night sky.
  • Mars Weatherplugin-autotooltip__default plugin-autotooltip_bigMars Weather

    Weather Reports Insight Lander Perseverance Rover Curiosity data to come Follow Conjunctions as they occur.

    Martian Day

    The Martian day is 39 mins 35.244 secs longer than a standard day. This means that approx every 36.1 days the Earth weather date skips a day while the Martian Sol marches on as normal. You can see this in the Insight data. April 16th 2019 seems to be missing, yet the Sols on April 15th and April 17th are consecutive.
  • Downloadsplugin-autotooltip__default plugin-autotooltip_bigDownloads

    Orbital Calculator Current Version This is a portable application, meaning there is no installer. Just unzip into a folder and run the executable. Since it is portable, it can be run from a USB stick.

    A full description and a list of the features are available
  • Orbital Calculatorplugin-autotooltip__default plugin-autotooltip_bigOrbital Calculator

    I needed to calculate orbital characteristics for any orbit around any gravitational mass (because I write sci-fi stories), so I wrote this program because I'm a programmer and I'm too lazy to do it by hand all the time. The program has expanded over the last few years, sometimes from suggestions by other writers. I make it freely available and as simple to use as possible. It now has a list of functions as long as your arm (assuming you're not a tentacle user), and the numbe…
  • Cookie Policy & GDPRplugin-autotooltip__default plugin-autotooltip_bigCookie Policy & GDPR

    There are NO tracking cookies on this site!

    The Cookie policy is straightforward. This site only uses cookies that are required to make your experience of using this site better, and only uses session cookies (see exceptions below). Session cookies are deleted when you close your browser.
  • Book Reviewsplugin-autotooltip__default plugin-autotooltip_bigBook Reviews

    Here you can find all the book reviews, broken down by genre, and further subdivided by author. If you want me to review your novel, please read my Rules on Reviewing.

    * Science-Fiction * Fantasy * Non-Fiction
  • Contactplugin-autotooltip__default plugin-autotooltip_bigContact

    If you have a burning desire to contact me, use the discussion form below. Anything you say remains private between you and me.