diff options
author | blizzz <blizzz@owncloud.com> | 2013-11-22 03:42:28 -0800 |
---|---|---|
committer | blizzz <blizzz@owncloud.com> | 2013-11-22 03:42:28 -0800 |
commit | 2f73db12bb5de852485b550b11c65d3205792cf7 (patch) | |
tree | cea96b485e82d75f24796f238f181465d2952d88 /lib | |
parent | 60cfdae50399c362edee204cb6849db8203a63b0 (diff) | |
parent | 92c8672c0f4cae5881abdb4832955e3fa6ae6350 (diff) | |
download | nextcloud-server-2f73db12bb5de852485b550b11c65d3205792cf7.tar.gz nextcloud-server-2f73db12bb5de852485b550b11c65d3205792cf7.zip |
Merge pull request #5040 from owncloud/public_api_avatar_master
Add public API for \OC\Avatar
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/avatar.php | 8 | ||||
-rw-r--r-- | lib/private/avatarmanager.php | 26 | ||||
-rw-r--r-- | lib/private/server.php | 12 | ||||
-rw-r--r-- | lib/public/iavatar.php | 38 | ||||
-rw-r--r-- | lib/public/iavatarmanager.php | 23 | ||||
-rw-r--r-- | lib/public/iservercontainer.php | 6 |
6 files changed, 110 insertions, 3 deletions
diff --git a/lib/private/avatar.php b/lib/private/avatar.php index 720740569df..814a9b22bed 100644 --- a/lib/private/avatar.php +++ b/lib/private/avatar.php @@ -10,7 +10,7 @@ * This class gets and sets users avatars. */ -class OC_Avatar { +class OC_Avatar implements \OCP\IAvatar { private $view; @@ -24,7 +24,7 @@ class OC_Avatar { /** * @brief get the users avatar - * @param $size integer size in px of the avatar, defaults to 64 + * @param $size integer size in px of the avatar, avatars are square, defaults to 64 * @return boolean|\OC_Image containing the avatar or false if there's no image */ public function get ($size = 64) { @@ -54,7 +54,9 @@ class OC_Avatar { $img = new OC_Image($data); $type = substr($img->mimeType(), -3); - if ($type === 'peg') { $type = 'jpg'; } + if ($type === 'peg') { + $type = 'jpg'; + } if ($type !== 'jpg' && $type !== 'png') { $l = \OC_L10N::get('lib'); throw new \Exception($l->t("Unknown filetype")); diff --git a/lib/private/avatarmanager.php b/lib/private/avatarmanager.php new file mode 100644 index 00000000000..3ca46868ea6 --- /dev/null +++ b/lib/private/avatarmanager.php @@ -0,0 +1,26 @@ +<?php +/** + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC; + +use OCP\IAvatarManager; + +/* + * This class implements methods to access Avatar functionality + */ +class AvatarManager implements IAvatarManager { + + /** + * @brief return a user specific instance of \OCP\IAvatar + * @see \OCP\IAvatar + * @param $user string the ownCloud user id + * @return \OCP\IAvatar + */ + function getAvatar($user) { + return new \OC_Avatar($user); + } +} diff --git a/lib/private/server.php b/lib/private/server.php index 65899f3007e..77c3732a9ca 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -131,6 +131,9 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('ActivityManager', function($c) { return new ActivityManager(); }); + $this->registerService('AvatarManager', function($c) { + return new AvatarManager(); + }); } /** @@ -171,6 +174,15 @@ class Server extends SimpleContainer implements IServerContainer { } /** + * Returns the avatar manager, used for avatar functionality + * + * @return \OCP\IAvatarManager + */ + function getAvatarManager() { + return $this->query('AvatarManager'); + } + + /** * Returns the root folder of ownCloud's data directory * * @return \OCP\Files\Folder diff --git a/lib/public/iavatar.php b/lib/public/iavatar.php new file mode 100644 index 00000000000..2cbec0d45c3 --- /dev/null +++ b/lib/public/iavatar.php @@ -0,0 +1,38 @@ +<?php +/** + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +/** + * This class provides avatar functionality + */ + +interface IAvatar { + + /** + * @brief get the users avatar + * @param $size integer size in px of the avatar, avatars are square, defaults to 64 + * @return boolean|\OC_Image containing the avatar or false if there's no image + */ + function get($size = 64); + + /** + * @brief sets the users avatar + * @param $data mixed imagedata or path to set a new avatar + * @throws Exception if the provided file is not a jpg or png image + * @throws Exception if the provided image is not valid + * @throws \OCP\NotSquareException if the image is not square + * @return void + */ + function set($data); + + /** + * @brief remove the users avatar + * @return void + */ + function remove(); +} diff --git a/lib/public/iavatarmanager.php b/lib/public/iavatarmanager.php new file mode 100644 index 00000000000..9b185ae0467 --- /dev/null +++ b/lib/public/iavatarmanager.php @@ -0,0 +1,23 @@ +<?php +/** + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +/** + * This class provides avatar functionality + */ + +interface IAvatarManager { + + /** + * @brief return a user specific instance of \OCP\IAvatar + * @see \OCP\IAvatar + * @param $user string the ownCloud user id + * @return \OCP\IAvatar + */ + function getAvatar($user); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 14822817a47..36296a59850 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -154,4 +154,10 @@ interface IServerContainer { */ function getDatabaseConnection(); + /** + * @brief Returns an avatar manager, used for avatar functionality + * @return \OCP\IAvatarManager + */ + function getAvatarManager(); + } |