function track_da_files_tracking in Track da files 7
Analyses uri of file, updates counter and redirects user to file url.
1 string reference to 'track_da_files_tracking'
- track_da_files_menu in ./
track_da_files.module - Implements hook_menu().
File
- ./
track_da_files.module, line 552 - This file contains Track da files main functions.
Code
function track_da_files_tracking($uri) {
$roles = variable_get('track_da_files_specific_roles', array());
global $user;
$track = track_da_files_roles($user);
if (!isset($_GET['file'])) {
// Our menu hook wasn't called, so we should ignore this.
return;
}
// Arguments of the function : public and uri components.
$args = func_get_args();
$scheme = array_shift($args);
$target = implode('/', $args);
$uri = $scheme . '://' . $target;
$file_name = basename($uri);
// Retrieve entity id information in query parameters.
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
if (isset($_GET['type'])) {
$type = $_GET['type'];
}
if (isset($_GET['force'])) {
$force = $_GET['force'];
}
$query = "SELECT f.fid, f.filename, f.filemime, f.filesize FROM {file_managed} f WHERE f.uri = :uri";
$result = db_query($query, array(
':uri' => $uri,
))
->fetch();
if (!empty($result)) {
$filename = isset($result->filename) ? $result->filename : '';
$fid = isset($result->fid) ? $result->fid : '';
$filemime = isset($result->filemime) ? $result->filemime : '';
$filesize = isset($result->filesize) ? $result->filesize : '';
}
// If uri exists and valid uri scheme interaction with database begins.
if (file_stream_wrapper_valid_scheme($scheme) && file_exists($uri)) {
if (!empty($fid) && $track) {
if (!empty($id) && !empty($type)) {
track_da_files_register_new_display($uri, $fid, $id, $type);
}
else {
track_da_files_register_new_display($uri, $fid);
}
}
$headers = array(
'Content-Type' => $filemime,
'Content-Length' => $filesize,
);
if (isset($force) && $force == 1) {
$headers['Content-Disposition'] = 'attachment; filename="' . $filename . '"';
}
file_transfer($uri, $headers);
}
}