diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2015-03-03 12:52:27 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2015-03-11 16:37:42 +0100 |
commit | 1a0f9c375be12502d9b016c6bdb4c898ec765bbd (patch) | |
tree | 6b287f2d71e94740b364d17a5f23424d5f6668aa /lib | |
parent | cfaee93552b519b8e017e63fd5a82b1e5c9f951b (diff) | |
download | nextcloud-server-1a0f9c375be12502d9b016c6bdb4c898ec765bbd.tar.gz nextcloud-server-1a0f9c375be12502d9b016c6bdb4c898ec765bbd.zip |
Avatar controller moved to AppFrameWork
* Original avatarcontroller migrated to the appframework
* Added DataDisplayResponse that show data inline in the browser (used
to retrun the image)
* Removed some unneeded code
* Added unit tests for the avatarcontroller
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/avatar.php | 10 | ||||
-rw-r--r-- | lib/private/avatarmanager.php | 5 | ||||
-rw-r--r-- | lib/private/helper.php | 2 | ||||
-rw-r--r-- | lib/public/appframework/http/datadisplayresponse.php | 77 | ||||
-rw-r--r-- | lib/public/iavatar.php | 2 |
5 files changed, 89 insertions, 7 deletions
diff --git a/lib/private/avatar.php b/lib/private/avatar.php index 5e234d77bb2..23b3c82771a 100644 --- a/lib/private/avatar.php +++ b/lib/private/avatar.php @@ -6,11 +6,15 @@ * See the COPYING-README file. */ + namespace OC; + + use OC_Image; + /** * This class gets and sets users avatars. */ -class OC_Avatar implements \OCP\IAvatar { +class Avatar implements \OCP\IAvatar { private $view; @@ -54,8 +58,8 @@ class OC_Avatar implements \OCP\IAvatar { /** * sets the users avatar * @param \OC_Image|resource|string $data OC_Image, 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 \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 */ diff --git a/lib/private/avatarmanager.php b/lib/private/avatarmanager.php index 6abe87c4f41..8dc20a5240b 100644 --- a/lib/private/avatarmanager.php +++ b/lib/private/avatarmanager.php @@ -8,8 +8,9 @@ namespace OC; use OCP\IAvatarManager; +use OC\Avatar; -/* +/** * This class implements methods to access Avatar functionality */ class AvatarManager implements IAvatarManager { @@ -21,6 +22,6 @@ class AvatarManager implements IAvatarManager { * @return \OCP\IAvatar */ function getAvatar($user) { - return new \OC_Avatar($user); + return new Avatar($user); } } diff --git a/lib/private/helper.php b/lib/private/helper.php index fb7049854bb..ebc30395a6b 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -288,7 +288,7 @@ class OC_Helper { * @return bool avatar set or not **/ public static function userAvatarSet($user) { - $avatar = new \OC_Avatar($user); + $avatar = new \OC\Avatar($user); return $avatar->exists(); } diff --git a/lib/public/appframework/http/datadisplayresponse.php b/lib/public/appframework/http/datadisplayresponse.php new file mode 100644 index 00000000000..ebb77950c96 --- /dev/null +++ b/lib/public/appframework/http/datadisplayresponse.php @@ -0,0 +1,77 @@ +<?php +/** + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\AppFramework\Http; + +use OCP\AppFramework\Http; + +class DataDisplayResponse extends Response { + + /** + * response data + * @var string; + */ + protected $data; + + + /** + * @param string $data the data to display + * @param int $statusCode the Http status code, defaults to 200 + * @param array $headers additional key value based headers + */ + public function __construct($data="", $statusCode=Http::STATUS_OK, + $headers=[]) { + $this->data = $data; + $this->setStatus($statusCode); + $this->setHeaders(array_merge($this->getHeaders(), $headers)); + $this->addHeader('Content-Disposition', 'inline; filename=""'); + } + + /** + * Outputs data. No processing is done. + * @return string + */ + public function render() { + return $this->data; + } + + + /** + * Sets values in the data + * @param string $data the data to display + * @return DataDisplayResponse Reference to this object + */ + public function setData($data){ + $this->data = $data; + + return $this; + } + + + /** + * Used to get the set parameters + * @return string the data + */ + public function getData(){ + return $this->data; + } + +} diff --git a/lib/public/iavatar.php b/lib/public/iavatar.php index fdb044f9e5c..8f432c23fb8 100644 --- a/lib/public/iavatar.php +++ b/lib/public/iavatar.php @@ -29,7 +29,7 @@ interface IAvatar { /** * sets the users avatar - * @param Image $data mixed imagedata or path to set a new avatar + * @param \OC_Image|resource|string $data OC_Image, 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 |