server/lib/search/provider/file.php
2012-09-24 19:24:20 +02:00

34 lines
1.2 KiB
PHP

<?php
class OC_Search_Provider_File extends OC_Search_Provider{
function search($query) {
$files=OC_FileCache::search($query,true);
$results=array();
foreach($files as $fileData) {
$file=$fileData['path'];
$mime=$fileData['mimetype'];
if($mime=='httpd/unix-directory') {
$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'index.php', array('dir' => $file)),'Files');
}else{
$mimeBase=$fileData['mimepart'];
switch($mimeBase) {
case 'audio':
break;
case 'text':
$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('file' => $file) ),'Text');
break;
case 'image':
$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('file' => $file) ),'Images');
break;
default:
if($mime=='application/xml') {
$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('file' => $file) ),'Text');
}else{
$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('file' => $file) ),'Files');
}
}
}
}
return $results;
}
}