Till Krüss’s Pepper

Downloads Pepper: Documentation

Installation

Installing Pepper

  1. If you have orderedlist’s “Download Counter Pepper” installed, uninstall it.
  2. Upload the /downloads/ directory and its contents to /mint/pepper/tillkruess/. If the directory /tillkruess/ doesn’t exist, create it.
  3. Login to your Mint installation and in the Preferences click “Install” under Pepper.
  4. Click the Downloads Pepper “Install” button. Click “Okay”.

Updating Pepper

  1. Delete the /downloads/ directory on the server.
  2. Upload the /downloads/ directory and its contents to /mint/pepper/tillkruess/.

Tracking Methods

Method 1: Manual Redirect

Redirect those files that you want to track to the tracker.
Example: http://minteddomain.com/mint/pepper/tillkruess/downloads/tracker.php?url=http://minteddomain.com/archive.zip
If you want to track files that are not on your local server, or your Mint installation is on a subdomain use the &remote query command.
Example: http://mint.domain.com/pepper/tillkruess/downloads/tracker.php?url=http://domain.com/archive.zip&remote
Example: http://minteddomain.com/mint/pepper/tillkruess/downloads/tracker.php?url=http://anotherdomain.com/archive.zip&remote

Note: If the file extension isn’t listed in the Pepper’s preferences, the tracker won’t count the download.
Note: If you’re using the &remote parameter, you have to enable remote file tracking in the Pepper’s preferences.
Note: The uri parameter has been renamed to url in Downloads v2.2.

Method 2: Automatic Redirect

Enable the automatic redirection in the Pepper’s preferences and set the file extensions that you want to get redirected.

Note: The script considers the “Site Domain(s)” in preferences.
Note: The script doesn’t work in older browsers like Netscape 4 and Explorer 5 Mac.

Method 3: Advanced Redirect

The base of this method is Apache’s mod_rewrite module, the &force (and &inline) or &remote query command and a .htaccess file.

Example 1: Redirect all file requests in this directory and subdirectories, if the requested file exists.

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ http://minteddomain.com/mint/pepper/tillkruess/downloads/tracker.php?url=http://%{HTTP_HOST}%{REQUEST_URI}&force

Example 2: Redirect only file requests that end with .zip, .rar or .tar.gz in this directory and subdirectories, if the requested file exists.

<FilesMatch "\.(zip|rar|tar\.gz)$">
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule ^(.*)$ http://minteddomain.com/mint/pepper/tillkruess/downloads/tracker.php?url=http://%{HTTP_HOST}%{REQUEST_URI}&force
</FilesMatch>

Example 3: Redirect file requests in this directory and sub-directories that end with .mp3 or .pdf, and “display” them inline.

<FilesMatch "\.(mp3|pdf)$">
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule ^(.*)$ http://minteddomain.com/mint/pepper/tillkruess/downloads/tracker.php?url=http://%{HTTP_HOST}%{REQUEST_URI}&force&inline
</FilesMatch>

Note: Use the &force parameter to avoid an infinite loop.
Note: Use the &inline parameter to set the Content-Disposition from attachment to inline.
Note: If RewriteEngine On isn't inside the <FilesMatch> directive, subdirectories won’t be affected.
Note: If you’re using the &remote parameter, you have to enable remote file tracking in the Pepper’s preferences.
Note: The uri parameter has been renamed to url in Downloads v2.2.

Modules

phpBB3 module

To track attachment requests, setup the absolut path to root of your phpBB3 installation in
/mint/pepper/tillkruess/downloads/modules/phpbb3/config.php and create a .htaccess file in /phpBB3/download/ with the following contents.

RewriteCond %{QUERY_STRING} !avatar
RewriteRule ^file.php$ http://minteddomain.com/mint/pepper/tillkruess/downloads/tracker.php?%{QUERY_STRING}&type=phpbb3

External Data Access

The following code displays the five most downloaded files.

<?php

  $_link = mysql_connect('localhost', 'username', 'password');
  mysql_select_db('database', $_link);

  $result = mysql_query('SELECT url, size, hits FROM mint_files ORDER BY hits DESC LIMIT 0, 5', $_link);

  print '<table border="1"><tr><th>File</th><th>Bytes</th><th>Downloads</th></tr>';
  while ($row = mysql_fetch_assoc($result)) {
    print '<tr><td>'.$row['url'].'</td><td>'.$row['size'].'</td><td>'.$row['hits'].'x</td></tr>';
  }
  print '</table>';

?>

The following code displays the the hits of the first file that is ending with “somefile.zip”.

<?php

  $_link = mysql_connect('localhost', 'username', 'password');
  mysql_select_db('database', $_link);

  $result = mysql_query("SELECT hits FROM mint_files WHERE url LIKE '%somefile.zip' LIMIT 0, 1", $_link);

  $row = mysql_fetch_assoc($result);
  print 'This file has been downloaded '.$row['hits'].' times.';

?>

Note: The uri column has been renamed to url in Downloads v2.2.