summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBernhard Posselt <Raydiation@users.noreply.github.com>2013-09-14 16:00:36 -0700
committerBernhard Posselt <Raydiation@users.noreply.github.com>2013-09-14 16:00:36 -0700
commita58e176852d80dd23b9346b4f8bd676e9ca4d8ed (patch)
tree3f06e0ab511159221e915a6fdce8393b6192bfdb /lib
parenta0c2c2473a975893d590e779433091a3f7d6abb2 (diff)
parent86143beb6ae264e31e806dd195a04e5ed6f9f2d1 (diff)
downloadnextcloud-server-a58e176852d80dd23b9346b4f8bd676e9ca4d8ed.tar.gz
nextcloud-server-a58e176852d80dd23b9346b4f8bd676e9ca4d8ed.zip
Merge pull request #4506 from owncloud/oc_avatars
OC Avatars
Diffstat (limited to 'lib')
-rw-r--r--lib/avatar.php89
-rw-r--r--lib/base.php8
-rw-r--r--lib/installer.php1
-rw-r--r--lib/notsquareexception.php12
-rw-r--r--lib/templatelayout.php1
5 files changed, 111 insertions, 0 deletions
diff --git a/lib/avatar.php b/lib/avatar.php
new file mode 100644
index 00000000000..f20980c364b
--- /dev/null
+++ b/lib/avatar.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * This class gets and sets users avatars.
+ */
+
+class OC_Avatar {
+
+ private $view;
+
+ /**
+ * @brief constructor
+ * @param $user string user to do avatar-management with
+ */
+ public function __construct ($user) {
+ $this->view = new \OC\Files\View('/'.$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
+ */
+ public function get ($size = 64) {
+ if ($this->view->file_exists('avatar.jpg')) {
+ $ext = 'jpg';
+ } elseif ($this->view->file_exists('avatar.png')) {
+ $ext = 'png';
+ } else {
+ return false;
+ }
+
+ $avatar = new OC_Image();
+ $avatar->loadFromData($this->view->file_get_contents('avatar.'.$ext));
+ $avatar->resize($size);
+ return $avatar;
+ }
+
+ /**
+ * @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
+ */
+ public function set ($data) {
+ if (\OC_App::isEnabled('files_encryption')) {
+ $l = \OC_L10N::get('lib');
+ throw new \Exception($l->t("Custom profile pictures don't work with encryption yet"));
+ }
+
+ $img = new OC_Image($data);
+ $type = substr($img->mimeType(), -3);
+ if ($type === 'peg') { $type = 'jpg'; }
+ if ($type !== 'jpg' && $type !== 'png') {
+ $l = \OC_L10N::get('lib');
+ throw new \Exception($l->t("Unknown filetype"));
+ }
+
+ if (!$img->valid()) {
+ $l = \OC_L10N::get('lib');
+ throw new \Exception($l->t("Invalid image"));
+ }
+
+ if (!($img->height() === $img->width())) {
+ throw new \OC\NotSquareException();
+ }
+
+ $this->view->unlink('avatar.jpg');
+ $this->view->unlink('avatar.png');
+ $this->view->file_put_contents('avatar.'.$type, $data);
+ }
+
+ /**
+ * @brief remove the users avatar
+ * @return void
+ */
+ public function remove () {
+ $this->view->unlink('avatar.jpg');
+ $this->view->unlink('avatar.png');
+ }
+}
diff --git a/lib/base.php b/lib/base.php
index ea5adbadc9d..d3d570e3f37 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -266,6 +266,14 @@ class OC {
OC_Util::addScript('router');
OC_Util::addScript("oc-requesttoken");
+ // avatars
+ if (\OC_Config::getValue('enable_avatars', true) === true) {
+ \OC_Util::addScript('placeholder');
+ \OC_Util::addScript('3rdparty', 'md5/md5.min');
+ \OC_Util::addScript('jquery.avatar');
+ \OC_Util::addScript('avatar');
+ }
+
OC_Util::addStyle("styles");
OC_Util::addStyle("apps");
OC_Util::addStyle("fixes");
diff --git a/lib/installer.php b/lib/installer.php
index 607e6da7265..e082c7eeee9 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -428,6 +428,7 @@ class OC_Installer{
'OC_API::',
'OC_App::',
'OC_AppConfig::',
+ 'OC_Avatar',
'OC_BackgroundJob::',
'OC_Config::',
'OC_DB::',
diff --git a/lib/notsquareexception.php b/lib/notsquareexception.php
new file mode 100644
index 00000000000..03dba8fb25f
--- /dev/null
+++ b/lib/notsquareexception.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC;
+
+class NotSquareException extends \Exception {
+}
diff --git a/lib/templatelayout.php b/lib/templatelayout.php
index 0b868a39e49..625f3424a04 100644
--- a/lib/templatelayout.php
+++ b/lib/templatelayout.php
@@ -46,6 +46,7 @@ class OC_TemplateLayout extends OC_Template {
$user_displayname = OC_User::getDisplayName();
$this->assign( 'user_displayname', $user_displayname );
$this->assign( 'user_uid', OC_User::getUser() );
+ $this->assign('enableAvatars', \OC_Config::getValue('enable_avatars', true));
} else if ($renderas == 'guest' || $renderas == 'error') {
parent::__construct('core', 'layout.guest');
} else {