@@ -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 thumbnails 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 | |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | return false; |
135 | 135 | } |
136 | 136 | //no value returned |
137 | - else if( $ret === null ) { |
|
137 | + else if ($ret === null) { |
|
138 | 138 | $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback); |
139 | 139 | $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, |
140 | - "CKFinder extension returned an invalid value (null)." . |
|
141 | - "Hook " . $functionName . " should return a value."); |
|
140 | + "CKFinder extension returned an invalid value (null).". |
|
141 | + "Hook ".$functionName." should return a value."); |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | else if (!$ret) { |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | } else { |
164 | 164 | $className = strval($callback[0]); |
165 | 165 | } |
166 | - $functionName = $className . '::' . strval($callback[1]); |
|
166 | + $functionName = $className.'::'.strval($callback[1]); |
|
167 | 167 | } |
168 | 168 | else { |
169 | 169 | $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); |
@@ -140,8 +139,7 @@ discard block |
||
140 | 139 | "CKFinder extension returned an invalid value (null)." . |
141 | 140 | "Hook " . $functionName . " should return a value."); |
142 | 141 | return false; |
143 | - } |
|
144 | - else if (!$ret) { |
|
142 | + } else if (!$ret) { |
|
145 | 143 | return false; |
146 | 144 | } |
147 | 145 | } |
@@ -164,8 +162,7 @@ discard block |
||
164 | 162 | $className = strval($callback[0]); |
165 | 163 | } |
166 | 164 | $functionName = $className . '::' . strval($callback[1]); |
167 | - } |
|
168 | - else { |
|
165 | + } else { |
|
169 | 166 | $functionName = strval($callback); |
170 | 167 | } |
171 | 168 | 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 | 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 | 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 | 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 | } |
@@ -35,7 +35,7 @@ |
||
35 | 35 | * Throw file upload error, return true if error has been thrown, false if error has been catched |
36 | 36 | * |
37 | 37 | * @param int $number |
38 | - * @param string $text |
|
38 | + * @param string $exit |
|
39 | 39 | * @access public |
40 | 40 | */ |
41 | 41 | public function throwError($number, $uploaded = false, $exit = true) { |
@@ -31,52 +31,52 @@ |
||
31 | 31 | * @copyright CKSource - Frederico Knabben |
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_ErrorHandler_QuickUpload extends CKFinder_Connector_ErrorHandler_Base { |
34 | - /** |
|
35 | - * Throw file upload error, return true if error has been thrown, false if error has been catched |
|
36 | - * |
|
37 | - * @param int $number |
|
38 | - * @param string $text |
|
39 | - * @access public |
|
40 | - */ |
|
41 | - public function throwError($number, $uploaded = false, $exit = true) { |
|
42 | - if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
43 | - return false; |
|
44 | - } |
|
34 | + /** |
|
35 | + * Throw file upload error, return true if error has been thrown, false if error has been catched |
|
36 | + * |
|
37 | + * @param int $number |
|
38 | + * @param string $text |
|
39 | + * @access public |
|
40 | + */ |
|
41 | + public function throwError($number, $uploaded = false, $exit = true) { |
|
42 | + if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
43 | + return false; |
|
44 | + } |
|
45 | 45 | |
46 | - $oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry"); |
|
47 | - $sFileName = $oRegistry->get("FileUpload_fileName"); |
|
48 | - $sFileUrl = $oRegistry->get("FileUpload_url"); |
|
46 | + $oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry"); |
|
47 | + $sFileName = $oRegistry->get("FileUpload_fileName"); |
|
48 | + $sFileUrl = $oRegistry->get("FileUpload_url"); |
|
49 | 49 | |
50 | - header('Content-Type: text/html; charset=utf-8'); |
|
50 | + header('Content-Type: text/html; charset=utf-8'); |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * echo <script> is not called before CKFinder_Connector_Utils_Misc::getErrorMessage |
54 | 54 | * because PHP has problems with including files that contain BOM character. |
55 | 55 | * Having BOM character after <script> tag causes a javascript error. |
56 | 56 | */ |
57 | - echo "<script type=\"text/javascript\">"; |
|
58 | - if (!empty($_GET['CKEditor'])) { |
|
59 | - $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName); |
|
57 | + echo "<script type=\"text/javascript\">"; |
|
58 | + if (!empty($_GET['CKEditor'])) { |
|
59 | + $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName); |
|
60 | 60 | |
61 | - if (!$uploaded) { |
|
62 | - $sFileUrl = ""; |
|
63 | - $sFileName = ""; |
|
64 | - } |
|
61 | + if (!$uploaded) { |
|
62 | + $sFileUrl = ""; |
|
63 | + $sFileName = ""; |
|
64 | + } |
|
65 | 65 | |
66 | - $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']); |
|
67 | - echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
|
68 | - } |
|
69 | - else { |
|
70 | - if (!$uploaded) { |
|
71 | - echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;"; |
|
72 | - } else { |
|
73 | - echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;"; |
|
74 | - } |
|
75 | - } |
|
76 | - echo "</script>"; |
|
66 | + $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']); |
|
67 | + echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
|
68 | + } |
|
69 | + else { |
|
70 | + if (!$uploaded) { |
|
71 | + echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;"; |
|
72 | + } else { |
|
73 | + echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;"; |
|
74 | + } |
|
75 | + } |
|
76 | + echo "</script>"; |
|
77 | 77 | |
78 | - if ($exit) { |
|
79 | - exit; |
|
80 | - } |
|
81 | - } |
|
78 | + if ($exit) { |
|
79 | + exit; |
|
80 | + } |
|
81 | + } |
|
82 | 82 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include base error handling class |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/ErrorHandler/Base.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * File upload error handler |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']); |
68 | - echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
|
68 | + echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '".str_replace("'", "\\'", $sFileUrl.$sFileName)."', '".str_replace("'", "\\'", $errorMessage)."');"; |
|
69 | 69 | } |
70 | 70 | else { |
71 | 71 | if (!$uploaded) { |
72 | - echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;"; |
|
72 | + echo "window.parent.OnUploadCompleted(".$number.", '', '', '') ;"; |
|
73 | 73 | } else { |
74 | - echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;"; |
|
74 | + echo "window.parent.OnUploadCompleted(".$number.", '".str_replace("'", "\\'", $sFileUrl.$sFileName)."', '".str_replace("'", "\\'", $sFileName)."', '') ;"; |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | echo "</script>"; |
@@ -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 |
@@ -66,8 +68,7 @@ discard block |
||
66 | 68 | |
67 | 69 | $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']); |
68 | 70 | echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
69 | - } |
|
70 | - else { |
|
71 | + } else { |
|
71 | 72 | if (!$uploaded) { |
72 | 73 | echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;"; |
73 | 74 | } else { |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | * @static |
415 | 415 | * @access public |
416 | 416 | * @param string $filePath absolute path to file |
417 | - * @return boolean |
|
417 | + * @return string |
|
418 | 418 | */ |
419 | 419 | public static function detectHtml($filePath) |
420 | 420 | { |
@@ -475,8 +475,7 @@ discard block |
||
475 | 475 | * @access public |
476 | 476 | * @param string $filePath absolute path to file |
477 | 477 | * @param string $extension file extension |
478 | - * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images |
|
479 | - * @return boolean |
|
478 | + * @return string |
|
480 | 479 | */ |
481 | 480 | public static function isImageValid($filePath, $extension) |
482 | 481 | { |
@@ -26,198 +26,198 @@ discard block |
||
26 | 26 | class CKFinder_Connector_Utils_FileSystem |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * This function behaves similar to System.IO.Path.Combine in C#, the only diffrenece is that it also accepts null values and treat them as empty string |
|
31 | - * |
|
32 | - * @static |
|
33 | - * @access public |
|
34 | - * @param string $path1 first path |
|
35 | - * @param string $path2 scecond path |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public static function combinePaths($path1, $path2) |
|
39 | - { |
|
40 | - if (is_null($path1)) { |
|
41 | - $path1 = ""; |
|
42 | - } |
|
43 | - if (is_null($path2)) { |
|
44 | - $path2 = ""; |
|
45 | - } |
|
46 | - if (!strlen($path2)) { |
|
47 | - if (strlen($path1)) { |
|
48 | - $_lastCharP1 = substr($path1, -1, 1); |
|
49 | - if ($_lastCharP1 != "/" && $_lastCharP1 != "\\") { |
|
50 | - $path1 .= DIRECTORY_SEPARATOR; |
|
51 | - } |
|
52 | - } |
|
53 | - } |
|
54 | - else { |
|
55 | - $_firstCharP2 = substr($path2, 0, 1); |
|
56 | - if (strlen($path1)) { |
|
57 | - if (strpos($path2, $path1)===0) { |
|
58 | - return $path2; |
|
59 | - } |
|
60 | - $_lastCharP1 = substr($path1, -1, 1); |
|
61 | - if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") { |
|
62 | - $path1 .= DIRECTORY_SEPARATOR; |
|
63 | - } |
|
64 | - } |
|
65 | - else { |
|
66 | - return $path2; |
|
67 | - } |
|
68 | - } |
|
69 | - return $path1 . $path2; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Check whether $fileName is a valid file name, return true on success |
|
74 | - * |
|
75 | - * @static |
|
76 | - * @access public |
|
77 | - * @param string $fileName |
|
78 | - * @return boolean |
|
79 | - */ |
|
80 | - public static function checkFileName($fileName) |
|
81 | - { |
|
82 | - if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) { |
|
83 | - return false; |
|
84 | - } |
|
85 | - |
|
86 | - if (preg_match(CKFINDER_REGEX_INVALID_FILE, $fileName)) { |
|
87 | - return false; |
|
88 | - } |
|
89 | - |
|
90 | - return true; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Unlink file/folder |
|
95 | - * |
|
96 | - * @static |
|
97 | - * @access public |
|
98 | - * @param string $path |
|
99 | - * @return boolean |
|
100 | - */ |
|
101 | - public static function unlink($path) |
|
102 | - { |
|
103 | - /* make sure the path exists */ |
|
104 | - if(!file_exists($path)) { |
|
105 | - return false; |
|
106 | - } |
|
107 | - |
|
108 | - /* If it is a file or link, just delete it */ |
|
109 | - if(is_file($path) || is_link($path)) { |
|
110 | - return @unlink($path); |
|
111 | - } |
|
112 | - |
|
113 | - /* Scan the dir and recursively unlink */ |
|
114 | - $files = scandir($path); |
|
115 | - if ($files) { |
|
116 | - foreach($files as $filename) |
|
117 | - { |
|
118 | - if ($filename == '.' || $filename == '..') { |
|
119 | - continue; |
|
120 | - } |
|
121 | - $file = str_replace('//','/',$path.'/'.$filename); |
|
122 | - CKFinder_Connector_Utils_FileSystem::unlink($file); |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /* Remove the parent dir */ |
|
127 | - if(!@rmdir($path)) { |
|
128 | - return false; |
|
129 | - } |
|
130 | - |
|
131 | - return true; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Return file name without extension (without dot & last part after dot) |
|
136 | - * |
|
137 | - * @static |
|
138 | - * @access public |
|
139 | - * @param string $fileName |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public static function getFileNameWithoutExtension($fileName) |
|
143 | - { |
|
144 | - $dotPos = strrpos( $fileName, '.' ); |
|
145 | - if (false === $dotPos) { |
|
146 | - return $fileName; |
|
147 | - } |
|
148 | - |
|
149 | - return substr($fileName, 0, $dotPos); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Get file extension (only last part - e.g. extension of file.foo.bar.jpg = jpg) |
|
154 | - * |
|
155 | - * @static |
|
156 | - * @access public |
|
157 | - * @param string $fileName |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public static function getExtension( $fileName ) |
|
161 | - { |
|
162 | - $dotPos = strrpos( $fileName, '.' ); |
|
163 | - if (false === $dotPos) { |
|
164 | - return ""; |
|
165 | - } |
|
166 | - |
|
167 | - return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
29 | + /** |
|
30 | + * This function behaves similar to System.IO.Path.Combine in C#, the only diffrenece is that it also accepts null values and treat them as empty string |
|
31 | + * |
|
32 | + * @static |
|
33 | + * @access public |
|
34 | + * @param string $path1 first path |
|
35 | + * @param string $path2 scecond path |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public static function combinePaths($path1, $path2) |
|
39 | + { |
|
40 | + if (is_null($path1)) { |
|
41 | + $path1 = ""; |
|
42 | + } |
|
43 | + if (is_null($path2)) { |
|
44 | + $path2 = ""; |
|
45 | + } |
|
46 | + if (!strlen($path2)) { |
|
47 | + if (strlen($path1)) { |
|
48 | + $_lastCharP1 = substr($path1, -1, 1); |
|
49 | + if ($_lastCharP1 != "/" && $_lastCharP1 != "\\") { |
|
50 | + $path1 .= DIRECTORY_SEPARATOR; |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | + else { |
|
55 | + $_firstCharP2 = substr($path2, 0, 1); |
|
56 | + if (strlen($path1)) { |
|
57 | + if (strpos($path2, $path1)===0) { |
|
58 | + return $path2; |
|
59 | + } |
|
60 | + $_lastCharP1 = substr($path1, -1, 1); |
|
61 | + if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") { |
|
62 | + $path1 .= DIRECTORY_SEPARATOR; |
|
63 | + } |
|
64 | + } |
|
65 | + else { |
|
66 | + return $path2; |
|
67 | + } |
|
68 | + } |
|
69 | + return $path1 . $path2; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Check whether $fileName is a valid file name, return true on success |
|
74 | + * |
|
75 | + * @static |
|
76 | + * @access public |
|
77 | + * @param string $fileName |
|
78 | + * @return boolean |
|
79 | + */ |
|
80 | + public static function checkFileName($fileName) |
|
81 | + { |
|
82 | + if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) { |
|
83 | + return false; |
|
84 | + } |
|
85 | + |
|
86 | + if (preg_match(CKFINDER_REGEX_INVALID_FILE, $fileName)) { |
|
87 | + return false; |
|
88 | + } |
|
89 | + |
|
90 | + return true; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Unlink file/folder |
|
95 | + * |
|
96 | + * @static |
|
97 | + * @access public |
|
98 | + * @param string $path |
|
99 | + * @return boolean |
|
100 | + */ |
|
101 | + public static function unlink($path) |
|
102 | + { |
|
103 | + /* make sure the path exists */ |
|
104 | + if(!file_exists($path)) { |
|
105 | + return false; |
|
106 | + } |
|
107 | + |
|
108 | + /* If it is a file or link, just delete it */ |
|
109 | + if(is_file($path) || is_link($path)) { |
|
110 | + return @unlink($path); |
|
111 | + } |
|
112 | + |
|
113 | + /* Scan the dir and recursively unlink */ |
|
114 | + $files = scandir($path); |
|
115 | + if ($files) { |
|
116 | + foreach($files as $filename) |
|
117 | + { |
|
118 | + if ($filename == '.' || $filename == '..') { |
|
119 | + continue; |
|
120 | + } |
|
121 | + $file = str_replace('//','/',$path.'/'.$filename); |
|
122 | + CKFinder_Connector_Utils_FileSystem::unlink($file); |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /* Remove the parent dir */ |
|
127 | + if(!@rmdir($path)) { |
|
128 | + return false; |
|
129 | + } |
|
130 | + |
|
131 | + return true; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Return file name without extension (without dot & last part after dot) |
|
136 | + * |
|
137 | + * @static |
|
138 | + * @access public |
|
139 | + * @param string $fileName |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public static function getFileNameWithoutExtension($fileName) |
|
143 | + { |
|
144 | + $dotPos = strrpos( $fileName, '.' ); |
|
145 | + if (false === $dotPos) { |
|
146 | + return $fileName; |
|
147 | + } |
|
148 | + |
|
149 | + return substr($fileName, 0, $dotPos); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Get file extension (only last part - e.g. extension of file.foo.bar.jpg = jpg) |
|
154 | + * |
|
155 | + * @static |
|
156 | + * @access public |
|
157 | + * @param string $fileName |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public static function getExtension( $fileName ) |
|
161 | + { |
|
162 | + $dotPos = strrpos( $fileName, '.' ); |
|
163 | + if (false === $dotPos) { |
|
164 | + return ""; |
|
165 | + } |
|
166 | + |
|
167 | + return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | 171 | * Read file, split it into small chunks and send it to the browser |
172 | 172 | * |
173 | - * @static |
|
174 | - * @access public |
|
173 | + * @static |
|
174 | + * @access public |
|
175 | 175 | * @param string $filename |
176 | 176 | * @return boolean |
177 | 177 | */ |
178 | - public static function readfileChunked($filename) |
|
179 | - { |
|
180 | - $chunksize = 1024 * 10; // how many bytes per chunk |
|
181 | - |
|
182 | - $handle = fopen($filename, 'rb'); |
|
183 | - if ($handle === false) { |
|
184 | - return false; |
|
185 | - } |
|
186 | - while (!feof($handle)) { |
|
187 | - echo fread($handle, $chunksize); |
|
188 | - @ob_flush(); |
|
189 | - flush(); |
|
190 | - @set_time_limit(8); |
|
191 | - } |
|
192 | - fclose($handle); |
|
193 | - return true; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Replace accented UTF-8 characters by unaccented ASCII-7 "equivalents". |
|
198 | - * The purpose of this function is to replace characters commonly found in Latin |
|
199 | - * alphabets with something more or less equivalent from the ASCII range. This can |
|
200 | - * be useful for converting a UTF-8 to something ready for a filename, for example. |
|
201 | - * Following the use of this function, you would probably also pass the string |
|
202 | - * through utf8_strip_non_ascii to clean out any other non-ASCII chars |
|
203 | - * |
|
204 | - * For a more complete implementation of transliteration, see the utf8_to_ascii package |
|
205 | - * available from the phputf8 project downloads: |
|
206 | - * http://prdownloads.sourceforge.net/phputf8 |
|
207 | - * |
|
208 | - * @param string UTF-8 string |
|
209 | - * @param string UTF-8 with accented characters replaced by ASCII chars |
|
210 | - * @return string accented chars replaced with ascii equivalents |
|
211 | - * @author Andreas Gohr <[email protected]> |
|
212 | - * @see http://sourceforge.net/projects/phputf8/ |
|
213 | - */ |
|
214 | - public static function convertToAscii($str) |
|
215 | - { |
|
216 | - static $UTF8_LOWER_ACCENTS = NULL; |
|
217 | - static $UTF8_UPPER_ACCENTS = NULL; |
|
218 | - |
|
219 | - if ( is_null($UTF8_LOWER_ACCENTS) ) { |
|
220 | - $UTF8_LOWER_ACCENTS = array( |
|
178 | + public static function readfileChunked($filename) |
|
179 | + { |
|
180 | + $chunksize = 1024 * 10; // how many bytes per chunk |
|
181 | + |
|
182 | + $handle = fopen($filename, 'rb'); |
|
183 | + if ($handle === false) { |
|
184 | + return false; |
|
185 | + } |
|
186 | + while (!feof($handle)) { |
|
187 | + echo fread($handle, $chunksize); |
|
188 | + @ob_flush(); |
|
189 | + flush(); |
|
190 | + @set_time_limit(8); |
|
191 | + } |
|
192 | + fclose($handle); |
|
193 | + return true; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Replace accented UTF-8 characters by unaccented ASCII-7 "equivalents". |
|
198 | + * The purpose of this function is to replace characters commonly found in Latin |
|
199 | + * alphabets with something more or less equivalent from the ASCII range. This can |
|
200 | + * be useful for converting a UTF-8 to something ready for a filename, for example. |
|
201 | + * Following the use of this function, you would probably also pass the string |
|
202 | + * through utf8_strip_non_ascii to clean out any other non-ASCII chars |
|
203 | + * |
|
204 | + * For a more complete implementation of transliteration, see the utf8_to_ascii package |
|
205 | + * available from the phputf8 project downloads: |
|
206 | + * http://prdownloads.sourceforge.net/phputf8 |
|
207 | + * |
|
208 | + * @param string UTF-8 string |
|
209 | + * @param string UTF-8 with accented characters replaced by ASCII chars |
|
210 | + * @return string accented chars replaced with ascii equivalents |
|
211 | + * @author Andreas Gohr <[email protected]> |
|
212 | + * @see http://sourceforge.net/projects/phputf8/ |
|
213 | + */ |
|
214 | + public static function convertToAscii($str) |
|
215 | + { |
|
216 | + static $UTF8_LOWER_ACCENTS = NULL; |
|
217 | + static $UTF8_UPPER_ACCENTS = NULL; |
|
218 | + |
|
219 | + if ( is_null($UTF8_LOWER_ACCENTS) ) { |
|
220 | + $UTF8_LOWER_ACCENTS = array( |
|
221 | 221 | 'à' => 'a', 'ô' => 'o', 'ď' => 'd', 'ḟ' => 'f', 'ë' => 'e', 'š' => 's', 'ơ' => 'o', |
222 | 222 | 'ß' => 'ss', 'ă' => 'a', 'ř' => 'r', 'ț' => 't', 'ň' => 'n', 'ā' => 'a', 'ķ' => 'k', |
223 | 223 | 'ŝ' => 's', 'ỳ' => 'y', 'ņ' => 'n', 'ĺ' => 'l', 'ħ' => 'h', 'ṗ' => 'p', 'ó' => 'o', |
@@ -233,17 +233,17 @@ discard block |
||
233 | 233 | 'â' => 'a', 'ľ' => 'l', 'ẅ' => 'w', 'ż' => 'z', 'ī' => 'i', 'ã' => 'a', 'ġ' => 'g', |
234 | 234 | 'ṁ' => 'm', 'ō' => 'o', 'ĩ' => 'i', 'ù' => 'u', 'į' => 'i', 'ź' => 'z', 'á' => 'a', |
235 | 235 | 'û' => 'u', 'þ' => 'th', 'ð' => 'dh', 'æ' => 'ae', 'µ' => 'u', 'ĕ' => 'e', |
236 | - ); |
|
237 | - } |
|
236 | + ); |
|
237 | + } |
|
238 | 238 | |
239 | - $str = str_replace( |
|
240 | - array_keys($UTF8_LOWER_ACCENTS), |
|
241 | - array_values($UTF8_LOWER_ACCENTS), |
|
242 | - $str |
|
243 | - ); |
|
239 | + $str = str_replace( |
|
240 | + array_keys($UTF8_LOWER_ACCENTS), |
|
241 | + array_values($UTF8_LOWER_ACCENTS), |
|
242 | + $str |
|
243 | + ); |
|
244 | 244 | |
245 | - if ( is_null($UTF8_UPPER_ACCENTS) ) { |
|
246 | - $UTF8_UPPER_ACCENTS = array( |
|
245 | + if ( is_null($UTF8_UPPER_ACCENTS) ) { |
|
246 | + $UTF8_UPPER_ACCENTS = array( |
|
247 | 247 | 'À' => 'A', 'Ô' => 'O', 'Ď' => 'D', 'Ḟ' => 'F', 'Ë' => 'E', 'Š' => 'S', 'Ơ' => 'O', |
248 | 248 | 'Ă' => 'A', 'Ř' => 'R', 'Ț' => 'T', 'Ň' => 'N', 'Ā' => 'A', 'Ķ' => 'K', |
249 | 249 | 'Ŝ' => 'S', 'Ỳ' => 'Y', 'Ņ' => 'N', 'Ĺ' => 'L', 'Ħ' => 'H', 'Ṗ' => 'P', 'Ó' => 'O', |
@@ -259,291 +259,291 @@ discard block |
||
259 | 259 | 'Â' => 'A', 'Ľ' => 'L', 'Ẅ' => 'W', 'Ż' => 'Z', 'Ī' => 'I', 'Ã' => 'A', 'Ġ' => 'G', |
260 | 260 | 'Ṁ' => 'M', 'Ō' => 'O', 'Ĩ' => 'I', 'Ù' => 'U', 'Į' => 'I', 'Ź' => 'Z', 'Á' => 'A', |
261 | 261 | 'Û' => 'U', 'Þ' => 'Th', 'Ð' => 'Dh', 'Æ' => 'Ae', 'Ĕ' => 'E', |
262 | - ); |
|
263 | - } |
|
264 | - $str = str_replace( |
|
265 | - array_keys($UTF8_UPPER_ACCENTS), |
|
266 | - array_values($UTF8_UPPER_ACCENTS), |
|
267 | - $str |
|
268 | - ); |
|
269 | - return $str; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Convert file name from UTF-8 to system encoding |
|
274 | - * |
|
275 | - * @static |
|
276 | - * @access public |
|
277 | - * @param string $fileName |
|
278 | - * @return string |
|
279 | - */ |
|
280 | - public static function convertToFilesystemEncoding($fileName) |
|
281 | - { |
|
282 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
283 | - $encoding = $_config->getFilesystemEncoding(); |
|
284 | - if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { |
|
285 | - return $fileName; |
|
286 | - } |
|
287 | - |
|
288 | - if (!function_exists("iconv")) { |
|
289 | - if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) { |
|
290 | - return str_replace("\0", "_", utf8_decode($fileName)); |
|
291 | - } else if (function_exists('mb_convert_encoding')) { |
|
292 | - |
|
293 | - $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8'); |
|
294 | - if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) { |
|
295 | - return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
|
296 | - } |
|
297 | - else { |
|
298 | - return str_replace("\0", "_", $encoded); |
|
299 | - } |
|
300 | - } else { |
|
301 | - return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName); |
|
306 | - if ($converted === false) { |
|
307 | - return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
|
308 | - } |
|
309 | - |
|
310 | - return $converted; |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Convert file name from system encoding into UTF-8 |
|
315 | - * |
|
316 | - * @static |
|
317 | - * @access public |
|
318 | - * @param string $fileName |
|
319 | - * @return string |
|
320 | - */ |
|
321 | - public static function convertToConnectorEncoding($fileName) |
|
322 | - { |
|
323 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
324 | - $encoding = $_config->getFilesystemEncoding(); |
|
325 | - if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { |
|
326 | - return $fileName; |
|
327 | - } |
|
328 | - |
|
329 | - if (!function_exists("iconv")) { |
|
330 | - if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) { |
|
331 | - return utf8_encode($fileName); |
|
332 | - } else { |
|
333 | - return $fileName; |
|
334 | - } |
|
335 | - } |
|
336 | - |
|
337 | - $converted = @iconv($encoding, "UTF-8", $fileName); |
|
338 | - |
|
339 | - if ($converted === false) { |
|
340 | - return $fileName; |
|
341 | - } |
|
342 | - |
|
343 | - return $converted; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Find document root |
|
348 | - * |
|
349 | - * @return string |
|
350 | - * @access public |
|
351 | - */ |
|
352 | - public function getDocumentRootPath() |
|
353 | - { |
|
354 | - /** |
|
355 | - * The absolute pathname of the currently executing script. |
|
356 | - * Notatka: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, |
|
357 | - * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user. |
|
358 | - */ |
|
359 | - if (isset($_SERVER['SCRIPT_FILENAME'])) { |
|
360 | - $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']); |
|
361 | - } |
|
362 | - else { |
|
363 | - /** |
|
364 | - * realpath — Returns canonicalized absolute pathname |
|
365 | - */ |
|
366 | - $sRealPath = realpath( './' ) ; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * The filename of the currently executing script, relative to the document root. |
|
371 | - * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar |
|
372 | - * would be /test.php/foo.bar. |
|
373 | - */ |
|
374 | - $sSelfPath = dirname($_SERVER['PHP_SELF']); |
|
375 | - |
|
376 | - return substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath)); |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Create directory recursively |
|
381 | - * |
|
382 | - * @access public |
|
383 | - * @static |
|
384 | - * @param string $dir |
|
385 | - * @return boolean |
|
386 | - */ |
|
387 | - public static function createDirectoryRecursively($dir) |
|
388 | - { |
|
389 | - if (DIRECTORY_SEPARATOR === "\\") { |
|
390 | - $dir = str_replace("/", "\\", $dir); |
|
391 | - } |
|
392 | - else if (DIRECTORY_SEPARATOR === "/") { |
|
393 | - $dir = str_replace("\\", "/", $dir); |
|
394 | - } |
|
395 | - |
|
396 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
397 | - if ($perms = $_config->getChmodFolders()) { |
|
398 | - $oldUmask = umask(0); |
|
399 | - $bCreated = @mkdir($dir, $perms, true); |
|
400 | - umask($oldUmask); |
|
401 | - } |
|
402 | - else { |
|
403 | - $bCreated = @mkdir($dir, 0777, true); |
|
404 | - } |
|
405 | - |
|
406 | - return $bCreated; |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Detect HTML in the first KB to prevent against potential security issue with |
|
411 | - * IE/Safari/Opera file type auto detection bug. |
|
412 | - * Returns true if file contain insecure HTML code at the beginning. |
|
413 | - * |
|
414 | - * @static |
|
415 | - * @access public |
|
416 | - * @param string $filePath absolute path to file |
|
417 | - * @return boolean |
|
418 | - */ |
|
419 | - public static function detectHtml($filePath) |
|
420 | - { |
|
421 | - $fp = @fopen($filePath, 'rb'); |
|
422 | - if ( $fp === false || !flock( $fp, LOCK_SH ) ) { |
|
423 | - return -1 ; |
|
424 | - } |
|
425 | - $chunk = fread($fp, 1024); |
|
426 | - flock( $fp, LOCK_UN ) ; |
|
427 | - fclose($fp); |
|
428 | - |
|
429 | - $chunk = strtolower($chunk); |
|
430 | - |
|
431 | - if (!$chunk) { |
|
432 | - return false; |
|
433 | - } |
|
434 | - |
|
435 | - $chunk = trim($chunk); |
|
436 | - |
|
437 | - if (preg_match("/<!DOCTYPE\W*X?HTML/sim", $chunk)) { |
|
438 | - return true; |
|
439 | - } |
|
440 | - |
|
441 | - $tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title'); |
|
442 | - |
|
443 | - foreach( $tags as $tag ) { |
|
444 | - if(false !== strpos($chunk, $tag)) { |
|
445 | - return true ; |
|
446 | - } |
|
447 | - } |
|
448 | - |
|
449 | - //type = javascript |
|
450 | - if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) { |
|
451 | - return true ; |
|
452 | - } |
|
453 | - |
|
454 | - //href = javascript |
|
455 | - //src = javascript |
|
456 | - //data = javascript |
|
457 | - if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) { |
|
458 | - return true ; |
|
459 | - } |
|
460 | - |
|
461 | - //url(javascript |
|
462 | - if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) { |
|
463 | - return true ; |
|
464 | - } |
|
465 | - |
|
466 | - return false ; |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * Check file content. |
|
471 | - * Currently this function validates only image files. |
|
472 | - * Returns false if file is invalid. |
|
473 | - * |
|
474 | - * @static |
|
475 | - * @access public |
|
476 | - * @param string $filePath absolute path to file |
|
477 | - * @param string $extension file extension |
|
478 | - * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images |
|
479 | - * @return boolean |
|
480 | - */ |
|
481 | - public static function isImageValid($filePath, $extension) |
|
482 | - { |
|
483 | - if (!@is_readable($filePath)) { |
|
484 | - return -1; |
|
485 | - } |
|
486 | - |
|
487 | - $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff'); |
|
488 | - |
|
489 | - // version_compare is available since PHP4 >= 4.0.7 |
|
490 | - if ( function_exists( 'version_compare' ) ) { |
|
491 | - $sCurrentVersion = phpversion(); |
|
492 | - if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) { |
|
493 | - $imageCheckExtensions[] = "tiff"; |
|
494 | - $imageCheckExtensions[] = "tif"; |
|
495 | - } |
|
496 | - if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) { |
|
497 | - $imageCheckExtensions[] = "swc"; |
|
498 | - } |
|
499 | - if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) { |
|
500 | - $imageCheckExtensions[] = "jpc"; |
|
501 | - $imageCheckExtensions[] = "jp2"; |
|
502 | - $imageCheckExtensions[] = "jpx"; |
|
503 | - $imageCheckExtensions[] = "jb2"; |
|
504 | - $imageCheckExtensions[] = "xbm"; |
|
505 | - $imageCheckExtensions[] = "wbmp"; |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - if ( !in_array( $extension, $imageCheckExtensions ) ) { |
|
510 | - return true; |
|
511 | - } |
|
512 | - |
|
513 | - if ( @getimagesize( $filePath ) === false ) { |
|
514 | - return false ; |
|
515 | - } |
|
516 | - |
|
517 | - return true; |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Returns true if directory is not empty |
|
522 | - * |
|
523 | - * @access public |
|
524 | - * @static |
|
525 | - * @param string $serverPath |
|
526 | - * @return boolean |
|
527 | - */ |
|
528 | - public static function hasChildren($serverPath) |
|
529 | - { |
|
530 | - if (!is_dir($serverPath) || (false === $fh = @opendir($serverPath))) { |
|
531 | - return false; |
|
532 | - } |
|
533 | - |
|
534 | - $hasChildren = false; |
|
535 | - while (false !== ($filename = readdir($fh))) { |
|
536 | - if ($filename == '.' || $filename == '..') { |
|
537 | - continue; |
|
538 | - } else if (is_dir($serverPath . DIRECTORY_SEPARATOR . $filename)) { |
|
539 | - //we have found valid directory |
|
540 | - $hasChildren = true; |
|
541 | - break; |
|
542 | - } |
|
543 | - } |
|
544 | - |
|
545 | - closedir($fh); |
|
546 | - |
|
547 | - return $hasChildren; |
|
548 | - } |
|
262 | + ); |
|
263 | + } |
|
264 | + $str = str_replace( |
|
265 | + array_keys($UTF8_UPPER_ACCENTS), |
|
266 | + array_values($UTF8_UPPER_ACCENTS), |
|
267 | + $str |
|
268 | + ); |
|
269 | + return $str; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Convert file name from UTF-8 to system encoding |
|
274 | + * |
|
275 | + * @static |
|
276 | + * @access public |
|
277 | + * @param string $fileName |
|
278 | + * @return string |
|
279 | + */ |
|
280 | + public static function convertToFilesystemEncoding($fileName) |
|
281 | + { |
|
282 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
283 | + $encoding = $_config->getFilesystemEncoding(); |
|
284 | + if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { |
|
285 | + return $fileName; |
|
286 | + } |
|
287 | + |
|
288 | + if (!function_exists("iconv")) { |
|
289 | + if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) { |
|
290 | + return str_replace("\0", "_", utf8_decode($fileName)); |
|
291 | + } else if (function_exists('mb_convert_encoding')) { |
|
292 | + |
|
293 | + $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8'); |
|
294 | + if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) { |
|
295 | + return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
|
296 | + } |
|
297 | + else { |
|
298 | + return str_replace("\0", "_", $encoded); |
|
299 | + } |
|
300 | + } else { |
|
301 | + return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName); |
|
306 | + if ($converted === false) { |
|
307 | + return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
|
308 | + } |
|
309 | + |
|
310 | + return $converted; |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Convert file name from system encoding into UTF-8 |
|
315 | + * |
|
316 | + * @static |
|
317 | + * @access public |
|
318 | + * @param string $fileName |
|
319 | + * @return string |
|
320 | + */ |
|
321 | + public static function convertToConnectorEncoding($fileName) |
|
322 | + { |
|
323 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
324 | + $encoding = $_config->getFilesystemEncoding(); |
|
325 | + if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { |
|
326 | + return $fileName; |
|
327 | + } |
|
328 | + |
|
329 | + if (!function_exists("iconv")) { |
|
330 | + if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) { |
|
331 | + return utf8_encode($fileName); |
|
332 | + } else { |
|
333 | + return $fileName; |
|
334 | + } |
|
335 | + } |
|
336 | + |
|
337 | + $converted = @iconv($encoding, "UTF-8", $fileName); |
|
338 | + |
|
339 | + if ($converted === false) { |
|
340 | + return $fileName; |
|
341 | + } |
|
342 | + |
|
343 | + return $converted; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Find document root |
|
348 | + * |
|
349 | + * @return string |
|
350 | + * @access public |
|
351 | + */ |
|
352 | + public function getDocumentRootPath() |
|
353 | + { |
|
354 | + /** |
|
355 | + * The absolute pathname of the currently executing script. |
|
356 | + * Notatka: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, |
|
357 | + * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user. |
|
358 | + */ |
|
359 | + if (isset($_SERVER['SCRIPT_FILENAME'])) { |
|
360 | + $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']); |
|
361 | + } |
|
362 | + else { |
|
363 | + /** |
|
364 | + * realpath — Returns canonicalized absolute pathname |
|
365 | + */ |
|
366 | + $sRealPath = realpath( './' ) ; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * The filename of the currently executing script, relative to the document root. |
|
371 | + * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar |
|
372 | + * would be /test.php/foo.bar. |
|
373 | + */ |
|
374 | + $sSelfPath = dirname($_SERVER['PHP_SELF']); |
|
375 | + |
|
376 | + return substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath)); |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Create directory recursively |
|
381 | + * |
|
382 | + * @access public |
|
383 | + * @static |
|
384 | + * @param string $dir |
|
385 | + * @return boolean |
|
386 | + */ |
|
387 | + public static function createDirectoryRecursively($dir) |
|
388 | + { |
|
389 | + if (DIRECTORY_SEPARATOR === "\\") { |
|
390 | + $dir = str_replace("/", "\\", $dir); |
|
391 | + } |
|
392 | + else if (DIRECTORY_SEPARATOR === "/") { |
|
393 | + $dir = str_replace("\\", "/", $dir); |
|
394 | + } |
|
395 | + |
|
396 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
397 | + if ($perms = $_config->getChmodFolders()) { |
|
398 | + $oldUmask = umask(0); |
|
399 | + $bCreated = @mkdir($dir, $perms, true); |
|
400 | + umask($oldUmask); |
|
401 | + } |
|
402 | + else { |
|
403 | + $bCreated = @mkdir($dir, 0777, true); |
|
404 | + } |
|
405 | + |
|
406 | + return $bCreated; |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Detect HTML in the first KB to prevent against potential security issue with |
|
411 | + * IE/Safari/Opera file type auto detection bug. |
|
412 | + * Returns true if file contain insecure HTML code at the beginning. |
|
413 | + * |
|
414 | + * @static |
|
415 | + * @access public |
|
416 | + * @param string $filePath absolute path to file |
|
417 | + * @return boolean |
|
418 | + */ |
|
419 | + public static function detectHtml($filePath) |
|
420 | + { |
|
421 | + $fp = @fopen($filePath, 'rb'); |
|
422 | + if ( $fp === false || !flock( $fp, LOCK_SH ) ) { |
|
423 | + return -1 ; |
|
424 | + } |
|
425 | + $chunk = fread($fp, 1024); |
|
426 | + flock( $fp, LOCK_UN ) ; |
|
427 | + fclose($fp); |
|
428 | + |
|
429 | + $chunk = strtolower($chunk); |
|
430 | + |
|
431 | + if (!$chunk) { |
|
432 | + return false; |
|
433 | + } |
|
434 | + |
|
435 | + $chunk = trim($chunk); |
|
436 | + |
|
437 | + if (preg_match("/<!DOCTYPE\W*X?HTML/sim", $chunk)) { |
|
438 | + return true; |
|
439 | + } |
|
440 | + |
|
441 | + $tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title'); |
|
442 | + |
|
443 | + foreach( $tags as $tag ) { |
|
444 | + if(false !== strpos($chunk, $tag)) { |
|
445 | + return true ; |
|
446 | + } |
|
447 | + } |
|
448 | + |
|
449 | + //type = javascript |
|
450 | + if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) { |
|
451 | + return true ; |
|
452 | + } |
|
453 | + |
|
454 | + //href = javascript |
|
455 | + //src = javascript |
|
456 | + //data = javascript |
|
457 | + if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) { |
|
458 | + return true ; |
|
459 | + } |
|
460 | + |
|
461 | + //url(javascript |
|
462 | + if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) { |
|
463 | + return true ; |
|
464 | + } |
|
465 | + |
|
466 | + return false ; |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * Check file content. |
|
471 | + * Currently this function validates only image files. |
|
472 | + * Returns false if file is invalid. |
|
473 | + * |
|
474 | + * @static |
|
475 | + * @access public |
|
476 | + * @param string $filePath absolute path to file |
|
477 | + * @param string $extension file extension |
|
478 | + * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images |
|
479 | + * @return boolean |
|
480 | + */ |
|
481 | + public static function isImageValid($filePath, $extension) |
|
482 | + { |
|
483 | + if (!@is_readable($filePath)) { |
|
484 | + return -1; |
|
485 | + } |
|
486 | + |
|
487 | + $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff'); |
|
488 | + |
|
489 | + // version_compare is available since PHP4 >= 4.0.7 |
|
490 | + if ( function_exists( 'version_compare' ) ) { |
|
491 | + $sCurrentVersion = phpversion(); |
|
492 | + if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) { |
|
493 | + $imageCheckExtensions[] = "tiff"; |
|
494 | + $imageCheckExtensions[] = "tif"; |
|
495 | + } |
|
496 | + if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) { |
|
497 | + $imageCheckExtensions[] = "swc"; |
|
498 | + } |
|
499 | + if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) { |
|
500 | + $imageCheckExtensions[] = "jpc"; |
|
501 | + $imageCheckExtensions[] = "jp2"; |
|
502 | + $imageCheckExtensions[] = "jpx"; |
|
503 | + $imageCheckExtensions[] = "jb2"; |
|
504 | + $imageCheckExtensions[] = "xbm"; |
|
505 | + $imageCheckExtensions[] = "wbmp"; |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + if ( !in_array( $extension, $imageCheckExtensions ) ) { |
|
510 | + return true; |
|
511 | + } |
|
512 | + |
|
513 | + if ( @getimagesize( $filePath ) === false ) { |
|
514 | + return false ; |
|
515 | + } |
|
516 | + |
|
517 | + return true; |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Returns true if directory is not empty |
|
522 | + * |
|
523 | + * @access public |
|
524 | + * @static |
|
525 | + * @param string $serverPath |
|
526 | + * @return boolean |
|
527 | + */ |
|
528 | + public static function hasChildren($serverPath) |
|
529 | + { |
|
530 | + if (!is_dir($serverPath) || (false === $fh = @opendir($serverPath))) { |
|
531 | + return false; |
|
532 | + } |
|
533 | + |
|
534 | + $hasChildren = false; |
|
535 | + while (false !== ($filename = readdir($fh))) { |
|
536 | + if ($filename == '.' || $filename == '..') { |
|
537 | + continue; |
|
538 | + } else if (is_dir($serverPath . DIRECTORY_SEPARATOR . $filename)) { |
|
539 | + //we have found valid directory |
|
540 | + $hasChildren = true; |
|
541 | + break; |
|
542 | + } |
|
543 | + } |
|
544 | + |
|
545 | + closedir($fh); |
|
546 | + |
|
547 | + return $hasChildren; |
|
548 | + } |
|
549 | 549 | } |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public static function combinePaths($path1, $path2) |
39 | 39 | { |
40 | - if (is_null($path1)) { |
|
40 | + if (is_null($path1)) { |
|
41 | 41 | $path1 = ""; |
42 | 42 | } |
43 | - if (is_null($path2)) { |
|
43 | + if (is_null($path2)) { |
|
44 | 44 | $path2 = ""; |
45 | 45 | } |
46 | 46 | if (!strlen($path2)) { |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | else { |
55 | 55 | $_firstCharP2 = substr($path2, 0, 1); |
56 | 56 | if (strlen($path1)) { |
57 | - if (strpos($path2, $path1)===0) { |
|
57 | + if (strpos($path2, $path1) === 0) { |
|
58 | 58 | return $path2; |
59 | 59 | } |
60 | 60 | $_lastCharP1 = substr($path1, -1, 1); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | return $path2; |
67 | 67 | } |
68 | 68 | } |
69 | - return $path1 . $path2; |
|
69 | + return $path1.$path2; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public static function checkFileName($fileName) |
81 | 81 | { |
82 | - if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) { |
|
82 | + if (is_null($fileName) || !strlen($fileName) || substr($fileName, -1, 1) == "." || false !== strpos($fileName, "..")) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
@@ -101,30 +101,30 @@ discard block |
||
101 | 101 | public static function unlink($path) |
102 | 102 | { |
103 | 103 | /* make sure the path exists */ |
104 | - if(!file_exists($path)) { |
|
104 | + if (!file_exists($path)) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
108 | 108 | /* If it is a file or link, just delete it */ |
109 | - if(is_file($path) || is_link($path)) { |
|
109 | + if (is_file($path) || is_link($path)) { |
|
110 | 110 | return @unlink($path); |
111 | 111 | } |
112 | 112 | |
113 | 113 | /* Scan the dir and recursively unlink */ |
114 | 114 | $files = scandir($path); |
115 | 115 | if ($files) { |
116 | - foreach($files as $filename) |
|
116 | + foreach ($files as $filename) |
|
117 | 117 | { |
118 | 118 | if ($filename == '.' || $filename == '..') { |
119 | 119 | continue; |
120 | 120 | } |
121 | - $file = str_replace('//','/',$path.'/'.$filename); |
|
121 | + $file = str_replace('//', '/', $path.'/'.$filename); |
|
122 | 122 | CKFinder_Connector_Utils_FileSystem::unlink($file); |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | 126 | /* Remove the parent dir */ |
127 | - if(!@rmdir($path)) { |
|
127 | + if (!@rmdir($path)) { |
|
128 | 128 | return false; |
129 | 129 | } |
130 | 130 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public static function getFileNameWithoutExtension($fileName) |
143 | 143 | { |
144 | - $dotPos = strrpos( $fileName, '.' ); |
|
144 | + $dotPos = strrpos($fileName, '.'); |
|
145 | 145 | if (false === $dotPos) { |
146 | 146 | return $fileName; |
147 | 147 | } |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | * @param string $fileName |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - public static function getExtension( $fileName ) |
|
160 | + public static function getExtension($fileName) |
|
161 | 161 | { |
162 | - $dotPos = strrpos( $fileName, '.' ); |
|
162 | + $dotPos = strrpos($fileName, '.'); |
|
163 | 163 | if (false === $dotPos) { |
164 | 164 | return ""; |
165 | 165 | } |
166 | 166 | |
167 | - return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ; |
|
167 | + return substr($fileName, strrpos($fileName, '.') + 1); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | static $UTF8_LOWER_ACCENTS = NULL; |
217 | 217 | static $UTF8_UPPER_ACCENTS = NULL; |
218 | 218 | |
219 | - if ( is_null($UTF8_LOWER_ACCENTS) ) { |
|
219 | + if (is_null($UTF8_LOWER_ACCENTS)) { |
|
220 | 220 | $UTF8_LOWER_ACCENTS = array( |
221 | 221 | 'à' => 'a', 'ô' => 'o', 'ď' => 'd', 'ḟ' => 'f', 'ë' => 'e', 'š' => 's', 'ơ' => 'o', |
222 | 222 | 'ß' => 'ss', 'ă' => 'a', 'ř' => 'r', 'ț' => 't', 'ň' => 'n', 'ā' => 'a', 'ķ' => 'k', |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | $str |
243 | 243 | ); |
244 | 244 | |
245 | - if ( is_null($UTF8_UPPER_ACCENTS) ) { |
|
245 | + if (is_null($UTF8_UPPER_ACCENTS)) { |
|
246 | 246 | $UTF8_UPPER_ACCENTS = array( |
247 | 247 | 'À' => 'A', 'Ô' => 'O', 'Ď' => 'D', 'Ḟ' => 'F', 'Ë' => 'E', 'Š' => 'S', 'Ơ' => 'O', |
248 | 248 | 'Ă' => 'A', 'Ř' => 'R', 'Ț' => 'T', 'Ň' => 'N', 'Ā' => 'A', 'Ķ' => 'K', |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public static function convertToFilesystemEncoding($fileName) |
281 | 281 | { |
282 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
282 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
283 | 283 | $encoding = $_config->getFilesystemEncoding(); |
284 | 284 | if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { |
285 | 285 | return $fileName; |
@@ -292,19 +292,19 @@ discard block |
||
292 | 292 | |
293 | 293 | $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8'); |
294 | 294 | if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) { |
295 | - return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
|
295 | + return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u", "_", $fileName)); |
|
296 | 296 | } |
297 | 297 | else { |
298 | 298 | return str_replace("\0", "_", $encoded); |
299 | 299 | } |
300 | 300 | } else { |
301 | - return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
|
301 | + return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u", "_", $fileName)); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | - $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName); |
|
305 | + $converted = @iconv("UTF-8", $encoding."//IGNORE//TRANSLIT", $fileName); |
|
306 | 306 | if ($converted === false) { |
307 | - return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
|
307 | + return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u", "_", $fileName)); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | return $converted; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public static function convertToConnectorEncoding($fileName) |
322 | 322 | { |
323 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
323 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
324 | 324 | $encoding = $_config->getFilesystemEncoding(); |
325 | 325 | if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { |
326 | 326 | return $fileName; |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | /** |
364 | 364 | * realpath — Returns canonicalized absolute pathname |
365 | 365 | */ |
366 | - $sRealPath = realpath( './' ) ; |
|
366 | + $sRealPath = realpath('./'); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | $dir = str_replace("\\", "/", $dir); |
394 | 394 | } |
395 | 395 | |
396 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
396 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
397 | 397 | if ($perms = $_config->getChmodFolders()) { |
398 | 398 | $oldUmask = umask(0); |
399 | 399 | $bCreated = @mkdir($dir, $perms, true); |
@@ -419,11 +419,11 @@ discard block |
||
419 | 419 | public static function detectHtml($filePath) |
420 | 420 | { |
421 | 421 | $fp = @fopen($filePath, 'rb'); |
422 | - if ( $fp === false || !flock( $fp, LOCK_SH ) ) { |
|
423 | - return -1 ; |
|
422 | + if ($fp === false || !flock($fp, LOCK_SH)) { |
|
423 | + return -1; |
|
424 | 424 | } |
425 | 425 | $chunk = fread($fp, 1024); |
426 | - flock( $fp, LOCK_UN ) ; |
|
426 | + flock($fp, LOCK_UN); |
|
427 | 427 | fclose($fp); |
428 | 428 | |
429 | 429 | $chunk = strtolower($chunk); |
@@ -440,30 +440,30 @@ discard block |
||
440 | 440 | |
441 | 441 | $tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title'); |
442 | 442 | |
443 | - foreach( $tags as $tag ) { |
|
444 | - if(false !== strpos($chunk, $tag)) { |
|
445 | - return true ; |
|
443 | + foreach ($tags as $tag) { |
|
444 | + if (false !== strpos($chunk, $tag)) { |
|
445 | + return true; |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | |
449 | 449 | //type = javascript |
450 | 450 | if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) { |
451 | - return true ; |
|
451 | + return true; |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | //href = javascript |
455 | 455 | //src = javascript |
456 | 456 | //data = javascript |
457 | - if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) { |
|
458 | - return true ; |
|
457 | + if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) { |
|
458 | + return true; |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | //url(javascript |
462 | 462 | if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) { |
463 | - return true ; |
|
463 | + return true; |
|
464 | 464 | } |
465 | 465 | |
466 | - return false ; |
|
466 | + return false; |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -487,16 +487,16 @@ discard block |
||
487 | 487 | $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff'); |
488 | 488 | |
489 | 489 | // version_compare is available since PHP4 >= 4.0.7 |
490 | - if ( function_exists( 'version_compare' ) ) { |
|
490 | + if (function_exists('version_compare')) { |
|
491 | 491 | $sCurrentVersion = phpversion(); |
492 | - if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) { |
|
492 | + if (version_compare($sCurrentVersion, "4.2.0") >= 0) { |
|
493 | 493 | $imageCheckExtensions[] = "tiff"; |
494 | 494 | $imageCheckExtensions[] = "tif"; |
495 | 495 | } |
496 | - if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) { |
|
496 | + if (version_compare($sCurrentVersion, "4.3.0") >= 0) { |
|
497 | 497 | $imageCheckExtensions[] = "swc"; |
498 | 498 | } |
499 | - if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) { |
|
499 | + if (version_compare($sCurrentVersion, "4.3.2") >= 0) { |
|
500 | 500 | $imageCheckExtensions[] = "jpc"; |
501 | 501 | $imageCheckExtensions[] = "jp2"; |
502 | 502 | $imageCheckExtensions[] = "jpx"; |
@@ -506,12 +506,12 @@ discard block |
||
506 | 506 | } |
507 | 507 | } |
508 | 508 | |
509 | - if ( !in_array( $extension, $imageCheckExtensions ) ) { |
|
509 | + if (!in_array($extension, $imageCheckExtensions)) { |
|
510 | 510 | return true; |
511 | 511 | } |
512 | 512 | |
513 | - if ( @getimagesize( $filePath ) === false ) { |
|
514 | - return false ; |
|
513 | + if (@getimagesize($filePath) === false) { |
|
514 | + return false; |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | return true; |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | while (false !== ($filename = readdir($fh))) { |
536 | 536 | if ($filename == '.' || $filename == '..') { |
537 | 537 | continue; |
538 | - } else if (is_dir($serverPath . DIRECTORY_SEPARATOR . $filename)) { |
|
538 | + } else if (is_dir($serverPath.DIRECTORY_SEPARATOR.$filename)) { |
|
539 | 539 | //we have found valid directory |
540 | 540 | $hasChildren = true; |
541 | 541 | break; |
@@ -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 |
@@ -50,8 +52,7 @@ discard block |
||
50 | 52 | $path1 .= DIRECTORY_SEPARATOR; |
51 | 53 | } |
52 | 54 | } |
53 | - } |
|
54 | - else { |
|
55 | + } else { |
|
55 | 56 | $_firstCharP2 = substr($path2, 0, 1); |
56 | 57 | if (strlen($path1)) { |
57 | 58 | if (strpos($path2, $path1)===0) { |
@@ -61,8 +62,7 @@ discard block |
||
61 | 62 | if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") { |
62 | 63 | $path1 .= DIRECTORY_SEPARATOR; |
63 | 64 | } |
64 | - } |
|
65 | - else { |
|
65 | + } else { |
|
66 | 66 | return $path2; |
67 | 67 | } |
68 | 68 | } |
@@ -293,8 +293,7 @@ discard block |
||
293 | 293 | $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8'); |
294 | 294 | if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) { |
295 | 295 | return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); |
296 | - } |
|
297 | - else { |
|
296 | + } else { |
|
298 | 297 | return str_replace("\0", "_", $encoded); |
299 | 298 | } |
300 | 299 | } else { |
@@ -358,8 +357,7 @@ discard block |
||
358 | 357 | */ |
359 | 358 | if (isset($_SERVER['SCRIPT_FILENAME'])) { |
360 | 359 | $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']); |
361 | - } |
|
362 | - else { |
|
360 | + } else { |
|
363 | 361 | /** |
364 | 362 | * realpath — Returns canonicalized absolute pathname |
365 | 363 | */ |
@@ -388,8 +386,7 @@ discard block |
||
388 | 386 | { |
389 | 387 | if (DIRECTORY_SEPARATOR === "\\") { |
390 | 388 | $dir = str_replace("/", "\\", $dir); |
391 | - } |
|
392 | - else if (DIRECTORY_SEPARATOR === "/") { |
|
389 | + } else if (DIRECTORY_SEPARATOR === "/") { |
|
393 | 390 | $dir = str_replace("\\", "/", $dir); |
394 | 391 | } |
395 | 392 | |
@@ -398,8 +395,7 @@ discard block |
||
398 | 395 | $oldUmask = umask(0); |
399 | 396 | $bCreated = @mkdir($dir, $perms, true); |
400 | 397 | umask($oldUmask); |
401 | - } |
|
402 | - else { |
|
398 | + } else { |
|
403 | 399 | $bCreated = @mkdir($dir, 0777, true); |
404 | 400 | } |
405 | 401 |
@@ -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 | public static 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 | public static function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels) |
@@ -25,345 +25,345 @@ |
||
25 | 25 | */ |
26 | 26 | class CKFinder_Connector_Utils_Misc |
27 | 27 | { |
28 | - public static 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 | - public static 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 | - public static 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 | - public static 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 | - |
|
164 | - return true; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * convert shorthand php.ini notation into bytes, much like how the PHP source does it |
|
169 | - * @link http://pl.php.net/manual/en/function.ini-get.php |
|
170 | - * |
|
171 | - * @static |
|
172 | - * @access public |
|
173 | - * @param string $val |
|
174 | - * @return int |
|
175 | - */ |
|
176 | - public static function returnBytes($val) { |
|
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 | - public static 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 | - public static 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 | - public static 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 | + public static 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 | + public static 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 | + public static 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 | + public static 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 | + |
|
164 | + return true; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * convert shorthand php.ini notation into bytes, much like how the PHP source does it |
|
169 | + * @link http://pl.php.net/manual/en/function.ini-get.php |
|
170 | + * |
|
171 | + * @static |
|
172 | + * @access public |
|
173 | + * @param string $val |
|
174 | + * @return int |
|
175 | + */ |
|
176 | + public static function returnBytes($val) { |
|
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 | + public static 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 | + public static 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 | + public static 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 | public static 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 | - public static 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 | + public static 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 | public static 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 | public 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 | - private $_attributes = array(); |
|
37 | - /** |
|
38 | - * Array that stores child nodes |
|
39 | - * |
|
40 | - * @access private |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - private $_childNodes = array(); |
|
44 | - /** |
|
45 | - * Node name |
|
46 | - * |
|
47 | - * @access private |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - private $_name; |
|
51 | - /** |
|
52 | - * Node value |
|
53 | - * |
|
54 | - * @access private |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - private $_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 __construct($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 | - public 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 | - public 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 | - public 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 | - public 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 | - public 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 | - public 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 | + private $_attributes = array(); |
|
37 | + /** |
|
38 | + * Array that stores child nodes |
|
39 | + * |
|
40 | + * @access private |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + private $_childNodes = array(); |
|
44 | + /** |
|
45 | + * Node name |
|
46 | + * |
|
47 | + * @access private |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + private $_name; |
|
51 | + /** |
|
52 | + * Node value |
|
53 | + * |
|
54 | + * @access private |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + private $_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 __construct($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 | + public 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 | + public 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 | + public 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 | + public 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 | + public 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 | + public 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 |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @param object $filePathInfo |
98 | 98 | * @param string $originalFileName |
99 | - * @return mixed bool(false) - if security checks fails. Otherwise string - ralative zip archive path with secured filename. |
|
99 | + * @return false|string bool(false) - if security checks fails. Otherwise string - ralative zip archive path with secured filename. |
|
100 | 100 | */ |
101 | 101 | protected function checkOneFile($filePathInfo, $originalFileName ) |
102 | 102 | { |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | /** |
189 | 189 | * Add error node to the list |
190 | - * @param obj $oErrorsNode |
|
190 | + * @param Ckfinder_Connector_Utils_XmlNode $oErrorsNode |
|
191 | 191 | * @param int $errorCode |
192 | 192 | * @param string $name |
193 | 193 | * @param string $type |
@@ -30,65 +30,65 @@ discard block |
||
30 | 30 | */ |
31 | 31 | protected function buildXml() |
32 | 32 | { |
33 | - if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
34 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
35 | - } |
|
33 | + if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
34 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
35 | + } |
|
36 | 36 | |
37 | - if (!extension_loaded('zip')) { |
|
38 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_COMMAND); |
|
39 | - } |
|
37 | + if (!extension_loaded('zip')) { |
|
38 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_COMMAND); |
|
39 | + } |
|
40 | 40 | |
41 | - $this->checkConnector(); |
|
42 | - $this->checkRequest(); |
|
41 | + $this->checkConnector(); |
|
42 | + $this->checkRequest(); |
|
43 | 43 | |
44 | - if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
45 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
46 | - } |
|
44 | + if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
45 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
46 | + } |
|
47 | 47 | |
48 | - if (!isset($_POST["fileName"])) { |
|
49 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
50 | - } |
|
48 | + if (!isset($_POST["fileName"])) { |
|
49 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
50 | + } |
|
51 | 51 | |
52 | - $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_POST["fileName"]); |
|
53 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
52 | + $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_POST["fileName"]); |
|
53 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
54 | 54 | |
55 | - if (!$resourceTypeInfo->checkExtension($fileName)) { |
|
56 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
57 | - } |
|
55 | + if (!$resourceTypeInfo->checkExtension($fileName)) { |
|
56 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
57 | + } |
|
58 | 58 | |
59 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { |
|
60 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
61 | - } |
|
59 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { |
|
60 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
61 | + } |
|
62 | 62 | |
63 | - $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); |
|
63 | + $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); |
|
64 | 64 | |
65 | - if (!file_exists($filePath) || !is_file($filePath)) { |
|
66 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
67 | - } |
|
65 | + if (!file_exists($filePath) || !is_file($filePath)) { |
|
66 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
67 | + } |
|
68 | 68 | |
69 | - if (!is_writable(dirname($filePath))) { |
|
70 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
71 | - } |
|
69 | + if (!is_writable(dirname($filePath))) { |
|
70 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
71 | + } |
|
72 | 72 | |
73 | - if ( strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip'){ |
|
74 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
75 | - } |
|
73 | + if ( strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip'){ |
|
74 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
75 | + } |
|
76 | 76 | |
77 | - $zip = new ZipArchive(); |
|
78 | - $result = $zip->open($filePath); |
|
79 | - if ($result !== TRUE) { |
|
80 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN); |
|
81 | - } |
|
82 | - $this->zip = $zip; |
|
83 | - $this->filePath = $filePath; |
|
84 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
77 | + $zip = new ZipArchive(); |
|
78 | + $result = $zip->open($filePath); |
|
79 | + if ($result !== TRUE) { |
|
80 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN); |
|
81 | + } |
|
82 | + $this->zip = $zip; |
|
83 | + $this->filePath = $filePath; |
|
84 | + $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
85 | 85 | |
86 | - // list of unzipped nodes |
|
87 | - $this->unzippedNodes = new CKFinder_Connector_Utils_XmlNode("UnzippedFiles"); |
|
86 | + // list of unzipped nodes |
|
87 | + $this->unzippedNodes = new CKFinder_Connector_Utils_XmlNode("UnzippedFiles"); |
|
88 | 88 | |
89 | - // list of files which could not be unzipped |
|
90 | - $this->skippedFilesNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
91 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
89 | + // list of files which could not be unzipped |
|
90 | + $this->skippedFilesNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
91 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -100,89 +100,89 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function checkOneFile($filePathInfo, $originalFileName ) |
102 | 102 | { |
103 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
104 | - |
|
105 | - // checked if it is a folder |
|
106 | - $fileStat = $this->zip->statName($originalFileName); |
|
107 | - if ( empty($filePathInfo['extension']) && empty($fileStat['size']) ){ |
|
108 | - $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(rtrim($fileStat['name'],'/')); |
|
109 | - if ($this->_config->forceAscii()) { |
|
110 | - $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sNewFolderName); |
|
111 | - } |
|
112 | - if (!CKFinder_Connector_Utils_FileSystem::checkFolderPath($sNewFolderName) || $resourceTypeInfo->checkIsHiddenFolder($sNewFolderName)) { |
|
113 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_NAME; |
|
114 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
115 | - return false; |
|
116 | - } |
|
117 | - |
|
118 | - if (!is_writeable($this->_currentFolder->getServerPath())) { |
|
119 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
120 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
121 | - return false; |
|
122 | - } |
|
123 | - |
|
124 | - return $originalFileName; |
|
125 | - } |
|
126 | - |
|
127 | - $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($filePathInfo['basename']); |
|
128 | - $sFileName = CKFinder_Connector_Utils_FileSystem::secureFileName($fileName); |
|
129 | - |
|
130 | - // max file size |
|
131 | - $maxSize = $resourceTypeInfo->getMaxSize(); |
|
132 | - if ( $maxSize && $fileStat['size'] > $maxSize ) |
|
133 | - { |
|
134 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
135 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
136 | - return false; |
|
137 | - } |
|
138 | - // extension |
|
139 | - if ( !$resourceTypeInfo->checkExtension($sFileName) ) |
|
140 | - { |
|
141 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
142 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
143 | - return false; |
|
144 | - } |
|
145 | - // hidden file |
|
146 | - if ( !CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $resourceTypeInfo->checkIsHiddenFile($sFileName) ){ |
|
147 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST; |
|
148 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
149 | - return false; |
|
150 | - } |
|
151 | - |
|
152 | - // unpack file to tmp dir for detecting html and valid image |
|
153 | - $dir = CKFinder_Connector_Utils_FileSystem::getTmpDir().'/'; |
|
154 | - if ( file_exists($dir.$sFileName) && !CKFinder_Connector_Utils_FileSystem::unlink($dir.$sFileName) ){ |
|
155 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST; |
|
156 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
157 | - return false; |
|
158 | - } |
|
159 | - if ( copy('zip://'.$this->filePath.'#'.$originalFileName, $dir.$sFileName) ) |
|
160 | - { |
|
161 | - // html extensions |
|
162 | - $htmlExtensions = $this->_config->getHtmlExtensions(); |
|
163 | - $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension( $dir.$sFileName ); |
|
164 | - if ( $htmlExtensions |
|
165 | - && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive( $sExtension, $htmlExtensions ) |
|
166 | - && CKFinder_Connector_Utils_FileSystem::detectHtml($dir.$sFileName) === true ) |
|
167 | - { |
|
168 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID; |
|
169 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
170 | - return false; |
|
171 | - } |
|
172 | - |
|
173 | - // proper image |
|
174 | - $secureImageUploads = $this->_config->getSecureImageUploads(); |
|
175 | - if ( $secureImageUploads |
|
176 | - && ( $isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($dir.$sFileName, $sExtension) ) === false ) |
|
177 | - { |
|
178 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID; |
|
179 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
180 | - return false; |
|
181 | - } |
|
182 | - } |
|
183 | - $sDirName = ($filePathInfo['dirname'] != '.')? $filePathInfo['dirname'].'/' : ''; |
|
184 | - |
|
185 | - return $sDirName.$sFileName; |
|
103 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
104 | + |
|
105 | + // checked if it is a folder |
|
106 | + $fileStat = $this->zip->statName($originalFileName); |
|
107 | + if ( empty($filePathInfo['extension']) && empty($fileStat['size']) ){ |
|
108 | + $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(rtrim($fileStat['name'],'/')); |
|
109 | + if ($this->_config->forceAscii()) { |
|
110 | + $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sNewFolderName); |
|
111 | + } |
|
112 | + if (!CKFinder_Connector_Utils_FileSystem::checkFolderPath($sNewFolderName) || $resourceTypeInfo->checkIsHiddenFolder($sNewFolderName)) { |
|
113 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_NAME; |
|
114 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
115 | + return false; |
|
116 | + } |
|
117 | + |
|
118 | + if (!is_writeable($this->_currentFolder->getServerPath())) { |
|
119 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
120 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
121 | + return false; |
|
122 | + } |
|
123 | + |
|
124 | + return $originalFileName; |
|
125 | + } |
|
126 | + |
|
127 | + $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($filePathInfo['basename']); |
|
128 | + $sFileName = CKFinder_Connector_Utils_FileSystem::secureFileName($fileName); |
|
129 | + |
|
130 | + // max file size |
|
131 | + $maxSize = $resourceTypeInfo->getMaxSize(); |
|
132 | + if ( $maxSize && $fileStat['size'] > $maxSize ) |
|
133 | + { |
|
134 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
135 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
136 | + return false; |
|
137 | + } |
|
138 | + // extension |
|
139 | + if ( !$resourceTypeInfo->checkExtension($sFileName) ) |
|
140 | + { |
|
141 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
142 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
143 | + return false; |
|
144 | + } |
|
145 | + // hidden file |
|
146 | + if ( !CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $resourceTypeInfo->checkIsHiddenFile($sFileName) ){ |
|
147 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST; |
|
148 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
149 | + return false; |
|
150 | + } |
|
151 | + |
|
152 | + // unpack file to tmp dir for detecting html and valid image |
|
153 | + $dir = CKFinder_Connector_Utils_FileSystem::getTmpDir().'/'; |
|
154 | + if ( file_exists($dir.$sFileName) && !CKFinder_Connector_Utils_FileSystem::unlink($dir.$sFileName) ){ |
|
155 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST; |
|
156 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
157 | + return false; |
|
158 | + } |
|
159 | + if ( copy('zip://'.$this->filePath.'#'.$originalFileName, $dir.$sFileName) ) |
|
160 | + { |
|
161 | + // html extensions |
|
162 | + $htmlExtensions = $this->_config->getHtmlExtensions(); |
|
163 | + $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension( $dir.$sFileName ); |
|
164 | + if ( $htmlExtensions |
|
165 | + && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive( $sExtension, $htmlExtensions ) |
|
166 | + && CKFinder_Connector_Utils_FileSystem::detectHtml($dir.$sFileName) === true ) |
|
167 | + { |
|
168 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID; |
|
169 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
170 | + return false; |
|
171 | + } |
|
172 | + |
|
173 | + // proper image |
|
174 | + $secureImageUploads = $this->_config->getSecureImageUploads(); |
|
175 | + if ( $secureImageUploads |
|
176 | + && ( $isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($dir.$sFileName, $sExtension) ) === false ) |
|
177 | + { |
|
178 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID; |
|
179 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
180 | + return false; |
|
181 | + } |
|
182 | + } |
|
183 | + $sDirName = ($filePathInfo['dirname'] != '.')? $filePathInfo['dirname'].'/' : ''; |
|
184 | + |
|
185 | + return $sDirName.$sFileName; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -195,16 +195,16 @@ discard block |
||
195 | 195 | */ |
196 | 196 | protected function appendErrorNode($oErrorsNode, $errorCode=0, $name, $type=null, $path=null) |
197 | 197 | { |
198 | - $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
199 | - $oErrorNode->addAttribute("code", $errorCode); |
|
200 | - $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
201 | - if ( $type ){ |
|
202 | - $oErrorNode->addAttribute("type", $type); |
|
203 | - } |
|
204 | - if ( $path ){ |
|
205 | - $oErrorNode->addAttribute("folder", $path); |
|
206 | - } |
|
207 | - $oErrorsNode->addChild($oErrorNode); |
|
198 | + $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
199 | + $oErrorNode->addAttribute("code", $errorCode); |
|
200 | + $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
201 | + if ( $type ){ |
|
202 | + $oErrorNode->addAttribute("type", $type); |
|
203 | + } |
|
204 | + if ( $path ){ |
|
205 | + $oErrorNode->addAttribute("folder", $path); |
|
206 | + } |
|
207 | + $oErrorsNode->addChild($oErrorNode); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -215,10 +215,10 @@ discard block |
||
215 | 215 | */ |
216 | 216 | protected function appendUnzippedNode($oUnzippedNodes, $name, $action='ok') |
217 | 217 | { |
218 | - $oUnzippedNode = new CKFinder_Connector_Utils_XmlNode("File"); |
|
219 | - $oUnzippedNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
220 | - $oUnzippedNode->addAttribute("action", $action ); |
|
221 | - $oUnzippedNodes->addChild($oUnzippedNode); |
|
218 | + $oUnzippedNode = new CKFinder_Connector_Utils_XmlNode("File"); |
|
219 | + $oUnzippedNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
220 | + $oUnzippedNode->addAttribute("action", $action ); |
|
221 | + $oUnzippedNodes->addChild($oUnzippedNode); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -232,72 +232,72 @@ discard block |
||
232 | 232 | */ |
233 | 233 | protected function extractTo($extractPath, $extractClientPath, $filePathInfo, $sFileName, $originalFileName) |
234 | 234 | { |
235 | - $sfilePathInfo = pathinfo($extractPath.$sFileName); |
|
236 | - $extractClientPathDir = $filePathInfo['dirname']; |
|
237 | - if ( $filePathInfo['dirname'] == '.' ){ |
|
238 | - $extractClientPathDir = ''; |
|
239 | - } |
|
240 | - $folderPath = CKFinder_Connector_Utils_FileSystem::combinePaths($extractClientPath,$extractClientPathDir); |
|
241 | - |
|
242 | - $_aclConfig = $this->_config->getAccessControlConfig(); |
|
243 | - $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(),$folderPath); |
|
244 | - $canCreateFolder = (($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ); |
|
245 | - // create sub-directory of zip archive |
|
246 | - if ( empty($sfilePathInfo['extension']) ) |
|
247 | - { |
|
248 | - $fileStat = $this->zip->statName($originalFileName); |
|
249 | - $isDir = false; |
|
250 | - if ( $fileStat && empty($fileStat['size']) ){ |
|
251 | - $isDir = true; |
|
252 | - } |
|
253 | - if( !empty($sfilePathInfo['dirname']) && !empty($sfilePathInfo['basename']) && !file_exists($sfilePathInfo['dirname'].'/'.$sfilePathInfo['basename']) ) |
|
254 | - { |
|
255 | - if ( !$canCreateFolder ){ |
|
256 | - return; |
|
257 | - } |
|
258 | - if ( $isDir ) { |
|
259 | - CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively( $sfilePathInfo['dirname'].'/'.$sfilePathInfo['basename'] ); |
|
260 | - return; |
|
261 | - } else { |
|
262 | - CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively( $sfilePathInfo['dirname']); |
|
263 | - } |
|
264 | - } else { |
|
265 | - return; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - // extract file |
|
270 | - if ( !file_exists($sfilePathInfo['dirname']) ){ |
|
271 | - if ( !$canCreateFolder ){ |
|
272 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
|
273 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName ); |
|
274 | - return; |
|
275 | - } |
|
276 | - CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($sfilePathInfo['dirname']); |
|
277 | - } |
|
278 | - $isAuthorized = (($aclMask & CKFINDER_CONNECTOR_ACL_FILE_UPLOAD ) == CKFINDER_CONNECTOR_ACL_FILE_UPLOAD ); |
|
279 | - if ( !$isAuthorized ){ |
|
280 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_COPY_FAILED; |
|
281 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
282 | - return; |
|
283 | - } |
|
284 | - if ( copy('zip://'.$this->filePath.'#'.$originalFileName, $extractPath.$sFileName) ) |
|
285 | - { |
|
286 | - $this->appendUnzippedNode($this->unzippedNodes,$originalFileName); |
|
287 | - // chmod extracted file |
|
288 | - if ( is_file($extractPath.$sFileName) && ( $perms = $this->_config->getChmodFiles()) ) |
|
289 | - { |
|
290 | - $oldumask = umask(0); |
|
291 | - chmod( $extractPath.$sFileName, $perms ); |
|
292 | - umask( $oldumask ); |
|
293 | - } |
|
294 | - } |
|
295 | - // file extraction failed, add to skipped |
|
296 | - else |
|
297 | - { |
|
298 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_COPY_FAILED; |
|
299 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
300 | - } |
|
235 | + $sfilePathInfo = pathinfo($extractPath.$sFileName); |
|
236 | + $extractClientPathDir = $filePathInfo['dirname']; |
|
237 | + if ( $filePathInfo['dirname'] == '.' ){ |
|
238 | + $extractClientPathDir = ''; |
|
239 | + } |
|
240 | + $folderPath = CKFinder_Connector_Utils_FileSystem::combinePaths($extractClientPath,$extractClientPathDir); |
|
241 | + |
|
242 | + $_aclConfig = $this->_config->getAccessControlConfig(); |
|
243 | + $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(),$folderPath); |
|
244 | + $canCreateFolder = (($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ); |
|
245 | + // create sub-directory of zip archive |
|
246 | + if ( empty($sfilePathInfo['extension']) ) |
|
247 | + { |
|
248 | + $fileStat = $this->zip->statName($originalFileName); |
|
249 | + $isDir = false; |
|
250 | + if ( $fileStat && empty($fileStat['size']) ){ |
|
251 | + $isDir = true; |
|
252 | + } |
|
253 | + if( !empty($sfilePathInfo['dirname']) && !empty($sfilePathInfo['basename']) && !file_exists($sfilePathInfo['dirname'].'/'.$sfilePathInfo['basename']) ) |
|
254 | + { |
|
255 | + if ( !$canCreateFolder ){ |
|
256 | + return; |
|
257 | + } |
|
258 | + if ( $isDir ) { |
|
259 | + CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively( $sfilePathInfo['dirname'].'/'.$sfilePathInfo['basename'] ); |
|
260 | + return; |
|
261 | + } else { |
|
262 | + CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively( $sfilePathInfo['dirname']); |
|
263 | + } |
|
264 | + } else { |
|
265 | + return; |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + // extract file |
|
270 | + if ( !file_exists($sfilePathInfo['dirname']) ){ |
|
271 | + if ( !$canCreateFolder ){ |
|
272 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
|
273 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName ); |
|
274 | + return; |
|
275 | + } |
|
276 | + CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($sfilePathInfo['dirname']); |
|
277 | + } |
|
278 | + $isAuthorized = (($aclMask & CKFINDER_CONNECTOR_ACL_FILE_UPLOAD ) == CKFINDER_CONNECTOR_ACL_FILE_UPLOAD ); |
|
279 | + if ( !$isAuthorized ){ |
|
280 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_COPY_FAILED; |
|
281 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
282 | + return; |
|
283 | + } |
|
284 | + if ( copy('zip://'.$this->filePath.'#'.$originalFileName, $extractPath.$sFileName) ) |
|
285 | + { |
|
286 | + $this->appendUnzippedNode($this->unzippedNodes,$originalFileName); |
|
287 | + // chmod extracted file |
|
288 | + if ( is_file($extractPath.$sFileName) && ( $perms = $this->_config->getChmodFiles()) ) |
|
289 | + { |
|
290 | + $oldumask = umask(0); |
|
291 | + chmod( $extractPath.$sFileName, $perms ); |
|
292 | + umask( $oldumask ); |
|
293 | + } |
|
294 | + } |
|
295 | + // file extraction failed, add to skipped |
|
296 | + else |
|
297 | + { |
|
298 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_COPY_FAILED; |
|
299 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
300 | + } |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | } // end of CKFinder_Connector_CommandHandler_Unzip class |
@@ -309,111 +309,111 @@ discard block |
||
309 | 309 | */ |
310 | 310 | protected function buildXml() |
311 | 311 | { |
312 | - parent::buildXml(); |
|
312 | + parent::buildXml(); |
|
313 | 313 | |
314 | 314 | $checkedFiles = array(); |
315 | 315 | if ( !empty($_POST['files']) && is_array($_POST['files']) ){ |
316 | - foreach ( $_POST['files'] as $file){ |
|
317 | - $checkedFiles[$file['name']] = $file; |
|
318 | - } |
|
316 | + foreach ( $_POST['files'] as $file){ |
|
317 | + $checkedFiles[$file['name']] = $file; |
|
318 | + } |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | for ($i = 0; $i < $this->zip->numFiles; $i++) |
322 | - { |
|
323 | - $fileName = $this->zip->getNameIndex($i); |
|
324 | - if ( !empty($checkedFiles[$fileName]) && $checkedFiles[$fileName]['options'] == 'ok' ) |
|
325 | - { |
|
326 | - // file was sucessfully unzipped before |
|
327 | - $this->appendUnzippedNode($this->unzippedNodes,$fileName); |
|
328 | - continue; |
|
329 | - } |
|
330 | - |
|
331 | - $filePathInfo = pathinfo($fileName); |
|
332 | - $fileType = 'File'; |
|
333 | - $fileStat = $this->zip->statName($i); |
|
334 | - if ( empty($filePathInfo['extension']) && empty($fileStat['size']) ){ |
|
335 | - $fileType = 'Folder'; |
|
336 | - // check if we can create subfolder |
|
337 | - if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) ){ |
|
338 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
|
339 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
|
340 | - continue; |
|
341 | - } |
|
342 | - } |
|
343 | - $extractPath = $this->_currentFolder->getServerPath(); |
|
344 | - $extractClientPath = $this->_currentFolder->getClientPath(); |
|
345 | - |
|
346 | - $sFileName = $this->checkOneFile( $filePathInfo, $fileName ); |
|
347 | - // security test failed, add to skipped |
|
348 | - if ( false !== $sFileName ) |
|
349 | - { |
|
350 | - if ( file_exists($extractPath.$sFileName) ) |
|
351 | - { |
|
352 | - if ( !is_dir($extractPath.$sFileName) ) |
|
353 | - { |
|
354 | - // file was checked before |
|
355 | - if ( !empty($checkedFiles[$fileName]['options']) ) |
|
356 | - { |
|
357 | - if ( $checkedFiles[$fileName]['options'] == 'autorename') |
|
358 | - { |
|
359 | - $sFileName = CKFinder_Connector_Utils_FileSystem::autoRename($extractPath,$sFileName); |
|
360 | - $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
361 | - } |
|
362 | - elseif ( $checkedFiles[$fileName]['options'] == 'overwrite') |
|
363 | - { |
|
364 | - if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FILE_DELETE ) ){ |
|
365 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
|
366 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
|
367 | - continue; |
|
368 | - } |
|
369 | - if (!CKFinder_Connector_Utils_FileSystem::unlink($extractPath.$sFileName)) |
|
370 | - { |
|
371 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
372 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
|
373 | - } |
|
374 | - else |
|
375 | - { |
|
376 | - $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
377 | - } |
|
378 | - } |
|
379 | - else |
|
380 | - { |
|
381 | - // add to skipped files |
|
382 | - $this->appendUnzippedNode($this->unzippedNodes,$fileName,'skip'); |
|
383 | - } |
|
384 | - } |
|
385 | - else |
|
386 | - { |
|
387 | - $this->errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
388 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
|
389 | - } |
|
390 | - } |
|
391 | - } |
|
392 | - // file doesn't exist yet |
|
393 | - else |
|
394 | - { |
|
395 | - $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
396 | - } |
|
397 | - } |
|
398 | - } |
|
399 | - $this->zip->close(); |
|
400 | - |
|
401 | - $this->_connectorNode->addChild($this->unzippedNodes); |
|
402 | - |
|
403 | - if ($this->errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
404 | - $this->_connectorNode->addChild($this->skippedFilesNode); |
|
405 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ZIP_FAILED); |
|
406 | - } |
|
322 | + { |
|
323 | + $fileName = $this->zip->getNameIndex($i); |
|
324 | + if ( !empty($checkedFiles[$fileName]) && $checkedFiles[$fileName]['options'] == 'ok' ) |
|
325 | + { |
|
326 | + // file was sucessfully unzipped before |
|
327 | + $this->appendUnzippedNode($this->unzippedNodes,$fileName); |
|
328 | + continue; |
|
329 | + } |
|
330 | + |
|
331 | + $filePathInfo = pathinfo($fileName); |
|
332 | + $fileType = 'File'; |
|
333 | + $fileStat = $this->zip->statName($i); |
|
334 | + if ( empty($filePathInfo['extension']) && empty($fileStat['size']) ){ |
|
335 | + $fileType = 'Folder'; |
|
336 | + // check if we can create subfolder |
|
337 | + if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) ){ |
|
338 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
|
339 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
|
340 | + continue; |
|
341 | + } |
|
342 | + } |
|
343 | + $extractPath = $this->_currentFolder->getServerPath(); |
|
344 | + $extractClientPath = $this->_currentFolder->getClientPath(); |
|
345 | + |
|
346 | + $sFileName = $this->checkOneFile( $filePathInfo, $fileName ); |
|
347 | + // security test failed, add to skipped |
|
348 | + if ( false !== $sFileName ) |
|
349 | + { |
|
350 | + if ( file_exists($extractPath.$sFileName) ) |
|
351 | + { |
|
352 | + if ( !is_dir($extractPath.$sFileName) ) |
|
353 | + { |
|
354 | + // file was checked before |
|
355 | + if ( !empty($checkedFiles[$fileName]['options']) ) |
|
356 | + { |
|
357 | + if ( $checkedFiles[$fileName]['options'] == 'autorename') |
|
358 | + { |
|
359 | + $sFileName = CKFinder_Connector_Utils_FileSystem::autoRename($extractPath,$sFileName); |
|
360 | + $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
361 | + } |
|
362 | + elseif ( $checkedFiles[$fileName]['options'] == 'overwrite') |
|
363 | + { |
|
364 | + if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FILE_DELETE ) ){ |
|
365 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
|
366 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
|
367 | + continue; |
|
368 | + } |
|
369 | + if (!CKFinder_Connector_Utils_FileSystem::unlink($extractPath.$sFileName)) |
|
370 | + { |
|
371 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
372 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
|
373 | + } |
|
374 | + else |
|
375 | + { |
|
376 | + $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
377 | + } |
|
378 | + } |
|
379 | + else |
|
380 | + { |
|
381 | + // add to skipped files |
|
382 | + $this->appendUnzippedNode($this->unzippedNodes,$fileName,'skip'); |
|
383 | + } |
|
384 | + } |
|
385 | + else |
|
386 | + { |
|
387 | + $this->errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
388 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
|
389 | + } |
|
390 | + } |
|
391 | + } |
|
392 | + // file doesn't exist yet |
|
393 | + else |
|
394 | + { |
|
395 | + $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
396 | + } |
|
397 | + } |
|
398 | + } |
|
399 | + $this->zip->close(); |
|
400 | + |
|
401 | + $this->_connectorNode->addChild($this->unzippedNodes); |
|
402 | + |
|
403 | + if ($this->errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
404 | + $this->_connectorNode->addChild($this->skippedFilesNode); |
|
405 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ZIP_FAILED); |
|
406 | + } |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | public function onBeforeExecuteCommand( &$command ) |
410 | 410 | { |
411 | - if ( $command == 'ExtractHere' ) |
|
412 | - { |
|
413 | - $this->sendResponse(); |
|
414 | - return false; |
|
415 | - } |
|
416 | - return true ; |
|
411 | + if ( $command == 'ExtractHere' ) |
|
412 | + { |
|
413 | + $this->sendResponse(); |
|
414 | + return false; |
|
415 | + } |
|
416 | + return true ; |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | } // end of CKFinder_Connector_CommandHandler_UnzipHere class |
@@ -425,82 +425,82 @@ discard block |
||
425 | 425 | */ |
426 | 426 | protected function buildXml() |
427 | 427 | { |
428 | - parent::buildXml(); |
|
429 | - |
|
430 | - $extractDir = ( !empty($_POST['extractDir']) ) ? ltrim($_POST['extractDir'],'/') : ''; |
|
431 | - $extractDir = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($extractDir); |
|
432 | - if ( preg_match(CKFINDER_REGEX_INVALID_PATH, $extractDir) ){ |
|
433 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
434 | - } |
|
435 | - $extractPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $extractDir.'/'); |
|
436 | - $extractClientPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getClientPath(),$extractDir); |
|
437 | - // acl for upload dir |
|
438 | - $_aclConfig = $this->_config->getAccessControlConfig(); |
|
439 | - $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(),$extractDir); |
|
440 | - |
|
441 | - if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) ){ |
|
442 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
443 | - } |
|
444 | - if ( empty( $_POST['force']) && file_exists($extractPath) && is_dir($extractPath) && !CKFinder_Connector_Utils_FileSystem::isEmptyDir($extractPath) ) |
|
445 | - { |
|
446 | - $dirExists = new CKFinder_Connector_Utils_XmlNode("FolderExists"); |
|
447 | - $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Folder"); |
|
448 | - $oErrorNode->addAttribute("name", $extractDir); |
|
449 | - $dirExists->addChild($oErrorNode); |
|
450 | - $this->_connectorNode->addChild($dirExists); |
|
451 | - return; |
|
452 | - } |
|
453 | - elseif ( !empty( $_POST['force']) && $_POST['force'] =='overwrite' ) |
|
454 | - { |
|
455 | - if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE ) == CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE ) ){ |
|
456 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
457 | - } |
|
458 | - if ( $extractDir && file_exists($extractPath) && is_dir($extractPath) ) |
|
459 | - { |
|
460 | - if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE | CKFINDER_CONNECTOR_ACL_FOLDER_DELETE ) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE | CKFINDER_CONNECTOR_ACL_FOLDER_DELETE ) ){ |
|
461 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
462 | - } |
|
463 | - if (!CKFinder_Connector_Utils_FileSystem::unlink($extractPath)) |
|
464 | - { |
|
465 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
466 | - } |
|
467 | - } |
|
468 | - } |
|
469 | - else if ( !empty( $_POST['force']) && $_POST['force'] !== 'merge' ) |
|
470 | - { |
|
471 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
472 | - } |
|
473 | - |
|
474 | - for ($i = 0; $i < $this->zip->numFiles; $i++) |
|
475 | - { |
|
476 | - $fileName = $this->zip->getNameIndex($i); |
|
477 | - $filePathInfo = pathinfo($fileName); |
|
478 | - |
|
479 | - $sFileName = $this->checkOneFile( $filePathInfo, $fileName ); |
|
480 | - // security test failed, add to skipped |
|
481 | - if ( $sFileName ) |
|
482 | - { |
|
483 | - $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
484 | - } |
|
485 | - } |
|
486 | - $this->zip->close(); |
|
487 | - |
|
488 | - |
|
489 | - $this->_connectorNode->addChild($this->unzippedNodes); |
|
490 | - |
|
491 | - if ($this->errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
492 | - $this->_connectorNode->addChild($this->skippedFilesNode); |
|
493 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ZIP_FAILED); |
|
494 | - } |
|
428 | + parent::buildXml(); |
|
429 | + |
|
430 | + $extractDir = ( !empty($_POST['extractDir']) ) ? ltrim($_POST['extractDir'],'/') : ''; |
|
431 | + $extractDir = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($extractDir); |
|
432 | + if ( preg_match(CKFINDER_REGEX_INVALID_PATH, $extractDir) ){ |
|
433 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
434 | + } |
|
435 | + $extractPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $extractDir.'/'); |
|
436 | + $extractClientPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getClientPath(),$extractDir); |
|
437 | + // acl for upload dir |
|
438 | + $_aclConfig = $this->_config->getAccessControlConfig(); |
|
439 | + $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(),$extractDir); |
|
440 | + |
|
441 | + if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) ){ |
|
442 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
443 | + } |
|
444 | + if ( empty( $_POST['force']) && file_exists($extractPath) && is_dir($extractPath) && !CKFinder_Connector_Utils_FileSystem::isEmptyDir($extractPath) ) |
|
445 | + { |
|
446 | + $dirExists = new CKFinder_Connector_Utils_XmlNode("FolderExists"); |
|
447 | + $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Folder"); |
|
448 | + $oErrorNode->addAttribute("name", $extractDir); |
|
449 | + $dirExists->addChild($oErrorNode); |
|
450 | + $this->_connectorNode->addChild($dirExists); |
|
451 | + return; |
|
452 | + } |
|
453 | + elseif ( !empty( $_POST['force']) && $_POST['force'] =='overwrite' ) |
|
454 | + { |
|
455 | + if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE ) == CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE ) ){ |
|
456 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
457 | + } |
|
458 | + if ( $extractDir && file_exists($extractPath) && is_dir($extractPath) ) |
|
459 | + { |
|
460 | + if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE | CKFINDER_CONNECTOR_ACL_FOLDER_DELETE ) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE | CKFINDER_CONNECTOR_ACL_FOLDER_DELETE ) ){ |
|
461 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
462 | + } |
|
463 | + if (!CKFinder_Connector_Utils_FileSystem::unlink($extractPath)) |
|
464 | + { |
|
465 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
466 | + } |
|
467 | + } |
|
468 | + } |
|
469 | + else if ( !empty( $_POST['force']) && $_POST['force'] !== 'merge' ) |
|
470 | + { |
|
471 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
472 | + } |
|
473 | + |
|
474 | + for ($i = 0; $i < $this->zip->numFiles; $i++) |
|
475 | + { |
|
476 | + $fileName = $this->zip->getNameIndex($i); |
|
477 | + $filePathInfo = pathinfo($fileName); |
|
478 | + |
|
479 | + $sFileName = $this->checkOneFile( $filePathInfo, $fileName ); |
|
480 | + // security test failed, add to skipped |
|
481 | + if ( $sFileName ) |
|
482 | + { |
|
483 | + $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
484 | + } |
|
485 | + } |
|
486 | + $this->zip->close(); |
|
487 | + |
|
488 | + |
|
489 | + $this->_connectorNode->addChild($this->unzippedNodes); |
|
490 | + |
|
491 | + if ($this->errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
492 | + $this->_connectorNode->addChild($this->skippedFilesNode); |
|
493 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ZIP_FAILED); |
|
494 | + } |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | public function onBeforeExecuteCommand( &$command ) |
498 | 498 | { |
499 | - if ( $command == 'ExtractTo'){ |
|
500 | - $this->sendResponse(); |
|
501 | - return false; |
|
502 | - } |
|
503 | - return true ; |
|
499 | + if ( $command == 'ExtractTo'){ |
|
500 | + $this->sendResponse(); |
|
501 | + return false; |
|
502 | + } |
|
503 | + return true ; |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | } // end of CKFinder_Connector_CommandHandler_UnzipTo class |
@@ -517,14 +517,14 @@ discard block |
||
517 | 517 | * @return array |
518 | 518 | */ |
519 | 519 | protected function getConfig(){ |
520 | - $config = array(); |
|
520 | + $config = array(); |
|
521 | 521 | |
522 | - $config['zipMaxSize'] = 'default'; |
|
523 | - if (isset($GLOBALS['config']['ZipMaxSize']) && (string)$GLOBALS['config']['ZipMaxSize']!='default' ){ |
|
524 | - $config['zipMaxSize'] = CKFinder_Connector_Utils_Misc::returnBytes((string)$GLOBALS['config']['ZipMaxSize']); |
|
525 | - } |
|
522 | + $config['zipMaxSize'] = 'default'; |
|
523 | + if (isset($GLOBALS['config']['ZipMaxSize']) && (string)$GLOBALS['config']['ZipMaxSize']!='default' ){ |
|
524 | + $config['zipMaxSize'] = CKFinder_Connector_Utils_Misc::returnBytes((string)$GLOBALS['config']['ZipMaxSize']); |
|
525 | + } |
|
526 | 526 | |
527 | - return $config; |
|
527 | + return $config; |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | /** |
@@ -536,44 +536,44 @@ discard block |
||
536 | 536 | */ |
537 | 537 | protected function checkOneFile($file) |
538 | 538 | { |
539 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
540 | - $_aclConfig = $this->_config->getAccessControlConfig(); |
|
541 | - $directory = str_replace('\\','/', $resourceTypeInfo->getDirectory()); |
|
542 | - $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($file->getFilename()); |
|
543 | - |
|
544 | - if ($this->_config->forceAscii()) { |
|
545 | - $fileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($fileName); |
|
546 | - } |
|
547 | - $pathName = str_replace('\\','/', pathinfo($file->getPathname(), PATHINFO_DIRNAME) ); |
|
548 | - $pathName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($pathName); |
|
549 | - |
|
550 | - // acl |
|
551 | - $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(), str_ireplace($directory,'',$pathName)); |
|
552 | - $isAuthorized = (($aclMask & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
553 | - if ( !$isAuthorized ){ |
|
554 | - return false; |
|
555 | - } |
|
556 | - |
|
557 | - // if it is a folder fileName represents the dir |
|
558 | - if ( $file->isDir() && ( !CKFinder_Connector_Utils_FileSystem::checkFolderPath($fileName) || $resourceTypeInfo->checkIsHiddenPath($fileName) ) ){ |
|
559 | - return false; |
|
560 | - } |
|
561 | - // folder name |
|
562 | - if ( !CKFinder_Connector_Utils_FileSystem::checkFolderPath($pathName) ){ |
|
563 | - return false; |
|
564 | - } |
|
565 | - |
|
566 | - // is hidden |
|
567 | - if ( $resourceTypeInfo->checkIsHiddenPath($pathName) || $resourceTypeInfo->checkIsHiddenFile($fileName) ){ |
|
568 | - return false; |
|
569 | - } |
|
570 | - |
|
571 | - // extension |
|
572 | - if ( !$resourceTypeInfo->checkExtension($fileName) || !CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) ){ |
|
573 | - return false; |
|
574 | - } |
|
575 | - |
|
576 | - return true; |
|
539 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
540 | + $_aclConfig = $this->_config->getAccessControlConfig(); |
|
541 | + $directory = str_replace('\\','/', $resourceTypeInfo->getDirectory()); |
|
542 | + $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($file->getFilename()); |
|
543 | + |
|
544 | + if ($this->_config->forceAscii()) { |
|
545 | + $fileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($fileName); |
|
546 | + } |
|
547 | + $pathName = str_replace('\\','/', pathinfo($file->getPathname(), PATHINFO_DIRNAME) ); |
|
548 | + $pathName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($pathName); |
|
549 | + |
|
550 | + // acl |
|
551 | + $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(), str_ireplace($directory,'',$pathName)); |
|
552 | + $isAuthorized = (($aclMask & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
553 | + if ( !$isAuthorized ){ |
|
554 | + return false; |
|
555 | + } |
|
556 | + |
|
557 | + // if it is a folder fileName represents the dir |
|
558 | + if ( $file->isDir() && ( !CKFinder_Connector_Utils_FileSystem::checkFolderPath($fileName) || $resourceTypeInfo->checkIsHiddenPath($fileName) ) ){ |
|
559 | + return false; |
|
560 | + } |
|
561 | + // folder name |
|
562 | + if ( !CKFinder_Connector_Utils_FileSystem::checkFolderPath($pathName) ){ |
|
563 | + return false; |
|
564 | + } |
|
565 | + |
|
566 | + // is hidden |
|
567 | + if ( $resourceTypeInfo->checkIsHiddenPath($pathName) || $resourceTypeInfo->checkIsHiddenFile($fileName) ){ |
|
568 | + return false; |
|
569 | + } |
|
570 | + |
|
571 | + // extension |
|
572 | + if ( !$resourceTypeInfo->checkExtension($fileName) || !CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) ){ |
|
573 | + return false; |
|
574 | + } |
|
575 | + |
|
576 | + return true; |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -585,36 +585,36 @@ discard block |
||
585 | 585 | */ |
586 | 586 | protected function getFilesRecursively( $directory, $zipMaxSize ) |
587 | 587 | { |
588 | - $allFiles = array(); |
|
589 | - $_zipFilesSize = 0; |
|
590 | - $serverPath = str_replace('\\','/',$directory); |
|
591 | - |
|
592 | - foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $file ) { |
|
593 | - if ( !$this->checkOneFile($file) ){ |
|
594 | - continue; |
|
595 | - } |
|
596 | - if ( !empty($zipMaxSize) ){ |
|
597 | - clearstatcache(); |
|
598 | - $_zipFilesSize += $file->getSize(); |
|
599 | - if ( $_zipFilesSize > $zipMaxSize ) { |
|
600 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CREATED_FILE_TOO_BIG); |
|
601 | - } |
|
602 | - } |
|
603 | - $pathName = str_replace('\\','/',$file->getPathname()); |
|
604 | - if ( $file->isDir() ){ |
|
605 | - // skip dot folders on unix systems ( do not try to use isDot() as $file is not a DirectoryIterator obj ) |
|
606 | - if ( in_array($file->getFilename(),array('..','.')) ){ |
|
607 | - continue; |
|
608 | - } |
|
609 | - if ($pathName != rtrim($serverPath,'/')){ |
|
610 | - $allFiles[ ltrim(str_ireplace(rtrim($serverPath,'/'),'',$pathName),'/') ] = ''; |
|
611 | - } |
|
612 | - } else { |
|
613 | - $allFiles[$pathName] = str_ireplace($serverPath,'',$pathName); |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - return $allFiles; |
|
588 | + $allFiles = array(); |
|
589 | + $_zipFilesSize = 0; |
|
590 | + $serverPath = str_replace('\\','/',$directory); |
|
591 | + |
|
592 | + foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $file ) { |
|
593 | + if ( !$this->checkOneFile($file) ){ |
|
594 | + continue; |
|
595 | + } |
|
596 | + if ( !empty($zipMaxSize) ){ |
|
597 | + clearstatcache(); |
|
598 | + $_zipFilesSize += $file->getSize(); |
|
599 | + if ( $_zipFilesSize > $zipMaxSize ) { |
|
600 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CREATED_FILE_TOO_BIG); |
|
601 | + } |
|
602 | + } |
|
603 | + $pathName = str_replace('\\','/',$file->getPathname()); |
|
604 | + if ( $file->isDir() ){ |
|
605 | + // skip dot folders on unix systems ( do not try to use isDot() as $file is not a DirectoryIterator obj ) |
|
606 | + if ( in_array($file->getFilename(),array('..','.')) ){ |
|
607 | + continue; |
|
608 | + } |
|
609 | + if ($pathName != rtrim($serverPath,'/')){ |
|
610 | + $allFiles[ ltrim(str_ireplace(rtrim($serverPath,'/'),'',$pathName),'/') ] = ''; |
|
611 | + } |
|
612 | + } else { |
|
613 | + $allFiles[$pathName] = str_ireplace($serverPath,'',$pathName); |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + return $allFiles; |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
@@ -622,229 +622,229 @@ discard block |
||
622 | 622 | */ |
623 | 623 | public function buildXml() |
624 | 624 | { |
625 | - if (!extension_loaded('zip')) { |
|
626 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_COMMAND); |
|
627 | - } |
|
628 | - |
|
629 | - $this->checkConnector(); |
|
630 | - $this->checkRequest(); |
|
631 | - |
|
632 | - if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
633 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
634 | - } |
|
635 | - |
|
636 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
637 | - $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
638 | - $_sServerDir = $this->_currentFolder->getServerPath(); |
|
639 | - |
|
640 | - $files = array(); |
|
641 | - |
|
642 | - $_zipFilesSize = 0; |
|
643 | - $config = $this->getConfig(); |
|
644 | - $zipMaxSize = $config['zipMaxSize']; |
|
645 | - if ( !empty($zipMaxSize) && $zipMaxSize == 'default' ){ |
|
646 | - $zipMaxSize = $currentResourceTypeConfig->getMaxSize(); |
|
647 | - } |
|
648 | - |
|
649 | - $_isBasket = ( isset($_POST['basket']) && $_POST['basket'] == 'true' )? true : false; |
|
650 | - |
|
651 | - if ( !empty($_POST['files'])) |
|
652 | - { |
|
653 | - |
|
654 | - $_aclConfig = $this->_config->getAccessControlConfig(); |
|
655 | - $aclMasks = array(); |
|
656 | - $_resourceTypeConfig = array(); |
|
657 | - |
|
658 | - foreach ( $_POST['files'] as $arr ){ |
|
659 | - if ( empty($arr['name']) || empty($arr['type']) || empty($arr['folder']) ) { |
|
660 | - continue; |
|
661 | - } |
|
662 | - // file name |
|
663 | - $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
664 | - // resource type |
|
665 | - $type = $arr['type']; |
|
666 | - // client path |
|
667 | - $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
668 | - |
|
669 | - // check #1 (path) |
|
670 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
671 | - continue; |
|
672 | - } |
|
673 | - |
|
674 | - // get resource type config for current file |
|
675 | - if (!isset($_resourceTypeConfig[$type])) { |
|
676 | - $_resourceTypeConfig[$type] = $this->_config->getResourceTypeConfig($type); |
|
677 | - } |
|
678 | - |
|
679 | - // check #2 (resource type) |
|
680 | - if (is_null($_resourceTypeConfig[$type])) { |
|
681 | - continue; |
|
682 | - } |
|
683 | - |
|
684 | - // check #3 (extension) |
|
685 | - if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
686 | - continue; |
|
687 | - } |
|
688 | - |
|
689 | - // check #4 (extension) - when moving to another resource type, double check extension |
|
690 | - if ($currentResourceTypeConfig->getName() != $type && !$currentResourceTypeConfig->checkExtension($name, false)) { |
|
691 | - continue; |
|
692 | - } |
|
693 | - |
|
694 | - // check #5 (hidden folders) |
|
695 | - // cache results |
|
696 | - if (empty($checkedPaths[$path])) { |
|
697 | - $checkedPaths[$path] = true; |
|
698 | - |
|
699 | - if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
700 | - continue; |
|
701 | - } |
|
702 | - } |
|
703 | - |
|
704 | - // check #6 (hidden file name) |
|
705 | - if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
706 | - continue; |
|
707 | - } |
|
708 | - |
|
709 | - // check #7 (Access Control, need file view permission to source files) |
|
710 | - if (!isset($aclMasks[$type."@".$path])) { |
|
711 | - $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
712 | - } |
|
713 | - |
|
714 | - $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
715 | - if (!$isAuthorized) { |
|
716 | - continue; |
|
717 | - } |
|
718 | - |
|
719 | - $sourceFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($_resourceTypeConfig[$type]->getDirectory().$path,$name); |
|
720 | - // check #8 (invalid file name) |
|
721 | - if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
722 | - continue; |
|
723 | - } |
|
724 | - |
|
725 | - // check #9 - max file size |
|
726 | - if ( !empty($zipMaxSize) ){ |
|
727 | - clearstatcache(); |
|
728 | - $_zipFilesSize += filesize($sourceFilePath); |
|
729 | - if ( $_zipFilesSize > $zipMaxSize ) { |
|
730 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CREATED_FILE_TOO_BIG); |
|
731 | - } |
|
732 | - } |
|
733 | - |
|
734 | - $zipPathPart = ( $_isBasket ) ? CKFinder_Connector_Utils_FileSystem::combinePaths($type,$path) : ''; |
|
735 | - |
|
736 | - $files[$sourceFilePath] = $zipPathPart.pathinfo($sourceFilePath,PATHINFO_BASENAME); |
|
737 | - } |
|
738 | - } |
|
739 | - else |
|
740 | - { |
|
741 | - if (!is_dir($_sServerDir)) { |
|
742 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
743 | - } |
|
744 | - $files = $this->getFilesRecursively($_sServerDir,$zipMaxSize); |
|
745 | - } |
|
746 | - if ( sizeof($files)<1) { |
|
747 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
748 | - } |
|
749 | - // default destination dir - temp |
|
750 | - $dest_dir = CKFinder_Connector_Utils_FileSystem::getTmpDir(); |
|
751 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
752 | - |
|
753 | - // default file name - hash |
|
754 | - $zip_filename = substr(md5(serialize($files)), 0, 16).$resourceTypeInfo->getHash().'.zip'; |
|
755 | - |
|
756 | - // compress files - do not download them |
|
757 | - // change destination and name |
|
758 | - if ( isset($_POST['download']) && $_POST['download'] == 'false'){ |
|
759 | - $dest_dir = $_sServerDir; |
|
760 | - if ( isset($_POST['zipName']) && !empty($_POST['zipName'])){ |
|
761 | - $zip_filename = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_POST['zipName']); |
|
762 | - if (!$resourceTypeInfo->checkExtension($zip_filename)) { |
|
763 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
764 | - } |
|
765 | - } |
|
766 | - } |
|
767 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($zip_filename) || $resourceTypeInfo->checkIsHiddenFile($zip_filename)) { |
|
768 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
769 | - } |
|
770 | - if ($this->_config->forceAscii()) { |
|
771 | - $zip_filename = CKFinder_Connector_Utils_FileSystem::convertToAscii($zip_filename); |
|
772 | - } |
|
773 | - |
|
774 | - $zipFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir, $zip_filename); |
|
775 | - |
|
776 | - if (!is_writable(dirname($zipFilePath))) { |
|
777 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
778 | - } |
|
779 | - |
|
780 | - // usually we would need to create zip? |
|
781 | - $createZip = true; |
|
782 | - |
|
783 | - // only if file already exists and we want download it |
|
784 | - // do not create new one - because hash of previously created is the same - existing archive is ok |
|
785 | - if ( file_exists($zipFilePath) && isset($_POST['download']) && $_POST['download'] == 'true' ){ |
|
786 | - $createZip = false; |
|
787 | - } |
|
788 | - // if we only want to create archive |
|
789 | - else |
|
790 | - { |
|
791 | - if ( file_exists($zipFilePath) && ( !isset($_POST['fileExistsAction']) || !in_array($_POST['fileExistsAction'], array('autorename','overwrite')) ) ){ |
|
792 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); |
|
793 | - } |
|
794 | - |
|
795 | - if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FILE_UPLOAD )) { |
|
796 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
797 | - } |
|
798 | - // check how to deal with existing file |
|
799 | - if ( isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'autorename' ) |
|
800 | - { |
|
801 | - if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_RENAME )) { |
|
802 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
803 | - } |
|
804 | - $zip_filename = CKFinder_Connector_Utils_FileSystem::autoRename($dest_dir, $zip_filename); |
|
805 | - $zipFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir, $zip_filename); |
|
806 | - } |
|
807 | - elseif ( isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'overwrite' ) |
|
808 | - { |
|
809 | - if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
810 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
811 | - } |
|
812 | - if (!CKFinder_Connector_Utils_FileSystem::unlink($zipFilePath)){ |
|
813 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
814 | - } |
|
815 | - } |
|
816 | - } |
|
817 | - |
|
818 | - if ( $createZip ){ |
|
819 | - $zip = new ZipArchive(); |
|
820 | - $result = $zip->open( $zipFilePath, ZIPARCHIVE::CREATE); |
|
821 | - if ( $result !== TRUE ) { |
|
822 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN); |
|
823 | - } |
|
824 | - foreach ( $files as $pathname => $filename ){ |
|
825 | - if ( !empty($filename) ){ |
|
826 | - if ( file_exists($pathname) && is_readable($pathname) ){ |
|
827 | - $zip->addFile( $pathname, $filename ); |
|
828 | - } |
|
829 | - } else { |
|
830 | - $zip->addEmptyDir( $pathname ); |
|
831 | - } |
|
832 | - } |
|
833 | - $zip->close(); |
|
834 | - } |
|
835 | - |
|
836 | - $file = new CKFinder_Connector_Utils_XmlNode("ZipFile"); |
|
837 | - $file->addAttribute("name", $zip_filename); |
|
838 | - $this->_connectorNode->addChild($file); |
|
625 | + if (!extension_loaded('zip')) { |
|
626 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_COMMAND); |
|
627 | + } |
|
628 | + |
|
629 | + $this->checkConnector(); |
|
630 | + $this->checkRequest(); |
|
631 | + |
|
632 | + if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
633 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
634 | + } |
|
635 | + |
|
636 | + $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
637 | + $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
638 | + $_sServerDir = $this->_currentFolder->getServerPath(); |
|
639 | + |
|
640 | + $files = array(); |
|
641 | + |
|
642 | + $_zipFilesSize = 0; |
|
643 | + $config = $this->getConfig(); |
|
644 | + $zipMaxSize = $config['zipMaxSize']; |
|
645 | + if ( !empty($zipMaxSize) && $zipMaxSize == 'default' ){ |
|
646 | + $zipMaxSize = $currentResourceTypeConfig->getMaxSize(); |
|
647 | + } |
|
648 | + |
|
649 | + $_isBasket = ( isset($_POST['basket']) && $_POST['basket'] == 'true' )? true : false; |
|
650 | + |
|
651 | + if ( !empty($_POST['files'])) |
|
652 | + { |
|
653 | + |
|
654 | + $_aclConfig = $this->_config->getAccessControlConfig(); |
|
655 | + $aclMasks = array(); |
|
656 | + $_resourceTypeConfig = array(); |
|
657 | + |
|
658 | + foreach ( $_POST['files'] as $arr ){ |
|
659 | + if ( empty($arr['name']) || empty($arr['type']) || empty($arr['folder']) ) { |
|
660 | + continue; |
|
661 | + } |
|
662 | + // file name |
|
663 | + $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
664 | + // resource type |
|
665 | + $type = $arr['type']; |
|
666 | + // client path |
|
667 | + $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
668 | + |
|
669 | + // check #1 (path) |
|
670 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
671 | + continue; |
|
672 | + } |
|
673 | + |
|
674 | + // get resource type config for current file |
|
675 | + if (!isset($_resourceTypeConfig[$type])) { |
|
676 | + $_resourceTypeConfig[$type] = $this->_config->getResourceTypeConfig($type); |
|
677 | + } |
|
678 | + |
|
679 | + // check #2 (resource type) |
|
680 | + if (is_null($_resourceTypeConfig[$type])) { |
|
681 | + continue; |
|
682 | + } |
|
683 | + |
|
684 | + // check #3 (extension) |
|
685 | + if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
686 | + continue; |
|
687 | + } |
|
688 | + |
|
689 | + // check #4 (extension) - when moving to another resource type, double check extension |
|
690 | + if ($currentResourceTypeConfig->getName() != $type && !$currentResourceTypeConfig->checkExtension($name, false)) { |
|
691 | + continue; |
|
692 | + } |
|
693 | + |
|
694 | + // check #5 (hidden folders) |
|
695 | + // cache results |
|
696 | + if (empty($checkedPaths[$path])) { |
|
697 | + $checkedPaths[$path] = true; |
|
698 | + |
|
699 | + if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
700 | + continue; |
|
701 | + } |
|
702 | + } |
|
703 | + |
|
704 | + // check #6 (hidden file name) |
|
705 | + if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
706 | + continue; |
|
707 | + } |
|
708 | + |
|
709 | + // check #7 (Access Control, need file view permission to source files) |
|
710 | + if (!isset($aclMasks[$type."@".$path])) { |
|
711 | + $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
712 | + } |
|
713 | + |
|
714 | + $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
715 | + if (!$isAuthorized) { |
|
716 | + continue; |
|
717 | + } |
|
718 | + |
|
719 | + $sourceFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($_resourceTypeConfig[$type]->getDirectory().$path,$name); |
|
720 | + // check #8 (invalid file name) |
|
721 | + if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
722 | + continue; |
|
723 | + } |
|
724 | + |
|
725 | + // check #9 - max file size |
|
726 | + if ( !empty($zipMaxSize) ){ |
|
727 | + clearstatcache(); |
|
728 | + $_zipFilesSize += filesize($sourceFilePath); |
|
729 | + if ( $_zipFilesSize > $zipMaxSize ) { |
|
730 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CREATED_FILE_TOO_BIG); |
|
731 | + } |
|
732 | + } |
|
733 | + |
|
734 | + $zipPathPart = ( $_isBasket ) ? CKFinder_Connector_Utils_FileSystem::combinePaths($type,$path) : ''; |
|
735 | + |
|
736 | + $files[$sourceFilePath] = $zipPathPart.pathinfo($sourceFilePath,PATHINFO_BASENAME); |
|
737 | + } |
|
738 | + } |
|
739 | + else |
|
740 | + { |
|
741 | + if (!is_dir($_sServerDir)) { |
|
742 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
743 | + } |
|
744 | + $files = $this->getFilesRecursively($_sServerDir,$zipMaxSize); |
|
745 | + } |
|
746 | + if ( sizeof($files)<1) { |
|
747 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
748 | + } |
|
749 | + // default destination dir - temp |
|
750 | + $dest_dir = CKFinder_Connector_Utils_FileSystem::getTmpDir(); |
|
751 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
752 | + |
|
753 | + // default file name - hash |
|
754 | + $zip_filename = substr(md5(serialize($files)), 0, 16).$resourceTypeInfo->getHash().'.zip'; |
|
755 | + |
|
756 | + // compress files - do not download them |
|
757 | + // change destination and name |
|
758 | + if ( isset($_POST['download']) && $_POST['download'] == 'false'){ |
|
759 | + $dest_dir = $_sServerDir; |
|
760 | + if ( isset($_POST['zipName']) && !empty($_POST['zipName'])){ |
|
761 | + $zip_filename = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_POST['zipName']); |
|
762 | + if (!$resourceTypeInfo->checkExtension($zip_filename)) { |
|
763 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
764 | + } |
|
765 | + } |
|
766 | + } |
|
767 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($zip_filename) || $resourceTypeInfo->checkIsHiddenFile($zip_filename)) { |
|
768 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
769 | + } |
|
770 | + if ($this->_config->forceAscii()) { |
|
771 | + $zip_filename = CKFinder_Connector_Utils_FileSystem::convertToAscii($zip_filename); |
|
772 | + } |
|
773 | + |
|
774 | + $zipFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir, $zip_filename); |
|
775 | + |
|
776 | + if (!is_writable(dirname($zipFilePath))) { |
|
777 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
778 | + } |
|
779 | + |
|
780 | + // usually we would need to create zip? |
|
781 | + $createZip = true; |
|
782 | + |
|
783 | + // only if file already exists and we want download it |
|
784 | + // do not create new one - because hash of previously created is the same - existing archive is ok |
|
785 | + if ( file_exists($zipFilePath) && isset($_POST['download']) && $_POST['download'] == 'true' ){ |
|
786 | + $createZip = false; |
|
787 | + } |
|
788 | + // if we only want to create archive |
|
789 | + else |
|
790 | + { |
|
791 | + if ( file_exists($zipFilePath) && ( !isset($_POST['fileExistsAction']) || !in_array($_POST['fileExistsAction'], array('autorename','overwrite')) ) ){ |
|
792 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); |
|
793 | + } |
|
794 | + |
|
795 | + if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FILE_UPLOAD )) { |
|
796 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
797 | + } |
|
798 | + // check how to deal with existing file |
|
799 | + if ( isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'autorename' ) |
|
800 | + { |
|
801 | + if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_RENAME )) { |
|
802 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
803 | + } |
|
804 | + $zip_filename = CKFinder_Connector_Utils_FileSystem::autoRename($dest_dir, $zip_filename); |
|
805 | + $zipFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir, $zip_filename); |
|
806 | + } |
|
807 | + elseif ( isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'overwrite' ) |
|
808 | + { |
|
809 | + if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
810 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
811 | + } |
|
812 | + if (!CKFinder_Connector_Utils_FileSystem::unlink($zipFilePath)){ |
|
813 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
814 | + } |
|
815 | + } |
|
816 | + } |
|
817 | + |
|
818 | + if ( $createZip ){ |
|
819 | + $zip = new ZipArchive(); |
|
820 | + $result = $zip->open( $zipFilePath, ZIPARCHIVE::CREATE); |
|
821 | + if ( $result !== TRUE ) { |
|
822 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN); |
|
823 | + } |
|
824 | + foreach ( $files as $pathname => $filename ){ |
|
825 | + if ( !empty($filename) ){ |
|
826 | + if ( file_exists($pathname) && is_readable($pathname) ){ |
|
827 | + $zip->addFile( $pathname, $filename ); |
|
828 | + } |
|
829 | + } else { |
|
830 | + $zip->addEmptyDir( $pathname ); |
|
831 | + } |
|
832 | + } |
|
833 | + $zip->close(); |
|
834 | + } |
|
835 | + |
|
836 | + $file = new CKFinder_Connector_Utils_XmlNode("ZipFile"); |
|
837 | + $file->addAttribute("name", $zip_filename); |
|
838 | + $this->_connectorNode->addChild($file); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | public function onBeforeExecuteCommand( &$command ) |
842 | 842 | { |
843 | - if ( $command == 'CreateZip'){ |
|
844 | - $this->sendResponse(); |
|
845 | - return false; |
|
846 | - } |
|
847 | - return true ; |
|
843 | + if ( $command == 'CreateZip'){ |
|
844 | + $this->sendResponse(); |
|
845 | + return false; |
|
846 | + } |
|
847 | + return true ; |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | } // end of CKFinder_Connector_CommandHandler_DownloadZip class |
@@ -856,77 +856,77 @@ discard block |
||
856 | 856 | */ |
857 | 857 | protected function sendZipFile() |
858 | 858 | { |
859 | - if (!function_exists('ob_list_handlers') || ob_list_handlers()) { |
|
860 | - @ob_end_clean(); |
|
861 | - } |
|
862 | - header("Content-Encoding: none"); |
|
863 | - |
|
864 | - $this->checkConnector(); |
|
865 | - $this->checkRequest(); |
|
866 | - |
|
867 | - // empty wystarczy |
|
868 | - if ( empty($_GET['FileName']) ){ |
|
869 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
870 | - } |
|
871 | - |
|
872 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
873 | - $hash = $resourceTypeInfo->getHash(); |
|
874 | - if ( $hash !== $_GET['hash'] || $hash !== substr($_GET['FileName'],16,16) ){ |
|
875 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
876 | - } |
|
877 | - |
|
878 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { |
|
879 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
880 | - } |
|
881 | - |
|
882 | - $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(trim($_GET['FileName'])); |
|
883 | - |
|
884 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) { |
|
885 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
886 | - } |
|
887 | - |
|
888 | - if ( strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip'){ |
|
889 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
890 | - } |
|
891 | - |
|
892 | - $dest_dir = CKFinder_Connector_Utils_FileSystem::getTmpDir(); |
|
893 | - $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir,$fileName); |
|
894 | - if ( !file_exists($filePath) || !is_file($filePath)) { |
|
895 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
896 | - } |
|
897 | - if (!is_readable($filePath)) { |
|
898 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
899 | - } |
|
900 | - |
|
901 | - $zipFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(trim($_GET['ZipName'])); |
|
902 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($zipFileName)) { |
|
903 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
904 | - } |
|
905 | - $fileFilename = pathinfo($zipFileName,PATHINFO_BASENAME ); |
|
906 | - |
|
907 | - header("Content-Encoding: none"); |
|
908 | - header("Cache-Control: cache, must-revalidate"); |
|
909 | - header("Pragma: public"); |
|
910 | - header("Expires: 0"); |
|
911 | - $user_agent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; |
|
912 | - $encodedName = str_replace("\"", "\\\"", $fileFilename); |
|
913 | - if (strpos($user_agent, "MSIE") !== false) { |
|
914 | - $encodedName = str_replace(array("+", "%2E"), array(" ", "."), urlencode($encodedName)); |
|
915 | - } |
|
916 | - header("Content-type: application/octet-stream; name=\"" . $fileFilename . "\""); |
|
917 | - header("Content-Disposition: attachment; filename=\"" . $encodedName. "\""); |
|
918 | - header("Content-Length: " . filesize($filePath)); |
|
919 | - CKFinder_Connector_Utils_FileSystem::sendFile($filePath); |
|
920 | - exit; |
|
859 | + if (!function_exists('ob_list_handlers') || ob_list_handlers()) { |
|
860 | + @ob_end_clean(); |
|
861 | + } |
|
862 | + header("Content-Encoding: none"); |
|
863 | + |
|
864 | + $this->checkConnector(); |
|
865 | + $this->checkRequest(); |
|
866 | + |
|
867 | + // empty wystarczy |
|
868 | + if ( empty($_GET['FileName']) ){ |
|
869 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
870 | + } |
|
871 | + |
|
872 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
873 | + $hash = $resourceTypeInfo->getHash(); |
|
874 | + if ( $hash !== $_GET['hash'] || $hash !== substr($_GET['FileName'],16,16) ){ |
|
875 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
876 | + } |
|
877 | + |
|
878 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { |
|
879 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
880 | + } |
|
881 | + |
|
882 | + $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(trim($_GET['FileName'])); |
|
883 | + |
|
884 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) { |
|
885 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
886 | + } |
|
887 | + |
|
888 | + if ( strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip'){ |
|
889 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
890 | + } |
|
891 | + |
|
892 | + $dest_dir = CKFinder_Connector_Utils_FileSystem::getTmpDir(); |
|
893 | + $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir,$fileName); |
|
894 | + if ( !file_exists($filePath) || !is_file($filePath)) { |
|
895 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
896 | + } |
|
897 | + if (!is_readable($filePath)) { |
|
898 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
899 | + } |
|
900 | + |
|
901 | + $zipFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(trim($_GET['ZipName'])); |
|
902 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($zipFileName)) { |
|
903 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
904 | + } |
|
905 | + $fileFilename = pathinfo($zipFileName,PATHINFO_BASENAME ); |
|
906 | + |
|
907 | + header("Content-Encoding: none"); |
|
908 | + header("Cache-Control: cache, must-revalidate"); |
|
909 | + header("Pragma: public"); |
|
910 | + header("Expires: 0"); |
|
911 | + $user_agent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; |
|
912 | + $encodedName = str_replace("\"", "\\\"", $fileFilename); |
|
913 | + if (strpos($user_agent, "MSIE") !== false) { |
|
914 | + $encodedName = str_replace(array("+", "%2E"), array(" ", "."), urlencode($encodedName)); |
|
915 | + } |
|
916 | + header("Content-type: application/octet-stream; name=\"" . $fileFilename . "\""); |
|
917 | + header("Content-Disposition: attachment; filename=\"" . $encodedName. "\""); |
|
918 | + header("Content-Length: " . filesize($filePath)); |
|
919 | + CKFinder_Connector_Utils_FileSystem::sendFile($filePath); |
|
920 | + exit; |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | public function onBeforeExecuteCommand( &$command ) |
924 | 924 | { |
925 | - if ( $command == 'DownloadZip'){ |
|
926 | - $this->sendZipFile(); |
|
927 | - return false; |
|
928 | - } |
|
929 | - return true ; |
|
925 | + if ( $command == 'DownloadZip'){ |
|
926 | + $this->sendZipFile(); |
|
927 | + return false; |
|
928 | + } |
|
929 | + return true ; |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | } // end of CKFinder_Connector_CommandHandler_DownloadZip |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Include base XML command handler |
19 | 19 | */ |
20 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php"; |
|
20 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/XmlCommandHandlerBase.php"; |
|
21 | 21 | |
22 | 22 | class CKFinder_Connector_CommandHandler_Unzip extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
23 | 23 | { |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $this->checkConnector(); |
42 | 42 | $this->checkRequest(); |
43 | 43 | |
44 | - if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
44 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
45 | 45 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
46 | 46 | } |
47 | 47 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
71 | 71 | } |
72 | 72 | |
73 | - if ( strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip'){ |
|
73 | + if (strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip') { |
|
74 | 74 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
75 | 75 | } |
76 | 76 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | } |
82 | 82 | $this->zip = $zip; |
83 | 83 | $this->filePath = $filePath; |
84 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
84 | + $this->_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
85 | 85 | |
86 | 86 | // list of unzipped nodes |
87 | 87 | $this->unzippedNodes = new CKFinder_Connector_Utils_XmlNode("UnzippedFiles"); |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | * @param string $originalFileName |
99 | 99 | * @return mixed bool(false) - if security checks fails. Otherwise string - ralative zip archive path with secured filename. |
100 | 100 | */ |
101 | - protected function checkOneFile($filePathInfo, $originalFileName ) |
|
101 | + protected function checkOneFile($filePathInfo, $originalFileName) |
|
102 | 102 | { |
103 | 103 | $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
104 | 104 | |
105 | 105 | // checked if it is a folder |
106 | 106 | $fileStat = $this->zip->statName($originalFileName); |
107 | - if ( empty($filePathInfo['extension']) && empty($fileStat['size']) ){ |
|
108 | - $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(rtrim($fileStat['name'],'/')); |
|
107 | + if (empty($filePathInfo['extension']) && empty($fileStat['size'])) { |
|
108 | + $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(rtrim($fileStat['name'], '/')); |
|
109 | 109 | if ($this->_config->forceAscii()) { |
110 | 110 | $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sNewFolderName); |
111 | 111 | } |
@@ -129,21 +129,21 @@ discard block |
||
129 | 129 | |
130 | 130 | // max file size |
131 | 131 | $maxSize = $resourceTypeInfo->getMaxSize(); |
132 | - if ( $maxSize && $fileStat['size'] > $maxSize ) |
|
132 | + if ($maxSize && $fileStat['size'] > $maxSize) |
|
133 | 133 | { |
134 | 134 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
135 | 135 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | // extension |
139 | - if ( !$resourceTypeInfo->checkExtension($sFileName) ) |
|
139 | + if (!$resourceTypeInfo->checkExtension($sFileName)) |
|
140 | 140 | { |
141 | 141 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
142 | 142 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | // hidden file |
146 | - if ( !CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $resourceTypeInfo->checkIsHiddenFile($sFileName) ){ |
|
146 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $resourceTypeInfo->checkIsHiddenFile($sFileName)) { |
|
147 | 147 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST; |
148 | 148 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
149 | 149 | return false; |
@@ -151,19 +151,19 @@ discard block |
||
151 | 151 | |
152 | 152 | // unpack file to tmp dir for detecting html and valid image |
153 | 153 | $dir = CKFinder_Connector_Utils_FileSystem::getTmpDir().'/'; |
154 | - if ( file_exists($dir.$sFileName) && !CKFinder_Connector_Utils_FileSystem::unlink($dir.$sFileName) ){ |
|
154 | + if (file_exists($dir.$sFileName) && !CKFinder_Connector_Utils_FileSystem::unlink($dir.$sFileName)) { |
|
155 | 155 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST; |
156 | 156 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
157 | 157 | return false; |
158 | 158 | } |
159 | - if ( copy('zip://'.$this->filePath.'#'.$originalFileName, $dir.$sFileName) ) |
|
159 | + if (copy('zip://'.$this->filePath.'#'.$originalFileName, $dir.$sFileName)) |
|
160 | 160 | { |
161 | 161 | // html extensions |
162 | 162 | $htmlExtensions = $this->_config->getHtmlExtensions(); |
163 | - $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension( $dir.$sFileName ); |
|
164 | - if ( $htmlExtensions |
|
165 | - && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive( $sExtension, $htmlExtensions ) |
|
166 | - && CKFinder_Connector_Utils_FileSystem::detectHtml($dir.$sFileName) === true ) |
|
163 | + $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($dir.$sFileName); |
|
164 | + if ($htmlExtensions |
|
165 | + && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) |
|
166 | + && CKFinder_Connector_Utils_FileSystem::detectHtml($dir.$sFileName) === true) |
|
167 | 167 | { |
168 | 168 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID; |
169 | 169 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | |
173 | 173 | // proper image |
174 | 174 | $secureImageUploads = $this->_config->getSecureImageUploads(); |
175 | - if ( $secureImageUploads |
|
176 | - && ( $isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($dir.$sFileName, $sExtension) ) === false ) |
|
175 | + if ($secureImageUploads |
|
176 | + && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($dir.$sFileName, $sExtension)) === false) |
|
177 | 177 | { |
178 | 178 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID; |
179 | 179 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
180 | 180 | return false; |
181 | 181 | } |
182 | 182 | } |
183 | - $sDirName = ($filePathInfo['dirname'] != '.')? $filePathInfo['dirname'].'/' : ''; |
|
183 | + $sDirName = ($filePathInfo['dirname'] != '.') ? $filePathInfo['dirname'].'/' : ''; |
|
184 | 184 | |
185 | 185 | return $sDirName.$sFileName; |
186 | 186 | } |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | * @param string $type |
194 | 194 | * @param string $path |
195 | 195 | */ |
196 | - protected function appendErrorNode($oErrorsNode, $errorCode=0, $name, $type=null, $path=null) |
|
196 | + protected function appendErrorNode($oErrorsNode, $errorCode = 0, $name, $type = null, $path = null) |
|
197 | 197 | { |
198 | 198 | $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
199 | 199 | $oErrorNode->addAttribute("code", $errorCode); |
200 | 200 | $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
201 | - if ( $type ){ |
|
201 | + if ($type) { |
|
202 | 202 | $oErrorNode->addAttribute("type", $type); |
203 | 203 | } |
204 | - if ( $path ){ |
|
204 | + if ($path) { |
|
205 | 205 | $oErrorNode->addAttribute("folder", $path); |
206 | 206 | } |
207 | 207 | $oErrorsNode->addChild($oErrorNode); |
@@ -213,11 +213,11 @@ discard block |
||
213 | 213 | * @param string $name |
214 | 214 | * @param string $action |
215 | 215 | */ |
216 | - protected function appendUnzippedNode($oUnzippedNodes, $name, $action='ok') |
|
216 | + protected function appendUnzippedNode($oUnzippedNodes, $name, $action = 'ok') |
|
217 | 217 | { |
218 | 218 | $oUnzippedNode = new CKFinder_Connector_Utils_XmlNode("File"); |
219 | 219 | $oUnzippedNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
220 | - $oUnzippedNode->addAttribute("action", $action ); |
|
220 | + $oUnzippedNode->addAttribute("action", $action); |
|
221 | 221 | $oUnzippedNodes->addChild($oUnzippedNode); |
222 | 222 | } |
223 | 223 | |
@@ -234,32 +234,32 @@ discard block |
||
234 | 234 | { |
235 | 235 | $sfilePathInfo = pathinfo($extractPath.$sFileName); |
236 | 236 | $extractClientPathDir = $filePathInfo['dirname']; |
237 | - if ( $filePathInfo['dirname'] == '.' ){ |
|
237 | + if ($filePathInfo['dirname'] == '.') { |
|
238 | 238 | $extractClientPathDir = ''; |
239 | 239 | } |
240 | - $folderPath = CKFinder_Connector_Utils_FileSystem::combinePaths($extractClientPath,$extractClientPathDir); |
|
240 | + $folderPath = CKFinder_Connector_Utils_FileSystem::combinePaths($extractClientPath, $extractClientPathDir); |
|
241 | 241 | |
242 | 242 | $_aclConfig = $this->_config->getAccessControlConfig(); |
243 | - $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(),$folderPath); |
|
244 | - $canCreateFolder = (($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ); |
|
243 | + $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(), $folderPath); |
|
244 | + $canCreateFolder = (($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE); |
|
245 | 245 | // create sub-directory of zip archive |
246 | - if ( empty($sfilePathInfo['extension']) ) |
|
246 | + if (empty($sfilePathInfo['extension'])) |
|
247 | 247 | { |
248 | 248 | $fileStat = $this->zip->statName($originalFileName); |
249 | 249 | $isDir = false; |
250 | - if ( $fileStat && empty($fileStat['size']) ){ |
|
250 | + if ($fileStat && empty($fileStat['size'])) { |
|
251 | 251 | $isDir = true; |
252 | 252 | } |
253 | - if( !empty($sfilePathInfo['dirname']) && !empty($sfilePathInfo['basename']) && !file_exists($sfilePathInfo['dirname'].'/'.$sfilePathInfo['basename']) ) |
|
253 | + if (!empty($sfilePathInfo['dirname']) && !empty($sfilePathInfo['basename']) && !file_exists($sfilePathInfo['dirname'].'/'.$sfilePathInfo['basename'])) |
|
254 | 254 | { |
255 | - if ( !$canCreateFolder ){ |
|
255 | + if (!$canCreateFolder) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | - if ( $isDir ) { |
|
259 | - CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively( $sfilePathInfo['dirname'].'/'.$sfilePathInfo['basename'] ); |
|
258 | + if ($isDir) { |
|
259 | + CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($sfilePathInfo['dirname'].'/'.$sfilePathInfo['basename']); |
|
260 | 260 | return; |
261 | 261 | } else { |
262 | - CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively( $sfilePathInfo['dirname']); |
|
262 | + CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($sfilePathInfo['dirname']); |
|
263 | 263 | } |
264 | 264 | } else { |
265 | 265 | return; |
@@ -267,29 +267,29 @@ discard block |
||
267 | 267 | } |
268 | 268 | |
269 | 269 | // extract file |
270 | - if ( !file_exists($sfilePathInfo['dirname']) ){ |
|
271 | - if ( !$canCreateFolder ){ |
|
270 | + if (!file_exists($sfilePathInfo['dirname'])) { |
|
271 | + if (!$canCreateFolder) { |
|
272 | 272 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
273 | - $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName ); |
|
273 | + $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
|
274 | 274 | return; |
275 | 275 | } |
276 | 276 | CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($sfilePathInfo['dirname']); |
277 | 277 | } |
278 | - $isAuthorized = (($aclMask & CKFINDER_CONNECTOR_ACL_FILE_UPLOAD ) == CKFINDER_CONNECTOR_ACL_FILE_UPLOAD ); |
|
279 | - if ( !$isAuthorized ){ |
|
278 | + $isAuthorized = (($aclMask & CKFINDER_CONNECTOR_ACL_FILE_UPLOAD) == CKFINDER_CONNECTOR_ACL_FILE_UPLOAD); |
|
279 | + if (!$isAuthorized) { |
|
280 | 280 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_COPY_FAILED; |
281 | 281 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); |
282 | 282 | return; |
283 | 283 | } |
284 | - if ( copy('zip://'.$this->filePath.'#'.$originalFileName, $extractPath.$sFileName) ) |
|
284 | + if (copy('zip://'.$this->filePath.'#'.$originalFileName, $extractPath.$sFileName)) |
|
285 | 285 | { |
286 | - $this->appendUnzippedNode($this->unzippedNodes,$originalFileName); |
|
286 | + $this->appendUnzippedNode($this->unzippedNodes, $originalFileName); |
|
287 | 287 | // chmod extracted file |
288 | - if ( is_file($extractPath.$sFileName) && ( $perms = $this->_config->getChmodFiles()) ) |
|
288 | + if (is_file($extractPath.$sFileName) && ($perms = $this->_config->getChmodFiles())) |
|
289 | 289 | { |
290 | 290 | $oldumask = umask(0); |
291 | - chmod( $extractPath.$sFileName, $perms ); |
|
292 | - umask( $oldumask ); |
|
291 | + chmod($extractPath.$sFileName, $perms); |
|
292 | + umask($oldumask); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | // file extraction failed, add to skipped |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | parent::buildXml(); |
313 | 313 | |
314 | 314 | $checkedFiles = array(); |
315 | - if ( !empty($_POST['files']) && is_array($_POST['files']) ){ |
|
316 | - foreach ( $_POST['files'] as $file){ |
|
315 | + if (!empty($_POST['files']) && is_array($_POST['files'])) { |
|
316 | + foreach ($_POST['files'] as $file) { |
|
317 | 317 | $checkedFiles[$file['name']] = $file; |
318 | 318 | } |
319 | 319 | } |
@@ -321,20 +321,20 @@ discard block |
||
321 | 321 | for ($i = 0; $i < $this->zip->numFiles; $i++) |
322 | 322 | { |
323 | 323 | $fileName = $this->zip->getNameIndex($i); |
324 | - if ( !empty($checkedFiles[$fileName]) && $checkedFiles[$fileName]['options'] == 'ok' ) |
|
324 | + if (!empty($checkedFiles[$fileName]) && $checkedFiles[$fileName]['options'] == 'ok') |
|
325 | 325 | { |
326 | 326 | // file was sucessfully unzipped before |
327 | - $this->appendUnzippedNode($this->unzippedNodes,$fileName); |
|
327 | + $this->appendUnzippedNode($this->unzippedNodes, $fileName); |
|
328 | 328 | continue; |
329 | 329 | } |
330 | 330 | |
331 | 331 | $filePathInfo = pathinfo($fileName); |
332 | 332 | $fileType = 'File'; |
333 | 333 | $fileStat = $this->zip->statName($i); |
334 | - if ( empty($filePathInfo['extension']) && empty($fileStat['size']) ){ |
|
334 | + if (empty($filePathInfo['extension']) && empty($fileStat['size'])) { |
|
335 | 335 | $fileType = 'Folder'; |
336 | 336 | // check if we can create subfolder |
337 | - if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) ){ |
|
337 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_CREATE)) { |
|
338 | 338 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
339 | 339 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
340 | 340 | continue; |
@@ -343,25 +343,25 @@ discard block |
||
343 | 343 | $extractPath = $this->_currentFolder->getServerPath(); |
344 | 344 | $extractClientPath = $this->_currentFolder->getClientPath(); |
345 | 345 | |
346 | - $sFileName = $this->checkOneFile( $filePathInfo, $fileName ); |
|
346 | + $sFileName = $this->checkOneFile($filePathInfo, $fileName); |
|
347 | 347 | // security test failed, add to skipped |
348 | - if ( false !== $sFileName ) |
|
348 | + if (false !== $sFileName) |
|
349 | 349 | { |
350 | - if ( file_exists($extractPath.$sFileName) ) |
|
350 | + if (file_exists($extractPath.$sFileName)) |
|
351 | 351 | { |
352 | - if ( !is_dir($extractPath.$sFileName) ) |
|
352 | + if (!is_dir($extractPath.$sFileName)) |
|
353 | 353 | { |
354 | 354 | // file was checked before |
355 | - if ( !empty($checkedFiles[$fileName]['options']) ) |
|
355 | + if (!empty($checkedFiles[$fileName]['options'])) |
|
356 | 356 | { |
357 | - if ( $checkedFiles[$fileName]['options'] == 'autorename') |
|
357 | + if ($checkedFiles[$fileName]['options'] == 'autorename') |
|
358 | 358 | { |
359 | - $sFileName = CKFinder_Connector_Utils_FileSystem::autoRename($extractPath,$sFileName); |
|
360 | - $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
359 | + $sFileName = CKFinder_Connector_Utils_FileSystem::autoRename($extractPath, $sFileName); |
|
360 | + $this->extractTo($extractPath, $extractClientPath, $filePathInfo, $sFileName, $fileName); |
|
361 | 361 | } |
362 | - elseif ( $checkedFiles[$fileName]['options'] == 'overwrite') |
|
362 | + elseif ($checkedFiles[$fileName]['options'] == 'overwrite') |
|
363 | 363 | { |
364 | - if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FILE_DELETE ) ){ |
|
364 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
365 | 365 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
366 | 366 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
367 | 367 | continue; |
@@ -373,13 +373,13 @@ discard block |
||
373 | 373 | } |
374 | 374 | else |
375 | 375 | { |
376 | - $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
376 | + $this->extractTo($extractPath, $extractClientPath, $filePathInfo, $sFileName, $fileName); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | else |
380 | 380 | { |
381 | 381 | // add to skipped files |
382 | - $this->appendUnzippedNode($this->unzippedNodes,$fileName,'skip'); |
|
382 | + $this->appendUnzippedNode($this->unzippedNodes, $fileName, 'skip'); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | else |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | // file doesn't exist yet |
393 | 393 | else |
394 | 394 | { |
395 | - $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
395 | + $this->extractTo($extractPath, $extractClientPath, $filePathInfo, $sFileName, $fileName); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | } |
@@ -406,14 +406,14 @@ discard block |
||
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | - public function onBeforeExecuteCommand( &$command ) |
|
409 | + public function onBeforeExecuteCommand(&$command) |
|
410 | 410 | { |
411 | - if ( $command == 'ExtractHere' ) |
|
411 | + if ($command == 'ExtractHere') |
|
412 | 412 | { |
413 | 413 | $this->sendResponse(); |
414 | 414 | return false; |
415 | 415 | } |
416 | - return true ; |
|
416 | + return true; |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | } // end of CKFinder_Connector_CommandHandler_UnzipHere class |
@@ -427,21 +427,21 @@ discard block |
||
427 | 427 | { |
428 | 428 | parent::buildXml(); |
429 | 429 | |
430 | - $extractDir = ( !empty($_POST['extractDir']) ) ? ltrim($_POST['extractDir'],'/') : ''; |
|
430 | + $extractDir = (!empty($_POST['extractDir'])) ? ltrim($_POST['extractDir'], '/') : ''; |
|
431 | 431 | $extractDir = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($extractDir); |
432 | - if ( preg_match(CKFINDER_REGEX_INVALID_PATH, $extractDir) ){ |
|
432 | + if (preg_match(CKFINDER_REGEX_INVALID_PATH, $extractDir)) { |
|
433 | 433 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
434 | 434 | } |
435 | 435 | $extractPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $extractDir.'/'); |
436 | - $extractClientPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getClientPath(),$extractDir); |
|
436 | + $extractClientPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getClientPath(), $extractDir); |
|
437 | 437 | // acl for upload dir |
438 | 438 | $_aclConfig = $this->_config->getAccessControlConfig(); |
439 | - $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(),$extractDir); |
|
439 | + $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(), $extractDir); |
|
440 | 440 | |
441 | - if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE ) ){ |
|
441 | + if (!(($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE)) { |
|
442 | 442 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
443 | 443 | } |
444 | - if ( empty( $_POST['force']) && file_exists($extractPath) && is_dir($extractPath) && !CKFinder_Connector_Utils_FileSystem::isEmptyDir($extractPath) ) |
|
444 | + if (empty($_POST['force']) && file_exists($extractPath) && is_dir($extractPath) && !CKFinder_Connector_Utils_FileSystem::isEmptyDir($extractPath)) |
|
445 | 445 | { |
446 | 446 | $dirExists = new CKFinder_Connector_Utils_XmlNode("FolderExists"); |
447 | 447 | $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Folder"); |
@@ -450,14 +450,14 @@ discard block |
||
450 | 450 | $this->_connectorNode->addChild($dirExists); |
451 | 451 | return; |
452 | 452 | } |
453 | - elseif ( !empty( $_POST['force']) && $_POST['force'] =='overwrite' ) |
|
453 | + elseif (!empty($_POST['force']) && $_POST['force'] == 'overwrite') |
|
454 | 454 | { |
455 | - if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE ) == CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE ) ){ |
|
455 | + if (!(($aclMask & CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE) == CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
456 | 456 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
457 | 457 | } |
458 | - if ( $extractDir && file_exists($extractPath) && is_dir($extractPath) ) |
|
458 | + if ($extractDir && file_exists($extractPath) && is_dir($extractPath)) |
|
459 | 459 | { |
460 | - if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE | CKFINDER_CONNECTOR_ACL_FOLDER_DELETE ) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE | CKFINDER_CONNECTOR_ACL_FOLDER_DELETE ) ){ |
|
460 | + if (!(($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_CREATE | CKFINDER_CONNECTOR_ACL_FOLDER_DELETE) == CKFINDER_CONNECTOR_ACL_FOLDER_CREATE | CKFINDER_CONNECTOR_ACL_FOLDER_DELETE)) { |
|
461 | 461 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
462 | 462 | } |
463 | 463 | if (!CKFinder_Connector_Utils_FileSystem::unlink($extractPath)) |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | } |
467 | 467 | } |
468 | 468 | } |
469 | - else if ( !empty( $_POST['force']) && $_POST['force'] !== 'merge' ) |
|
469 | + else if (!empty($_POST['force']) && $_POST['force'] !== 'merge') |
|
470 | 470 | { |
471 | 471 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
472 | 472 | } |
@@ -476,11 +476,11 @@ discard block |
||
476 | 476 | $fileName = $this->zip->getNameIndex($i); |
477 | 477 | $filePathInfo = pathinfo($fileName); |
478 | 478 | |
479 | - $sFileName = $this->checkOneFile( $filePathInfo, $fileName ); |
|
479 | + $sFileName = $this->checkOneFile($filePathInfo, $fileName); |
|
480 | 480 | // security test failed, add to skipped |
481 | - if ( $sFileName ) |
|
481 | + if ($sFileName) |
|
482 | 482 | { |
483 | - $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
|
483 | + $this->extractTo($extractPath, $extractClientPath, $filePathInfo, $sFileName, $fileName); |
|
484 | 484 | } |
485 | 485 | } |
486 | 486 | $this->zip->close(); |
@@ -494,13 +494,13 @@ discard block |
||
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | - public function onBeforeExecuteCommand( &$command ) |
|
497 | + public function onBeforeExecuteCommand(&$command) |
|
498 | 498 | { |
499 | - if ( $command == 'ExtractTo'){ |
|
499 | + if ($command == 'ExtractTo') { |
|
500 | 500 | $this->sendResponse(); |
501 | 501 | return false; |
502 | 502 | } |
503 | - return true ; |
|
503 | + return true; |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | } // end of CKFinder_Connector_CommandHandler_UnzipTo class |
@@ -516,11 +516,11 @@ discard block |
||
516 | 516 | * @access protected |
517 | 517 | * @return array |
518 | 518 | */ |
519 | - protected function getConfig(){ |
|
519 | + protected function getConfig() { |
|
520 | 520 | $config = array(); |
521 | 521 | |
522 | 522 | $config['zipMaxSize'] = 'default'; |
523 | - if (isset($GLOBALS['config']['ZipMaxSize']) && (string)$GLOBALS['config']['ZipMaxSize']!='default' ){ |
|
523 | + if (isset($GLOBALS['config']['ZipMaxSize']) && (string)$GLOBALS['config']['ZipMaxSize'] != 'default') { |
|
524 | 524 | $config['zipMaxSize'] = CKFinder_Connector_Utils_Misc::returnBytes((string)$GLOBALS['config']['ZipMaxSize']); |
525 | 525 | } |
526 | 526 | |
@@ -538,38 +538,38 @@ discard block |
||
538 | 538 | { |
539 | 539 | $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
540 | 540 | $_aclConfig = $this->_config->getAccessControlConfig(); |
541 | - $directory = str_replace('\\','/', $resourceTypeInfo->getDirectory()); |
|
541 | + $directory = str_replace('\\', '/', $resourceTypeInfo->getDirectory()); |
|
542 | 542 | $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($file->getFilename()); |
543 | 543 | |
544 | 544 | if ($this->_config->forceAscii()) { |
545 | 545 | $fileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($fileName); |
546 | 546 | } |
547 | - $pathName = str_replace('\\','/', pathinfo($file->getPathname(), PATHINFO_DIRNAME) ); |
|
547 | + $pathName = str_replace('\\', '/', pathinfo($file->getPathname(), PATHINFO_DIRNAME)); |
|
548 | 548 | $pathName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($pathName); |
549 | 549 | |
550 | 550 | // acl |
551 | - $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(), str_ireplace($directory,'',$pathName)); |
|
551 | + $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(), str_ireplace($directory, '', $pathName)); |
|
552 | 552 | $isAuthorized = (($aclMask & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
553 | - if ( !$isAuthorized ){ |
|
553 | + if (!$isAuthorized) { |
|
554 | 554 | return false; |
555 | 555 | } |
556 | 556 | |
557 | 557 | // if it is a folder fileName represents the dir |
558 | - if ( $file->isDir() && ( !CKFinder_Connector_Utils_FileSystem::checkFolderPath($fileName) || $resourceTypeInfo->checkIsHiddenPath($fileName) ) ){ |
|
558 | + if ($file->isDir() && (!CKFinder_Connector_Utils_FileSystem::checkFolderPath($fileName) || $resourceTypeInfo->checkIsHiddenPath($fileName))) { |
|
559 | 559 | return false; |
560 | 560 | } |
561 | 561 | // folder name |
562 | - if ( !CKFinder_Connector_Utils_FileSystem::checkFolderPath($pathName) ){ |
|
562 | + if (!CKFinder_Connector_Utils_FileSystem::checkFolderPath($pathName)) { |
|
563 | 563 | return false; |
564 | 564 | } |
565 | 565 | |
566 | 566 | // is hidden |
567 | - if ( $resourceTypeInfo->checkIsHiddenPath($pathName) || $resourceTypeInfo->checkIsHiddenFile($fileName) ){ |
|
567 | + if ($resourceTypeInfo->checkIsHiddenPath($pathName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { |
|
568 | 568 | return false; |
569 | 569 | } |
570 | 570 | |
571 | 571 | // extension |
572 | - if ( !$resourceTypeInfo->checkExtension($fileName) || !CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) ){ |
|
572 | + if (!$resourceTypeInfo->checkExtension($fileName) || !CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) { |
|
573 | 573 | return false; |
574 | 574 | } |
575 | 575 | |
@@ -583,34 +583,34 @@ discard block |
||
583 | 583 | * @param int $zipMaxSize Maximum zip file size |
584 | 584 | * @return array $allFiles |
585 | 585 | */ |
586 | - protected function getFilesRecursively( $directory, $zipMaxSize ) |
|
586 | + protected function getFilesRecursively($directory, $zipMaxSize) |
|
587 | 587 | { |
588 | 588 | $allFiles = array(); |
589 | 589 | $_zipFilesSize = 0; |
590 | - $serverPath = str_replace('\\','/',$directory); |
|
590 | + $serverPath = str_replace('\\', '/', $directory); |
|
591 | 591 | |
592 | - foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $file ) { |
|
593 | - if ( !$this->checkOneFile($file) ){ |
|
592 | + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $file) { |
|
593 | + if (!$this->checkOneFile($file)) { |
|
594 | 594 | continue; |
595 | 595 | } |
596 | - if ( !empty($zipMaxSize) ){ |
|
596 | + if (!empty($zipMaxSize)) { |
|
597 | 597 | clearstatcache(); |
598 | 598 | $_zipFilesSize += $file->getSize(); |
599 | - if ( $_zipFilesSize > $zipMaxSize ) { |
|
599 | + if ($_zipFilesSize > $zipMaxSize) { |
|
600 | 600 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CREATED_FILE_TOO_BIG); |
601 | 601 | } |
602 | 602 | } |
603 | - $pathName = str_replace('\\','/',$file->getPathname()); |
|
604 | - if ( $file->isDir() ){ |
|
603 | + $pathName = str_replace('\\', '/', $file->getPathname()); |
|
604 | + if ($file->isDir()) { |
|
605 | 605 | // skip dot folders on unix systems ( do not try to use isDot() as $file is not a DirectoryIterator obj ) |
606 | - if ( in_array($file->getFilename(),array('..','.')) ){ |
|
606 | + if (in_array($file->getFilename(), array('..', '.'))) { |
|
607 | 607 | continue; |
608 | 608 | } |
609 | - if ($pathName != rtrim($serverPath,'/')){ |
|
610 | - $allFiles[ ltrim(str_ireplace(rtrim($serverPath,'/'),'',$pathName),'/') ] = ''; |
|
609 | + if ($pathName != rtrim($serverPath, '/')) { |
|
610 | + $allFiles[ltrim(str_ireplace(rtrim($serverPath, '/'), '', $pathName), '/')] = ''; |
|
611 | 611 | } |
612 | 612 | } else { |
613 | - $allFiles[$pathName] = str_ireplace($serverPath,'',$pathName); |
|
613 | + $allFiles[$pathName] = str_ireplace($serverPath, '', $pathName); |
|
614 | 614 | } |
615 | 615 | } |
616 | 616 | |
@@ -629,11 +629,11 @@ discard block |
||
629 | 629 | $this->checkConnector(); |
630 | 630 | $this->checkRequest(); |
631 | 631 | |
632 | - if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
632 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
633 | 633 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
634 | 634 | } |
635 | 635 | |
636 | - $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
636 | + $this->_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
637 | 637 | $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
638 | 638 | $_sServerDir = $this->_currentFolder->getServerPath(); |
639 | 639 | |
@@ -642,21 +642,21 @@ discard block |
||
642 | 642 | $_zipFilesSize = 0; |
643 | 643 | $config = $this->getConfig(); |
644 | 644 | $zipMaxSize = $config['zipMaxSize']; |
645 | - if ( !empty($zipMaxSize) && $zipMaxSize == 'default' ){ |
|
645 | + if (!empty($zipMaxSize) && $zipMaxSize == 'default') { |
|
646 | 646 | $zipMaxSize = $currentResourceTypeConfig->getMaxSize(); |
647 | 647 | } |
648 | 648 | |
649 | - $_isBasket = ( isset($_POST['basket']) && $_POST['basket'] == 'true' )? true : false; |
|
649 | + $_isBasket = (isset($_POST['basket']) && $_POST['basket'] == 'true') ? true : false; |
|
650 | 650 | |
651 | - if ( !empty($_POST['files'])) |
|
651 | + if (!empty($_POST['files'])) |
|
652 | 652 | { |
653 | 653 | |
654 | 654 | $_aclConfig = $this->_config->getAccessControlConfig(); |
655 | 655 | $aclMasks = array(); |
656 | 656 | $_resourceTypeConfig = array(); |
657 | 657 | |
658 | - foreach ( $_POST['files'] as $arr ){ |
|
659 | - if ( empty($arr['name']) || empty($arr['type']) || empty($arr['folder']) ) { |
|
658 | + foreach ($_POST['files'] as $arr) { |
|
659 | + if (empty($arr['name']) || empty($arr['type']) || empty($arr['folder'])) { |
|
660 | 660 | continue; |
661 | 661 | } |
662 | 662 | // file name |
@@ -716,24 +716,24 @@ discard block |
||
716 | 716 | continue; |
717 | 717 | } |
718 | 718 | |
719 | - $sourceFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($_resourceTypeConfig[$type]->getDirectory().$path,$name); |
|
719 | + $sourceFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($_resourceTypeConfig[$type]->getDirectory().$path, $name); |
|
720 | 720 | // check #8 (invalid file name) |
721 | 721 | if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
722 | 722 | continue; |
723 | 723 | } |
724 | 724 | |
725 | 725 | // check #9 - max file size |
726 | - if ( !empty($zipMaxSize) ){ |
|
726 | + if (!empty($zipMaxSize)) { |
|
727 | 727 | clearstatcache(); |
728 | 728 | $_zipFilesSize += filesize($sourceFilePath); |
729 | - if ( $_zipFilesSize > $zipMaxSize ) { |
|
729 | + if ($_zipFilesSize > $zipMaxSize) { |
|
730 | 730 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CREATED_FILE_TOO_BIG); |
731 | 731 | } |
732 | 732 | } |
733 | 733 | |
734 | - $zipPathPart = ( $_isBasket ) ? CKFinder_Connector_Utils_FileSystem::combinePaths($type,$path) : ''; |
|
734 | + $zipPathPart = ($_isBasket) ? CKFinder_Connector_Utils_FileSystem::combinePaths($type, $path) : ''; |
|
735 | 735 | |
736 | - $files[$sourceFilePath] = $zipPathPart.pathinfo($sourceFilePath,PATHINFO_BASENAME); |
|
736 | + $files[$sourceFilePath] = $zipPathPart.pathinfo($sourceFilePath, PATHINFO_BASENAME); |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | else |
@@ -741,9 +741,9 @@ discard block |
||
741 | 741 | if (!is_dir($_sServerDir)) { |
742 | 742 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
743 | 743 | } |
744 | - $files = $this->getFilesRecursively($_sServerDir,$zipMaxSize); |
|
744 | + $files = $this->getFilesRecursively($_sServerDir, $zipMaxSize); |
|
745 | 745 | } |
746 | - if ( sizeof($files)<1) { |
|
746 | + if (sizeof($files) < 1) { |
|
747 | 747 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
748 | 748 | } |
749 | 749 | // default destination dir - temp |
@@ -755,9 +755,9 @@ discard block |
||
755 | 755 | |
756 | 756 | // compress files - do not download them |
757 | 757 | // change destination and name |
758 | - if ( isset($_POST['download']) && $_POST['download'] == 'false'){ |
|
758 | + if (isset($_POST['download']) && $_POST['download'] == 'false') { |
|
759 | 759 | $dest_dir = $_sServerDir; |
760 | - if ( isset($_POST['zipName']) && !empty($_POST['zipName'])){ |
|
760 | + if (isset($_POST['zipName']) && !empty($_POST['zipName'])) { |
|
761 | 761 | $zip_filename = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_POST['zipName']); |
762 | 762 | if (!$resourceTypeInfo->checkExtension($zip_filename)) { |
763 | 763 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
@@ -782,52 +782,52 @@ discard block |
||
782 | 782 | |
783 | 783 | // only if file already exists and we want download it |
784 | 784 | // do not create new one - because hash of previously created is the same - existing archive is ok |
785 | - if ( file_exists($zipFilePath) && isset($_POST['download']) && $_POST['download'] == 'true' ){ |
|
785 | + if (file_exists($zipFilePath) && isset($_POST['download']) && $_POST['download'] == 'true') { |
|
786 | 786 | $createZip = false; |
787 | 787 | } |
788 | 788 | // if we only want to create archive |
789 | 789 | else |
790 | 790 | { |
791 | - if ( file_exists($zipFilePath) && ( !isset($_POST['fileExistsAction']) || !in_array($_POST['fileExistsAction'], array('autorename','overwrite')) ) ){ |
|
791 | + if (file_exists($zipFilePath) && (!isset($_POST['fileExistsAction']) || !in_array($_POST['fileExistsAction'], array('autorename', 'overwrite')))) { |
|
792 | 792 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); |
793 | 793 | } |
794 | 794 | |
795 | - if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FILE_UPLOAD )) { |
|
795 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
796 | 796 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
797 | 797 | } |
798 | 798 | // check how to deal with existing file |
799 | - if ( isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'autorename' ) |
|
799 | + if (isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'autorename') |
|
800 | 800 | { |
801 | - if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_RENAME )) { |
|
801 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_RENAME)) { |
|
802 | 802 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
803 | 803 | } |
804 | 804 | $zip_filename = CKFinder_Connector_Utils_FileSystem::autoRename($dest_dir, $zip_filename); |
805 | 805 | $zipFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir, $zip_filename); |
806 | 806 | } |
807 | - elseif ( isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'overwrite' ) |
|
807 | + elseif (isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'overwrite') |
|
808 | 808 | { |
809 | - if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
809 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
810 | 810 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
811 | 811 | } |
812 | - if (!CKFinder_Connector_Utils_FileSystem::unlink($zipFilePath)){ |
|
812 | + if (!CKFinder_Connector_Utils_FileSystem::unlink($zipFilePath)) { |
|
813 | 813 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
814 | 814 | } |
815 | 815 | } |
816 | 816 | } |
817 | 817 | |
818 | - if ( $createZip ){ |
|
818 | + if ($createZip) { |
|
819 | 819 | $zip = new ZipArchive(); |
820 | - $result = $zip->open( $zipFilePath, ZIPARCHIVE::CREATE); |
|
821 | - if ( $result !== TRUE ) { |
|
820 | + $result = $zip->open($zipFilePath, ZIPARCHIVE::CREATE); |
|
821 | + if ($result !== TRUE) { |
|
822 | 822 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN); |
823 | 823 | } |
824 | - foreach ( $files as $pathname => $filename ){ |
|
825 | - if ( !empty($filename) ){ |
|
826 | - if ( file_exists($pathname) && is_readable($pathname) ){ |
|
827 | - $zip->addFile( $pathname, $filename ); |
|
824 | + foreach ($files as $pathname => $filename) { |
|
825 | + if (!empty($filename)) { |
|
826 | + if (file_exists($pathname) && is_readable($pathname)) { |
|
827 | + $zip->addFile($pathname, $filename); |
|
828 | 828 | } |
829 | 829 | } else { |
830 | - $zip->addEmptyDir( $pathname ); |
|
830 | + $zip->addEmptyDir($pathname); |
|
831 | 831 | } |
832 | 832 | } |
833 | 833 | $zip->close(); |
@@ -838,13 +838,13 @@ discard block |
||
838 | 838 | $this->_connectorNode->addChild($file); |
839 | 839 | } |
840 | 840 | |
841 | - public function onBeforeExecuteCommand( &$command ) |
|
841 | + public function onBeforeExecuteCommand(&$command) |
|
842 | 842 | { |
843 | - if ( $command == 'CreateZip'){ |
|
843 | + if ($command == 'CreateZip') { |
|
844 | 844 | $this->sendResponse(); |
845 | 845 | return false; |
846 | 846 | } |
847 | - return true ; |
|
847 | + return true; |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | } // end of CKFinder_Connector_CommandHandler_DownloadZip class |
@@ -865,13 +865,13 @@ discard block |
||
865 | 865 | $this->checkRequest(); |
866 | 866 | |
867 | 867 | // empty wystarczy |
868 | - if ( empty($_GET['FileName']) ){ |
|
868 | + if (empty($_GET['FileName'])) { |
|
869 | 869 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
870 | 870 | } |
871 | 871 | |
872 | 872 | $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
873 | 873 | $hash = $resourceTypeInfo->getHash(); |
874 | - if ( $hash !== $_GET['hash'] || $hash !== substr($_GET['FileName'],16,16) ){ |
|
874 | + if ($hash !== $_GET['hash'] || $hash !== substr($_GET['FileName'], 16, 16)) { |
|
875 | 875 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
876 | 876 | } |
877 | 877 | |
@@ -885,13 +885,13 @@ discard block |
||
885 | 885 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
886 | 886 | } |
887 | 887 | |
888 | - if ( strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip'){ |
|
888 | + if (strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip') { |
|
889 | 889 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
890 | 890 | } |
891 | 891 | |
892 | 892 | $dest_dir = CKFinder_Connector_Utils_FileSystem::getTmpDir(); |
893 | - $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir,$fileName); |
|
894 | - if ( !file_exists($filePath) || !is_file($filePath)) { |
|
893 | + $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir, $fileName); |
|
894 | + if (!file_exists($filePath) || !is_file($filePath)) { |
|
895 | 895 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
896 | 896 | } |
897 | 897 | if (!is_readable($filePath)) { |
@@ -902,7 +902,7 @@ discard block |
||
902 | 902 | if (!CKFinder_Connector_Utils_FileSystem::checkFileName($zipFileName)) { |
903 | 903 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
904 | 904 | } |
905 | - $fileFilename = pathinfo($zipFileName,PATHINFO_BASENAME ); |
|
905 | + $fileFilename = pathinfo($zipFileName, PATHINFO_BASENAME); |
|
906 | 906 | |
907 | 907 | header("Content-Encoding: none"); |
908 | 908 | header("Cache-Control: cache, must-revalidate"); |
@@ -913,20 +913,20 @@ discard block |
||
913 | 913 | if (strpos($user_agent, "MSIE") !== false) { |
914 | 914 | $encodedName = str_replace(array("+", "%2E"), array(" ", "."), urlencode($encodedName)); |
915 | 915 | } |
916 | - header("Content-type: application/octet-stream; name=\"" . $fileFilename . "\""); |
|
917 | - header("Content-Disposition: attachment; filename=\"" . $encodedName. "\""); |
|
918 | - header("Content-Length: " . filesize($filePath)); |
|
916 | + header("Content-type: application/octet-stream; name=\"".$fileFilename."\""); |
|
917 | + header("Content-Disposition: attachment; filename=\"".$encodedName."\""); |
|
918 | + header("Content-Length: ".filesize($filePath)); |
|
919 | 919 | CKFinder_Connector_Utils_FileSystem::sendFile($filePath); |
920 | 920 | exit; |
921 | 921 | } |
922 | 922 | |
923 | - public function onBeforeExecuteCommand( &$command ) |
|
923 | + public function onBeforeExecuteCommand(&$command) |
|
924 | 924 | { |
925 | - if ( $command == 'DownloadZip'){ |
|
925 | + if ($command == 'DownloadZip') { |
|
926 | 926 | $this->sendZipFile(); |
927 | 927 | return false; |
928 | 928 | } |
929 | - return true ; |
|
929 | + return true; |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | } // end of CKFinder_Connector_CommandHandler_DownloadZip |
@@ -12,7 +12,9 @@ discard block |
||
12 | 12 | * |
13 | 13 | * CKFinder extension: provides commands to add files into a zip archive, or extract contents from a zip. |
14 | 14 | */ |
15 | -if (!defined('IN_CKFINDER')) exit; |
|
15 | +if (!defined('IN_CKFINDER')) { |
|
16 | + exit; |
|
17 | +} |
|
16 | 18 | |
17 | 19 | /** |
18 | 20 | * Include base XML command handler |
@@ -358,8 +360,7 @@ discard block |
||
358 | 360 | { |
359 | 361 | $sFileName = CKFinder_Connector_Utils_FileSystem::autoRename($extractPath,$sFileName); |
360 | 362 | $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
361 | - } |
|
362 | - elseif ( $checkedFiles[$fileName]['options'] == 'overwrite') |
|
363 | + } elseif ( $checkedFiles[$fileName]['options'] == 'overwrite') |
|
363 | 364 | { |
364 | 365 | if ( !$this->_currentFolder->checkAcl( CKFINDER_CONNECTOR_ACL_FILE_DELETE ) ){ |
365 | 366 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED; |
@@ -370,19 +371,16 @@ discard block |
||
370 | 371 | { |
371 | 372 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
372 | 373 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
373 | - } |
|
374 | - else |
|
374 | + } else |
|
375 | 375 | { |
376 | 376 | $this->extractTo($extractPath,$extractClientPath,$filePathInfo,$sFileName,$fileName); |
377 | 377 | } |
378 | - } |
|
379 | - else |
|
378 | + } else |
|
380 | 379 | { |
381 | 380 | // add to skipped files |
382 | 381 | $this->appendUnzippedNode($this->unzippedNodes,$fileName,'skip'); |
383 | 382 | } |
384 | - } |
|
385 | - else |
|
383 | + } else |
|
386 | 384 | { |
387 | 385 | $this->errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
388 | 386 | $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $fileName, $fileType); |
@@ -449,8 +447,7 @@ discard block |
||
449 | 447 | $dirExists->addChild($oErrorNode); |
450 | 448 | $this->_connectorNode->addChild($dirExists); |
451 | 449 | return; |
452 | - } |
|
453 | - elseif ( !empty( $_POST['force']) && $_POST['force'] =='overwrite' ) |
|
450 | + } elseif ( !empty( $_POST['force']) && $_POST['force'] =='overwrite' ) |
|
454 | 451 | { |
455 | 452 | if ( !(($aclMask & CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE ) == CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE ) ){ |
456 | 453 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
@@ -465,8 +462,7 @@ discard block |
||
465 | 462 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
466 | 463 | } |
467 | 464 | } |
468 | - } |
|
469 | - else if ( !empty( $_POST['force']) && $_POST['force'] !== 'merge' ) |
|
465 | + } else if ( !empty( $_POST['force']) && $_POST['force'] !== 'merge' ) |
|
470 | 466 | { |
471 | 467 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
472 | 468 | } |
@@ -735,8 +731,7 @@ discard block |
||
735 | 731 | |
736 | 732 | $files[$sourceFilePath] = $zipPathPart.pathinfo($sourceFilePath,PATHINFO_BASENAME); |
737 | 733 | } |
738 | - } |
|
739 | - else |
|
734 | + } else |
|
740 | 735 | { |
741 | 736 | if (!is_dir($_sServerDir)) { |
742 | 737 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
@@ -803,8 +798,7 @@ discard block |
||
803 | 798 | } |
804 | 799 | $zip_filename = CKFinder_Connector_Utils_FileSystem::autoRename($dest_dir, $zip_filename); |
805 | 800 | $zipFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir, $zip_filename); |
806 | - } |
|
807 | - elseif ( isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'overwrite' ) |
|
801 | + } elseif ( isset($_POST['fileExistsAction']) && $_POST['fileExistsAction'] == 'overwrite' ) |
|
808 | 802 | { |
809 | 803 | if ( !$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
810 | 804 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |