You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

backend.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. class Test_Share_Backend implements OCP\Share_Backend {
  22. const FORMAT_SOURCE = 0;
  23. const FORMAT_TARGET = 1;
  24. const FORMAT_PERMISSIONS = 2;
  25. private $testItem1 = 'test.txt';
  26. private $testItem2 = 'share.txt';
  27. private $testId = 1;
  28. public function isValidSource($itemSource, $uidOwner) {
  29. if ($itemSource == $this->testItem1 || $itemSource == $this->testItem2 || $itemSource == 1) {
  30. return true;
  31. }
  32. }
  33. public function generateTarget($itemSource, $shareWith, $exclude = null) {
  34. // Always make target be test.txt to cause conflicts
  35. if (substr($itemSource, 0, strlen('test')) !== 'test') {
  36. $target = "test.txt";
  37. } else {
  38. $target = $itemSource;
  39. }
  40. $shares = \OCP\Share::getItemsSharedWithUser('test', $shareWith);
  41. $knownTargets = array();
  42. foreach ($shares as $share) {
  43. $knownTargets[] = $share['item_target'];
  44. }
  45. if (in_array($target, $knownTargets)) {
  46. $pos = strrpos($target, '.');
  47. $name = substr($target, 0, $pos);
  48. $ext = substr($target, $pos);
  49. $append = '';
  50. $i = 1;
  51. while (in_array($name.$append.$ext, $knownTargets)) {
  52. $append = $i;
  53. $i++;
  54. }
  55. $target = $name.$append.$ext;
  56. }
  57. return $target;
  58. }
  59. public function formatItems($items, $format, $parameters = null) {
  60. $testItems = array();
  61. foreach ($items as $item) {
  62. if ($format === self::FORMAT_SOURCE) {
  63. $testItems[] = $item['item_source'];
  64. } else if ($format === self::FORMAT_TARGET) {
  65. $testItems[] = $item['item_target'];
  66. } else if ($format === self::FORMAT_PERMISSIONS) {
  67. $testItems[] = $item['permissions'];
  68. }
  69. }
  70. return $testItems;
  71. }
  72. }