@@ -25,6 +25,9 @@ discard block |
||
25 | 25 | */ |
26 | 26 | class CKFinder_Connector_Utils_Misc |
27 | 27 | { |
28 | + /** |
|
29 | + * @param integer $number |
|
30 | + */ |
|
28 | 31 | function getErrorMessage($number, $arg = "") { |
29 | 32 | $langCode = 'en'; |
30 | 33 | if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) { |
@@ -113,7 +116,6 @@ discard block |
||
113 | 116 | * |
114 | 117 | * @static |
115 | 118 | * @access public |
116 | - * @param string $filename |
|
117 | 119 | * @return boolean |
118 | 120 | */ |
119 | 121 | function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels) |
@@ -25,345 +25,345 @@ |
||
25 | 25 | */ |
26 | 26 | class CKFinder_Connector_Utils_Misc |
27 | 27 | { |
28 | - function getErrorMessage($number, $arg = "") { |
|
29 | - $langCode = 'en'; |
|
30 | - if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) { |
|
31 | - if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php")) |
|
32 | - $langCode = $_GET['langCode']; |
|
33 | - } |
|
34 | - include CKFINDER_CONNECTOR_LANG_PATH . "/" . $langCode . ".php"; |
|
35 | - if ($number) { |
|
36 | - if (!empty ($GLOBALS['CKFLang']['Errors'][$number])) { |
|
37 | - $errorMessage = str_replace("%1", $arg, $GLOBALS['CKFLang']['Errors'][$number]); |
|
38 | - } else { |
|
39 | - $errorMessage = str_replace("%1", $number, $GLOBALS['CKFLang']['ErrorUnknown']); |
|
40 | - } |
|
41 | - } else { |
|
42 | - $errorMessage = ""; |
|
43 | - } |
|
44 | - return $errorMessage; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Convert any value to boolean, strings like "false", "FalSE" and "off" are also considered as false |
|
49 | - * |
|
50 | - * @static |
|
51 | - * @access public |
|
52 | - * @param mixed $value |
|
53 | - * @return boolean |
|
54 | - */ |
|
55 | - function booleanValue($value) |
|
56 | - { |
|
57 | - if (strcasecmp("false", $value) == 0 || strcasecmp("off", $value) == 0 || !$value) { |
|
58 | - return false; |
|
59 | - } else { |
|
60 | - return true; |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @link http://pl.php.net/manual/en/function.imagecopyresampled.php |
|
66 | - * replacement to imagecopyresampled that will deliver results that are almost identical except MUCH faster (very typically 30 times faster) |
|
67 | - * |
|
68 | - * @static |
|
69 | - * @access public |
|
70 | - * @param string $dst_image |
|
71 | - * @param string $src_image |
|
72 | - * @param int $dst_x |
|
73 | - * @param int $dst_y |
|
74 | - * @param int $src_x |
|
75 | - * @param int $src_y |
|
76 | - * @param int $dst_w |
|
77 | - * @param int $dst_h |
|
78 | - * @param int $src_w |
|
79 | - * @param int $src_h |
|
80 | - * @param int $quality |
|
81 | - * @return boolean |
|
82 | - */ |
|
83 | - function fastImageCopyResampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) |
|
84 | - { |
|
85 | - if (empty($src_image) || empty($dst_image)) { |
|
86 | - return false; |
|
87 | - } |
|
88 | - |
|
89 | - if ($quality <= 1) { |
|
90 | - $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1); |
|
91 | - imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h); |
|
92 | - imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h); |
|
93 | - imagedestroy ($temp); |
|
94 | - |
|
95 | - } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) { |
|
96 | - $tmp_w = $dst_w * $quality; |
|
97 | - $tmp_h = $dst_h * $quality; |
|
98 | - $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1); |
|
99 | - imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h); |
|
100 | - imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h); |
|
101 | - imagedestroy ($temp); |
|
102 | - |
|
103 | - } else { |
|
104 | - imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
105 | - } |
|
106 | - |
|
107 | - return true; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @link http://pl.php.net/manual/pl/function.imagecreatefromjpeg.php |
|
112 | - * function posted by e dot a dot schultz at gmail dot com |
|
113 | - * |
|
114 | - * @static |
|
115 | - * @access public |
|
116 | - * @param string $filename |
|
117 | - * @return boolean |
|
118 | - */ |
|
119 | - function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels) |
|
120 | - { |
|
121 | - $MB = 1048576; // number of bytes in 1M |
|
122 | - $K64 = 65536; // number of bytes in 64K |
|
123 | - $TWEAKFACTOR = 2.4; // Or whatever works for you |
|
124 | - $memoryNeeded = round( ( $imageWidth * $imageHeight |
|
125 | - * $imageBits |
|
126 | - * $imageChannels / 8 |
|
127 | - + $K64 |
|
128 | - ) * $TWEAKFACTOR |
|
129 | - ) + 3*$MB; |
|
130 | - |
|
131 | - //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also |
|
132 | - //Default memory limit is 8MB so well stick with that. |
|
133 | - //To find out what yours is, view your php.ini file. |
|
134 | - $memoryLimit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'))/$MB; |
|
135 | - if (!$memoryLimit) { |
|
136 | - $memoryLimit = 8; |
|
137 | - } |
|
138 | - |
|
139 | - $memoryLimitMB = $memoryLimit * $MB; |
|
140 | - if (function_exists('memory_get_usage')) { |
|
141 | - if (memory_get_usage() + $memoryNeeded > $memoryLimitMB) { |
|
142 | - $newLimit = $memoryLimit + ceil( ( memory_get_usage() |
|
143 | - + $memoryNeeded |
|
144 | - - $memoryLimitMB |
|
145 | - ) / $MB |
|
146 | - ); |
|
147 | - if (@ini_set( 'memory_limit', $newLimit . 'M' ) === false) { |
|
148 | - return false; |
|
149 | - } |
|
150 | - } |
|
151 | - } else { |
|
152 | - if ($memoryNeeded + 3*$MB > $memoryLimitMB) { |
|
153 | - $newLimit = $memoryLimit + ceil(( 3*$MB |
|
154 | - + $memoryNeeded |
|
155 | - - $memoryLimitMB |
|
156 | - ) / $MB |
|
157 | - ); |
|
158 | - if (false === @ini_set( 'memory_limit', $newLimit . 'M' )) { |
|
159 | - return false; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - return true; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * convert shorthand php.ini notation into bytes, much like how the PHP source does it |
|
168 | - * @link http://pl.php.net/manual/en/function.ini-get.php |
|
169 | - * |
|
170 | - * @static |
|
171 | - * @access public |
|
172 | - * @param string $val |
|
173 | - * @return int |
|
174 | - */ |
|
175 | - function returnBytes($val) |
|
176 | - { |
|
177 | - $val = trim($val); |
|
178 | - if (!$val) { |
|
179 | - return 0; |
|
180 | - } |
|
181 | - $last = strtolower($val[strlen($val)-1]); |
|
182 | - switch($last) { |
|
183 | - // The 'G' modifier is available since PHP 5.1.0 |
|
184 | - case 'g': |
|
185 | - $val *= 1024; |
|
186 | - case 'm': |
|
187 | - $val *= 1024; |
|
188 | - case 'k': |
|
189 | - $val *= 1024; |
|
190 | - } |
|
191 | - |
|
192 | - return $val; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Checks if a value exists in an array (case insensitive) |
|
197 | - * |
|
198 | - * @static |
|
199 | - * @access public |
|
200 | - * @param string $needle |
|
201 | - * @param array $haystack |
|
202 | - * @return boolean |
|
203 | - */ |
|
204 | - function inArrayCaseInsensitive($needle, $haystack) |
|
205 | - { |
|
206 | - if (!$haystack || !is_array($haystack)) { |
|
207 | - return false; |
|
208 | - } |
|
209 | - $lcase = array(); |
|
210 | - foreach ($haystack as $key => $val) { |
|
211 | - $lcase[$key] = strtolower($val); |
|
212 | - } |
|
213 | - return in_array($needle, $lcase); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * UTF-8 compatible version of basename() |
|
218 | - * |
|
219 | - * @static |
|
220 | - * @access public |
|
221 | - * @param string $file |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - function mbBasename($file) |
|
225 | - { |
|
226 | - $explode = explode('/', str_replace("\\", "/", $file)); |
|
227 | - return end($explode); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Source: http://pl.php.net/imagecreate |
|
232 | - * (optimized for speed and memory usage, but yet not very efficient) |
|
233 | - * |
|
234 | - * @static |
|
235 | - * @access public |
|
236 | - * @param string $filename |
|
237 | - * @return resource |
|
238 | - */ |
|
239 | - function imageCreateFromBmp($filename) |
|
240 | - { |
|
241 | - //20 seconds seems to be a reasonable value to not kill a server and process images up to 1680x1050 |
|
242 | - @set_time_limit(20); |
|
243 | - |
|
244 | - if (false === ($f1 = fopen($filename, "rb"))) { |
|
245 | - return false; |
|
246 | - } |
|
247 | - |
|
248 | - $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14)); |
|
249 | - if ($FILE['file_type'] != 19778) { |
|
250 | - return false; |
|
251 | - } |
|
252 | - |
|
253 | - $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'. |
|
254 | - '/Vcompression/Vsize_bitmap/Vhoriz_resolution'. |
|
255 | - '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40)); |
|
256 | - |
|
257 | - $BMP['colors'] = pow(2,$BMP['bits_per_pixel']); |
|
258 | - |
|
259 | - if ($BMP['size_bitmap'] == 0) { |
|
260 | - $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset']; |
|
261 | - } |
|
262 | - |
|
263 | - $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8; |
|
264 | - $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']); |
|
265 | - $BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4); |
|
266 | - $BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4); |
|
267 | - $BMP['decal'] = 4-(4*$BMP['decal']); |
|
268 | - |
|
269 | - if ($BMP['decal'] == 4) { |
|
270 | - $BMP['decal'] = 0; |
|
271 | - } |
|
272 | - |
|
273 | - $PALETTE = array(); |
|
274 | - if ($BMP['colors'] < 16777216) { |
|
275 | - $PALETTE = unpack('V'.$BMP['colors'], fread($f1, $BMP['colors']*4)); |
|
276 | - } |
|
277 | - |
|
278 | - //2048x1536px@24bit don't even try to process larger files as it will probably fail |
|
279 | - if ($BMP['size_bitmap'] > 3 * 2048 * 1536) { |
|
280 | - return false; |
|
281 | - } |
|
282 | - |
|
283 | - $IMG = fread($f1, $BMP['size_bitmap']); |
|
284 | - fclose($f1); |
|
285 | - $VIDE = chr(0); |
|
286 | - |
|
287 | - $res = imagecreatetruecolor($BMP['width'],$BMP['height']); |
|
288 | - $P = 0; |
|
289 | - $Y = $BMP['height']-1; |
|
290 | - |
|
291 | - $line_length = $BMP['bytes_per_pixel']*$BMP['width']; |
|
292 | - |
|
293 | - if ($BMP['bits_per_pixel'] == 24) { |
|
294 | - while ($Y >= 0) |
|
295 | - { |
|
296 | - $X=0; |
|
297 | - $temp = unpack( "C*", substr($IMG, $P, $line_length)); |
|
298 | - |
|
299 | - while ($X < $BMP['width']) |
|
300 | - { |
|
301 | - $offset = $X*3; |
|
302 | - imagesetpixel($res, $X++, $Y, ($temp[$offset+3] << 16) + ($temp[$offset+2] << 8) + $temp[$offset+1]); |
|
303 | - } |
|
304 | - $Y--; |
|
305 | - $P += $line_length + $BMP['decal']; |
|
306 | - } |
|
307 | - } |
|
308 | - elseif ($BMP['bits_per_pixel'] == 8) |
|
309 | - { |
|
310 | - while ($Y >= 0) |
|
311 | - { |
|
312 | - $X=0; |
|
313 | - |
|
314 | - $temp = unpack( "C*", substr($IMG, $P, $line_length)); |
|
315 | - |
|
316 | - while ($X < $BMP['width']) |
|
317 | - { |
|
318 | - imagesetpixel($res, $X++, $Y, $PALETTE[$temp[$X] +1]); |
|
319 | - } |
|
320 | - $Y--; |
|
321 | - $P += $line_length + $BMP['decal']; |
|
322 | - } |
|
323 | - } |
|
324 | - elseif ($BMP['bits_per_pixel'] == 4) |
|
325 | - { |
|
326 | - while ($Y >= 0) |
|
327 | - { |
|
328 | - $X=0; |
|
329 | - $i = 1; |
|
330 | - $low = true; |
|
331 | - |
|
332 | - $temp = unpack( "C*", substr($IMG, $P, $line_length)); |
|
333 | - |
|
334 | - while ($X < $BMP['width']) |
|
335 | - { |
|
336 | - if ($low) { |
|
337 | - $index = $temp[$i] >> 4; |
|
338 | - } |
|
339 | - else { |
|
340 | - $index = $temp[$i++] & 0x0F; |
|
341 | - } |
|
342 | - $low = !$low; |
|
343 | - |
|
344 | - imagesetpixel($res, $X++, $Y, $PALETTE[$index +1]); |
|
345 | - } |
|
346 | - $Y--; |
|
347 | - $P += $line_length + $BMP['decal']; |
|
348 | - } |
|
349 | - } |
|
350 | - elseif ($BMP['bits_per_pixel'] == 1) |
|
351 | - { |
|
352 | - $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1)); |
|
353 | - if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7; |
|
354 | - elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6; |
|
355 | - elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5; |
|
356 | - elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4; |
|
357 | - elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3; |
|
358 | - elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2; |
|
359 | - elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1; |
|
360 | - elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1); |
|
361 | - $COLOR[1] = $PALETTE[$COLOR[1]+1]; |
|
362 | - } |
|
363 | - else { |
|
364 | - return false; |
|
365 | - } |
|
366 | - |
|
367 | - return $res; |
|
368 | - } |
|
28 | + function getErrorMessage($number, $arg = "") { |
|
29 | + $langCode = 'en'; |
|
30 | + if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) { |
|
31 | + if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php")) |
|
32 | + $langCode = $_GET['langCode']; |
|
33 | + } |
|
34 | + include CKFINDER_CONNECTOR_LANG_PATH . "/" . $langCode . ".php"; |
|
35 | + if ($number) { |
|
36 | + if (!empty ($GLOBALS['CKFLang']['Errors'][$number])) { |
|
37 | + $errorMessage = str_replace("%1", $arg, $GLOBALS['CKFLang']['Errors'][$number]); |
|
38 | + } else { |
|
39 | + $errorMessage = str_replace("%1", $number, $GLOBALS['CKFLang']['ErrorUnknown']); |
|
40 | + } |
|
41 | + } else { |
|
42 | + $errorMessage = ""; |
|
43 | + } |
|
44 | + return $errorMessage; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Convert any value to boolean, strings like "false", "FalSE" and "off" are also considered as false |
|
49 | + * |
|
50 | + * @static |
|
51 | + * @access public |
|
52 | + * @param mixed $value |
|
53 | + * @return boolean |
|
54 | + */ |
|
55 | + function booleanValue($value) |
|
56 | + { |
|
57 | + if (strcasecmp("false", $value) == 0 || strcasecmp("off", $value) == 0 || !$value) { |
|
58 | + return false; |
|
59 | + } else { |
|
60 | + return true; |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @link http://pl.php.net/manual/en/function.imagecopyresampled.php |
|
66 | + * replacement to imagecopyresampled that will deliver results that are almost identical except MUCH faster (very typically 30 times faster) |
|
67 | + * |
|
68 | + * @static |
|
69 | + * @access public |
|
70 | + * @param string $dst_image |
|
71 | + * @param string $src_image |
|
72 | + * @param int $dst_x |
|
73 | + * @param int $dst_y |
|
74 | + * @param int $src_x |
|
75 | + * @param int $src_y |
|
76 | + * @param int $dst_w |
|
77 | + * @param int $dst_h |
|
78 | + * @param int $src_w |
|
79 | + * @param int $src_h |
|
80 | + * @param int $quality |
|
81 | + * @return boolean |
|
82 | + */ |
|
83 | + function fastImageCopyResampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) |
|
84 | + { |
|
85 | + if (empty($src_image) || empty($dst_image)) { |
|
86 | + return false; |
|
87 | + } |
|
88 | + |
|
89 | + if ($quality <= 1) { |
|
90 | + $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1); |
|
91 | + imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h); |
|
92 | + imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h); |
|
93 | + imagedestroy ($temp); |
|
94 | + |
|
95 | + } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) { |
|
96 | + $tmp_w = $dst_w * $quality; |
|
97 | + $tmp_h = $dst_h * $quality; |
|
98 | + $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1); |
|
99 | + imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h); |
|
100 | + imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h); |
|
101 | + imagedestroy ($temp); |
|
102 | + |
|
103 | + } else { |
|
104 | + imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
105 | + } |
|
106 | + |
|
107 | + return true; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @link http://pl.php.net/manual/pl/function.imagecreatefromjpeg.php |
|
112 | + * function posted by e dot a dot schultz at gmail dot com |
|
113 | + * |
|
114 | + * @static |
|
115 | + * @access public |
|
116 | + * @param string $filename |
|
117 | + * @return boolean |
|
118 | + */ |
|
119 | + function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels) |
|
120 | + { |
|
121 | + $MB = 1048576; // number of bytes in 1M |
|
122 | + $K64 = 65536; // number of bytes in 64K |
|
123 | + $TWEAKFACTOR = 2.4; // Or whatever works for you |
|
124 | + $memoryNeeded = round( ( $imageWidth * $imageHeight |
|
125 | + * $imageBits |
|
126 | + * $imageChannels / 8 |
|
127 | + + $K64 |
|
128 | + ) * $TWEAKFACTOR |
|
129 | + ) + 3*$MB; |
|
130 | + |
|
131 | + //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also |
|
132 | + //Default memory limit is 8MB so well stick with that. |
|
133 | + //To find out what yours is, view your php.ini file. |
|
134 | + $memoryLimit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'))/$MB; |
|
135 | + if (!$memoryLimit) { |
|
136 | + $memoryLimit = 8; |
|
137 | + } |
|
138 | + |
|
139 | + $memoryLimitMB = $memoryLimit * $MB; |
|
140 | + if (function_exists('memory_get_usage')) { |
|
141 | + if (memory_get_usage() + $memoryNeeded > $memoryLimitMB) { |
|
142 | + $newLimit = $memoryLimit + ceil( ( memory_get_usage() |
|
143 | + + $memoryNeeded |
|
144 | + - $memoryLimitMB |
|
145 | + ) / $MB |
|
146 | + ); |
|
147 | + if (@ini_set( 'memory_limit', $newLimit . 'M' ) === false) { |
|
148 | + return false; |
|
149 | + } |
|
150 | + } |
|
151 | + } else { |
|
152 | + if ($memoryNeeded + 3*$MB > $memoryLimitMB) { |
|
153 | + $newLimit = $memoryLimit + ceil(( 3*$MB |
|
154 | + + $memoryNeeded |
|
155 | + - $memoryLimitMB |
|
156 | + ) / $MB |
|
157 | + ); |
|
158 | + if (false === @ini_set( 'memory_limit', $newLimit . 'M' )) { |
|
159 | + return false; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + return true; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * convert shorthand php.ini notation into bytes, much like how the PHP source does it |
|
168 | + * @link http://pl.php.net/manual/en/function.ini-get.php |
|
169 | + * |
|
170 | + * @static |
|
171 | + * @access public |
|
172 | + * @param string $val |
|
173 | + * @return int |
|
174 | + */ |
|
175 | + function returnBytes($val) |
|
176 | + { |
|
177 | + $val = trim($val); |
|
178 | + if (!$val) { |
|
179 | + return 0; |
|
180 | + } |
|
181 | + $last = strtolower($val[strlen($val)-1]); |
|
182 | + switch($last) { |
|
183 | + // The 'G' modifier is available since PHP 5.1.0 |
|
184 | + case 'g': |
|
185 | + $val *= 1024; |
|
186 | + case 'm': |
|
187 | + $val *= 1024; |
|
188 | + case 'k': |
|
189 | + $val *= 1024; |
|
190 | + } |
|
191 | + |
|
192 | + return $val; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Checks if a value exists in an array (case insensitive) |
|
197 | + * |
|
198 | + * @static |
|
199 | + * @access public |
|
200 | + * @param string $needle |
|
201 | + * @param array $haystack |
|
202 | + * @return boolean |
|
203 | + */ |
|
204 | + function inArrayCaseInsensitive($needle, $haystack) |
|
205 | + { |
|
206 | + if (!$haystack || !is_array($haystack)) { |
|
207 | + return false; |
|
208 | + } |
|
209 | + $lcase = array(); |
|
210 | + foreach ($haystack as $key => $val) { |
|
211 | + $lcase[$key] = strtolower($val); |
|
212 | + } |
|
213 | + return in_array($needle, $lcase); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * UTF-8 compatible version of basename() |
|
218 | + * |
|
219 | + * @static |
|
220 | + * @access public |
|
221 | + * @param string $file |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + function mbBasename($file) |
|
225 | + { |
|
226 | + $explode = explode('/', str_replace("\\", "/", $file)); |
|
227 | + return end($explode); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Source: http://pl.php.net/imagecreate |
|
232 | + * (optimized for speed and memory usage, but yet not very efficient) |
|
233 | + * |
|
234 | + * @static |
|
235 | + * @access public |
|
236 | + * @param string $filename |
|
237 | + * @return resource |
|
238 | + */ |
|
239 | + function imageCreateFromBmp($filename) |
|
240 | + { |
|
241 | + //20 seconds seems to be a reasonable value to not kill a server and process images up to 1680x1050 |
|
242 | + @set_time_limit(20); |
|
243 | + |
|
244 | + if (false === ($f1 = fopen($filename, "rb"))) { |
|
245 | + return false; |
|
246 | + } |
|
247 | + |
|
248 | + $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14)); |
|
249 | + if ($FILE['file_type'] != 19778) { |
|
250 | + return false; |
|
251 | + } |
|
252 | + |
|
253 | + $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'. |
|
254 | + '/Vcompression/Vsize_bitmap/Vhoriz_resolution'. |
|
255 | + '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40)); |
|
256 | + |
|
257 | + $BMP['colors'] = pow(2,$BMP['bits_per_pixel']); |
|
258 | + |
|
259 | + if ($BMP['size_bitmap'] == 0) { |
|
260 | + $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset']; |
|
261 | + } |
|
262 | + |
|
263 | + $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8; |
|
264 | + $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']); |
|
265 | + $BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4); |
|
266 | + $BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4); |
|
267 | + $BMP['decal'] = 4-(4*$BMP['decal']); |
|
268 | + |
|
269 | + if ($BMP['decal'] == 4) { |
|
270 | + $BMP['decal'] = 0; |
|
271 | + } |
|
272 | + |
|
273 | + $PALETTE = array(); |
|
274 | + if ($BMP['colors'] < 16777216) { |
|
275 | + $PALETTE = unpack('V'.$BMP['colors'], fread($f1, $BMP['colors']*4)); |
|
276 | + } |
|
277 | + |
|
278 | + //2048x1536px@24bit don't even try to process larger files as it will probably fail |
|
279 | + if ($BMP['size_bitmap'] > 3 * 2048 * 1536) { |
|
280 | + return false; |
|
281 | + } |
|
282 | + |
|
283 | + $IMG = fread($f1, $BMP['size_bitmap']); |
|
284 | + fclose($f1); |
|
285 | + $VIDE = chr(0); |
|
286 | + |
|
287 | + $res = imagecreatetruecolor($BMP['width'],$BMP['height']); |
|
288 | + $P = 0; |
|
289 | + $Y = $BMP['height']-1; |
|
290 | + |
|
291 | + $line_length = $BMP['bytes_per_pixel']*$BMP['width']; |
|
292 | + |
|
293 | + if ($BMP['bits_per_pixel'] == 24) { |
|
294 | + while ($Y >= 0) |
|
295 | + { |
|
296 | + $X=0; |
|
297 | + $temp = unpack( "C*", substr($IMG, $P, $line_length)); |
|
298 | + |
|
299 | + while ($X < $BMP['width']) |
|
300 | + { |
|
301 | + $offset = $X*3; |
|
302 | + imagesetpixel($res, $X++, $Y, ($temp[$offset+3] << 16) + ($temp[$offset+2] << 8) + $temp[$offset+1]); |
|
303 | + } |
|
304 | + $Y--; |
|
305 | + $P += $line_length + $BMP['decal']; |
|
306 | + } |
|
307 | + } |
|
308 | + elseif ($BMP['bits_per_pixel'] == 8) |
|
309 | + { |
|
310 | + while ($Y >= 0) |
|
311 | + { |
|
312 | + $X=0; |
|
313 | + |
|
314 | + $temp = unpack( "C*", substr($IMG, $P, $line_length)); |
|
315 | + |
|
316 | + while ($X < $BMP['width']) |
|
317 | + { |
|
318 | + imagesetpixel($res, $X++, $Y, $PALETTE[$temp[$X] +1]); |
|
319 | + } |
|
320 | + $Y--; |
|
321 | + $P += $line_length + $BMP['decal']; |
|
322 | + } |
|
323 | + } |
|
324 | + elseif ($BMP['bits_per_pixel'] == 4) |
|
325 | + { |
|
326 | + while ($Y >= 0) |
|
327 | + { |
|
328 | + $X=0; |
|
329 | + $i = 1; |
|
330 | + $low = true; |
|
331 | + |
|
332 | + $temp = unpack( "C*", substr($IMG, $P, $line_length)); |
|
333 | + |
|
334 | + while ($X < $BMP['width']) |
|
335 | + { |
|
336 | + if ($low) { |
|
337 | + $index = $temp[$i] >> 4; |
|
338 | + } |
|
339 | + else { |
|
340 | + $index = $temp[$i++] & 0x0F; |
|
341 | + } |
|
342 | + $low = !$low; |
|
343 | + |
|
344 | + imagesetpixel($res, $X++, $Y, $PALETTE[$index +1]); |
|
345 | + } |
|
346 | + $Y--; |
|
347 | + $P += $line_length + $BMP['decal']; |
|
348 | + } |
|
349 | + } |
|
350 | + elseif ($BMP['bits_per_pixel'] == 1) |
|
351 | + { |
|
352 | + $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1)); |
|
353 | + if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7; |
|
354 | + elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6; |
|
355 | + elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5; |
|
356 | + elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4; |
|
357 | + elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3; |
|
358 | + elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2; |
|
359 | + elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1; |
|
360 | + elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1); |
|
361 | + $COLOR[1] = $PALETTE[$COLOR[1]+1]; |
|
362 | + } |
|
363 | + else { |
|
364 | + return false; |
|
365 | + } |
|
366 | + |
|
367 | + return $res; |
|
368 | + } |
|
369 | 369 | } |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | function getErrorMessage($number, $arg = "") { |
29 | 29 | $langCode = 'en'; |
30 | 30 | if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) { |
31 | - if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php")) |
|
31 | + if (file_exists(CKFINDER_CONNECTOR_LANG_PATH."/".$_GET['langCode'].".php")) |
|
32 | 32 | $langCode = $_GET['langCode']; |
33 | 33 | } |
34 | - include CKFINDER_CONNECTOR_LANG_PATH . "/" . $langCode . ".php"; |
|
34 | + include CKFINDER_CONNECTOR_LANG_PATH."/".$langCode.".php"; |
|
35 | 35 | if ($number) { |
36 | 36 | if (!empty ($GLOBALS['CKFLang']['Errors'][$number])) { |
37 | 37 | $errorMessage = str_replace("%1", $arg, $GLOBALS['CKFLang']['Errors'][$number]); |
@@ -80,28 +80,28 @@ discard block |
||
80 | 80 | * @param int $quality |
81 | 81 | * @return boolean |
82 | 82 | */ |
83 | - function fastImageCopyResampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) |
|
83 | + function fastImageCopyResampled(&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) |
|
84 | 84 | { |
85 | 85 | if (empty($src_image) || empty($dst_image)) { |
86 | 86 | return false; |
87 | 87 | } |
88 | 88 | |
89 | 89 | if ($quality <= 1) { |
90 | - $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1); |
|
91 | - imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h); |
|
92 | - imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h); |
|
93 | - imagedestroy ($temp); |
|
90 | + $temp = imagecreatetruecolor($dst_w + 1, $dst_h + 1); |
|
91 | + imagecopyresized($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h); |
|
92 | + imagecopyresized($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h); |
|
93 | + imagedestroy($temp); |
|
94 | 94 | |
95 | 95 | } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) { |
96 | 96 | $tmp_w = $dst_w * $quality; |
97 | 97 | $tmp_h = $dst_h * $quality; |
98 | - $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1); |
|
99 | - imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h); |
|
100 | - imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h); |
|
101 | - imagedestroy ($temp); |
|
98 | + $temp = imagecreatetruecolor($tmp_w + 1, $tmp_h + 1); |
|
99 | + imagecopyresized($temp, $src_image, 0, 0, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h); |
|
100 | + imagecopyresampled($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h); |
|
101 | + imagedestroy($temp); |
|
102 | 102 | |
103 | 103 | } else { |
104 | - imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
104 | + imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | return true; |
@@ -118,20 +118,20 @@ discard block |
||
118 | 118 | */ |
119 | 119 | function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels) |
120 | 120 | { |
121 | - $MB = 1048576; // number of bytes in 1M |
|
122 | - $K64 = 65536; // number of bytes in 64K |
|
123 | - $TWEAKFACTOR = 2.4; // Or whatever works for you |
|
124 | - $memoryNeeded = round( ( $imageWidth * $imageHeight |
|
121 | + $MB = 1048576; // number of bytes in 1M |
|
122 | + $K64 = 65536; // number of bytes in 64K |
|
123 | + $TWEAKFACTOR = 2.4; // Or whatever works for you |
|
124 | + $memoryNeeded = round(($imageWidth * $imageHeight |
|
125 | 125 | * $imageBits |
126 | 126 | * $imageChannels / 8 |
127 | 127 | + $K64 |
128 | 128 | ) * $TWEAKFACTOR |
129 | - ) + 3*$MB; |
|
129 | + ) + 3 * $MB; |
|
130 | 130 | |
131 | 131 | //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also |
132 | 132 | //Default memory limit is 8MB so well stick with that. |
133 | 133 | //To find out what yours is, view your php.ini file. |
134 | - $memoryLimit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'))/$MB; |
|
134 | + $memoryLimit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit')) / $MB; |
|
135 | 135 | if (!$memoryLimit) { |
136 | 136 | $memoryLimit = 8; |
137 | 137 | } |
@@ -139,23 +139,23 @@ discard block |
||
139 | 139 | $memoryLimitMB = $memoryLimit * $MB; |
140 | 140 | if (function_exists('memory_get_usage')) { |
141 | 141 | if (memory_get_usage() + $memoryNeeded > $memoryLimitMB) { |
142 | - $newLimit = $memoryLimit + ceil( ( memory_get_usage() |
|
142 | + $newLimit = $memoryLimit + ceil((memory_get_usage() |
|
143 | 143 | + $memoryNeeded |
144 | 144 | - $memoryLimitMB |
145 | 145 | ) / $MB |
146 | 146 | ); |
147 | - if (@ini_set( 'memory_limit', $newLimit . 'M' ) === false) { |
|
147 | + if (@ini_set('memory_limit', $newLimit.'M') === false) { |
|
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | } |
151 | 151 | } else { |
152 | - if ($memoryNeeded + 3*$MB > $memoryLimitMB) { |
|
153 | - $newLimit = $memoryLimit + ceil(( 3*$MB |
|
152 | + if ($memoryNeeded + 3 * $MB > $memoryLimitMB) { |
|
153 | + $newLimit = $memoryLimit + ceil((3 * $MB |
|
154 | 154 | + $memoryNeeded |
155 | 155 | - $memoryLimitMB |
156 | 156 | ) / $MB |
157 | 157 | ); |
158 | - if (false === @ini_set( 'memory_limit', $newLimit . 'M' )) { |
|
158 | + if (false === @ini_set('memory_limit', $newLimit.'M')) { |
|
159 | 159 | return false; |
160 | 160 | } |
161 | 161 | } |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | if (!$val) { |
179 | 179 | return 0; |
180 | 180 | } |
181 | - $last = strtolower($val[strlen($val)-1]); |
|
182 | - switch($last) { |
|
181 | + $last = strtolower($val[strlen($val) - 1]); |
|
182 | + switch ($last) { |
|
183 | 183 | // The 'G' modifier is available since PHP 5.1.0 |
184 | 184 | case 'g': |
185 | 185 | $val *= 1024; |
@@ -254,17 +254,17 @@ discard block |
||
254 | 254 | '/Vcompression/Vsize_bitmap/Vhoriz_resolution'. |
255 | 255 | '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40)); |
256 | 256 | |
257 | - $BMP['colors'] = pow(2,$BMP['bits_per_pixel']); |
|
257 | + $BMP['colors'] = pow(2, $BMP['bits_per_pixel']); |
|
258 | 258 | |
259 | 259 | if ($BMP['size_bitmap'] == 0) { |
260 | 260 | $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset']; |
261 | 261 | } |
262 | 262 | |
263 | - $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8; |
|
263 | + $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8; |
|
264 | 264 | $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']); |
265 | - $BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4); |
|
266 | - $BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4); |
|
267 | - $BMP['decal'] = 4-(4*$BMP['decal']); |
|
265 | + $BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4); |
|
266 | + $BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4); |
|
267 | + $BMP['decal'] = 4 - (4 * $BMP['decal']); |
|
268 | 268 | |
269 | 269 | if ($BMP['decal'] == 4) { |
270 | 270 | $BMP['decal'] = 0; |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | |
273 | 273 | $PALETTE = array(); |
274 | 274 | if ($BMP['colors'] < 16777216) { |
275 | - $PALETTE = unpack('V'.$BMP['colors'], fread($f1, $BMP['colors']*4)); |
|
275 | + $PALETTE = unpack('V'.$BMP['colors'], fread($f1, $BMP['colors'] * 4)); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | //2048x1536px@24bit don't even try to process larger files as it will probably fail |
@@ -284,22 +284,22 @@ discard block |
||
284 | 284 | fclose($f1); |
285 | 285 | $VIDE = chr(0); |
286 | 286 | |
287 | - $res = imagecreatetruecolor($BMP['width'],$BMP['height']); |
|
287 | + $res = imagecreatetruecolor($BMP['width'], $BMP['height']); |
|
288 | 288 | $P = 0; |
289 | - $Y = $BMP['height']-1; |
|
289 | + $Y = $BMP['height'] - 1; |
|
290 | 290 | |
291 | - $line_length = $BMP['bytes_per_pixel']*$BMP['width']; |
|
291 | + $line_length = $BMP['bytes_per_pixel'] * $BMP['width']; |
|
292 | 292 | |
293 | 293 | if ($BMP['bits_per_pixel'] == 24) { |
294 | 294 | while ($Y >= 0) |
295 | 295 | { |
296 | - $X=0; |
|
297 | - $temp = unpack( "C*", substr($IMG, $P, $line_length)); |
|
296 | + $X = 0; |
|
297 | + $temp = unpack("C*", substr($IMG, $P, $line_length)); |
|
298 | 298 | |
299 | 299 | while ($X < $BMP['width']) |
300 | 300 | { |
301 | - $offset = $X*3; |
|
302 | - imagesetpixel($res, $X++, $Y, ($temp[$offset+3] << 16) + ($temp[$offset+2] << 8) + $temp[$offset+1]); |
|
301 | + $offset = $X * 3; |
|
302 | + imagesetpixel($res, $X++, $Y, ($temp[$offset + 3] << 16) + ($temp[$offset + 2] << 8) + $temp[$offset + 1]); |
|
303 | 303 | } |
304 | 304 | $Y--; |
305 | 305 | $P += $line_length + $BMP['decal']; |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | { |
310 | 310 | while ($Y >= 0) |
311 | 311 | { |
312 | - $X=0; |
|
312 | + $X = 0; |
|
313 | 313 | |
314 | - $temp = unpack( "C*", substr($IMG, $P, $line_length)); |
|
314 | + $temp = unpack("C*", substr($IMG, $P, $line_length)); |
|
315 | 315 | |
316 | 316 | while ($X < $BMP['width']) |
317 | 317 | { |
318 | - imagesetpixel($res, $X++, $Y, $PALETTE[$temp[$X] +1]); |
|
318 | + imagesetpixel($res, $X++, $Y, $PALETTE[$temp[$X] + 1]); |
|
319 | 319 | } |
320 | 320 | $Y--; |
321 | 321 | $P += $line_length + $BMP['decal']; |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | { |
326 | 326 | while ($Y >= 0) |
327 | 327 | { |
328 | - $X=0; |
|
328 | + $X = 0; |
|
329 | 329 | $i = 1; |
330 | 330 | $low = true; |
331 | 331 | |
332 | - $temp = unpack( "C*", substr($IMG, $P, $line_length)); |
|
332 | + $temp = unpack("C*", substr($IMG, $P, $line_length)); |
|
333 | 333 | |
334 | 334 | while ($X < $BMP['width']) |
335 | 335 | { |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | } |
342 | 342 | $low = !$low; |
343 | 343 | |
344 | - imagesetpixel($res, $X++, $Y, $PALETTE[$index +1]); |
|
344 | + imagesetpixel($res, $X++, $Y, $PALETTE[$index + 1]); |
|
345 | 345 | } |
346 | 346 | $Y--; |
347 | 347 | $P += $line_length + $BMP['decal']; |
@@ -349,16 +349,16 @@ discard block |
||
349 | 349 | } |
350 | 350 | elseif ($BMP['bits_per_pixel'] == 1) |
351 | 351 | { |
352 | - $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1)); |
|
353 | - if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7; |
|
354 | - elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6; |
|
355 | - elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5; |
|
356 | - elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4; |
|
357 | - elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3; |
|
358 | - elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2; |
|
359 | - elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1; |
|
360 | - elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1); |
|
361 | - $COLOR[1] = $PALETTE[$COLOR[1]+1]; |
|
352 | + $COLOR = unpack("n", $VIDE.substr($IMG, floor($P), 1)); |
|
353 | + if (($P * 8) % 8 == 0) $COLOR[1] = $COLOR[1] >> 7; |
|
354 | + elseif (($P * 8) % 8 == 1) $COLOR[1] = ($COLOR[1] & 0x40) >> 6; |
|
355 | + elseif (($P * 8) % 8 == 2) $COLOR[1] = ($COLOR[1] & 0x20) >> 5; |
|
356 | + elseif (($P * 8) % 8 == 3) $COLOR[1] = ($COLOR[1] & 0x10) >> 4; |
|
357 | + elseif (($P * 8) % 8 == 4) $COLOR[1] = ($COLOR[1] & 0x8) >> 3; |
|
358 | + elseif (($P * 8) % 8 == 5) $COLOR[1] = ($COLOR[1] & 0x4) >> 2; |
|
359 | + elseif (($P * 8) % 8 == 6) $COLOR[1] = ($COLOR[1] & 0x2) >> 1; |
|
360 | + elseif (($P * 8) % 8 == 7) $COLOR[1] = ($COLOR[1] & 0x1); |
|
361 | + $COLOR[1] = $PALETTE[$COLOR[1] + 1]; |
|
362 | 362 | } |
363 | 363 | else { |
364 | 364 | return false; |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -28,8 +30,9 @@ discard block |
||
28 | 30 | function getErrorMessage($number, $arg = "") { |
29 | 31 | $langCode = 'en'; |
30 | 32 | if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) { |
31 | - if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php")) |
|
32 | - $langCode = $_GET['langCode']; |
|
33 | + if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php")) { |
|
34 | + $langCode = $_GET['langCode']; |
|
35 | + } |
|
33 | 36 | } |
34 | 37 | include CKFINDER_CONNECTOR_LANG_PATH . "/" . $langCode . ".php"; |
35 | 38 | if ($number) { |
@@ -304,8 +307,7 @@ discard block |
||
304 | 307 | $Y--; |
305 | 308 | $P += $line_length + $BMP['decal']; |
306 | 309 | } |
307 | - } |
|
308 | - elseif ($BMP['bits_per_pixel'] == 8) |
|
310 | + } elseif ($BMP['bits_per_pixel'] == 8) |
|
309 | 311 | { |
310 | 312 | while ($Y >= 0) |
311 | 313 | { |
@@ -320,8 +322,7 @@ discard block |
||
320 | 322 | $Y--; |
321 | 323 | $P += $line_length + $BMP['decal']; |
322 | 324 | } |
323 | - } |
|
324 | - elseif ($BMP['bits_per_pixel'] == 4) |
|
325 | + } elseif ($BMP['bits_per_pixel'] == 4) |
|
325 | 326 | { |
326 | 327 | while ($Y >= 0) |
327 | 328 | { |
@@ -335,8 +336,7 @@ discard block |
||
335 | 336 | { |
336 | 337 | if ($low) { |
337 | 338 | $index = $temp[$i] >> 4; |
338 | - } |
|
339 | - else { |
|
339 | + } else { |
|
340 | 340 | $index = $temp[$i++] & 0x0F; |
341 | 341 | } |
342 | 342 | $low = !$low; |
@@ -346,21 +346,28 @@ discard block |
||
346 | 346 | $Y--; |
347 | 347 | $P += $line_length + $BMP['decal']; |
348 | 348 | } |
349 | - } |
|
350 | - elseif ($BMP['bits_per_pixel'] == 1) |
|
349 | + } elseif ($BMP['bits_per_pixel'] == 1) |
|
351 | 350 | { |
352 | 351 | $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1)); |
353 | - if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7; |
|
354 | - elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6; |
|
355 | - elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5; |
|
356 | - elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4; |
|
357 | - elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3; |
|
358 | - elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2; |
|
359 | - elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1; |
|
360 | - elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1); |
|
352 | + if (($P*8)%8 == 0) { |
|
353 | + $COLOR[1] = $COLOR[1] >>7; |
|
354 | + } elseif (($P*8)%8 == 1) { |
|
355 | + $COLOR[1] = ($COLOR[1] & 0x40)>>6; |
|
356 | + } elseif (($P*8)%8 == 2) { |
|
357 | + $COLOR[1] = ($COLOR[1] & 0x20)>>5; |
|
358 | + } elseif (($P*8)%8 == 3) { |
|
359 | + $COLOR[1] = ($COLOR[1] & 0x10)>>4; |
|
360 | + } elseif (($P*8)%8 == 4) { |
|
361 | + $COLOR[1] = ($COLOR[1] & 0x8)>>3; |
|
362 | + } elseif (($P*8)%8 == 5) { |
|
363 | + $COLOR[1] = ($COLOR[1] & 0x4)>>2; |
|
364 | + } elseif (($P*8)%8 == 6) { |
|
365 | + $COLOR[1] = ($COLOR[1] & 0x2)>>1; |
|
366 | + } elseif (($P*8)%8 == 7) { |
|
367 | + $COLOR[1] = ($COLOR[1] & 0x1); |
|
368 | + } |
|
361 | 369 | $COLOR[1] = $PALETTE[$COLOR[1]+1]; |
362 | - } |
|
363 | - else { |
|
370 | + } else { |
|
364 | 371 | return false; |
365 | 372 | } |
366 | 373 |
@@ -107,7 +107,6 @@ discard block |
||
107 | 107 | /** |
108 | 108 | * Set element value |
109 | 109 | * |
110 | - * @param string $name |
|
111 | 110 | * @param string $value |
112 | 111 | * @access public |
113 | 112 | */ |
@@ -119,8 +118,6 @@ discard block |
||
119 | 118 | /** |
120 | 119 | * Get element value |
121 | 120 | * |
122 | - * @param string $name |
|
123 | - * @param string $value |
|
124 | 121 | * @access public |
125 | 122 | */ |
126 | 123 | function getValue() |
@@ -27,158 +27,158 @@ |
||
27 | 27 | */ |
28 | 28 | class Ckfinder_Connector_Utils_XmlNode |
29 | 29 | { |
30 | - /** |
|
31 | - * Array that stores XML attributes |
|
32 | - * |
|
33 | - * @access private |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - var $_attributes = array(); |
|
37 | - /** |
|
38 | - * Array that stores child nodes |
|
39 | - * |
|
40 | - * @access private |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - var $_childNodes = array(); |
|
44 | - /** |
|
45 | - * Node name |
|
46 | - * |
|
47 | - * @access private |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - var $_name; |
|
51 | - /** |
|
52 | - * Node value |
|
53 | - * |
|
54 | - * @access private |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - var $_value; |
|
58 | - |
|
59 | - /** |
|
60 | - * Create new node |
|
61 | - * |
|
62 | - * @param string $nodeName node name |
|
63 | - * @param string $nodeValue node value |
|
64 | - * @return Ckfinder_Connector_Utils_XmlNode |
|
65 | - */ |
|
66 | - function Ckfinder_Connector_Utils_XmlNode($nodeName, $nodeValue = null) |
|
67 | - { |
|
68 | - $this->_name = $nodeName; |
|
69 | - if (!is_null($nodeValue)) { |
|
70 | - $this->_value = $nodeValue; |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - function &getChild($name) |
|
75 | - { |
|
76 | - foreach ($this->_childNodes as $i => $node) { |
|
77 | - if ($node->_name == $name) { |
|
78 | - return $this->_childNodes[$i]; |
|
79 | - } |
|
80 | - } |
|
81 | - return null; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Add attribute |
|
86 | - * |
|
87 | - * @param string $name |
|
88 | - * @param string $value |
|
89 | - * @access public |
|
90 | - */ |
|
91 | - function addAttribute($name, $value) |
|
92 | - { |
|
93 | - $this->_attributes[$name] = $value; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get attribute value |
|
98 | - * |
|
99 | - * @param string $name |
|
100 | - * @access public |
|
101 | - */ |
|
102 | - function getAttribute($name) |
|
103 | - { |
|
104 | - return $this->_attributes[$name]; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Set element value |
|
109 | - * |
|
110 | - * @param string $name |
|
111 | - * @param string $value |
|
112 | - * @access public |
|
113 | - */ |
|
114 | - function setValue($value) |
|
115 | - { |
|
116 | - $this->_value = $value; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Get element value |
|
121 | - * |
|
122 | - * @param string $name |
|
123 | - * @param string $value |
|
124 | - * @access public |
|
125 | - */ |
|
126 | - function getValue() |
|
127 | - { |
|
128 | - return $this->_value; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Adds new child at the end of the children |
|
133 | - * |
|
134 | - * @param Ckfinder_Connector_Utils_XmlNode $node |
|
135 | - * @access public |
|
136 | - */ |
|
137 | - function addChild(&$node) |
|
138 | - { |
|
139 | - $this->_childNodes[] =& $node; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Return a well-formed XML string based on Ckfinder_Connector_Utils_XmlNode element |
|
144 | - * |
|
145 | - * @return string |
|
146 | - * @access public |
|
147 | - */ |
|
148 | - function asXML() |
|
149 | - { |
|
150 | - $ret = "<" . $this->_name; |
|
151 | - |
|
152 | - //print Attributes |
|
153 | - if (sizeof($this->_attributes)>0) { |
|
154 | - foreach ($this->_attributes as $_name => $_value) { |
|
155 | - $ret .= " " . $_name . '="' . htmlspecialchars($_value) . '"'; |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - //if there is nothing more |
|
160 | - if (is_null($this->_value) && !sizeof($this->_childNodes)) { |
|
161 | - $ret .= " />"; |
|
162 | - return $ret; |
|
163 | - } |
|
164 | - |
|
165 | - //close opening tag |
|
166 | - $ret .= ">"; |
|
167 | - |
|
168 | - //print value |
|
169 | - if (!is_null($this->_value)) { |
|
170 | - $ret .= htmlspecialchars($this->_value); |
|
171 | - } |
|
172 | - |
|
173 | - //print child nodes |
|
174 | - if (sizeof($this->_childNodes)>0) { |
|
175 | - foreach ($this->_childNodes as $_node) { |
|
176 | - $ret .= $_node->asXml(); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - $ret .= "</" . $this->_name . ">"; |
|
181 | - |
|
182 | - return $ret; |
|
183 | - } |
|
30 | + /** |
|
31 | + * Array that stores XML attributes |
|
32 | + * |
|
33 | + * @access private |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + var $_attributes = array(); |
|
37 | + /** |
|
38 | + * Array that stores child nodes |
|
39 | + * |
|
40 | + * @access private |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + var $_childNodes = array(); |
|
44 | + /** |
|
45 | + * Node name |
|
46 | + * |
|
47 | + * @access private |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + var $_name; |
|
51 | + /** |
|
52 | + * Node value |
|
53 | + * |
|
54 | + * @access private |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + var $_value; |
|
58 | + |
|
59 | + /** |
|
60 | + * Create new node |
|
61 | + * |
|
62 | + * @param string $nodeName node name |
|
63 | + * @param string $nodeValue node value |
|
64 | + * @return Ckfinder_Connector_Utils_XmlNode |
|
65 | + */ |
|
66 | + function Ckfinder_Connector_Utils_XmlNode($nodeName, $nodeValue = null) |
|
67 | + { |
|
68 | + $this->_name = $nodeName; |
|
69 | + if (!is_null($nodeValue)) { |
|
70 | + $this->_value = $nodeValue; |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + function &getChild($name) |
|
75 | + { |
|
76 | + foreach ($this->_childNodes as $i => $node) { |
|
77 | + if ($node->_name == $name) { |
|
78 | + return $this->_childNodes[$i]; |
|
79 | + } |
|
80 | + } |
|
81 | + return null; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Add attribute |
|
86 | + * |
|
87 | + * @param string $name |
|
88 | + * @param string $value |
|
89 | + * @access public |
|
90 | + */ |
|
91 | + function addAttribute($name, $value) |
|
92 | + { |
|
93 | + $this->_attributes[$name] = $value; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get attribute value |
|
98 | + * |
|
99 | + * @param string $name |
|
100 | + * @access public |
|
101 | + */ |
|
102 | + function getAttribute($name) |
|
103 | + { |
|
104 | + return $this->_attributes[$name]; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Set element value |
|
109 | + * |
|
110 | + * @param string $name |
|
111 | + * @param string $value |
|
112 | + * @access public |
|
113 | + */ |
|
114 | + function setValue($value) |
|
115 | + { |
|
116 | + $this->_value = $value; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Get element value |
|
121 | + * |
|
122 | + * @param string $name |
|
123 | + * @param string $value |
|
124 | + * @access public |
|
125 | + */ |
|
126 | + function getValue() |
|
127 | + { |
|
128 | + return $this->_value; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Adds new child at the end of the children |
|
133 | + * |
|
134 | + * @param Ckfinder_Connector_Utils_XmlNode $node |
|
135 | + * @access public |
|
136 | + */ |
|
137 | + function addChild(&$node) |
|
138 | + { |
|
139 | + $this->_childNodes[] =& $node; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Return a well-formed XML string based on Ckfinder_Connector_Utils_XmlNode element |
|
144 | + * |
|
145 | + * @return string |
|
146 | + * @access public |
|
147 | + */ |
|
148 | + function asXML() |
|
149 | + { |
|
150 | + $ret = "<" . $this->_name; |
|
151 | + |
|
152 | + //print Attributes |
|
153 | + if (sizeof($this->_attributes)>0) { |
|
154 | + foreach ($this->_attributes as $_name => $_value) { |
|
155 | + $ret .= " " . $_name . '="' . htmlspecialchars($_value) . '"'; |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + //if there is nothing more |
|
160 | + if (is_null($this->_value) && !sizeof($this->_childNodes)) { |
|
161 | + $ret .= " />"; |
|
162 | + return $ret; |
|
163 | + } |
|
164 | + |
|
165 | + //close opening tag |
|
166 | + $ret .= ">"; |
|
167 | + |
|
168 | + //print value |
|
169 | + if (!is_null($this->_value)) { |
|
170 | + $ret .= htmlspecialchars($this->_value); |
|
171 | + } |
|
172 | + |
|
173 | + //print child nodes |
|
174 | + if (sizeof($this->_childNodes)>0) { |
|
175 | + foreach ($this->_childNodes as $_node) { |
|
176 | + $ret .= $_node->asXml(); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + $ret .= "</" . $this->_name . ">"; |
|
181 | + |
|
182 | + return $ret; |
|
183 | + } |
|
184 | 184 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | function addChild(&$node) |
138 | 138 | { |
139 | - $this->_childNodes[] =& $node; |
|
139 | + $this->_childNodes[] = & $node; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -147,12 +147,12 @@ discard block |
||
147 | 147 | */ |
148 | 148 | function asXML() |
149 | 149 | { |
150 | - $ret = "<" . $this->_name; |
|
150 | + $ret = "<".$this->_name; |
|
151 | 151 | |
152 | 152 | //print Attributes |
153 | - if (sizeof($this->_attributes)>0) { |
|
153 | + if (sizeof($this->_attributes) > 0) { |
|
154 | 154 | foreach ($this->_attributes as $_name => $_value) { |
155 | - $ret .= " " . $_name . '="' . htmlspecialchars($_value) . '"'; |
|
155 | + $ret .= " ".$_name.'="'.htmlspecialchars($_value).'"'; |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | } |
172 | 172 | |
173 | 173 | //print child nodes |
174 | - if (sizeof($this->_childNodes)>0) { |
|
174 | + if (sizeof($this->_childNodes) > 0) { |
|
175 | 175 | foreach ($this->_childNodes as $_node) { |
176 | 176 | $ret .= $_node->asXml(); |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - $ret .= "</" . $this->_name . ">"; |
|
180 | + $ret .= "</".$this->_name.">"; |
|
181 | 181 | |
182 | 182 | return $ret; |
183 | 183 | } |
@@ -10,7 +10,9 @@ |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -243,6 +243,10 @@ |
||
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | + /** |
|
247 | + * @param integer $errorCode |
|
248 | + * @param string $path |
|
249 | + */ |
|
246 | 250 | private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path) |
247 | 251 | { |
248 | 252 | $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
@@ -32,224 +32,224 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_CopyFiles extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - private $command = "CopyFiles"; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * handle request and build XML |
|
46 | - * @access protected |
|
47 | - * |
|
48 | - */ |
|
49 | - protected function buildXml() |
|
50 | - { |
|
51 | - if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | - } |
|
54 | - |
|
55 | - $clientPath = $this->_currentFolder->getClientPath(); |
|
56 | - $sServerDir = $this->_currentFolder->getServerPath(); |
|
57 | - $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
58 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | - $_aclConfig = $_config->getAccessControlConfig(); |
|
60 | - $aclMasks = array(); |
|
61 | - $_resourceTypeConfig = array(); |
|
62 | - |
|
63 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
64 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
65 | - } |
|
66 | - |
|
67 | - // Create the "Errors" node. |
|
68 | - $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
69 | - $errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
70 | - $copied = 0; |
|
71 | - $copiedAll = 0; |
|
72 | - if (!empty($_POST['copied'])) { |
|
73 | - $copiedAll = intval($_POST['copied']); |
|
74 | - } |
|
75 | - $checkedPaths = array(); |
|
76 | - |
|
77 | - $oCopyFilesNode = new Ckfinder_Connector_Utils_XmlNode("CopyFiles"); |
|
78 | - |
|
79 | - if (!empty($_POST['files']) && is_array($_POST['files'])) { |
|
80 | - foreach ($_POST['files'] as $index => $arr) { |
|
81 | - if (empty($arr['name'])) { |
|
82 | - continue; |
|
83 | - } |
|
84 | - if (!isset($arr['name'], $arr['type'], $arr['folder'])) { |
|
85 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
86 | - } |
|
87 | - |
|
88 | - // file name |
|
89 | - $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
90 | - // resource type |
|
91 | - $type = $arr['type']; |
|
92 | - // client path |
|
93 | - $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
94 | - // options |
|
95 | - $options = (!empty($arr['options'])) ? $arr['options'] : ''; |
|
96 | - |
|
97 | - $destinationFilePath = $sServerDir.$name; |
|
98 | - |
|
99 | - // check #1 (path) |
|
100 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
101 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
102 | - } |
|
103 | - |
|
104 | - // get resource type config for current file |
|
105 | - if (!isset($_resourceTypeConfig[$type])) { |
|
106 | - $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type); |
|
107 | - } |
|
108 | - |
|
109 | - // check #2 (resource type) |
|
110 | - if (is_null($_resourceTypeConfig[$type])) { |
|
111 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | - } |
|
113 | - |
|
114 | - // check #3 (extension) |
|
115 | - if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
116 | - $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
117 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
118 | - continue; |
|
119 | - } |
|
120 | - |
|
121 | - // check #4 (extension) - when moving to another resource type, double check extension |
|
122 | - if ($currentResourceTypeConfig->getName() != $type) { |
|
123 | - if (!$currentResourceTypeConfig->checkExtension($name, false)) { |
|
124 | - $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
125 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
126 | - continue; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - // check #5 (hidden folders) |
|
131 | - // cache results |
|
132 | - if (empty($checkedPaths[$path])) { |
|
133 | - $checkedPaths[$path] = true; |
|
134 | - |
|
135 | - if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
136 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name; |
|
141 | - |
|
142 | - // check #6 (hidden file name) |
|
143 | - if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
144 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
145 | - } |
|
146 | - |
|
147 | - // check #7 (Access Control, need file view permission to source files) |
|
148 | - if (!isset($aclMasks[$type."@".$path])) { |
|
149 | - $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
150 | - } |
|
151 | - |
|
152 | - $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
153 | - if (!$isAuthorized) { |
|
154 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
155 | - } |
|
156 | - |
|
157 | - // check #8 (invalid file name) |
|
158 | - if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
159 | - $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND; |
|
160 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
161 | - continue; |
|
162 | - } |
|
163 | - |
|
164 | - // check #9 (max size) |
|
165 | - if ($currentResourceTypeConfig->getName() != $type) { |
|
166 | - $maxSize = $currentResourceTypeConfig->getMaxSize(); |
|
167 | - $fileSize = filesize($sourceFilePath); |
|
168 | - if ($maxSize && $fileSize>$maxSize) { |
|
169 | - $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
170 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
171 | - continue; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - //$overwrite |
|
176 | - // finally, no errors so far, we may attempt to copy a file |
|
177 | - // protection against copying files to itself |
|
178 | - if ($sourceFilePath == $destinationFilePath) { |
|
179 | - $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL; |
|
180 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
181 | - continue; |
|
182 | - } |
|
183 | - // check if file exists if we don't force overwriting |
|
184 | - else if (file_exists($destinationFilePath) && strpos($options, "overwrite") === false) { |
|
185 | - if (strpos($options, "autorename") !== false) { |
|
186 | - $iCounter = 1; |
|
187 | - while (true) |
|
188 | - { |
|
189 | - $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
190 | - "(" . $iCounter . ")" . "." . |
|
191 | - CKFinder_Connector_Utils_FileSystem::getExtension($name); |
|
192 | - |
|
193 | - $destinationFilePath = $sServerDir.$fileName; |
|
194 | - if (!file_exists($destinationFilePath)) { |
|
195 | - break; |
|
196 | - } |
|
197 | - else { |
|
198 | - $iCounter++; |
|
199 | - } |
|
200 | - } |
|
201 | - if (!@copy($sourceFilePath, $destinationFilePath)) { |
|
202 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
203 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
204 | - continue; |
|
205 | - } |
|
206 | - else { |
|
207 | - $copied++; |
|
208 | - } |
|
209 | - } |
|
210 | - else { |
|
211 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
212 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
213 | - continue; |
|
214 | - } |
|
215 | - } |
|
216 | - // copy() overwrites without warning |
|
217 | - else { |
|
218 | - if (!@copy($sourceFilePath, $destinationFilePath)) { |
|
219 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
220 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
221 | - continue; |
|
222 | - } |
|
223 | - else { |
|
224 | - $copied++; |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - $this->_connectorNode->addChild($oCopyFilesNode); |
|
231 | - if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
232 | - $this->_connectorNode->addChild($oErrorsNode); |
|
233 | - } |
|
234 | - $oCopyFilesNode->addAttribute("copied", $copied); |
|
235 | - $oCopyFilesNode->addAttribute("copiedTotal", $copiedAll + $copied); |
|
236 | - |
|
237 | - /** |
|
238 | - * Note: actually we could have more than one error. |
|
239 | - * This is just a flag for CKFinder interface telling it to check all errors. |
|
240 | - */ |
|
241 | - if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
242 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_COPY_FAILED); |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path) |
|
247 | - { |
|
248 | - $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
249 | - $oErrorNode->addAttribute("code", $errorCode); |
|
250 | - $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
251 | - $oErrorNode->addAttribute("type", $type); |
|
252 | - $oErrorNode->addAttribute("folder", $path); |
|
253 | - $oErrorsNode->addChild($oErrorNode); |
|
254 | - } |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + private $command = "CopyFiles"; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * handle request and build XML |
|
46 | + * @access protected |
|
47 | + * |
|
48 | + */ |
|
49 | + protected function buildXml() |
|
50 | + { |
|
51 | + if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | + } |
|
54 | + |
|
55 | + $clientPath = $this->_currentFolder->getClientPath(); |
|
56 | + $sServerDir = $this->_currentFolder->getServerPath(); |
|
57 | + $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
58 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | + $_aclConfig = $_config->getAccessControlConfig(); |
|
60 | + $aclMasks = array(); |
|
61 | + $_resourceTypeConfig = array(); |
|
62 | + |
|
63 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
64 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
65 | + } |
|
66 | + |
|
67 | + // Create the "Errors" node. |
|
68 | + $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
69 | + $errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
70 | + $copied = 0; |
|
71 | + $copiedAll = 0; |
|
72 | + if (!empty($_POST['copied'])) { |
|
73 | + $copiedAll = intval($_POST['copied']); |
|
74 | + } |
|
75 | + $checkedPaths = array(); |
|
76 | + |
|
77 | + $oCopyFilesNode = new Ckfinder_Connector_Utils_XmlNode("CopyFiles"); |
|
78 | + |
|
79 | + if (!empty($_POST['files']) && is_array($_POST['files'])) { |
|
80 | + foreach ($_POST['files'] as $index => $arr) { |
|
81 | + if (empty($arr['name'])) { |
|
82 | + continue; |
|
83 | + } |
|
84 | + if (!isset($arr['name'], $arr['type'], $arr['folder'])) { |
|
85 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
86 | + } |
|
87 | + |
|
88 | + // file name |
|
89 | + $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
90 | + // resource type |
|
91 | + $type = $arr['type']; |
|
92 | + // client path |
|
93 | + $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
94 | + // options |
|
95 | + $options = (!empty($arr['options'])) ? $arr['options'] : ''; |
|
96 | + |
|
97 | + $destinationFilePath = $sServerDir.$name; |
|
98 | + |
|
99 | + // check #1 (path) |
|
100 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
101 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
102 | + } |
|
103 | + |
|
104 | + // get resource type config for current file |
|
105 | + if (!isset($_resourceTypeConfig[$type])) { |
|
106 | + $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type); |
|
107 | + } |
|
108 | + |
|
109 | + // check #2 (resource type) |
|
110 | + if (is_null($_resourceTypeConfig[$type])) { |
|
111 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | + } |
|
113 | + |
|
114 | + // check #3 (extension) |
|
115 | + if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
116 | + $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
117 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
118 | + continue; |
|
119 | + } |
|
120 | + |
|
121 | + // check #4 (extension) - when moving to another resource type, double check extension |
|
122 | + if ($currentResourceTypeConfig->getName() != $type) { |
|
123 | + if (!$currentResourceTypeConfig->checkExtension($name, false)) { |
|
124 | + $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
125 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
126 | + continue; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + // check #5 (hidden folders) |
|
131 | + // cache results |
|
132 | + if (empty($checkedPaths[$path])) { |
|
133 | + $checkedPaths[$path] = true; |
|
134 | + |
|
135 | + if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
136 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name; |
|
141 | + |
|
142 | + // check #6 (hidden file name) |
|
143 | + if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
144 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
145 | + } |
|
146 | + |
|
147 | + // check #7 (Access Control, need file view permission to source files) |
|
148 | + if (!isset($aclMasks[$type."@".$path])) { |
|
149 | + $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
150 | + } |
|
151 | + |
|
152 | + $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
153 | + if (!$isAuthorized) { |
|
154 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
155 | + } |
|
156 | + |
|
157 | + // check #8 (invalid file name) |
|
158 | + if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
159 | + $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND; |
|
160 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
161 | + continue; |
|
162 | + } |
|
163 | + |
|
164 | + // check #9 (max size) |
|
165 | + if ($currentResourceTypeConfig->getName() != $type) { |
|
166 | + $maxSize = $currentResourceTypeConfig->getMaxSize(); |
|
167 | + $fileSize = filesize($sourceFilePath); |
|
168 | + if ($maxSize && $fileSize>$maxSize) { |
|
169 | + $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
170 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
171 | + continue; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + //$overwrite |
|
176 | + // finally, no errors so far, we may attempt to copy a file |
|
177 | + // protection against copying files to itself |
|
178 | + if ($sourceFilePath == $destinationFilePath) { |
|
179 | + $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL; |
|
180 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
181 | + continue; |
|
182 | + } |
|
183 | + // check if file exists if we don't force overwriting |
|
184 | + else if (file_exists($destinationFilePath) && strpos($options, "overwrite") === false) { |
|
185 | + if (strpos($options, "autorename") !== false) { |
|
186 | + $iCounter = 1; |
|
187 | + while (true) |
|
188 | + { |
|
189 | + $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
190 | + "(" . $iCounter . ")" . "." . |
|
191 | + CKFinder_Connector_Utils_FileSystem::getExtension($name); |
|
192 | + |
|
193 | + $destinationFilePath = $sServerDir.$fileName; |
|
194 | + if (!file_exists($destinationFilePath)) { |
|
195 | + break; |
|
196 | + } |
|
197 | + else { |
|
198 | + $iCounter++; |
|
199 | + } |
|
200 | + } |
|
201 | + if (!@copy($sourceFilePath, $destinationFilePath)) { |
|
202 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
203 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
204 | + continue; |
|
205 | + } |
|
206 | + else { |
|
207 | + $copied++; |
|
208 | + } |
|
209 | + } |
|
210 | + else { |
|
211 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
212 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
213 | + continue; |
|
214 | + } |
|
215 | + } |
|
216 | + // copy() overwrites without warning |
|
217 | + else { |
|
218 | + if (!@copy($sourceFilePath, $destinationFilePath)) { |
|
219 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
220 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
221 | + continue; |
|
222 | + } |
|
223 | + else { |
|
224 | + $copied++; |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + $this->_connectorNode->addChild($oCopyFilesNode); |
|
231 | + if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
232 | + $this->_connectorNode->addChild($oErrorsNode); |
|
233 | + } |
|
234 | + $oCopyFilesNode->addAttribute("copied", $copied); |
|
235 | + $oCopyFilesNode->addAttribute("copiedTotal", $copiedAll + $copied); |
|
236 | + |
|
237 | + /** |
|
238 | + * Note: actually we could have more than one error. |
|
239 | + * This is just a flag for CKFinder interface telling it to check all errors. |
|
240 | + */ |
|
241 | + if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
242 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_COPY_FAILED); |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path) |
|
247 | + { |
|
248 | + $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
249 | + $oErrorNode->addAttribute("code", $errorCode); |
|
250 | + $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
251 | + $oErrorNode->addAttribute("type", $type); |
|
252 | + $oErrorNode->addAttribute("folder", $path); |
|
253 | + $oErrorsNode->addChild($oErrorNode); |
|
254 | + } |
|
255 | 255 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include base XML command handler |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/XmlCommandHandlerBase.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Handle CopyFiles command |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $clientPath = $this->_currentFolder->getClientPath(); |
56 | 56 | $sServerDir = $this->_currentFolder->getServerPath(); |
57 | 57 | $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
58 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
58 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | 59 | $_aclConfig = $_config->getAccessControlConfig(); |
60 | 60 | $aclMasks = array(); |
61 | 61 | $_resourceTypeConfig = array(); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | if ($currentResourceTypeConfig->getName() != $type) { |
166 | 166 | $maxSize = $currentResourceTypeConfig->getMaxSize(); |
167 | 167 | $fileSize = filesize($sourceFilePath); |
168 | - if ($maxSize && $fileSize>$maxSize) { |
|
168 | + if ($maxSize && $fileSize > $maxSize) { |
|
169 | 169 | $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
170 | 170 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
171 | 171 | continue; |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | $iCounter = 1; |
187 | 187 | while (true) |
188 | 188 | { |
189 | - $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
190 | - "(" . $iCounter . ")" . "." . |
|
189 | + $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name). |
|
190 | + "(".$iCounter.")".".". |
|
191 | 191 | CKFinder_Connector_Utils_FileSystem::getExtension($name); |
192 | 192 | |
193 | 193 | $destinationFilePath = $sServerDir.$fileName; |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -193,8 +195,7 @@ discard block |
||
193 | 195 | $destinationFilePath = $sServerDir.$fileName; |
194 | 196 | if (!file_exists($destinationFilePath)) { |
195 | 197 | break; |
196 | - } |
|
197 | - else { |
|
198 | + } else { |
|
198 | 199 | $iCounter++; |
199 | 200 | } |
200 | 201 | } |
@@ -202,12 +203,10 @@ discard block |
||
202 | 203 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
203 | 204 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
204 | 205 | continue; |
205 | - } |
|
206 | - else { |
|
206 | + } else { |
|
207 | 207 | $copied++; |
208 | 208 | } |
209 | - } |
|
210 | - else { |
|
209 | + } else { |
|
211 | 210 | $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
212 | 211 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
213 | 212 | continue; |
@@ -219,8 +218,7 @@ discard block |
||
219 | 218 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
220 | 219 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
221 | 220 | continue; |
222 | - } |
|
223 | - else { |
|
221 | + } else { |
|
224 | 222 | $copied++; |
225 | 223 | } |
226 | 224 | } |
@@ -259,6 +259,10 @@ |
||
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
262 | + /** |
|
263 | + * @param integer $errorCode |
|
264 | + * @param string $path |
|
265 | + */ |
|
262 | 266 | private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path) |
263 | 267 | { |
264 | 268 | $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
@@ -32,240 +32,240 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_MoveFiles extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - private $command = "MoveFiles"; |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + private $command = "MoveFiles"; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * handle request and build XML |
|
46 | - * @access protected |
|
47 | - * |
|
48 | - */ |
|
49 | - protected function buildXml() |
|
50 | - { |
|
51 | - if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | - } |
|
44 | + /** |
|
45 | + * handle request and build XML |
|
46 | + * @access protected |
|
47 | + * |
|
48 | + */ |
|
49 | + protected function buildXml() |
|
50 | + { |
|
51 | + if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | + } |
|
54 | 54 | |
55 | - $clientPath = $this->_currentFolder->getClientPath(); |
|
56 | - $sServerDir = $this->_currentFolder->getServerPath(); |
|
57 | - $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
58 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | - $_aclConfig = $_config->getAccessControlConfig(); |
|
60 | - $aclMasks = array(); |
|
61 | - $_resourceTypeConfig = array(); |
|
55 | + $clientPath = $this->_currentFolder->getClientPath(); |
|
56 | + $sServerDir = $this->_currentFolder->getServerPath(); |
|
57 | + $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
58 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | + $_aclConfig = $_config->getAccessControlConfig(); |
|
60 | + $aclMasks = array(); |
|
61 | + $_resourceTypeConfig = array(); |
|
62 | 62 | |
63 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
64 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
65 | - } |
|
63 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
64 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
65 | + } |
|
66 | 66 | |
67 | - // Create the "Errors" node. |
|
68 | - $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
69 | - $errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
70 | - $moved = 0; |
|
71 | - $movedAll = 0; |
|
72 | - if (!empty($_POST['moved'])) { |
|
73 | - $movedAll = intval($_POST['moved']); |
|
74 | - } |
|
75 | - $checkedPaths = array(); |
|
67 | + // Create the "Errors" node. |
|
68 | + $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
69 | + $errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
70 | + $moved = 0; |
|
71 | + $movedAll = 0; |
|
72 | + if (!empty($_POST['moved'])) { |
|
73 | + $movedAll = intval($_POST['moved']); |
|
74 | + } |
|
75 | + $checkedPaths = array(); |
|
76 | 76 | |
77 | - $oMoveFilesNode = new Ckfinder_Connector_Utils_XmlNode("MoveFiles"); |
|
77 | + $oMoveFilesNode = new Ckfinder_Connector_Utils_XmlNode("MoveFiles"); |
|
78 | 78 | |
79 | - if (!empty($_POST['files']) && is_array($_POST['files'])) { |
|
80 | - foreach ($_POST['files'] as $index => $arr) { |
|
81 | - if (empty($arr['name'])) { |
|
82 | - continue; |
|
83 | - } |
|
84 | - if (!isset($arr['name'], $arr['type'], $arr['folder'])) { |
|
85 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
86 | - } |
|
79 | + if (!empty($_POST['files']) && is_array($_POST['files'])) { |
|
80 | + foreach ($_POST['files'] as $index => $arr) { |
|
81 | + if (empty($arr['name'])) { |
|
82 | + continue; |
|
83 | + } |
|
84 | + if (!isset($arr['name'], $arr['type'], $arr['folder'])) { |
|
85 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
86 | + } |
|
87 | 87 | |
88 | - // file name |
|
89 | - $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
90 | - // resource type |
|
91 | - $type = $arr['type']; |
|
92 | - // client path |
|
93 | - $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
94 | - // options |
|
95 | - $options = (!empty($arr['options'])) ? $arr['options'] : ''; |
|
88 | + // file name |
|
89 | + $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
90 | + // resource type |
|
91 | + $type = $arr['type']; |
|
92 | + // client path |
|
93 | + $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
94 | + // options |
|
95 | + $options = (!empty($arr['options'])) ? $arr['options'] : ''; |
|
96 | 96 | |
97 | - $destinationFilePath = $sServerDir.$name; |
|
97 | + $destinationFilePath = $sServerDir.$name; |
|
98 | 98 | |
99 | - // check #1 (path) |
|
100 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
101 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
102 | - } |
|
99 | + // check #1 (path) |
|
100 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
101 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
102 | + } |
|
103 | 103 | |
104 | - // get resource type config for current file |
|
105 | - if (!isset($_resourceTypeConfig[$type])) { |
|
106 | - $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type); |
|
107 | - } |
|
104 | + // get resource type config for current file |
|
105 | + if (!isset($_resourceTypeConfig[$type])) { |
|
106 | + $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type); |
|
107 | + } |
|
108 | 108 | |
109 | - // check #2 (resource type) |
|
110 | - if (is_null($_resourceTypeConfig[$type])) { |
|
111 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | - } |
|
109 | + // check #2 (resource type) |
|
110 | + if (is_null($_resourceTypeConfig[$type])) { |
|
111 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | + } |
|
113 | 113 | |
114 | - // check #3 (extension) |
|
115 | - if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
116 | - $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
117 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
118 | - continue; |
|
119 | - } |
|
114 | + // check #3 (extension) |
|
115 | + if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
116 | + $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
117 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
118 | + continue; |
|
119 | + } |
|
120 | 120 | |
121 | - // check #4 (extension) - when moving to another resource type, double check extension |
|
122 | - if ($currentResourceTypeConfig->getName() != $type) { |
|
123 | - if (!$currentResourceTypeConfig->checkExtension($name, false)) { |
|
124 | - $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
125 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
126 | - continue; |
|
127 | - } |
|
128 | - } |
|
121 | + // check #4 (extension) - when moving to another resource type, double check extension |
|
122 | + if ($currentResourceTypeConfig->getName() != $type) { |
|
123 | + if (!$currentResourceTypeConfig->checkExtension($name, false)) { |
|
124 | + $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
125 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
126 | + continue; |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - // check #5 (hidden folders) |
|
131 | - // cache results |
|
132 | - if (empty($checkedPaths[$path])) { |
|
133 | - $checkedPaths[$path] = true; |
|
130 | + // check #5 (hidden folders) |
|
131 | + // cache results |
|
132 | + if (empty($checkedPaths[$path])) { |
|
133 | + $checkedPaths[$path] = true; |
|
134 | 134 | |
135 | - if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
136 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
137 | - } |
|
138 | - } |
|
135 | + if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
136 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name; |
|
140 | + $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name; |
|
141 | 141 | |
142 | - // check #6 (hidden file name) |
|
143 | - if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
144 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
145 | - } |
|
142 | + // check #6 (hidden file name) |
|
143 | + if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
144 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
145 | + } |
|
146 | 146 | |
147 | - // check #7 (Access Control, need file view permission to source files) |
|
148 | - if (!isset($aclMasks[$type."@".$path])) { |
|
149 | - $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
150 | - } |
|
147 | + // check #7 (Access Control, need file view permission to source files) |
|
148 | + if (!isset($aclMasks[$type."@".$path])) { |
|
149 | + $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
150 | + } |
|
151 | 151 | |
152 | - $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
153 | - if (!$isAuthorized) { |
|
154 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
155 | - } |
|
152 | + $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
153 | + if (!$isAuthorized) { |
|
154 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
155 | + } |
|
156 | 156 | |
157 | - // check #8 (invalid file name) |
|
158 | - if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
159 | - $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND; |
|
160 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
161 | - continue; |
|
162 | - } |
|
157 | + // check #8 (invalid file name) |
|
158 | + if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
159 | + $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND; |
|
160 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
161 | + continue; |
|
162 | + } |
|
163 | 163 | |
164 | - // check #9 (max size) |
|
165 | - if ($currentResourceTypeConfig->getName() != $type) { |
|
166 | - $maxSize = $currentResourceTypeConfig->getMaxSize(); |
|
167 | - $fileSize = filesize($sourceFilePath); |
|
168 | - if ($maxSize && $fileSize>$maxSize) { |
|
169 | - $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
170 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
171 | - continue; |
|
172 | - } |
|
173 | - } |
|
164 | + // check #9 (max size) |
|
165 | + if ($currentResourceTypeConfig->getName() != $type) { |
|
166 | + $maxSize = $currentResourceTypeConfig->getMaxSize(); |
|
167 | + $fileSize = filesize($sourceFilePath); |
|
168 | + if ($maxSize && $fileSize>$maxSize) { |
|
169 | + $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
170 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
171 | + continue; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - //$overwrite |
|
176 | - // finally, no errors so far, we may attempt to copy a file |
|
177 | - // protection against copying files to itself |
|
178 | - if ($sourceFilePath == $destinationFilePath) { |
|
179 | - $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL; |
|
180 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
181 | - continue; |
|
182 | - } |
|
183 | - // check if file exists if we don't force overwriting |
|
184 | - else if (file_exists($destinationFilePath)) { |
|
185 | - if (strpos($options, "overwrite") !== false) { |
|
186 | - if (!@unlink($destinationFilePath)) { |
|
187 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
188 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
189 | - continue; |
|
190 | - } |
|
191 | - else { |
|
192 | - if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
193 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
194 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
195 | - continue; |
|
196 | - } |
|
197 | - else { |
|
198 | - $moved++; |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - else if (strpos($options, "autorename") !== false) { |
|
203 | - $iCounter = 1; |
|
204 | - while (true) |
|
205 | - { |
|
206 | - $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
207 | - "(" . $iCounter . ")" . "." . |
|
208 | - CKFinder_Connector_Utils_FileSystem::getExtension($name); |
|
175 | + //$overwrite |
|
176 | + // finally, no errors so far, we may attempt to copy a file |
|
177 | + // protection against copying files to itself |
|
178 | + if ($sourceFilePath == $destinationFilePath) { |
|
179 | + $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL; |
|
180 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
181 | + continue; |
|
182 | + } |
|
183 | + // check if file exists if we don't force overwriting |
|
184 | + else if (file_exists($destinationFilePath)) { |
|
185 | + if (strpos($options, "overwrite") !== false) { |
|
186 | + if (!@unlink($destinationFilePath)) { |
|
187 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
188 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
189 | + continue; |
|
190 | + } |
|
191 | + else { |
|
192 | + if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
193 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
194 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
195 | + continue; |
|
196 | + } |
|
197 | + else { |
|
198 | + $moved++; |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + else if (strpos($options, "autorename") !== false) { |
|
203 | + $iCounter = 1; |
|
204 | + while (true) |
|
205 | + { |
|
206 | + $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
207 | + "(" . $iCounter . ")" . "." . |
|
208 | + CKFinder_Connector_Utils_FileSystem::getExtension($name); |
|
209 | 209 | |
210 | - $destinationFilePath = $sServerDir.$fileName; |
|
211 | - if (!file_exists($destinationFilePath)) { |
|
212 | - break; |
|
213 | - } |
|
214 | - else { |
|
215 | - $iCounter++; |
|
216 | - } |
|
217 | - } |
|
218 | - if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
219 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
220 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
221 | - continue; |
|
222 | - } |
|
223 | - else { |
|
224 | - $moved++; |
|
225 | - } |
|
226 | - } |
|
227 | - else { |
|
228 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
229 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
230 | - continue; |
|
231 | - } |
|
232 | - } |
|
233 | - else { |
|
234 | - if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
235 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
236 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
237 | - continue; |
|
238 | - } |
|
239 | - else { |
|
240 | - $moved++; |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
210 | + $destinationFilePath = $sServerDir.$fileName; |
|
211 | + if (!file_exists($destinationFilePath)) { |
|
212 | + break; |
|
213 | + } |
|
214 | + else { |
|
215 | + $iCounter++; |
|
216 | + } |
|
217 | + } |
|
218 | + if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
219 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
220 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
221 | + continue; |
|
222 | + } |
|
223 | + else { |
|
224 | + $moved++; |
|
225 | + } |
|
226 | + } |
|
227 | + else { |
|
228 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
229 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
230 | + continue; |
|
231 | + } |
|
232 | + } |
|
233 | + else { |
|
234 | + if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
235 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
236 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
237 | + continue; |
|
238 | + } |
|
239 | + else { |
|
240 | + $moved++; |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | - $this->_connectorNode->addChild($oMoveFilesNode); |
|
247 | - if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
248 | - $this->_connectorNode->addChild($oErrorsNode); |
|
249 | - } |
|
250 | - $oMoveFilesNode->addAttribute("moved", $moved); |
|
251 | - $oMoveFilesNode->addAttribute("movedTotal", $movedAll + $moved); |
|
246 | + $this->_connectorNode->addChild($oMoveFilesNode); |
|
247 | + if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
248 | + $this->_connectorNode->addChild($oErrorsNode); |
|
249 | + } |
|
250 | + $oMoveFilesNode->addAttribute("moved", $moved); |
|
251 | + $oMoveFilesNode->addAttribute("movedTotal", $movedAll + $moved); |
|
252 | 252 | |
253 | - /** |
|
254 | - * Note: actually we could have more than one error. |
|
255 | - * This is just a flag for CKFinder interface telling it to check all errors. |
|
256 | - */ |
|
257 | - if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
258 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_MOVE_FAILED); |
|
259 | - } |
|
260 | - } |
|
253 | + /** |
|
254 | + * Note: actually we could have more than one error. |
|
255 | + * This is just a flag for CKFinder interface telling it to check all errors. |
|
256 | + */ |
|
257 | + if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
258 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_MOVE_FAILED); |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path) |
|
263 | - { |
|
264 | - $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
265 | - $oErrorNode->addAttribute("code", $errorCode); |
|
266 | - $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
267 | - $oErrorNode->addAttribute("type", $type); |
|
268 | - $oErrorNode->addAttribute("folder", $path); |
|
269 | - $oErrorsNode->addChild($oErrorNode); |
|
270 | - } |
|
262 | + private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path) |
|
263 | + { |
|
264 | + $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
265 | + $oErrorNode->addAttribute("code", $errorCode); |
|
266 | + $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
267 | + $oErrorNode->addAttribute("type", $type); |
|
268 | + $oErrorNode->addAttribute("folder", $path); |
|
269 | + $oErrorsNode->addChild($oErrorNode); |
|
270 | + } |
|
271 | 271 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include base XML command handler |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/XmlCommandHandlerBase.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Handle MoveFiles command |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $clientPath = $this->_currentFolder->getClientPath(); |
56 | 56 | $sServerDir = $this->_currentFolder->getServerPath(); |
57 | 57 | $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
58 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
58 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | 59 | $_aclConfig = $_config->getAccessControlConfig(); |
60 | 60 | $aclMasks = array(); |
61 | 61 | $_resourceTypeConfig = array(); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | if ($currentResourceTypeConfig->getName() != $type) { |
166 | 166 | $maxSize = $currentResourceTypeConfig->getMaxSize(); |
167 | 167 | $fileSize = filesize($sourceFilePath); |
168 | - if ($maxSize && $fileSize>$maxSize) { |
|
168 | + if ($maxSize && $fileSize > $maxSize) { |
|
169 | 169 | $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
170 | 170 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
171 | 171 | continue; |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | $iCounter = 1; |
204 | 204 | while (true) |
205 | 205 | { |
206 | - $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
207 | - "(" . $iCounter . ")" . "." . |
|
206 | + $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name). |
|
207 | + "(".$iCounter.")".".". |
|
208 | 208 | CKFinder_Connector_Utils_FileSystem::getExtension($name); |
209 | 209 | |
210 | 210 | $destinationFilePath = $sServerDir.$fileName; |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -187,19 +189,16 @@ discard block |
||
187 | 189 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
188 | 190 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
189 | 191 | continue; |
190 | - } |
|
191 | - else { |
|
192 | + } else { |
|
192 | 193 | if (!@rename($sourceFilePath, $destinationFilePath)) { |
193 | 194 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
194 | 195 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
195 | 196 | continue; |
196 | - } |
|
197 | - else { |
|
197 | + } else { |
|
198 | 198 | $moved++; |
199 | 199 | } |
200 | 200 | } |
201 | - } |
|
202 | - else if (strpos($options, "autorename") !== false) { |
|
201 | + } else if (strpos($options, "autorename") !== false) { |
|
203 | 202 | $iCounter = 1; |
204 | 203 | while (true) |
205 | 204 | { |
@@ -210,8 +209,7 @@ discard block |
||
210 | 209 | $destinationFilePath = $sServerDir.$fileName; |
211 | 210 | if (!file_exists($destinationFilePath)) { |
212 | 211 | break; |
213 | - } |
|
214 | - else { |
|
212 | + } else { |
|
215 | 213 | $iCounter++; |
216 | 214 | } |
217 | 215 | } |
@@ -219,24 +217,20 @@ discard block |
||
219 | 217 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
220 | 218 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
221 | 219 | continue; |
222 | - } |
|
223 | - else { |
|
220 | + } else { |
|
224 | 221 | $moved++; |
225 | 222 | } |
226 | - } |
|
227 | - else { |
|
223 | + } else { |
|
228 | 224 | $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
229 | 225 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
230 | 226 | continue; |
231 | 227 | } |
232 | - } |
|
233 | - else { |
|
228 | + } else { |
|
234 | 229 | if (!@rename($sourceFilePath, $destinationFilePath)) { |
235 | 230 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
236 | 231 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
237 | 232 | continue; |
238 | - } |
|
239 | - else { |
|
233 | + } else { |
|
240 | 234 | $moved++; |
241 | 235 | } |
242 | 236 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * Get "forceAscii" value |
233 | 233 | * |
234 | 234 | * @access public |
235 | - * @return array |
|
235 | + * @return boolean |
|
236 | 236 | */ |
237 | 237 | public function forceAscii() |
238 | 238 | { |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * Get regular expression to hide folders |
244 | 244 | * |
245 | 245 | * @access public |
246 | - * @return array |
|
246 | + * @return string |
|
247 | 247 | */ |
248 | 248 | public function getHideFoldersRegex() |
249 | 249 | { |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * Get regular expression to hide files |
270 | 270 | * |
271 | 271 | * @access public |
272 | - * @return array |
|
272 | + * @return string |
|
273 | 273 | */ |
274 | 274 | public function getHideFilesRegex() |
275 | 275 | { |
@@ -46,491 +46,491 @@ |
||
46 | 46 | */ |
47 | 47 | class CKFinder_Connector_Core_Config |
48 | 48 | { |
49 | - /** |
|
50 | - * Is CKFinder enabled |
|
51 | - * |
|
52 | - * @var boolean |
|
53 | - * @access private |
|
54 | - */ |
|
55 | - private $_isEnabled = false; |
|
56 | - /** |
|
49 | + /** |
|
50 | + * Is CKFinder enabled |
|
51 | + * |
|
52 | + * @var boolean |
|
53 | + * @access private |
|
54 | + */ |
|
55 | + private $_isEnabled = false; |
|
56 | + /** |
|
57 | 57 | * License Name |
58 | 58 | * |
59 | 59 | * @var string |
60 | 60 | * @access private |
61 | 61 | */ |
62 | - private $_licenseName = ""; |
|
63 | - /** |
|
64 | - * License Key |
|
65 | - * |
|
66 | - * @var string |
|
67 | - * @access private |
|
68 | - */ |
|
69 | - private $_licenseKey = ""; |
|
70 | - /** |
|
71 | - * Role session variable name |
|
72 | - * |
|
73 | - * @var string |
|
74 | - * @access private |
|
75 | - */ |
|
76 | - private $_roleSessionVar = "CKFinder_UserRole"; |
|
77 | - /** |
|
78 | - * Access Control Configuration |
|
79 | - * |
|
80 | - * @var CKFinder_Connector_Core_AccessControlConfig |
|
81 | - * @access private |
|
82 | - */ |
|
83 | - private $_accessControlConfigCache; |
|
84 | - /** |
|
85 | - * ResourceType config cache |
|
86 | - * |
|
87 | - * @var array |
|
88 | - * @access private |
|
89 | - */ |
|
90 | - private $_resourceTypeConfigCache = array(); |
|
91 | - /** |
|
92 | - * Thumbnails config cache |
|
93 | - * |
|
94 | - * @var CKFinder_Connector_Core_ThumbnailsConfig |
|
95 | - * @access private |
|
96 | - */ |
|
97 | - private $_thumbnailsConfigCache; |
|
98 | - /** |
|
99 | - * Images config cache |
|
100 | - * |
|
101 | - * @var CKFinder_Connector_Core_ImagesConfig |
|
102 | - * @access private |
|
103 | - */ |
|
104 | - private $_imagesConfigCache; |
|
105 | - /** |
|
106 | - * Array with default resource types names |
|
107 | - * |
|
108 | - * @access private |
|
109 | - * @var array |
|
110 | - */ |
|
111 | - private $_defaultResourceTypes = array(); |
|
112 | - /** |
|
113 | - * Filesystem encoding |
|
114 | - * |
|
115 | - * @var string |
|
116 | - * @access private |
|
117 | - */ |
|
118 | - private $_filesystemEncoding; |
|
119 | - /** |
|
120 | - * Check double extension |
|
121 | - * |
|
122 | - * @var boolean |
|
123 | - * @access private |
|
124 | - */ |
|
125 | - private $_checkDoubleExtension = true; |
|
126 | - /** |
|
127 | - * If set to true, validate image size |
|
128 | - * |
|
129 | - * @var boolean |
|
130 | - * @access private |
|
131 | - */ |
|
132 | - private $_secureImageUploads = true; |
|
133 | - /** |
|
134 | - * Check file size after scaling images (applies to images only) |
|
135 | - * |
|
136 | - * @var boolean |
|
137 | - */ |
|
138 | - private $_checkSizeAfterScaling = true; |
|
139 | - /** |
|
140 | - * For security, HTML is allowed in the first Kb of data for files having the following extensions only |
|
141 | - * |
|
142 | - * @var array |
|
143 | - * @access private |
|
144 | - */ |
|
145 | - private $_htmlExtensions = array('html', 'htm', 'xml', 'xsd', 'txt', 'js'); |
|
146 | - /** |
|
147 | - * Chmod files after upload to the following permission |
|
148 | - * |
|
149 | - * @var integer |
|
150 | - * @access private |
|
151 | - */ |
|
152 | - private $_chmodFiles = 0777; |
|
153 | - /** |
|
154 | - * Chmod directories after creation |
|
155 | - * |
|
156 | - * @var integer |
|
157 | - * @access private |
|
158 | - */ |
|
159 | - private $_chmodFolders = 0755; |
|
160 | - /** |
|
161 | - * Hide folders |
|
162 | - * |
|
163 | - * @var array |
|
164 | - * @access private |
|
165 | - */ |
|
166 | - private $_hideFolders = array(".svn", "CVS"); |
|
167 | - /** |
|
168 | - * Hide files |
|
169 | - * |
|
170 | - * @var integer |
|
171 | - * @access private |
|
172 | - */ |
|
173 | - private $_hideFiles = array(".*"); |
|
174 | - /** |
|
175 | - * If set to true, force ASCII names |
|
176 | - * |
|
177 | - * @var boolean |
|
178 | - * @access private |
|
179 | - */ |
|
180 | - private $_forceAscii = false; |
|
181 | - |
|
182 | - function __construct() |
|
183 | - { |
|
184 | - $this->loadValues(); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
62 | + private $_licenseName = ""; |
|
63 | + /** |
|
64 | + * License Key |
|
65 | + * |
|
66 | + * @var string |
|
67 | + * @access private |
|
68 | + */ |
|
69 | + private $_licenseKey = ""; |
|
70 | + /** |
|
71 | + * Role session variable name |
|
72 | + * |
|
73 | + * @var string |
|
74 | + * @access private |
|
75 | + */ |
|
76 | + private $_roleSessionVar = "CKFinder_UserRole"; |
|
77 | + /** |
|
78 | + * Access Control Configuration |
|
79 | + * |
|
80 | + * @var CKFinder_Connector_Core_AccessControlConfig |
|
81 | + * @access private |
|
82 | + */ |
|
83 | + private $_accessControlConfigCache; |
|
84 | + /** |
|
85 | + * ResourceType config cache |
|
86 | + * |
|
87 | + * @var array |
|
88 | + * @access private |
|
89 | + */ |
|
90 | + private $_resourceTypeConfigCache = array(); |
|
91 | + /** |
|
92 | + * Thumbnails config cache |
|
93 | + * |
|
94 | + * @var CKFinder_Connector_Core_ThumbnailsConfig |
|
95 | + * @access private |
|
96 | + */ |
|
97 | + private $_thumbnailsConfigCache; |
|
98 | + /** |
|
99 | + * Images config cache |
|
100 | + * |
|
101 | + * @var CKFinder_Connector_Core_ImagesConfig |
|
102 | + * @access private |
|
103 | + */ |
|
104 | + private $_imagesConfigCache; |
|
105 | + /** |
|
106 | + * Array with default resource types names |
|
107 | + * |
|
108 | + * @access private |
|
109 | + * @var array |
|
110 | + */ |
|
111 | + private $_defaultResourceTypes = array(); |
|
112 | + /** |
|
113 | + * Filesystem encoding |
|
114 | + * |
|
115 | + * @var string |
|
116 | + * @access private |
|
117 | + */ |
|
118 | + private $_filesystemEncoding; |
|
119 | + /** |
|
120 | + * Check double extension |
|
121 | + * |
|
122 | + * @var boolean |
|
123 | + * @access private |
|
124 | + */ |
|
125 | + private $_checkDoubleExtension = true; |
|
126 | + /** |
|
127 | + * If set to true, validate image size |
|
128 | + * |
|
129 | + * @var boolean |
|
130 | + * @access private |
|
131 | + */ |
|
132 | + private $_secureImageUploads = true; |
|
133 | + /** |
|
134 | + * Check file size after scaling images (applies to images only) |
|
135 | + * |
|
136 | + * @var boolean |
|
137 | + */ |
|
138 | + private $_checkSizeAfterScaling = true; |
|
139 | + /** |
|
140 | + * For security, HTML is allowed in the first Kb of data for files having the following extensions only |
|
141 | + * |
|
142 | + * @var array |
|
143 | + * @access private |
|
144 | + */ |
|
145 | + private $_htmlExtensions = array('html', 'htm', 'xml', 'xsd', 'txt', 'js'); |
|
146 | + /** |
|
147 | + * Chmod files after upload to the following permission |
|
148 | + * |
|
149 | + * @var integer |
|
150 | + * @access private |
|
151 | + */ |
|
152 | + private $_chmodFiles = 0777; |
|
153 | + /** |
|
154 | + * Chmod directories after creation |
|
155 | + * |
|
156 | + * @var integer |
|
157 | + * @access private |
|
158 | + */ |
|
159 | + private $_chmodFolders = 0755; |
|
160 | + /** |
|
161 | + * Hide folders |
|
162 | + * |
|
163 | + * @var array |
|
164 | + * @access private |
|
165 | + */ |
|
166 | + private $_hideFolders = array(".svn", "CVS"); |
|
167 | + /** |
|
168 | + * Hide files |
|
169 | + * |
|
170 | + * @var integer |
|
171 | + * @access private |
|
172 | + */ |
|
173 | + private $_hideFiles = array(".*"); |
|
174 | + /** |
|
175 | + * If set to true, force ASCII names |
|
176 | + * |
|
177 | + * @var boolean |
|
178 | + * @access private |
|
179 | + */ |
|
180 | + private $_forceAscii = false; |
|
181 | + |
|
182 | + function __construct() |
|
183 | + { |
|
184 | + $this->loadValues(); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | 188 | * Get file system encoding, returns null if encoding is not set |
189 | 189 | * |
190 | 190 | * @access public |
191 | 191 | * @return string |
192 | 192 | */ |
193 | - public function getFilesystemEncoding() |
|
194 | - { |
|
195 | - return $this->_filesystemEncoding; |
|
196 | - } |
|
193 | + public function getFilesystemEncoding() |
|
194 | + { |
|
195 | + return $this->_filesystemEncoding; |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
198 | + /** |
|
199 | 199 | * Get "secureImageUploads" value |
200 | 200 | * |
201 | 201 | * @access public |
202 | 202 | * @return boolean |
203 | 203 | */ |
204 | - public function getSecureImageUploads() |
|
205 | - { |
|
206 | - return $this->_secureImageUploads; |
|
207 | - } |
|
204 | + public function getSecureImageUploads() |
|
205 | + { |
|
206 | + return $this->_secureImageUploads; |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
209 | + /** |
|
210 | 210 | * Get "checkSizeAfterScaling" value |
211 | 211 | * |
212 | 212 | * @access public |
213 | 213 | * @return boolean |
214 | 214 | */ |
215 | - public function checkSizeAfterScaling() |
|
216 | - { |
|
217 | - return $this->_checkSizeAfterScaling; |
|
218 | - } |
|
215 | + public function checkSizeAfterScaling() |
|
216 | + { |
|
217 | + return $this->_checkSizeAfterScaling; |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
220 | + /** |
|
221 | 221 | * Get "htmlExtensions" value |
222 | 222 | * |
223 | 223 | * @access public |
224 | 224 | * @return array |
225 | 225 | */ |
226 | - public function getHtmlExtensions() |
|
227 | - { |
|
228 | - return $this->_htmlExtensions; |
|
229 | - } |
|
226 | + public function getHtmlExtensions() |
|
227 | + { |
|
228 | + return $this->_htmlExtensions; |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
231 | + /** |
|
232 | 232 | * Get "forceAscii" value |
233 | 233 | * |
234 | 234 | * @access public |
235 | 235 | * @return array |
236 | 236 | */ |
237 | - public function forceAscii() |
|
238 | - { |
|
239 | - return $this->_forceAscii; |
|
240 | - } |
|
237 | + public function forceAscii() |
|
238 | + { |
|
239 | + return $this->_forceAscii; |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
242 | + /** |
|
243 | 243 | * Get regular expression to hide folders |
244 | 244 | * |
245 | 245 | * @access public |
246 | 246 | * @return array |
247 | 247 | */ |
248 | - public function getHideFoldersRegex() |
|
249 | - { |
|
250 | - static $folderRegex; |
|
251 | - |
|
252 | - if (!isset($folderRegex)) { |
|
253 | - if (is_array($this->_hideFolders) && $this->_hideFolders) { |
|
254 | - $folderRegex = join("|", $this->_hideFolders); |
|
255 | - $folderRegex = strtr($folderRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__")); |
|
256 | - $folderRegex = preg_quote($folderRegex, "/"); |
|
257 | - $folderRegex = strtr($folderRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|")); |
|
258 | - $folderRegex = "/^(?:" . $folderRegex . ")$/uim"; |
|
259 | - } |
|
260 | - else { |
|
261 | - $folderRegex = ""; |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - return $folderRegex; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
248 | + public function getHideFoldersRegex() |
|
249 | + { |
|
250 | + static $folderRegex; |
|
251 | + |
|
252 | + if (!isset($folderRegex)) { |
|
253 | + if (is_array($this->_hideFolders) && $this->_hideFolders) { |
|
254 | + $folderRegex = join("|", $this->_hideFolders); |
|
255 | + $folderRegex = strtr($folderRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__")); |
|
256 | + $folderRegex = preg_quote($folderRegex, "/"); |
|
257 | + $folderRegex = strtr($folderRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|")); |
|
258 | + $folderRegex = "/^(?:" . $folderRegex . ")$/uim"; |
|
259 | + } |
|
260 | + else { |
|
261 | + $folderRegex = ""; |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + return $folderRegex; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | 269 | * Get regular expression to hide files |
270 | 270 | * |
271 | 271 | * @access public |
272 | 272 | * @return array |
273 | 273 | */ |
274 | - public function getHideFilesRegex() |
|
275 | - { |
|
276 | - static $fileRegex; |
|
277 | - |
|
278 | - if (!isset($fileRegex)) { |
|
279 | - if (is_array($this->_hideFiles) && $this->_hideFiles) { |
|
280 | - $fileRegex = join("|", $this->_hideFiles); |
|
281 | - $fileRegex = strtr($fileRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__")); |
|
282 | - $fileRegex = preg_quote($fileRegex, "/"); |
|
283 | - $fileRegex = strtr($fileRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|")); |
|
284 | - $fileRegex = "/^(?:" . $fileRegex . ")$/uim"; |
|
285 | - } |
|
286 | - else { |
|
287 | - $fileRegex = ""; |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - return $fileRegex; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
274 | + public function getHideFilesRegex() |
|
275 | + { |
|
276 | + static $fileRegex; |
|
277 | + |
|
278 | + if (!isset($fileRegex)) { |
|
279 | + if (is_array($this->_hideFiles) && $this->_hideFiles) { |
|
280 | + $fileRegex = join("|", $this->_hideFiles); |
|
281 | + $fileRegex = strtr($fileRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__")); |
|
282 | + $fileRegex = preg_quote($fileRegex, "/"); |
|
283 | + $fileRegex = strtr($fileRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|")); |
|
284 | + $fileRegex = "/^(?:" . $fileRegex . ")$/uim"; |
|
285 | + } |
|
286 | + else { |
|
287 | + $fileRegex = ""; |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + return $fileRegex; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | 295 | * Get "Check double extension" value |
296 | 296 | * |
297 | 297 | * @access public |
298 | 298 | * @return boolean |
299 | 299 | */ |
300 | - public function getCheckDoubleExtension() |
|
301 | - { |
|
302 | - return $this->_checkDoubleExtension; |
|
303 | - } |
|
300 | + public function getCheckDoubleExtension() |
|
301 | + { |
|
302 | + return $this->_checkDoubleExtension; |
|
303 | + } |
|
304 | 304 | |
305 | - /** |
|
305 | + /** |
|
306 | 306 | * Get default resource types |
307 | 307 | * |
308 | 308 | * @access public |
309 | 309 | * @return array() |
310 | 310 | */ |
311 | - public function getDefaultResourceTypes() |
|
312 | - { |
|
313 | - return $this->_defaultResourceTypes; |
|
314 | - } |
|
311 | + public function getDefaultResourceTypes() |
|
312 | + { |
|
313 | + return $this->_defaultResourceTypes; |
|
314 | + } |
|
315 | 315 | |
316 | - /** |
|
316 | + /** |
|
317 | 317 | * Is CKFinder enabled |
318 | 318 | * |
319 | 319 | * @access public |
320 | 320 | * @return boolean |
321 | 321 | */ |
322 | - public function getIsEnabled() |
|
323 | - { |
|
324 | - return $this->_isEnabled; |
|
325 | - } |
|
322 | + public function getIsEnabled() |
|
323 | + { |
|
324 | + return $this->_isEnabled; |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
327 | + /** |
|
328 | 328 | * Get license key |
329 | 329 | * |
330 | 330 | * @access public |
331 | 331 | * @return string |
332 | 332 | */ |
333 | - public function getLicenseKey() |
|
334 | - { |
|
335 | - return $this->_licenseKey; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Get license name |
|
340 | - * |
|
341 | - * @access public |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - public function getLicenseName() |
|
345 | - { |
|
346 | - return $this->_licenseName; |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Get chmod settings for uploaded files |
|
351 | - * |
|
352 | - * @access public |
|
353 | - * @return integer |
|
354 | - */ |
|
355 | - public function getChmodFiles() |
|
356 | - { |
|
357 | - return $this->_chmodFiles; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Get chmod settings for created directories |
|
362 | - * |
|
363 | - * @access public |
|
364 | - * @return integer |
|
365 | - */ |
|
366 | - public function getChmodFolders() |
|
367 | - { |
|
368 | - return $this->_chmodFolders; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
333 | + public function getLicenseKey() |
|
334 | + { |
|
335 | + return $this->_licenseKey; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Get license name |
|
340 | + * |
|
341 | + * @access public |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + public function getLicenseName() |
|
345 | + { |
|
346 | + return $this->_licenseName; |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Get chmod settings for uploaded files |
|
351 | + * |
|
352 | + * @access public |
|
353 | + * @return integer |
|
354 | + */ |
|
355 | + public function getChmodFiles() |
|
356 | + { |
|
357 | + return $this->_chmodFiles; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Get chmod settings for created directories |
|
362 | + * |
|
363 | + * @access public |
|
364 | + * @return integer |
|
365 | + */ |
|
366 | + public function getChmodFolders() |
|
367 | + { |
|
368 | + return $this->_chmodFolders; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | 372 | * Get role sesion variable name |
373 | 373 | * |
374 | 374 | * @access public |
375 | 375 | * @return string |
376 | 376 | */ |
377 | - public function getRoleSessionVar() |
|
378 | - { |
|
379 | - return $this->_roleSessionVar; |
|
380 | - } |
|
377 | + public function getRoleSessionVar() |
|
378 | + { |
|
379 | + return $this->_roleSessionVar; |
|
380 | + } |
|
381 | 381 | |
382 | - /** |
|
382 | + /** |
|
383 | 383 | * Get resourceTypeName config |
384 | 384 | * |
385 | 385 | * @param string $resourceTypeName |
386 | 386 | * @return CKFinder_Connector_Core_ResourceTypeConfig|null |
387 | 387 | * @access public |
388 | 388 | */ |
389 | - public function &getResourceTypeConfig($resourceTypeName) |
|
390 | - { |
|
391 | - $_null = null; |
|
392 | - |
|
393 | - if (isset($this->_resourceTypeConfigCache[$resourceTypeName])) { |
|
394 | - return $this->_resourceTypeConfigCache[$resourceTypeName]; |
|
395 | - } |
|
396 | - |
|
397 | - if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) { |
|
398 | - return $_null; |
|
399 | - } |
|
400 | - |
|
401 | - reset($GLOBALS['config']['ResourceType']); |
|
402 | - while (list($_key,$_resourceTypeNode) = each($GLOBALS['config']['ResourceType'])) { |
|
403 | - if ($_resourceTypeNode['name'] === $resourceTypeName) { |
|
404 | - $this->_resourceTypeConfigCache[$resourceTypeName] = new CKFinder_Connector_Core_ResourceTypeConfig($_resourceTypeNode); |
|
405 | - |
|
406 | - return $this->_resourceTypeConfigCache[$resourceTypeName]; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - return $_null; |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * Get thumbnails config |
|
415 | - * |
|
416 | - * @access public |
|
417 | - * @return CKFinder_Connector_Core_ThumbnailsConfig |
|
418 | - */ |
|
419 | - public function &getThumbnailsConfig() |
|
420 | - { |
|
421 | - if (!isset($this->_thumbnailsConfigCache)) { |
|
422 | - $this->_thumbnailsConfigCache = new CKFinder_Connector_Core_ThumbnailsConfig(isset($GLOBALS['config']['Thumbnails']) ? $GLOBALS['config']['Thumbnails'] : array()); |
|
423 | - } |
|
424 | - |
|
425 | - return $this->_thumbnailsConfigCache; |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Get images config |
|
430 | - * |
|
431 | - * @access public |
|
432 | - * @return CKFinder_Connector_Core_ImagesConfig |
|
433 | - */ |
|
434 | - public function &getImagesConfig() |
|
435 | - { |
|
436 | - if (!isset($this->_imagesConfigCache)) { |
|
437 | - $this->_imagesConfigCache = new CKFinder_Connector_Core_ImagesConfig(isset($GLOBALS['config']['Images']) ? $GLOBALS['config']['Images'] : array()); |
|
438 | - } |
|
439 | - |
|
440 | - return $this->_imagesConfigCache; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Get access control config |
|
445 | - * |
|
446 | - * @access public |
|
447 | - * @return CKFinder_Connector_Core_AccessControlConfig |
|
448 | - */ |
|
449 | - public function &getAccessControlConfig() |
|
450 | - { |
|
451 | - if (!isset($this->_accessControlConfigCache)) { |
|
452 | - $this->_accessControlConfigCache = new CKFinder_Connector_Core_AccessControlConfig(isset($GLOBALS['config']['AccessControl']) ? $GLOBALS['config']['AccessControl'] : array()); |
|
453 | - } |
|
454 | - |
|
455 | - return $this->_accessControlConfigCache; |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * Load values from config |
|
460 | - * |
|
461 | - * @access private |
|
462 | - */ |
|
463 | - private function loadValues() |
|
464 | - { |
|
465 | - if (function_exists('CheckAuthentication')) { |
|
466 | - $this->_isEnabled = CheckAuthentication(); |
|
467 | - } |
|
468 | - if (isset($GLOBALS['config']['LicenseName'])) { |
|
469 | - $this->_licenseName = (string)$GLOBALS['config']['LicenseName']; |
|
470 | - } |
|
471 | - if (isset($GLOBALS['config']['LicenseKey'])) { |
|
472 | - $this->_licenseKey = (string)$GLOBALS['config']['LicenseKey']; |
|
473 | - } |
|
474 | - if (isset($GLOBALS['config']['FilesystemEncoding'])) { |
|
475 | - $this->_filesystemEncoding = (string)$GLOBALS['config']['FilesystemEncoding']; |
|
476 | - } |
|
477 | - if (isset($GLOBALS['config']['RoleSessionVar'])) { |
|
478 | - $this->_roleSessionVar = (string)$GLOBALS['config']['RoleSessionVar']; |
|
479 | - } |
|
480 | - if (isset($GLOBALS['config']['CheckDoubleExtension'])) { |
|
481 | - $this->_checkDoubleExtension = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckDoubleExtension']); |
|
482 | - } |
|
483 | - if (isset($GLOBALS['config']['SecureImageUploads'])) { |
|
484 | - $this->_secureImageUploads = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['SecureImageUploads']); |
|
485 | - } |
|
486 | - if (isset($GLOBALS['config']['CheckSizeAfterScaling'])) { |
|
487 | - $this->_checkSizeAfterScaling = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckSizeAfterScaling']); |
|
488 | - } |
|
489 | - if (isset($GLOBALS['config']['ForceAscii'])) { |
|
490 | - $this->_forceAscii = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['ForceAscii']); |
|
491 | - } |
|
492 | - if (isset($GLOBALS['config']['HtmlExtensions'])) { |
|
493 | - $this->_htmlExtensions = (array)$GLOBALS['config']['HtmlExtensions']; |
|
494 | - } |
|
495 | - if (isset($GLOBALS['config']['HideFolders'])) { |
|
496 | - $this->_hideFolders = (array)$GLOBALS['config']['HideFolders']; |
|
497 | - } |
|
498 | - if (isset($GLOBALS['config']['HideFiles'])) { |
|
499 | - $this->_hideFiles = (array)$GLOBALS['config']['HideFiles']; |
|
500 | - } |
|
501 | - if (isset($GLOBALS['config']['ChmodFiles'])) { |
|
502 | - $this->_chmodFiles = $GLOBALS['config']['ChmodFiles']; |
|
503 | - } |
|
504 | - if (isset($GLOBALS['config']['ChmodFolders'])) { |
|
505 | - $this->_chmodFolders = $GLOBALS['config']['ChmodFolders']; |
|
506 | - } |
|
507 | - if (isset($GLOBALS['config']['DefaultResourceTypes'])) { |
|
508 | - $_defaultResourceTypes = (string)$GLOBALS['config']['DefaultResourceTypes']; |
|
509 | - if (strlen($_defaultResourceTypes)) { |
|
510 | - $this->_defaultResourceTypes = explode(",", $_defaultResourceTypes); |
|
511 | - } |
|
512 | - } |
|
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * Get all resource type names defined in config |
|
517 | - * |
|
518 | - * @return array |
|
519 | - * @access public |
|
520 | - */ |
|
521 | - public function getResourceTypeNames() |
|
522 | - { |
|
523 | - if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) { |
|
524 | - return array(); |
|
525 | - } |
|
526 | - |
|
527 | - $_names = array(); |
|
528 | - foreach ($GLOBALS['config']['ResourceType'] as $key => $_resourceType) { |
|
529 | - if (isset($_resourceType['name'])) { |
|
530 | - $_names[] = (string)$_resourceType['name']; |
|
531 | - } |
|
532 | - } |
|
533 | - |
|
534 | - return $_names; |
|
535 | - } |
|
389 | + public function &getResourceTypeConfig($resourceTypeName) |
|
390 | + { |
|
391 | + $_null = null; |
|
392 | + |
|
393 | + if (isset($this->_resourceTypeConfigCache[$resourceTypeName])) { |
|
394 | + return $this->_resourceTypeConfigCache[$resourceTypeName]; |
|
395 | + } |
|
396 | + |
|
397 | + if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) { |
|
398 | + return $_null; |
|
399 | + } |
|
400 | + |
|
401 | + reset($GLOBALS['config']['ResourceType']); |
|
402 | + while (list($_key,$_resourceTypeNode) = each($GLOBALS['config']['ResourceType'])) { |
|
403 | + if ($_resourceTypeNode['name'] === $resourceTypeName) { |
|
404 | + $this->_resourceTypeConfigCache[$resourceTypeName] = new CKFinder_Connector_Core_ResourceTypeConfig($_resourceTypeNode); |
|
405 | + |
|
406 | + return $this->_resourceTypeConfigCache[$resourceTypeName]; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + return $_null; |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * Get thumbnails config |
|
415 | + * |
|
416 | + * @access public |
|
417 | + * @return CKFinder_Connector_Core_ThumbnailsConfig |
|
418 | + */ |
|
419 | + public function &getThumbnailsConfig() |
|
420 | + { |
|
421 | + if (!isset($this->_thumbnailsConfigCache)) { |
|
422 | + $this->_thumbnailsConfigCache = new CKFinder_Connector_Core_ThumbnailsConfig(isset($GLOBALS['config']['Thumbnails']) ? $GLOBALS['config']['Thumbnails'] : array()); |
|
423 | + } |
|
424 | + |
|
425 | + return $this->_thumbnailsConfigCache; |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Get images config |
|
430 | + * |
|
431 | + * @access public |
|
432 | + * @return CKFinder_Connector_Core_ImagesConfig |
|
433 | + */ |
|
434 | + public function &getImagesConfig() |
|
435 | + { |
|
436 | + if (!isset($this->_imagesConfigCache)) { |
|
437 | + $this->_imagesConfigCache = new CKFinder_Connector_Core_ImagesConfig(isset($GLOBALS['config']['Images']) ? $GLOBALS['config']['Images'] : array()); |
|
438 | + } |
|
439 | + |
|
440 | + return $this->_imagesConfigCache; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Get access control config |
|
445 | + * |
|
446 | + * @access public |
|
447 | + * @return CKFinder_Connector_Core_AccessControlConfig |
|
448 | + */ |
|
449 | + public function &getAccessControlConfig() |
|
450 | + { |
|
451 | + if (!isset($this->_accessControlConfigCache)) { |
|
452 | + $this->_accessControlConfigCache = new CKFinder_Connector_Core_AccessControlConfig(isset($GLOBALS['config']['AccessControl']) ? $GLOBALS['config']['AccessControl'] : array()); |
|
453 | + } |
|
454 | + |
|
455 | + return $this->_accessControlConfigCache; |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * Load values from config |
|
460 | + * |
|
461 | + * @access private |
|
462 | + */ |
|
463 | + private function loadValues() |
|
464 | + { |
|
465 | + if (function_exists('CheckAuthentication')) { |
|
466 | + $this->_isEnabled = CheckAuthentication(); |
|
467 | + } |
|
468 | + if (isset($GLOBALS['config']['LicenseName'])) { |
|
469 | + $this->_licenseName = (string)$GLOBALS['config']['LicenseName']; |
|
470 | + } |
|
471 | + if (isset($GLOBALS['config']['LicenseKey'])) { |
|
472 | + $this->_licenseKey = (string)$GLOBALS['config']['LicenseKey']; |
|
473 | + } |
|
474 | + if (isset($GLOBALS['config']['FilesystemEncoding'])) { |
|
475 | + $this->_filesystemEncoding = (string)$GLOBALS['config']['FilesystemEncoding']; |
|
476 | + } |
|
477 | + if (isset($GLOBALS['config']['RoleSessionVar'])) { |
|
478 | + $this->_roleSessionVar = (string)$GLOBALS['config']['RoleSessionVar']; |
|
479 | + } |
|
480 | + if (isset($GLOBALS['config']['CheckDoubleExtension'])) { |
|
481 | + $this->_checkDoubleExtension = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckDoubleExtension']); |
|
482 | + } |
|
483 | + if (isset($GLOBALS['config']['SecureImageUploads'])) { |
|
484 | + $this->_secureImageUploads = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['SecureImageUploads']); |
|
485 | + } |
|
486 | + if (isset($GLOBALS['config']['CheckSizeAfterScaling'])) { |
|
487 | + $this->_checkSizeAfterScaling = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckSizeAfterScaling']); |
|
488 | + } |
|
489 | + if (isset($GLOBALS['config']['ForceAscii'])) { |
|
490 | + $this->_forceAscii = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['ForceAscii']); |
|
491 | + } |
|
492 | + if (isset($GLOBALS['config']['HtmlExtensions'])) { |
|
493 | + $this->_htmlExtensions = (array)$GLOBALS['config']['HtmlExtensions']; |
|
494 | + } |
|
495 | + if (isset($GLOBALS['config']['HideFolders'])) { |
|
496 | + $this->_hideFolders = (array)$GLOBALS['config']['HideFolders']; |
|
497 | + } |
|
498 | + if (isset($GLOBALS['config']['HideFiles'])) { |
|
499 | + $this->_hideFiles = (array)$GLOBALS['config']['HideFiles']; |
|
500 | + } |
|
501 | + if (isset($GLOBALS['config']['ChmodFiles'])) { |
|
502 | + $this->_chmodFiles = $GLOBALS['config']['ChmodFiles']; |
|
503 | + } |
|
504 | + if (isset($GLOBALS['config']['ChmodFolders'])) { |
|
505 | + $this->_chmodFolders = $GLOBALS['config']['ChmodFolders']; |
|
506 | + } |
|
507 | + if (isset($GLOBALS['config']['DefaultResourceTypes'])) { |
|
508 | + $_defaultResourceTypes = (string)$GLOBALS['config']['DefaultResourceTypes']; |
|
509 | + if (strlen($_defaultResourceTypes)) { |
|
510 | + $this->_defaultResourceTypes = explode(",", $_defaultResourceTypes); |
|
511 | + } |
|
512 | + } |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * Get all resource type names defined in config |
|
517 | + * |
|
518 | + * @return array |
|
519 | + * @access public |
|
520 | + */ |
|
521 | + public function getResourceTypeNames() |
|
522 | + { |
|
523 | + if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) { |
|
524 | + return array(); |
|
525 | + } |
|
526 | + |
|
527 | + $_names = array(); |
|
528 | + foreach ($GLOBALS['config']['ResourceType'] as $key => $_resourceType) { |
|
529 | + if (isset($_resourceType['name'])) { |
|
530 | + $_names[] = (string)$_resourceType['name']; |
|
531 | + } |
|
532 | + } |
|
533 | + |
|
534 | + return $_names; |
|
535 | + } |
|
536 | 536 | } |
@@ -21,19 +21,19 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include access control config class |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/AccessControlConfig.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/Core/AccessControlConfig.php"; |
|
25 | 25 | /** |
26 | 26 | * Include resource type config class |
27 | 27 | */ |
28 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/ResourceTypeConfig.php"; |
|
28 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/Core/ResourceTypeConfig.php"; |
|
29 | 29 | /** |
30 | 30 | * Include thumbnails config class |
31 | 31 | */ |
32 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/ThumbnailsConfig.php"; |
|
32 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/Core/ThumbnailsConfig.php"; |
|
33 | 33 | /** |
34 | 34 | * Include images config class |
35 | 35 | */ |
36 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/ImagesConfig.php"; |
|
36 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/Core/ImagesConfig.php"; |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Main config parser |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $folderRegex = strtr($folderRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__")); |
256 | 256 | $folderRegex = preg_quote($folderRegex, "/"); |
257 | 257 | $folderRegex = strtr($folderRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|")); |
258 | - $folderRegex = "/^(?:" . $folderRegex . ")$/uim"; |
|
258 | + $folderRegex = "/^(?:".$folderRegex.")$/uim"; |
|
259 | 259 | } |
260 | 260 | else { |
261 | 261 | $folderRegex = ""; |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | $fileRegex = strtr($fileRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__")); |
282 | 282 | $fileRegex = preg_quote($fileRegex, "/"); |
283 | 283 | $fileRegex = strtr($fileRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|")); |
284 | - $fileRegex = "/^(?:" . $fileRegex . ")$/uim"; |
|
284 | + $fileRegex = "/^(?:".$fileRegex.")$/uim"; |
|
285 | 285 | } |
286 | 286 | else { |
287 | 287 | $fileRegex = ""; |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | } |
400 | 400 | |
401 | 401 | reset($GLOBALS['config']['ResourceType']); |
402 | - while (list($_key,$_resourceTypeNode) = each($GLOBALS['config']['ResourceType'])) { |
|
402 | + while (list($_key, $_resourceTypeNode) = each($GLOBALS['config']['ResourceType'])) { |
|
403 | 403 | if ($_resourceTypeNode['name'] === $resourceTypeName) { |
404 | 404 | $this->_resourceTypeConfigCache[$resourceTypeName] = new CKFinder_Connector_Core_ResourceTypeConfig($_resourceTypeNode); |
405 | 405 |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -256,8 +258,7 @@ discard block |
||
256 | 258 | $folderRegex = preg_quote($folderRegex, "/"); |
257 | 259 | $folderRegex = strtr($folderRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|")); |
258 | 260 | $folderRegex = "/^(?:" . $folderRegex . ")$/uim"; |
259 | - } |
|
260 | - else { |
|
261 | + } else { |
|
261 | 262 | $folderRegex = ""; |
262 | 263 | } |
263 | 264 | } |
@@ -282,8 +283,7 @@ discard block |
||
282 | 283 | $fileRegex = preg_quote($fileRegex, "/"); |
283 | 284 | $fileRegex = strtr($fileRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|")); |
284 | 285 | $fileRegex = "/^(?:" . $fileRegex . ")$/uim"; |
285 | - } |
|
286 | - else { |
|
286 | + } else { |
|
287 | 287 | $fileRegex = ""; |
288 | 288 | } |
289 | 289 | } |
@@ -24,7 +24,6 @@ |
||
24 | 24 | * Run user defined hooks |
25 | 25 | * |
26 | 26 | * @param string $event |
27 | - * @param object $errorHandler |
|
28 | 27 | * @param array $args |
29 | 28 | * @return boolean (true to continue processing, false otherwise) |
30 | 29 | */ |
@@ -20,153 +20,153 @@ |
||
20 | 20 | class CKFinder_Connector_Core_Hooks |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Run user defined hooks |
|
25 | - * |
|
26 | - * @param string $event |
|
27 | - * @param object $errorHandler |
|
28 | - * @param array $args |
|
29 | - * @return boolean (true to continue processing, false otherwise) |
|
30 | - */ |
|
31 | - public static function run($event, $args = array()) |
|
32 | - { |
|
33 | - $config = $GLOBALS['config']; |
|
34 | - if (!isset($config['Hooks'])) { |
|
35 | - return true; |
|
36 | - } |
|
37 | - $hooks =& $config['Hooks']; |
|
23 | + /** |
|
24 | + * Run user defined hooks |
|
25 | + * |
|
26 | + * @param string $event |
|
27 | + * @param object $errorHandler |
|
28 | + * @param array $args |
|
29 | + * @return boolean (true to continue processing, false otherwise) |
|
30 | + */ |
|
31 | + public static function run($event, $args = array()) |
|
32 | + { |
|
33 | + $config = $GLOBALS['config']; |
|
34 | + if (!isset($config['Hooks'])) { |
|
35 | + return true; |
|
36 | + } |
|
37 | + $hooks =& $config['Hooks']; |
|
38 | 38 | |
39 | - if (!is_array($hooks) || !array_key_exists($event, $hooks) || !is_array($hooks[$event])) { |
|
40 | - return true; |
|
41 | - } |
|
39 | + if (!is_array($hooks) || !array_key_exists($event, $hooks) || !is_array($hooks[$event])) { |
|
40 | + return true; |
|
41 | + } |
|
42 | 42 | |
43 | - $errorHandler = $GLOBALS['connector']->getErrorHandler(); |
|
43 | + $errorHandler = $GLOBALS['connector']->getErrorHandler(); |
|
44 | 44 | |
45 | - foreach ($hooks[$event] as $i => $hook) { |
|
45 | + foreach ($hooks[$event] as $i => $hook) { |
|
46 | 46 | |
47 | - $object = NULL; |
|
48 | - $method = NULL; |
|
49 | - $function = NULL; |
|
50 | - $data = NULL; |
|
51 | - $passData = false; |
|
47 | + $object = NULL; |
|
48 | + $method = NULL; |
|
49 | + $function = NULL; |
|
50 | + $data = NULL; |
|
51 | + $passData = false; |
|
52 | 52 | |
53 | - /* $hook can be: a function, an object, an array of $functiontion and $data, |
|
53 | + /* $hook can be: a function, an object, an array of $functiontion and $data, |
|
54 | 54 | * an array of just a function, an array of object and method, or an |
55 | 55 | * array of object, method, and data. |
56 | 56 | */ |
57 | - //function |
|
58 | - if (is_string($hook)) { |
|
59 | - $function = $hook; |
|
60 | - } |
|
61 | - //object |
|
62 | - else if (is_object($hook)) { |
|
63 | - $object = $hooks[$event][$i]; |
|
64 | - $method = "on" . $event; |
|
65 | - } |
|
66 | - //array of... |
|
67 | - else if (is_array($hook)) { |
|
68 | - $count = count($hook); |
|
69 | - if ($count) { |
|
70 | - //...object |
|
71 | - if (is_object($hook[0])) { |
|
72 | - $object = $hooks[$event][$i][0]; |
|
73 | - if ($count < 2) { |
|
74 | - $method = "on" . $event; |
|
75 | - } else { |
|
76 | - //...object and method |
|
77 | - $method = $hook[1]; |
|
78 | - if (count($hook) > 2) { |
|
79 | - //...object, method and data |
|
80 | - $passData = true; |
|
81 | - $data = $hook[2]; |
|
82 | - } |
|
83 | - } |
|
84 | - } |
|
85 | - //...function |
|
86 | - else if (is_string($hook[0])) { |
|
87 | - $function = $hook[0]; |
|
88 | - if ($count > 1) { |
|
89 | - //...function with data |
|
90 | - $passData = true; |
|
91 | - $data = $hook[1]; |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
57 | + //function |
|
58 | + if (is_string($hook)) { |
|
59 | + $function = $hook; |
|
60 | + } |
|
61 | + //object |
|
62 | + else if (is_object($hook)) { |
|
63 | + $object = $hooks[$event][$i]; |
|
64 | + $method = "on" . $event; |
|
65 | + } |
|
66 | + //array of... |
|
67 | + else if (is_array($hook)) { |
|
68 | + $count = count($hook); |
|
69 | + if ($count) { |
|
70 | + //...object |
|
71 | + if (is_object($hook[0])) { |
|
72 | + $object = $hooks[$event][$i][0]; |
|
73 | + if ($count < 2) { |
|
74 | + $method = "on" . $event; |
|
75 | + } else { |
|
76 | + //...object and method |
|
77 | + $method = $hook[1]; |
|
78 | + if (count($hook) > 2) { |
|
79 | + //...object, method and data |
|
80 | + $passData = true; |
|
81 | + $data = $hook[2]; |
|
82 | + } |
|
83 | + } |
|
84 | + } |
|
85 | + //...function |
|
86 | + else if (is_string($hook[0])) { |
|
87 | + $function = $hook[0]; |
|
88 | + if ($count > 1) { |
|
89 | + //...function with data |
|
90 | + $passData = true; |
|
91 | + $data = $hook[1]; |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - /* If defined, add data to the arguments array */ |
|
98 | - if ($passData) { |
|
99 | - $args = array_merge(array($data), $args); |
|
100 | - } |
|
97 | + /* If defined, add data to the arguments array */ |
|
98 | + if ($passData) { |
|
99 | + $args = array_merge(array($data), $args); |
|
100 | + } |
|
101 | 101 | |
102 | - if (isset($object)) { |
|
103 | - $callback = array($object, $method); |
|
104 | - } |
|
105 | - else if (false !== ($pos = strpos($function, '::'))) { |
|
106 | - $callback = array(substr($function, 0, $pos), substr($function, $pos + 2)); |
|
107 | - } |
|
108 | - else { |
|
109 | - $callback = $function; |
|
110 | - } |
|
102 | + if (isset($object)) { |
|
103 | + $callback = array($object, $method); |
|
104 | + } |
|
105 | + else if (false !== ($pos = strpos($function, '::'))) { |
|
106 | + $callback = array(substr($function, 0, $pos), substr($function, $pos + 2)); |
|
107 | + } |
|
108 | + else { |
|
109 | + $callback = $function; |
|
110 | + } |
|
111 | 111 | |
112 | - if (is_callable($callback)) { |
|
113 | - $ret = call_user_func_array($callback, $args); |
|
114 | - } |
|
115 | - else { |
|
116 | - $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback); |
|
117 | - $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, |
|
118 | - "CKFinder failed to call a hook: " . $functionName); |
|
119 | - return false; |
|
120 | - } |
|
112 | + if (is_callable($callback)) { |
|
113 | + $ret = call_user_func_array($callback, $args); |
|
114 | + } |
|
115 | + else { |
|
116 | + $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback); |
|
117 | + $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, |
|
118 | + "CKFinder failed to call a hook: " . $functionName); |
|
119 | + return false; |
|
120 | + } |
|
121 | 121 | |
122 | - //String return is a custom error |
|
123 | - if (is_string($ret)) { |
|
124 | - $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, $ret); |
|
125 | - return false; |
|
126 | - } |
|
127 | - //hook returned an error code, user error codes start from 50000 |
|
128 | - //error codes are important because this way it is possible to create multilanguage extensions |
|
129 | - //recomendation: create a function that calculates the error codes starting number |
|
130 | - //for an extension, a pool of 100 error codes for each extension should be safe enough |
|
131 | - else if (is_int($ret)) { |
|
132 | - $errorHandler->throwError($ret); |
|
133 | - return false; |
|
134 | - } |
|
135 | - //no value returned |
|
136 | - else if( $ret === null ) { |
|
137 | - $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback); |
|
138 | - $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, |
|
139 | - "CKFinder extension returned an invalid value (null)." . |
|
140 | - "Hook " . $functionName . " should return a value."); |
|
141 | - return false; |
|
142 | - } |
|
143 | - else if (!$ret) { |
|
144 | - return false; |
|
145 | - } |
|
146 | - } |
|
122 | + //String return is a custom error |
|
123 | + if (is_string($ret)) { |
|
124 | + $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, $ret); |
|
125 | + return false; |
|
126 | + } |
|
127 | + //hook returned an error code, user error codes start from 50000 |
|
128 | + //error codes are important because this way it is possible to create multilanguage extensions |
|
129 | + //recomendation: create a function that calculates the error codes starting number |
|
130 | + //for an extension, a pool of 100 error codes for each extension should be safe enough |
|
131 | + else if (is_int($ret)) { |
|
132 | + $errorHandler->throwError($ret); |
|
133 | + return false; |
|
134 | + } |
|
135 | + //no value returned |
|
136 | + else if( $ret === null ) { |
|
137 | + $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback); |
|
138 | + $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, |
|
139 | + "CKFinder extension returned an invalid value (null)." . |
|
140 | + "Hook " . $functionName . " should return a value."); |
|
141 | + return false; |
|
142 | + } |
|
143 | + else if (!$ret) { |
|
144 | + return false; |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | - return true; |
|
149 | - } |
|
148 | + return true; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Print user friendly name of a callback |
|
153 | - * |
|
154 | - * @param mixed $callback |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public static function _printCallback($callback) |
|
158 | - { |
|
159 | - if (is_array($callback)) { |
|
160 | - if (is_object($callback[0])) { |
|
161 | - $className = get_class($callback[0]); |
|
162 | - } else { |
|
163 | - $className = strval($callback[0]); |
|
164 | - } |
|
165 | - $functionName = $className . '::' . strval($callback[1]); |
|
166 | - } |
|
167 | - else { |
|
168 | - $functionName = strval($callback); |
|
169 | - } |
|
170 | - return $functionName; |
|
171 | - } |
|
151 | + /** |
|
152 | + * Print user friendly name of a callback |
|
153 | + * |
|
154 | + * @param mixed $callback |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public static function _printCallback($callback) |
|
158 | + { |
|
159 | + if (is_array($callback)) { |
|
160 | + if (is_object($callback[0])) { |
|
161 | + $className = get_class($callback[0]); |
|
162 | + } else { |
|
163 | + $className = strval($callback[0]); |
|
164 | + } |
|
165 | + $functionName = $className . '::' . strval($callback[1]); |
|
166 | + } |
|
167 | + else { |
|
168 | + $functionName = strval($callback); |
|
169 | + } |
|
170 | + return $functionName; |
|
171 | + } |
|
172 | 172 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | if (!isset($config['Hooks'])) { |
35 | 35 | return true; |
36 | 36 | } |
37 | - $hooks =& $config['Hooks']; |
|
37 | + $hooks = & $config['Hooks']; |
|
38 | 38 | |
39 | 39 | if (!is_array($hooks) || !array_key_exists($event, $hooks) || !is_array($hooks[$event])) { |
40 | 40 | return true; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | //object |
62 | 62 | else if (is_object($hook)) { |
63 | 63 | $object = $hooks[$event][$i]; |
64 | - $method = "on" . $event; |
|
64 | + $method = "on".$event; |
|
65 | 65 | } |
66 | 66 | //array of... |
67 | 67 | else if (is_array($hook)) { |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | if (is_object($hook[0])) { |
72 | 72 | $object = $hooks[$event][$i][0]; |
73 | 73 | if ($count < 2) { |
74 | - $method = "on" . $event; |
|
74 | + $method = "on".$event; |
|
75 | 75 | } else { |
76 | 76 | //...object and method |
77 | 77 | $method = $hook[1]; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | else { |
116 | 116 | $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback); |
117 | 117 | $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, |
118 | - "CKFinder failed to call a hook: " . $functionName); |
|
118 | + "CKFinder failed to call a hook: ".$functionName); |
|
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | return false; |
134 | 134 | } |
135 | 135 | //no value returned |
136 | - else if( $ret === null ) { |
|
136 | + else if ($ret === null) { |
|
137 | 137 | $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback); |
138 | 138 | $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, |
139 | - "CKFinder extension returned an invalid value (null)." . |
|
140 | - "Hook " . $functionName . " should return a value."); |
|
139 | + "CKFinder extension returned an invalid value (null).". |
|
140 | + "Hook ".$functionName." should return a value."); |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | else if (!$ret) { |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | } else { |
163 | 163 | $className = strval($callback[0]); |
164 | 164 | } |
165 | - $functionName = $className . '::' . strval($callback[1]); |
|
165 | + $functionName = $className.'::'.strval($callback[1]); |
|
166 | 166 | } |
167 | 167 | else { |
168 | 168 | $functionName = strval($callback); |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -101,18 +103,15 @@ discard block |
||
101 | 103 | |
102 | 104 | if (isset($object)) { |
103 | 105 | $callback = array($object, $method); |
104 | - } |
|
105 | - else if (false !== ($pos = strpos($function, '::'))) { |
|
106 | + } else if (false !== ($pos = strpos($function, '::'))) { |
|
106 | 107 | $callback = array(substr($function, 0, $pos), substr($function, $pos + 2)); |
107 | - } |
|
108 | - else { |
|
108 | + } else { |
|
109 | 109 | $callback = $function; |
110 | 110 | } |
111 | 111 | |
112 | 112 | if (is_callable($callback)) { |
113 | 113 | $ret = call_user_func_array($callback, $args); |
114 | - } |
|
115 | - else { |
|
114 | + } else { |
|
116 | 115 | $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback); |
117 | 116 | $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, |
118 | 117 | "CKFinder failed to call a hook: " . $functionName); |
@@ -139,8 +138,7 @@ discard block |
||
139 | 138 | "CKFinder extension returned an invalid value (null)." . |
140 | 139 | "Hook " . $functionName . " should return a value."); |
141 | 140 | return false; |
142 | - } |
|
143 | - else if (!$ret) { |
|
141 | + } else if (!$ret) { |
|
144 | 142 | return false; |
145 | 143 | } |
146 | 144 | } |
@@ -163,8 +161,7 @@ discard block |
||
163 | 161 | $className = strval($callback[0]); |
164 | 162 | } |
165 | 163 | $functionName = $className . '::' . strval($callback[1]); |
166 | - } |
|
167 | - else { |
|
164 | + } else { |
|
168 | 165 | $functionName = strval($callback); |
169 | 166 | } |
170 | 167 | return $functionName; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * Set value |
52 | 52 | * |
53 | 53 | * @param string $key |
54 | - * @param mixed $obj |
|
54 | + * @param string $obj |
|
55 | 55 | * @access public |
56 | 56 | */ |
57 | 57 | public function set($key, $obj) |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * Get value |
64 | 64 | * |
65 | 65 | * @param string $key |
66 | - * @return mixed |
|
66 | + * @return string |
|
67 | 67 | * @access public |
68 | 68 | */ |
69 | 69 | public function get($key) |
@@ -27,49 +27,49 @@ |
||
27 | 27 | */ |
28 | 28 | class CKFinder_Connector_Core_Registry |
29 | 29 | { |
30 | - /** |
|
31 | - * Arrat that stores all values |
|
32 | - * |
|
33 | - * @var array |
|
34 | - * @access private |
|
35 | - */ |
|
36 | - private $_store = array(); |
|
30 | + /** |
|
31 | + * Arrat that stores all values |
|
32 | + * |
|
33 | + * @var array |
|
34 | + * @access private |
|
35 | + */ |
|
36 | + private $_store = array(); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Chacke if value has been set |
|
40 | - * |
|
41 | - * @param string $key |
|
42 | - * @return boolean |
|
43 | - * @access private |
|
44 | - */ |
|
45 | - private function isValid($key) |
|
46 | - { |
|
47 | - return array_key_exists($key, $this->_store); |
|
48 | - } |
|
38 | + /** |
|
39 | + * Chacke if value has been set |
|
40 | + * |
|
41 | + * @param string $key |
|
42 | + * @return boolean |
|
43 | + * @access private |
|
44 | + */ |
|
45 | + private function isValid($key) |
|
46 | + { |
|
47 | + return array_key_exists($key, $this->_store); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Set value |
|
52 | - * |
|
53 | - * @param string $key |
|
54 | - * @param mixed $obj |
|
55 | - * @access public |
|
56 | - */ |
|
57 | - public function set($key, $obj) |
|
58 | - { |
|
59 | - $this->_store[$key] = $obj; |
|
60 | - } |
|
50 | + /** |
|
51 | + * Set value |
|
52 | + * |
|
53 | + * @param string $key |
|
54 | + * @param mixed $obj |
|
55 | + * @access public |
|
56 | + */ |
|
57 | + public function set($key, $obj) |
|
58 | + { |
|
59 | + $this->_store[$key] = $obj; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Get value |
|
64 | - * |
|
65 | - * @param string $key |
|
66 | - * @return mixed |
|
67 | - * @access public |
|
68 | - */ |
|
69 | - public function get($key) |
|
70 | - { |
|
71 | - if ($this->isValid($key)) { |
|
72 | - return $this->_store[$key]; |
|
73 | - } |
|
74 | - } |
|
62 | + /** |
|
63 | + * Get value |
|
64 | + * |
|
65 | + * @param string $key |
|
66 | + * @return mixed |
|
67 | + * @access public |
|
68 | + */ |
|
69 | + public function get($key) |
|
70 | + { |
|
71 | + if ($this->isValid($key)) { |
|
72 | + return $this->_store[$key]; |
|
73 | + } |
|
74 | + } |
|
75 | 75 | } |
@@ -10,7 +10,9 @@ |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -221,7 +221,6 @@ discard block |
||
221 | 221 | * If allowed extensions are defined, return false if extension isn't on allowed list. |
222 | 222 | * |
223 | 223 | * @access public |
224 | - * @param string $extension extension |
|
225 | 224 | * @param boolean $renameIfRequired whether try to rename file or not |
226 | 225 | * @return boolean |
227 | 226 | */ |
@@ -314,8 +313,8 @@ discard block |
||
314 | 313 | * Check given path |
315 | 314 | * Return true if path contains folder name that matches hidden folder names list |
316 | 315 | * |
317 | - * @param string $folderName |
|
318 | 316 | * @access public |
317 | + * @param string $path |
|
319 | 318 | * @return boolean |
320 | 319 | */ |
321 | 320 | public function checkIsHiddenPath($path) |
@@ -27,325 +27,325 @@ |
||
27 | 27 | */ |
28 | 28 | class CKFinder_Connector_Core_ResourceTypeConfig |
29 | 29 | { |
30 | - /** |
|
31 | - * Resource name |
|
32 | - * |
|
33 | - * @var string |
|
34 | - * @access private |
|
35 | - */ |
|
36 | - private $_name = ""; |
|
37 | - /** |
|
38 | - * Resource url |
|
39 | - * |
|
40 | - * @var string |
|
41 | - * @access private |
|
42 | - */ |
|
43 | - private $_url = ""; |
|
44 | - /** |
|
45 | - * Directory path on a server |
|
46 | - * |
|
47 | - * @var string |
|
48 | - * @access private |
|
49 | - */ |
|
50 | - private $_directory = ""; |
|
51 | - /** |
|
52 | - * Max size |
|
53 | - * |
|
54 | - * @var unknown_type |
|
55 | - * @access private |
|
56 | - */ |
|
57 | - private $_maxSize = 0; |
|
58 | - /** |
|
59 | - * Array with allowed extensions |
|
60 | - * |
|
61 | - * @var array[]string |
|
62 | - * @access private |
|
63 | - */ |
|
64 | - private $_allowedExtensions = array(); |
|
65 | - /** |
|
66 | - * Array with denied extensions |
|
67 | - * |
|
68 | - * @var array[]string |
|
69 | - * @access private |
|
70 | - */ |
|
71 | - private $_deniedExtensions = array(); |
|
72 | - /** |
|
73 | - * used for CKFinder_Connector_Core_Config object caching |
|
74 | - * |
|
75 | - * @var CKFinder_Connector_Core_Config |
|
76 | - * @access private |
|
77 | - */ |
|
78 | - private $_config; |
|
79 | - |
|
80 | - /** |
|
81 | - * Get ResourceType configuration |
|
82 | - * |
|
83 | - * @param string $resourceTypeNode |
|
84 | - * @return array |
|
85 | - * |
|
86 | - */ |
|
87 | - function __construct($resourceTypeNode) |
|
88 | - { |
|
89 | - if (isset($resourceTypeNode["name"])) { |
|
90 | - $this->_name = $resourceTypeNode["name"]; |
|
91 | - } |
|
92 | - |
|
93 | - if (isset($resourceTypeNode["url"])) { |
|
94 | - $this->_url = $resourceTypeNode["url"]; |
|
95 | - } |
|
96 | - |
|
97 | - if (!strlen($this->_url)) { |
|
98 | - $this->_url = "/"; |
|
99 | - } |
|
100 | - else if(substr($this->_url,-1,1) != "/") { |
|
101 | - $this->_url .= "/"; |
|
102 | - } |
|
103 | - |
|
104 | - if (isset($resourceTypeNode["maxSize"])) { |
|
105 | - $this->_maxSize = CKFinder_Connector_Utils_Misc::returnBytes((string)$resourceTypeNode["maxSize"]); |
|
106 | - } |
|
107 | - |
|
108 | - if (isset($resourceTypeNode["directory"])) { |
|
109 | - $this->_directory = $resourceTypeNode["directory"]; |
|
110 | - } |
|
111 | - |
|
112 | - if (!strlen($this->_directory)) { |
|
113 | - $this->_directory = resolveUrl($this->_url); |
|
114 | - } |
|
115 | - |
|
116 | - if (isset($resourceTypeNode["allowedExtensions"])) { |
|
117 | - if (is_array($resourceTypeNode["allowedExtensions"])) { |
|
118 | - foreach ($resourceTypeNode["allowedExtensions"] as $e) { |
|
119 | - $this->_allowedExtensions[] = strtolower(trim((string)$e)); |
|
120 | - } |
|
121 | - } |
|
122 | - else { |
|
123 | - $resourceTypeNode["allowedExtensions"] = trim((string)$resourceTypeNode["allowedExtensions"]); |
|
124 | - if (strlen($resourceTypeNode["allowedExtensions"])) { |
|
125 | - $extensions = explode(",", $resourceTypeNode["allowedExtensions"]); |
|
126 | - foreach ($extensions as $e) { |
|
127 | - $this->_allowedExtensions[] = strtolower(trim($e)); |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - if (isset($resourceTypeNode["deniedExtensions"])) { |
|
134 | - if (is_array($resourceTypeNode["deniedExtensions"])) { |
|
135 | - |
|
136 | - foreach ($resourceTypeNode["deniedExtensions"] as $extension) { |
|
137 | - $this->_deniedExtensions[] = strtolower(trim((string)$e)); |
|
138 | - } |
|
139 | - } |
|
140 | - else { |
|
141 | - $resourceTypeNode["deniedExtensions"] = trim((string)$resourceTypeNode["deniedExtensions"]); |
|
142 | - if (strlen($resourceTypeNode["deniedExtensions"])) { |
|
143 | - $extensions = explode(",", $resourceTypeNode["deniedExtensions"]); |
|
144 | - foreach ($extensions as $e) { |
|
145 | - $this->_deniedExtensions[] = strtolower(trim($e)); |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Get name |
|
154 | - * |
|
155 | - * @access public |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function getName() |
|
159 | - { |
|
160 | - return $this->_name; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Get url |
|
165 | - * |
|
166 | - * @access public |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function getUrl() |
|
170 | - { |
|
171 | - return $this->_url; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Get directory |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function getDirectory() |
|
181 | - { |
|
182 | - return $this->_directory; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Get max size |
|
187 | - * |
|
188 | - * @access public |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function getMaxSize() |
|
192 | - { |
|
193 | - return $this->_maxSize; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Get allowed extensions |
|
198 | - * |
|
199 | - * @access public |
|
200 | - * @return array[]string |
|
201 | - */ |
|
202 | - public function getAllowedExtensions() |
|
203 | - { |
|
204 | - return $this->_allowedExtensions; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Get denied extensions |
|
209 | - * |
|
210 | - * @access public |
|
211 | - * @return array[]string |
|
212 | - */ |
|
213 | - public function getDeniedExtensions() |
|
214 | - { |
|
215 | - return $this->_deniedExtensions; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Check extension, return true if file name is valid. |
|
220 | - * Return false if extension is on denied list. |
|
221 | - * If allowed extensions are defined, return false if extension isn't on allowed list. |
|
222 | - * |
|
223 | - * @access public |
|
224 | - * @param string $extension extension |
|
225 | - * @param boolean $renameIfRequired whether try to rename file or not |
|
226 | - * @return boolean |
|
227 | - */ |
|
228 | - public function checkExtension(&$fileName, $renameIfRequired = true) |
|
229 | - { |
|
230 | - if (strpos($fileName, '.') === false) { |
|
231 | - return true; |
|
232 | - } |
|
233 | - |
|
234 | - if (is_null($this->_config)) { |
|
235 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
236 | - } |
|
237 | - |
|
238 | - $toCheck = array(); |
|
239 | - |
|
240 | - if ($this->_config->getCheckDoubleExtension()) { |
|
241 | - $pieces = explode('.', $fileName); |
|
242 | - |
|
243 | - // First, check the last extension (ex. in file.php.jpg, the "jpg"). |
|
244 | - if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) { |
|
245 | - return false; |
|
246 | - } |
|
247 | - |
|
248 | - if ($renameIfRequired) { |
|
249 | - // Check the other extensions, rebuilding the file name. If an extension is |
|
250 | - // not allowed, replace the dot with an underscore. |
|
251 | - $fileName = $pieces[0] ; |
|
252 | - for ($i=1; $i<sizeof($pieces)-1; $i++) { |
|
253 | - $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ; |
|
254 | - $fileName .= $pieces[$i]; |
|
255 | - } |
|
256 | - |
|
257 | - // Add the last extension to the final name. |
|
258 | - $fileName .= '.' . $pieces[sizeof($pieces)-1] ; |
|
259 | - } |
|
260 | - } |
|
261 | - else { |
|
262 | - // Check only the last extension (ex. in file.php.jpg, only "jpg"). |
|
263 | - return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) ); |
|
264 | - } |
|
265 | - |
|
266 | - return true; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Check given folder name |
|
271 | - * Return true if folder name matches hidden folder names list |
|
272 | - * |
|
273 | - * @param string $folderName |
|
274 | - * @access public |
|
275 | - * @return boolean |
|
276 | - */ |
|
277 | - public function checkIsHiddenFolder($folderName) |
|
278 | - { |
|
279 | - if (is_null($this->_config)) { |
|
280 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
281 | - } |
|
282 | - |
|
283 | - $regex = $this->_config->getHideFoldersRegex(); |
|
284 | - if ($regex) { |
|
285 | - return preg_match($regex, $folderName); |
|
286 | - } |
|
287 | - |
|
288 | - return false; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Check given file name |
|
293 | - * Return true if file name matches hidden file names list |
|
294 | - * |
|
295 | - * @param string $fileName |
|
296 | - * @access public |
|
297 | - * @return boolean |
|
298 | - */ |
|
299 | - public function checkIsHiddenFile($fileName) |
|
300 | - { |
|
301 | - if (is_null($this->_config)) { |
|
302 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
303 | - } |
|
304 | - |
|
305 | - $regex = $this->_config->getHideFilesRegex(); |
|
306 | - if ($regex) { |
|
307 | - return preg_match($regex, $fileName); |
|
308 | - } |
|
309 | - |
|
310 | - return false; |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Check given path |
|
315 | - * Return true if path contains folder name that matches hidden folder names list |
|
316 | - * |
|
317 | - * @param string $folderName |
|
318 | - * @access public |
|
319 | - * @return boolean |
|
320 | - */ |
|
321 | - public function checkIsHiddenPath($path) |
|
322 | - { |
|
323 | - $_clientPathParts = explode("/", trim($path, "/")); |
|
324 | - if ($_clientPathParts) { |
|
325 | - foreach ($_clientPathParts as $_part) { |
|
326 | - if ($this->checkIsHiddenFolder($_part)) { |
|
327 | - return true; |
|
328 | - } |
|
329 | - } |
|
330 | - } |
|
331 | - |
|
332 | - return false; |
|
333 | - } |
|
334 | - |
|
335 | - public function checkSingleExtension($extension) |
|
336 | - { |
|
337 | - $extension = strtolower(ltrim($extension,'.')); |
|
338 | - |
|
339 | - if (sizeof($this->_deniedExtensions)) { |
|
340 | - if (in_array($extension, $this->_deniedExtensions)) { |
|
341 | - return false; |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - if (sizeof($this->_allowedExtensions)) { |
|
346 | - return in_array($extension, $this->_allowedExtensions); |
|
347 | - } |
|
348 | - |
|
349 | - return true; |
|
350 | - } |
|
30 | + /** |
|
31 | + * Resource name |
|
32 | + * |
|
33 | + * @var string |
|
34 | + * @access private |
|
35 | + */ |
|
36 | + private $_name = ""; |
|
37 | + /** |
|
38 | + * Resource url |
|
39 | + * |
|
40 | + * @var string |
|
41 | + * @access private |
|
42 | + */ |
|
43 | + private $_url = ""; |
|
44 | + /** |
|
45 | + * Directory path on a server |
|
46 | + * |
|
47 | + * @var string |
|
48 | + * @access private |
|
49 | + */ |
|
50 | + private $_directory = ""; |
|
51 | + /** |
|
52 | + * Max size |
|
53 | + * |
|
54 | + * @var unknown_type |
|
55 | + * @access private |
|
56 | + */ |
|
57 | + private $_maxSize = 0; |
|
58 | + /** |
|
59 | + * Array with allowed extensions |
|
60 | + * |
|
61 | + * @var array[]string |
|
62 | + * @access private |
|
63 | + */ |
|
64 | + private $_allowedExtensions = array(); |
|
65 | + /** |
|
66 | + * Array with denied extensions |
|
67 | + * |
|
68 | + * @var array[]string |
|
69 | + * @access private |
|
70 | + */ |
|
71 | + private $_deniedExtensions = array(); |
|
72 | + /** |
|
73 | + * used for CKFinder_Connector_Core_Config object caching |
|
74 | + * |
|
75 | + * @var CKFinder_Connector_Core_Config |
|
76 | + * @access private |
|
77 | + */ |
|
78 | + private $_config; |
|
79 | + |
|
80 | + /** |
|
81 | + * Get ResourceType configuration |
|
82 | + * |
|
83 | + * @param string $resourceTypeNode |
|
84 | + * @return array |
|
85 | + * |
|
86 | + */ |
|
87 | + function __construct($resourceTypeNode) |
|
88 | + { |
|
89 | + if (isset($resourceTypeNode["name"])) { |
|
90 | + $this->_name = $resourceTypeNode["name"]; |
|
91 | + } |
|
92 | + |
|
93 | + if (isset($resourceTypeNode["url"])) { |
|
94 | + $this->_url = $resourceTypeNode["url"]; |
|
95 | + } |
|
96 | + |
|
97 | + if (!strlen($this->_url)) { |
|
98 | + $this->_url = "/"; |
|
99 | + } |
|
100 | + else if(substr($this->_url,-1,1) != "/") { |
|
101 | + $this->_url .= "/"; |
|
102 | + } |
|
103 | + |
|
104 | + if (isset($resourceTypeNode["maxSize"])) { |
|
105 | + $this->_maxSize = CKFinder_Connector_Utils_Misc::returnBytes((string)$resourceTypeNode["maxSize"]); |
|
106 | + } |
|
107 | + |
|
108 | + if (isset($resourceTypeNode["directory"])) { |
|
109 | + $this->_directory = $resourceTypeNode["directory"]; |
|
110 | + } |
|
111 | + |
|
112 | + if (!strlen($this->_directory)) { |
|
113 | + $this->_directory = resolveUrl($this->_url); |
|
114 | + } |
|
115 | + |
|
116 | + if (isset($resourceTypeNode["allowedExtensions"])) { |
|
117 | + if (is_array($resourceTypeNode["allowedExtensions"])) { |
|
118 | + foreach ($resourceTypeNode["allowedExtensions"] as $e) { |
|
119 | + $this->_allowedExtensions[] = strtolower(trim((string)$e)); |
|
120 | + } |
|
121 | + } |
|
122 | + else { |
|
123 | + $resourceTypeNode["allowedExtensions"] = trim((string)$resourceTypeNode["allowedExtensions"]); |
|
124 | + if (strlen($resourceTypeNode["allowedExtensions"])) { |
|
125 | + $extensions = explode(",", $resourceTypeNode["allowedExtensions"]); |
|
126 | + foreach ($extensions as $e) { |
|
127 | + $this->_allowedExtensions[] = strtolower(trim($e)); |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + if (isset($resourceTypeNode["deniedExtensions"])) { |
|
134 | + if (is_array($resourceTypeNode["deniedExtensions"])) { |
|
135 | + |
|
136 | + foreach ($resourceTypeNode["deniedExtensions"] as $extension) { |
|
137 | + $this->_deniedExtensions[] = strtolower(trim((string)$e)); |
|
138 | + } |
|
139 | + } |
|
140 | + else { |
|
141 | + $resourceTypeNode["deniedExtensions"] = trim((string)$resourceTypeNode["deniedExtensions"]); |
|
142 | + if (strlen($resourceTypeNode["deniedExtensions"])) { |
|
143 | + $extensions = explode(",", $resourceTypeNode["deniedExtensions"]); |
|
144 | + foreach ($extensions as $e) { |
|
145 | + $this->_deniedExtensions[] = strtolower(trim($e)); |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Get name |
|
154 | + * |
|
155 | + * @access public |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function getName() |
|
159 | + { |
|
160 | + return $this->_name; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Get url |
|
165 | + * |
|
166 | + * @access public |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function getUrl() |
|
170 | + { |
|
171 | + return $this->_url; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Get directory |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function getDirectory() |
|
181 | + { |
|
182 | + return $this->_directory; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Get max size |
|
187 | + * |
|
188 | + * @access public |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function getMaxSize() |
|
192 | + { |
|
193 | + return $this->_maxSize; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Get allowed extensions |
|
198 | + * |
|
199 | + * @access public |
|
200 | + * @return array[]string |
|
201 | + */ |
|
202 | + public function getAllowedExtensions() |
|
203 | + { |
|
204 | + return $this->_allowedExtensions; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Get denied extensions |
|
209 | + * |
|
210 | + * @access public |
|
211 | + * @return array[]string |
|
212 | + */ |
|
213 | + public function getDeniedExtensions() |
|
214 | + { |
|
215 | + return $this->_deniedExtensions; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Check extension, return true if file name is valid. |
|
220 | + * Return false if extension is on denied list. |
|
221 | + * If allowed extensions are defined, return false if extension isn't on allowed list. |
|
222 | + * |
|
223 | + * @access public |
|
224 | + * @param string $extension extension |
|
225 | + * @param boolean $renameIfRequired whether try to rename file or not |
|
226 | + * @return boolean |
|
227 | + */ |
|
228 | + public function checkExtension(&$fileName, $renameIfRequired = true) |
|
229 | + { |
|
230 | + if (strpos($fileName, '.') === false) { |
|
231 | + return true; |
|
232 | + } |
|
233 | + |
|
234 | + if (is_null($this->_config)) { |
|
235 | + $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
236 | + } |
|
237 | + |
|
238 | + $toCheck = array(); |
|
239 | + |
|
240 | + if ($this->_config->getCheckDoubleExtension()) { |
|
241 | + $pieces = explode('.', $fileName); |
|
242 | + |
|
243 | + // First, check the last extension (ex. in file.php.jpg, the "jpg"). |
|
244 | + if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) { |
|
245 | + return false; |
|
246 | + } |
|
247 | + |
|
248 | + if ($renameIfRequired) { |
|
249 | + // Check the other extensions, rebuilding the file name. If an extension is |
|
250 | + // not allowed, replace the dot with an underscore. |
|
251 | + $fileName = $pieces[0] ; |
|
252 | + for ($i=1; $i<sizeof($pieces)-1; $i++) { |
|
253 | + $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ; |
|
254 | + $fileName .= $pieces[$i]; |
|
255 | + } |
|
256 | + |
|
257 | + // Add the last extension to the final name. |
|
258 | + $fileName .= '.' . $pieces[sizeof($pieces)-1] ; |
|
259 | + } |
|
260 | + } |
|
261 | + else { |
|
262 | + // Check only the last extension (ex. in file.php.jpg, only "jpg"). |
|
263 | + return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) ); |
|
264 | + } |
|
265 | + |
|
266 | + return true; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * Check given folder name |
|
271 | + * Return true if folder name matches hidden folder names list |
|
272 | + * |
|
273 | + * @param string $folderName |
|
274 | + * @access public |
|
275 | + * @return boolean |
|
276 | + */ |
|
277 | + public function checkIsHiddenFolder($folderName) |
|
278 | + { |
|
279 | + if (is_null($this->_config)) { |
|
280 | + $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
281 | + } |
|
282 | + |
|
283 | + $regex = $this->_config->getHideFoldersRegex(); |
|
284 | + if ($regex) { |
|
285 | + return preg_match($regex, $folderName); |
|
286 | + } |
|
287 | + |
|
288 | + return false; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Check given file name |
|
293 | + * Return true if file name matches hidden file names list |
|
294 | + * |
|
295 | + * @param string $fileName |
|
296 | + * @access public |
|
297 | + * @return boolean |
|
298 | + */ |
|
299 | + public function checkIsHiddenFile($fileName) |
|
300 | + { |
|
301 | + if (is_null($this->_config)) { |
|
302 | + $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
303 | + } |
|
304 | + |
|
305 | + $regex = $this->_config->getHideFilesRegex(); |
|
306 | + if ($regex) { |
|
307 | + return preg_match($regex, $fileName); |
|
308 | + } |
|
309 | + |
|
310 | + return false; |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Check given path |
|
315 | + * Return true if path contains folder name that matches hidden folder names list |
|
316 | + * |
|
317 | + * @param string $folderName |
|
318 | + * @access public |
|
319 | + * @return boolean |
|
320 | + */ |
|
321 | + public function checkIsHiddenPath($path) |
|
322 | + { |
|
323 | + $_clientPathParts = explode("/", trim($path, "/")); |
|
324 | + if ($_clientPathParts) { |
|
325 | + foreach ($_clientPathParts as $_part) { |
|
326 | + if ($this->checkIsHiddenFolder($_part)) { |
|
327 | + return true; |
|
328 | + } |
|
329 | + } |
|
330 | + } |
|
331 | + |
|
332 | + return false; |
|
333 | + } |
|
334 | + |
|
335 | + public function checkSingleExtension($extension) |
|
336 | + { |
|
337 | + $extension = strtolower(ltrim($extension,'.')); |
|
338 | + |
|
339 | + if (sizeof($this->_deniedExtensions)) { |
|
340 | + if (in_array($extension, $this->_deniedExtensions)) { |
|
341 | + return false; |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + if (sizeof($this->_allowedExtensions)) { |
|
346 | + return in_array($extension, $this->_allowedExtensions); |
|
347 | + } |
|
348 | + |
|
349 | + return true; |
|
350 | + } |
|
351 | 351 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | if (!strlen($this->_url)) { |
98 | 98 | $this->_url = "/"; |
99 | 99 | } |
100 | - else if(substr($this->_url,-1,1) != "/") { |
|
100 | + else if (substr($this->_url, -1, 1) != "/") { |
|
101 | 101 | $this->_url .= "/"; |
102 | 102 | } |
103 | 103 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | if (is_null($this->_config)) { |
235 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
235 | + $this->_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | $toCheck = array(); |
@@ -241,26 +241,26 @@ discard block |
||
241 | 241 | $pieces = explode('.', $fileName); |
242 | 242 | |
243 | 243 | // First, check the last extension (ex. in file.php.jpg, the "jpg"). |
244 | - if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) { |
|
244 | + if (!$this->checkSingleExtension($pieces[sizeof($pieces) - 1])) { |
|
245 | 245 | return false; |
246 | 246 | } |
247 | 247 | |
248 | 248 | if ($renameIfRequired) { |
249 | 249 | // Check the other extensions, rebuilding the file name. If an extension is |
250 | 250 | // not allowed, replace the dot with an underscore. |
251 | - $fileName = $pieces[0] ; |
|
252 | - for ($i=1; $i<sizeof($pieces)-1; $i++) { |
|
253 | - $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ; |
|
251 | + $fileName = $pieces[0]; |
|
252 | + for ($i = 1; $i < sizeof($pieces) - 1; $i++) { |
|
253 | + $fileName .= $this->checkSingleExtension($pieces[$i]) ? '.' : '_'; |
|
254 | 254 | $fileName .= $pieces[$i]; |
255 | 255 | } |
256 | 256 | |
257 | 257 | // Add the last extension to the final name. |
258 | - $fileName .= '.' . $pieces[sizeof($pieces)-1] ; |
|
258 | + $fileName .= '.'.$pieces[sizeof($pieces) - 1]; |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | else { |
262 | 262 | // Check only the last extension (ex. in file.php.jpg, only "jpg"). |
263 | - return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) ); |
|
263 | + return $this->checkSingleExtension(substr($fileName, strrpos($fileName, '.') + 1)); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | return true; |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | public function checkIsHiddenFolder($folderName) |
278 | 278 | { |
279 | 279 | if (is_null($this->_config)) { |
280 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
280 | + $this->_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | $regex = $this->_config->getHideFoldersRegex(); |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | public function checkIsHiddenFile($fileName) |
300 | 300 | { |
301 | 301 | if (is_null($this->_config)) { |
302 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
302 | + $this->_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | $regex = $this->_config->getHideFilesRegex(); |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | |
335 | 335 | public function checkSingleExtension($extension) |
336 | 336 | { |
337 | - $extension = strtolower(ltrim($extension,'.')); |
|
337 | + $extension = strtolower(ltrim($extension, '.')); |
|
338 | 338 | |
339 | 339 | if (sizeof($this->_deniedExtensions)) { |
340 | 340 | if (in_array($extension, $this->_deniedExtensions)) { |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -96,8 +98,7 @@ discard block |
||
96 | 98 | |
97 | 99 | if (!strlen($this->_url)) { |
98 | 100 | $this->_url = "/"; |
99 | - } |
|
100 | - else if(substr($this->_url,-1,1) != "/") { |
|
101 | + } else if(substr($this->_url,-1,1) != "/") { |
|
101 | 102 | $this->_url .= "/"; |
102 | 103 | } |
103 | 104 | |
@@ -118,8 +119,7 @@ discard block |
||
118 | 119 | foreach ($resourceTypeNode["allowedExtensions"] as $e) { |
119 | 120 | $this->_allowedExtensions[] = strtolower(trim((string)$e)); |
120 | 121 | } |
121 | - } |
|
122 | - else { |
|
122 | + } else { |
|
123 | 123 | $resourceTypeNode["allowedExtensions"] = trim((string)$resourceTypeNode["allowedExtensions"]); |
124 | 124 | if (strlen($resourceTypeNode["allowedExtensions"])) { |
125 | 125 | $extensions = explode(",", $resourceTypeNode["allowedExtensions"]); |
@@ -136,8 +136,7 @@ discard block |
||
136 | 136 | foreach ($resourceTypeNode["deniedExtensions"] as $extension) { |
137 | 137 | $this->_deniedExtensions[] = strtolower(trim((string)$e)); |
138 | 138 | } |
139 | - } |
|
140 | - else { |
|
139 | + } else { |
|
141 | 140 | $resourceTypeNode["deniedExtensions"] = trim((string)$resourceTypeNode["deniedExtensions"]); |
142 | 141 | if (strlen($resourceTypeNode["deniedExtensions"])) { |
143 | 142 | $extensions = explode(",", $resourceTypeNode["deniedExtensions"]); |
@@ -257,8 +256,7 @@ discard block |
||
257 | 256 | // Add the last extension to the final name. |
258 | 257 | $fileName .= '.' . $pieces[sizeof($pieces)-1] ; |
259 | 258 | } |
260 | - } |
|
261 | - else { |
|
259 | + } else { |
|
262 | 260 | // Check only the last extension (ex. in file.php.jpg, only "jpg"). |
263 | 261 | return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) ); |
264 | 262 | } |
@@ -36,7 +36,7 @@ |
||
36 | 36 | * Throw file upload error, return true if error has been thrown, false if error has been catched |
37 | 37 | * |
38 | 38 | * @param int $number |
39 | - * @param string $text |
|
39 | + * @param string $exit |
|
40 | 40 | * @access public |
41 | 41 | */ |
42 | 42 | public function throwError($number, $uploaded = false, $exit = true) { |
@@ -32,50 +32,50 @@ |
||
32 | 32 | * @copyright CKSource - Frederico Knabben |
33 | 33 | */ |
34 | 34 | class CKFinder_Connector_ErrorHandler_FileUpload extends CKFinder_Connector_ErrorHandler_Base { |
35 | - /** |
|
36 | - * Throw file upload error, return true if error has been thrown, false if error has been catched |
|
37 | - * |
|
38 | - * @param int $number |
|
39 | - * @param string $text |
|
40 | - * @access public |
|
41 | - */ |
|
42 | - public function throwError($number, $uploaded = false, $exit = true) { |
|
43 | - if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
44 | - return false; |
|
45 | - } |
|
35 | + /** |
|
36 | + * Throw file upload error, return true if error has been thrown, false if error has been catched |
|
37 | + * |
|
38 | + * @param int $number |
|
39 | + * @param string $text |
|
40 | + * @access public |
|
41 | + */ |
|
42 | + public function throwError($number, $uploaded = false, $exit = true) { |
|
43 | + if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
44 | + return false; |
|
45 | + } |
|
46 | 46 | |
47 | - $oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry"); |
|
48 | - $sFileName = $oRegistry->get("FileUpload_fileName"); |
|
49 | - $sFileUrl = $oRegistry->get("FileUpload_url"); |
|
47 | + $oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry"); |
|
48 | + $sFileName = $oRegistry->get("FileUpload_fileName"); |
|
49 | + $sFileUrl = $oRegistry->get("FileUpload_url"); |
|
50 | 50 | |
51 | - header('Content-Type: text/html; charset=utf-8'); |
|
51 | + header('Content-Type: text/html; charset=utf-8'); |
|
52 | 52 | |
53 | - $errorMessage = CKFinder_Connector_Utils_Misc :: getErrorMessage($number, $sFileName); |
|
54 | - if (!$uploaded) { |
|
55 | - $sFileName = ""; |
|
56 | - } |
|
53 | + $errorMessage = CKFinder_Connector_Utils_Misc :: getErrorMessage($number, $sFileName); |
|
54 | + if (!$uploaded) { |
|
55 | + $sFileName = ""; |
|
56 | + } |
|
57 | 57 | |
58 | - echo "<script type=\"text/javascript\">"; |
|
58 | + echo "<script type=\"text/javascript\">"; |
|
59 | 59 | |
60 | - if (!empty($_GET['CKFinderFuncNum'])) { |
|
61 | - $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName); |
|
60 | + if (!empty($_GET['CKFinderFuncNum'])) { |
|
61 | + $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName); |
|
62 | 62 | |
63 | - if (!$uploaded) { |
|
64 | - $sFileUrl = ""; |
|
65 | - $sFileName = ""; |
|
66 | - } |
|
63 | + if (!$uploaded) { |
|
64 | + $sFileUrl = ""; |
|
65 | + $sFileName = ""; |
|
66 | + } |
|
67 | 67 | |
68 | - $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']); |
|
69 | - echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
|
70 | - } |
|
71 | - else { |
|
72 | - echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;"; |
|
73 | - } |
|
68 | + $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']); |
|
69 | + echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
|
70 | + } |
|
71 | + else { |
|
72 | + echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;"; |
|
73 | + } |
|
74 | 74 | |
75 | - echo "</script>"; |
|
75 | + echo "</script>"; |
|
76 | 76 | |
77 | - if ($exit) { |
|
78 | - exit; |
|
79 | - } |
|
80 | - } |
|
77 | + if ($exit) { |
|
78 | + exit; |
|
79 | + } |
|
80 | + } |
|
81 | 81 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * Include base error handling class |
24 | 24 | */ |
25 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php"; |
|
25 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/ErrorHandler/Base.php"; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * File upload error handler |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']); |
69 | - echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
|
69 | + echo "window.parent.CKFinder.tools.callFunction($funcNum, '".str_replace("'", "\\'", $sFileUrl.$sFileName)."', '".str_replace("'", "\\'", $errorMessage)."');"; |
|
70 | 70 | } |
71 | 71 | else { |
72 | - echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;"; |
|
72 | + echo "window.parent.OnUploadCompleted('".str_replace("'", "\\'", $sFileName)."', '".str_replace("'", "\\'", $errorMessage)."') ;"; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | echo "</script>"; |
@@ -11,7 +11,9 @@ discard block |
||
11 | 11 | * modifying or distribute this file or part of its contents. The contents of |
12 | 12 | * this file is part of the Source Code of CKFinder. |
13 | 13 | */ |
14 | -if (!defined('IN_CKFINDER')) exit; |
|
14 | +if (!defined('IN_CKFINDER')) { |
|
15 | + exit; |
|
16 | +} |
|
15 | 17 | |
16 | 18 | /** |
17 | 19 | * @package CKFinder |
@@ -67,8 +69,7 @@ discard block |
||
67 | 69 | |
68 | 70 | $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']); |
69 | 71 | echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
70 | - } |
|
71 | - else { |
|
72 | + } else { |
|
72 | 73 | echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;"; |
73 | 74 | } |
74 | 75 |