예제 #1
0
파일: display.php 프로젝트: AARNet/activity
 /**
  * Get the template for a specific activity-event in the activities
  *
  * @param array $activity An array with all the activity data in it
  * @return string
  */
 public function show($activity)
 {
     $tmpl = new Template('activity', 'stream.item');
     $tmpl->assign('formattedDate', $this->dateTimeFormatter->formatDateTime($activity['timestamp']));
     $tmpl->assign('formattedTimestamp', Template::relative_modified_date($activity['timestamp']));
     if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
         // We do not link the subject as we create links for the parameters instead
         $activity['link'] = '';
     }
     $tmpl->assign('event', $activity);
     if ($activity['file']) {
         $this->view->chroot('/' . $activity['affecteduser'] . '/files');
         $exist = $this->view->file_exists($activity['file']);
         $is_dir = $this->view->is_dir($activity['file']);
         $tmpl->assign('previewLink', $this->getPreviewLink($activity['file'], $is_dir));
         // show a preview image if the file still exists
         $mimeType = Files::getMimeType($activity['file']);
         if ($mimeType && !$is_dir && $this->preview->isMimeSupported($mimeType) && $exist) {
             $tmpl->assign('previewImageLink', $this->urlGenerator->linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
         } else {
             $mimeTypeIcon = Template::mimetype_icon($is_dir ? 'dir' : $mimeType);
             $mimeTypeIcon = substr($mimeTypeIcon, -4) === '.png' ? substr($mimeTypeIcon, 0, -4) . '.svg' : $mimeTypeIcon;
             $tmpl->assign('previewImageLink', $mimeTypeIcon);
             $tmpl->assign('previewLinkIsDir', true);
         }
     }
     return $tmpl->fetchPage();
 }
예제 #2
0
 /**
  * @return TemplateResponse
  */
 public function displayPanel()
 {
     $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($this->config->getAppValue('core', 'lastupdatedat'));
     $channels = ['daily', 'beta', 'stable', 'production'];
     $currentChannel = \OCP\Util::getChannel();
     // Remove the currently used channel from the channels list
     if (($key = array_search($currentChannel, $channels)) !== false) {
         unset($channels[$key]);
     }
     $updateState = $this->updateChecker->getUpdateState();
     $params = ['isNewVersionAvailable' => $updateState === [] ? false : true, 'lastChecked' => $lastUpdateCheck, 'currentChannel' => $currentChannel, 'channels' => $channels, 'newVersionString' => $updateState === [] ? '' : $updateState['updateVersion']];
     return new TemplateResponse($this->appName, 'admin', $params, '');
 }
예제 #3
0
 /**
  * executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted
  *
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Symfony\Component\Console\Helper\Table $table */
     $table = $this->getHelperSet()->get('table');
     $table->setHeaders(array('ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', 'Dir', 'Sharer'));
     $rows = array();
     $resultSet = $this->dui->getUsers();
     foreach ($resultSet as $user) {
         $hAS = $user->getHasActiveShares() ? 'Y' : 'N';
         $lastLogin = $user->getLastLogin() > 0 ? $this->dateFormatter->formatDate($user->getLastLogin()) : '-';
         $rows[] = array($user->getOCName(), $user->getDisplayName(), $user->getUid(), $user->getDN(), $lastLogin, $user->getHomePath(), $hAS);
     }
     $table->setRows($rows);
     $table->render($output);
 }
 /**
  * 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);
     $this->dataHelper->setUser($userName);
     $this->dataHelper->setL10n($l);
     $activityList = array();
     foreach ($mailData as $activity) {
         $relativeDateTime = $this->dateFormatter->formatDateTimeRelativeDay($activity['amq_timestamp'], 'long', 'medium', new \DateTimeZone($timezone), $l);
         $activityList[] = array($this->dataHelper->translation($activity['amq_appid'], $activity['amq_subject'], $this->dataHelper->getParameters($activity['amq_subjectparams'])), $relativeDateTime);
     }
     $alttext = new Template('activity', 'email.notification', '');
     $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);
 }
예제 #5
0
 /**
  * executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted
  *
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Symfony\Component\Console\Helper\Table $table */
     $table = $this->getHelperSet()->get('table');
     $table->setHeaders(array('ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', 'Dir', 'Sharer'));
     $rows = array();
     $resultSet = $this->dui->getUsers();
     foreach ($resultSet as $user) {
         $hAS = $user->getHasActiveShares() ? 'Y' : 'N';
         $lastLogin = $user->getLastLogin() > 0 ? $this->dateFormatter->formatDate($user->getLastLogin()) : '-';
         $rows[] = array('ocName' => $user->getOCName(), 'displayName' => $user->getDisplayName(), 'uid' => $user->getUID(), 'dn' => $user->getDN(), 'lastLogin' => $lastLogin, 'homePath' => $user->getHomePath(), 'sharer' => $hAS);
     }
     if ($input->getOption('json')) {
         $output->writeln(json_encode($rows));
     } else {
         $table->setRows($rows);
         $table->render($output);
     }
 }
예제 #6
0
 public function fetch($page, $user, $filter = 'all', $objecttype = '', $objectid = 0)
 {
     $pageOffset = $page - 1;
     $filter = $this->data->validateFilter($filter);
     $activities = $this->data->read($this->helper, $this->settings, $pageOffset * self::DEFAULT_PAGE_SIZE, self::DEFAULT_PAGE_SIZE, $filter, $user, $objecttype, $objectid);
     $preparedActivities = [];
     foreach ($activities as $activity) {
         $activity['relativeTimestamp'] = (string) Template::relative_modified_date($activity['timestamp'], true);
         $activity['readableTimestamp'] = (string) $this->dateTimeFormatter->formatDate($activity['timestamp']);
         $activity['relativeDateTimestamp'] = (string) Template::relative_modified_date($activity['timestamp']);
         $activity['readableDateTimestamp'] = (string) $this->dateTimeFormatter->formatDateTime($activity['timestamp']);
         if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
             // We do not link the subject as we create links for the parameters instead
             $activity['link'] = '';
         }
         $activity['previews'] = [];
         if ($activity['object_type'] === 'files' && !empty($activity['files'])) {
             foreach ($activity['files'] as $objectId => $objectName) {
                 if ((int) $objectId === 0 || $objectName === '') {
                     // No file, no preview
                     continue;
                 }
                 $activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $objectId, $objectName);
                 if (sizeof($activity['previews']) >= self::MAX_NUM_THUMBNAILS) {
                     // Don't want to clutter the page, so we stop after a few thumbnails
                     break;
                 }
             }
         } else {
             if ($activity['object_type'] === 'files' && $activity['object_id']) {
                 $activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $activity['object_id'], $activity['file']);
             }
         }
         $preparedActivities[] = $activity;
     }
     return new JSONResponse($preparedActivities);
 }
 public function testDisplayPanelWithoutUpdate()
 {
     $channels = ['daily', 'beta', 'stable', 'production'];
     $currentChannel = \OCP\Util::getChannel();
     // Remove the currently used channel from the channels list
     if (($key = array_search($currentChannel, $channels)) !== false) {
         unset($channels[$key]);
     }
     $this->config->expects($this->exactly(2))->method('getAppValue')->willReturnMap([['core', 'lastupdatedat', '', '12345'], ['updatenotification', 'notify_groups', '["admin"]', '["admin"]']]);
     $this->dateTimeFormatter->expects($this->once())->method('formatDateTime')->with('12345')->willReturn('LastCheckedReturnValue');
     $this->updateChecker->expects($this->once())->method('getUpdateState')->willReturn([]);
     $params = ['isNewVersionAvailable' => false, 'lastChecked' => 'LastCheckedReturnValue', 'currentChannel' => \OCP\Util::getChannel(), 'channels' => $channels, 'newVersionString' => '', 'notify_groups' => 'admin'];
     $expected = new TemplateResponse('updatenotification', 'admin', $params, '');
     $this->assertEquals($expected, $this->adminController->displayPanel());
 }
 /**
  * Send a notification to one user
  *
  * @param string $user 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 array $mailData Notification data we send to the user
  */
 public function sendEmailToUser($user, $email, $lang, $timezone, $mailData)
 {
     $l = $this->getLanguage($lang);
     $dataHelper = new DataHelper(\OC::$server->getActivityManager(), new ParameterHelper(\OC::$server->getActivityManager(), new \OC\Files\View(''), \OC::$server->getConfig(), $l), $l);
     $activityList = array();
     foreach ($mailData as $activity) {
         $relativeDateTime = $this->dateFormatter->formatDateTimeRelativeDay($activity['amq_timestamp'], 'long', 'medium', new \DateTimeZone($timezone), $l);
         $activityList[] = array($dataHelper->translation($activity['amq_appid'], $activity['amq_subject'], unserialize($activity['amq_subjectparams'])), $relativeDateTime);
     }
     $alttext = new \OCP\Template('activity', 'email.notification', '');
     $alttext->assign('username', \OCP\User::getDisplayName($user));
     $alttext->assign('timeframe', $this->getLangForApproximatedTimeFrame($mailData[0]['amq_timestamp']));
     $alttext->assign('activities', $activityList);
     $alttext->assign('owncloud_installation', \OC_Helper::makeURLAbsolute('/'));
     $alttext->assign('overwriteL10N', $l);
     $emailText = $alttext->fetchPage();
     try {
         \OCP\Util::sendMail($email, \OCP\User::getDisplayName($user), $l->t('Activity notification'), $emailText, $this->getSenderData('email'), $this->getSenderData('name'));
     } catch (\Exception $e) {
         \OCP\Util::writeLog('Activity', 'A problem occurred while sending the e-mail. Please revisit your settings.', \OCP\Util::ERROR);
     }
 }