From d0be5056be0b7316dce1b05846c5b27ab26c4bc8 Mon Sep 17 00:00:00 2001 From: LEDfan Date: Sun, 15 Jun 2014 10:28:30 +0200 Subject: [PATCH] add extra code for localusers --- lib/app.php | 2 +- lib/utils/temporaryphoto.php | 9 +++++ lib/utils/temporaryphoto/user.php | 61 +++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 lib/utils/temporaryphoto/user.php diff --git a/lib/app.php b/lib/app.php index ec37b367..62b722cd 100644 --- a/lib/app.php +++ b/lib/app.php @@ -56,7 +56,7 @@ class App { public static $backendClasses = array( 'local' => 'OCA\Contacts\Backend\Database', 'shared' => 'OCA\Contacts\Backend\Shared', - //'localusers' => 'OCA\Contacts\Backend\LocalUsers', + 'localusers' => 'OC\Contacts\Backend\LocalUsers', ); public function __construct( diff --git a/lib/utils/temporaryphoto.php b/lib/utils/temporaryphoto.php index 5ab99352..19972d57 100644 --- a/lib/utils/temporaryphoto.php +++ b/lib/utils/temporaryphoto.php @@ -37,6 +37,7 @@ class TemporaryPhoto { const PHOTO_CURRENT = 0; const PHOTO_FILESYSTEM = 1; const PHOTO_UPLOADED = 2; + const PHOTO_USER = 3; /** * @var \OCP\ICache @@ -79,6 +80,7 @@ class TemporaryPhoto { 'OCA\\Contacts\\Utils\\TemporaryPhoto\\Contact', 'OCA\\Contacts\\Utils\\TemporaryPhoto\\FileSystem', 'OCA\\Contacts\\Utils\\TemporaryPhoto\\Uploaded', + 'OCA\\Contacts\\Utils\\TemporaryPhoto\\User', ); /** @@ -197,4 +199,11 @@ class TemporaryPhoto { $this->normalized = true; } + public function getMimeType(){ + return $this->image->mimeType(); + } + + public function getImage(){ + return $this->image; + } } \ No newline at end of file diff --git a/lib/utils/temporaryphoto/user.php b/lib/utils/temporaryphoto/user.php new file mode 100644 index 00000000..17e0e983 --- /dev/null +++ b/lib/utils/temporaryphoto/user.php @@ -0,0 +1,61 @@ +. + * + */ + +namespace OCA\Contacts\Utils\TemporaryPhoto; + +use OCA\Contacts\Contact as ContactObject, + OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto, + OCP\ICache; + +/** + * This class loads the PHOTO or LOGO property from a contact. + */ +class User extends BaseTemporaryPhoto { + + /** + * The Contact object to load the image from + * + * @var OCA\Contacts\Contact + */ + protected $userId; + + public function __construct(ICache $cache, $userId) { + parent::__construct($cache); + // check if userId is a real ownCloud user + if(!in_array($userId, \OCP\User::getUsers())){ + throw new \Exception('Second argument must be an ownCloud user ID'); + } + $this->userId = $userId; + $this->processImage(); + } + + /** + * Do what's needed to get the image from storage + * depending on the type. + */ + protected function processImage() { + $localPath = \OCP\Config::getSystemValue('datadirectory') . '/' . $this->userId . '/avatar.png'; + $this->image = new \OCP\Image(); + $this->image->loadFromFile($localPath); + } + +} \ No newline at end of file