示例#1
0
文件: feed.php 项目: samj1912/repo
 /**
  * @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 = Util::getL10N('activity', $userLang);
         $l->forceLanguage($userLang);
         $this->helper->setL10n($l);
         $this->helper->setUser($user);
         $description = (string) $l->t('Personal activity feed for %s', $user);
         $activities = $this->data->read($this->helper, $this->settings, 0, self::DEFAULT_PAGE_SIZE, 'all', $user);
     } catch (\UnexpectedValueException $e) {
         $l = Util::getL10N('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;
 }
 protected function setUp()
 {
     parent::setUp();
     $app = $this->getUniqueID('MailQueueHandlerTest');
     $this->userManager = $this->getMock('OCP\\IUserManager');
     $connection = \OC::$server->getDatabaseConnection();
     $query = $connection->prepare('INSERT INTO `*PREFIX*activity_mq` ' . ' (`amq_appid`, `amq_subject`, `amq_subjectparams`, `amq_affecteduser`, `amq_timestamp`, `amq_type`, `amq_latest_send`) ' . ' VALUES(?, ?, ?, ?, ?, ?, ?)');
     $query->execute(array($app, 'Test data', 'Param1', 'user1', 150, 'phpunit', 152));
     $query->execute(array($app, 'Test data', 'Param1', 'user1', 150, 'phpunit', 153));
     $query->execute(array($app, 'Test data', 'Param1', 'user2', 150, 'phpunit', 150));
     $query->execute(array($app, 'Test data', 'Param1', 'user2', 150, 'phpunit', 151));
     $query->execute(array($app, 'Test data', 'Param1', 'user3', 150, 'phpunit', 154));
     $query->execute(array($app, 'Test data', 'Param1', 'user3', 150, 'phpunit', 155));
     $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
     $event->expects($this->any())->method('setApp')->willReturnSelf();
     $event->expects($this->any())->method('setType')->willReturnSelf();
     $event->expects($this->any())->method('setAffectedUser')->willReturnSelf();
     $event->expects($this->any())->method('setTimestamp')->willReturnSelf();
     $event->expects($this->any())->method('setSubject')->willReturnSelf();
     $this->activityManager = $this->getMockBuilder('OCP\\Activity\\IManager')->disableOriginalConstructor()->getMock();
     $this->activityManager->expects($this->any())->method('generateEvent')->willReturn($event);
     $this->dataHelper = $this->getMockBuilder('OCA\\Activity\\DataHelper')->disableOriginalConstructor()->getMock();
     $this->dataHelper->expects($this->any())->method('getParameters')->willReturn([]);
     $this->message = $this->getMockBuilder('OC\\Mail\\Message')->disableOriginalConstructor()->getMock();
     $this->mailer = $this->getMock('OCP\\Mail\\IMailer');
     $this->mailer->expects($this->any())->method('createMessage')->willReturn($this->message);
     $this->mailQueueHandler = new MailQueueHandler($this->getMock('\\OCP\\IDateTimeFormatter'), $connection, $this->dataHelper, $this->mailer, $this->getMockBuilder('\\OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(), $this->userManager, $this->activityManager);
 }
 public function testAppActivity()
 {
     $this->activityManager->expects($this->once())->method('registerExtension')->willReturnCallback(function ($closure) {
         $this->assertInstanceOf('\\Closure', $closure);
         $navigation = $closure();
         $this->assertInstanceOf('\\OCA\\AnnouncementCenter\\ActivityExtension', $navigation);
     });
     include __DIR__ . '/../../appinfo/app.php';
 }
示例#4
0
 /**
  * Get all items for the users we want to send an email to
  *
  * @return array Notification data (user => array of rows from the table)
  */
 public function getLinkList()
 {
     $topEntries = [['id' => 'all', 'name' => (string) $this->l->t('All Activities'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList')]];
     if ($this->user && $this->userSettings->getUserSetting($this->user, 'setting', 'self')) {
         $topEntries[] = ['id' => 'self', 'name' => (string) $this->l->t('Activities by you'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'self'))];
         $topEntries[] = ['id' => 'by', 'name' => (string) $this->l->t('Activities by others'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'by'))];
     }
     $additionalEntries = $this->activityManager->getNavigation();
     $topEntries = array_merge($topEntries, $additionalEntries['top']);
     return array('top' => $topEntries, 'apps' => $additionalEntries['apps']);
 }
 public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode)
 {
     if ($app !== 'activity_ext') {
         return false;
     }
     $l = $this->getL10N($languageCode);
     if ($this->activityManager->isFormattingFilteredObject()) {
         $translation = $this->translateShort($text, $l, $params);
         if ($translation !== false) {
             return $translation;
         }
     }
     return $this->translateLong($text, $l, $params);
 }
示例#6
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 array $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, $params, $stripPath = false, $highlightParams = false)
 {
     if (!$text) {
         return '';
     }
     $preparedParams = $this->parameterHelper->prepareParameters($params, $this->parameterHelper->getSpecialParameterList($app, $text), $stripPath, $highlightParams);
     // 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 = Util::getL10N($app, $this->l->getLanguageCode());
     return $l->t($text, $preparedParams);
 }
 /**
  * Get the default selection of types for a method
  *
  * @param string $method Should be one of 'stream' or 'email'
  * @return array Array of strings
  */
 public function getDefaultTypes($method)
 {
     $settings = array();
     if ($method === 'stream') {
         $settings[] = Data::TYPE_SHARE_CREATED;
         $settings[] = Data::TYPE_SHARE_CHANGED;
         $settings[] = Data::TYPE_SHARE_DELETED;
         //			$settings[] = Data::TYPE_SHARE_RESHARED;
         $settings[] = Data::TYPE_SHARE_RESTORED;
         //			$settings[] = Data::TYPE_SHARE_DOWNLOADED;
     }
     if ($method === 'stream' || $method === 'email') {
         $settings[] = Data::TYPE_SHARED;
         //			$settings[] = Data::TYPE_SHARE_EXPIRED;
         //			$settings[] = Data::TYPE_SHARE_UNSHARED;
         //
         //			$settings[] = Data::TYPE_SHARE_UPLOADED;
         //
         //			$settings[] = Data::TYPE_STORAGE_QUOTA_90;
         //			$settings[] = Data::TYPE_STORAGE_FAILURE;
     }
     // Allow other apps to add notification types to the default setting
     $additionalSettings = $this->manager->getDefaultTypes($method);
     $settings = array_merge($settings, $additionalSettings);
     return $settings;
 }
 /**
  * Send a notification to one user
  *
  * @param string $userName Username of the recipient
  * @param string $email Email address of the recipient
  * @param string $lang Selected language of the recipient
  * @param string $timezone Selected timezone of the recipient
  * @param int $maxTime
  */
 public function sendEmailToUser($userName, $email, $lang, $timezone, $maxTime)
 {
     $user = $this->userManager->get($userName);
     if (!$user instanceof IUser) {
         return;
     }
     list($mailData, $skippedCount) = $this->getItemsForUser($userName, $maxTime);
     $l = $this->getLanguage($lang);
     $parser = new PlainTextParser($l);
     $this->dataHelper->setUser($userName);
     $this->dataHelper->setL10n($l);
     $this->activityManager->setCurrentUserId($userName);
     $activityList = array();
     foreach ($mailData as $activity) {
         $event = $this->activityManager->generateEvent();
         $event->setApp($activity['amq_appid'])->setType($activity['amq_type'])->setTimestamp($activity['amq_timestamp'])->setSubject($activity['amq_subject'], []);
         $relativeDateTime = $this->dateFormatter->formatDateTimeRelativeDay($activity['amq_timestamp'], 'long', 'medium', new \DateTimeZone($timezone), $l);
         $activityList[] = array($parser->parseMessage($this->dataHelper->translation($activity['amq_appid'], $activity['amq_subject'], $this->dataHelper->getParameters($event, 'subject', $activity['amq_subjectparams']))), $relativeDateTime);
     }
     $alttext = new Template('activity', 'email.notification', '', false);
     $alttext->assign('username', $user->getDisplayName());
     $alttext->assign('activities', $activityList);
     $alttext->assign('skippedCount', $skippedCount);
     $alttext->assign('owncloud_installation', $this->urlGenerator->getAbsoluteURL('/'));
     $alttext->assign('overwriteL10N', $l);
     $emailText = $alttext->fetchPage();
     $message = $this->mailer->createMessage();
     $message->setTo([$email => $user->getDisplayName()]);
     $message->setSubject((string) $l->t('Activity notification'));
     $message->setPlainBody($emailText);
     $message->setFrom([$this->getSenderData('email') => $this->getSenderData('name')]);
     $this->mailer->send($message);
     $this->activityManager->setCurrentUserId(null);
 }
示例#9
0
 /**
  * @param MapperEvent $event
  */
 public function mapperEvent(MapperEvent $event)
 {
     $tagIds = $event->getTags();
     if ($event->getObjectType() !== 'files' || empty($tagIds) || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) || !$this->appManager->isInstalled('activity')) {
         // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy)
         return;
     }
     try {
         $tags = $this->tagManager->getTagsByIds($tagIds);
     } catch (TagNotFoundException $e) {
         // User assigned/unassigned a non-existing tag, ignore...
         return;
     }
     if (empty($tags)) {
         return;
     }
     // Get all mount point owners
     $cache = $this->mountCollection->getMountCache();
     $mounts = $cache->getMountsForFileId($event->getObjectId());
     if (empty($mounts)) {
         return;
     }
     $users = [];
     foreach ($mounts as $mount) {
         $owner = $mount->getUser()->getUID();
         $ownerFolder = $this->rootFolder->getUserFolder($owner);
         $nodes = $ownerFolder->getById($event->getObjectId());
         if (!empty($nodes)) {
             /** @var Node $node */
             $node = array_shift($nodes);
             $path = $node->getPath();
             if (strpos($path, '/' . $owner . '/files/') === 0) {
                 $path = substr($path, strlen('/' . $owner . '/files'));
             }
             // Get all users that have access to the mount point
             $users = array_merge($users, Share::getUsersSharingFile($path, $owner, true, true));
         }
     }
     $actor = $this->session->getUser();
     if ($actor instanceof IUser) {
         $actor = $actor->getUID();
     } else {
         $actor = '';
     }
     $activity = $this->activityManager->generateEvent();
     $activity->setApp(Extension::APP_NAME)->setType(Extension::APP_NAME)->setAuthor($actor)->setObject($event->getObjectType(), $event->getObjectId());
     foreach ($users as $user => $path) {
         $activity->setAffectedUser($user);
         foreach ($tags as $tag) {
             if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) {
                 $activity->setSubject(Extension::ASSIGN_TAG, [$actor, $path, $this->prepareTagAsParameter($tag)]);
             } else {
                 if ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) {
                     $activity->setSubject(Extension::UNASSIGN_TAG, [$actor, $path, $this->prepareTagAsParameter($tag)]);
                 }
             }
             $this->activityManager->publish($activity);
         }
     }
 }
 public function testCreatePublicity()
 {
     $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('setApp')->with('announcementcenter')->willReturnSelf();
     $event->expects($this->once())->method('setType')->with('announcementcenter')->willReturnSelf();
     $event->expects($this->once())->method('setAuthor')->with('author')->willReturnSelf();
     $event->expects($this->once())->method('setTimestamp')->with(1337)->willReturnSelf();
     $event->expects($this->once())->method('setSubject')->with('announcementsubject#10', ['author'])->willReturnSelf();
     $event->expects($this->once())->method('setMessage')->with('announcementmessage#10', ['author'])->willReturnSelf();
     $event->expects($this->once())->method('setObject')->with('announcement', 10)->willReturnSelf();
     $event->expects($this->exactly(5))->method('setAffectedUser')->willReturnSelf();
     $notification = $this->getMockBuilder('OC\\Notification\\INotification')->disableOriginalConstructor()->getMock();
     $notification->expects($this->once())->method('setApp')->with('announcementcenter')->willReturnSelf();
     $dateTime = new \DateTime();
     $dateTime->setTimestamp(1337);
     $notification->expects($this->once())->method('setDateTime')->with($dateTime)->willReturnSelf();
     $notification->expects($this->once())->method('setSubject')->with('announced', ['author'])->willReturnSelf();
     $notification->expects($this->once())->method('setObject')->with('announcement', 10)->willReturnSelf();
     $notification->expects($this->once())->method('setLink')->willReturnSelf();
     $notification->expects($this->exactly(4))->method('setUser')->willReturnSelf();
     $controller = $this->getController();
     $this->activityManager->expects($this->once())->method('generateEvent')->willReturn($event);
     $this->notificationManager->expects($this->once())->method('createNotification')->willReturn($notification);
     $this->userManager->expects($this->once())->method('search')->with('')->willReturn([$this->getUserMock('author', 'User One'), $this->getUserMock('u2', 'User Two'), $this->getUserMock('u3', 'User Three'), $this->getUserMock('u4', 'User Four'), $this->getUserMock('u5', 'User Five')]);
     $this->activityManager->expects($this->exactly(5))->method('publish');
     $this->notificationManager->expects($this->exactly(4))->method('notify');
     $this->invokePrivate($controller, 'createPublicity', [10, 'author', 1337]);
 }
 /**
  * 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;
 }
示例#12
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
         $this->l = $this->l10nFactory->get('activity', $userLang);
         $parser = new PlainTextParser($this->l);
         $this->helper->setL10n($this->l);
         $this->helper->setUser($user);
         $description = (string) $this->l->t('Personal activity feed for %s', $user);
         $response = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', 'all');
         $data = $response['data'];
         $activities = [];
         foreach ($data as $activity) {
             $activity['subject_prepared'] = $parser->parseMessage($activity['subject_prepared']);
             $activity['message_prepared'] = $parser->parseMessage($activity['message_prepared']);
             $activities[] = $activity;
         }
     } catch (\UnexpectedValueException $e) {
         $this->l = $this->l10nFactory->get('activity');
         $description = (string) $this->l->t('Your feed URL is invalid');
         $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subject_prepared' => $description]];
     }
     $response = new TemplateResponse('activity', 'rss', ['rssLang' => $this->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;
 }
示例#13
0
 protected function mockUserSession($user)
 {
     $mockUser = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock();
     $mockUser->expects($this->any())->method('getUID')->willReturn($user);
     $this->session->expects($this->any())->method('isLoggedIn')->willReturn(true);
     $this->session->expects($this->any())->method('getUser')->willReturn($mockUser);
     $this->manager->expects($this->any())->method('getCurrentUserId')->willReturn($user);
 }
示例#14
0
 /**
  * Check if the author is the current user
  *
  * @param string $user Parameter e.g. `<user display-name="admin">admin</user>`
  * @return bool
  */
 protected function actorIsCurrentUser($user)
 {
     try {
         return strip_tags($user) === $this->activityManager->getCurrentUserId();
     } catch (\UnexpectedValueException $e) {
         return false;
     }
 }
 /**
  * List with special parameters for the message
  *
  * @param string $app
  * @param string $text
  * @return array
  */
 public function getSpecialParameterList($app, $text)
 {
     $specialParameters = $this->activityManager->getSpecialParameterList($app, $text);
     if ($specialParameters !== false) {
         return $specialParameters;
     }
     return array();
 }
示例#16
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $token
  * @param string $files
  * @param string $path
  * @return void|RedirectResponse
  */
 public function downloadShare($token, $files = null, $path = '')
 {
     \OC_User::setIncognitoMode(true);
     $linkItem = OCP\Share::getShareByToken($token, false);
     // Share is password protected - check whether the user is permitted to access the share
     if (isset($linkItem['share_with'])) {
         if (!Helper::authenticate($linkItem)) {
             return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token)));
         }
     }
     $files_list = null;
     if (!is_null($files)) {
         // download selected files
         $files_list = json_decode($files);
         // in case we get only a single file
         if ($files_list === null) {
             $files_list = array($files);
         }
     }
     $originalSharePath = self::getPath($token);
     // Create the activities
     if (isset($originalSharePath) && Filesystem::isReadable($originalSharePath . $path)) {
         $originalSharePath = Filesystem::normalizePath($originalSharePath . $path);
         $isDir = \OC\Files\Filesystem::is_dir($originalSharePath);
         $activities = [];
         if (!$isDir) {
             // Single file public share
             $activities[$originalSharePath] = Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
         } else {
             if (!empty($files_list)) {
                 // Only some files are downloaded
                 foreach ($files_list as $file) {
                     $filePath = Filesystem::normalizePath($originalSharePath . '/' . $file);
                     $isDir = \OC\Files\Filesystem::is_dir($filePath);
                     $activities[$filePath] = $isDir ? Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED : Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
                 }
             } else {
                 // The folder is downloaded
                 $activities[$originalSharePath] = Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
             }
         }
         foreach ($activities as $filePath => $subject) {
             $this->activityManager->publishActivity('files_sharing', $subject, array($filePath), '', array(), $filePath, '', $linkItem['uid_owner'], Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM);
         }
     }
     // download selected files
     if (!is_null($files)) {
         // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
         // after dispatching the request which results in a "Cannot modify header information" notice.
         OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');
         exit;
     } else {
         // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
         // after dispatching the request which results in a "Cannot modify header information" notice.
         OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $_SERVER['REQUEST_METHOD'] == 'HEAD');
         exit;
     }
 }
示例#17
0
 /**
  * Check if the author is the current user
  *
  * @param string $user Parameter e.g. `<user display-name="admin">admin</user>`
  * @return bool
  */
 protected function authorIsCurrentUser($user)
 {
     try {
         return strip_tags($user) === $this->activityManager->getCurrentUserId();
     } catch (\UnexpectedValueException $e) {
         // FIXME this is awkward, but we have no access to the current user in emails
         return false;
     }
 }
示例#18
0
 /**
  * Get a good default setting for a preference
  *
  * @param string $method Should be one of 'stream', 'email' or 'setting'
  * @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
  * @return bool|int
  */
 public function getDefaultSetting($method, $type)
 {
     if ($method === 'setting') {
         if ($type === 'batchtime') {
             return 3600;
         } else {
             if ($type === 'self') {
                 return true;
             } else {
                 if ($type === 'selfemail') {
                     return false;
                 }
             }
         }
     }
     $settings = $this->manager->getDefaultTypes($method);
     return in_array($type, $settings);
 }
示例#19
0
 /**
  * Get all items for the users we want to send an email to
  *
  * @return array Notification data (user => array of rows from the table)
  */
 public function getLinkList()
 {
     $topEntries = array(array('id' => 'all', 'name' => (string) $this->l->t('All Activities'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList')), array('id' => 'self', 'name' => (string) $this->l->t('Activities by you'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'self'))), array('id' => 'by', 'name' => (string) $this->l->t('Activities by others'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'by'))), array('id' => 'shares', 'name' => (string) $this->l->t('Shares'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'shares'))));
     $appFilterEntries = array(array('id' => 'files', 'name' => (string) $this->l->t('Files'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'files'))));
     $additionalEntries = $this->activityManager->getNavigation();
     $topEntries = array_merge($topEntries, $additionalEntries['top']);
     $appFilterEntries = array_merge($appFilterEntries, $additionalEntries['apps']);
     return array('top' => $topEntries, 'apps' => $appFilterEntries);
 }
示例#20
0
 protected function setUp()
 {
     parent::setUp();
     $this->request = $this->getMockBuilder('OCP\\IRequest')->disableOriginalConstructor()->getMock();
     $this->session = $this->getMockBuilder('OCP\\IUserSession')->disableOriginalConstructor()->getMock();
     $this->config = $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock();
     $this->activityHelper = $this->getMockBuilder('OCA\\Files\\ActivityHelper')->disableOriginalConstructor()->getMock();
     $this->activityManager = new \OC\Activity\Manager($this->request, $this->session, $this->config);
     $this->l10nFactory = $this->getMockBuilder('OCP\\L10N\\IFactory')->disableOriginalConstructor()->getMock();
     $deL10n = $this->getMockBuilder('OC_L10N')->disableOriginalConstructor()->getMock();
     $deL10n->expects($this->any())->method('t')->willReturnCallback(function ($argument) {
         return 'translate(' . $argument . ')';
     });
     $this->l10nFactory->expects($this->any())->method('get')->willReturnMap([['files', null, new \OC_L10N('files', 'en')], ['files', 'en', new \OC_L10N('files', 'en')], ['files', 'de', $deL10n]]);
     $this->activityExtension = $activityExtension = new Activity($this->l10nFactory, $this->getMockBuilder('OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(), $this->activityManager, $this->activityHelper, \OC::$server->getDatabaseConnection(), $this->config);
     $this->activityManager->registerExtension(function () use($activityExtension) {
         return $activityExtension;
     });
 }
示例#21
0
 /**
  * Get the prepared activities
  *
  * @return array translated activities ready for use
  */
 public function getActivities()
 {
     $this->closeOpenGroup();
     $return = array();
     foreach ($this->activities as $activity) {
         $activity = $this->dataHelper->formatStrings($activity, 'subject');
         $activity = $this->dataHelper->formatStrings($activity, 'message');
         $activity['typeicon'] = $this->activityManager->getTypeIcon($activity['type']);
         $return[] = $activity;
     }
     return $return;
 }
示例#22
0
 /**
  * List with special parameters for the message
  *
  * @param string $app
  * @param string $text
  * @return array
  */
 public function getSpecialParameterList($app, $text)
 {
     if ($app === 'files' && $text === 'shared_group_self') {
         return array(0 => 'file');
     } else {
         if ($app === 'files') {
             return array(0 => 'file', 1 => 'username');
         }
     }
     $specialParameters = $this->activityManager->getSpecialParameterList($app, $text);
     if ($specialParameters !== false) {
         return $specialParameters;
     }
     return array();
 }
示例#23
0
 /**
  * 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 !== self::FILES_SHARING_APP) {
         return false;
     }
     $l = $this->getL10N($languageCode);
     file_put_contents('trans', print_r($l, true));
     if ($this->activityManager->isFormattingFilteredObject()) {
         $translation = $this->translateShort($text, $l, $params);
         if ($translation !== false) {
             return $translation;
         }
     }
     return $this->translateLong($text, $l, $params);
 }
 /**
  * @dataProvider dataTranslate
  *
  * @param string $app
  * @param string $text
  * @param array $params
  * @param bool $stripPath
  * @param bool $highlightParams
  * @param string $languageCode
  * @param mixed $managerReturn
  * @param string $currentUser
  * @param mixed $expected
  */
 public function testTranslate($app, $text, $params, $stripPath, $highlightParams, $languageCode, $managerReturn, $currentUser, $expected)
 {
     if ($managerReturn === null) {
         $this->manager->expects($this->never())->method('getAnnouncement');
     } else {
         $this->factory->expects($this->any())->method('get')->with('announcementcenter', $languageCode)->willReturn($this->l);
         $this->activity->expects($this->any())->method('getCurrentUserId')->willReturn($currentUser);
         if ($managerReturn === false) {
             $this->manager->expects($this->once())->method('getAnnouncement')->with(10, $highlightParams)->willThrowException(new \InvalidArgumentException());
         } else {
             $this->manager->expects($this->once())->method('getAnnouncement')->with(10, $highlightParams)->willReturn($managerReturn);
         }
     }
     $this->assertSame($expected, $this->extension->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode));
 }
示例#25
0
 /**
  * Get the icon for a given activity type
  *
  * @param string $type
  * @return string CSS class which adds the icon
  */
 public function getTypeIcon($type)
 {
     switch ($type) {
         case Data::TYPE_SHARE_CHANGED:
             return 'icon-change';
         case Data::TYPE_SHARE_CREATED:
             return 'icon-add-color';
         case Data::TYPE_SHARE_DELETED:
             return 'icon-delete-color';
         case Data::TYPE_SHARED:
             return 'icon-share';
     }
     // Allow other apps to add a icon for their notifications
     return $this->activityManager->getTypeIcon($type);
 }
示例#26
0
 /**
  * @dataProvider dataGetEventFromArray
  * @param array $activity
  */
 public function testGetEventFromArray(array $activity)
 {
     $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('setApp')->with($activity['app'])->willReturnSelf();
     $event->expects($this->once())->method('setType')->with($activity['type'])->willReturnSelf();
     $event->expects($this->once())->method('setAffectedUser')->with($activity['affecteduser'])->willReturnSelf();
     $event->expects($this->once())->method('setAuthor')->with($activity['user'])->willReturnSelf();
     $event->expects($this->once())->method('setTimestamp')->with($activity['timestamp'])->willReturnSelf();
     $event->expects($this->once())->method('setSubject')->with($activity['subject'], $activity['subjectparams'])->willReturnSelf();
     $event->expects($this->once())->method('setMessage')->with($activity['message'], $activity['messageparams'])->willReturnSelf();
     $event->expects($this->once())->method('setObject')->with($activity['object_type'], $activity['object_id'], $activity['object_name'])->willReturnSelf();
     $event->expects($this->once())->method('setLink')->with($activity['link'])->willReturnSelf();
     $this->activityManager->expects($this->once())->method('generateEvent')->willReturn($event);
     $helper = $this->getHelper();
     $instance = $helper->getEventFromArray($activity);
     $this->assertSame($event, $instance);
 }
示例#27
0
文件: data.php 项目: samj1912/repo
 /**
  * Verify that the filter is valid
  *
  * @param string $filterValue
  * @return string
  */
 public function validateFilter($filterValue)
 {
     if (!isset($filterValue)) {
         return 'all';
     }
     switch ($filterValue) {
         case 'by':
         case 'self':
         case 'all':
             return $filterValue;
         default:
             if ($this->activityManager->isFilterValid($filterValue)) {
                 return $filterValue;
             }
             return 'all';
     }
 }
 /**
  * @param int $id
  * @param string $authorId
  * @param int $timeStamp
  */
 protected function createPublicity($id, $authorId, $timeStamp)
 {
     $users = $this->userManager->search('');
     $event = $this->activityManager->generateEvent();
     $event->setApp('announcementcenter')->setType('announcementcenter')->setAuthor($authorId)->setTimestamp($timeStamp)->setSubject('announcementsubject#' . $id, [$authorId])->setMessage('announcementmessage#' . $id, [$authorId])->setObject('announcement', $id);
     $dateTime = new \DateTime();
     $dateTime->setTimestamp($timeStamp);
     $notification = $this->notificationManager->createNotification();
     $notification->setApp('announcementcenter')->setDateTime($dateTime)->setObject('announcement', $id)->setSubject('announced', [$authorId])->setLink($this->urlGenerator->linkToRoute('announcementcenter.page.index'));
     foreach ($users as $user) {
         $event->setAffectedUser($user->getUID());
         $this->activityManager->publish($event);
         if ($authorId !== $user->getUID()) {
             $notification->setUser($user->getUID());
             $this->notificationManager->notify($notification);
         }
     }
 }
示例#29
0
	/**
	 * @PublicPage
	 * @NoCSRFRequired
	 *
	 * @param string $token
	 * @param string $files
	 * @param string $path
	 * @return void|RedirectResponse
	 */
	public function downloadShare($token, $files = null, $path = '') {
		\OC_User::setIncognitoMode(true);

		$linkItem = OCP\Share::getShareByToken($token, false);

		// Share is password protected - check whether the user is permitted to access the share
		if (isset($linkItem['share_with'])) {
			if(!Helper::authenticate($linkItem)) {
				return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate',
					array('token' => $token)));
			}
		}

		$originalSharePath = self::getPath($token);

		if (isset($originalSharePath) && Filesystem::isReadable($originalSharePath . $path)) {
			$originalSharePath = Filesystem::normalizePath($originalSharePath . $path);
			$type = \OC\Files\Filesystem::is_dir($originalSharePath) ? 'folder' : 'file';
			$args = $type === 'folder' ? array('dir' => $originalSharePath) : array('dir' => dirname($originalSharePath), 'scrollto' => basename($originalSharePath));
			$linkToFile = \OCP\Util::linkToAbsolute('files', 'index.php', $args);
			$subject = $type === 'folder' ? Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED : Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
			$this->activityManager->publishActivity(
					'files_sharing', $subject, array($originalSharePath), '', array(), $originalSharePath,
					$linkToFile, $linkItem['uid_owner'], Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM);
		}

		if (!is_null($files)) { // download selected files
			$files_list = json_decode($files);
			// in case we get only a single file
			if ($files_list === NULL) {
				$files_list = array($files);
			}

			// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
			// after dispatching the request which results in a "Cannot modify header information" notice.
			OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');
			exit();
		} else {
			// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
			// after dispatching the request which results in a "Cannot modify header information" notice.
			OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $_SERVER['REQUEST_METHOD'] == 'HEAD');
			exit();
		}
	}
示例#30
0
 protected function getGroupParameter($activity)
 {
     if (!$this->allowGrouping) {
         return false;
     }
     if ($activity['app'] === 'files') {
         switch ($activity['subject']) {
             case 'created_self':
             case 'created_by':
             case 'changed_self':
             case 'changed_by':
             case 'deleted_self':
             case 'deleted_by':
                 return 0;
         }
     }
     // Allow other apps to group their notifications
     return $this->activityManager->getGroupParameter($activity);
 }