getVersions.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Frank Karlitschek <frank@karlitschek.de>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Sam Tuke <mail@samtuke.com>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  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. \OC_JSON::checkLoggedIn();
  28. \OC_JSON::callCheck();
  29. \OC_JSON::checkAppEnabled('files_versions');
  30. $source = (string)$_GET['source'];
  31. $start = (int)$_GET['start'];
  32. list ($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($source);
  33. $count = 5; //show the newest revisions
  34. $versions = OCA\Files_Versions\Storage::getVersions($uid, $filename, $source);
  35. if( $versions ) {
  36. $endReached = false;
  37. if (count($versions) <= $start+$count) {
  38. $endReached = true;
  39. }
  40. $versions = array_slice($versions, $start, $count);
  41. // remove owner path from request to not disclose it to the recipient
  42. foreach ($versions as $version) {
  43. unset($version['path']);
  44. }
  45. \OC_JSON::success(array('data' => array('versions' => $versions, 'endReached' => $endReached)));
  46. } else {
  47. \OC_JSON::success(array('data' => array('versions' => [], 'endReached' => true)));
  48. }