/setup/processors/path_search.php

http://github.com/modxcms/revolution · PHP · 34 lines · 30 code · 0 blank · 4 comment · 15 complexity · c19959e414899fc5989747a00a5d76b9 MD5 · raw file

  1. <?php
  2. /**
  3. * @package setup
  4. */
  5. $output= '';
  6. $mode= isset ($_POST['installmode']) ? intval($_POST['installmode']) : modInstall::MODE_NEW;
  7. if (function_exists('json_encode') && isset ($_REQUEST['search']) && $_REQUEST['search']) {
  8. $id= 0;
  9. $results= array();
  10. $searchString= $_REQUEST['search'];
  11. $dirname= strtr(realpath(dirname($searchString)), '\\', '/') . '/';
  12. $filepart= basename($searchString);
  13. if ($handle= @ opendir($dirname)) {
  14. while (false !== ($file= @ readdir($handle))) {
  15. if ($file != '.' && $file != '..') { /* Ignore . and .. */
  16. /* if ($filepart && strpos($file, $filepart) === false) continue; */
  17. $path= $dirname . $file;
  18. if (is_dir($path) && (!$filepart || strpos($file, $filepart) !== false)) {
  19. $results[]= array (
  20. 'id' => $id++,
  21. 'value' => $path . '/',
  22. );
  23. }
  24. }
  25. }
  26. $output= json_encode($results);
  27. }
  28. }
  29. if (empty ($output) || $output == '[]') {
  30. $output= "[]";
  31. }
  32. header('Content-Type:text/javascript');
  33. echo '{"success": true, "results":' . $output . '}';
  34. exit();