search.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  5. * @author Lukas Reschke <lukas@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <icewind@owncloud.com>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @copyright Copyright (c) 2016, ownCloud, Inc.
  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. // Check if we are a user
  27. \OCP\JSON::checkLoggedIn();
  28. \OCP\JSON::callCheck();
  29. \OC::$server->getSession()->close();
  30. if (isset($_GET['query'])) {
  31. $query = $_GET['query'];
  32. } else {
  33. $query = '';
  34. }
  35. if (isset($_GET['inApps'])) {
  36. $inApps = $_GET['inApps'];
  37. if (is_string($inApps)) {
  38. $inApps = array($inApps);
  39. }
  40. } else {
  41. $inApps = array();
  42. }
  43. if (isset($_GET['page'])) {
  44. $page = (int)$_GET['page'];
  45. } else {
  46. $page = 1;
  47. }
  48. if (isset($_GET['size'])) {
  49. $size = (int)$_GET['size'];
  50. } else {
  51. $size = 30;
  52. }
  53. if($query) {
  54. $result = \OC::$server->getSearch()->searchPaged($query, $inApps, $page, $size);
  55. OC_JSON::encodedPrint($result);
  56. }
  57. else {
  58. echo 'false';
  59. }