]> source.dussan.org Git - nextcloud-server.git/commitdiff
Request proper size for contacts menu
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 3 May 2017 12:44:23 +0000 (14:44 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 8 May 2017 09:20:49 +0000 (11:20 +0200)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
apps/dav/lib/CardDAV/ImageExportPlugin.php
apps/dav/lib/CardDAV/PhotoCache.php
core/js/contactsmenu.js

index 24bf1ada9f713cff549178f9f2aa7109e9215430..9d5eba453fb8fa6fed090b4afcba92492adf9b3b 100644 (file)
@@ -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 '';
-       }
 }
index 0f7194a5377a40d9f483e15110d31e50db84eef0..29c45debdefd009a197279ce598f7e4f94ef7f5d 100644 (file)
@@ -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);
                        }
index 9ce27509e8b9213ad6fe76cf8287911e53802ed4..3da6ea127cd9eb0fdf54b818317221deb5e38f61 100644 (file)
@@ -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}}'