1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Icybee package. |
5
|
|
|
* |
6
|
|
|
* (c) Olivier Laviale <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Icybee\Modules\Files\Routing; |
13
|
|
|
|
14
|
|
|
use ICanBoogie\HTTP\FileResponse; |
15
|
|
|
use ICanBoogie\HTTP\Request; |
16
|
|
|
|
17
|
|
|
use Icybee\Modules\Files\Binding\CoreBindings; |
18
|
|
|
use Icybee\Modules\Files\File; |
19
|
|
|
use Icybee\Modules\Files\FileModel; |
20
|
|
|
use Icybee\Modules\Files\Module; |
21
|
|
|
use Icybee\Modules\Nodes\Routing\NodesAdminController; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @property FileModel $model |
25
|
|
|
*/ |
26
|
|
|
class FilesAdminController extends NodesAdminController |
27
|
|
|
{ |
28
|
|
|
use CoreBindings; |
29
|
|
|
|
30
|
|
|
protected function action_show($id) |
31
|
|
|
{ |
32
|
|
|
/* @var $record File */ |
33
|
|
|
|
34
|
|
|
$record = $this->model[$id]; |
35
|
|
|
|
36
|
|
|
$this->assert_has_permission(Module::PERMISSION_ACCESS, $record); |
37
|
|
|
|
38
|
|
|
$pathname = $this->file_storage->find($id); |
39
|
|
|
|
40
|
|
|
if (!$pathname) |
41
|
|
|
{ |
42
|
|
|
return null; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return new FileResponse($pathname, $this->request, [ |
46
|
|
|
|
47
|
|
|
FileResponse::OPTION_ETAG => $pathname->hash |
48
|
|
|
|
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function action_download($id) |
53
|
|
|
{ |
54
|
|
|
/* @var $record File */ |
55
|
|
|
|
56
|
|
|
$record = $this->model[$id]; |
57
|
|
|
|
58
|
|
|
$this->assert_has_permission(Module::PERMISSION_ACCESS, $record); |
59
|
|
|
|
60
|
|
|
$matches = $this->file_storage_index->find($id); |
61
|
|
|
|
62
|
|
|
if (!$matches) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
return null; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$key = $matches[0]; |
68
|
|
|
$pathname = $this->file_storage->find($key); |
69
|
|
|
|
70
|
|
|
if (!$pathname) |
71
|
|
|
{ |
72
|
|
|
return null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/* @var $record File */ |
76
|
|
|
|
77
|
|
|
$record = $this->model[$key->id]; |
78
|
|
|
|
79
|
|
|
return new FileResponse($pathname, $this->request, [ |
80
|
|
|
|
81
|
|
|
FileResponse::OPTION_ETAG => $pathname->hash, |
82
|
|
|
FileResponse::OPTION_FILENAME => $record->title . $record->extension, |
83
|
|
|
FileResponse::OPTION_MIME => $record->mime |
84
|
|
|
|
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.