summaryrefslogtreecommitdiffstats
path: root/lib/search/provider/file.php
blob: 5fd35fa3e523416bba7d2eb647297b2845a185b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

class OC_Search_Provider_File extends OC_Search_Provider{
	function search($query){
		$files=OC_Filesystem::search($query);
		$results=array();
		foreach($files as $file){
			if(OC_Filesystem::is_dir($file)){
				$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'index.php?dir='.$file ),'Files');
			}else{
				$mime=OC_Filesystem::getMimeType($file);
				$mimeBase=substr($mime,0,strpos($mime,'/'));
				switch($mimeBase){
					case 'audio':
						break;
					case 'text':
						$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Text');
						break;
					case 'image':
						$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Images');
						break;
					default:
						if($mime=='application/xml'){
							$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Text');
						}else{
							$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Files');
						}
				}
			}
		}
		return $results;
	}
}