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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Vincent Petry <pvince81@owncloud.com>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OCA\Files_Sharing;
  29. use OC\Files\Filesystem;
  30. use OC\Files\View;
  31. class Helper {
  32. public static function registerHooks() {
  33. \OCP\Util::connectHook('OC_Filesystem', 'post_rename', '\OCA\Files_Sharing\Updater', 'renameHook');
  34. \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren');
  35. \OCP\Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Files_Sharing\Hooks', 'deleteUser');
  36. }
  37. /**
  38. * check if file name already exists and generate unique target
  39. *
  40. * @param string $path
  41. * @param array $excludeList
  42. * @param View $view
  43. * @return string $path
  44. */
  45. public static function generateUniqueTarget($path, $excludeList, $view) {
  46. $pathinfo = pathinfo($path);
  47. $ext = isset($pathinfo['extension']) ? '.'.$pathinfo['extension'] : '';
  48. $name = $pathinfo['filename'];
  49. $dir = $pathinfo['dirname'];
  50. $i = 2;
  51. while ($view->file_exists($path) || in_array($path, $excludeList)) {
  52. $path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext);
  53. $i++;
  54. }
  55. return $path;
  56. }
  57. /**
  58. * get default share folder
  59. *
  60. * @param \OC\Files\View $view
  61. * @return string
  62. */
  63. public static function getShareFolder($view = null) {
  64. if ($view === null) {
  65. $view = Filesystem::getView();
  66. }
  67. $shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/');
  68. $shareFolder = Filesystem::normalizePath($shareFolder);
  69. if (!$view->file_exists($shareFolder)) {
  70. $dir = '';
  71. $subdirs = explode('/', $shareFolder);
  72. foreach ($subdirs as $subdir) {
  73. $dir = $dir . '/' . $subdir;
  74. if (!$view->is_dir($dir)) {
  75. $view->mkdir($dir);
  76. }
  77. }
  78. }
  79. return $shareFolder;
  80. }
  81. /**
  82. * set default share folder
  83. *
  84. * @param string $shareFolder
  85. */
  86. public static function setShareFolder($shareFolder) {
  87. \OC::$server->getConfig()->setSystemValue('share_folder', $shareFolder);
  88. }
  89. }