File.php 2.2 KB

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