nextcloud/lib/private/search/provider/file.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2011-07-29 23:03:53 +04:00
<?php
class OC_Search_Provider_File extends OC_Search_Provider{
2012-09-07 17:22:01 +04:00
function search($query) {
2012-10-27 01:05:02 +04:00
$files=\OC\Files\Filesystem::search($query, true);
2011-07-29 23:03:53 +04:00
$results=array();
$l=OC_L10N::get('lib');
2012-09-07 17:22:01 +04:00
foreach($files as $fileData) {
$path = $fileData['path'];
$mime = $fileData['mimetype'];
$name = basename($path);
$container = dirname($path);
$text = '';
$skip = false;
2012-09-07 17:22:01 +04:00
if($mime=='httpd/unix-directory') {
$link = OC_Helper::linkTo( 'files', 'index.php', array('dir' => $path));
$type = (string)$l->t('Files');
2011-07-29 23:03:53 +04:00
}else{
$link = OC_Helper::linkToRoute( 'download', array('file' => $path));
$mimeBase = $fileData['mimepart'];
2012-09-07 17:22:01 +04:00
switch($mimeBase) {
2011-07-31 04:20:34 +04:00
case 'audio':
$skip = true;
2011-07-31 04:20:34 +04:00
break;
case 'text':
$type = (string)$l->t('Text');
break;
2011-07-31 04:20:34 +04:00
case 'image':
$type = (string)$l->t('Images');
2011-07-31 04:20:34 +04:00
break;
default:
2012-09-07 17:22:01 +04:00
if($mime=='application/xml') {
$type = (string)$l->t('Text');
}else{
$type = (string)$l->t('Files');
}
2011-07-31 04:20:34 +04:00
}
2011-07-29 23:03:53 +04:00
}
if(!$skip) {
$results[] = new OC_Search_Result($name, $text, $link, $type, $container);
}
2011-07-29 23:03:53 +04:00
}
return $results;
}
}