Ejemplo n.º 1
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function show()
 {
     try {
         $user = $this->activityManager->getCurrentUserId();
         $userLang = $this->config->getUserValue($user, 'core', 'lang');
         // Overwrite user and language in the helper
         $l = $this->l10nFactory->get('activity', $userLang);
         $this->helper->setL10n($l);
         $this->helper->setUser($user);
         $description = (string) $l->t('Personal activity feed for %s', $user);
         $response = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', 'all');
         $activities = $response['data'];
     } catch (\UnexpectedValueException $e) {
         $l = $this->l10nFactory->get('activity');
         $description = (string) $l->t('Your feed URL is invalid');
         $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subjectformatted' => ['full' => $description]]];
     }
     $response = new TemplateResponse('activity', 'rss', ['rssLang' => $l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
     if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
         $response->addHeader('Content-Type', 'application/rss+xml');
     } else {
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
     }
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * @param INotification $notification
  * @param string $languageCode The code of the language that should be used to prepare the notification
  * @return INotification
  */
 public function prepare(INotification $notification, $languageCode)
 {
     if ($notification->getApp() !== 'files_sharing') {
         // Not my app => throw
         throw new \InvalidArgumentException();
     }
     // Read the language from the notification
     $l = $this->factory->get('files_sharing', $languageCode);
     switch ($notification->getSubject()) {
         // Deal with known subjects
         case 'remote_share':
             $params = $notification->getSubjectParameters();
             $notification->setParsedSubject((string) $l->t('You received %s as a remote share from %s', $params));
             // Deal with the actions for a known subject
             foreach ($notification->getActions() as $action) {
                 switch ($action->getLabel()) {
                     case 'accept':
                         $action->setParsedLabel((string) $l->t('Accept'));
                         break;
                     case 'decline':
                         $action->setParsedLabel((string) $l->t('Decline'));
                         break;
                 }
                 $notification->addParsedAction($action);
             }
             return $notification;
         default:
             // Unknown subject => Unknown notification => throw
             throw new \InvalidArgumentException();
     }
 }
Ejemplo n.º 3
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);
     }
 }
 /**
  * The extension can translate a given message to the requested languages.
  * If no translation is available false is to be returned.
  *
  * @param string $app
  * @param string $text
  * @param array $params
  * @param boolean $stripPath
  * @param boolean $highlightParams
  * @param string $languageCode
  * @return string|false
  */
 public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode)
 {
     if ($app === 'announcementcenter') {
         $l = $this->languageFactory->get('announcementcenter', $languageCode);
         list(, $id) = explode('#', $text);
         try {
             $announcement = $this->manager->getAnnouncement($id, $highlightParams);
         } catch (\InvalidArgumentException $e) {
             return (string) $l->t('Announcement does not exist anymore', $params);
         }
         if (strpos($text, 'announcementmessage#') === 0) {
             return $announcement['message'];
         }
         if ($highlightParams) {
             $params[] = '<strong>' . $announcement['subject'] . '</strong>';
         } else {
             $params[] = $announcement['subject'];
         }
         if ($announcement['author'] === $this->activityManager->getCurrentUserId()) {
             array_shift($params);
             return (string) $l->t('You announced %s', $params);
         }
         return (string) $l->t('%s announced %s', $params);
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * @param INotification $notification
  * @param string $languageCode The code of the language that should be used to prepare the notification
  * @return INotification
  * @throws \InvalidArgumentException When the notification was not prepared by a notifier
  * @since 9.0.0
  */
 public function prepare(INotification $notification, $languageCode)
 {
     if ($notification->getApp() !== 'updatenotification') {
         throw new \InvalidArgumentException();
     }
     $l = $this->l10NFactory->get('updatenotification', $languageCode);
     if ($notification->getObjectType() === 'core') {
         $appName = $l->t('ownCloud core');
         $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions());
     } else {
         $appInfo = $this->getAppInfo($notification->getObjectType());
         $appName = $appInfo === null ? $notification->getObjectType() : $appInfo['name'];
         if (isset($this->appVersions[$notification->getObjectType()])) {
             $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]);
         }
     }
     $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()]));
     return $notification;
 }
Ejemplo n.º 6
0
 /**
  * @param INotification $notification
  * @param string $languageCode The code of the language that should be used to prepare the notification
  * @return INotification
  * @throws \InvalidArgumentException When the notification was not prepared by a notifier
  */
 public function prepare(INotification $notification, $languageCode)
 {
     if ($notification->getApp() !== 'popularitycontestclient') {
         // Not my app => throw
         throw new \InvalidArgumentException();
     }
     // Read the language from the notification
     $l = $this->l10nFactory->get('popularitycontestclient', $languageCode);
     $notification->setParsedSubject((string) $l->t('Do you want to send monthly usage statistics to ownCloud?'));
     foreach ($notification->getActions() as $action) {
         if ($action->getLabel() === 'enable') {
             $action->setParsedLabel((string) $l->t('Yes'));
         } else {
             if ($action->getLabel() === 'disable') {
                 $action->setParsedLabel((string) $l->t('Not now'));
             }
         }
         $notification->addParsedAction($action);
     }
     return $notification;
 }
 /**
  * @param INotification $notification
  * @param string $languageCode The code of the language that should be used to prepare the notification
  * @return INotification
  * @throws \InvalidArgumentException When the notification was not prepared by a notifier
  */
 public function prepare(INotification $notification, $languageCode)
 {
     if ($notification->getApp() !== 'announcementcenter') {
         // Not my app => throw
         throw new \InvalidArgumentException();
     }
     // Read the language from the notification
     $l = $this->l10nFactory->get('announcementcenter', $languageCode);
     switch ($notification->getSubject()) {
         // Deal with known subjects
         case 'announced':
             $params = $notification->getSubjectParameters();
             $announcement = $this->manager->getAnnouncement($notification->getObjectId(), false);
             $params[] = $this->prepareMessage($announcement['subject']);
             $notification->setParsedMessage($this->prepareMessage($announcement['message']))->setParsedSubject((string) $l->t('%1$s announced “%2$s”', $params));
             return $notification;
         default:
             // Unknown subject => Unknown notification => throw
             throw new \InvalidArgumentException();
     }
 }
Ejemplo n.º 8
0
 /**
  * @brief Translate an event string with the translations from the app where it was send from
  * @param string $app The app where this event comes from
  * @param string $text The text including placeholders
  * @param IParameter[] $params The parameter for the placeholder
  * @param bool $stripPath Shall we strip the path from file names?
  * @param bool $highlightParams Shall we highlight the parameters in the string?
  *             They will be highlighted with `<strong>`, all data will be passed through
  *             \OCP\Util::sanitizeHTML() before, so no XSS is possible.
  * @return string translated
  */
 public function translation($app, $text, array $params, $stripPath = false, $highlightParams = false)
 {
     if (!$text) {
         return '';
     }
     $preparedParams = [];
     foreach ($params as $parameter) {
         $preparedParams[] = $parameter->format($highlightParams, !$stripPath);
     }
     // Allow apps to correctly translate their activities
     $translation = $this->activityManager->translate($app, $text, $preparedParams, $stripPath, $highlightParams, $this->l->getLanguageCode());
     if ($translation !== false) {
         return $translation;
     }
     $l = $this->l10Nfactory->get($app, $this->l->getLanguageCode());
     return $l->t($text, $preparedParams);
 }
Ejemplo n.º 9
0
 protected function getL10N($languageCode = null)
 {
     return $this->languageFactory->get(self::APP_NAME, $languageCode);
 }
Ejemplo n.º 10
0
 protected function getL10N($languageCode = null)
 {
     return $this->languageFactory->get(self::FILES_SHARING_APP, $languageCode);
 }