PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/setup/processors/url_search.php

http://github.com/modxcms/revolution
PHP | 43 lines | 39 code | 1 blank | 3 comment | 17 complexity | 2b3b327516daa0a1377767fe22863e9d MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1
  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. $filepart= '';
  12. if ($searchString{strlen($searchString)-1} != '/') {
  13. $filepart= basename(trim($searchString, '/'));
  14. $searchString= strtr(dirname($searchString), '\\', '/');
  15. } else {
  16. $searchString= strtr($searchString, '\\', '/');
  17. }
  18. $searchString= trim($searchString, '/');
  19. $docroot= $_SERVER['DOCUMENT_ROOT'];
  20. $dirname= $docroot . '/' . $searchString;
  21. if ($handle= @ opendir($dirname)) {
  22. while (false !== ($file= @ readdir($handle))) {
  23. if ($file != '.' && $file != '..') { /* Ignore . and .. */
  24. $path= $dirname . '/' . $file;
  25. $result= '/' . trim(str_replace($docroot, '', $path), '/') . '/';
  26. if (is_dir($path) && (!$filepart || (strpos($file, $filepart) === 0))) {
  27. $results[]= array (
  28. 'id' => $result,
  29. 'value' => $result
  30. );
  31. }
  32. }
  33. }
  34. $output= json_encode($results);
  35. }
  36. }
  37. if (empty ($output) || $output == '[]') {
  38. $output= "[]";
  39. }
  40. header('Content-Type:text/javascript');
  41. echo '{"success": true, "results":' . $output . '}';
  42. exit();