2011-05-28 21:31:36 +04:00
|
|
|
<?php
|
|
|
|
//provide auto completion of paths for use with jquer ui autocomplete
|
|
|
|
|
|
|
|
|
|
|
|
// Init owncloud
|
2012-04-17 21:31:29 +04:00
|
|
|
|
2011-05-28 21:31:36 +04:00
|
|
|
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::checkLoggedIn();
|
2011-05-28 21:31:36 +04:00
|
|
|
|
|
|
|
// Get data
|
|
|
|
$query = $_GET['term'];
|
|
|
|
$dirOnly=(isset($_GET['dironly']))?($_GET['dironly']=='true'):false;
|
|
|
|
|
2012-08-29 02:36:27 +04:00
|
|
|
if($query[0]!='/') {
|
2011-05-28 21:31:36 +04:00
|
|
|
$query='/'.$query;
|
|
|
|
}
|
|
|
|
|
2012-08-29 02:36:27 +04:00
|
|
|
if(substr($query, -1, 1)=='/') {
|
2011-05-28 21:31:36 +04:00
|
|
|
$base=$query;
|
2012-08-29 02:36:27 +04:00
|
|
|
} else {
|
2011-05-28 21:31:36 +04:00
|
|
|
$base=dirname($query);
|
|
|
|
}
|
|
|
|
|
2012-08-29 02:36:27 +04:00
|
|
|
$query=substr($query, strlen($base));
|
2011-06-01 16:05:30 +04:00
|
|
|
|
2012-08-29 02:36:27 +04:00
|
|
|
if($base!='/') {
|
|
|
|
$query=substr($query, 1);
|
2011-06-01 16:05:30 +04:00
|
|
|
}
|
2011-05-28 21:31:36 +04:00
|
|
|
$queryLen=strlen($query);
|
2011-06-02 04:31:04 +04:00
|
|
|
$query=strtolower($query);
|
2011-05-28 21:31:36 +04:00
|
|
|
|
|
|
|
// echo "$base - $query";
|
|
|
|
|
|
|
|
$files=array();
|
|
|
|
|
2012-08-29 02:36:27 +04:00
|
|
|
if(OC_Filesystem::file_exists($base) and OC_Filesystem::is_dir($base)) {
|
2011-07-29 23:36:03 +04:00
|
|
|
$dh = OC_Filesystem::opendir($base);
|
2012-08-29 02:36:27 +04:00
|
|
|
if($dh) {
|
|
|
|
if(substr($base, -1, 1)!='/') {
|
2011-07-12 19:45:01 +04:00
|
|
|
$base=$base.'/';
|
|
|
|
}
|
|
|
|
while (($file = readdir($dh)) !== false) {
|
2012-08-29 02:36:27 +04:00
|
|
|
if ($file != "." && $file != "..") {
|
|
|
|
if(substr(strtolower($file), 0, $queryLen)==$query) {
|
2011-07-12 19:45:01 +04:00
|
|
|
$item=$base.$file;
|
2012-08-29 02:36:27 +04:00
|
|
|
if((!$dirOnly or OC_Filesystem::is_dir($item))) {
|
2011-07-12 19:45:01 +04:00
|
|
|
$files[]=(object)array('id'=>$item,'label'=>$item,'name'=>$item);
|
|
|
|
}
|
2011-05-28 21:31:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::encodedPrint($files);
|