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

ExtendedFileManager   F

Complexity

Total Complexity 127

Size/Duplication

Total Lines 796
Duplicated Lines 27.39 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 218
loc 796
rs 1.804
c 0
b 0
f 0
wmc 127
lcom 1
cbo 1

32 Methods

Rating   Name   Duplication   Size   Complexity  
A getThumbURL() 0 21 5
A processPaste() 0 26 5
A getFullPath() 0 3 1
B _processFiles() 0 50 10
A processNewDir() 0 15 5
A getDiskInfo() 0 10 4
A isThumb() 0 7 2
A isThumbDir() 0 7 3
B countFiles() 0 22 7
A isValidBase() 0 3 1
A getImagesDir() 0 5 3
A isTmpFile() 0 7 2
A ExtendedFileManager() 0 5 3
A getDefaultThumb() 0 6 2
A _dirs() 0 27 6
A getFileURL() 0 3 1
A getDirs() 0 9 2
A processRenames() 0 34 5
C getFiles() 0 57 12
A getThumbName() 0 22 5
A _delFile() 0 21 4
A getImageInfo() 0 3 1
A processUploads() 0 16 5
A checkImageSize() 0 29 5
A deleteFiles() 0 5 2
A getImagesURL() 0 5 3
A validRelativePath() 0 17 4
A getTmpPrefix() 0 3 1
B getThumbnail() 0 50 10
A deleteDirs() 0 6 2
A _delDir() 0 5 1
A getResizedName() 0 16 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ExtendedFileManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ExtendedFileManager, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * ExtendedFileManager, list images, directories, and thumbnails.
4
 * Authors: Wei Zhuo, Afru, Krzysztof Kotowicz, Raimund Meyer
5
 * Version: Updated on 08-01-2005 by Afru
6
 * Version: Updated on 04-07-2006 by Krzysztof Kotowicz
7
 * Version: Updated on 29-10-2006 by Raimund Meyer
8
 * Package: ExtendedFileManager (EFM 1.1.3)
9
 * http://www.afrusoft.com/htmlarea
10
 */
11
12
/**
13
 * We use classes from ImageManager to avoid code duplication
14
 */
15
require_once '../ImageManager/Classes/Files.php';
16
17
/**
18
 * ExtendedFileManager Class.
19
 * @author Wei Zhuo, Afru, Krzysztof Kotowicz, Raimund Meyer
20
 * @version $Id: ExtendedFileManager.php 1171 2009-03-19 22:06:09Z ray $
21
 */
22
class ExtendedFileManager 
23
{
24
	/**
25
	 * Configuration array.
26
	 */
27
	var $config;
28
29
	/**
30
	 * Array of directory information.
31
	 */
32
	var $dirs;
33
	
34
    /**
35
     * Manager mode - image | link
36
     */
37
	var $mode;
38
39
	/**
40
	 * Constructor. Create a new Image Manager instance.
41
	 * @param array $config configuration array, see config.inc.php
42
	 */
43
	function ExtendedFileManager($config, $mode = null)
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...
44
	{
45
		$this->config = $config;
46
		
47
		$this->mode = empty($mode) ? (empty($config['insert_mode']) ? 'image' : $config['insert_mode']): $mode;
48
	}
49
50
	/**
51
	 * Get the base directory.
52
	 * @return string base dir, see config.inc.php
53
	 */
54
	function getImagesDir()
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...
55
	{
56
		if ($this->mode == 'link' && isset($this->config['files_dir']))
57
			Return $this->config['files_dir'];
58
		else Return $this->config['images_dir'];
59
	}
60
61
	/**
62
	 * Get the base URL.
63
	 * @return string base url, see config.inc.php
64
	 */
65
	function getImagesURL()
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...
66
	{
67
		if ($this->mode == 'link' && isset($this->config['files_url']))
68
				Return $this->config['files_url'];
69
		else Return $this->config['images_url'];
70
	}
71
72
	function isValidBase()
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...
73
	{
74
		return is_dir($this->getImagesDir());
75
	}
76
77
	/**
78
	 * Get the tmp file prefix.
79
     * @return string tmp file prefix.
80
	 */
81
	function getTmpPrefix() 
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...
82
	{
83
		Return $this->config['tmp_prefix'];
84
	}
85
86
	/**
87
	 * Get the sub directories in the base dir.
88
	 * Each array element contain
89
	 * the relative path (relative to the base dir) as key and the 
90
	 * full path as value.
91
	 * @return array of sub directries
92
	 * <code>array('path name' => 'full directory path', ...)</code>
93
	 */
94
	function getDirs() 
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...
95
	{
96
		if(is_null($this->dirs))
97
		{
98
			$dirs = $this->_dirs($this->getImagesDir(),'/');
99
			ksort($dirs);
100
			$this->dirs = $dirs;
101
		}
102
		return $this->dirs;
103
	}
104
105
	/**
106
	 * Recursively travese the directories to get a list
107
	 * of accessable directories.
108
	 * @param string $base the full path to the current directory
109
	 * @param string $path the relative path name
110
	 * @return array of accessiable sub-directories
111
	 * <code>array('path name' => 'full directory path', ...)</code>
112
	 */
113
	function _dirs($base, $path) 
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...
114
	{
115
		$base = Files::fixPath($base);
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

115
		/** @scrutinizer ignore-call */ 
116
  $base = Files::fixPath($base);
Loading history...
116
		$dirs = array();
117
118
		if($this->isValidBase() == false)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
119
			return $dirs;
120
121
		$d = @dir($base);
122
		
123
		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

123
		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...
124
		{
125
			//If it is a directory, and it doesn't start with
126
			// a dot, and if is it not the thumbnail directory
127
			if(is_dir($base.$entry) 
128
				&& substr($entry,0,1) != '.'
129
				&& $this->isThumbDir($entry) == false) 
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
130
			{
131
				$relative = Files::fixPath($path.$entry);
132
				$fullpath = Files::fixPath($base.$entry);
133
				$dirs[$relative] = $fullpath;
134
				$dirs = array_merge($dirs, $this->_dirs($fullpath, $relative));
135
			}
136
		}
137
		$d->close();
138
139
		Return $dirs;
140
	}
141
142
	/**
143
	 * Get all the files and directories of a relative path.
144
	 * @param string $path relative path to be base path.
145
	 * @return array of file and path information.
146
	 * <code>array(0=>array('relative'=>'fullpath',...), 1=>array('filename'=>fileinfo array(),...)</code>
147
	 * fileinfo array: <code>array('url'=>'full url', 
148
	 *                       'relative'=>'relative to base', 
149
	 *                        'fullpath'=>'full file path', 
150
	 *                        'image'=>imageInfo array() false if not image,
151
	 *                        'stat' => filestat)</code>
152
	 */
153
	function getFiles($path) 
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...
154
	{
155
		$files = array();
156
		$dirs = array();
157
158
        $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions'];
159
160
		if($this->isValidBase() == false)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
161
			return array($files,$dirs);
162
163
		$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

163
		/** @scrutinizer ignore-call */ 
164
  $path = Files::fixPath($path);
Loading history...
164
		$base = Files::fixPath($this->getImagesDir());
165
		$fullpath = Files::makePath($base,$path);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makePath() 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

165
		/** @scrutinizer ignore-call */ 
166
  $fullpath = Files::makePath($base,$path);
Loading history...
166
167
168
		$d = @dir($fullpath);
169
		
170
		while (false !== ($entry = $d->read())) 
171
		{
172
			//not a dot file or directory
173
			if(substr($entry,0,1) != '.')
174
			{
175
				if(is_dir($fullpath.$entry)
176
					&& $this->isThumbDir($entry) == false)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
177
				{
178
					$relative = Files::fixPath($path.$entry);
179
					$full = Files::fixPath($fullpath.$entry);
180
					$count = $this->countFiles($full);
181
					$dirs[$relative] = array('fullpath'=>$full,'entry'=>$entry,'count'=>$count, 'stat'=>stat($fullpath.$entry));
182
				}
183
184
				else if(is_file($fullpath.$entry) && $this->isThumb($entry)==false && $this->isTmpFile($entry) == false) 
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
185
				{
186
					$afruext = strtolower(substr(strrchr($entry, "."), 1));
187
188
                    if(in_array($afruext,$valid_extensions))
189
					{
190
191
						$file['url'] = Files::makePath($this->config['base_url'],$path).$entry;
192
						$file['relative'] = $path.$entry;
193
						$file['fullpath'] = $fullpath.$entry;
194
						$img = $this->getImageInfo($fullpath.$entry);
195
						if(!is_array($img)) $img[0]=$img[1]=0;
196
						$file['image'] = $img;
197
						$file['stat'] = stat($fullpath.$entry);
198
						$file['ext'] = $afruext;
199
						$files[$entry] = $file;
200
					}
201
202
				}
203
			}
204
		}
205
		$d->close();
206
		ksort($dirs);
207
		ksort($files);
208
		
209
		Return array($dirs, $files);
210
	}	
211
212
	/**
213
	 * Count the number of files and directories in a given folder
214
	 * minus the thumbnail folders and thumbnails.
215
	 */
216
	function countFiles($path) 
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...
217
	{
218
		$total = 0;
219
220
		if(is_dir($path)) 
221
		{
222
			$d = @dir($path);
223
224
			while (false !== ($entry = $d->read())) 
225
			{
226
				//echo $entry."<br>";
227
				if(substr($entry,0,1) != '.'
228
					&& $this->isThumbDir($entry) == false
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
229
					&& $this->isTmpFile($entry) == false
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
230
					&& $this->isThumb($entry) == false) 
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
231
				{
232
					$total++;
233
				}
234
			}
235
			$d->close();
236
		}
237
		return $total;
238
	}
239
240
	/**
241
	 * Get image size information.
242
	 * @param string $file the image file
243
	 * @return array of getImageSize information, 
244
	 *  false if the file is not an image.
245
	 */
246
	function getImageInfo($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...
247
	{
248
		Return @getImageSize($file);
0 ignored issues
show
Bug Best Practice introduced by
The expression return @getImageSize($file) could also return false which is incompatible with the documented return type array. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
249
	}
250
251
	/**
252
	 * Check if the file contains the thumbnail prefix.
253
	 * @param string $file filename to be checked
254
	 * @return true if the file contains the thumbnail prefix, false otherwise.
255
	 */
256
	function isThumb($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...
257
	{
258
		$len = strlen($this->config['thumbnail_prefix']);
259
		if(substr($file,0,$len)==$this->config['thumbnail_prefix'])
260
			Return true;
261
		else
262
			Return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type true.
Loading history...
263
	}
264
265
	/**
266
	 * Check if the given directory is a thumbnail directory.
267
	 * @param string $entry directory name
268
	 * @return true if it is a thumbnail directory, false otherwise
269
	 */
270
	function isThumbDir($entry) 
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...
271
	{
272
		if($this->config['thumbnail_dir'] == false
273
			|| strlen(trim($this->config['thumbnail_dir'])) == 0)
274
			Return false;		
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type true.
Loading history...
275
		else
276
			Return ($entry == $this->config['thumbnail_dir']);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $entry == $this->config['thumbnail_dir'] returns the type boolean which is incompatible with the documented return type true.
Loading history...
277
	}
278
279
	/**
280
	 * Check if the given file is a tmp file.
281
	 * @param string $file file name
282
	 * @return boolean true if it is a tmp file, false otherwise
283
	 */
284
	function isTmpFile($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...
285
	{
286
		$len = strlen($this->config['tmp_prefix']);
287
		if(substr($file,0,$len)==$this->config['tmp_prefix'])
288
			Return true;
289
		else
290
			Return false;	 	
291
	}
292
293
	/**
294
	 * For a given image file, get the respective thumbnail filename
295
	 * no file existence check is done.
296
	 * @param string $fullpathfile the full path to the image file
297
	 * @return string of the thumbnail file
298
	 */
299
	function getThumbName($fullpathfile) 
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...
300
	{
301
		$path_parts = pathinfo($fullpathfile);
302
		
303
		$thumbnail = $this->config['thumbnail_prefix'].$path_parts['basename'];
304
305
		if($this->config['safe_mode'] == true
306
			|| strlen(trim($this->config['thumbnail_dir'])) == 0)
307
		{
308
			Return Files::makeFile($path_parts['dirname'],$thumbnail);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

308
			Return Files::/** @scrutinizer ignore-call */ makeFile($path_parts['dirname'],$thumbnail);
Loading history...
309
		}
310
		else
311
		{
312
			if(strlen(trim($this->config['thumbnail_dir'])) > 0)
313
			{
314
				$path = Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makePath() 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

314
				/** @scrutinizer ignore-call */ 
315
    $path = Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']);
Loading history...
315
				if(!is_dir($path))
316
					Files::createFolder($path);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::createFolder() 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

316
					Files::/** @scrutinizer ignore-call */ 
317
            createFolder($path);
Loading history...
317
				Return Files::makeFile($path,$thumbnail);
318
			}
319
			else //should this ever happen?
320
			{
321
				//error_log('ExtendedFileManager: Error in creating thumbnail name');
322
			}
323
		}
324
	}
325
	
326
	/**
327
	 * Similar to getThumbName, but returns the URL, base on the
328
	 * given base_url in config.inc.php
329
	 * @param string $relative the relative image file name, 
330
	 * relative to the base_dir path
331
	 * @return string the url of the thumbnail
332
	 */
333
	function getThumbURL($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...
334
	{
335
		$path_parts = pathinfo($relative);
336
		$thumbnail = $this->config['thumbnail_prefix'].$path_parts['basename'];
337
		if($path_parts['dirname']=='\\') $path_parts['dirname']='/';
338
339
		if($this->config['safe_mode'] == true
340
			|| strlen(trim($this->config['thumbnail_dir'])) == 0)
341
		{
342
			Return Files::makeFile($this->getImagesURL(),$thumbnail);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

342
			Return Files::/** @scrutinizer ignore-call */ makeFile($this->getImagesURL(),$thumbnail);
Loading history...
343
		}
344
		else
345
		{
346
			if(strlen(trim($this->config['thumbnail_dir'])) > 0)
347
			{
348
				$path = Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makePath() 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

348
				/** @scrutinizer ignore-call */ 
349
    $path = Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']);
Loading history...
349
				$url_path = Files::makePath($this->getImagesURL(), $path);
350
				Return Files::makeFile($url_path,$thumbnail);
351
			}
352
			else //should this ever happen?
353
			{
354
				//error_log('ExtendedFileManager: Error in creating thumbnail url');
355
			}
356
357
		}
358
	}
359
360
   /**
361
    * For a given image file, get the respective resized filename
362
    * no file existence check is done.
363
    * @param string $fullpathfile the full path to the image file
364
    * @param integer $width the intended width
365
    * @param integer $height the intended height
366
    * @param boolean $mkDir whether to attempt to make the resized_dir if it doesn't exist
367
    * @return string of the resized filename
368
    */
369
	function getResizedName($fullpathfile, $width, $height, $mkDir = TRUE)
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...
370
	{
371
		$path_parts = pathinfo($fullpathfile);
372
373
		$thumbnail = $this->config['resized_prefix']."_{$width}x{$height}_{$path_parts['basename']}";
374
375
		if( strlen(trim($this->config['resized_dir'])) == 0 || $this->config['safe_mode'] == true )
376
		{
377
			Return Files::makeFile($path_parts['dirname'],$thumbnail);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

377
			Return Files::/** @scrutinizer ignore-call */ makeFile($path_parts['dirname'],$thumbnail);
Loading history...
378
		}
379
		else
380
		{
381
      $path = Files::makePath($path_parts['dirname'],$this->config['resized_dir']);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makePath() 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

381
      /** @scrutinizer ignore-call */ 
382
      $path = Files::makePath($path_parts['dirname'],$this->config['resized_dir']);
Loading history...
382
      if($mkDir && !is_dir($path))
383
        Files::createFolder($path);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::createFolder() 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
        Files::/** @scrutinizer ignore-call */ 
384
               createFolder($path);
Loading history...
384
      Return Files::makeFile($path,$thumbnail);
385
		}
386
	}
387
388
	/**
389
	 * Check if the given path is part of the subdirectories
390
	 * under the base_dir.
391
	 * @param string $path the relative path to be checked
392
	 * @return boolean true if the path exists, false otherwise
393
	 */
394
	function validRelativePath($path) 
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...
395
	{
396
		$dirs = $this->getDirs();
397
		if($path == '/')
398
			Return true;
399
		//check the path given in the url against the 
400
		//list of paths in the system.
401
		for($i = 0; $i < count($dirs); $i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
402
		{
403
			$key = key($dirs);
404
			//we found the path
405
			if($key == $path)
406
				Return true;
407
		
408
			next($dirs);
409
		}		
410
		Return false;
411
	}
412
413
	/**
414
	 * Process uploaded files, assumes the file is in 
415
	 * $_FILES['upload'] and $_POST['dir'] is set.
416
	 * The dir must be relative to the base_dir and exists.
417
	 * @return null
418
	 */
419
	function processUploads() 
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...
420
	{
421
		if($this->isValidBase() == false)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
422
			return;
423
424
		$relative = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $relative is dead and can be removed.
Loading history...
425
426
		if(isset($_POST['dir'])) 
427
			$relative = rawurldecode($_POST['dir']);
428
		else
429
			return;
430
431
		//check for the file, and must have valid relative path
432
		if(isset($_FILES['upload']) && $this->validRelativePath($relative))
433
		{
434
			Return $this->_processFiles($relative, $_FILES['upload']);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->_processFi...ive, $_FILES['upload']) returns the type boolean which is incompatible with the documented return type null.
Loading history...
435
		}
436
	}
437
438
	/**
439
	 * Process upload files. The file must be an 
440
	 * uploaded file. Any duplicate
441
	 * file will be renamed. See Files::copyFile for details
442
	 * on renaming.
443
	 * @param string $relative the relative path where the file
444
	 * should be copied to.
445
	 * @param array $file the uploaded file from $_FILES
446
	 * @return boolean true if the file was processed successfully, 
447
	 * false otherwise
448
	 */
449
	function _processFiles($relative, $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...
450
	{
451
		
452
		if($file['error']!=0)
453
		{
454
			Return false;
455
		}
456
457
		if(!is_uploaded_file($file['tmp_name']))
458
		{
459
			Files::delFile($file['tmp_name']);
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

459
			Files::/** @scrutinizer ignore-call */ 
460
          delFile($file['tmp_name']);
Loading history...
460
			Return false;
461
		}
462
463
        $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions'];
464
        $max_size = $this->mode == 'image' ? $this->config['max_filesize_kb_image'] : $this->config['max_filesize_kb_link'];
465
		$afruext = strtolower(substr(strrchr($file['name'], "."), 1));
466
467
		if(!in_array($afruext, $valid_extensions))
468
		{
469
			Files::delFile($file['tmp_name']);
470
			Return 'Cannot upload $extension='.$afruext.'$ Files. Permission denied.';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'Cannot upload $e...es. Permission denied.' returns the type string which is incompatible with the documented return type boolean.
Loading history...
471
		}
472
473
		if($file['size']>($max_size*1024))
474
		{
475
			Files::delFile($file['tmp_name']);
476
			Return 'Unble to upload file. Maximum file size [$max_size='.$max_size.'$ KB] exceeded.';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'Unble to upload ...ize . '$ KB] exceeded.' returns the type string which is incompatible with the documented return type boolean.
Loading history...
477
		}
478
479
		if(!empty($this->config['max_foldersize_mb']) &&  (Files::dirSize($this->getImagesDir()))+$file['size']> ($this->config['max_foldersize_mb']*1048576))
0 ignored issues
show
Bug Best Practice introduced by
The method Files::dirSize() 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

479
		if(!empty($this->config['max_foldersize_mb']) &&  (Files::/** @scrutinizer ignore-call */ dirSize($this->getImagesDir()))+$file['size']> ($this->config['max_foldersize_mb']*1048576))
Loading history...
480
		{
481
			Files::delFile($file['tmp_name']);
482
			Return ("Cannot upload. Maximum folder size reached. Delete unwanted files and try again.");
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'Cannot upload. M...d files and try again.' returns the type string which is incompatible with the documented return type boolean.
Loading history...
483
		}
484
485
		//now copy the file
486
		$path = Files::makePath($this->getImagesDir(),$relative);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makePath() 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

486
		/** @scrutinizer ignore-call */ 
487
  $path = Files::makePath($this->getImagesDir(),$relative);
Loading history...
487
		$result = Files::copyFile($file['tmp_name'], $path, $file['name']);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::copyFile() 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

487
		/** @scrutinizer ignore-call */ 
488
  $result = Files::copyFile($file['tmp_name'], $path, $file['name']);
Loading history...
488
489
		//no copy error
490
		if(!is_int($result))
0 ignored issues
show
introduced by
The condition is_int($result) is always false.
Loading history...
491
		{
492
			Files::delFile($file['tmp_name']);
493
			Return 'File "$file='.$file['name'].'$" successfully uploaded.';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'File "$file=' . ...successfully uploaded.' returns the type string which is incompatible with the documented return type boolean.
Loading history...
494
		}
495
496
		//delete tmp files.
497
		Files::delFile($file['tmp_name']);
498
		Return false;
499
500
	}
501
502
503
	function getDiskInfo()
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...
504
	{
505
        if (empty($this->config['max_foldersize_mb']))
506
            return '';
507
            
508
		$tmpFreeSize=($this->config['max_foldersize_mb']*1048576)-Files::dirSize($this->getImagesDir());
0 ignored issues
show
Bug Best Practice introduced by
The method Files::dirSize() 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

508
		$tmpFreeSize=($this->config['max_foldersize_mb']*1048576)-Files::/** @scrutinizer ignore-call */ dirSize($this->getImagesDir());
Loading history...
509
510
		if(!is_numeric($tmpFreeSize) || $tmpFreeSize<0)	$tmpFreeSize=0;
0 ignored issues
show
introduced by
The condition is_numeric($tmpFreeSize) is always true.
Loading history...
511
        
512
		Return 'Total Size : $max_foldersize_mb='.$this->config['max_foldersize_mb'].'$ MB, Free Space: $free_space='.Files::formatSize($tmpFreeSize).'$';
0 ignored issues
show
Bug Best Practice introduced by
The method Files::formatSize() 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

512
		Return 'Total Size : $max_foldersize_mb='.$this->config['max_foldersize_mb'].'$ MB, Free Space: $free_space='.Files::/** @scrutinizer ignore-call */ formatSize($tmpFreeSize).'$';
Loading history...
513
	}
514
515
516
517
	/**
518
	 * Get the URL of the relative file.
519
	 * basically appends the relative file to the 
520
	 * base_url given in config.inc.php
521
	 * @param string $relative a file the relative to the base_dir
522
	 * @return string the URL of the relative file.
523
	 */
524
	function getFileURL($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...
525
	{
526
		Return Files::makeFile($this->getImagesURL(),$relative);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

526
		Return Files::/** @scrutinizer ignore-call */ makeFile($this->getImagesURL(),$relative);
Loading history...
527
	}
528
529
	/**
530
	 * Get the fullpath to a relative file.
531
	 * @param string $relative the relative file.
532
	 * @return string the full path, .ie. the base_dir + relative.
533
	 */
534
	function getFullPath($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...
535
	{
536
		Return Files::makeFile($this->getImagesDir(),$relative);;
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

536
		Return Files::/** @scrutinizer ignore-call */ makeFile($this->getImagesDir(),$relative);;
Loading history...
537
	}
538
539
	/**
540
	 * Get the default thumbnail.
541
	 * @return string default thumbnail, empty string if 
542
	 * the thumbnail doesn't exist.
543
	 */
544
	function getDefaultThumb() 
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...
545
	{
546
		if(is_file($this->config['default_thumbnail']))
547
			Return $this->config['default_thumbnail'];
548
		else 
549
			Return '';
550
	}
551
552
553
	/**
554
	 * Checks image size. If the image size is less than default size
555
	 * returns the original size else returns default size to display thumbnail
556
	*/
557
	function checkImageSize($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...
558
	{
559
		$fullpath = Files::makeFile($this->getImagesDir(),$relative);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

559
		/** @scrutinizer ignore-call */ 
560
  $fullpath = Files::makeFile($this->getImagesDir(),$relative);
Loading history...
560
561
		$afruext = strtolower(substr(strrchr($relative, "."), 1));
562
		
563
		if(!in_array($afruext,$this->config['thumbnail_extensions']))
564
		{
565
			$imgInfo=array(0,0);
566
			Return $imgInfo;
567
		}
568
		else
569
		{
570
			$imgInfo = @getImageSize($fullpath);
571
			//not an image
572
			if(!is_array($imgInfo))
573
			{
574
				$imgInfo=array(0,0);
575
				Return $imgInfo;
576
			}
577
			else
578
			{
579
				if($imgInfo[0] > $this->config['thumbnail_width'])
580
				$imgInfo[0] = $this->config['thumbnail_width'];
581
582
				if($imgInfo[1] > $this->config['thumbnail_height'])
583
				$imgInfo[1] = $this->config['thumbnail_height'];
584
585
				Return $imgInfo;
586
			}
587
		}
588
589
	}
590
591
592
	/**
593
	 * Get the thumbnail url to be displayed. 
594
	 * If the thumbnail exists, and it is up-to-date
595
	 * the thumbnail url will be returns. If the 
596
	 * file is not an image, a default image will be returned.
597
	 * If it is an image file, and no thumbnail exists or 
598
	 * the thumbnail is out-of-date (i.e. the thumbnail 
599
	 * modified time is less than the original file)
600
	 * then a thumbs.php?img=filename.jpg is returned.
601
	 * The thumbs.php url will generate a new thumbnail
602
	 * on the fly. If the image is less than the dimensions
603
	 * of the thumbnails, the image will be display instead.
604
	 * @param string $relative the relative image file.
605
	 * @return string the url of the thumbnail, be it
606
	 * actually thumbnail or a script to generate the
607
	 * thumbnail on the fly.
608
	 */
609
	function getThumbnail($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...
610
	{
611
		global $IMConfig;
612
		
613
		$fullpath = Files::makeFile($this->getImagesDir(),$relative);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

613
		/** @scrutinizer ignore-call */ 
614
  $fullpath = Files::makeFile($this->getImagesDir(),$relative);
Loading history...
614
615
		//not a file???
616
		if(!is_file($fullpath))
617
			Return $this->getDefaultThumb();
618
619
		$afruext = strtolower(substr(strrchr($relative, "."), 1));
620
		
621
		if(!in_array($afruext,$this->config['thumbnail_extensions']))
622
		{
623
			if(is_file('icons/'.$afruext.'.gif')) 
624
				Return('icons/'.$afruext.'.gif');
625
			else
626
				Return $this->getDefaultThumb();
627
		}
628
629
		$imgInfo = @getImageSize($fullpath);
630
631
		//not an image
632
		if(!is_array($imgInfo))
633
			Return $this->getDefaultThumb();
634
635
636
		//Returning original image as thumbnail without Image Library by Afru
637
		if(!$this->config['img_library']) Return $this->getFileURL($relative);
638
639
640
		//the original image is smaller than thumbnails,
641
		//so just return the url to the original image.
642
		if ($imgInfo[0] <= $this->config['thumbnail_width']
643
		 && $imgInfo[1] <= $this->config['thumbnail_height'])
644
			Return $this->getFileURL($relative);
645
646
		$thumbnail = $this->getThumbName($fullpath);
647
		
648
		//check for thumbnails, if exists and
649
		// it is up-to-date, return the thumbnail url
650
		if(is_file($thumbnail))
651
		{
652
			if(filemtime($thumbnail) >= filemtime($fullpath))
653
				Return $this->getThumbURL($relative);
654
		}
655
656
		//well, no thumbnail was found, so ask the thumbs.php
657
		//to generate the thumbnail on the fly.
658
		Return $IMConfig['backend_url'] . '__function=thumbs&img='.rawurlencode($relative)."&mode=$this->mode";
659
	}
660
661
	/**
662
	 * Delete and specified files.
663
	 * @return boolean true if delete, false otherwise
664
	 */
665
	function deleteFiles() 
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...
666
	{
667
		if(isset($_GET['delf']))
668
			return $this->_delFile(rawurldecode($_GET['delf']));
669
        return false;
670
	}
671
672
	/**
673
	 * Delete and specified directories.
674
	 * @return boolean true if delete, false otherwise
675
	 */
676
	function deleteDirs() 
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...
677
	{
678
		 if(isset($_GET['deld']))
679
			return $this->_delDir(rawurldecode($_GET['deld']));		
680
		 else
681
			 Return false;
682
	}
683
684
	/**
685
	 * Delete the relative file, and any thumbnails.
686
	 * @param string $relative the relative file.
687
	 * @return boolean true if deleted, false otherwise.
688
	 */
689
	function _delFile($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...
690
	{
691
		$fullpath = Files::makeFile($this->getImagesDir(),$relative);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

691
		/** @scrutinizer ignore-call */ 
692
  $fullpath = Files::makeFile($this->getImagesDir(),$relative);
Loading history...
692
	
693
		$afruext = strtolower(substr(strrchr($relative, "."), 1));
694
695
        $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions'];
696
697
		if(!in_array($afruext,$valid_extensions))
698
		{
699
			return false;
700
		}
701
702
		//check that the file is an image
703
		if(is_array($this->getImageInfo($fullpath)))
0 ignored issues
show
introduced by
The condition is_array($this->getImageInfo($fullpath)) is always true.
Loading history...
704
		{
705
			$thumbnail = $this->getThumbName($fullpath);
706
			Files::delFile($thumbnail);
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

706
			Files::/** @scrutinizer ignore-call */ 
707
          delFile($thumbnail);
Loading history...
707
		}
708
709
		Return Files::delFile($fullpath);
710
	}
711
712
	/**
713
	 * Delete directories recursively.
714
	 * @param string $relative the relative path to be deleted.
715
	 * @return boolean true if deleted, false otherwise.
716
	 */
717
	function _delDir($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...
718
	{
719
		$fullpath = Files::makePath($this->getImagesDir(),$relative);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makePath() 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

719
		/** @scrutinizer ignore-call */ 
720
  $fullpath = Files::makePath($this->getImagesDir(),$relative);
Loading history...
720
	//	if($this->countFiles($fullpath) <= 0)
721
			return Files::delFolder($fullpath,true); //delete recursively.
0 ignored issues
show
Bug Best Practice introduced by
The method Files::delFolder() 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

721
			return Files::/** @scrutinizer ignore-call */ delFolder($fullpath,true); //delete recursively.
Loading history...
722
		//else
723
			//Return false;
724
	}
725
726
	/**
727
	 * Create new directories.
728
	 * If in safe_mode, nothing happens.
729
	 * @return boolean true if created, false otherwise.
730
	 */
731
	function processNewDir() 
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...
732
	{
733
		if($this->config['safe_mode'] == true)
734
			Return false;
735
736
		if(isset($_GET['newDir']) && isset($_GET['dir']))
737
		{
738
			$newDir = rawurldecode($_GET['newDir']);
739
			$dir = rawurldecode($_GET['dir']);
740
			$path = Files::makePath($this->getImagesDir(),$dir);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makePath() 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

740
			/** @scrutinizer ignore-call */ 
741
   $path = Files::makePath($this->getImagesDir(),$dir);
Loading history...
741
			$fullpath = Files::makePath($path, Files::escape($newDir));
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

741
			$fullpath = Files::makePath($path, Files::/** @scrutinizer ignore-call */ escape($newDir));
Loading history...
742
			if(is_dir($fullpath))
743
				Return false;
744
745
			Return Files::createFolder($fullpath);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::createFolder() 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

745
			Return Files::/** @scrutinizer ignore-call */ createFolder($fullpath);
Loading history...
746
		}
747
	}
748
749
	/**
750
	 * Renames files if certain GET variables are set
751
	 * @return bool
752
	 */
753
	function processRenames()
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...
754
	{
755
		if(!empty($_GET['rename']) && !empty($_GET['renameTo']))
756
		{
757
			// new file name (without path and extension)
758
			$newName = Files::escape(rawurldecode($_GET['renameTo']));
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

758
			/** @scrutinizer ignore-call */ 
759
   $newName = Files::escape(rawurldecode($_GET['renameTo']));
Loading history...
759
			$newName = str_replace('.', '', $newName);
760
761
			// path to file (from base images directory)
762
			$oldName = rawurldecode($_GET['rename']);
763
764
			// strip parent dir ("..") to avoid escaping from base directiory
765
			$oldName = preg_replace('#\.\.#', '', $oldName);
766
767
			if (is_dir($oldPath = Files::makeFile($this->getImagesDir(), $_GET['dir'].$oldName)))
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

767
			if (is_dir($oldPath = Files::/** @scrutinizer ignore-call */ makeFile($this->getImagesDir(), $_GET['dir'].$oldName)))
Loading history...
768
			{
769
				$newPath = Files::makeFile($this->getImagesDir(), $_GET['dir'].$newName);
770
				return Files::rename($oldPath,$newPath);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::rename() 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

770
				return Files::/** @scrutinizer ignore-call */ rename($oldPath,$newPath);
Loading history...
Bug Best Practice introduced by
The expression return Files::rename($oldPath, $newPath) returns the type integer which is incompatible with the documented return type boolean.
Loading history...
771
			}
772
			else 
773
			{
774
				// path to old file
775
				$oldPath = Files::makeFile($this->getImagesDir(), $oldName);
776
	
777
				$ret = Files::renameFile($oldPath, $newName);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::renameFile() 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

777
				/** @scrutinizer ignore-call */ 
778
    $ret = Files::renameFile($oldPath, $newName);
Loading history...
778
				if ($ret === true) {
0 ignored issues
show
introduced by
The condition $ret === true is always false.
Loading history...
779
					// delete old thumbnail
780
					Files::delFile($this->getThumbname($oldPath));
781
				}
782
			}
783
			return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret also could return the type integer which is incompatible with the documented return type boolean.
Loading history...
784
		}
785
		
786
		return null;
787
	}
788
789
	function processPaste()
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...
790
	{
791
		switch ($_GET['paste'])
792
		{
793
			case 'copyFile':
794
				$src = Files::makeFile($this->getImagesDir(), $_GET['srcdir'].$_GET['file']);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::makeFile() 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

794
				/** @scrutinizer ignore-call */ 
795
    $src = Files::makeFile($this->getImagesDir(), $_GET['srcdir'].$_GET['file']);
Loading history...
795
				$file = $_GET['file'];
796
				$dest = Files::makeFile($this->getImagesDir(), $_GET['dir']);
797
				return Files::copyFile($src,$dest,$file);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::copyFile() 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

797
				return Files::/** @scrutinizer ignore-call */ copyFile($src,$dest,$file);
Loading history...
798
			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...
799
			case 'copyDir':
800
				$basePath = $this->getImagesDir();
801
				$src = $_GET['srcdir'].$_GET['file'];
802
				$dest = $_GET['dir'].$_GET['file'];
803
				return Files::copyDir($basePath,$src,$dest);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::copyDir() 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

803
				return Files::/** @scrutinizer ignore-call */ copyDir($basePath,$src,$dest);
Loading history...
804
			break;
805
			case 'moveFile':
806
				$src = Files::makeFile($this->getImagesDir(), $_GET['srcdir'].$_GET['file']);
807
				$dest = Files::makeFile($this->getImagesDir(), $_GET['dir'].$_GET['file']);
808
				return Files::rename($src,$dest);
0 ignored issues
show
Bug Best Practice introduced by
The method Files::rename() 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

808
				return Files::/** @scrutinizer ignore-call */ rename($src,$dest);
Loading history...
809
			break;
810
			case 'moveDir':
811
				$src = Files::makeFile($this->getImagesDir(), $_GET['srcdir'].$_GET['file']);
812
				$dest = Files::makeFile($this->getImagesDir(), $_GET['dir'].$_GET['file']);
813
				return Files::rename($src,$dest);
814
			break;
815
		}
816
	}
817
}
818
819
?>
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...
820