backend.php 2.0 KB

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