source: branches/MootoolsFileManager-Update/plugins/MootoolsFileManager/mootools-filemanager/Demos/test-backend.php @ 1302

Last change on this file since 1302 was 1302, checked in by gogo, 9 years ago

Updates to http://www.github.com/sleemanj/mootools-filemanager from GerHoblett?

http://www.github.com/GerHoblett/

Changes to said updates by gogo (sleemanj @ github)

Modifications to MootoolsFileManager? to work with those updates, some courtesy of GerHoblett?, some sleemanj

GerHoblett? provided a large diff which accomplished the goal in a quite different way. It has merit, however I have opted for a less-affecting path in so far as Xinha's "way" is concerned, namely, not splitting the config for a single plugin into several calls to backend config passing functions which seemed a little cumbersome.

Instead I take the option of using POST to send backend data around, at the minor expense of an extra round trip when displaying thumbnails (for each one). This could be reduced by checking for thumbnail existence and returning the thumbnail name directly in "onView" rather than the backend request to generate said thumbnail.

Still to do, is to make the preview pane thumbnail also work.


File size: 14.0 KB
RevLine 
[1302]1<?php
2die("<html><body><h1>Security precaution</h1> <p>To enable the test code, edit <file>Demos/".basename(__FILE__)."</file> and comment out line 2.</p></body></html>");
3
4error_reporting(E_ALL | E_STRICT);
5
6define('FILEMANAGER_CODE', true);
7
8
9define('SITE_USES_ALIASES', 01);
10define('DEVELOPMENT', 01);   // set to 01 / 1 to enable logging of each incoming event request.
11
12
13require_once('FM-common.php');
14
15?>
16<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
17"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
18<html xmlns="http://www.w3.org/1999/xhtml">
19<head>
20  <title>MooTools FileManager Backend Testground</title>
21  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
22  <link rel="shortcut icon" href="http://og5.net/christoph/favicon.png" />
23  <style type="text/css">
24  body {
25    font-size: 11px;
26    font-family: Tahoma, sans-serif;
27  }
28 
29  h1 {
30    margin: 0 0 10px 0;
31    padding: 0;
32   
33    color: #666;
34    font-weight: normal;
35    font-size: 24px;
36    letter-spacing: 1px;
37    word-spacing: 2px;
38    line-height: 22px;
39    min-height: 25px;
40  }
41
42  h1 span {
43    font-size: 11px;
44    letter-spacing: 0;
45    word-spacing: 0;
46    text-shadow: none;
47  }
48 
49  .blue { color: #1f52b0; }
50 
51  div.content {
52    min-height: 200px;
53    margin: 23px 34px;
54    padding: 10px 17px;
55    border: 1px solid #b2b2b2;
56    background: #fff;
57    box-shadow: rgba(0, 0, 0, 0.3) 0 0 10px;
58  -moz-box-shadow: rgba(0, 0, 0, 0.3) 0 0 10px;
59  -webkit-box-shadow: rgba(0, 0, 0, 0.3) 0 0 10px;
60  }
61 
62  div.content div.example {
63    float: left;
64    clear: both;
65    margin: 10px 0;
66  }
67 
68  button {
69    margin: 5px 0;
70  }
71
72  /* http://labnol.blogspot.com/2006/10/html-css-trick-for-displaying-code.html */ 
73  pre {
74        white-space: pre-wrap; /* css-3 */
75        white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
76        white-space: -pre-wrap; /* Opera 4-6 */
77        white-space: -o-pre-wrap; /* Opera 7 */
78        word-wrap: break-word; /* Internet Explorer 5.5+ */
79  }
80  </style>
81 
82  <script type="text/javascript" src="mootools-core.js"></script>
83  <script type="text/javascript" src="mootools-more.js"></script>
84 
85  <script type="text/javascript" src="../Source/FileManager.js"></script>
86  <script type="text/javascript" src="../Source/Gallery.js"></script>
87  <script type="text/javascript" src="../Source/Uploader/Fx.ProgressBar.js"></script>
88  <script type="text/javascript" src="../Source/Uploader/Swiff.Uploader.js"></script>
89  <script type="text/javascript" src="../Source/Uploader.js"></script>
90  <script type="text/javascript" src="../Language/Language.en.js"></script>
91  <script type="text/javascript" src="../Language/Language.de.js"></script>
92 
93  <script type="text/javascript">
94    window.addEvent('domready', function() {
95
96    });
97  </script>
98</head>
99<body>
100<div id="content" class="content">
101  <h1>FileManager Backend Tests</h1>
102
103  <h2>Basic PHP tests</h2>
104  <pre>
105<?php
106
107
108
109// log request data:
110FM_vardumper(null, 'testFM' . (!empty($_GET['event']) ? '-' . $_GET['event'] : null));
111
112
113
114if (01) // debugging
115{
116        $re_extra = '-_., []()~!@+' /* . '#&' */;
117        $trim_extra = '-_,~@+#&';
118       
119        echo "pagetitle(str, NULL, '$re_extra', '$trim_extra'): regex to filter file &amp; dirnames before they are created:\n";
120       
121        // ASCII range
122        for ($i = 0; $i < 8; $i++)
123        {
124                $msg = '';
125                $str = '';
126                for ($j = 0; $j < 16; $j++)
127                {
128                        $c = $i * 16 + $j;
129                        switch ($c)
130                        {
131                        case 9:
132                                $msg .= "(TAB)";
133                                break;
134                               
135                        case 13:
136                                $msg .= "(CR)";
137                                break;
138                               
139                        case 10:
140                                $msg .= "(LF)";
141                                break;
142                               
143                        default:
144                                $msg .= ($c >= 32 ? htmlentities(chr($c), ENT_NOQUOTES, 'UTF-8') : '&#' . $c . ';');
145                                break;
146                        }
147                        $str .= chr($c);
148                }
149       
150                echo "ORIG:     [X" . $msg . "X]";
151                if ($i < 2)
152                {
153                        echo " (these characters are 'low ASCII' charactercodes " . ($i * 16) . " ... " . ($i * 16 + 15);
154                }
155                echo "\n";
156               
157                $r = FileManagerUtility::pagetitle('X' . $str . 'X', null, $re_extra, $trim_extra);
158
159                echo "FILTERED: [" . htmlentities($r, ENT_NOQUOTES, 'UTF-8') . "]\n\n";
160        }
161       
162        $trimset = '_.';
163        echo "\n\ntrim() with multiple characters in the trim set: [$trimset]\n";
164       
165        $test = array(
166                '.ignore',
167                '___ignore',
168                '_._.ignore',
169                '._._ignore',
170                'X.ignore',
171                'X___ignore',
172                'X_._.ignore',
173                'X._._ignore',
174                '__X_ignore',
175                '_._X.ignore',
176                '._.X_ignore'
177                );
178        foreach ($test as $t)
179        {
180                $r = trim($t, $trimset);
181
182                echo "\nORIG: [" . htmlentities($t, ENT_NOQUOTES, 'UTF-8') . "]\nRES:  [" . htmlentities($r, ENT_NOQUOTES, 'UTF-8') . "]\n";
183        }
184}
185
186
187$browser = new FileManagerWithAliasSupport(array(
188        'directory' => 'Files/',                   // relative paths: are relative to the URI request script path, i.e. dirname(__FILE__)
189        //'thumbnailPath' => 'Files/Thumbnails/',
190        'assetBasePath' => '../Assets',
191        'chmod' => 0777,
192        //'maxUploadSize' => 1024 * 1024 * 5,
193        //'upload' => false,
194        //'destroy' => false,
195        //'create' => false,
196        //'move' => false,
197        //'download' => false,
198        //'filter' => 'image/',
199        'allowExtChange' => true,                  // allow file name extensions to be changed; the default however is: NO (FALSE)
200        'UploadIsAuthorized_cb' => 'FM_IsAuthorized',
201        'DownloadIsAuthorized_cb' => 'FM_IsAuthorized',
202        'CreateIsAuthorized_cb' => 'FM_IsAuthorized',
203        'DestroyIsAuthorized_cb' => 'FM_IsAuthorized',
204        'MoveIsAuthorized_cb' => 'FM_IsAuthorized'
205       
206        // http://httpd.apache.org/docs/2.2/mod/mod_alias.html -- we only emulate the Alias statement.
207        // Implementing other path translation features is left as an exercise to the reader:
208        , 'Aliases' => array(
209                '/c/lib/includes/js/mootools-filemanager/Demos/Files/alias' => "D:/xxx",
210                '/c/lib/includes/js/mootools-filemanager/Demos/Files/d' => "D:/xxx.tobesorted",
211                '/c/lib/includes/js/mootools-filemanager/Demos/Files/u' => "D:/websites-uploadarea",
212               
213                '/c/lib/includes/js/mootools-filemanager/Demos/Files' => "D:/experiment"
214        )
215));
216
217echo "\n\n";
218$settings = $browser->getSettings();
219var_dump($settings);
220
221?>
222</pre>
223<h2>Important server variables</h2>
224
225<p>$_SERVER['DOCUMENT_ROOT'] = '<?php echo $_SERVER['DOCUMENT_ROOT']; ?>'</p>
226<p>$_SERVER['SCRIPT_NAME'] = '<?php echo $_SERVER['SCRIPT_NAME']; ?>'</p>
227
228<h2>FileManagerUtility class static methods</h2>
229
230<?php
231
232$re_extra = '-_., []()~!@+' /* . '#&' */;
233$trim_extra = '-_,~@+#&';
234
235?>
236<h3>pagetitle(str, NULL, '<?php echo $re_extra; ?>', '<?php echo $trim_extra; ?>')</h3>
237
238<?php
239
240$test = array(
241        array('src' => '.htaccess', 'expect' => 'htaccess'),
242        array('src' => 'regular.jpg', 'expect' => 'regular.jpg'),
243        array('src' => 'Umgebung Altstadt Østgat', 'expect' => 'Umgebung Altstadt Ostgat'),
244        array('src' => '  Sed ut perspiciatis unde omnis iste natus error ', 'expect' => 'Sed ut perspiciatis unde omnis iste natus error'),
245        array('src' => '  advantage from it? But who has any right  ', 'expect' => 'advantage from it_ But who has any right'),
246        array('src' => 'welche aus geistiger SchwÀche, d.h.', 'expect' => 'welche aus geistiger Schwaeche, d.h'),
247        array('src' => 'MÃŒnchen - AusrÃŒstung - Spaß - Viele GrÌße!', 'expect' => 'Muenchen - Ausruestung - Spass - Viele Gruesse!'),
248        array('src' => 'C:\\Windows\\TEMP\\', 'expect' => 'C_Windows_TEMP'),
249        array('src' => '/etc/passwd', 'expect' => 'etc_passwd'),
250        array('src' => 'Let\'s see what " quotes do?', 'expect' => 'Let_s see what _ quotes do'),
251        array('src' => '䞭囜出售的蜯件必须䜿甚猖码 新 和 湖南北郚 父母通垞郜䌚对子女诎地方方蚀 现圚銙枯的日垞䜿甚䞭出现了越来越倚的简䜓汉字 华语, èµ° 莵州 看䞍懂 枅浊声', 'expect' => ''),
252        array('src' => 'également appelé lorem ipsum', 'expect' => 'egalement appele lorem ipsum'),
253        array('src' => 'łaciński tekst pochodzący ze staroÅŒytności, zaczerpnięty', 'expect' => 'aci_ski tekst pochodz_cy ze staro_ytno_ci, zaczerpni_ty'),
254        array('src' => 'Ipsum текст Lorem, кПтПрые, как правОлП, бессЌыслеММый спОсПк пПлу-латОМскОе слПва', 'expect' => 'Ipsum _ Lorem'),
255        array('src' => 'اول دو واژه از ر؎ته ای از متن لاتین مورد استفاده در طراحی وؚ سایت و چاٟ ØšÙ‡ جای انگلیسی ØšÙ‡ استرس و ؚا تکیه تلف؞ کردن اهمیت', 'expect' => ''),
256        array('src' => '섀명하는 귞래픜 등의 요소의 시각적 프레 ì   테읎션, 묞서 또는 Ꞁꌎ , 활판 읞쇄술 , 귞늬고 레읎아웃 . 의 섞믞 띌틎얎', 'expect' => ''),
257        array('src' => '׀ילעך טעקסט) שו באַווייַזן די גךאַ׀יק עלעמענטן ׀ון אַ דא֞קומענט א֞דעך וויסואַל ׀֌ךעזענטיךונג, אַזאַ ווי שךי׀ֿט , טאַ׀֌אַגךאַ׀י', 'expect' => ')'),
258        array('src' => 'χρησιΌοποιούΜται κείΌεΜο κράτησης Ξέσης (κείΌεΜο πλήρωσης), για Μα αποΎειχΞεί η γραφικά στοιχεία', 'expect' => '(_ _)'),
259        array('src' => 'ルダテキスト フィラヌテキスト瀺すために、グラフィックなどの芁玠を指定するの芖芚的なプレれンテヌション、', 'expect' => ''),
260        array('src' => 'SQL: \'\'; DROP TABLE; \'', 'expect' => 'SQL_ _ DROP TABLE'),
261        array('src' => '<script>alert(\'boom!\');</script>', 'expect' => 'script_alert(_boom!_)_script'),
262        array('src' => '%20%2F%41%39 &amp; X?', 'expect' => '20_2F_41_39 _amp_ X'),
263        array('src' => 'https://127893215784/xyz', 'expect' => 'https_127893215784_xyz'),
264        );
265
266foreach ($test as $tc)
267{
268        $t = $tc['src'];
269        $e = $tc['expect'];
270        $r = FileManagerUtility::pagetitle($t, null, $re_extra, $trim_extra);
271
272        echo "\n<pre>ORIG: [" . htmlentities($t, ENT_NOQUOTES, 'UTF-8') . "]\nRES:  [" . htmlentities($r, ENT_NOQUOTES, 'UTF-8') . "]</pre>\n";
273       
274        if (strcmp($e, $r) != 0)
275        {
276                echo "<p><strong>FAILED!</strong></p>\n";
277        }
278        echo "\n<hr />\n";
279}
280
281?>
282
283
284<h3>getSiteRoot</h3>
285
286<p>$_SERVER['DOCUMENT_ROOT'] = '<?php echo $_SERVER['DOCUMENT_ROOT']; ?>'</p>
287
288<p>realpath('/') = '<?php echo realpath('/'); ?>'</p>
289
290<h3>getRequestPath</h3>
291
292<p>getRequestPath() => '<?php echo $browser->getRequestPath(); ?>'</p>
293
294
295<h3>URI to abs &amp; file path transform for DocumentRoot based URIs</h3>
296
297<?php
298
299$test = array(
300        array('src' => ''),
301        array('src' => '/'),
302        array('src' => 'Files/'),
303        array('src' => '/Files'),
304        array('src' => '/Files/'),
305        array('src' => 'Files/../alias'),
306        array('src' => 'Files/../d'),
307        array('src' => 'Files/../u'),
308        array('src' => '/alias'),
309        array('src' => '/d'),
310        array('src' => '/u'),
311        array('src' => 'Files/alias'),
312        array('src' => 'Files/d'),
313        array('src' => 'Files/u'),
314        array('src' => '../Demos/Files/u'),
315        array('src' => '../Assets/../Demos/Files'),
316        array('src' => 'Files/././../../D/.././Demos/Files'),
317        );
318
319foreach ($test as $tc)
320{
321        $t = $tc['src'];
322        $emsg = null;
323        $r1 = '';
324        $r2 = '';
325       
326        try
327        {
328                $r1 = $browser->rel2abs_url_path($t);
329                $r2 = $browser->url_path2file_path($t);
330    }
331    catch(FileManagerException $e)
332    {
333        $emsg = $e->getMessage();
334    }
335
336        echo "\n<pre>ORIG:    [" . htmlentities($t, ENT_NOQUOTES, 'UTF-8') . "]\nURI.ABS: [" . htmlentities($r1, ENT_NOQUOTES, 'UTF-8') . "]\nDIR.ABS: [" . htmlentities($r2, ENT_NOQUOTES, 'UTF-8') . "]</pre>\n";
337       
338        if ($emsg !== null)
339        {
340                echo "<p><strong>FileManagerException('$emsg')!</strong></p>\n";
341        }
342        echo "\n<hr />\n";
343}
344
345?>
346
347<h3>URI to abs &amp; file path transform for options['directory'] based URIs</h3>
348
349<?php
350
351foreach ($test as $tc)
352{
353        $t = $tc['src'];
354        $emsg = null;
355        $r1 = '';
356        $r2 = '';
357        $r3 = '';
358        $r4 = '';
359        $r5 = '';
360       
361        try
362        {
363                $r3 = $settings['directory'] . $t;
364                $r5 = $browser->normalize($r3);
365                $r4 = $browser->url_path2file_path($r3);
366                $r1 = $browser->rel2abs_legal_url_path($t);
367                $r2 = $browser->legal_url_path2file_path($t);
368    }
369    catch(FileManagerException $e)
370    {
371        $emsg = $e->getMessage();
372    }
373
374        echo "\n<pre>ORIG:    [" . htmlentities($t, ENT_NOQUOTES, 'UTF-8') . "]\nURI.ABS: [" . htmlentities($r1, ENT_NOQUOTES, 'UTF-8') . "]\nDIR.ABS: [" . htmlentities($r2, ENT_NOQUOTES, 'UTF-8') . "]\nRAW.URI: [" . htmlentities($r3, ENT_NOQUOTES, 'UTF-8') . "]\nNORMLZD: [" . htmlentities($r5, ENT_NOQUOTES, 'UTF-8') . "]\nDIR.ABS: [" . htmlentities($r4, ENT_NOQUOTES, 'UTF-8') . "]</pre>\n";
375       
376        if ($emsg !== null)
377        {
378                echo "<p><strong>FileManagerException('$emsg')!</strong></p>\n";
379        }
380        echo "\n<hr />\n";
381}
382
383?>
384
385<h3>FM Aliased directory scan output</h3>
386
387<?php
388
389$test = array(
390        array('src' => ''),
391        array('src' => '/'),
392        array('src' => '/Files'),
393        array('src' => '/Files/..'),
394        array('src' => '/Files/../alias/'),
395        array('src' => '/Files/../d'),
396        array('src' => '/Files/../u'),
397        );
398
399
400foreach ($test as $tc)
401{
402        $t = $tc['src'];
403        $emsg = null;
404        $r1 = '';
405        $r2 = '';
406        $c1 = '';
407       
408        try
409        {
410                $r1 = $browser->rel2abs_legal_url_path($t);
411                $r2 = $browser->legal_url_path2file_path($t);
412               
413                $c1 = $browser->scandir($r2);
414    }
415    catch(FileManagerException $e)
416    {
417        $emsg = $e->getMessage();
418    }
419
420        echo "\n<strong><pre>dir = '$r2'</pre></strong>\n";
421       
422        echo "\n<h4>scandir output:</h4>\n<pre>";
423        var_dump($c1);
424        echo "</pre>\n";
425       
426        if ($emsg !== null)
427        {
428                echo "<p><strong>FileManagerException('$emsg')!</strong></p>\n";
429        }
430        echo "\n<hr />\n";
431}
432
433?>
434
435
436
437
438
439
440
441
442
443
444<h3>FM 'view' output</h3>
445
446<pre>
447<?php
448$dump = '{}';
449ob_start();
450        $_POST = array();
451        $_POST['directory'] = '/'; // '/bugger/';
452        $_POST['file'] = '0[]~!@()-._  90826039_1_1_3.jpg';
453        $_POST['type'] = 'thumb';
454        $browser->fireEvent('detail');
455$dump = ob_get_clean();
456
457echo "input:\n";
458var_dump($_POST);
459echo "\n\noutput for event 'detail':\n\n";
460
461$json = json_decode($dump);
462var_dump($json);
463
464?>
465<hr />
466
467
468<pre>
469<?php
470$dump = '{}';
471ob_start();
472        $_POST = array();
473        $_POST['directory'] = '/'; // '/bugger/';
474        $_POST['file'] = 'MO mc 5.jpg';
475        $_POST['type'] = 'thumb';
476        $browser->fireEvent('detail');
477$dump = ob_get_clean();
478
479echo "input:\n";
480var_dump($_POST);
481echo "\n\noutput for event 'detail':\n\n";
482
483//echo "</pre><div>" . htmlentities($dump, ENT_NOQUOTES, 'UTF-8') . "</div><pre>\n";
484//echo "\n\n";
485
486$json = json_decode($dump);
487var_dump($json);
488
489?>
490<hr />
491
492
493
494<pre>
495<?php
496$dump = '{}';
497ob_start();
498        $_POST = array();
499        $_POST['directory'] = '';
500        $_POST['filter'] = '';
501        $_POST['type'] = 'list';
502        $browser->fireEvent('view');
503$dump = ob_get_clean();
504
505echo "input:\n";
506var_dump($_POST);
507echo "\n\noutput for event 'view':\n\n";
508
509$json = json_decode($dump);
510var_dump($json);
511
512?>
513<hr />
514
515
516
517
Note: See TracBrowser for help on using the repository browser.