From 507325dd501c89972d5c820bcfefb3aab8b81e34 Mon Sep 17 00:00:00 2001 From: kondou Date: Fri, 20 Sep 2013 11:46:11 +0200 Subject: [PATCH 1/6] Add public API for \OC\Avatar --- lib/avatarmanager.php | 55 +++++++++++++++++++++++++++++++++ lib/private/avatar.php | 2 +- lib/private/server.php | 23 +++++++++++++- lib/public/iavatarmanager.php | 38 +++++++++++++++++++++++ lib/public/iservercontainer.php | 6 ++++ 5 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 lib/avatarmanager.php create mode 100644 lib/public/iavatarmanager.php diff --git a/lib/avatarmanager.php b/lib/avatarmanager.php new file mode 100644 index 0000000000..51481e412d --- /dev/null +++ b/lib/avatarmanager.php @@ -0,0 +1,55 @@ +avatar = new \OC\Avatar($user); + } + + /** + * @brief get the users avatar + * @param $size integer size in px of the avatar, defaults to 64 + * @return boolean|\OC_Image containing the avatar or false if there's no image + */ + function get($size = 64) { + $this->avatar->get($size); + } + + /** + * @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 \OC\NotSquareException if the image is not square + * @return void + */ + function set($data) { + $this->avatar->set($data); + } + + /** + * @brief remove the users avatar + * @return void + */ + function remove() { + $this->avatar->remove(); + } +} diff --git a/lib/private/avatar.php b/lib/private/avatar.php index 720740569d..e9b02a7d34 100644 --- a/lib/private/avatar.php +++ b/lib/private/avatar.php @@ -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) { diff --git a/lib/private/server.php b/lib/private/server.php index 65899f3007..65542d19ab 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -56,7 +56,7 @@ class Server extends SimpleContainer implements IServerContainer { }); $this->registerService('TagManager', function($c) { $user = \OC_User::getUser(); - return new TagManager($user); + return new Tags($user); }); $this->registerService('RootFolder', function($c) { // TODO: get user and user manager from container as well @@ -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(); //TODO AvatarManager needs $user + }); } /** @@ -160,6 +163,15 @@ class Server extends SimpleContainer implements IServerContainer { return $this->query('PreviewManager'); } + /** + * Returns the avatar manager, used for avatar functionality + * + * @return \OCP\IAvatar + */ + function getAvatarManager() { + return $this->query('AvatarManager'); + } + /** * Returns the tag manager which can get and set tags for different object types * @@ -170,6 +182,15 @@ class Server extends SimpleContainer implements IServerContainer { return $this->query('TagManager'); } + /** + * Returns the avatar manager, used for avatar functionality + * + * @return \OCP\IAvatar + */ + function getAvatarManager() { + return $this->query('AvatarManager'); + } + /** * Returns the root folder of ownCloud's data directory * diff --git a/lib/public/iavatarmanager.php b/lib/public/iavatarmanager.php new file mode 100644 index 0000000000..818dbb124a --- /dev/null +++ b/lib/public/iavatarmanager.php @@ -0,0 +1,38 @@ + Date: Mon, 30 Sep 2013 22:25:01 +0200 Subject: [PATCH 2/6] Remove duplicate getAvatarManager() --- lib/private/server.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/private/server.php b/lib/private/server.php index 65542d19ab..ec0703cce3 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -163,15 +163,6 @@ class Server extends SimpleContainer implements IServerContainer { return $this->query('PreviewManager'); } - /** - * Returns the avatar manager, used for avatar functionality - * - * @return \OCP\IAvatar - */ - function getAvatarManager() { - return $this->query('AvatarManager'); - } - /** * Returns the tag manager which can get and set tags for different object types * From bcd776b0c0480291c793c89ba36477163c9e4249 Mon Sep 17 00:00:00 2001 From: kondou Date: Thu, 7 Nov 2013 12:51:03 +0100 Subject: [PATCH 3/6] =?UTF-8?q?Fix=20a=20regression=20(Tags=E2=86=92TagMan?= =?UTF-8?q?ager)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/private/server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/server.php b/lib/private/server.php index ec0703cce3..7711269acf 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -56,7 +56,7 @@ class Server extends SimpleContainer implements IServerContainer { }); $this->registerService('TagManager', function($c) { $user = \OC_User::getUser(); - return new Tags($user); + return new TagManager($user); }); $this->registerService('RootFolder', function($c) { // TODO: get user and user manager from container as well From 00071401d7c16e700becf5447bebdc70441736ea Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 21 Nov 2013 23:40:25 +0100 Subject: [PATCH 4/6] Round out Avatar Public API --- lib/avatarmanager.php | 55 ----------------------------------- lib/private/avatar.php | 2 +- lib/private/avatarmanager.php | 26 +++++++++++++++++ lib/public/iavatarmanager.php | 25 ++++------------ tests/lib/avatar.php | 15 ++++++++++ 5 files changed, 47 insertions(+), 76 deletions(-) delete mode 100644 lib/avatarmanager.php create mode 100644 lib/private/avatarmanager.php diff --git a/lib/avatarmanager.php b/lib/avatarmanager.php deleted file mode 100644 index 51481e412d..0000000000 --- a/lib/avatarmanager.php +++ /dev/null @@ -1,55 +0,0 @@ -avatar = new \OC\Avatar($user); - } - - /** - * @brief get the users avatar - * @param $size integer size in px of the avatar, defaults to 64 - * @return boolean|\OC_Image containing the avatar or false if there's no image - */ - function get($size = 64) { - $this->avatar->get($size); - } - - /** - * @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 \OC\NotSquareException if the image is not square - * @return void - */ - function set($data) { - $this->avatar->set($data); - } - - /** - * @brief remove the users avatar - * @return void - */ - function remove() { - $this->avatar->remove(); - } -} diff --git a/lib/private/avatar.php b/lib/private/avatar.php index e9b02a7d34..e82e517b09 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; diff --git a/lib/private/avatarmanager.php b/lib/private/avatarmanager.php new file mode 100644 index 0000000000..3ca46868ea --- /dev/null +++ b/lib/private/avatarmanager.php @@ -0,0 +1,26 @@ +remove(); $this->assertEquals(false, $avatar->get()); } + + public function testAvatarApi() { + $avatarManager = \OC::$server->getAvatarManager(); + $avatar = $avatarManager->getAvatar(\OC_User::getUser()); + + $this->assertEquals(false, $avatar->get()); + + $expected = new OC_Image(\OC::$SERVERROOT.'/tests/data/testavatar.png'); + $expected->resize(64); + $avatar->set($expected->data()); + $this->assertEquals($expected->data(), $avatar->get()->data()); + + $avatar->remove(); + $this->assertEquals(false, $avatar->get()); + } } From f94a6eb1669cbdae45ccd76ecc4c07988ecddecf Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 22 Nov 2013 00:43:23 +0100 Subject: [PATCH 5/6] Add missing Avatar Interface --- lib/public/iavatar.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/public/iavatar.php diff --git a/lib/public/iavatar.php b/lib/public/iavatar.php new file mode 100644 index 0000000000..2cbec0d45c --- /dev/null +++ b/lib/public/iavatar.php @@ -0,0 +1,38 @@ + Date: Fri, 22 Nov 2013 12:34:37 +0100 Subject: [PATCH 6/6] fixing PHPDoc comments and syntax --- lib/private/avatar.php | 4 +++- lib/private/server.php | 4 ++-- lib/public/iservercontainer.php | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/private/avatar.php b/lib/private/avatar.php index e82e517b09..814a9b22be 100644 --- a/lib/private/avatar.php +++ b/lib/private/avatar.php @@ -54,7 +54,9 @@ class OC_Avatar implements \OCP\IAvatar { $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/server.php b/lib/private/server.php index 7711269acf..77c3732a9c 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -132,7 +132,7 @@ class Server extends SimpleContainer implements IServerContainer { return new ActivityManager(); }); $this->registerService('AvatarManager', function($c) { - return new AvatarManager(); //TODO AvatarManager needs $user + return new AvatarManager(); }); } @@ -176,7 +176,7 @@ class Server extends SimpleContainer implements IServerContainer { /** * Returns the avatar manager, used for avatar functionality * - * @return \OCP\IAvatar + * @return \OCP\IAvatarManager */ function getAvatarManager() { return $this->query('AvatarManager'); diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 6556b52c3b..36296a5985 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -156,7 +156,7 @@ interface IServerContainer { /** * @brief Returns an avatar manager, used for avatar functionality - * @return \OCP\IAvatar + * @return \OCP\IAvatarManager */ function getAvatarManager();