public function TrackDaFilesController::tracking_private in Track da files 8
1 string reference to 'TrackDaFilesController::tracking_private'
File
- src/
Controller/ TrackDaFilesController.php, line 601
Class
- TrackDaFilesController
- Class TrackDaFilesController.
Namespace
Drupal\track_da_files\ControllerCode
public function tracking_private($file_uri, $uritest) {
$uri = $full_uri = '';
$request = \Drupal::request();
$querystring = $request
->getQueryString();
$pathinfo = $request
->getPathinfo();
$file_uri = $request
->getRequestUri();
$roles = \Drupal::config('track_da_files.settings')
->get('specific_roles');
$account = \Drupal::currentUser();
$track = track_da_files_roles($account);
if (!empty($file)) {
// Our menu hook wasn't called, so we should ignore this.
return;
}
$file_name = basename($file_uri);
$file_relative_path = str_replace('/system/files/', '', $pathinfo);
$scheme = 'private';
$uri = $scheme . '://' . $file_relative_path;
$file = $request
->get('file');
$id = $request
->get('id');
$type = $request
->get('type');
$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 (!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,
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
);
$response = new Response();
return new BinaryFileResponse($uri, 200, $headers);
}