Request proper size for contacts menu
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
dd430c2fd7
commit
34d97aa51c
3 changed files with 9 additions and 73 deletions
|
@ -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 '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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}}'
|
||||
|
|
Loading…
Reference in a new issue