1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
set_time_limit(0); // just in case it too long, not recommended for production |
4
|
|
|
error_reporting(E_ALL | E_STRICT); // Set E_ALL for debuging |
5
|
|
|
// error_reporting(0); |
6
|
|
|
ini_set('max_file_uploads', 50); // allow uploading up to 50 files at once |
7
|
|
|
|
8
|
|
|
// needed for case insensitive search to work, due to broken UTF-8 support in PHP |
9
|
|
|
ini_set('mbstring.internal_encoding', 'UTF-8'); |
10
|
|
|
ini_set('mbstring.func_overload', 2); |
11
|
|
|
|
12
|
|
|
if (function_exists('date_default_timezone_set')) { |
13
|
|
|
date_default_timezone_set('Europe/Moscow'); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderConnector.class.php'; |
17
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinder.class.php'; |
18
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php'; |
19
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php'; |
20
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeMySQL.class.php'; |
21
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeFTP.class.php'; |
22
|
|
|
|
23
|
|
|
function debug($o) { |
24
|
|
|
echo '<pre>'; |
25
|
|
|
print_r($o); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Smart logger function |
32
|
|
|
* Demonstrate how to work with elFinder event api |
33
|
|
|
* |
34
|
|
|
* @param string $cmd command name |
35
|
|
|
* @param array $result command result |
36
|
|
|
* @param array $args command arguments from client |
37
|
|
|
* @param elFinder $elfinder elFinder instance |
38
|
|
|
* @return void|true |
39
|
|
|
* @author Troex Nevelin |
40
|
|
|
**/ |
41
|
|
|
function logger($cmd, $result, $args, $elfinder) { |
|
|
|
|
42
|
|
|
|
43
|
|
|
|
44
|
|
|
$log = sprintf("[%s] %s: %s \n", date('r'), strtoupper($cmd), var_export($result, true)); |
45
|
|
|
$logfile = '../files/temp/log.txt'; |
46
|
|
|
$dir = dirname($logfile); |
47
|
|
|
if (!is_dir($dir) && !mkdir($dir)) { |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
if (($fp = fopen($logfile, 'a'))) { |
51
|
|
|
fwrite($fp, $log); |
52
|
|
|
fclose($fp); |
53
|
|
|
} |
54
|
|
|
return; |
55
|
|
|
|
56
|
|
|
foreach ($result as $key => $value) { |
|
|
|
|
57
|
|
|
if (empty($value)) { |
58
|
|
|
continue; |
59
|
|
|
} |
60
|
|
|
$data = array(); |
61
|
|
|
if (in_array($key, array('error', 'warning'))) { |
62
|
|
|
array_push($data, implode(' ', $value)); |
63
|
|
|
} else { |
64
|
|
|
if (is_array($value)) { // changes made to files |
65
|
|
|
foreach ($value as $file) { |
66
|
|
|
$filepath = (isset($file['realpath']) ? $file['realpath'] : $elfinder->realpath($file['hash'])); |
67
|
|
|
array_push($data, $filepath); |
68
|
|
|
} |
69
|
|
|
} else { // other value (ex. header) |
70
|
|
|
array_push($data, $value); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
$log .= sprintf(' %s(%s)', $key, implode(', ', $data)); |
74
|
|
|
} |
75
|
|
|
$log .= "\n"; |
76
|
|
|
|
77
|
|
|
$logfile = '../files/temp/log.txt'; |
78
|
|
|
$dir = dirname($logfile); |
79
|
|
|
if (!is_dir($dir) && !mkdir($dir)) { |
|
|
|
|
80
|
|
|
return; |
81
|
|
|
} |
82
|
|
|
if (($fp = fopen($logfile, 'a'))) { |
|
|
|
|
83
|
|
|
fwrite($fp, $log); |
84
|
|
|
fclose($fp); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Simple logger function. |
91
|
|
|
* Demonstrate how to work with elFinder event api. |
92
|
|
|
* |
93
|
|
|
* @package elFinder |
94
|
|
|
* @author Dmitry (dio) Levashov |
95
|
|
|
**/ |
96
|
|
|
class elFinderSimpleLogger { |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Log file path |
100
|
|
|
* |
101
|
|
|
* @var string |
102
|
|
|
**/ |
103
|
|
|
protected $file = ''; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* constructor |
107
|
|
|
* |
108
|
|
|
* @return void |
|
|
|
|
109
|
|
|
* @author Dmitry (dio) Levashov |
110
|
|
|
**/ |
111
|
|
|
public function __construct($path) { |
112
|
|
|
$this->file = $path; |
113
|
|
|
$dir = dirname($path); |
114
|
|
|
if (!is_dir($dir)) { |
115
|
|
|
mkdir($dir); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Create log record |
121
|
|
|
* |
122
|
|
|
* @param string $cmd command name |
123
|
|
|
* @param array $result command result |
124
|
|
|
* @param array $args command arguments from client |
125
|
|
|
* @param elFinder $elfinder elFinder instance |
126
|
|
|
* @return void|true |
127
|
|
|
* @author Dmitry (dio) Levashov |
128
|
|
|
**/ |
129
|
|
|
public function log($cmd, $result, $args, $elfinder) { |
|
|
|
|
130
|
|
|
$log = $cmd.' ['.date('d.m H:s')."]\n"; |
131
|
|
|
|
132
|
|
View Code Duplication |
if (!empty($result['error'])) { |
|
|
|
|
133
|
|
|
$log .= "\tERROR: ".implode(' ', $result['error'])."\n"; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
View Code Duplication |
if (!empty($result['warning'])) { |
|
|
|
|
137
|
|
|
$log .= "\tWARNING: ".implode(' ', $result['warning'])."\n"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
if (!empty($result['removed'])) { |
141
|
|
|
foreach ($result['removed'] as $file) { |
142
|
|
|
// removed file contain additional field "realpath" |
143
|
|
|
$log .= "\tREMOVED: ".$file['realpath']."\n"; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
View Code Duplication |
if (!empty($result['added'])) { |
|
|
|
|
148
|
|
|
foreach ($result['added'] as $file) { |
149
|
|
|
$log .= "\tADDED: ".$elfinder->realpath($file['hash'])."\n"; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
View Code Duplication |
if (!empty($result['changed'])) { |
|
|
|
|
154
|
|
|
foreach ($result['changed'] as $file) { |
155
|
|
|
$log .= "\tCHANGED: ".$elfinder->realpath($file['hash'])."\n"; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$this->write($log); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Write log into file |
164
|
|
|
* |
165
|
|
|
* @param string $log log record |
166
|
|
|
* @return void |
167
|
|
|
* @author Dmitry (dio) Levashov |
168
|
|
|
**/ |
169
|
|
|
protected function write($log) { |
170
|
|
|
|
171
|
|
|
if (($fp = @fopen($this->file, 'a'))) { |
172
|
|
|
fwrite($fp, $log."\n"); |
173
|
|
|
fclose($fp); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
} // END class |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Simple function to demonstrate how to control file access using "accessControl" callback. |
183
|
|
|
* This method will disable accessing files/folders starting from '.' (dot) |
184
|
|
|
* |
185
|
|
|
* @param string $attr attribute name (read|write|locked|hidden) |
186
|
|
|
* @param string $path file path relative to volume root directory started with directory separator |
187
|
|
|
* @return bool|null |
188
|
|
|
**/ |
189
|
|
|
function access($attr, $path, $data, $volume) { |
|
|
|
|
190
|
|
|
return strpos(basename($path), '.') === 0 // if file/folder begins with '.' (dot) |
191
|
|
|
? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true |
192
|
|
|
: null; // else elFinder decide it itself |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Access control example class |
197
|
|
|
* |
198
|
|
|
* @author Dmitry (dio) Levashov |
199
|
|
|
**/ |
200
|
|
|
class elFinderTestACL { |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* make dotfiles not readable, not writable, hidden and locked |
204
|
|
|
* |
205
|
|
|
* @param string $attr attribute name (read|write|locked|hidden) |
206
|
|
|
* @param string $path file path. Attention! This is path relative to volume root directory started with directory separator. |
207
|
|
|
* @param mixed $data data which seted in 'accessControlData' elFinder option |
208
|
|
|
* @param elFinderVolumeDriver $volume volume driver |
209
|
|
|
* @return bool |
210
|
|
|
* @author Dmitry (dio) Levashov |
211
|
|
|
**/ |
212
|
|
|
public function fsAccess($attr, $path, $data, $volume) { |
|
|
|
|
213
|
|
|
|
214
|
|
|
if ($volume->name() == 'localfilesystem') { |
|
|
|
|
215
|
|
|
return strpos(basename($path), '.') === 0 |
216
|
|
|
? !($attr == 'read' || $attr == 'write') |
217
|
|
|
: $attr == 'read' || $attr == 'write'; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
return true; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
} // END class |
224
|
|
|
|
225
|
|
|
$acl = new elFinderTestACL(); |
226
|
|
|
|
227
|
|
|
function validName($name) { |
228
|
|
|
return strpos($name, '.') !== 0; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
$logger = new elFinderSimpleLogger('../files/temp/log.txt'); |
233
|
|
|
|
234
|
|
|
|
235
|
|
|
|
236
|
|
|
$opts = array( |
237
|
|
|
'locale' => 'en_US.UTF-8', |
238
|
|
|
'bind' => array( |
239
|
|
|
// '*' => 'logger', |
240
|
|
|
'mkdir mkfile rename duplicate upload rm paste' => 'logger' |
241
|
|
|
), |
242
|
|
|
'debug' => true, |
243
|
|
|
'roots' => array( |
244
|
|
|
array( |
245
|
|
|
'driver' => 'LocalFileSystem', |
246
|
|
|
'path' => '../files/', |
247
|
|
|
'startPath' => '../files/test/', |
248
|
|
|
'URL' => dirname($_SERVER['PHP_SELF']) . '/../files/', |
249
|
|
|
// 'treeDeep' => 3, |
250
|
|
|
// 'alias' => 'File system', |
251
|
|
|
'mimeDetect' => 'internal', |
252
|
|
|
'tmbPath' => '.tmb', |
253
|
|
|
'utf8fix' => true, |
254
|
|
|
'tmbCrop' => false, |
255
|
|
|
'tmbBgColor' => 'transparent', |
256
|
|
|
'accessControl' => 'access', |
257
|
|
|
'acceptedName' => '/^[^\.].*$/', |
258
|
|
|
// 'disabled' => array('extract', 'archive'), |
259
|
|
|
// 'tmbSize' => 128, |
260
|
|
|
'attributes' => array( |
261
|
|
|
array( |
262
|
|
|
'pattern' => '/\.js$/', |
263
|
|
|
'read' => true, |
264
|
|
|
'write' => false |
265
|
|
|
), |
266
|
|
|
array( |
267
|
|
|
'pattern' => '/^\/icons$/', |
268
|
|
|
'read' => true, |
269
|
|
|
'write' => false |
270
|
|
|
) |
271
|
|
|
) |
272
|
|
|
// 'uploadDeny' => array('application', 'text/xml') |
273
|
|
|
), |
274
|
|
|
// array( |
275
|
|
|
// 'driver' => 'LocalFileSystem', |
276
|
|
|
// 'path' => '../files2/', |
277
|
|
|
// // 'URL' => dirname($_SERVER['PHP_SELF']) . '/../files2/', |
278
|
|
|
// 'alias' => 'File system', |
279
|
|
|
// 'mimeDetect' => 'internal', |
280
|
|
|
// 'tmbPath' => '.tmb', |
281
|
|
|
// 'utf8fix' => true, |
282
|
|
|
// 'tmbCrop' => false, |
283
|
|
|
// 'startPath' => '../files/test', |
284
|
|
|
// // 'separator' => ':', |
285
|
|
|
// 'attributes' => array( |
286
|
|
|
// array( |
287
|
|
|
// 'pattern' => '~/\.~', |
288
|
|
|
// // 'pattern' => '/^\/\./', |
289
|
|
|
// 'read' => false, |
290
|
|
|
// 'write' => false, |
291
|
|
|
// 'hidden' => true, |
292
|
|
|
// 'locked' => false |
293
|
|
|
// ), |
294
|
|
|
// array( |
295
|
|
|
// 'pattern' => '~/replace/.+png$~', |
296
|
|
|
// // 'pattern' => '/^\/\./', |
297
|
|
|
// 'read' => false, |
298
|
|
|
// 'write' => false, |
299
|
|
|
// // 'hidden' => true, |
300
|
|
|
// 'locked' => true |
301
|
|
|
// ) |
302
|
|
|
// ), |
303
|
|
|
// // 'defaults' => array('read' => false, 'write' => true) |
304
|
|
|
// ), |
305
|
|
|
|
306
|
|
|
// array( |
307
|
|
|
// 'driver' => 'FTP', |
308
|
|
|
// 'host' => '192.168.1.38', |
309
|
|
|
// 'user' => 'dio', |
310
|
|
|
// 'pass' => 'hane', |
311
|
|
|
// 'path' => '/Users/dio/Documents', |
312
|
|
|
// 'tmpPath' => '../files/ftp', |
313
|
|
|
// 'utf8fix' => true, |
314
|
|
|
// 'attributes' => array( |
315
|
|
|
// array( |
316
|
|
|
// 'pattern' => '~/\.~', |
317
|
|
|
// 'read' => false, |
318
|
|
|
// 'write' => false, |
319
|
|
|
// 'hidden' => true, |
320
|
|
|
// 'locked' => false |
321
|
|
|
// ), |
322
|
|
|
// |
323
|
|
|
// ) |
324
|
|
|
// ), |
325
|
|
|
array( |
326
|
|
|
'driver' => 'FTP', |
327
|
|
|
'host' => 'work.std42.ru', |
328
|
|
|
'user' => 'dio', |
329
|
|
|
'pass' => 'wallrus', |
330
|
|
|
'path' => '/', |
331
|
|
|
'tmpPath' => '../files/ftp', |
332
|
|
|
), |
333
|
|
|
// array( |
334
|
|
|
// 'driver' => 'FTP', |
335
|
|
|
// 'host' => '10.0.1.3', |
336
|
|
|
// 'user' => 'frontrow', |
337
|
|
|
// 'pass' => 'frontrow', |
338
|
|
|
// 'path' => '/', |
339
|
|
|
// 'tmpPath' => '../files/ftp', |
340
|
|
|
// ), |
341
|
|
|
|
342
|
|
|
// array( |
343
|
|
|
// 'driver' => 'LocalFileSystem', |
344
|
|
|
// 'path' => '../files2/', |
345
|
|
|
// 'URL' => dirname($_SERVER['PHP_SELF']) . '/../files2/', |
346
|
|
|
// 'alias' => 'Files', |
347
|
|
|
// 'mimeDetect' => 'internal', |
348
|
|
|
// 'tmbPath' => '.tmb', |
349
|
|
|
// // 'copyOverwrite' => false, |
350
|
|
|
// 'utf8fix' => true, |
351
|
|
|
// 'attributes' => array( |
352
|
|
|
// array( |
353
|
|
|
// 'pattern' => '~/\.~', |
354
|
|
|
// // 'pattern' => '/^\/\./', |
355
|
|
|
// // 'read' => false, |
356
|
|
|
// // 'write' => false, |
357
|
|
|
// 'hidden' => true, |
358
|
|
|
// 'locked' => false |
359
|
|
|
// ), |
360
|
|
|
// ) |
361
|
|
|
// ), |
362
|
|
|
|
363
|
|
|
// array( |
364
|
|
|
// 'driver' => 'MySQL', |
365
|
|
|
// 'path' => 1, |
366
|
|
|
// // 'treeDeep' => 2, |
367
|
|
|
// // 'socket' => '/opt/local/var/run/mysql5/mysqld.sock', |
368
|
|
|
// 'user' => 'root', |
369
|
|
|
// 'pass' => 'hane', |
370
|
|
|
// 'db' => 'elfinder', |
371
|
|
|
// 'user_id' => 1, |
372
|
|
|
// // 'accessControl' => 'access', |
373
|
|
|
// // 'separator' => ':', |
374
|
|
|
// 'tmbCrop' => true, |
375
|
|
|
// // thumbnails background color (hex #rrggbb or 'transparent') |
376
|
|
|
// 'tmbBgColor' => '#000000', |
377
|
|
|
// 'files_table' => 'elfinder_file', |
378
|
|
|
// // 'imgLib' => 'imagick', |
379
|
|
|
// // 'uploadOverwrite' => false, |
380
|
|
|
// // 'copyTo' => false, |
381
|
|
|
// // 'URL' => 'http://localhost/git/elfinder', |
382
|
|
|
// 'tmpPath' => '../filesdb/tmp', |
383
|
|
|
// 'tmbPath' => '../filesdb/tmb', |
384
|
|
|
// 'tmbURL' => dirname($_SERVER['PHP_SELF']) . '/../filesdb/tmb/', |
385
|
|
|
// // 'attributes' => array( |
386
|
|
|
// // array(), |
387
|
|
|
// // array( |
388
|
|
|
// // 'pattern' => '/\.jpg$/', |
389
|
|
|
// // 'read' => false, |
390
|
|
|
// // 'write' => false, |
391
|
|
|
// // 'locked' => true, |
392
|
|
|
// // 'hidden' => true |
393
|
|
|
// // ) |
394
|
|
|
// // ) |
395
|
|
|
// |
|
|
|
|
396
|
|
|
// ) |
397
|
|
|
) |
398
|
|
|
|
399
|
|
|
); |
400
|
|
|
|
401
|
|
|
|
402
|
|
|
|
403
|
|
|
// sleep(3); |
404
|
|
|
header('Access-Control-Allow-Origin: *'); |
405
|
|
|
$connector = new elFinderConnector(new elFinder($opts), true); |
406
|
|
|
$connector->run(); |
407
|
|
|
|
408
|
|
|
// echo '<pre>'; |
409
|
|
|
// print_r($connector); |
410
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.