1
0

Backend.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Michael Gapczynski
  6. * @copyright 2012 Michael Gapczynski mtgap@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. namespace Test\Share;
  22. class Backend implements \OCP\Share_Backend {
  23. public const FORMAT_SOURCE = 0;
  24. public const FORMAT_TARGET = 1;
  25. public const FORMAT_PERMISSIONS = 2;
  26. private $testItem1 = 'test.txt';
  27. private $testItem2 = 'share.txt';
  28. private $testId = 1;
  29. public function isValidSource($itemSource, $uidOwner) {
  30. if ($itemSource == $this->testItem1 || $itemSource == $this->testItem2 || $itemSource == 1) {
  31. return true;
  32. }
  33. }
  34. public function generateTarget($itemSource, $shareWith, $exclude = null) {
  35. // Always make target be test.txt to cause conflicts
  36. if (substr($itemSource, 0, strlen('test')) !== 'test') {
  37. $target = "test.txt";
  38. } else {
  39. $target = $itemSource;
  40. }
  41. $shares = \OC\Share\Share::getItemsSharedWithUser('test', $shareWith);
  42. $knownTargets = [];
  43. foreach ($shares as $share) {
  44. $knownTargets[] = $share['item_target'];
  45. }
  46. if (in_array($target, $knownTargets)) {
  47. $pos = strrpos($target, '.');
  48. $name = substr($target, 0, $pos);
  49. $ext = substr($target, $pos);
  50. $append = '';
  51. $i = 1;
  52. while (in_array($name.$append.$ext, $knownTargets)) {
  53. $append = $i;
  54. $i++;
  55. }
  56. $target = $name.$append.$ext;
  57. }
  58. return $target;
  59. }
  60. public function formatItems($items, $format, $parameters = null) {
  61. $testItems = [];
  62. foreach ($items as $item) {
  63. if ($format === self::FORMAT_SOURCE) {
  64. $testItems[] = $item['item_source'];
  65. } elseif ($format === self::FORMAT_TARGET) {
  66. $testItems[] = $item['item_target'];
  67. } elseif ($format === self::FORMAT_PERMISSIONS) {
  68. $testItems[] = $item['permissions'];
  69. }
  70. }
  71. return $testItems;
  72. }
  73. public function isShareTypeAllowed($shareType) {
  74. return true;
  75. }
  76. }