From 72116b9587dda61491e43ae9bce00fb3cf56fdca Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 6 Apr 2020 20:14:42 +0200 Subject: [PATCH] Jitsi avatars: shareing url for pictures, anonymous letter-avatar or gravatar if none --- api/anon_lavatar.php | 46 ++++++++++++++++++++ api/src/Contacts/Photo.php | 34 ++++++++++++--- calendar/inc/class.calendar_boupdate.inc.php | 6 ++- 3 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 api/anon_lavatar.php diff --git a/api/anon_lavatar.php b/api/anon_lavatar.php new file mode 100644 index 0000000000..5904359ec4 --- /dev/null +++ b/api/anon_lavatar.php @@ -0,0 +1,46 @@ + + * @license http://opensource.org/licenses/gpl-license.php LGPL - GNU General Public License Version 2 or later + * @package api + * @subpackage contacts + */ + +use EGroupware\Api; + +$GLOBALS['egw_info'] = array('flags' => array( + 'disable_Template_class' => True, + 'noheader' => True, + // misuse session creation callback to send the image, in case we have no session + 'autocreate_session_callback' => 'send_image', + 'currentapp' => 'api', +)); + +require('../header.inc.php'); + +send_image(); + +function send_image() +{ + $params = [ + 'firstname' => $_GET['firstname'], + 'lastname' => $_GET['lastname'], + 'id' => $_GET['id'], + ]; + Api\Session::cache_control(864000); // 10 days + header('Content-type: image/jpeg'); + header('Etag: '.md5(json_encode($params))); + + if (($image = Api\avatar::lavatar($params)) !== false) + { + echo $image; + } + else + { + http_response_code(404); + } + exit; +} diff --git a/api/src/Contacts/Photo.php b/api/src/Contacts/Photo.php index 116c02c3c7..7f43231f98 100644 --- a/api/src/Contacts/Photo.php +++ b/api/src/Contacts/Photo.php @@ -36,8 +36,9 @@ class Photo protected $path; /** + * Contructor * - * @param int|str|array $id_data contact-id or array with data + * @param int|string|array $id_data contact-id, "account:$account_id", array with contact-data or email for gravatar-url */ function __construct($id_data) { @@ -51,7 +52,8 @@ class Photo if (!($this->contact = $contact->read($id_data))) { - throw Api\Exception\NotFound("Contact '$id_data' not found!"); + $this->contact = $id_data; + //throw Api\Exception\NotFound("Contact '$id_data' not found!"); } } } @@ -79,6 +81,10 @@ class Photo */ function hasPhoto() { + if (!is_array($this->contact)) + { + return null; + } if (!empty($this->contact['jpegphoto'])) { return $this->contact['jpegphoto']; @@ -90,6 +96,24 @@ class Photo return NULL; } + /** + * Return URL for anonymous letter-avatar or Gravatar for email-addresses + * + * @return string + */ + function anonLavatar() + { + if (!is_array($this->contact)) + { + return 'https://gravatar.com/'.md5(trim(strtolower($this->contact))); + } + return Api\Framework::getUrl(Api\Egw::link('/api/anon_lavatar.php', [ + 'firstname' => $this->contact['firstname'], + 'lastname' => $this->contact['lastname'], + 'id' => $this->contact['id'], + ])); + } + /** * Get session-independent url / sharing link for the contact photo * @@ -101,7 +125,7 @@ class Photo if (empty($path)) { - return null; + return $this->anonLavatar(); } // if we got photo, we have to create a temp. file to share if ($path[0] !== '/') @@ -109,12 +133,12 @@ class Photo $tmp = tempnam($GLOBALS['egw_info']['server']['temp_dir'], '.jpeg'); if (!file_put_contents($tmp, $path)) { - return null; + return $this->anonLavatar(); } $path = $tmp; } return Api\Vfs\Sharing::share2link(Api\Vfs\Sharing::create( - '', $path, Api\Vfs\Sharing::READONLY, basename($path), array() + '', $path, Api\Vfs\Sharing::READONLY, basename($path), array() )); } } \ No newline at end of file diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php index 86b2e2da3b..c237562790 100644 --- a/calendar/inc/class.calendar_boupdate.inc.php +++ b/calendar/inc/class.calendar_boupdate.inc.php @@ -1051,11 +1051,13 @@ class calendar_boupdate extends calendar_bo // generate a personal videoconference url, if we need one if (!empty($event['##videoconference']) && class_exists('EGroupware\\Status\\Videoconference\\Call')) { + $avatar = new Api\Contacts\Photo(is_numeric($userid) ? "account:$userid" : + (isset($res_info) && $res_info['type'] === 'c' ? $res_info['res_id'] : $userid)); + $details['videoconference'] = EGroupware\Status\Videoconference\Call::genMeetingUrl($event['##videoconference'], [ 'name' => $fullname, 'email' => is_numeric($userid) ? Api\Accounts::id2name($userid, 'account_email') : $userid, - // todo: contacts and email-addresses (eg. Gravatar-Url) - 'avatar' => Api\Framework::getUrl(Api\Egw::link('/api/avatar.php', array('account_id' => $userid))), + 'avatar' => (string)$avatar, 'account_id' => $userid ]); $event_arr['videoconference'] = [