/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
- <?php
- /**
- * @package setup
- */
- $output= '';
- $mode= isset ($_POST['installmode']) ? intval($_POST['installmode']) : modInstall::MODE_NEW;
- if (function_exists('json_encode') && isset ($_REQUEST['search']) && $_REQUEST['search']) {
- $id= 0;
- $results= array();
- $searchString= $_REQUEST['search'];
- $dirname= strtr(realpath(dirname($searchString)), '\\', '/') . '/';
- $filepart= basename($searchString);
- if ($handle= @ opendir($dirname)) {
- while (false !== ($file= @ readdir($handle))) {
- if ($file != '.' && $file != '..') { /* Ignore . and .. */
- /* if ($filepart && strpos($file, $filepart) === false) continue; */
- $path= $dirname . $file;
- if (is_dir($path) && (!$filepart || strpos($file, $filepart) !== false)) {
- $results[]= array (
- 'id' => $id++,
- 'value' => $path . '/',
- );
- }
- }
- }
- $output= json_encode($results);
- }
- }
- if (empty ($output) || $output == '[]') {
- $output= "[]";
- }
- header('Content-Type:text/javascript');
- echo '{"success": true, "results":' . $output . '}';
- exit();