* Copyright 1999-2001 (c) VA Linux Systems
* Copyright 2002-2004 (c) GForge Team
* Copyright 2010 (c) FusionForge Team
+ * Copyright 2013, Franck Villaume - TrivialDev
* http://fusionforge.org/
*
* This file is part of FusionForge. FusionForge is free software;
* package_id)
*/
-function send_file ($filename,$filepath,$file_id=NULL) {
+function send_file($filename, $filepath, $file_id = NULL, $mode = NULL) {
if (!file_exists($filepath)) {
session_redirect404();
}
}
$ip = getStringFromServer('REMOTE_ADDR');
- $res = db_query_params("INSERT INTO frs_dlstats_file (ip_address,file_id,month,day,user_id) VALUES ($1, $2, $3, $4, $5)", array($ip,$file_id,date('Ym'),date('d'),$us));
+ if ($mode != 'latestzip') {
+ $res = db_query_params("INSERT INTO frs_dlstats_file (ip_address,file_id,month,day,user_id) VALUES ($1, $2, $3, $4, $5)", array($ip,$file_id,date('Ym'),date('d'),$us));
+ } else {
+ // here $file_id is a package_id
+ $Package = frspackage_get_object($file_id);
+ $release = $Package->getNewestRelease();
+ $files = $release->getFiles();
+ foreach ($files as $fileObject) {
+ $res = db_query_params("INSERT INTO frs_dlstats_file (ip_address,file_id,month,day,user_id) VALUES ($1, $2, $3, $4, $5)", array($ip, $fileObject->getID(), date('Ym'), date('d'), $us));
+ }
+ }
}
$normalized_urlprefix = normalized_urlprefix();
// .../download.php/file/123/foo.tar.gz
// 123 -> file_id
// foo.tar.gz ignored
+
$file_id = $expl_pathinfo[4];
+
+ // Allow alternate content-type rendering by hook
+ $default_content_type = 'application/binary';
+
+ $script = 'frs_download_file';
+ $content_type = util_negociate_alternate_content_types($script, $default_content_type);
+
+ if($content_type != $default_content_type) {
+ $hook_params = array();
+ $hook_params['accept'] = $content_type;
+ $hook_params['group_id'] = $group_id;
+ $hook_params['file_id'] = $file_id;
+ $hook_params['return'] = '';
+ $hook_params['content_type'] = '';
+ plugin_hook_by_reference('content_negociated_frs_download_file', $hook_params);
+ if($hook_params['content_type'] != ''){
+ header('Content-type: '. $hook_params['content_type']);
+ echo $hook_params['content'];
+ }
+ else {
+ header('HTTP/1.1 406 Not Acceptable',true,406);
+ }
+ exit(0);
+ }
+
$File = frsfile_get_object($file_id);
if (!$File) {
session_redirect404();
$filename = $Package->getNewestReleaseZipName();
$filepath = $Package->getNewestReleaseZipPath();
- send_file ($filename, $filepath);
+ send_file ($filename, $filepath, $package_id, $mode);
break;