download_count.theme.inc in Download Count 7.2
Same filename and directory in other branches
Theme related functions for the download_count module.
File
includes/download_count.theme.incView source
<?php
/**
* @file
* Theme related functions for the download_count module.
*/
function theme_download_count_upload_attachments($variables) {
$files = $variables['files'];
$downloads = $variables['downloads'];
$header = array(
t('Attachment'),
t('Size'),
t('Downloads'),
t('Last Download'),
);
$rows = array();
foreach ($files as $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(REQUEST_TIME - $downloads[$file->filename]['last']),
)) : 'never';
$count = isset($downloads[$file->filename]['count']) ? $downloads[$file->filename]['count'] : 0;
$rows[] = array(
l($text, $href),
format_size($file->filesize),
$count,
$last,
);
}
}
if (count($rows)) {
return theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array(
'id' => 'attachments',
),
));
}
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function theme_download_count_formatter_download_count($variables) {
$element = $variables['element'];
if (empty($element['#item']['fid'])) {
return '';
}
global $user;
$file = $element['#item'];
$node = $element['#node'];
$field = content_fields($element['#field_name']);
$filepath = $file['filepath'];
if (user_access('view own download counts') && $user->uid != 1) {
$count = db_query("SELECT COUNT(dc.dcid) FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid WHERE f.filepath = :f.filepath AND dc.nid = :dc.nid AND dc.uid = :dc.uid", array(
':f.filepath' => $filepath,
':dc.nid' => $node->nid,
':dc.uid' => $user->uid,
))
->fetchField();
}
elseif (user_access('view all download counts')) {
$count = db_query("SELECT COUNT(dc.dcid) FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid WHERE f.filepath = :f.filepath AND dc.nid = :dc.nid", array(
':f.filepath' => $filepath,
':dc.nid' => $node->nid,
))
->fetchField();
}
// TODO Please change this theme call to use an associative array for the $variables parameter.
$output = theme('filefield_file', $file);
if ($output) {
if (user_access('view all download counts') || user_access('view own download counts')) {
$text = ' — ';
if ($count) {
$text .= format_plural($count, 'Downloaded 1 time', 'Downloaded @count times');
}
else {
$text .= t('Never downloaded');
}
}
else {
$text = '';
}
if (substr($output, -6) == '</div>') {
return substr($output, 0, -6) . $text . '</div>';
}
else {
return $output . $text;
}
}
return $output;
}
Functions
Name![]() |
Description |
---|---|
theme_download_count_formatter_download_count | @todo Please document this function. |
theme_download_count_upload_attachments | @file Theme related functions for the download_count module. |