37 function __construct()
39 $this->Name =
"download";
40 $this->Title = _(
"Download File");
41 $this->Dependency = array();
43 parent::__construct();
52 $text = _(
"Download this file");
53 if ($_SESSION[Auth::USER_LEVEL] >= $SysConf[
'SYSCONFIG'][
'SourceCodeDownloadRights']) {
54 menu_insert(
"Browse-Pfile::Download",0,$this->Name,$text);
68 header(
'Content-type: text/html');
69 header(
"Pragma: no-cache");
70 header(
'Cache-Control: no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0');
71 header(
'Expires: Expires: Thu, 19 Nov 1981 08:52:00 GMT');
74 if (($this->NoMenu == 0) && ($this->Name !=
"menus")) {
75 $Menu = &$Plugins[plugin_find_id(
"menus")];
81 $V .=
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "xhtml1-frameset.dtd">' .
"\n";
85 $V .=
"<meta name='description' content='The study of Open Source'>\n";
86 if ($this->NoHeader == 0) {
92 if (!empty($this->Title)) {
93 $V .=
"<title>" . htmlentities($this->Title) .
"</title>\n";
95 $V .=
"<link rel='stylesheet' href='css/fossology.css'>\n";
97 print $Menu->OutputCSS();
100 $V .=
"<body class='text'>\n";
102 if (! empty($Menu)) {
103 $Menu->Output($this->Title);
107 $P = &$Plugins[plugin_find_id(
"view")];
108 $P->ShowView(null,
"browse");
112 function getResponse()
115 $output = $this->getPathAndName();
116 list($Filename,
$Name) = $output;
121 $this->vars[
'content'] = $e->getMessage();
122 $response = $this->
render($this->getTemplateName());
131 protected function getPathAndName()
133 if ($this->
State != \PLUGIN_STATE_READY) {
134 throw new Exception(
'Download plugin is not ready');
140 $dbManager = $container->get(
'db.manager');
141 if (!$dbManager->getDriver()) {
142 throw new Exception(
"Missing database connection.");
149 if (!empty($reportId)) {
150 $row = $dbManager->getSingleRow(
"SELECT * FROM reportgen WHERE job_fk = $1", array($reportId),
"reportFileName");
151 if ($row ===
false) {
152 throw new Exception(
"Missing report");
154 $path = $row[
'filepath'];
155 $filename = basename($path);
156 $uploadId = $row[
'upload_fk'];
157 } elseif (!empty($logJq)) {
158 $sql =
"SELECT jq_log, job_upload_fk FROM jobqueue LEFT JOIN job ON job.job_pk = jobqueue.jq_job_fk WHERE jobqueue.jq_pk =$1";
159 $row = $dbManager->getSingleRow($sql, array($logJq),
"jqLogFileName");
160 if ($row ===
false) {
161 throw new Exception(
"Missing report");
163 $path = $row[
'jq_log'];
164 $filename = basename($path);
165 $uploadId = $row[
'job_upload_fk'];
166 } elseif (empty($item)) {
167 throw new Exception(
"Invalid item parameter");
168 } elseif ($_SESSION[Auth::USER_LEVEL] < $SysConf[
'SYSCONFIG'][
'SourceCodeDownloadRights']) {
169 throw new Exception(
"User permissions not sufficient for source code download");
173 throw new Exception(
"Invalid item parameter");
178 if (empty($fileHandle)) {
182 $row = $dbManager->getSingleRow(
"SELECT ufile_name, upload_fk FROM uploadtree WHERE uploadtree_pk = $1",array($item));
184 throw new Exception(
"Missing item");
186 $filename = $row[
'ufile_name'];
187 $uploadId = $row[
'upload_fk'];
191 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
192 if (!Auth::isAdmin() && !$uploadDao->isAccessible($uploadId, Auth::getGroupId())) {
193 throw new Exception(
"No Permission: $uploadId");
195 if (!file_exists($path)) {
196 throw new Exception(
"File does not exist");
198 if (!is_file($path)) {
199 throw new Exception(
"Not a regular file");
201 return array($path, $filename);
213 $session = $container->get(
'session');
216 $filenameFallback = str_replace(
'%',
'_',$filename);
217 $filenameFallback = str_replace(
'/',
'_',$filenameFallback);
218 $filenameFallback = str_replace(
'\\',
'_',$filenameFallback);
220 $response =
new BinaryFileResponse($path);
221 $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, $filenameFallback);
222 if (pathinfo($filename, PATHINFO_EXTENSION) ==
'docx') {
223 $response->headers->set(
'Content-Type',
'');
226 $logger = $container->get(
"logger");
227 $logger->pushHandler(
new NullHandler(Logger::DEBUG));
228 BrowserConsoleHandler::resetStatic();
241 $_GET[
'report'] = $jobId;
242 list($Filename,
$Name) = $this->getPathAndName();
248 $NewPlugin->Initialize();
RegisterMenus()
Customize submenus.
downloadFile($path, $filename)
CheckRestore($Item, $Filename)
Called if there is no file. User is queried if they want to reunpack.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
RepPathItem($Item, $Repo="files")
Given an uploadtree_pk, retrieve the pfile path.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
This is the Plugin class. All plugins should:
render($templateName, $vars=null)