diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2017-05-03 14:44:23 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-05-08 11:20:49 +0200 |
commit | 34d97aa51c5e7ddb638aeb105a590ae159a34abe (patch) | |
tree | f12a75cea6ae2bd53695c3d414e7f60cde5e2e1d /apps/dav/lib | |
parent | dd430c2fd72e2d77d69ab93090b5fb6ea6ba76a6 (diff) | |
download | nextcloud-server-34d97aa51c5e7ddb638aeb105a590ae159a34abe.tar.gz nextcloud-server-34d97aa51c5e7ddb638aeb105a590ae159a34abe.zip |
Request proper size for contacts menu
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/CardDAV/ImageExportPlugin.php | 72 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/PhotoCache.php | 7 |
2 files changed, 7 insertions, 72 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); } |