2016-11-07 17:08:56 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-11-24 17:46:38 +03:00
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
2016-11-07 17:08:56 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
*
|
2016-11-07 17:08:56 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-11-07 17:08:56 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\ShareByMail;
|
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
use OCP\Activity\IEvent;
|
2016-11-07 17:08:56 +03:00
|
|
|
use OCP\Activity\IManager;
|
2016-11-24 17:46:38 +03:00
|
|
|
use OCP\Activity\IProvider;
|
2016-11-25 13:17:06 +03:00
|
|
|
use OCP\Contacts\IManager as IContactsManager;
|
2016-11-07 17:08:56 +03:00
|
|
|
use OCP\IL10N;
|
2016-11-24 17:46:38 +03:00
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserManager;
|
2016-12-01 13:35:23 +03:00
|
|
|
use OCP\L10N\IFactory;
|
2016-11-07 17:08:56 +03:00
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
class Activity implements IProvider {
|
2016-11-07 17:08:56 +03:00
|
|
|
|
2016-12-01 13:35:23 +03:00
|
|
|
/** @var IFactory */
|
|
|
|
protected $languageFactory;
|
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
/** @var IL10N */
|
|
|
|
protected $l;
|
2016-11-07 17:08:56 +03:00
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
protected $url;
|
2016-11-07 17:08:56 +03:00
|
|
|
|
|
|
|
/** @var IManager */
|
2016-11-24 17:46:38 +03:00
|
|
|
protected $activityManager;
|
2016-11-07 17:08:56 +03:00
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
/** @var IUserManager */
|
|
|
|
protected $userManager;
|
2016-11-25 13:17:06 +03:00
|
|
|
/** @var IContactsManager */
|
|
|
|
protected $contactsManager;
|
2016-11-07 17:08:56 +03:00
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
/** @var array */
|
|
|
|
protected $displayNames = [];
|
2016-11-07 17:08:56 +03:00
|
|
|
|
2016-11-25 13:17:06 +03:00
|
|
|
/** @var array */
|
|
|
|
protected $contactNames = [];
|
|
|
|
|
2020-04-10 17:54:27 +03:00
|
|
|
public const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self';
|
|
|
|
public const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by';
|
|
|
|
public const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send';
|
|
|
|
public const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self';
|
|
|
|
public const SUBJECT_UNSHARED_EMAIL_SELF = 'unshared_with_email_self';
|
|
|
|
public const SUBJECT_UNSHARED_EMAIL_BY = 'unshared_with_email_by';
|
2016-11-07 17:08:56 +03:00
|
|
|
|
|
|
|
/**
|
2016-12-01 13:35:23 +03:00
|
|
|
* @param IFactory $languageFactory
|
2016-11-24 17:46:38 +03:00
|
|
|
* @param IURLGenerator $url
|
|
|
|
* @param IManager $activityManager
|
|
|
|
* @param IUserManager $userManager
|
2016-11-25 13:17:06 +03:00
|
|
|
* @param IContactsManager $contactsManager
|
2016-11-07 17:08:56 +03:00
|
|
|
*/
|
2016-12-01 13:35:23 +03:00
|
|
|
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) {
|
|
|
|
$this->languageFactory = $languageFactory;
|
2016-11-24 17:46:38 +03:00
|
|
|
$this->url = $url;
|
|
|
|
$this->activityManager = $activityManager;
|
|
|
|
$this->userManager = $userManager;
|
2016-11-25 13:17:06 +03:00
|
|
|
$this->contactsManager = $contactsManager;
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-01 13:35:23 +03:00
|
|
|
* @param string $language
|
2016-11-24 17:46:38 +03:00
|
|
|
* @param IEvent $event
|
|
|
|
* @param IEvent|null $previousEvent
|
|
|
|
* @return IEvent
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @since 11.0.0
|
2016-11-07 17:08:56 +03:00
|
|
|
*/
|
2016-12-01 13:35:23 +03:00
|
|
|
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
|
2016-11-24 17:46:38 +03:00
|
|
|
if ($event->getApp() !== 'sharebymail') {
|
|
|
|
throw new \InvalidArgumentException();
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 13:35:23 +03:00
|
|
|
$this->l = $this->languageFactory->get('sharebymail', $language);
|
|
|
|
|
2016-11-07 17:08:56 +03:00
|
|
|
if ($this->activityManager->isFormattingFilteredObject()) {
|
2016-11-24 17:46:38 +03:00
|
|
|
try {
|
|
|
|
return $this->parseShortVersion($event);
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
|
// Ignore and simply use the long version...
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
return $this->parseLongVersion($event);
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-11-24 17:46:38 +03:00
|
|
|
* @param IEvent $event
|
|
|
|
* @return IEvent
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @since 11.0.0
|
2016-11-07 17:08:56 +03:00
|
|
|
*/
|
2016-11-24 17:46:38 +03:00
|
|
|
public function parseShortVersion(IEvent $event) {
|
|
|
|
$parsedParameters = $this->getParsedParameters($event);
|
|
|
|
|
|
|
|
if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) {
|
|
|
|
$event->setParsedSubject($this->l->t('Shared with %1$s', [
|
2020-04-09 10:22:29 +03:00
|
|
|
$parsedParameters['email']['name'],
|
|
|
|
]))
|
2016-11-24 17:46:38 +03:00
|
|
|
->setRichSubject($this->l->t('Shared with {email}'), [
|
|
|
|
'email' => $parsedParameters['email'],
|
2017-06-20 14:48:51 +03:00
|
|
|
]);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
|
2016-11-24 17:46:38 +03:00
|
|
|
$event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [
|
2017-04-19 16:10:22 +03:00
|
|
|
$parsedParameters['email']['name'],
|
|
|
|
$parsedParameters['actor']['name'],
|
|
|
|
]))
|
2016-11-24 17:46:38 +03:00
|
|
|
->setRichSubject($this->l->t('Shared with {email} by {actor}'), [
|
|
|
|
'email' => $parsedParameters['email'],
|
|
|
|
'actor' => $parsedParameters['actor'],
|
2017-06-20 14:48:51 +03:00
|
|
|
]);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) {
|
2018-11-23 15:04:16 +03:00
|
|
|
$event->setParsedSubject($this->l->t('Unshared from %1$s', [
|
2020-04-09 10:22:29 +03:00
|
|
|
$parsedParameters['email']['name'],
|
|
|
|
]))
|
2018-11-23 15:04:16 +03:00
|
|
|
->setRichSubject($this->l->t('Unshared from {email}'), [
|
|
|
|
'email' => $parsedParameters['email'],
|
|
|
|
]);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) {
|
2018-11-23 15:04:16 +03:00
|
|
|
$event->setParsedSubject($this->l->t('Unshared from %1$s by %2$s', [
|
|
|
|
$parsedParameters['email']['name'],
|
|
|
|
$parsedParameters['actor']['name'],
|
|
|
|
]))
|
|
|
|
->setRichSubject($this->l->t('Unshared from {email} by {actor}'), [
|
|
|
|
'email' => $parsedParameters['email'],
|
|
|
|
'actor' => $parsedParameters['actor'],
|
|
|
|
]);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
|
2017-04-22 00:07:12 +03:00
|
|
|
$event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [
|
2017-04-19 16:10:22 +03:00
|
|
|
$parsedParameters['email']['name']
|
|
|
|
]))
|
2017-04-22 00:07:12 +03:00
|
|
|
->setRichSubject($this->l->t('Password for mail share sent to {email}'), [
|
2017-04-19 16:10:22 +03:00
|
|
|
'email' => $parsedParameters['email']
|
2017-06-20 14:48:51 +03:00
|
|
|
]);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
|
2017-04-22 00:07:12 +03:00
|
|
|
$event->setParsedSubject($this->l->t('Password for mail share sent to you'))
|
2017-06-20 14:48:51 +03:00
|
|
|
->setRichSubject($this->l->t('Password for mail share sent to you'));
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2016-11-24 17:46:38 +03:00
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException();
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
return $event;
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-11-24 17:46:38 +03:00
|
|
|
* @param IEvent $event
|
|
|
|
* @return IEvent
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @since 11.0.0
|
2016-11-07 17:08:56 +03:00
|
|
|
*/
|
2016-11-24 17:46:38 +03:00
|
|
|
public function parseLongVersion(IEvent $event) {
|
|
|
|
$parsedParameters = $this->getParsedParameters($event);
|
|
|
|
|
|
|
|
if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) {
|
|
|
|
$event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [
|
2020-04-09 10:22:29 +03:00
|
|
|
$parsedParameters['file']['path'],
|
|
|
|
$parsedParameters['email']['name'],
|
|
|
|
]))
|
2017-06-20 14:48:51 +03:00
|
|
|
->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
|
2016-11-24 17:46:38 +03:00
|
|
|
$event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [
|
2017-04-19 16:10:22 +03:00
|
|
|
$parsedParameters['file']['path'],
|
|
|
|
$parsedParameters['email']['name'],
|
|
|
|
$parsedParameters['actor']['name'],
|
|
|
|
]))
|
2017-06-20 14:48:51 +03:00
|
|
|
->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) {
|
2018-11-23 15:04:16 +03:00
|
|
|
$event->setParsedSubject($this->l->t('You unshared %1$s from %2$s by mail', [
|
2020-04-09 10:22:29 +03:00
|
|
|
$parsedParameters['file']['path'],
|
|
|
|
$parsedParameters['email']['name'],
|
|
|
|
]))
|
2018-11-23 15:04:16 +03:00
|
|
|
->setRichSubject($this->l->t('You unshared {file} from {email} by mail'), $parsedParameters);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) {
|
2018-11-23 15:04:16 +03:00
|
|
|
$event->setParsedSubject($this->l->t('%3$s unshared %1$s from %2$s by mail', [
|
|
|
|
$parsedParameters['file']['path'],
|
|
|
|
$parsedParameters['email']['name'],
|
|
|
|
$parsedParameters['actor']['name'],
|
|
|
|
]))
|
|
|
|
->setRichSubject($this->l->t('{actor} unshared {file} from {email} by mail'), $parsedParameters);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
|
2017-04-26 10:27:41 +03:00
|
|
|
$event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [
|
2017-04-19 16:10:22 +03:00
|
|
|
$parsedParameters['file']['path'],
|
|
|
|
$parsedParameters['email']['name']
|
|
|
|
]))
|
2017-06-20 14:48:51 +03:00
|
|
|
->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
|
2017-04-19 16:10:22 +03:00
|
|
|
$event->setParsedSubject(
|
2017-04-26 10:27:41 +03:00
|
|
|
$this->l->t('Password to access %1$s was sent to you',
|
2017-04-19 16:10:22 +03:00
|
|
|
[$parsedParameters['file']['path']]))
|
2017-06-20 14:48:51 +03:00
|
|
|
->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters);
|
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2016-11-24 17:46:38 +03:00
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException();
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
return $event;
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
protected function getParsedParameters(IEvent $event) {
|
|
|
|
$subject = $event->getSubject();
|
|
|
|
$parameters = $event->getSubjectParameters();
|
2016-11-07 17:08:56 +03:00
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
switch ($subject) {
|
2016-11-25 13:45:40 +03:00
|
|
|
case self::SUBJECT_SHARED_EMAIL_SELF:
|
2018-11-23 15:04:16 +03:00
|
|
|
case self::SUBJECT_UNSHARED_EMAIL_SELF:
|
2016-11-24 17:46:38 +03:00
|
|
|
return [
|
|
|
|
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
|
|
|
|
'email' => $this->generateEmailParameter($parameters[1]),
|
|
|
|
];
|
2016-11-25 13:45:40 +03:00
|
|
|
case self::SUBJECT_SHARED_EMAIL_BY:
|
2018-11-23 15:04:16 +03:00
|
|
|
case self::SUBJECT_UNSHARED_EMAIL_BY:
|
2016-11-24 17:46:38 +03:00
|
|
|
return [
|
|
|
|
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
|
|
|
|
'email' => $this->generateEmailParameter($parameters[1]),
|
|
|
|
'actor' => $this->generateUserParameter($parameters[2]),
|
|
|
|
];
|
2017-04-19 16:10:22 +03:00
|
|
|
case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND:
|
|
|
|
return [
|
|
|
|
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
|
|
|
|
'email' => $this->generateEmailParameter($parameters[1]),
|
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF:
|
|
|
|
return [
|
|
|
|
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
|
|
|
|
];
|
2016-11-24 17:46:38 +03:00
|
|
|
}
|
|
|
|
throw new \InvalidArgumentException();
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-11-24 17:46:38 +03:00
|
|
|
* @param int $id
|
|
|
|
* @param string $path
|
|
|
|
* @return array
|
2016-11-07 17:08:56 +03:00
|
|
|
*/
|
2016-11-24 17:46:38 +03:00
|
|
|
protected function generateFileParameter($id, $path) {
|
|
|
|
return [
|
|
|
|
'type' => 'file',
|
|
|
|
'id' => $id,
|
|
|
|
'name' => basename($path),
|
2016-12-15 17:53:48 +03:00
|
|
|
'path' => trim($path, '/'),
|
2016-11-24 17:46:38 +03:00
|
|
|
'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
|
|
|
|
];
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-11-24 17:46:38 +03:00
|
|
|
* @param string $email
|
|
|
|
* @return array
|
2016-11-07 17:08:56 +03:00
|
|
|
*/
|
2016-11-24 17:46:38 +03:00
|
|
|
protected function generateEmailParameter($email) {
|
2016-11-25 13:17:06 +03:00
|
|
|
if (!isset($this->contactNames[$email])) {
|
|
|
|
$this->contactNames[$email] = $this->getContactName($email);
|
|
|
|
}
|
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
return [
|
|
|
|
'type' => 'email',
|
|
|
|
'id' => $email,
|
2016-11-25 13:17:06 +03:00
|
|
|
'name' => $this->contactNames[$email],
|
2016-11-24 17:46:38 +03:00
|
|
|
];
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-11-24 17:46:38 +03:00
|
|
|
* @param string $uid
|
|
|
|
* @return array
|
2016-11-07 17:08:56 +03:00
|
|
|
*/
|
2016-11-24 17:46:38 +03:00
|
|
|
protected function generateUserParameter($uid) {
|
|
|
|
if (!isset($this->displayNames[$uid])) {
|
|
|
|
$this->displayNames[$uid] = $this->getDisplayName($uid);
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
2016-11-24 17:46:38 +03:00
|
|
|
return [
|
|
|
|
'type' => 'user',
|
|
|
|
'id' => $uid,
|
|
|
|
'name' => $this->displayNames[$uid],
|
|
|
|
];
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:17:06 +03:00
|
|
|
/**
|
|
|
|
* @param string $email
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getContactName($email) {
|
|
|
|
$addressBookContacts = $this->contactsManager->search($email, ['EMAIL']);
|
|
|
|
|
|
|
|
foreach ($addressBookContacts as $contact) {
|
|
|
|
if (isset($contact['isLocalSystemBook'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($email, $contact['EMAIL'])) {
|
|
|
|
return $contact['FN'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $email;
|
|
|
|
}
|
|
|
|
|
2016-11-07 17:08:56 +03:00
|
|
|
/**
|
2016-11-24 17:46:38 +03:00
|
|
|
* @param string $uid
|
|
|
|
* @return string
|
2016-11-07 17:08:56 +03:00
|
|
|
*/
|
2016-11-24 17:46:38 +03:00
|
|
|
protected function getDisplayName($uid) {
|
|
|
|
$user = $this->userManager->get($uid);
|
|
|
|
if ($user instanceof IUser) {
|
|
|
|
return $user->getDisplayName();
|
|
|
|
} else {
|
|
|
|
return $uid;
|
2016-11-07 17:08:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|