IAvatar.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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 OCP;
  28. use OCP\Files\NotFoundException;
  29. use OCP\Files\SimpleFS\ISimpleFile;
  30. /**
  31. * This class provides avatar functionality
  32. * @since 6.0.0
  33. */
  34. interface IAvatar {
  35. /**
  36. * Get the users avatar
  37. *
  38. * @param int $size size in px of the avatar, avatars are square, defaults to 64, -1 can be used to not scale the image
  39. * @param bool $darkTheme Should the generated avatar be dark themed
  40. * @return false|\OCP\IImage containing the avatar or false if there's no image
  41. * @since 6.0.0 - size of -1 was added in 9.0.0
  42. */
  43. public function get(int $size = 64, bool $darkTheme = false);
  44. /**
  45. * Check if an avatar exists for the user
  46. *
  47. * @since 8.1.0
  48. */
  49. public function exists(): bool;
  50. /**
  51. * Check if the avatar of a user is a custom uploaded one
  52. *
  53. * @since 14.0.0
  54. */
  55. public function isCustomAvatar(): bool;
  56. /**
  57. * Sets the users avatar
  58. *
  59. * @param \OCP\IImage|resource|string $data An image object, imagedata or path to set a new avatar
  60. * @throws \Exception if the provided file is not a jpg or png image
  61. * @throws \Exception if the provided image is not valid
  62. * @throws \OC\NotSquareException if the image is not square
  63. * @since 6.0.0
  64. */
  65. public function set($data): void;
  66. /**
  67. * Remove the user's avatar
  68. *
  69. * @param bool $silent Whether removing the avatar should trigger a change
  70. * @since 6.0.0
  71. */
  72. public function remove(bool $silent = false): void;
  73. /**
  74. * Get the file of the avatar
  75. *
  76. * @param int $size The desired image size. -1 can be used to not scale the image
  77. * @param bool $darkTheme Should the generated avatar be dark themed
  78. * @throws NotFoundException
  79. * @since 9.0.0
  80. */
  81. public function getFile(int $size, bool $darkTheme = false): ISimpleFile;
  82. /**
  83. * Get the avatar background color
  84. *
  85. * @since 14.0.0
  86. */
  87. public function avatarBackgroundColor(string $hash): Color;
  88. /**
  89. * Updates the display name if changed.
  90. *
  91. * @param string $feature The changed feature
  92. * @param mixed $oldValue The previous value
  93. * @param mixed $newValue The new value
  94. * @since 13.0.0
  95. */
  96. public function userChanged(string $feature, $oldValue, $newValue): void;
  97. }