avatarmanager.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  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 Thomas Müller <thomas.mueller@tmit.eu>
  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 OC;
  28. use OCP\Files\Folder;
  29. use OCP\Files\NotFoundException;
  30. use OCP\IAvatarManager;
  31. use OCP\ILogger;
  32. use OCP\IUserManager;
  33. use OCP\Files\IRootFolder;
  34. use OCP\IL10N;
  35. /**
  36. * This class implements methods to access Avatar functionality
  37. */
  38. class AvatarManager implements IAvatarManager {
  39. /** @var IUserManager */
  40. private $userManager;
  41. /** @var IRootFolder */
  42. private $rootFolder;
  43. /** @var IL10N */
  44. private $l;
  45. /** @var ILogger */
  46. private $logger;
  47. /**
  48. * AvatarManager constructor.
  49. *
  50. * @param IUserManager $userManager
  51. * @param IRootFolder $rootFolder
  52. * @param IL10N $l
  53. * @param ILogger $logger
  54. */
  55. public function __construct(
  56. IUserManager $userManager,
  57. IRootFolder $rootFolder,
  58. IL10N $l,
  59. ILogger $logger) {
  60. $this->userManager = $userManager;
  61. $this->rootFolder = $rootFolder;
  62. $this->l = $l;
  63. $this->logger = $logger;
  64. }
  65. /**
  66. * return a user specific instance of \OCP\IAvatar
  67. * @see \OCP\IAvatar
  68. * @param string $userId the ownCloud user id
  69. * @return \OCP\IAvatar
  70. * @throws \Exception In case the username is potentially dangerous
  71. * @throws NotFoundException In case there is no user folder yet
  72. */
  73. public function getAvatar($userId) {
  74. $user = $this->userManager->get($userId);
  75. if (is_null($user)) {
  76. throw new \Exception('user does not exist');
  77. }
  78. /*
  79. * Fix for #22119
  80. * Basically we do not want to copy the skeleton folder
  81. */
  82. \OC\Files\Filesystem::initMountPoints($userId);
  83. $dir = '/' . $userId;
  84. /** @var Folder $folder */
  85. $folder = $this->rootFolder->get($dir);
  86. return new Avatar($folder, $this->l, $user, $this->logger);
  87. }
  88. }