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.

Helper.php 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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. namespace OCA\Files_Sharing;
  28. use OC\Files\Filesystem;
  29. use OC\Files\View;
  30. class Helper {
  31. public static function registerHooks() {
  32. \OCP\Util::connectHook('OC_Filesystem', 'post_rename', '\OCA\Files_Sharing\Updater', 'renameHook');
  33. \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren');
  34. \OCP\Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Files_Sharing\Hooks', 'deleteUser');
  35. }
  36. /**
  37. * check if file name already exists and generate unique target
  38. *
  39. * @param string $path
  40. * @param array $excludeList
  41. * @param View $view
  42. * @return string $path
  43. */
  44. public static function generateUniqueTarget($path, $excludeList, $view) {
  45. $pathinfo = pathinfo($path);
  46. $ext = isset($pathinfo['extension']) ? '.'.$pathinfo['extension'] : '';
  47. $name = $pathinfo['filename'];
  48. $dir = $pathinfo['dirname'];
  49. $i = 2;
  50. while ($view->file_exists($path) || in_array($path, $excludeList)) {
  51. $path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext);
  52. $i++;
  53. }
  54. return $path;
  55. }
  56. /**
  57. * get default share folder
  58. *
  59. * @param \OC\Files\View $view
  60. * @return string
  61. */
  62. public static function getShareFolder($view = null) {
  63. if ($view === null) {
  64. $view = Filesystem::getView();
  65. }
  66. $shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/');
  67. $shareFolder = Filesystem::normalizePath($shareFolder);
  68. if (!$view->file_exists($shareFolder)) {
  69. $dir = '';
  70. $subdirs = explode('/', $shareFolder);
  71. foreach ($subdirs as $subdir) {
  72. $dir = $dir . '/' . $subdir;
  73. if (!$view->is_dir($dir)) {
  74. $view->mkdir($dir);
  75. }
  76. }
  77. }
  78. return $shareFolder;
  79. }
  80. /**
  81. * set default share folder
  82. *
  83. * @param string $shareFolder
  84. */
  85. public static function setShareFolder($shareFolder) {
  86. \OC::$server->getConfig()->setSystemValue('share_folder', $shareFolder);
  87. }
  88. }