diff options
author | Robin Appelman <icewind1991@gmail.com> | 2011-05-28 19:31:36 +0200 |
---|---|---|
committer | Robin Appelman <icewind1991@gmail.com> | 2011-05-28 19:49:28 +0200 |
commit | 2617e4b607fd7b7b3272b9975687670c686c4ced (patch) | |
tree | 95e9f55ebd80fadabf3ea8d1c162ce3dc951633f /files/ajax/autocomplete.php | |
parent | f4e4617be7a22a0191bf1bc21f6d8462d215108e (diff) | |
download | nextcloud-server-2617e4b607fd7b7b3272b9975687670c686c4ced.tar.gz nextcloud-server-2617e4b607fd7b7b3272b9975687670c686c4ced.zip |
add autocomplete for paths
Diffstat (limited to 'files/ajax/autocomplete.php')
-rw-r--r-- | files/ajax/autocomplete.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/files/ajax/autocomplete.php b/files/ajax/autocomplete.php new file mode 100644 index 00000000000..4276bb9e1d0 --- /dev/null +++ b/files/ajax/autocomplete.php @@ -0,0 +1,56 @@ +<?php +//provide auto completion of paths for use with jquer ui autocomplete + + +// Init owncloud +require_once('../../lib/base.php'); + +// We send json data +// header( "Content-Type: application/jsonrequest" ); + +// Check if we are a user +if( !OC_USER::isLoggedIn()){ + echo json_encode( array( "status" => "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); + +?> |