AvatarManager.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\IConfig;
  32. use OCP\ILogger;
  33. use OCP\IUserManager;
  34. use OCP\Files\IRootFolder;
  35. use OCP\IL10N;
  36. /**
  37. * This class implements methods to access Avatar functionality
  38. */
  39. class AvatarManager implements IAvatarManager {
  40. /** @var IUserManager */
  41. private $userManager;
  42. /** @var IRootFolder */
  43. private $rootFolder;
  44. /** @var IL10N */
  45. private $l;
  46. /** @var ILogger */
  47. private $logger;
  48. /** @var IConfig */
  49. private $config;
  50. /**
  51. * AvatarManager constructor.
  52. *
  53. * @param IUserManager $userManager
  54. * @param IRootFolder $rootFolder
  55. * @param IL10N $l
  56. * @param ILogger $logger
  57. * @param IConfig $config
  58. */
  59. public function __construct(
  60. IUserManager $userManager,
  61. IRootFolder $rootFolder,
  62. IL10N $l,
  63. ILogger $logger,
  64. IConfig $config) {
  65. $this->userManager = $userManager;
  66. $this->rootFolder = $rootFolder;
  67. $this->l = $l;
  68. $this->logger = $logger;
  69. $this->config = $config;
  70. }
  71. /**
  72. * return a user specific instance of \OCP\IAvatar
  73. * @see \OCP\IAvatar
  74. * @param string $userId the ownCloud user id
  75. * @return \OCP\IAvatar
  76. * @throws \Exception In case the username is potentially dangerous
  77. * @throws NotFoundException In case there is no user folder yet
  78. */
  79. public function getAvatar($userId) {
  80. $user = $this->userManager->get($userId);
  81. if (is_null($user)) {
  82. throw new \Exception('user does not exist');
  83. }
  84. /*
  85. * Fix for #22119
  86. * Basically we do not want to copy the skeleton folder
  87. */
  88. \OC\Files\Filesystem::initMountPoints($userId);
  89. $dir = '/' . $userId;
  90. /** @var Folder $folder */
  91. $folder = $this->rootFolder->get($dir);
  92. return new Avatar($folder, $this->l, $user, $this->logger, $this->config);
  93. }
  94. }