2011-07-29 19:03:53 +00:00
|
|
|
<?php
|
|
|
|
|
2012-04-14 09:29:44 +00:00
|
|
|
class OC_Search_Provider_File extends OC_Search_Provider{
|
2012-09-07 13:22:01 +00:00
|
|
|
function search($query) {
|
2012-10-26 21:05:02 +00:00
|
|
|
$files=\OC\Files\Filesystem::search($query, true);
|
2011-07-29 19:03:53 +00:00
|
|
|
$results=array();
|
2012-10-22 18:52:51 +00:00
|
|
|
$l=OC_L10N::get('lib');
|
2012-09-07 13:22:01 +00:00
|
|
|
foreach($files as $fileData) {
|
2012-09-28 19:14:59 +00:00
|
|
|
$path = $fileData['path'];
|
|
|
|
$mime = $fileData['mimetype'];
|
|
|
|
|
|
|
|
$name = basename($path);
|
2013-07-31 20:24:52 +00:00
|
|
|
$container = dirname($path);
|
2012-09-28 19:14:59 +00:00
|
|
|
$text = '';
|
2012-10-01 17:11:26 +00:00
|
|
|
$skip = false;
|
2012-09-07 13:22:01 +00:00
|
|
|
if($mime=='httpd/unix-directory') {
|
2012-09-28 19:14:59 +00:00
|
|
|
$link = OC_Helper::linkTo( 'files', 'index.php', array('dir' => $path));
|
2012-10-22 18:52:51 +00:00
|
|
|
$type = (string)$l->t('Files');
|
2011-07-29 19:03:53 +00:00
|
|
|
}else{
|
2012-09-28 20:19:37 +00:00
|
|
|
$link = OC_Helper::linkToRoute( 'download', array('file' => $path));
|
2012-09-28 19:14:59 +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':
|
2012-10-01 17:11:26 +00:00
|
|
|
$skip = true;
|
2011-07-31 00:20:34 +00:00
|
|
|
break;
|
2011-08-02 22:30:21 +00:00
|
|
|
case 'text':
|
2012-10-22 18:52:51 +00:00
|
|
|
$type = (string)$l->t('Text');
|
2011-08-02 22:30:21 +00:00
|
|
|
break;
|
2011-07-31 00:20:34 +00:00
|
|
|
case 'image':
|
2012-10-22 18:52:51 +00:00
|
|
|
$type = (string)$l->t('Images');
|
2011-07-31 00:20:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-09-07 13:22:01 +00:00
|
|
|
if($mime=='application/xml') {
|
2012-10-22 18:52:51 +00:00
|
|
|
$type = (string)$l->t('Text');
|
2011-08-02 22:30:21 +00:00
|
|
|
}else{
|
2012-10-22 18:52:51 +00:00
|
|
|
$type = (string)$l->t('Files');
|
2011-08-02 22:30:21 +00:00
|
|
|
}
|
2011-07-31 00:20:34 +00:00
|
|
|
}
|
2011-07-29 19:03:53 +00:00
|
|
|
}
|
2012-10-01 17:11:26 +00:00
|
|
|
if(!$skip) {
|
2013-07-31 20:24:52 +00:00
|
|
|
$results[] = new OC_Search_Result($name, $text, $link, $type, $container);
|
2012-10-01 17:11:26 +00:00
|
|
|
}
|
2011-07-29 19:03:53 +00:00
|
|
|
}
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
}
|