/**
  * @param IEvent $event
  * @param string $parameter The parameter to be formatted
  * @return string The formatted parameter
  */
 public function format(IEvent $event, $parameter)
 {
     $param = $this->fixLegacyFilename($parameter);
     // If the activity is about the very same file, we use the current path
     // for the link generation instead of the one that was saved.
     $fileId = '';
     if (is_array($param)) {
         $fileId = key($param);
         $param = $param[$fileId];
         $info = $this->infoCache->getInfoById($this->user, $fileId, $param);
     } elseif ($event->getObjectType() === 'files' && $event->getObjectName() === $param) {
         $fileId = $event->getObjectId();
         $info = $this->infoCache->getInfoById($this->user, $fileId, $param);
     } else {
         $info = $this->infoCache->getInfoByPath($this->user, $param);
     }
     if ($info['is_dir']) {
         $linkData = ['dir' => $info['path']];
     } else {
         $parentDir = substr_count($info['path'], '/') === 1 ? '/' : dirname($info['path']);
         $fileName = basename($info['path']);
         $linkData = ['dir' => $parentDir, 'scrollto' => $fileName];
     }
     if ($info['view'] !== '') {
         $linkData['view'] = $info['view'];
     }
     $param = trim($param, '/');
     $fileLink = $this->urlGenerator->linkToRouteAbsolute('files.view.index', $linkData);
     return '<file link="' . $fileLink . '" id="' . Util::sanitizeHTML($fileId) . '">' . Util::sanitizeHTML($param) . '</file>';
 }
 /**
  * @dataProvider dataGetParameter
  * @param string $parameter
  * @param string $objectType
  * @param int $objectId
  * @param string $expected
  */
 public function testGetParameter($parameter, $objectType, $objectId, $expected)
 {
     $instance = $this->getParameter($parameter);
     $this->event->expects($this->atLeastOnce())->method('getObjectType')->willReturn($objectType);
     $this->event->expects($this->any())->method('getObjectId')->willReturn($objectId);
     $this->assertSame($expected, $instance->getParameter());
 }
Beispiel #3
0
 /**
  * @return mixed
  */
 public function getParameter()
 {
     if ($this->event->getObjectType() && $this->event->getObjectId()) {
         return $this->event->getObjectType() . '#' . $this->event->getObjectId();
     }
     return $this->parameter;
 }
 /**
  * Send an event to the notifications of a user
  *
  * @param IEvent $event
  * @return null
  */
 public function receive(IEvent $event)
 {
     $selfAction = $event->getAffectedUser() === $event->getAuthor();
     $streamSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'stream', $event->getType());
     $emailSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'email', $event->getType());
     $emailSetting = $emailSetting ? $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'batchtime') : false;
     // Add activity to stream
     if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'self'))) {
         $this->data->send($event);
     }
     // Add activity to mail queue
     if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'selfemail'))) {
         $latestSend = $event->getTimestamp() + $emailSetting;
         $this->data->storeMail($event, $latestSend);
     }
 }
Beispiel #5
0
 /**
  * @param IEvent $event
  * @param string $parameter The parameter to be formatted
  * @param bool $allowHtml   Should HTML be used to format the parameter?
  * @param bool $verbose     Should paths, names, etc be shortened or full length
  * @return string The formatted parameter
  */
 public function format(IEvent $event, $parameter, $allowHtml, $verbose = false)
 {
     $param = $this->fixLegacyFilename($parameter);
     // If the activity is about the very same file, we use the current path
     // for the link generation instead of the one that was saved.
     $fileId = '';
     if ($event->getObjectType() === 'files' && $event->getObjectName() === $param) {
         $fileId = $event->getObjectId();
         $info = $this->infoCache->getInfoById($this->user, $fileId, $param);
     } else {
         $info = $this->infoCache->getInfoByPath($this->user, $param);
     }
     if ($info['is_dir']) {
         $linkData = ['dir' => $info['path']];
     } else {
         $parentDir = substr_count($info['path'], '/') === 1 ? '/' : dirname($info['path']);
         $fileName = basename($info['path']);
         $linkData = ['dir' => $parentDir, 'scrollto' => $fileName];
     }
     if ($info['view'] !== '') {
         $linkData['view'] = $info['view'];
     }
     $param = trim($param, '/');
     list($path, $name) = $this->splitPathFromFilename($param);
     $fileLink = $this->urlGenerator->linkTo('files', 'index.php', $linkData);
     if ($allowHtml === null) {
         return '<file link="' . $fileLink . '" id="' . Util::sanitizeHTML($fileId) . '">' . Util::sanitizeHTML($param) . '</file>';
     }
     if ($verbose || $path === '') {
         if (!$allowHtml) {
             return $param;
         }
         return '<a class="filename" href="' . $fileLink . '">' . Util::sanitizeHTML($param) . '</a>';
     }
     if (!$allowHtml) {
         return $name;
     }
     $title = ' title="' . $this->l->t('in %s', array(Util::sanitizeHTML($path))) . '"';
     return '<a class="filename has-tooltip" href="' . $fileLink . '"' . $title . '>' . Util::sanitizeHTML($name) . '</a>';
 }
Beispiel #6
0
 /**
  * Publish an event to the activity consumers
  *
  * Make sure to call at least the following methods before sending an Event:
  *  - setApp()
  *  - setType()
  *  - setAffectedUser()
  *  - setSubject()
  *
  * @param IEvent $event
  * @return null
  * @throws \BadMethodCallException if required values have not been set
  */
 public function publish(IEvent $event)
 {
     if (!$event->getApp()) {
         throw new \BadMethodCallException('App not set', 10);
     }
     if (!$event->getType()) {
         throw new \BadMethodCallException('Type not set', 11);
     }
     if ($event->getAffectedUser() === null) {
         throw new \BadMethodCallException('Affected user not set', 12);
     }
     if ($event->getSubject() === null || $event->getSubjectParameters() === null) {
         throw new \BadMethodCallException('Subject not set', 13);
     }
     if ($event->getAuthor() === null) {
         if ($this->session->getUser() instanceof IUser) {
             $event->setAuthor($this->session->getUser()->getUID());
         }
     }
     if (!$event->getTimestamp()) {
         $event->setTimestamp(time());
     }
     foreach ($this->getConsumers() as $c) {
         $c->receive($event);
     }
 }
Beispiel #7
0
 /**
  * Get the parameter array from the parameter string of the database table
  *
  * @param IEvent $event
  * @param string $parsing What are we parsing `message` or `subject`
  * @param string $parameterString can be a JSON string, serialize() or a simple string.
  * @return array List of Parameters
  */
 public function getParameters(IEvent $event, $parsing, $parameterString)
 {
     $parameters = $this->parseParameters($parameterString);
     $parameterTypes = $this->getSpecialParameterList($event->getApp(), $parsing === 'subject' ? $event->getSubject() : $event->getMessage());
     foreach ($parameters as $i => $parameter) {
         $parameters[$i] = $this->parameterFactory->get($parameter, $event, isset($parameterTypes[$i]) ? $parameterTypes[$i] : 'base');
     }
     return $parameters;
 }
Beispiel #8
0
 /**
  * Send an event as email
  *
  * @param IEvent $event
  * @param int    $latestSendTime Activity $timestamp + batch setting of $affectedUser
  * @return bool
  */
 public function storeMail(IEvent $event, $latestSendTime)
 {
     if ($event->getAffectedUser() === '' || $event->getAffectedUser() === null) {
         return false;
     }
     // store in DB
     $queryBuilder = $this->connection->getQueryBuilder();
     $queryBuilder->insert('activity_mq')->values(['amq_appid' => $queryBuilder->createParameter('app'), 'amq_subject' => $queryBuilder->createParameter('subject'), 'amq_subjectparams' => $queryBuilder->createParameter('subjectparams'), 'amq_affecteduser' => $queryBuilder->createParameter('affecteduser'), 'amq_timestamp' => $queryBuilder->createParameter('timestamp'), 'amq_type' => $queryBuilder->createParameter('type'), 'amq_latest_send' => $queryBuilder->createParameter('latest_send')])->setParameters(['app' => $event->getApp(), 'subject' => $event->getSubject(), 'subjectparams' => json_encode($event->getSubjectParameters()), 'affecteduser' => $event->getAffectedUser(), 'timestamp' => (int) $event->getTimestamp(), 'type' => $event->getType(), 'latest_send' => $latestSendTime])->execute();
     return true;
 }
Beispiel #9
0
 /**
  * Send an event to the notifications of a user
  *
  * @param IEvent $event
  * @return null
  */
 public function receive(IEvent $event)
 {
     $selfAction = $event->getAffectedUser() === $event->getAuthor();
     $streamSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'stream', $event->getType());
     $emailSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'email', $event->getType());
     $emailSetting = $emailSetting ? $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'batchtime') : false;
     $types = $this->data->getNotificationTypes($this->l10nFactory->get('activity'));
     $typeData = $types[$event->getType()];
     // User is not the author or wants to see their own actions
     $createStream = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'self');
     // User can not control the setting
     $createStream = $createStream || is_array($typeData) && isset($typeData['methods']) && !in_array(IExtension::METHOD_STREAM, $typeData['methods']);
     // Add activity to stream
     if ($streamSetting && $createStream) {
         $this->data->send($event);
     }
     // User is not the author or wants to see their own actions
     $createEmail = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'selfemail');
     // User can not control the setting
     $createEmail = $createEmail || is_array($typeData) && isset($typeData['methods']) && !in_array(IExtension::METHOD_MAIL, $typeData['methods']);
     // Add activity to mail queue
     if ($emailSetting && $createEmail) {
         $latestSend = $event->getTimestamp() + $emailSetting;
         $this->data->storeMail($event, $latestSend);
     }
 }