PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/includes/js/mootools-filemanager/Demos/test-backend.php

https://github.com/KenBoyer/CompactCMS
PHP | 596 lines | 450 code | 127 blank | 19 comment | 42 complexity | a53e3ec70b280a9475a765af696b4f20 MD5 | raw file
  1. <?php
  2. error_reporting(E_ALL | E_STRICT);
  3. define("COMPACTCMS_CODE", true);
  4. //require_once('../Assets/Connector/FileManager.php');
  5. require_once('../Assets/Connector/FMgr4Alias.php');
  6. define('DEVELOPMENT', 01); // set to 01 / 1 to enable logging of each incoming event request.
  7. // dumper useful in development
  8. function FM_vardumper($mgr = null, $action = null, $info = null, $filenamebase = null)
  9. {
  10. if (DEVELOPMENT)
  11. {
  12. if (!is_string($filenamebase))
  13. {
  14. $filenamebase = basename(__FILE__);
  15. }
  16. if ($mgr)
  17. $settings = $mgr->getSettings();
  18. else
  19. $settings = null;
  20. //$mimetdefs = $mgr->getMimeTypeDefinitions();
  21. // log request data:
  22. ob_start();
  23. echo "FileManager::action:\n";
  24. var_dump($action);
  25. echo "\n\nFileManager::info:\n";
  26. var_dump($info);
  27. echo "\n\nFileManager::settings:\n";
  28. var_dump($settings);
  29. if (01) // set to 'if (01)' if you want this bit dumped as well; fastest back-n-forth edit that way :-)
  30. {
  31. echo "\n\n_SERVER:\n";
  32. var_dump($_SERVER);
  33. }
  34. if (0)
  35. {
  36. echo "\n\n_ENV:\n";
  37. if (isset($_ENV)) var_dump($_ENV); else echo "(null)\n";
  38. }
  39. if (01)
  40. {
  41. echo "\n\n_GET:\n";
  42. if (isset($_GET)) var_dump($_GET); else echo "(null)\n";
  43. }
  44. if (01)
  45. {
  46. echo "\n\n_POST:\n";
  47. if (isset($_POST)) var_dump($_POST); else echo "(null)\n";
  48. }
  49. if (01)
  50. {
  51. echo "\n\n_REQUEST:\n";
  52. if (isset($_REQUEST)) var_dump($_REQUEST); else echo "(null)\n";
  53. }
  54. if (01)
  55. {
  56. echo "\n\n_FILES:\n";
  57. if (isset($_FILES)) var_dump($_FILES); else echo "(null)\n";
  58. }
  59. if (01)
  60. {
  61. echo "\n\n_COOKIE:\n";
  62. if (isset($_COOKIE)) var_dump($_COOKIE); else echo "(null)\n";
  63. }
  64. if (0)
  65. {
  66. echo "\n\n_SESSION:\n";
  67. if (isset($_SESSION)) var_dump($_SESSION); else echo "(null)\n";
  68. }
  69. $dump = ob_get_clean();
  70. static $count;
  71. if (!$count) $count = 1; else $count++;
  72. $dst = ((!empty($filenamebase) ? $filenamebase . '.' : '') . date('Ymd-His') . '.' . fmod(microtime(true), 1) . '-' . $action . '-' . $count . '.log');
  73. $dst = preg_replace('/[^A-Za-z0-9-_.]+/', '_', $dst); // make suitable for filesystem
  74. @file_put_contents($dst, html_entity_decode(strip_tags($dump), ENT_NOQUOTES, 'UTF-8'));
  75. }
  76. }
  77. ?>
  78. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  79. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  80. <html xmlns="http://www.w3.org/1999/xhtml">
  81. <head>
  82. <title>MooTools FileManager Backend Testground</title>
  83. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  84. <link rel="shortcut icon" href="http://og5.net/christoph/favicon.png" />
  85. <style type="text/css">
  86. body {
  87. font-size: 11px;
  88. font-family: Tahoma, sans-serif;
  89. }
  90. h1 {
  91. margin: 0 0 10px 0;
  92. padding: 0;
  93. color: #666;
  94. font-weight: normal;
  95. font-size: 24px;
  96. letter-spacing: 1px;
  97. word-spacing: 2px;
  98. line-height: 22px;
  99. min-height: 25px;
  100. }
  101. h1 span {
  102. font-size: 11px;
  103. letter-spacing: 0;
  104. word-spacing: 0;
  105. text-shadow: none;
  106. }
  107. .blue { color: #1f52b0; }
  108. div.content {
  109. min-height: 200px;
  110. margin: 23px 34px;
  111. padding: 10px 17px;
  112. border: 1px solid #b2b2b2;
  113. background: #fff;
  114. box-shadow: rgba(0, 0, 0, 0.3) 0 0 10px;
  115. -moz-box-shadow: rgba(0, 0, 0, 0.3) 0 0 10px;
  116. -webkit-box-shadow: rgba(0, 0, 0, 0.3) 0 0 10px;
  117. }
  118. div.content div.example {
  119. float: left;
  120. clear: both;
  121. margin: 10px 0;
  122. }
  123. button {
  124. margin: 5px 0;
  125. }
  126. /* http://labnol.blogspot.com/2006/10/html-css-trick-for-displaying-code.html */
  127. pre {
  128. white-space: pre-wrap; /* css-3 */
  129. white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
  130. white-space: -pre-wrap; /* Opera 4-6 */
  131. white-space: -o-pre-wrap; /* Opera 7 */
  132. word-wrap: break-word; /* Internet Explorer 5.5+ */
  133. }
  134. </style>
  135. <script type="text/javascript" src="../../../../../lib/includes/js/mootools-core.js"></script>
  136. <script type="text/javascript" src="../../../../../lib/includes/js/mootools-more.js"></script>
  137. <script type="text/javascript" src="../Source/FileManager.js"></script>
  138. <script type="text/javascript" src="../Source/Gallery.js"></script>
  139. <script type="text/javascript" src="../Source/Uploader/Fx.ProgressBar.js"></script>
  140. <script type="text/javascript" src="../Source/Uploader/Swiff.Uploader.js"></script>
  141. <script type="text/javascript" src="../Source/Uploader.js"></script>
  142. <script type="text/javascript" src="../Language/Language.en.js"></script>
  143. <script type="text/javascript" src="../Language/Language.de.js"></script>
  144. <script type="text/javascript">
  145. window.addEvent('domready', function() {
  146. });
  147. </script>
  148. </head>
  149. <body>
  150. <div id="content" class="content">
  151. <h1>FileManager Backend Tests</h1>
  152. <h2>Basic PHP tests</h2>
  153. <pre>
  154. <?php
  155. // log request data:
  156. FM_vardumper(null, 'testFM' . (!empty($_GET['event']) ? '-' . $_GET['event'] : null));
  157. if (01) // debugging
  158. {
  159. $re_extra = '-_., []()~!@+' /* . '#&' */;
  160. $trim_extra = '-_,~@+#&';
  161. echo "pagetitle(str, NULL, '$re_extra', '$trim_extra'): regex to filter file &amp; dirnames before they are created:\n";
  162. // ASCII range
  163. for ($i = 0; $i < 8; $i++)
  164. {
  165. $msg = '';
  166. $str = '';
  167. for ($j = 0; $j < 16; $j++)
  168. {
  169. $c = $i * 16 + $j;
  170. switch ($c)
  171. {
  172. case 9:
  173. $msg .= "(TAB)";
  174. break;
  175. case 13:
  176. $msg .= "(CR)";
  177. break;
  178. case 10:
  179. $msg .= "(LF)";
  180. break;
  181. default:
  182. $msg .= ($c >= 32 ? htmlentities(chr($c), ENT_NOQUOTES, 'UTF-8') : '&#' . $c . ';');
  183. break;
  184. }
  185. $str .= chr($c);
  186. }
  187. echo "ORIG: [X" . $msg . "X]";
  188. if ($i < 2)
  189. {
  190. echo " (these characters are 'low ASCII' charactercodes " . ($i * 16) . " ... " . ($i * 16 + 15);
  191. }
  192. echo "\n";
  193. $r = FileManagerUtility::pagetitle('X' . $str . 'X', null, $re_extra, $trim_extra);
  194. echo "FILTERED: [" . htmlentities($r, ENT_NOQUOTES, 'UTF-8') . "]\n\n";
  195. }
  196. $trimset = '_.';
  197. echo "\n\ntrim() with multiple characters in the trim set: [$trimset]\n";
  198. $test = array(
  199. '.ignore',
  200. '___ignore',
  201. '_._.ignore',
  202. '._._ignore',
  203. 'X.ignore',
  204. 'X___ignore',
  205. 'X_._.ignore',
  206. 'X._._ignore',
  207. '__X_ignore',
  208. '_._X.ignore',
  209. '._.X_ignore'
  210. );
  211. foreach ($test as $t)
  212. {
  213. $r = trim($t, $trimset);
  214. echo "\nORIG: [" . htmlentities($t, ENT_NOQUOTES, 'UTF-8') . "]\nRES: [" . htmlentities($r, ENT_NOQUOTES, 'UTF-8') . "]\n";
  215. }
  216. }
  217. $browser = new FileManagerWithAliasSupport(array(
  218. 'directory' => 'Files/', // relative paths: are relative to the URI request script path, i.e. dirname(__FILE__)
  219. //'thumbnailPath' => 'Files/Thumbnails/',
  220. 'assetBasePath' => '../Assets',
  221. 'chmod' => 0777,
  222. //'maxUploadSize' => 1024 * 1024 * 5,
  223. //'upload' => false,
  224. //'destroy' => false,
  225. //'create' => false,
  226. //'move' => false,
  227. //'download' => false,
  228. //'filter' => 'image/',
  229. 'allowExtChange' => true, // allow file name extensions to be changed; the default however is: NO (FALSE)
  230. 'UploadIsAuthorized_cb' => 'FM_IsAuthorized',
  231. 'DownloadIsAuthorized_cb' => 'FM_IsAuthorized',
  232. 'CreateIsAuthorized_cb' => 'FM_IsAuthorized',
  233. 'DestroyIsAuthorized_cb' => 'FM_IsAuthorized',
  234. 'MoveIsAuthorized_cb' => 'FM_IsAuthorized'
  235. // http://httpd.apache.org/docs/2.2/mod/mod_alias.html -- we only emulate the Alias statement.
  236. // Implementing other path translation features is left as an exercise to the reader:
  237. , 'Aliases' => array(
  238. '/c/lib/includes/js/mootools-filemanager/Demos/Files/alias' => "D:/xxx",
  239. '/c/lib/includes/js/mootools-filemanager/Demos/Files/d' => "D:/xxx.tobesorted",
  240. '/c/lib/includes/js/mootools-filemanager/Demos/Files/u' => "D:/websites-uploadarea",
  241. '/c/lib/includes/js/mootools-filemanager/Demos/Files' => "D:/experiment"
  242. )
  243. ));
  244. echo "\n\n";
  245. $settings = $browser->getSettings();
  246. var_dump($settings);
  247. ?>
  248. </pre>
  249. <h2>Important server variables</h2>
  250. <p>$_SERVER['DOCUMENT_ROOT'] = '<?php echo $_SERVER['DOCUMENT_ROOT']; ?>'</p>
  251. <p>$_SERVER['SCRIPT_NAME'] = '<?php echo $_SERVER['SCRIPT_NAME']; ?>'</p>
  252. <h2>FileManagerUtility class static methods</h2>
  253. <?php
  254. $re_extra = '-_., []()~!@+' /* . '#&' */;
  255. $trim_extra = '-_,~@+#&';
  256. ?>
  257. <h3>pagetitle(str, NULL, '<?php echo $re_extra; ?>', '<?php echo $trim_extra; ?>')</h3>
  258. <?php
  259. $test = array(
  260. array('src' => '.htaccess', 'expect' => 'htaccess'),
  261. array('src' => 'regular.jpg', 'expect' => 'regular.jpg'),
  262. array('src' => 'Umgebung Altstadt Østgat', 'expect' => 'Umgebung Altstadt Ostgat'),
  263. array('src' => ' Sed ut perspiciatis unde omnis iste natus error ', 'expect' => 'Sed ut perspiciatis unde omnis iste natus error'),
  264. array('src' => ' advantage from it? But who has any right ', 'expect' => 'advantage from it_ But who has any right'),
  265. array('src' => 'welche aus geistiger Schwäche, d.h.', 'expect' => 'welche aus geistiger Schwaeche, d.h'),
  266. array('src' => 'München - Ausrüstung - Spaß - Viele Grüße!', 'expect' => 'Muenchen - Ausruestung - Spass - Viele Gruesse!'),
  267. array('src' => 'C:\\Windows\\TEMP\\', 'expect' => 'C_Windows_TEMP'),
  268. array('src' => '/etc/passwd', 'expect' => 'etc_passwd'),
  269. array('src' => 'Let\'s see what " quotes do?', 'expect' => 'Let_s see what _ quotes do'),
  270. array('src' => '中国出售的软件必须使用编码 新 和 湖南北部 父母通常都会对子女说地方方言 现在香港的日常使用中出现了越来越多的简体汉字 华语, 走 贵州 看不懂 清浊声', 'expect' => ''),
  271. array('src' => 'également appelé lorem ipsum', 'expect' => 'egalement appele lorem ipsum'),
  272. 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'),
  273. array('src' => 'Ipsum текст Lorem, которые, как правило, бессмысленный список полу-латинские слова', 'expect' => 'Ipsum _ Lorem'),
  274. array('src' => 'اول دو واژه از رشته ای از متن لاتین مورد استفاده در طراحی وب سایت و چاپ به جای انگلیسی به استرس و با تکیه تلفظ کردن اهمیت', 'expect' => ''),
  275. array('src' => '설명하는 그래픽 등의 요소의 시각적 프레 젠 테이션, 문서 또는 글꼴 , 활판 인쇄술 , 그리고 레이아웃 . 의 세미 라틴어', 'expect' => ''),
  276. array('src' => 'פילער טעקסט) צו באַווייַזן די גראַפיק עלעמענטן פון אַ דאָקומענט אָדער וויסואַל פּרעזענטירונג, אַזאַ ווי שריפֿט , טאַפּאַגראַפי', 'expect' => ')'),
  277. array('src' => 'χρησιμοποιούνται κείμενο κράτησης θέσης (κείμενο πλήρωσης), για να αποδειχθεί η γραφικά στοιχεία', 'expect' => '(_ _)'),
  278. array('src' => 'ルダテキスト (フィラーテキスト)示すために、グラフィックなどの要素を指定するの視覚的なプレゼンテーション、', 'expect' => ''),
  279. array('src' => 'SQL: \'\'; DROP TABLE; \'', 'expect' => 'SQL_ _ DROP TABLE'),
  280. array('src' => '<script>alert(\'boom!\');</script>', 'expect' => 'script_alert(_boom!_)_script'),
  281. array('src' => '%20%2F%41%39 &amp; X?', 'expect' => '20_2F_41_39 _amp_ X'),
  282. array('src' => 'https://127893215784/xyz', 'expect' => 'https_127893215784_xyz'),
  283. );
  284. foreach ($test as $tc)
  285. {
  286. $t = $tc['src'];
  287. $e = $tc['expect'];
  288. $r = FileManagerUtility::pagetitle($t, null, $re_extra, $trim_extra);
  289. echo "\n<pre>ORIG: [" . htmlentities($t, ENT_NOQUOTES, 'UTF-8') . "]\nRES: [" . htmlentities($r, ENT_NOQUOTES, 'UTF-8') . "]</pre>\n";
  290. if (strcmp($e, $r) != 0)
  291. {
  292. echo "<p><strong>FAILED!</strong></p>\n";
  293. }
  294. echo "\n<hr />\n";
  295. }
  296. ?>
  297. <h3>getSiteRoot</h3>
  298. <p>$_SERVER['DOCUMENT_ROOT'] = '<?php echo $_SERVER['DOCUMENT_ROOT']; ?>'</p>
  299. <p>realpath('/') = '<?php echo realpath('/'); ?>'</p>
  300. <h3>getRequestPath</h3>
  301. <p>getRequestPath() => '<?php echo $browser->getRequestPath(); ?>'</p>
  302. <h3>URI to abs &amp; file path transform for DocumentRoot based URIs</h3>
  303. <?php
  304. $test = array(
  305. array('src' => ''),
  306. array('src' => '/'),
  307. array('src' => 'Files/'),
  308. array('src' => '/Files'),
  309. array('src' => '/Files/'),
  310. array('src' => 'Files/../alias'),
  311. array('src' => 'Files/../d'),
  312. array('src' => 'Files/../u'),
  313. array('src' => '/alias'),
  314. array('src' => '/d'),
  315. array('src' => '/u'),
  316. array('src' => 'Files/alias'),
  317. array('src' => 'Files/d'),
  318. array('src' => 'Files/u'),
  319. array('src' => '../Demos/Files/u'),
  320. array('src' => '../Assets/../Demos/Files'),
  321. array('src' => 'Files/././../../D/.././Demos/Files'),
  322. );
  323. foreach ($test as $tc)
  324. {
  325. $t = $tc['src'];
  326. $emsg = null;
  327. $r1 = '';
  328. $r2 = '';
  329. try
  330. {
  331. $r1 = $browser->rel2abs_url_path($t);
  332. $r2 = $browser->url_path2file_path($t);
  333. }
  334. catch(FileManagerException $e)
  335. {
  336. $emsg = $e->getMessage();
  337. }
  338. 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";
  339. if ($emsg !== null)
  340. {
  341. echo "<p><strong>FileManagerException('$emsg')!</strong></p>\n";
  342. }
  343. echo "\n<hr />\n";
  344. }
  345. ?>
  346. <h3>URI to abs &amp; file path transform for options['directory'] based URIs</h3>
  347. <?php
  348. foreach ($test as $tc)
  349. {
  350. $t = $tc['src'];
  351. $emsg = null;
  352. $r1 = '';
  353. $r2 = '';
  354. $r3 = '';
  355. $r4 = '';
  356. $r5 = '';
  357. try
  358. {
  359. $r3 = $settings['directory'] . $t;
  360. $r5 = $browser->normalize($r3);
  361. $r4 = $browser->url_path2file_path($r3);
  362. $r1 = $browser->rel2abs_legal_url_path($t);
  363. $r2 = $browser->legal_url_path2file_path($t);
  364. }
  365. catch(FileManagerException $e)
  366. {
  367. $emsg = $e->getMessage();
  368. }
  369. 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";
  370. if ($emsg !== null)
  371. {
  372. echo "<p><strong>FileManagerException('$emsg')!</strong></p>\n";
  373. }
  374. echo "\n<hr />\n";
  375. }
  376. ?>
  377. <h3>FM Aliased directory scan output</h3>
  378. <?php
  379. $test = array(
  380. array('src' => ''),
  381. array('src' => '/'),
  382. array('src' => '/Files'),
  383. array('src' => '/Files/..'),
  384. array('src' => '/Files/../alias/'),
  385. array('src' => '/Files/../d'),
  386. array('src' => '/Files/../u'),
  387. );
  388. foreach ($test as $tc)
  389. {
  390. $t = $tc['src'];
  391. $emsg = null;
  392. $r1 = '';
  393. $r2 = '';
  394. $c1 = '';
  395. try
  396. {
  397. $r1 = $browser->rel2abs_legal_url_path($t);
  398. $r2 = $browser->legal_url_path2file_path($t);
  399. $c1 = $browser->scandir($r2);
  400. }
  401. catch(FileManagerException $e)
  402. {
  403. $emsg = $e->getMessage();
  404. }
  405. echo "\n<strong><pre>dir = '$r2'</pre></strong>\n";
  406. echo "\n<h4>scandir output:</h4>\n<pre>";
  407. var_dump($c1);
  408. echo "</pre>\n";
  409. if ($emsg !== null)
  410. {
  411. echo "<p><strong>FileManagerException('$emsg')!</strong></p>\n";
  412. }
  413. echo "\n<hr />\n";
  414. }
  415. ?>
  416. <h3>FM 'view' output</h3>
  417. <pre>
  418. <?php
  419. $dump = '{}';
  420. ob_start();
  421. $_POST = array();
  422. $_POST['directory'] = '/'; // '/bugger/';
  423. $_POST['file'] = '0[]~!@()-._ 90826039_1_1_3.jpg';
  424. $_POST['type'] = 'thumb';
  425. $browser->fireEvent('detail');
  426. $dump = ob_get_clean();
  427. echo "input:\n";
  428. var_dump($_POST);
  429. echo "\n\noutput for event 'detail':\n\n";
  430. $json = json_decode($dump);
  431. var_dump($json);
  432. ?>
  433. <hr />
  434. <pre>
  435. <?php
  436. $dump = '{}';
  437. ob_start();
  438. $_POST = array();
  439. $_POST['directory'] = '/'; // '/bugger/';
  440. $_POST['file'] = 'MO mc 5.jpg';
  441. $_POST['type'] = 'thumb';
  442. $browser->fireEvent('detail');
  443. $dump = ob_get_clean();
  444. echo "input:\n";
  445. var_dump($_POST);
  446. echo "\n\noutput for event 'detail':\n\n";
  447. //echo "</pre><div>" . htmlentities($dump, ENT_NOQUOTES, 'UTF-8') . "</div><pre>\n";
  448. //echo "\n\n";
  449. $json = json_decode($dump);
  450. var_dump($json);
  451. ?>
  452. <hr />
  453. <pre>
  454. <?php
  455. $dump = '{}';
  456. ob_start();
  457. $_POST = array();
  458. $_POST['directory'] = '';
  459. $_POST['filter'] = '';
  460. $_POST['type'] = 'list';
  461. $browser->fireEvent('view');
  462. $dump = ob_get_clean();
  463. echo "input:\n";
  464. var_dump($_POST);
  465. echo "\n\noutput for event 'view':\n\n";
  466. $json = json_decode($dump);
  467. var_dump($json);
  468. ?>
  469. <hr />