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 | * ownCloud - TemporaryPhoto |
||
4 | * |
||
5 | * @author Thomas Tanghus |
||
6 | * @copyright 2014 Thomas Tanghus ([email protected]) |
||
7 | * |
||
8 | * This library is free software; you can redistribute it and/or |
||
9 | * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
||
10 | * License as published by the Free Software Foundation; either |
||
11 | * version 3 of the License, or any later version. |
||
12 | * |
||
13 | * This library is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Affero General Public |
||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
||
20 | * |
||
21 | */ |
||
22 | |||
23 | namespace OCA\Contacts\Utils; |
||
24 | |||
25 | use OCP\ICache; |
||
26 | use OCP\Image; |
||
27 | |||
28 | /** |
||
29 | * This class is used for getting a temporary contact photo for cropping. |
||
30 | * |
||
31 | * Sub-classes must override __construct() and processImage() |
||
32 | */ |
||
33 | class TemporaryPhoto { |
||
34 | |||
35 | const MAX_SIZE = 400; |
||
36 | |||
37 | const PHOTO_CURRENT = 0; |
||
38 | const PHOTO_FILESYSTEM = 1; |
||
39 | const PHOTO_UPLOADED = 2; |
||
40 | const PHOTO_USER = 3; |
||
41 | |||
42 | /** |
||
43 | * @var \OCP\ICache |
||
44 | */ |
||
45 | protected $cache; |
||
46 | |||
47 | /** |
||
48 | * @var \OCP\Image |
||
49 | */ |
||
50 | protected $image; |
||
51 | |||
52 | /** |
||
53 | * Cache key for temporary storage. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $key; |
||
58 | |||
59 | |||
60 | /** |
||
61 | * Whether normalizePhoto() has already been called. |
||
62 | * |
||
63 | * @var bool |
||
64 | */ |
||
65 | protected $normalized; |
||
66 | |||
67 | /** |
||
68 | * Whether the photo is cached. |
||
69 | * |
||
70 | * @var bool |
||
71 | */ |
||
72 | protected $cached; |
||
73 | |||
74 | /** |
||
75 | * Photo loader classes. |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | static public $classMap = array( |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
80 | 'OCA\\Contacts\\Utils\\TemporaryPhoto\\Contact', |
||
81 | 'OCA\\Contacts\\Utils\\TemporaryPhoto\\FileSystem', |
||
82 | 'OCA\\Contacts\\Utils\\TemporaryPhoto\\Uploaded', |
||
83 | 'OCA\\Contacts\\Utils\\TemporaryPhoto\\User', |
||
84 | ); |
||
85 | |||
86 | /** |
||
87 | * Always call parents ctor in subclasses: |
||
88 | * parent::__construct($cache); |
||
89 | */ |
||
90 | public function __construct(ICache $cache, $key = null) { |
||
91 | $this->cache = $cache; |
||
92 | $this->key = $key; |
||
93 | if (!is_null($key)) { |
||
94 | $this->processImage(); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Returns an instance of a subclass of this class |
||
100 | * |
||
101 | */ |
||
102 | public static function create(ICache $cache, $type = null, $data = null) { |
||
103 | if (isset(self::$classMap[$type])) { |
||
104 | return new self::$classMap[$type]($cache, $data); |
||
105 | } else { |
||
106 | return new self($cache, $data); |
||
107 | } |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Remove a cached image by key. |
||
112 | * |
||
113 | * @param string $key |
||
114 | */ |
||
115 | public function remove($key) { |
||
116 | return $this->cache->remove($key); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Do what's needed to get the image from storage |
||
121 | * depending on the type. |
||
122 | * After this method is called $this->image must hold an |
||
123 | * instance of \OCP\Image. |
||
124 | */ |
||
125 | protected function processImage() { |
||
126 | $this->image = new Image(); |
||
127 | $this->image->loadFromData($this->cache->get($this->key)); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Whether this image is valied |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function isValid() { |
||
136 | return (($this->image instanceof Image) && $this->image->valid()); |
||
0 ignored issues
–
show
The class
OCP\Image does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Get the key to the cache image. |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getKey() { |
||
145 | $this->cachePhoto(); |
||
146 | return $this->key; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Get normalized image. |
||
151 | * |
||
152 | * @return \OCP\Image |
||
153 | */ |
||
154 | public function getPhoto() { |
||
155 | $this->normalizePhoto(); |
||
156 | return $this->image; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Save image data to cache and return the key |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | private function cachePhoto() { |
||
165 | if ($this->cached) { |
||
166 | return; |
||
167 | } |
||
168 | |||
169 | if (!$this->image instanceof Image) { |
||
0 ignored issues
–
show
The class
OCP\Image does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
170 | $this->processImage(); |
||
171 | } |
||
172 | $this->normalizePhoto(); |
||
173 | |||
174 | $data = $this->image->data(); |
||
175 | $this->key = uniqid('photo-'); |
||
176 | $this->cache->set($this->key, $data, 600); |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * Resize and rotate the image if needed. |
||
181 | */ |
||
182 | private function normalizePhoto() { |
||
183 | |||
184 | if($this->normalized) { |
||
185 | return; |
||
186 | } |
||
187 | |||
188 | $this->image->fixOrientation(); |
||
189 | |||
190 | if ($this->image->height() > self::MAX_SIZE |
||
191 | || $this->image->width() > self::MAX_SIZE |
||
192 | ) { |
||
193 | $this->image->resize(self::MAX_SIZE); |
||
194 | } |
||
195 | |||
196 | $this->normalized = true; |
||
197 | } |
||
198 | |||
199 | public function getMimeType(){ |
||
200 | return $this->image->mimeType(); |
||
201 | } |
||
202 | |||
203 | public function getImage(){ |
||
204 | return $this->image; |
||
205 | } |
||
206 | } |