From 2617e4b607fd7b7b3272b9975687670c686c4ced Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 28 May 2011 19:31:36 +0200 Subject: [PATCH] add autocomplete for paths --- files/ajax/autocomplete.php | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 files/ajax/autocomplete.php diff --git a/files/ajax/autocomplete.php b/files/ajax/autocomplete.php new file mode 100644 index 0000000000..4276bb9e1d --- /dev/null +++ b/files/ajax/autocomplete.php @@ -0,0 +1,56 @@ + "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +// Get data +$query = $_GET['term']; +$dirOnly=(isset($_GET['dironly']))?($_GET['dironly']=='true'):false; + +if($query[0]!='/'){ + $query='/'.$query; +} + +if(substr($query,-1,1)=='/'){ + $base=$query; +}else{ + $base=dirname($query); +} + +$query=substr($query,strlen($base)); +$queryLen=strlen($query); + +// echo "$base - $query"; + +$files=array(); + +if(OC_FILESYSTEM::is_dir($base)){ + $dh = OC_FILESYSTEM::opendir($base); + if(substr($base,-1,1)!='/'){ + $base=$base.'/'; + } + while (($file = readdir($dh)) !== false) { + if ($file != "." && $file != ".."){ + if(substr($file,0,$queryLen)==$query){ + $item=$base.$file; + if((!$dirOnly or OC_FILESYSTEM::is_dir($item))){ + $files[]=(object)array('id'=>$item,'label'=>$item,'name'=>$item); + } + } + } + } +} +echo json_encode($files); + +?>