Passed
Branch master (f2d2e3)
by Michael
18:45
created

ImageEditor::processAction()   F

Complexity

Conditions 42
Paths 1378

Size

Total Lines 199
Code Lines 113

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 42
eloc 113
c 1
b 0
f 0
nc 1378
nop 3
dl 0
loc 199
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Image Editor. Editing tools, crop, rotate, scale and save.
4
 * @author Wei Zhuo
5
 * @author Paul Moers <[email protected]> - watermarking and replace code + several small enhancements <http://www.saulmade.nl/FCKeditor/FCKPlugins.php>
6
 * @version $Id: ImageEditor.php,v 1.3 2006/12/20 18:34:11 thierrybo Exp $
7
 * @package ImageManager
8
 */
9
10
require_once('Transform.php');
11
12
/**
13
 * Handles the basic image editing capbabilities.
14
 * @author Wei Zhuo
15
 * @version $Id: ImageEditor.php,v 1.3 2006/12/20 18:34:11 thierrybo Exp $
16
 * @package ImageManager
17
 * @subpackage Editor
18
 */
19
class ImageEditor 
20
{
21
	/**
22
	 * ImageManager instance.
23
	 */
24
	var $manager;
25
26
	/**
27
	 * user based on IP address
28
	 */
29
	var $_uid;
30
31
	/**
32
	 * tmp file storage time.
33
	 */
34
	var $lapse_time =900; //15 mins
35
36
	var $filesaved = 0;
37
38
	/**
39
	 * Create a new ImageEditor instance. Editing requires a 
40
	 * tmp file, which is saved in the current directory where the
41
	 * image is edited. The tmp file is assigned by md5 hash of the
42
	 * user IP address. This hashed is used as an ID for cleaning up
43
	 * the tmp files. In addition, any tmp files older than the
44
	 * the specified period will be deleted.
45
	 * @param ImageManager $manager the image manager, we need this
46
	 * for some file and path handling functions.
47
	 */
48
	function ImageEditor($manager) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
49
	{
50
		$this->manager = $manager;
51
		$this->_uid = md5($_SERVER['REMOTE_ADDR']);
52
	}
53
	
54
	/**
55
	 * Did we save a file?
56
	 * @return int 1 if the file was saved sucessfully, 
57
	 * 0 no save operation, -1 file save error.
58
	 */
59
	function isFileSaved() 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
60
	{
61
		Return $this->filesaved;
62
	}
63
64
	/**
65
	 * Process the image, if not action, just display the image.
66
	 * @return array with image information, empty array if not an image.
67
	 * <code>array('src'=>'url of the image', 'dimensions'=>'width="xx" height="yy"',
68
	 * 'file'=>'image file, relative', 'fullpath'=>'full path to the image');</code>
69
	 */
70
	function processImage($uploadedRelative)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
71
	{
72
		if (isset($uploadedRelative) && $uploadedRelative != "")
73
		{
74
			$relative = $uploadedRelative;
75
		}
76
		elseif(isset($_GET['img']))
77
		{
78
			$relative = rawurldecode($_GET['img']);
79
		}
80
		else
81
		{
82
			Return array();
83
		}
84
85
		$imgURL = $this->manager->getFileURL($relative);
86
		$fullpath = $this->manager->getFullPath($relative);
87
		
88
		$imgInfo = @getImageSize($fullpath);
89
		if(!is_array($imgInfo))
90
			Return array();
91
92
		$action = $this->getAction();
93
94
		if(!is_null($action))
0 ignored issues
show
introduced by
The condition is_null($action) is always false.
Loading history...
95
		{
96
			$image = $this->processAction($action, $relative, $fullpath);
97
		}
98
		else
99
		{
100
			$image['src'] = $imgURL;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$image was never initialized. Although not strictly required by PHP, it is generally a good practice to add $image = array(); before regardless.
Loading history...
101
			$image['dimensions'] = $imgInfo[3];
102
			$image['width'] = $imgInfo[0];
103
			$image['height'] = $imgInfo[1];
104
			$image['file'] = $relative;
105
			$image['fullpath'] = $fullpath;
106
		}
107
108
		Return $image;
109
	}
110
111
112
	/**
113
	 * Process the actions, crop, scale(resize), rotate, flip, and save.
114
	 * When ever an action is performed, the result is save into a
115
	 * temporary image file, see createUnique on the filename specs.
116
	 * It does not return the saved file, alway returning the tmp file.
117
	 * @param string $action, should be 'crop', 'scale', 'rotate','flip', or 'save'
118
	 * @param string $relative the relative image filename
119
	 * @param string $fullpath the fullpath to the image file
120
	 * @return array with image information
121
	 * <code>array('src'=>'url of the image', 'dimensions'=>'width="xx" height="yy"',
122
	 * 'file'=>'image file, relative', 'fullpath'=>'full path to the image');</code>
123
	 */
124
	function processAction($action, $relative, $fullpath) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
125
	{
126
		$params = '';
127
128
		if(isset($_GET['params']))
129
			$params = $_GET['params'];
130
131
		$values =  explode(',',$params,4);
132
		$saveFile = $this->getSaveFileName($values[0]);
133
134
		$img = Image_Transform::factory(IMAGE_CLASS);
0 ignored issues
show
Bug Best Practice introduced by
The method Image_Transform::factory() is not static, but was called statically. ( Ignorable by Annotation )

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

134
		/** @scrutinizer ignore-call */ 
135
  $img = Image_Transform::factory(IMAGE_CLASS);
Loading history...
135
		$img->load($fullpath);
136
137
		switch ($action) 
138
		{
139
			case 'replace':
140
141
				// 'ImageManager.php' handled the uploaded file, it's now on the server.
142
				// If maximum size is specified, constrain image to it.
143
				$dimensionsIndex = isset($_REQUEST['uploadSize']) ? $_REQUEST['uploadSize'] : 0;
144
				if ($this->manager->config['maxWidth'][$dimensionsIndex] > 0 && $this->manager->config['maxHeight'][$dimensionsIndex] > 0 && ($img->img_x > $this->manager->config['maxWidth'][$dimensionsIndex] || $img->img_y > $this->manager->config['maxHeight'][$dimensionsIndex]))
145
				{
146
					$percentage = min($this->manager->config['maxWidth'][$dimensionsIndex]/$img->img_x, $this->manager->config['maxHeight'][$dimensionsIndex]/$img->img_y);
147
					$img->scale($percentage);
148
				}
149
150
				break;
151
152
			case 'watermark':
153
154
					// loading target image
155
					$functionName = 'ImageCreateFrom' . $img->type;
156
					if(function_exists($functionName))
157
					{
158
						$imageResource = $functionName($fullpath);
159
					}
160
					else
161
					{
162
						echo "<script>alert(\"Error when loading '" . basename($fullpath) . "' - Loading '" . $img->type . "' files not supported\");</script>";
163
						return false;
164
					}
165
166
					// loading watermark
167
					$watermarkFullPath = $_GET['watermarkFullPath'];
168
					$watermarkImageType = strtolower(substr($watermarkFullPath, strrpos($watermarkFullPath, ".") + 1));
169
					if ($watermarkImageType == "jpg") { $watermarkImageType = "jpeg"; }
170
					if ($watermarkImageType == "tif") { $watermarkImageType = "tiff"; }
171
					$functionName = 'ImageCreateFrom' . $watermarkImageType;
172
					if(function_exists($functionName))
173
					{
174
						$watermarkResource = $functionName($watermarkFullPath);
175
					}
176
					else
177
					{
178
						echo "<script>alert(\"Error when loading '" . basename($watermarkFullPath) . "' - Loading '" . $img->type . "' files not supported\");</script>";
179
						return false;
180
					}
181
182
					$numberOfColors = imagecolorstotal($watermarkResource);
183
184
					$watermarkX = isset($_GET['watermarkX']) ? $_GET['watermarkX'] : -1;
185
					$watermarkY = isset($_GET['watermarkY']) ? $_GET['watermarkY'] : -1;
186
					$opacity = $_GET['opacity'];
187
188
					// PNG24 watermark on GIF target needs special handling
189
					// PNG24 watermark with alpha transparency on other targets need also this handling
190
					if ($watermarkImageType == "png" && $numberOfColors == 0 && ($img->type == "gif" || $opacity < 100))
191
					{
192
						require_once('Classes/api.watermark.php');
193
194
						$watermarkAPI = new watermark();
195
						$imageResource = $watermarkAPI->create_watermark($imageResource, $watermarkResource, $opacity, $watermarkX, $watermarkY);
196
					}
197
					// PNG24 watermark without alpha transparency on other targets than GIF can use 'imagecopy'
198
					elseif ($watermarkImageType == "png" && $numberOfColors == 0 && $opacity == 100)
199
					{
200
						$watermark_width = imagesx($watermarkResource);
201
						$watermark_height = imagesy($watermarkResource);
202
203
						imagecopy($imageResource, $watermarkResource, $watermarkX, $watermarkY, 0, 0, $watermark_width, $watermark_height);
204
					}
205
					// Other watermarks can be appllied no swet on all targets
206
					else
207
					{
208
						$watermark_width = imagesx($watermarkResource);
209
						$watermark_height = imagesy($watermarkResource);
210
211
						imagecopymerge($imageResource, $watermarkResource, $watermarkX, $watermarkY, 0, 0, $watermark_width, $watermark_height, $opacity);
212
					}
213
214
				break;
215
216
			case 'crop':
217
				$img->crop(intval($values[0]),intval($values[1]),
218
							intval($values[2]),intval($values[3]));
219
				break;
220
			case 'scale':
221
				$img->resize(intval($values[0]),intval($values[1]));
222
				break;
223
			case 'rotate':
224
				$img->rotate(floatval($values[0]));
225
				break;
226
			case 'flip':
227
				if ($values[0] == 'hoz')
228
					$img->flip(true);
229
				else if($values[0] == 'ver') 
230
					$img->flip(false);
231
				break;
232
			case 'save':
233
				if(!is_null($saveFile))
234
				{
235
					$quality = intval($values[1]);
236
		            if($quality <0) $quality = 85;
237
					$newSaveFile = $this->makeRelative($relative, $saveFile);
238
					$oldSaveFile = $newSaveFile;
239
240
					if ($this->manager->config['allow_newFileName'] && $this->manager->config['allow_overwrite'] == false)
241
					{
242
						// check whether a file already exist and if there is, create a variant of the filename
243
						$newName = $this->getUniqueFilename($newSaveFile);
244
						//get unique filename just returns the filename, so
245
						//we need to make the relative path again.
246
						$newSaveFile = $this->makeRelative($relative, $newName);
247
					}
248
249
					// forced new name?
250
					if ($oldSaveFile != $newSaveFile)
251
					{
252
						$this->forcedNewName = $newName;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $newName does not seem to be defined for all execution paths leading up to this point.
Loading history...
253
					}
254
					else
255
					{
256
						$this->forcedNewName = false;
257
					}
258
						
259
					$newSaveFullpath = $this->manager->getFullPath($newSaveFile);
260
					$img->save($newSaveFullpath, $values[0], $quality);
261
					if(is_file($newSaveFullpath))
262
						$this->filesaved = 1;
263
					else
264
						$this->filesaved = -1;
265
				}
266
				break;
267
		}
268
		
269
		//create the tmp image file
270
		$filename = $this->createUnique($fullpath);
271
		$newRelative = $this->makeRelative($relative, $filename);
272
		$newFullpath = $this->manager->getFullPath($newRelative);
273
		$newURL = $this->manager->getFileURL($newRelative);
274
275
		// when uploaded and not resized, rename and don't save
276
		if ($action == "replace" && $percentage <= 0)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $percentage does not seem to be defined for all execution paths leading up to this point.
Loading history...
277
		{
278
			rename($fullpath, $newFullpath);
279
		}
280
		// when watermarked, save to new filename
281
		elseif ($action == "watermark")
282
		{
283
			// save image
284
			$functionName   = 'image' . $img->type;
285
			if(function_exists($functionName))
286
			{
287
				if($type=='jpeg')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $type seems to be never defined.
Loading history...
288
					$functionName($imageResource, $newFullpath, 100);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $imageResource does not seem to be defined for all execution paths leading up to this point.
Loading history...
289
				else
290
					$functionName($imageResource, $newFullpath);
291
			}
292
			else
293
			{
294
				echo "<script>alert(\"Error when saving '" . basename($newFullpath) . "' - Saving '" . $img->type . "' files not supported\");</script>";
295
				return false;
296
			}
297
		}
298
		else
299
		{
300
			//save the file.
301
			$img->save($newFullpath);
302
			$img->free();
303
		}
304
305
		// when uploaded was resized and saved, remove original
306
		if ($action == "replace" && $percentage > 0)
307
		{
308
			unlink($fullpath);
309
		}
310
311
		//get the image information
312
		$imgInfo = @getimagesize($newFullpath);
313
314
		$image['src'] = $newURL;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$image was never initialized. Although not strictly required by PHP, it is generally a good practice to add $image = array(); before regardless.
Loading history...
315
		$image['dimensions'] = $imgInfo[3];
316
		$image['width'] = $imgInfo[0];
317
		$image['height'] = $imgInfo[1];
318
		$image['file'] = $newRelative;
319
		$image['fullpath'] = $newFullpath;
320
321
322
		Return $image;
323
	
324
	}
325
326
327
328
	/**
329
	 * Get the file name base on the save name
330
	 * and the save type.
331
	 * @param string $type image type, 'jpeg', 'png', or 'gif'
332
	 * @return string the filename according to save type
333
	 */
334
	function getSaveFileName($type) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
335
	{
336
		if(!isset($_GET['file']))
337
			Return null;
338
339
		$filename = Files::escape(rawurldecode($_GET['file']));
0 ignored issues
show
Bug Best Practice introduced by
The method Files::escape() is not static, but was called statically. ( Ignorable by Annotation )

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

339
		/** @scrutinizer ignore-call */ 
340
  $filename = Files::escape(rawurldecode($_GET['file']));
Loading history...
340
		$index = strrpos($filename,'.');
341
		$base = substr($filename,0,$index);
342
		$ext = strtolower(substr($filename,$index+1,strlen($filename)));
343
344
		if($type == 'jpeg' && !($ext=='jpeg' || $ext=='jpg'))
345
		{
346
			Return $base.'.jpeg';
347
		}
348
		if($type=='png' && $ext != 'png')
349
			Return $base.'.png';
350
		if($type=='gif' && $ext != 'gif')
351
			Return $base.'.gif';
352
353
		Return $filename;
354
	}
355
356
	/**
357
	 * Get the default save file name, used by editor.php.
358
	 * @return string a suggestive filename, this should be unique
359
	 */
360
	function getDefaultSaveFile() 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
361
	{
362
		if(isset($_GET['img']))
363
			$relative = rawurldecode($_GET['img']);
364
		else
365
			Return null;
366
367
		Return $this->getUniqueFilename($relative);
368
	}
369
370
	/**
371
	 * Get a unique filename. If the file exists, the filename
372
	 * base is appended with an increasing integer.
373
	 * @param string $relative the relative filename to the base_dir
374
	 * @return string a unique filename in the current path
375
	 */
376
	function getUniqueFilename($relative) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
377
	{
378
		$fullpath = $this->manager->getFullPath($relative);
379
		
380
		$pathinfo = pathinfo($fullpath);
381
382
		$path = Files::fixPath($pathinfo['dirname']);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::fixPath() is not static, but was called statically. ( Ignorable by Annotation )

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

382
		/** @scrutinizer ignore-call */ 
383
  $path = Files::fixPath($pathinfo['dirname']);
Loading history...
383
		$file = Files::escape($pathinfo['basename']);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::escape() is not static, but was called statically. ( Ignorable by Annotation )

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

383
		/** @scrutinizer ignore-call */ 
384
  $file = Files::escape($pathinfo['basename']);
Loading history...
384
		
385
		$filename = $file;
386
387
		$dotIndex = strrpos($file, '.');
388
		$ext = '';
389
390
		if(is_int($dotIndex)) 
0 ignored issues
show
introduced by
The condition is_int($dotIndex) is always true.
Loading history...
391
		{
392
			$ext = substr($file, $dotIndex);
393
			$base = substr($file, 0, $dotIndex);
394
		}
395
396
		$counter = 0;
397
		while(is_file($path.$filename)) 
398
		{
399
			$counter++;
400
			$filename = $base.'_'.$counter.$ext;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $base does not seem to be defined for all execution paths leading up to this point.
Loading history...
401
		}
402
		
403
		Return $filename;
404
		
405
	}
406
407
	/**
408
	 * Specifiy the original relative path, a new filename
409
	 * and return the new filename with relative path.
410
	 * i.e. $pathA (-filename) + $file
411
	 * @param string $pathA the relative file
412
	 * @param string $file the new filename
413
	 * @return string relative path with the new filename
414
	 */
415
	function makeRelative($pathA, $file) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
416
	{
417
		$index = strrpos($pathA,'/');
418
		if(!is_int($index))
0 ignored issues
show
introduced by
The condition is_int($index) is always true.
Loading history...
419
			Return $file;
420
421
		$path = substr($pathA, 0, $index);
422
		Return Files::fixPath($path).$file;
0 ignored issues
show
Bug Best Practice introduced by
The method Files::fixPath() is not static, but was called statically. ( Ignorable by Annotation )

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

422
		Return Files::/** @scrutinizer ignore-call */ fixPath($path).$file;
Loading history...
423
	}
424
425
	/**
426
	 * Get the action GET parameter
427
	 * @return string action parameter
428
	 */
429
	function getAction() 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
430
	{
431
		$action = null;
432
		if(isset($_GET['action']))
433
			$action = $_GET['action'];
434
		Return $action;
435
	}
436
437
	/**
438
	 * Generate a unique string based on md5(microtime()).
439
	 * Well not so uniqe, as it is limited to 6 characters
440
	 * @return string unique string.
441
	 */
442
    function uniqueStr()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
443
    {
444
      return substr(md5(microtime()),0,6);
445
    }
446
447
	/**
448
	 * Create unique tmp image file name.
449
	 * The filename is based on the tmp file prefix
450
	 * specified in config.inc.php plus 
451
	 * the UID (basically a md5 of the remote IP)
452
	 * and some random 6 character string.
453
	 * This function also calls to clean up the tmp files.
454
	 * @param string $file the fullpath to a file
455
	 * @return string a unique filename for that path
456
	 * NOTE: it only returns the filename, path no included.
457
	 */
458
	function createUnique($file) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
459
	{
460
		$pathinfo = pathinfo($file);
461
		$path = Files::fixPath($pathinfo['dirname']);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::fixPath() is not static, but was called statically. ( Ignorable by Annotation )

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

461
		/** @scrutinizer ignore-call */ 
462
  $path = Files::fixPath($pathinfo['dirname']);
Loading history...
462
		$imgType = $this->getImageType($file);
463
464
		$unique_str = $this->manager->getTmpPrefix().$this->_uid.'_'.$this->uniqueStr().".".$imgType;
465
466
	   //make sure the the unique temp file does not exists
467
        while (file_exists($path.$unique_str))
468
        {
469
            $unique_str = $this->manager->getTmpPrefix().$this->_uid.'_'.$this->uniqueStr().".".$imgType;
470
        }
471
472
		$this->cleanUp($path,$pathinfo['basename']);
473
474
		Return $unique_str;
475
	}
476
477
	/**
478
	 * Delete any tmp image files.
479
	 * @param string $path the full path 
480
	 * where the clean should take place.
481
	 */
482
	function cleanUp($path,$file) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
483
	{
484
		$path = Files::fixPath($path);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::fixPath() is not static, but was called statically. ( Ignorable by Annotation )

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

484
		/** @scrutinizer ignore-call */ 
485
  $path = Files::fixPath($path);
Loading history...
485
486
		if(!is_dir($path))
487
			Return false;
488
489
		$d = @dir($path);
490
		
491
		$tmp = $this->manager->getTmpPrefix();
492
		$tmpLen = strlen($tmp);
493
494
		$prefix = $tmp.$this->_uid;
495
		$len = strlen($prefix);
496
497
		while (false !== ($entry = $d->read())) 
0 ignored issues
show
Bug introduced by
The method read() does not exist on null. ( Ignorable by Annotation )

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

497
		while (false !== ($entry = $d->/** @scrutinizer ignore-call */ read())) 

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
498
		{
499
			//echo $entry."<br>";
500
			if(is_file($path.$entry) && $this->manager->isTmpFile($entry))
501
			{
502
				if(substr($entry,0,$len)==$prefix && $entry != $file)
503
					Files::delFile($path.$entry);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::delFile() is not static, but was called statically. ( Ignorable by Annotation )

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

503
					Files::/** @scrutinizer ignore-call */ 
504
            delFile($path.$entry);
Loading history...
504
				else if(substr($entry,0,$tmpLen)==$tmp && $entry != $file)
505
				{
506
					if(filemtime($path.$entry)+$this->lapse_time < time())
507
						Files::delFile($path.$entry);
508
				}
509
			}
510
		}
511
		$d->close();
512
	}
513
514
	/**
515
	 * Get the image type base on an image file.
516
	 * @param string $file the full path to the image file.
517
	 * @return string of either 'gif', 'jpeg', 'png' or 'bmp'
518
	 * otherwise it will return null.
519
	 */
520
	function getImageType($file) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
521
	{
522
		$imageInfo = @getImageSize($file);
523
524
		if(!is_array($imageInfo))
525
			Return null;
526
527
		switch($imageInfo[2]) 
528
		{
529
			case 1:
530
				Return 'gif';
531
			case 2:
532
				Return 'jpeg';
533
			case 3:
534
				Return 'png';
535
			case 6:
536
				Return 'bmp';
537
		}
538
539
		Return null;
540
	}
541
542
	/**
543
	 * Check if the specified image can be edit by GD
544
	 * mainly to check that GD can read and save GIFs
545
	 * @return int 0 if it is not a GIF file, 1 is GIF is editable, -1 if not editable.
546
	 */
547
	function isGDEditable() 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
548
	{
549
		if(isset($_GET['img']))
550
			$relative = rawurldecode($_GET['img']);
551
		else
552
			Return 0;
553
		if(IMAGE_CLASS != 'GD')
0 ignored issues
show
introduced by
The condition IMAGE_CLASS != 'GD' is always false.
Loading history...
554
			Return 0;
555
556
		$fullpath = $this->manager->getFullPath($relative);
557
558
		$type = $this->getImageType($fullpath);
559
		if($type != 'gif')
560
			Return 0;
561
562
		if(function_exists('ImageCreateFrom'+$type)
563
			&& function_exists('image'+$type))
564
			Return 1;
565
		else
566
			Return -1;
567
	}
568
569
	/**
570
	 * Check if GIF can be edit by GD.
571
	 * @return int 0 if it is not using the GD library, 1 is GIF is editable, -1 if not editable.
572
	 */
573
	function isGDGIFAble() 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
574
	{
575
		if(IMAGE_CLASS != 'GD')
0 ignored issues
show
introduced by
The condition IMAGE_CLASS != 'GD' is always false.
Loading history...
576
			Return 0;
577
578
		if(function_exists('ImageCreateFromGif')
579
			&& function_exists('imagegif'))
580
			Return 1;
581
		else
582
			Return -1;
583
	}
584
}
585
586
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
587