file.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. class OC_Search_Provider_File extends OC_Search_Provider{
  3. function search($query) {
  4. $files=\OC\Files\Filesystem::search($query, true);
  5. $results=array();
  6. $l=OC_L10N::get('lib');
  7. foreach($files as $fileData) {
  8. $path = $fileData['path'];
  9. $mime = $fileData['mimetype'];
  10. $name = basename($path);
  11. $container = dirname($path);
  12. $text = '';
  13. $skip = false;
  14. if($mime=='httpd/unix-directory') {
  15. $link = OC_Helper::linkTo( 'files', 'index.php', array('dir' => $path));
  16. $type = (string)$l->t('Files');
  17. }else{
  18. $link = OC_Helper::linkToRoute( 'download', array('file' => $path));
  19. $mimeBase = $fileData['mimepart'];
  20. switch($mimeBase) {
  21. case 'audio':
  22. $skip = true;
  23. break;
  24. case 'text':
  25. $type = (string)$l->t('Text');
  26. break;
  27. case 'image':
  28. $type = (string)$l->t('Images');
  29. break;
  30. default:
  31. if($mime=='application/xml') {
  32. $type = (string)$l->t('Text');
  33. }else{
  34. $type = (string)$l->t('Files');
  35. }
  36. }
  37. }
  38. if(!$skip) {
  39. $results[] = new OC_Search_Result($name, $text, $link, $type, $container);
  40. }
  41. }
  42. return $results;
  43. }
  44. }