Skip to content
Snippets Groups Projects
Commit 1c4a82dc authored by WorldFallz's avatar WorldFallz
Browse files

Coder drupal code standards changes.

parent 17d0123c
No related branches found
Tags 6.x-2.0
No related merge requests found
Showing with 264 additions and 126 deletions
......@@ -11,7 +11,7 @@
function download_count_help($path, $arg) {
switch ($path) {
case 'admin/help#download_count':
return '<p>'. t("Tracks file downloads for files stored in the drupal files table. Requires either the 'private' download method setting or the method for combined public and private files described at <a href=@link>http://drupal.org/node/189239</a>. Also logs a message to the watchdog table.", array('@link' => url('http://drupal.org/node/189239'))) .'</p>';
return '<p>' . t("Tracks file downloads for files stored in the drupal files table. Requires either the 'private' download method setting or the method for combined public and private files described at <a href=@link>http://drupal.org/node/189239</a>. Also logs a message to the watchdog table.", array('@link' => url('http://drupal.org/node/189239'))) . '</p>';
}
}
......@@ -36,12 +36,12 @@ function download_count_menu() {
'page arguments' => array('download_count_admin_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'includes/download_count.admin.inc',
);
);
$items['admin/settings/download_count/general'] = array(
'title' => 'General',
'weight' => 1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
);
$items['download_count/%download_count_entry/reset'] = array(
'title' => 'Download Count Reset',
'page callback' => 'drupal_get_form',
......@@ -49,7 +49,7 @@ function download_count_menu() {
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
'file' => 'includes/download_count.pages.inc',
);
);
$items['download_count/%download_count_entry/export'] = array(
'title' => 'Download Count Export CSV',
'page callback' => 'drupal_get_form',
......@@ -57,7 +57,7 @@ function download_count_menu() {
'access arguments' => array('export download counts'),
'type' => MENU_CALLBACK,
'file' => 'includes/download_count.export.inc',
);
);
$items['download_count'] = array(
'title' => 'Download Count',
'page callback' => 'download_count_view_page',
......@@ -65,7 +65,7 @@ function download_count_menu() {
'access arguments' => array('view all download counts'),
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/download_count.pages.inc',
);
);
$items['my_download_count'] = array(
'title' => 'My Download Count',
'page callback' => 'download_count_view_page',
......@@ -73,7 +73,7 @@ function download_count_menu() {
'access arguments' => array('view own download counts'),
'type' => MENU_NORMAL_ITEM,
'file' => '/includes/download_count.pages.inc',
);
);
return $items;
}
......@@ -91,7 +91,7 @@ function download_count_entry_load($dcid) {
function download_count_nodeapi(&$node, $op, $teaser) {
$result = array();
switch ($op) {
case 'view' :
case 'view':
if (isset($node->files) && count($node->files) && user_access('view uploaded files') && !$teaser) {
global $user;
if (user_access('view own download counts') && $user->uid != 1) {
......@@ -118,14 +118,14 @@ function download_count_nodeapi(&$node, $op, $teaser) {
*/
function download_count_theme() {
return array(
'download_count_upload_attachments' => array(
'download_count_upload_attachments' => array(
'arguments' => array('files' => NULL, 'downloads' => NULL),
'file' => 'includes/download_count.theme.inc',
),
'download_count_formatter_download_count' => array(
'arguments' => array('element' => NULL),
'file' => 'includes/download_count.theme.inc',
),
),
);
}
......@@ -136,7 +136,8 @@ function download_count_field_formatter_info() {
'field types' => array('filefield'),
'multiple values' => CONTENT_HANDLE_CORE,
'description' => t('Displays all kinds of files with an icon and a linked file description with download count information.'),
));
),
);
}
/**
......@@ -145,7 +146,7 @@ function download_count_field_formatter_info() {
function download_count_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'download_count') . '/includes'
'path' => drupal_get_path('module', 'download_count') . '/includes',
);
}
......@@ -154,7 +155,9 @@ function download_count_views_api() {
*/
function download_count_file_download($filename, $checkonly = FALSE) {
// Special use of hook_file_download() - 2nd argument added to indicate that it is not a download, but only an access check.
if ($checkonly) return;
if ($checkonly) {
return;
}
global $user;
......@@ -170,23 +173,23 @@ function download_count_file_download($filename, $checkonly = FALSE) {
// NULL: not known
// FALSE: not accessible
// TRUE: accessible
$accessible_file=NULL;
$accessible_file = NULL;
// check if the file is known by Upload
$accessible_file=_download_count_is_accessible_by_upload($filepath);
$accessible_file = _download_count_is_accessible_by_upload($filepath);
if ($accessible_file===NULL) {
if ($accessible_file === NULL) {
// check if the file is known by CCK FileField
$accessible_file=_download_count_is_accessible_by_filefield($filepath);
$accessible_file = _download_count_is_accessible_by_filefield($filepath);
}
if ($accessible_file===NULL) {
if ($accessible_file === NULL) {
// not known by any hooks, so we don't care about this file
return;
}
// inaccessible file
if ($accessible_file===FALSE) {
if ($accessible_file === FALSE) {
watchdog('download_count', 'Failed to download %file', array('%file' => $filename), WATCHDOG_ERROR);
return;
}
......@@ -222,7 +225,7 @@ function download_count_file_download($filename, $checkonly = FALSE) {
* Implementation of hook_block().
*
*/
function download_count_block($op='list' , $delta=0, $edit=array()) {
function download_count_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
......@@ -238,57 +241,57 @@ function download_count_block($op='list' , $delta=0, $edit=array()) {
'#title' => t('Number of items to display'),
'#size' => 5,
'#default_value' => variable_get('download_count_' . $delta . '_block_limit', 10),
);
);
$form['download_count_' . $delta . '_show_size'] = array(
'#type' => 'checkbox',
'#title' => t('Display aggregated filesize'),
'#default_value' => variable_get('download_count_' . $delta . '_show_size', 0),
);
);
$form['download_count_' . $delta . '_show_last'] = array(
'#type' => 'checkbox',
'#title' => t('Display last download datetime'),
'#default_value' => variable_get('download_count_' . $delta . '_show_last', 0),
);
);
if ($delta == 'files') {
$form['download_count_files_file_links'] = array(
'#type' => 'checkbox',
'#title' => t('Display files names as links (based on permissions).'),
'#default_value' => variable_get('download_count_files_file_links', 1),
);
);
}
return $form;
case 'save' :
case 'save':
variable_set('download_count_' . $delta . '_block_limit', $edit['download_count_' . $delta . '_block_limit']);
variable_set('download_count_' . $delta . '_show_size', $edit['download_count_' . $delta . '_show_size']);
variable_set('download_count_' . $delta . '_show_last', $edit['download_count_' . $delta . '_show_last']);
$delta == 'files' ? variable_set('download_count_files_file_links', $edit['download_count_files_file_links']) : NULL;
break;
case 'view':
switch ($delta) {
case 'files':
$blocks['subject'] = t('Top Downloaded Files');
$blocks['content'] = _download_count_block_contents('files');
break;
case 'downloaders':
$blocks['subject'] = t('Top Downloaders');
$blocks['content'] = _download_count_block_contents('downloaders');
break;
case 'users':
$blocks['subject'] = t('Top Downloaded Users');
$blocks['content'] = _download_count_block_contents('users');
break;
case 'nodes':
$blocks['subject'] = t('Top Downloaded Nodes');
$blocks['content'] = _download_count_block_contents('nodes');
break;
}
case 'view':
switch ($delta) {
case 'files':
$blocks['subject'] = t('Top Downloaded Files');
$blocks['content'] = _download_count_block_contents('files');
break;
case 'downloaders':
$blocks['subject'] = t('Top Downloaders');
$blocks['content'] = _download_count_block_contents('downloaders');
break;
case 'users':
$blocks['subject'] = t('Top Downloaded Users');
$blocks['content'] = _download_count_block_contents('users');
break;
case 'nodes':
$blocks['subject'] = t('Top Downloaded Nodes');
$blocks['content'] = _download_count_block_contents('nodes');
break;
}
return $blocks;
return $blocks;
}
}
......@@ -297,7 +300,9 @@ function download_count_block($op='list' , $delta=0, $edit=array()) {
*/
function _download_count_get_file_by_upload($filepath) {
// check if Upload is enabled
if (!function_exists('upload_perm')) return NULL; // upload not enabled
if (!function_exists('upload_perm')) {
return NULL;
} // upload not enabled
$result = db_query("SELECT u.nid, u.vid, f.filepath, f.fid FROM {upload} u JOIN {files} f ON f.fid = u.fid WHERE f.filepath = '%s'", $filepath);
return db_fetch_object($result);
......@@ -316,15 +321,21 @@ function _download_count_is_accessible_by_upload($filepath) {
}
function _download_count_is_accessible_by_filefield($file) {
$nodes=_download_count_get_nodes_by_filefield($file);
if ($nodes===FALSE) return FALSE;
if ($nodes===NULL) return NULL;
$nodes = _download_count_get_nodes_by_filefield($file);
if ($nodes === FALSE) {
return FALSE;
}
if ($nodes === NULL) {
return NULL;
}
return TRUE;
}
function _download_count_get_nodes_by_filefield($file) {
// check if FileField is enabled
if (!function_exists('filefield_view_access')) return NULL; // not enabled
if (!function_exists('filefield_view_access')) {
return NULL;
} // not enabled
// The following logic is snipped from filefield.module 1.209 2009/10/20 17:46:22
// which is part of CCK FileField 6.x-3.2 release, see http://drupal.org/project/filefield
......@@ -346,11 +357,11 @@ function _download_count_get_nodes_by_filefield($file) {
$columns = array('vid', 'nid');
foreach ($db_info['columns'] as $property_name => $column_info) {
$columns[] = $column_info['column'] .' AS '. $property_name;
$columns[] = $column_info['column'] . ' AS ' . $property_name;
}
$result = db_query("SELECT ". implode(', ', $columns) ."
FROM {". $table ."}
WHERE ". $fid_column ." = %d", $file->fid);
$result = db_query("SELECT " . implode(', ', $columns) . "
FROM {" . $table . "}
WHERE " . $fid_column . " = %d", $file->fid);
while ($content = db_fetch_array($result)) {
$content['field'] = $field;
......@@ -409,10 +420,22 @@ function _download_count_block_contents($block) {
switch ($block) {
case 'files':
$rows = array();
$header[] = array('data' => t('Filename'), 'class' => 'filename');
$header[] = $show_size ? array('data' => t('Size'), 'class' => 'size') : '';
$header[] = array('data' => t('Count'), 'class' => 'count');
$header[] = $show_last ? array('data' => t('Last Downloaded'), 'class' => 'last') : '';
$header[] = array(
'data' => t('Filename'),
'class' => 'filename',
);
$header[] = $show_size ? array(
'data' => t('Size'),
'class' => 'size',
) : '';
$header[] = array(
'data' => t('Count'),
'class' => 'count',
);
$header[] = $show_last ? array(
'data' => t('Last Downloaded'),
'class' => 'last',
) : '';
if (user_access('view all download counts')) {
$result = db_query('SELECT COUNT(dc.dcid) AS count, f.filename, f.filepath, f.fid, SUM(f.filesize) AS size, MAX(dc.timestamp) as last FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid GROUP BY f.filename ORDER BY count DESC LIMIT %d', (int) $limit);
......@@ -434,10 +457,22 @@ function _download_count_block_contents($block) {
case 'downloaders':
$rows = array();
$header[] = array('data' => t('User'), 'class' => 'user');
$header[] = $show_size ? array('data' => t('Size'), 'class' => 'size') : '';
$header[] = array('data' => t('Count'), 'class' => 'count');
$header[] = $show_last ? array('data' => t('Last Downloaded'), 'class' => 'last') : '';
$header[] = array(
'data' => t('User'),
'class' => 'user',
);
$header[] = $show_size ? array(
'data' => t('Size'),
'class' => 'size',
) : '';
$header[] = array(
'data' => t('Count'),
'class' => 'count',
);
$header[] = $show_last ? array(
'data' => t('Last Downloaded'),
'class' => 'last',
) : '';
if (user_access('view all download counts')) {
$result = db_query('SELECT COUNT(dc.dcid) AS count, SUM(f.filesize) AS size, u.name, u.uid, MAX(dc.timestamp) as last FROM {download_count} dc JOIN {users} u ON dc.uid = u.uid JOIN {files} f on dc.fid = f.fid GROUP BY u.name ORDER BY count DESC LIMIT %d', (int) $limit);
......@@ -459,10 +494,22 @@ function _download_count_block_contents($block) {
case 'users':
$rows = array();
$header[] = array('data' => t('User'), 'class' => 'user');
$header[] = $show_size ? array('data' => t('Size'), 'class' => 'size') : '';
$header[] = array('data' => t('Count'), 'class' => 'count');
$header[] = $show_last ? array('data' => t('Last Downloaded'), 'class' => 'last') : '';
$header[] = array(
'data' => t('User'),
'class' => 'user',
);
$header[] = $show_size ? array(
'data' => t('Size'),
'class' => 'size',
) : '';
$header[] = array(
'data' => t('Count'),
'class' => 'count',
);
$header[] = $show_last ? array(
'data' => t('Last Downloaded'),
'class' => 'last',
) : '';
if (user_access('view all download counts')) {
$result = db_query('SELECT COUNT(dc.dcid) AS count, SUM(f.filesize) AS size, u.name, u.uid, MAX(dc.timestamp) as last FROM {download_count} dc JOIN {files} f on dc.fid = f.fid JOIN {users} u ON f.uid = u.uid GROUP BY u.name ORDER BY count DESC LIMIT %d', (int) $limit);
......@@ -484,10 +531,22 @@ function _download_count_block_contents($block) {
case 'nodes':
$rows = array();
$header[] = array('data' => t('Page'), 'class' => 'node');
$header[] = $show_size ? array('data' => t('Size'), 'class' => 'size') : '';
$header[] = array('data' => t('Count'), 'class' => 'count');
$header[] = $show_last ? array('data' => t('Last Downloaded'), 'class' => 'last') : '';
$header[] = array(
'data' => t('Page'),
'class' => 'node',
);
$header[] = $show_size ? array(
'data' => t('Size'),
'class' => 'size',
) : '';
$header[] = array(
'data' => t('Count'),
'class' => 'count',
);
$header[] = $show_last ? array(
'data' => t('Last Downloaded'),
'class' => 'last',
) : '';
if (user_access('view all download counts')) {
$result = db_query('SELECT COUNT(dc.dcid) AS count, SUM(f.filesize) AS size, dc.nid, MAX(dc.timestamp) as last FROM {download_count} dc JOIN {files} f on dc.fid = f.fid GROUP BY dc.nid ORDER BY count DESC LIMIT %d', (int) $limit);
......@@ -523,12 +582,30 @@ function download_count_rules_event_info() {
'label' => t('A file has been downloaded'),
'module' => 'Download Count',
'arguments' => array(
'filename' => array('type' => 'file', 'label' => t('Filename of the downloaded file.')),
'user' => array('type' => 'file', 'label' => t('User object of the user downloading the file.')),
'nid' => array('type' => 'file', 'label' => t('Filename of the downloaded file.')),
'ip' => array('type' => 'file', 'label' => t('Node id from which the file was downloaded.')),
'referrer' => array('type' => 'file', 'label' => t('HTTP Referrer of the downloaded file.')),
'time' => array('type' => 'file', 'label' => t('Timestamp of the download.')),
'filename' => array(
'type' => 'file',
'label' => t('Filename of the downloaded file.'),
),
'user' => array(
'type' => 'file',
'label' => t('User object of the user downloading the file.'),
),
'nid' => array(
'type' => 'file',
'label' => t('Filename of the downloaded file.'),
),
'ip' => array(
'type' => 'file',
'label' => t('Node id from which the file was downloaded.'),
),
'referrer' => array(
'type' => 'file',
'label' => t('HTTP Referrer of the downloaded file.'),
),
'time' => array(
'type' => 'file',
'label' => t('Timestamp of the download.'),
),
),
),
);
......
......@@ -20,7 +20,7 @@ function download_count_statistics_init() {
function download_count_statistics_help($path, $arg) {
switch ($path) {
case 'admin/help#download_count_statistics':
return '<p>'. t("Provides daily, weekly, monthly, and yearly statistics for <a href=@link>download_count module</a> data. Statistics are cached and updated via cron.", array('@link' => url('http://drupal.org/project/download_count'))) .'</p>';
return '<p>' . t("Provides daily, weekly, monthly, and yearly statistics for <a href=@link>download_count module</a> data. Statistics are cached and updated via cron.", array('@link' => url('http://drupal.org/project/download_count'))) . '</p>';
}
}
......@@ -46,7 +46,7 @@ function download_count_statistics_menu() {
'weight' => 2,
'type' => MENU_LOCAL_TASK,
'file' => 'includes/download_count_statistics.admin.inc',
);
);
$items['download_count/%download_count_statistics_entry/details'] = array(
'title' => 'Download Count Details',
'page callback' => 'download_count_statistics_details_page',
......@@ -54,7 +54,7 @@ function download_count_statistics_menu() {
'access arguments' => array('view download count statistics'),
'type' => MENU_CALLBACK,
'file' => 'includes/download_count_statistics.pages.inc',
);
);
return $items;
}
......@@ -103,5 +103,5 @@ function download_count_statistics_cron() {
*/
function download_count_statistics_get_daily_count($fid, $date) {
$sql = "SELECT * FROM {download_count_statistics} WHERE fid = $fid AND DATE(FROM_UNIXTIME(timestamp)) = '$date'";
return db_result(db_query($sql, $fid, $date));
return db_result(db_query($sql, $fid, $date));
}
......@@ -36,7 +36,7 @@ function download_count_admin_settings() {
'#title' => t('Excluded file extensions'),
'#default_value' => variable_get('download_count_excluded_file_extensions', 'jpg jpeg gif png'),
'#maxlength' => 255,
'#description' => t('This module only considers files that have been uploaded with the upload module and that become file attachments. However, if you are using a contributed module to upload images and display them in the body of nodes, these files may get flagged as downloaded whenever a visitor or robot views the node page, because strictly speaking they are file attachments. This will happen with the module img_assist. Note that this won\'t happen with the module imce, because imce treats inline images as nodes. If you do not want to set a download count for image files, list their extension here. Separate extensions with a space and do not include the leading dot. For example, you could list these extensions&nbsp: jpg jpeg gif png. If you do not want to exclude any file, leave that field blank. ')
'#description' => t('This module only considers files that have been uploaded with the upload module and that become file attachments. However, if you are using a contributed module to upload images and display them in the body of nodes, these files may get flagged as downloaded whenever a visitor or robot views the node page, because strictly speaking they are file attachments. This will happen with the module img_assist. Note that this won\'t happen with the module imce, because imce treats inline images as nodes. If you do not want to set a download count for image files, list their extension here. Separate extensions with a space and do not include the leading dot. For example, you could list these extensions&nbsp: jpg jpeg gif png. If you do not want to exclude any file, leave that field blank. '),
);
$form['download count page'] = array(
'#type' => 'fieldset',
......
......@@ -9,7 +9,7 @@
* Download_count export form.
*/
function download_count_export_form($form_state, $dc_entry = array()) {
drupal_add_js(drupal_get_path('module', 'download_count') .'/download_count.js');
drupal_add_js(drupal_get_path('module', 'download_count') . '/download_count.js');
if ($dc_entry == 'all') {
drupal_set_title(t('Download Count Export CSV - All Files'));
}
......@@ -95,7 +95,7 @@ function download_count_export_form_submit($form, &$form_state) {
return;
}
drupal_set_header('Content-Disposition: attachment; filename="'. basename($export_file_path) .'"');
drupal_set_header('Content-Disposition: attachment; filename="' . basename($export_file_path) . '"');
drupal_set_header("Content-Length: $file_size");
drupal_set_header('Content-Type: application/csv; charset=utf-8');
drupal_set_header('CacheControl: no-cache');
......
......@@ -11,10 +11,27 @@ function download_count_view_page($arg = NULL) {
$header = array();
$result = NULL;
$header[] = array('data' => t('Count'), 'field' => 'count', 'sort' => 'desc', 'class' => 'count');
$header[] = array('data' => t('File'), 'field' => 'filename', 'class' => 'file');
$header[] = array('data' => t('Page'), 'field' => 'title', 'class' => 'page');
$header[] = array('data' => t('Last Download'), 'field' => 'last', 'class' => 'date');
$header[] = array(
'data' => t('Count'),
'field' => 'count',
'sort' => 'desc',
'class' => 'count',
);
$header[] = array(
'data' => t('File'),
'field' => 'filename',
'class' => 'file',
);
$header[] = array(
'data' => t('Page'),
'field' => 'title',
'class' => 'page',
);
$header[] = array(
'data' => t('Last Download'),
'field' => 'last',
'class' => 'date',
);
if ($arg == 'download_count') {
drupal_set_title(check_plain(variable_get('download_count_view_page_title', t('Download Count'))));
......@@ -67,7 +84,10 @@ function download_count_view_page($arg = NULL) {
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No files have been downloaded.'), 'colspan' => '4'));
$rows[] = array(array(
'data' => t('No files have been downloaded.'),
'colspan' => '4',
));
}
if ($colspan > 1) {
......@@ -75,7 +95,6 @@ function download_count_view_page($arg = NULL) {
'data' => t('Action')
. (user_access('export download counts') ? l(t(' (Export All)'), 'download_count/all/export') : NULL)
. (user_access('administer site configuration') ? l(t(' (Reset All)'), 'download_count/all/reset') : NULL),
'colspan' => $colspan,
);
}
......@@ -92,10 +111,22 @@ function download_count_view_page($arg = NULL) {
function download_count_reset_form($form_state, $dc_entry = array()) {
$form = array();
if ($dc_entry != 'all') {
$form['dcid'] = array('#type' => 'value', '#value' => $dc_entry['dcid']);
$form['filename'] = array('#type' => 'value', '#value' => $dc_entry['filename']);
$form['fid'] = array('#type' => 'value', '#value' => $dc_entry['fid']);
$form['nid'] = array('#type' => 'value', '#value' => $dc_entry['nid']);
$form['dcid'] = array(
'#type' => 'value',
'#value' => $dc_entry['dcid'],
);
$form['filename'] = array(
'#type' => 'value',
'#value' => $dc_entry['filename'],
);
$form['fid'] = array(
'#type' => 'value',
'#value' => $dc_entry['fid'],
);
$form['nid'] = array(
'#type' => 'value',
'#value' => $dc_entry['nid'],
);
return confirm_form(
$form,
t('Are you sure you want to reset the download count for %filename?',
......@@ -103,17 +134,20 @@ function download_count_reset_form($form_state, $dc_entry = array()) {
),
'download_count',
t('This action cannot be undone.'),
t('Reset'), t('Cancel')
t('Reset'), t('Cancel')
);
}
else {
$form['dcid'] = array('#type' => 'value', '#value' => 'all');
$form['dcid'] = array(
'#type' => 'value',
'#value' => 'all',
);
return confirm_form(
$form,
t('Are you sure you want to reset all download counts?'),
'download_count',
t('This action cannot be undone.'),
t('Reset All'), t('Cancel')
t('Reset All'), t('Cancel')
);
}
}
......
......@@ -8,12 +8,12 @@ function theme_download_count_upload_attachments($files, $downloads) {
$header = array(t('Attachment'), t('Size'), t('Downloads'), t('Last Download'));
$rows = array();
foreach ($files as $file) {
$file = (object)$file;
$file = (object) $file;
if (isset($file->list) && empty($file->remove)) {
$href = function_exists('_private_upload_create_url') ? _private_upload_create_url($file) : file_create_url($file->filepath);
$text = $file->description ? $file->description : $file->filename;
$last = isset($downloads[$file->filename]['last']) ? t('@time ago', array('@time' => format_interval(time() - $downloads[$file->filename]['last']))) : 'never';
$count = isset($downloads[$file->filename]['count']) ? $downloads[$file->filename]['count'] : 0 ;
$count = isset($downloads[$file->filename]['count']) ? $downloads[$file->filename]['count'] : 0;
$rows[] = array(l($text, $href), format_size($file->filesize), $count, $last);
}
}
......@@ -32,7 +32,7 @@ function theme_download_count_formatter_download_count($element) {
$file = $element['#item'];
$node = $element['#node'];
$field = content_fields($element['#field_name']);
$filepath=$file['filepath'];
$filepath = $file['filepath'];
if (user_access('view own download counts') && $user->uid != 1) {
$count = db_result(db_query("SELECT COUNT(dc.dcid) FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid WHERE f.filepath = '%s' AND dc.nid = %d AND dc.uid = %d", $filepath, $node->nid, $user->uid));
......@@ -41,11 +41,11 @@ function theme_download_count_formatter_download_count($element) {
$count = db_result(db_query("SELECT COUNT(dc.dcid) FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid WHERE f.filepath = '%s' AND dc.nid = %d", $filepath, $node->nid));
}
$output=theme('filefield_file', $file);
$output = theme('filefield_file', $file);
if ($output) {
if (user_access('view all download counts') || user_access('view own download counts')) {
$text=' &mdash; ';
$text = ' &mdash; ';
if ($count) {
$text .= format_plural($count, 'Downloaded 1 time', 'Downloaded @count times');
}
......@@ -54,10 +54,10 @@ function theme_download_count_formatter_download_count($element) {
}
}
else {
$text='';
$text = '';
}
if (drupal_substr($output, -6)=='</div>') {
if (drupal_substr($output, -6) == '</div>') {
return drupal_substr($output, 0, -6) . $text . '</div>';
}
else {
......
......@@ -11,7 +11,7 @@
function download_count_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'download_count') .'/includes',
'path' => drupal_get_path('module', 'download_count') . '/includes',
),
'handlers' => array(
'download_count_views_handler_field_file' => array(
......
......@@ -92,7 +92,7 @@ function download_count_statistics_admin_settings() {
$form['sparklines'] = array(
'#type' => 'fieldset',
'#title' => t('Sparkline Options'),
'#description' => is_file(drupal_get_path('module', 'download_count_statistics') .'/jquery.sparkline.min.js') ? t('The jquery sparkline plugin is available at: ') . drupal_get_path('module', 'download_count_statistics') .'/jquery.sparkline.min.js' : '<em><span style="color: #A50000;">'. t('This option requires the jquery.sparkline.min.js plugin which is unavailable-- you can download it at <a href="http://omnipotent.net/jquery.sparkline">http://omnipotent.net/jquery.sparkline</a> (just copy the file to the download_count module directory).') .'</span></em>',
'#description' => is_file(drupal_get_path('module', 'download_count_statistics') . '/jquery.sparkline.min.js') ? t('The jquery sparkline plugin is available at: ') . drupal_get_path('module', 'download_count_statistics') . '/jquery.sparkline.min.js' : '<em><span style="color: #A50000;">' . t('This option requires the jquery.sparkline.min.js plugin which is unavailable-- you can download it at <a href="http://omnipotent.net/jquery.sparkline">http://omnipotent.net/jquery.sparkline</a> (just copy the file to the download_count module directory).') . '</span></em>',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
......@@ -106,9 +106,12 @@ function download_count_statistics_admin_settings() {
'#type' => 'select',
'#title' => t('Sparkline Type'),
'#default_value' => variable_get('download_count_statistics_sparkline_type', 'line'),
'#options' => array('line' => t('Line'), 'bar' => t('Bar')),
'#options' => array(
'line' => t('Line'),
'bar' => t('Bar'),
),
'#disabled' => !is_file(drupal_get_path('module', 'download_count_statistics') . '/jquery.sparkline.min.js'),
'#description' => 'Specify line or bar graph type.'
'#description' => 'Specify line or bar graph type.',
);
$form['sparklines']['download_count_statistics_sparkline_min'] = array(
'#type' => 'textfield',
......
......@@ -28,8 +28,17 @@ function download_count_statistics_details_page($arg = NULL) {
//daily statistics table
if (variable_get('download_count_statistics_daily', 1)) {
$caption = "Daily Statistics";
$header[] = array('data' => t('Day'), 'field' => 'date', 'sort' => 'desc', 'class' => 'day');
$header[] = array('data' => t('Count'), 'field' => 'count', 'class' => 'count');
$header[] = array(
'data' => t('Day'),
'field' => 'date',
'sort' => 'desc',
'class' => 'day',
);
$header[] = array(
'data' => t('Count'),
'field' => 'count',
'class' => 'count',
);
$rows = array();
$values = '[';
......@@ -57,7 +66,12 @@ function download_count_statistics_details_page($arg = NULL) {
if (variable_get('download_count_statistics_weekly', 1)) {
$rows = array();
$values = '[';
$header[0] = array('data' => t('Week'), 'field' => 'date', 'sort' => 'desc', 'class' => 'week');
$header[0] = array(
'data' => t('Week'),
'field' => 'date',
'sort' => 'desc',
'class' => 'week',
);
$caption = "Weekly Statistics";
$first_day = variable_get('date_first_day', '0');
if ($first_day == 0) {
......@@ -71,7 +85,7 @@ function download_count_statistics_details_page($arg = NULL) {
$result = db_query("SELECT *, SUM(count) as count, WEEK(DATE(FROM_UNIXTIME(datestamp)), $mode) as week FROM {download_count_statistics} dcs WHERE dcs.fid = $fid GROUP BY WEEK(DATE(FROM_UNIXTIME(datestamp)), $mode) ORDER BY datestamp DESC" . ($limit > 0 ? " LIMIT $limit" : NULL));
while ($file = db_fetch_object($result)) {
$row = array();
$row[] = $file->week . ' (ending '. date('l m-d-Y', strtotime('+6 days', strtotime(_download_count_statistics_week_start_date($file->week, date('Y', $file->datestamp), $first_day)))) . ')';
$row[] = $file->week . ' (ending ' . date('l m-d-Y', strtotime('+6 days', strtotime(_download_count_statistics_week_start_date($file->week, date('Y', $file->datestamp), $first_day)))) . ')';
$row[] = $file->count;
$values .= $file->count . ',';
$rows[] = $row;
......@@ -90,7 +104,12 @@ function download_count_statistics_details_page($arg = NULL) {
if (variable_get('download_count_statistics_monthly', 1)) {
$rows = array();
$values = '[';
$header[0] = array('data' => t('Month'), 'field' => 'date', 'sort' => 'desc', 'class' => 'month');
$header[0] = array(
'data' => t('Month'),
'field' => 'date',
'sort' => 'desc',
'class' => 'month',
);
$caption = "Monthly Statistics";
$limit = check_plain(variable_get('download_count_statistics_monthly_limit', 0));
......@@ -116,7 +135,12 @@ function download_count_statistics_details_page($arg = NULL) {
if (variable_get('download_count_statistics_yearly', 1)) {
$rows = array();
$values = '[';
$header[0] = array('data' => t('Year'), 'field' => 'date', 'sort' => 'desc', 'class' => 'year');
$header[0] = array(
'data' => t('Year'),
'field' => 'date',
'sort' => 'desc',
'class' => 'year',
);
$caption = "Yearly Statistics";
$limit = check_plain(variable_get('download_count_statistics_yearly_limit', 0));
......
......@@ -12,12 +12,12 @@ class download_count_views_handler_field_count extends views_handler_field_numer
function query() {
$this->table_alias = $this->ensure_my_table();
if (empty($this->relationship)) {
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = ". $this->table_alias . ".fid";
$this->field_alias = $this->query->add_field(NULL, "(". $sql .")", $this->table_alias .'_'. $this->field);
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = " . $this->table_alias . ".fid";
$this->field_alias = $this->query->add_field(NULL, "(" . $sql . ")", $this->table_alias . '_' . $this->field);
}
else {
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = ". $this->relationship . ".fid";
$this->field_alias = $this->query->add_field(NULL, "(" . $sql .")", $this->relationship .'_'. $this->field);
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = " . $this->relationship . ".fid";
$this->field_alias = $this->query->add_field(NULL, "(" . $sql . ")", $this->relationship . '_' . $this->field);
}
}
}
......@@ -39,7 +39,7 @@ class download_count_views_handler_field_file extends views_handler_field_file {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = function_exists('_private_upload_create_url') ? _private_upload_create_url($file) : file_create_url($values->{$this->aliases['filepath']});
if ($data == $file->filepath) {
$data = drupal_substr($this->options['alter']['path'], drupal_strlen($base_url)+1);
$data = drupal_substr($this->options['alter']['path'], drupal_strlen($base_url) + 1);
}
}
return $data;
......
......@@ -12,11 +12,11 @@ class download_count_views_handler_filter_count extends views_handler_filter_num
function query() {
$this->table_alias = $this->ensure_my_table();
if (empty($this->relationship)) {
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = ". $this->table_alias . ".fid";
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = " . $this->table_alias . ".fid";
}
else {
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = ". $this->relationship . ".fid";
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = " . $this->relationship . ".fid";
}
$this->query->add_where($this->options['group'], "(". $sql .") " . $this->operator . " '%d'", $this->value['value']);
$this->query->add_where($this->options['group'], "(" . $sql . ") " . $this->operator . " '%d'", $this->value['value']);
}
}
......@@ -11,7 +11,7 @@
class download_count_views_handler_sort_count extends views_handler_sort {
function query() {
$this->table_alias = $this->ensure_my_table();
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = ". $this->table_alias . ".fid";
$this->field_alias = $this->query->add_orderby(NULL, "(". $sql .")", $this->options['order'], $this->table_alias .'_'. $this->field);
$sql = "SELECT COUNT(dc.fid) FROM {download_count} dc WHERE dc.fid = " . $this->table_alias . ".fid";
$this->field_alias = $this->query->add_orderby(NULL, "(" . $sql . ")", $this->options['order'], $this->table_alias . '_' . $this->field);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment