summaryrefslogtreecommitdiffstats
path: root/lib/private/avatar.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/avatar.php')
-rw-r--r--lib/private/avatar.php61
1 files changed, 35 insertions, 26 deletions
diff --git a/lib/private/avatar.php b/lib/private/avatar.php
index 90a8b8c26f9..872da35f947 100644
--- a/lib/private/avatar.php
+++ b/lib/private/avatar.php
@@ -29,7 +29,9 @@
namespace OC;
-use OC\Files\Filesystem;
+use OCP\Files\Folder;
+use OCP\Files\File;
+use OCP\IL10N;
use OC_Image;
/**
@@ -37,19 +39,21 @@ use OC_Image;
*/
class Avatar implements \OCP\IAvatar {
- /** @var Files\View */
- private $view;
+ /** @var Folder */
+ private $folder;
+
+ /** @var IL10N */
+ private $l;
/**
* constructor
- * @param string $user user to do avatar-management with
- * @throws \Exception In case the username is potentially dangerous
+ *
+ * @param Folder $folder The folder where the avatars are
+ * @param IL10N $l
*/
- public function __construct ($user) {
- if(!Filesystem::isValidPath($user)) {
- throw new \Exception('Username may not contain slashes');
- }
- $this->view = new \OC\Files\View('/'.$user);
+ public function __construct (Folder $folder, IL10N $l) {
+ $this->folder = $folder;
+ $this->l = $l;
}
/**
@@ -58,21 +62,25 @@ class Avatar implements \OCP\IAvatar {
* @return boolean|\OCP\IImage containing the avatar or false if there's no image
*/
public function get ($size = 64) {
- if ($this->view->file_exists('avatar.jpg')) {
+ if ($this->folder->nodeExists('avatar.jpg')) {
$ext = 'jpg';
- } elseif ($this->view->file_exists('avatar.png')) {
+ } elseif ($this->folder->nodeExists('avatar.png')) {
$ext = 'png';
} else {
return false;
}
$avatar = new OC_Image();
- if ($this->view->file_exists('avatar.' . $size . '.' . $ext)) {
- $avatar->loadFromData($this->view->file_get_contents('avatar.' . $size . '.' . $ext));
+ if ($this->folder->nodeExists('avatar.' . $size . '.' . $ext)) {
+ /** @var File $node */
+ $node = $this->folder->get('avatar.' . $size . '.' . $ext);
+ $avatar->loadFromData($node->getContent());
} else {
- $avatar->loadFromData($this->view->file_get_contents('avatar.' . $ext));
+ /** @var File $node */
+ $node = $this->folder->get('avatar.' . $ext);
+ $avatar->loadFromData($node->getContent());
$avatar->resize($size);
- $this->view->file_put_contents('avatar.' . $size . '.' . $ext, $avatar->data());
+ $this->folder->newFile('avatar.' . $size . '.' . $ext)->putContent($avatar->data());
}
return $avatar;
}
@@ -83,7 +91,7 @@ class Avatar implements \OCP\IAvatar {
* @return bool
*/
public function exists() {
- return $this->view->file_exists('avatar.jpg') || $this->view->file_exists('avatar.png');
+ return $this->folder->nodeExists('avatar.jpg') || $this->folder->nodeExists('avatar.png');
}
/**
@@ -107,22 +115,19 @@ class Avatar implements \OCP\IAvatar {
$type = 'jpg';
}
if ($type !== 'jpg' && $type !== 'png') {
- $l = \OC::$server->getL10N('lib');
- throw new \Exception($l->t("Unknown filetype"));
+ throw new \Exception($this->l->t("Unknown filetype"));
}
if (!$img->valid()) {
- $l = \OC::$server->getL10N('lib');
- throw new \Exception($l->t("Invalid image"));
+ throw new \Exception($this->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);
+ $this->remove();
+ $this->folder->newFile('avatar.'.$type)->putContent($data);
}
/**
@@ -130,7 +135,11 @@ class Avatar implements \OCP\IAvatar {
* @return void
*/
public function remove () {
- $this->view->unlink('avatar.jpg');
- $this->view->unlink('avatar.png');
+ try {
+ $this->folder->get('avatar.jpg')->delete();
+ } catch (\OCP\Files\NotFoundException $e) {}
+ try {
+ $this->folder->get('avatar.png')->delete();
+ } catch (\OCP\Files\NotFoundException $e) {}
}
}