server/lib/search/provider/file.php

35 lines
1.2 KiB
PHP
Raw Normal View History

2011-07-29 19:03:53 +00:00
<?php
class OC_Search_Provider_File extends OC_Search_Provider{
2012-09-07 13:22:01 +00:00
function search($query) {
2012-01-31 15:12:49 +00:00
$files=OC_FileCache::search($query,true);
2011-07-29 19:03:53 +00:00
$results=array();
2012-09-07 13:22:01 +00:00
foreach($files as $fileData) {
2012-01-31 15:12:49 +00:00
$file=$fileData['path'];
$mime=$fileData['mimetype'];
2012-09-07 13:22:01 +00:00
if($mime=='httpd/unix-directory') {
$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'index.php', array('dir' => $file)),'Files');
2011-07-29 19:03:53 +00:00
}else{
2012-01-31 15:12:49 +00:00
$mimeBase=$fileData['mimepart'];
2012-09-07 13:22:01 +00:00
switch($mimeBase) {
2011-07-31 00:20:34 +00:00
case 'audio':
break;
case 'text':
$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('file' => $file) ),'Text');
break;
2011-07-31 00:20:34 +00:00
case 'image':
$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('file' => $file) ),'Images');
2011-07-31 00:20:34 +00:00
break;
default:
2012-09-07 13:22:01 +00:00
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');
}
2011-07-31 00:20:34 +00:00
}
2011-07-29 19:03:53 +00:00
}
}
return $results;
}
}