This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Gallery |
||
4 | * |
||
5 | * This file is licensed under the Affero General Public License version 3 or |
||
6 | * later. See the COPYING file. |
||
7 | * |
||
8 | * @author Olivier Paroz <[email protected]> |
||
9 | * |
||
10 | * @copyright Olivier Paroz 2014-2016 |
||
11 | */ |
||
12 | |||
13 | namespace OCA\Gallery\Preview; |
||
14 | |||
15 | use OCP\Files\Folder; |
||
16 | use OCP\IConfig; |
||
17 | use OCP\Image; |
||
18 | use OCP\Files\File; |
||
19 | use OCP\IPreview; |
||
20 | use OCP\ILogger; |
||
21 | |||
22 | /** |
||
23 | * Generates previews |
||
24 | * |
||
25 | * @todo On OC9, replace \OC\Preview with IPreview if methods we need have been added |
||
26 | * |
||
27 | * @package OCA\Gallery\Preview |
||
28 | */ |
||
29 | class Preview { |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $dataDir; |
||
35 | /** |
||
36 | * @var mixed |
||
37 | */ |
||
38 | private $previewManager; |
||
39 | /** |
||
40 | * @var ILogger |
||
41 | */ |
||
42 | private $logger; |
||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | private $userId; |
||
47 | /** |
||
48 | * @var \OC\Preview |
||
49 | */ |
||
50 | private $preview; |
||
51 | /** |
||
52 | * @var File |
||
53 | */ |
||
54 | private $file; |
||
55 | /** |
||
56 | * @var int[] |
||
57 | */ |
||
58 | private $dims; |
||
59 | |||
60 | /** |
||
61 | * Constructor |
||
62 | * |
||
63 | * @param IConfig $config |
||
64 | * @param IPreview $previewManager |
||
65 | * @param ILogger $logger |
||
66 | */ |
||
67 | public function __construct( |
||
68 | IConfig $config, |
||
69 | IPreview $previewManager, |
||
70 | ILogger $logger |
||
71 | ) { |
||
72 | $this->dataDir = $config->getSystemValue('datadirectory'); |
||
73 | $this->previewManager = $previewManager; |
||
74 | $this->logger = $logger; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Returns true if the passed mime type is supported |
||
79 | * |
||
80 | * @param string $mimeType |
||
81 | * |
||
82 | * @return boolean |
||
83 | */ |
||
84 | public function isMimeSupported($mimeType = '*') { |
||
85 | return $this->previewManager->isMimeSupported($mimeType); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Initialises the view which will be used to access files and generate previews |
||
90 | * |
||
91 | * @fixme Private API, but can't use the PreviewManager yet as it's incomplete |
||
92 | * |
||
93 | * @param string $userId |
||
94 | * @param File $file |
||
95 | * @param string $imagePathFromFolder |
||
96 | */ |
||
97 | public function setupView($userId, $file, $imagePathFromFolder) { |
||
98 | $this->userId = $userId; |
||
99 | $this->file = $file; |
||
100 | $imagePathFromFolder = \ltrim($imagePathFromFolder, '/'); |
||
101 | if (\version_compare(\implode('.', \OCP\Util::getVersion()), '10.0.9', '>=')) { |
||
102 | /** @var Folder $userFolder */ |
||
103 | $userFolder = \OC::$server->getUserFolder($userId); |
||
104 | $node = $userFolder->get($imagePathFromFolder); |
||
105 | $this->preview = new \OC\Preview($userId, 'files', $node); |
||
106 | } else { |
||
107 | $this->preview = new \OC\Preview($userId, 'files', $imagePathFromFolder); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Returns a preview based on OC's preview class and our custom methods |
||
113 | * |
||
114 | * We check that the preview returned by the Preview class can be used by |
||
115 | * the browser. If not, we send "false" to the controller |
||
116 | * |
||
117 | * @fixme setKeepAspect is missing from public interface. |
||
118 | * https://github.com/owncloud/core/issues/12772 |
||
119 | * |
||
120 | * @param int $maxWidth |
||
121 | * @param int $maxHeight |
||
122 | * @param bool $keepAspect |
||
123 | * |
||
124 | * @return array<string,string|\OC_Image>|false |
||
0 ignored issues
–
show
|
|||
125 | */ |
||
126 | public function preparePreview($maxWidth, $maxHeight, $keepAspect) { |
||
127 | $this->dims = [$maxWidth, $maxHeight]; |
||
128 | |||
129 | $previewData = $this->getPreviewFromCore($keepAspect); |
||
130 | |||
131 | if ($previewData && $previewData->valid()) { |
||
132 | $preview = [ |
||
133 | 'preview' => $previewData, |
||
134 | 'mimetype' => $previewData->mimeType() |
||
135 | ]; |
||
136 | } else { |
||
137 | $preview = false; |
||
138 | } |
||
139 | |||
140 | return $preview; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Asks core for a preview based on our criteria |
||
145 | * |
||
146 | * @todo Need to read scaling setting from settings |
||
147 | * |
||
148 | * @param bool $keepAspect |
||
149 | * |
||
150 | * @return \OC_Image |
||
151 | */ |
||
152 | private function getPreviewFromCore($keepAspect) { |
||
153 | list($maxX, $maxY) = $this->dims; |
||
154 | |||
155 | $this->preview->setMaxX($maxX); |
||
156 | $this->preview->setMaxY($maxY); |
||
157 | $this->preview->setScalingUp(false); |
||
158 | $this->preview->setKeepAspect($keepAspect); |
||
159 | |||
160 | //$this->logger->debug("[PreviewService] preview {preview}", ['preview' => $this->preview]); |
||
161 | |||
162 | $previewData = $this->preview->getPreview(); |
||
163 | |||
164 | return $previewData; |
||
165 | } |
||
166 | } |
||
167 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.