file.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @author Andrew Brown <andrew@casabrown.com>
  4. * @author Bart Visscher <bartv@thisnet.nl>
  5. * @author Jakob Sack <mail@jakobsack.de>
  6. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Search\Provider;
  26. use OC\Files\Filesystem;
  27. /**
  28. * Provide search results from the 'files' app
  29. */
  30. class File extends \OCP\Search\Provider {
  31. /**
  32. * Search for files and folders matching the given query
  33. * @param string $query
  34. * @return \OCP\Search\Result
  35. */
  36. function search($query) {
  37. $files = Filesystem::search($query);
  38. $results = array();
  39. // edit results
  40. foreach ($files as $fileData) {
  41. // skip versions
  42. if (strpos($fileData['path'], '_versions') === 0) {
  43. continue;
  44. }
  45. // skip top-level folder
  46. if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
  47. continue;
  48. }
  49. // create audio result
  50. if($fileData['mimepart'] === 'audio'){
  51. $result = new \OC\Search\Result\Audio($fileData);
  52. }
  53. // create image result
  54. elseif($fileData['mimepart'] === 'image'){
  55. $result = new \OC\Search\Result\Image($fileData);
  56. }
  57. // create folder result
  58. elseif($fileData['mimetype'] === 'httpd/unix-directory'){
  59. $result = new \OC\Search\Result\Folder($fileData);
  60. }
  61. // or create file result
  62. else{
  63. $result = new \OC\Search\Result\File($fileData);
  64. }
  65. // add to results
  66. $results[] = $result;
  67. }
  68. // return
  69. return $results;
  70. }
  71. }