/** * Get the current directory. * * @return The current directory. */ function ft_get_dir() { if (empty($_REQUEST['dir'])) { return ft_get_root(); } else { return ft_get_root() . $_REQUEST['dir']; } }
/** * Private function. Searches for file names and directories recursively. * * @param $dir * Directory to search. * @param $q * Search query. * @return An array of files. Each item is an array: * array( * 'name' => '', // File name. * 'shortname' => '', // File name. * 'type' => '', // 'file' or 'dir'. * 'dir' => '', // Directory where file is located. * ) */ function _ft_search_find_files($dir, $q) { $output = array(); if (ft_check_dir($dir) && ($dirlink = @opendir($dir))) { while (($file = readdir($dirlink)) !== false) { if ($file != "." && $file != ".." && (ft_check_file($file) && ft_check_filetype($file) || is_dir($dir . "/" . $file) && ft_check_dir($file))) { $path = $dir . '/' . $file; // Check if filename/directory name is a match. if (stristr($file, $q)) { $new['name'] = $file; $new['shortname'] = ft_get_nice_filename($file, 20); $new['dir'] = substr($dir, strlen(ft_get_root())); if (is_dir($path)) { if (ft_check_dir($path)) { $new['type'] = "dir"; $output[] = $new; } } else { $new['type'] = "file"; $output[] = $new; } } // Check subdirs for matches. if (is_dir($path)) { $dirres = _ft_search_find_files($path, $q); if (is_array($dirres) && count($dirres) > 0) { $output = array_merge($dirres, $output); unset($dirres); } } } } sort($output); closedir($dirlink); return $output; } else { return FALSE; } }