file::delete()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 13
ccs 0
cts 7
cp 0
rs 10
cc 4
nc 6
nop 2
crap 20
1
<?php
2
/**
3
 * phpBB Gallery - Core Extension
4
 *
5
 * @package   phpbbgallery/core
6
 * @author    nickvergessen
7
 * @author    satanasov
8
 * @author    Leinad4Mind
9
 * @copyright 2014 nickvergessen, 2014- satanasov, 2018- Leinad4Mind
10
 * @license   GPL-2.0-only
11
 */
12
13
namespace phpbbgallery\core\file;
14
15
/**
16
 * A little class for all the actions that the gallery does on images.
17
*
18
* resize, rotate, watermark, crete thumbnail, write to hdd, send to browser
19
 *
20
 * @property \phpbbgallery\core\url url
21
 * @property \phpbb\request\request request
22
 */
23
class file
24
{
25
	const THUMBNAIL_INFO_HEIGHT = 16;
26
	const GDLIB1 = 1;
27
	const GDLIB2 = 2;
28
29
	public $chmod = 0644;
30
31
	public $errors = array();
32
	private $browser_cache = true;
33
	private $last_modified = 0;
34
35
	public $gd_version = 0;
36
37
	/** @var \phpbbgallery\core\config */
38
	public $gallery_config;
39
40
	public $image;
41
	public $image_content_type;
42
	public $image_name = '';
43
	public $image_quality = 100;
44
	public $image_size = array();
45
	public $image_source = '';
46
	public $image_type;
47
48
	public $max_file_size = 0;
49
	public $max_height = 0;
50
	public $max_width = 0;
51
52
	public $resized = false;
53
	public $rotated = false;
54
55
	public $thumb_height = 0;
56
	public $thumb_width = 0;
57
58
	public $watermark;
59
	public $watermark_size = array();
60
	public $watermark_source = '';
61
	public $watermarked = false;
62
63
	/**
64
	 * Constructor - init some basic stuff
65
	 *
66
	 * @param \phpbb\request\request $request
67
	 * @param \phpbbgallery\core\url $url
68
	 * @param \phpbbgallery\core\config $gallery_config
69
	 * @param int $gd_version
70
	 */
71 96
	public function __construct(\phpbb\request\request $request, \phpbbgallery\core\url $url, \phpbbgallery\core\config $gallery_config, $gd_version)
0 ignored issues
show
Bug introduced by
The type phpbb\request\request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
	{
73 96
		$this->request = $request;
74 96
		$this->url = $url;
75 96
		$this->gallery_config = $gallery_config;
76 96
		$this->gd_version = $gd_version;
77 96
	}
78
79
	public function set_image_options($max_file_size, $max_height, $max_width)
80
	{
81
		$this->max_file_size = $max_file_size;
82
		$this->max_height = $max_height;
83
		$this->max_width = $max_width;
84
	}
85
86
	public function set_image_data($source = '', $name = '', $size = 0, $force_empty_image = false)
87
	{
88
		if ($source)
89
		{
90
			$this->image_source = $source;
91
		}
92
		if ($name)
93
		{
94
			$this->image_name = $name;
95
		}
96
		if ($size)
97
		{
98
			$this->image_size['file'] = $size;
99
		}
100
		if ($force_empty_image)
101
		{
102
			$this->image = null;
103
			$this->watermarked = false;
104
			$this->rotated = false;
105
			$this->resized = false;
106
		}
107
	}
108
109
	/**
110
	 * Get image mimetype by filename
111
	 *
112
	 * Only use this, if the image is secure. As we created all these images, they should be...
113
	 * @param $filename
114
	 * @return string
115
	 */
116
	static public function mimetype_by_filename($filename)
117
	{
118
		switch (utf8_substr(strtolower($filename), -4))
0 ignored issues
show
Bug introduced by
The function utf8_substr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

118
		switch (/** @scrutinizer ignore-call */ utf8_substr(strtolower($filename), -4))
Loading history...
119
		{
120
			case '.png':
121
				return 'image/png';
122
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
123
			case '.gif':
124
				return 'image/gif';
125
			break;
126
			case 'jpeg':
127
			case '.jpg':
128
				return 'image/jpeg';
129
			break;
130
			case '.webp':
131
				return 'image/webp';
132
			break;
133
		}
134
135
		return '';
136
	}
137
138
	static public function extension_by_filename($filename)
139
	{
140
		switch (utf8_substr(strtolower($filename), -4))
0 ignored issues
show
Bug introduced by
The function utf8_substr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

140
		switch (/** @scrutinizer ignore-call */ utf8_substr(strtolower($filename), -4))
Loading history...
141
		{
142
			case '.png':
143
				return 'png';
144
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
145
			case '.gif':
146
				return 'gif';
147
			break;
148
			case 'jpeg':
149
			case '.jpg':
150
				return 'jpg';
151
			break;
152
			case '.webp':
153
				return 'webp';
154
			break;
155
		}
156
157
		return '';
158
	}
159
160
	/**
161
	 * Read image
162
	 * @param bool $force_filesize
163
	 * @return bool
164
	 */
165
	public function read_image($force_filesize = false)
166
	{
167
		if (!file_exists($this->image_source))
168
		{
169
			return false;
170
		}
171
172
		switch (utf8_substr(strtolower($this->image_source), -4))
0 ignored issues
show
Bug introduced by
The function utf8_substr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

172
		switch (/** @scrutinizer ignore-call */ utf8_substr(strtolower($this->image_source), -4))
Loading history...
173
		{
174
			case '.png':
175
				$this->image_type = 'png';
176
				$this->image = @imagecreatefrompng($this->image_source);
177
				imagealphablending($this->image, true); // Set alpha blending on ...
0 ignored issues
show
Bug introduced by
It seems like $this->image can also be of type false; however, parameter $image of imagealphablending() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

177
				imagealphablending(/** @scrutinizer ignore-type */ $this->image, true); // Set alpha blending on ...
Loading history...
178
				imagesavealpha($this->image, true); // ... and save alpha blending!
0 ignored issues
show
Bug introduced by
It seems like $this->image can also be of type false; however, parameter $image of imagesavealpha() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

178
				imagesavealpha(/** @scrutinizer ignore-type */ $this->image, true); // ... and save alpha blending!
Loading history...
179
			break;
180
			case '.webp':
181
				$this->image_type = 'webp';
182
				$this->image = imagecreatefromwebp($this->image_source);
183
			break;
184
			case '.gif':
185
				$this->image_type = 'gif';
186
				$this->image = imagecreatefromgif($this->image_source);
187
			break;
188
			default:
189
				$this->image_type = 'jpeg';
190
				$this->image = imagecreatefromjpeg($this->image_source);
191
			break;
192
		}
193
194
		$file_size = 0;
195
		if (isset($this->image_size['file']))
196
		{
197
			$file_size = $this->image_size['file'];
198
		}
199
		else if ($force_filesize)
200
		{
201
			$file_size = @filesize($this->image_source);
202
		}
203
204
		$image_size = getimagesize($this->image_source);
205
206
		$this->image_size['file'] = $file_size;
207
		$this->image_size['width'] = $image_size[0];
208
		$this->image_size['height'] = $image_size[1];
209
210
		$this->image_content_type = $image_size['mime'];
211
	}
212
213
	/**
214
	 * Write image to disk
215
	 * @param $destination
216
	 * @param int $quality
217
	 * @param bool $destroy_image
218
	 */
219
	public function write_image($destination, $quality = -1, $destroy_image = false)
220
	{
221
		if ($quality == -1)
222
		{
223
			$quality = $this->gallery_config->get('jpg_quality');
224
		}
225
		switch ($this->image_type)
226
		{
227
			case 'jpeg':
228
				imagejpeg($this->image, $destination, $quality);
229
			break;
230
			case 'png':
231
				imagepng($this->image, $destination);
232
			break;
233
			case 'webp':
234
				imagewebp($this->image, $destination);
235
			break;
236
			case 'gif':
237
				imagegif($this->image, $destination);
238
			break;
239
		}
240
		@chmod($destination, $this->chmod);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for chmod(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

240
		/** @scrutinizer ignore-unhandled */ @chmod($destination, $this->chmod);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
241
242
		if ($destroy_image)
243
		{
244
			imagedestroy($this->image);
245
		}
246
	}
247
248
	/**
249
	 * Get a browser friendly UTF-8 encoded filename
250
	 *
251
	 * @param $file
252
	 * @return string
253
	 */
254
	public function header_filename($file)
255
	{
256
		$raw = $this->request->server('HTTP_USER_AGENT');
257
		$user_agent = htmlspecialchars($raw);
258
259
		// There be dragons here.
260
		// Not many follows the RFC...
261
		if (strpos($user_agent, 'MSIE') !== false || strpos($user_agent, 'Safari') !== false || strpos($user_agent, 'Konqueror') !== false)
262
		{
263
			return "filename=" . rawurlencode($file);
264
		}
265
266
		// follow the RFC for extended filename for the rest
267
		return "filename*=UTF-8''" . rawurlencode($file);
268
	}
269
270
	/**
271
	* We need to disable the "last-modified" caching for guests and in cases of image-errors,
272
	* so that they can view them, if they logged in or the error was fixed.
273
	*/
274
	public function disable_browser_cache()
275
	{
276
		$this->browser_cache = false;
277
	}
278
279
	/**
280
	 * Collect the last timestamp where something changed.
281
	 * This must contain:
282
	 *    - Last change of the file
283
	 *    - Last change of user's permissions
284
	 *    - Last change of user's groups
285
	 *    - Last change of watermark config
286
	 *    - Last change of watermark file
287
	 * @param $timestamp
288
	 */
289
	public function set_last_modified($timestamp)
290
	{
291
		$this->last_modified = max($timestamp, $this->last_modified);
292
	}
293
294
	static public function is_ie_greater7($browser)
295
	{
296
		return (bool) preg_match('/msie (\d{2,3}|[89]+).[0-9.]*;/', strtolower($browser));
297
	}
298
299
	public function create_thumbnail($max_width, $max_height, $print_details = false, $additional_height = 0, $image_size = array())
300
	{
301
		$this->resize_image($max_width, $max_height, (($print_details) ? $additional_height : 0));
302
303
		// Create image details credits to Dr.Death
304
		if ($print_details && sizeof($image_size))
305
		{
306
			$dimension_font = 1;
307
			$dimension_string = $image_size['width'] . "x" . $image_size['height'] . "(" . intval($image_size['file'] / 1024) . "KiB)";
308
			$dimension_colour = imagecolorallocate($this->image, 255, 255, 255);
309
			$dimension_height = imagefontheight($dimension_font);
310
			$dimension_width = imagefontwidth($dimension_font) * strlen($dimension_string);
311
			$dimension_x = ($this->image_size['width'] - $dimension_width) / 2;
312
			$dimension_y = $this->image_size['height'] + (($additional_height - $dimension_height) / 2);
313
			$black_background = imagecolorallocate($this->image, 0, 0, 0);
314
			imagefilledrectangle($this->image, 0, $this->thumb_height, $this->thumb_width, $this->thumb_height + $additional_height, $black_background);
315
			imagestring($this->image, 1, $dimension_x, $dimension_y, $dimension_string, $dimension_colour);
316
		}
317
	}
318
319
	public function resize_image($max_width, $max_height, $additional_height = 0)
320
	{
321
		if (!$this->image)
322
		{
323
			$this->read_image();
324
		}
325
326
		if (($this->image_size['height'] <= $max_height) && ($this->image_size['width'] <= $max_width))
327
		{
328
			// image is small enough, nothing to do here.
329
			return;
330
		}
331
332
		if (($this->image_size['height'] / $max_height) > ($this->image_size['width'] / $max_width))
333
		{
334
			$this->thumb_height	= $max_height;
335
			$this->thumb_width	= round($max_width * (($this->image_size['width'] / $max_width) / ($this->image_size['height'] / $max_height)));
336
		}
337
		else
338
		{
339
			$this->thumb_height	= round($max_height * (($this->image_size['height'] / $max_height) / ($this->image_size['width'] / $max_width)));
340
			$this->thumb_width	= $max_width;
341
		}
342
343
		$image_copy = (($this->gd_version == self::GDLIB1) ? @imagecreate($this->thumb_width, $this->thumb_height + $additional_height) : @imagecreatetruecolor($this->thumb_width, $this->thumb_height + $additional_height));
344
		if ($this->image_type != 'jpeg')
345
		{
346
			imagealphablending($image_copy, false);
0 ignored issues
show
Bug introduced by
It seems like $image_copy can also be of type false; however, parameter $image of imagealphablending() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

346
			imagealphablending(/** @scrutinizer ignore-type */ $image_copy, false);
Loading history...
347
			imagesavealpha($image_copy, true);
0 ignored issues
show
Bug introduced by
It seems like $image_copy can also be of type false; however, parameter $image of imagesavealpha() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

347
			imagesavealpha(/** @scrutinizer ignore-type */ $image_copy, true);
Loading history...
348
			$transparent = imagecolorallocatealpha($image_copy, 255, 255, 255, 127);
0 ignored issues
show
Bug introduced by
It seems like $image_copy can also be of type false; however, parameter $image of imagecolorallocatealpha() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

348
			$transparent = imagecolorallocatealpha(/** @scrutinizer ignore-type */ $image_copy, 255, 255, 255, 127);
Loading history...
349
			imagefilledrectangle($image_copy, 0, 0, $this->thumb_width, $this->thumb_height + $additional_height, $transparent);
0 ignored issues
show
Bug introduced by
It seems like $image_copy can also be of type false; however, parameter $image of imagefilledrectangle() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

349
			imagefilledrectangle(/** @scrutinizer ignore-type */ $image_copy, 0, 0, $this->thumb_width, $this->thumb_height + $additional_height, $transparent);
Loading history...
350
		}
351
352
		$resize_function = ($this->gd_version == self::GDLIB1) ? 'imagecopyresized' : 'imagecopyresampled';
353
		$resize_function($image_copy, $this->image, 0, 0, 0, 0, $this->thumb_width, $this->thumb_height, $this->image_size['width'], $this->image_size['height']);
354
355
		imagealphablending($image_copy, true);
356
		imagesavealpha($image_copy, true);
357
		$this->image = $image_copy;
358
359
		$this->image_size['height'] = $this->thumb_height;
360
		$this->image_size['width'] = $this->thumb_width;
361
362
		$this->resized = true;
363
	}
364
365
	/**
366
	 * Rotate the image
367
	 * Usage optimized for 0º, 90º, 180º and 270º because of the height and width
368
	 *
369
	 * @param $angle
370
	 * @param $ignore_dimensions
371
	 */
372
	public function rotate_image($angle, $ignore_dimensions)
373
	{
374
		if (!function_exists('imagerotate'))
375
		{
376
			$this->errors[] = array('ROTATE_IMAGE_FUNCTION', $angle);
377
			return;
378
		}
379
		if (($angle <= 0) || (($angle % 90) != 0))
380
		{
381
			$this->errors[] = array('ROTATE_IMAGE_ANGLE', $angle);
382
			return;
383
		}
384
385
		if (!$this->image)
386
		{
387
			$this->read_image();
388
		}
389
		if ((($angle / 90) % 2) == 1)
390
		{
391
			// Left or Right, we need to switch the height and width
392
			if (!$ignore_dimensions && (($this->image_size['height'] > $this->max_width) || ($this->image_size['width'] > $this->max_height)))
393
			{
394
				// image would be to wide/high
395
				if ($this->image_size['height'] > $this->max_width)
396
				{
397
					$this->errors[] = array('ROTATE_IMAGE_WIDTH');
398
				}
399
				if ($this->image_size['width'] > $this->max_height)
400
				{
401
					$this->errors[] = array('ROTATE_IMAGE_HEIGHT');
402
				}
403
				return;
404
			}
405
			$new_width = $this->image_size['height'];
406
			$this->image_size['height'] = $this->image_size['width'];
407
			$this->image_size['width'] = $new_width;
408
		}
409
		$this->image = imagerotate($this->image, $angle, 0);
410
411
		$this->rotated = true;
412
	}
413
414
	/**
415
	 * Watermark the image:
416
	 *
417
	 * @param $watermark_source
418
	 * @param int $watermark_position summary of the parameters for vertical and horizontal adjustment
419
	 * @param int $min_height
420
	 * @param int $min_width
421
	 */
422
	public function watermark_image($watermark_source, $watermark_position = 20, $min_height = 0, $min_width = 0)
423
	{
424
		$this->watermark_source = $watermark_source;
425
		if (!$this->watermark_source || !file_exists($this->watermark_source))
426
		{
427
			$this->errors[] = array('WATERMARK_IMAGE_SOURCE');
428
			return;
429
		}
430
431
		if (!$this->image)
432
		{
433
			$this->read_image();
434
		}
435
436
		if (($min_height && ($this->image_size['height'] < $min_height)) || ($min_width && ($this->image_size['width'] < $min_width)))
437
		{
438
			return;
439
			//$this->errors[] = array('WATERMARK_IMAGE_DIMENSION');
440
		}
441
		$get_dot = strrpos($this->image_source, '.');
442
		$get_wm_name = substr_replace($this->image_source, '_wm', $get_dot, 0);
443
		if (file_exists($get_wm_name))
0 ignored issues
show
Bug introduced by
It seems like $get_wm_name can also be of type array; however, parameter $filename of file_exists() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

443
		if (file_exists(/** @scrutinizer ignore-type */ $get_wm_name))
Loading history...
444
		{
445
			$this->image_source = $get_wm_name;
446
			$this->read_image();
447
		}
448
		else
449
		{
450
			$this->watermark_size = getimagesize($this->watermark_source);
451
			switch ($this->watermark_size['mime'])
452
			{
453
				case 'image/png':
454
					$imagecreate = 'imagecreatefrompng';
455
					break;
456
				case 'image/webp':
457
					$imagecreate = 'imagecreatefromwebp';
458
					break;
459
				case 'image/gif':
460
					$imagecreate = 'imagecreatefromgif';
461
					break;
462
				default:
463
					$imagecreate = 'imagecreatefromjpeg';
464
					break;
465
			}
466
467
			// Get the watermark as resource.
468
			if (($this->watermark = $imagecreate($this->watermark_source)) === false)
469
			{
470
				$this->errors[] = array('WATERMARK_IMAGE_IMAGECREATE');
471
			}
472
473
			$phpbb_gallery_constants = new \phpbbgallery\core\constants();
474
			// Where do we display the watermark? up-left, down-right, ...?
475
			$dst_x = (($this->image_size['width'] * 0.5) - ($this->watermark_size[0] * 0.5));
476
			$dst_y = ($this->image_size['height'] - $this->watermark_size[1] - 5);
477
			if ($watermark_position & $phpbb_gallery_constants::WATERMARK_LEFT)
478
			{
479
				$dst_x = 5;
480
			}
481
			else if ($watermark_position & $phpbb_gallery_constants::WATERMARK_RIGHT)
482
			{
483
				$dst_x = ($this->image_size['width'] - $this->watermark_size[0] - 5);
484
			}
485
			if ($watermark_position & $phpbb_gallery_constants::WATERMARK_TOP)
486
			{
487
				$dst_y = 5;
488
			}
489
			else if ($watermark_position & $phpbb_gallery_constants::WATERMARK_MIDDLE)
490
			{
491
				$dst_y = (($this->image_size['height'] * 0.5) - ($this->watermark_size[1] * 0.5));
492
			}
493
			imagecopy($this->image, $this->watermark, $dst_x, $dst_y, 0, 0, $this->watermark_size[0], $this->watermark_size[1]);
0 ignored issues
show
Bug introduced by
It seems like $dst_x can also be of type double; however, parameter $dst_x of imagecopy() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

493
			imagecopy($this->image, $this->watermark, /** @scrutinizer ignore-type */ $dst_x, $dst_y, 0, 0, $this->watermark_size[0], $this->watermark_size[1]);
Loading history...
Bug introduced by
It seems like $dst_y can also be of type double; however, parameter $dst_y of imagecopy() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

493
			imagecopy($this->image, $this->watermark, $dst_x, /** @scrutinizer ignore-type */ $dst_y, 0, 0, $this->watermark_size[0], $this->watermark_size[1]);
Loading history...
494
			imagedestroy($this->watermark);
495
			$this->write_image($get_wm_name);
496
			$this->image_source = $get_wm_name;
497
			$this->read_image();
498
		}
499
		$this->watermarked = true;
500
	}
501
502
	/**
503
	* Delete file from disc.
504
	*
505
	* @param	mixed		$files		String with filename or an array of filenames
506
	*									Array-Format: $image_id => $filename
507
	* @param	array		$locations	Array of valid url::path()s where the image should be deleted from
508
	*/
509
	public function delete($files, $locations = array('thumbnail', 'medium', 'upload'))
510
	{
511
		if (!is_array($files))
512
		{
513
			$files = array(1 => $files);
514
		}
515
		// Let's delete watermarked
516
		$this->delete_wm($files);
517
		foreach ($files as $image_id => $file)
518
		{
519
			foreach ($locations as $location)
520
			{
521
				@unlink($this->url->path($location) . $file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

521
				/** @scrutinizer ignore-unhandled */ @unlink($this->url->path($location) . $file);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
Are you sure $this->url->path($location) of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

521
				@unlink(/** @scrutinizer ignore-type */ $this->url->path($location) . $file);
Loading history...
522
			}
523
		}
524
	}
525
526
	/**
527
	 * @param $files
528
	 * @param array $locations
529
	 */
530
	public function delete_cache($files, $locations = array('thumbnail', 'medium'))
531
	{
532
		if (!is_array($files))
533
		{
534
			$files = array(1 => $files);
535
		}
536
		$this->delete_wm($files);
537
		foreach ($files as $image_id => $file)
538
		{
539
			foreach ($locations as $location)
540
			{
541
				@unlink($this->url->path($location) . $file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

541
				/** @scrutinizer ignore-unhandled */ @unlink($this->url->path($location) . $file);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
Are you sure $this->url->path($location) of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

541
				@unlink(/** @scrutinizer ignore-type */ $this->url->path($location) . $file);
Loading history...
542
			}
543
		}
544
	}
545
546
	/**
547
	 * @param $files
548
	 */
549
	public function delete_wm($files)
550
	{
551
		$locations = array('upload', 'medium');
552
		if (!is_array($files))
553
		{
554
			$files = array(1 => $files);
555
		}
556
		foreach ($files as $image_id => $file)
557
		{
558
			$get_dot = strrpos($file, '.');
559
			$get_wm_name = substr_replace($file, '_wm', $get_dot, 0);
560
			foreach ($locations as $location)
561
			{
562
				@unlink($this->url->path($location) . $get_wm_name);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

562
				/** @scrutinizer ignore-unhandled */ @unlink($this->url->path($location) . $get_wm_name);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
Are you sure $this->url->path($location) of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

562
				@unlink(/** @scrutinizer ignore-type */ $this->url->path($location) . $get_wm_name);
Loading history...
563
			}
564
		}
565
	}
566
}
567