summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/dav/lib/CardDAV/ImageExportPlugin.php72
-rw-r--r--apps/dav/lib/CardDAV/PhotoCache.php7
-rw-r--r--core/js/contactsmenu.js3
3 files changed, 9 insertions, 73 deletions
diff --git a/apps/dav/lib/CardDAV/ImageExportPlugin.php b/apps/dav/lib/CardDAV/ImageExportPlugin.php
index 24bf1ada9f7..9d5eba453fb 100644
--- a/apps/dav/lib/CardDAV/ImageExportPlugin.php
+++ b/apps/dav/lib/CardDAV/ImageExportPlugin.php
@@ -29,9 +29,6 @@ use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
-use Sabre\VObject\Parameter;
-use Sabre\VObject\Property\Binary;
-use Sabre\VObject\Reader;
class ImageExportPlugin extends ServerPlugin {
@@ -125,73 +122,4 @@ class ImageExportPlugin extends ServerPlugin {
return false;
}
-
- function getPhoto(Card $node) {
- // TODO: this is kind of expensive - load carddav data from database and parse it
- // we might want to build up a cache one day
- try {
- $vObject = $this->readCard($node->get());
- if (!$vObject->PHOTO) {
- return false;
- }
-
- $photo = $vObject->PHOTO;
- $type = $this->getType($photo);
-
- $val = $photo->getValue();
- if ($photo->getValueType() === 'URI') {
- $parsed = \Sabre\URI\parse($val);
- //only allow data://
- if ($parsed['scheme'] !== 'data') {
- return false;
- }
- if (substr_count($parsed['path'], ';') === 1) {
- list($type,) = explode(';', $parsed['path']);
- }
- $val = file_get_contents($val);
- }
-
- $allowedContentTypes = [
- 'image/png',
- 'image/jpeg',
- 'image/gif',
- ];
-
- if(!in_array($type, $allowedContentTypes, true)) {
- $type = 'application/octet-stream';
- }
-
- return [
- 'Content-Type' => $type,
- 'body' => $val
- ];
- } catch(\Exception $ex) {
- $this->logger->logException($ex);
- }
- return false;
- }
-
- private function readCard($cardData) {
- return Reader::read($cardData);
- }
-
- /**
- * @param Binary $photo
- * @return Parameter
- */
- private function getType($photo) {
- $params = $photo->parameters();
- if (isset($params['TYPE']) || isset($params['MEDIATYPE'])) {
- /** @var Parameter $typeParam */
- $typeParam = isset($params['TYPE']) ? $params['TYPE'] : $params['MEDIATYPE'];
- $type = $typeParam->getValue();
-
- if (strpos($type, 'image/') === 0) {
- return $type;
- } else {
- return 'image/' . strtolower($type);
- }
- }
- return '';
- }
}
diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php
index 0f7194a5377..29c45debdef 100644
--- a/apps/dav/lib/CardDAV/PhotoCache.php
+++ b/apps/dav/lib/CardDAV/PhotoCache.php
@@ -109,6 +109,13 @@ class PhotoCache {
/** @var ISimpleFile $file */
$file = $folder->getFile('photo.' . $ext);
$photo->loadFromData($file->getContent());
+
+ $ratio = $photo->width() / $photo->height();
+ if ($ratio < 1) {
+ $ratio = 1/$ratio;
+ }
+ $size = (int)($size * $ratio);
+
if ($size !== -1) {
$photo->resize($size);
}
diff --git a/core/js/contactsmenu.js b/core/js/contactsmenu.js
index 9ce27509e8b..3da6ea127cd 100644
--- a/core/js/contactsmenu.js
+++ b/core/js/contactsmenu.js
@@ -50,7 +50,8 @@
+ '</div>';
var CONTACT_TEMPLATE = ''
+ '{{#if contact.avatar}}'
- + '<img src="{{contact.avatar}}" class="avatar">'
+ + '<img src="{{contact.avatar}}&size=32" class="avatar"'
+ + 'srcset="{{contact.avatar}}&size=32 1x, {{contact.avatar}}&size=64 2x, {{contact.avatar}}&size=128 4x">'
+ '{{else}}'
+ '<div class="avatar"></div>'
+ '{{/if}}'