2011-05-28 17:31:36 +00:00
|
|
|
<?php
|
|
|
|
//provide auto completion of paths for use with jquer ui autocomplete
|
|
|
|
|
|
|
|
|
|
|
|
// Init owncloud
|
|
|
|
require_once('../../lib/base.php');
|
|
|
|
|
2011-09-23 20:22:59 +00:00
|
|
|
OC_JSON::checkLoggedIn();
|
2011-05-28 17:31:36 +00:00
|
|
|
|
|
|
|
// 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));
|
2011-06-01 12:05:30 +00:00
|
|
|
|
|
|
|
if($base!='/'){
|
|
|
|
$query=substr($query,1);
|
|
|
|
}
|
2011-05-28 17:31:36 +00:00
|
|
|
$queryLen=strlen($query);
|
2011-06-02 00:31:04 +00:00
|
|
|
$query=strtolower($query);
|
2011-05-28 17:31:36 +00:00
|
|
|
|
|
|
|
// echo "$base - $query";
|
|
|
|
|
|
|
|
$files=array();
|
|
|
|
|
2011-07-29 19:36:03 +00:00
|
|
|
if(OC_Filesystem::file_exists($base) and OC_Filesystem::is_dir($base)){
|
|
|
|
$dh = OC_Filesystem::opendir($base);
|
2011-07-12 15:45:01 +00:00
|
|
|
if($dh){
|
|
|
|
if(substr($base,-1,1)!='/'){
|
|
|
|
$base=$base.'/';
|
|
|
|
}
|
|
|
|
while (($file = readdir($dh)) !== false) {
|
|
|
|
if ($file != "." && $file != ".."){
|
|
|
|
if(substr(strtolower($file),0,$queryLen)==$query){
|
|
|
|
$item=$base.$file;
|
2011-07-29 19:36:03 +00:00
|
|
|
if((!$dirOnly or OC_Filesystem::is_dir($item))){
|
2011-07-12 15:45:01 +00:00
|
|
|
$files[]=(object)array('id'=>$item,'label'=>$item,'name'=>$item);
|
|
|
|
}
|
2011-05-28 17:31:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-23 20:22:59 +00:00
|
|
|
OC_JSON::encodedPrint($files);
|
2011-05-28 17:31:36 +00:00
|
|
|
|
|
|
|
?>
|