File.php 2.1 KB

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