Revision: 35371
          http://brlcad.svn.sourceforge.net/brlcad/?rev=35371&view=rev
Author:   ebautu
Date:     2009-07-29 14:47:39 +0000 (Wed, 29 Jul 2009)

Log Message:
-----------
Lightweight download counter custom made module (works with private and public 
downloads)

Added Paths:
-----------
    web/trunk/htdocs/more/sites/all/modules/light_download_count/
    web/trunk/htdocs/more/sites/all/modules/light_download_count/README.txt
    
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.info
    
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.install
    
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.module

Added: web/trunk/htdocs/more/sites/all/modules/light_download_count/README.txt
===================================================================
--- web/trunk/htdocs/more/sites/all/modules/light_download_count/README.txt     
                        (rev 0)
+++ web/trunk/htdocs/more/sites/all/modules/light_download_count/README.txt     
2009-07-29 14:47:39 UTC (rev 35371)
@@ -0,0 +1,31 @@
+ This is a very light download counter. It works for private downloads and can 
also count
+ public downloads if the following lines are added in the Rewrite section of 
the site's
+ .htaccess file:
+ 
+ RewriteCond %{QUERY_STRING} =""
+ RewriteCond %{REQUEST_URI} ^/files/
+ RewriteRule ^(.*)$ index.php?q=download_count&file=$1 [L,QSA]
+ 
+ The download counter value for each file is saved in the files table along 
with the file's
+ information. There is no user interface. If you want to display the download 
counter value
+ you'll have to update your themeing functions and include the download field 
of the file
+ array. For example, for the filefield module, this will be something like 
this:
+ 
+ function phptemplate_filefield($file) {
+  $output = '';
+  if (user_access('view filefield uploads') && is_file($file['filepath']) && 
$file['list']) {
+    $path = ($file['fid'] == 'upload')
+            ? file_create_filename($file['filename'], 
file_create_path($field['widget']['file_path']))
+            : $file['filepath'];
+    $output = '<div class="filefield-item">';
+    $output .= theme('filefield_icon', $file);
+    $output .= l($file['description'], file_create_url($path));
+    // include the download counter value
+    if(isset($file['downloads'])) {
+      $output .= ' (' . format_plural($file['downloads'], '@count download', 
'@count downloads') . ')';
+    }
+    $output .= '</div>';
+  }
+  return $output;
+}  
+


Property changes on: 
web/trunk/htdocs/more/sites/all/modules/light_download_count/README.txt
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Added: 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.info
===================================================================
--- 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.info
                              (rev 0)
+++ 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.info
      2009-07-29 14:47:39 UTC (rev 35371)
@@ -0,0 +1,3 @@
+name = Light download count
+description = "Increments a download counter for each file and logs a 
descriptive message each time an attached file is downloaded."
+version = "5.x-1.0"


Property changes on: 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.info
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Added: 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.install
===================================================================
--- 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.install
                           (rev 0)
+++ 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.install
   2009-07-29 14:47:39 UTC (rev 35371)
@@ -0,0 +1,15 @@
+<?php // $Id$
+
+/**
+ * Implementation of hook_install
+ */
+function light_download_count_install() {
+  db_query('ALTER TABLE {files} ADD COLUMN downloads INTEGER NOT NULL DEFAULT 
0');
+}
+
+/**
+ * Implementation of hook_uninstall
+ */
+function light_download_count_uninstall() {
+  db_query('ALTER TABLE {files} DROP COLUMN downloads');
+}


Property changes on: 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.install
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Added: 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.module
===================================================================
--- 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.module
                            (rev 0)
+++ 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.module
    2009-07-29 14:47:39 UTC (rev 35371)
@@ -0,0 +1,67 @@
+<?php // $Id$
+
+/**
+ * @file Light download count modules counts the download of each attached 
file.
+ */
+
+/**
+ * Implementation of hook_help()
+ */
+function light_download_count_help($section) {
+  switch ($section) {
+    case 'admin/modules#description':
+      return t('Increments a download counter and logs a descriptive message 
each time an attached file is downloaded.');
+  }
+}
+
+/**
+ * Implementation of hook_menu()
+ */
+function light_download_count_menu($may_cache) {
+  $items = array();
+
+  if ($may_cache) {
+    $items[] = array(
+      'path' => 'download_count',
+      'callback' => 'light_download_count_public',
+      'access' => true,
+      'type' => MENU_CALLBACK,
+    );
+  }
+  return $items;
+}
+
+/**
+ * Increases the download count and adds a watchdog messages.
+ * @param $local_filepath file path inside the Drupal's files directory.
+ */
+function _light_download_count_download($filepath) {
+  db_query('UPDATE {files} SET downloads=downloads+1 WHERE filepath="%s"', 
$filepath);
+  if(db_affected_rows()) {
+    watchdog('download', t('%file was downloaded', array('%file' => 
$filepath)), WATCHDOG_NOTICE);
+  }
+}
+
+/**
+ * Can be triggered by an public download via .htaccess to count it.
+ * @return unknown_type
+ */
+function light_download_count_public() {
+  global $base_url;
+  if(variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) != 
FILE_DOWNLOADS_PUBLIC) {
+    return MENU_ACCESS_DENIED;
+  }
+  $filepath = isset($_GET['file']) ? $_GET['file'] : '';
+  if ($filepath) {
+    _light_download_count_download($filepath);
+  }
+  header('Location: ' . $base_url .'/'. $filepath . '?skip_count');
+  exit;
+}
+
+/**
+ * Implementation of file_download()
+ */
+function light_download_count_file_download($filename) {
+  _light_download_count_download(file_create_path($filename));
+}


Property changes on: 
web/trunk/htdocs/more/sites/all/modules/light_download_count/light_download_count.module
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to