Esempio 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 = 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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 /**
  * @brief Read a list of events from the activity stream
  * @param GroupHelper $groupHelper Allows activities to be grouped
  * @param UserSettings $userSettings Gets the settings of the user
  * @param int $start The start entry
  * @param int $count The number of statements to read
  * @param string $filter Filter the activities
  * @param string $user User for whom we display the stream
  * @return array
  */
 public function read(GroupHelper $groupHelper, UserSettings $userSettings, $start, $count, $filter = 'all', $user = '')
 {
     // get current user
     $user = $user !== '' ? $user : User::getUser();
     $groupHelper->setUser($user);
     $enabledNotifications = $userSettings->getNotificationTypes($user, 'stream');
     $enabledNotifications = $this->activityManager->filterNotificationTypes($enabledNotifications, $filter);
     $parameters = array_unique($enabledNotifications);
     // We don't want to display any activities
     if (empty($parameters)) {
         return array();
     }
     $placeholders = implode(',', array_fill(0, sizeof($parameters), '?'));
     $limitActivities = " AND `type` IN (" . $placeholders . ")";
     array_unshift($parameters, $user);
     if ($filter === 'self') {
         $limitActivities .= ' AND `user` = ?';
         $parameters[] = $user;
     } else {
         if ($filter === 'by' || $filter === 'all' && !$userSettings->getUserSetting($user, 'setting', 'self')) {
             $limitActivities .= ' AND `user` <> ?';
             $parameters[] = $user;
         }
     }
     list($condition, $params) = $this->activityManager->getQueryForFilter($filter);
     if (!is_null($condition)) {
         $limitActivities .= ' ';
         $limitActivities .= $condition;
         if (is_array($params)) {
             $parameters = array_merge($parameters, $params);
         }
     }
     // fetch from DB
     $query = DB::prepare('SELECT * ' . ' FROM `*PREFIX*activity` ' . ' WHERE `affecteduser` = ? ' . $limitActivities . ' ORDER BY `timestamp` DESC', $count, $start);
     $result = $query->execute($parameters);
     return $this->getActivitiesFromQueryResult($result, $groupHelper);
 }
Esempio n. 4
0
 /**
  * Read a list of events from the activity stream
  *
  * @param GroupHelper $groupHelper Allows activities to be grouped
  * @param UserSettings $userSettings Gets the settings of the user
  * @param string $user User for whom we display the stream
  *
  * @param int $since The integer ID of the last activity that has been seen.
  * @param int $limit How many activities should be returned
  * @param string $sort Should activities be given ascending or descending
  *
  * @param string $filter Filter the activities
  * @param string $objectType Allows to filter the activities to a given object. May only appear together with $objectId
  * @param int $objectId Allows to filter the activities to a given object. May only appear together with $objectType
  *
  * @return array
  *
  * @throws \OutOfBoundsException if the user (Code: 1) or the since (Code: 2) is invalid
  * @throws \BadMethodCallException if the user has selected to display no types for this filter (Code: 3)
  */
 public function get(GroupHelper $groupHelper, UserSettings $userSettings, $user, $since, $limit, $sort, $filter, $objectType = '', $objectId = 0)
 {
     // get current user
     if ($user === '') {
         throw new \OutOfBoundsException('Invalid user', 1);
     }
     $groupHelper->setUser($user);
     $enabledNotifications = $userSettings->getNotificationTypes($user, 'stream');
     $enabledNotifications = $this->activityManager->filterNotificationTypes($enabledNotifications, $filter);
     $enabledNotifications = array_unique($enabledNotifications);
     // We don't want to display any activities
     if (empty($enabledNotifications)) {
         throw new \BadMethodCallException('No settings enabled', 3);
     }
     $query = $this->connection->getQueryBuilder();
     $query->select('*')->from('activity');
     $query->where($query->expr()->eq('affecteduser', $query->createNamedParameter($user)))->andWhere($query->expr()->in('type', $query->createNamedParameter($enabledNotifications, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)));
     if ($filter === 'self') {
         $query->andWhere($query->expr()->eq('user', $query->createNamedParameter($user)));
     } else {
         if ($filter === 'by') {
             $query->andWhere($query->expr()->neq('user', $query->createNamedParameter($user)));
         } else {
             if ($filter === 'all' && !$userSettings->getUserSetting($user, 'setting', 'self')) {
                 $query->andWhere($query->expr()->orX($query->expr()->neq('user', $query->createNamedParameter($user)), $query->expr()->notIn('type', $query->createNamedParameter(['file_created', 'file_changed', 'file_deleted', 'file_restored'], IQueryBuilder::PARAM_STR_ARRAY))));
             } else {
                 if ($filter === 'filter') {
                     if (!$userSettings->getUserSetting($user, 'setting', 'self')) {
                         $query->andWhere($query->expr()->orX($query->expr()->neq('user', $query->createNamedParameter($user)), $query->expr()->notIn('type', $query->createNamedParameter(['file_created', 'file_changed', 'file_deleted', 'file_restored'], IQueryBuilder::PARAM_STR_ARRAY))));
                     }
                     $query->andWhere($query->expr()->eq('object_type', $query->createNamedParameter($objectType)));
                     $query->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId)));
                 }
             }
         }
     }
     list($condition, $params) = $this->activityManager->getQueryForFilter($filter);
     if (!is_null($condition)) {
         // Strip away ' and '
         $condition = substr($condition, 5);
         if (is_array($params)) {
             // Replace ? placeholders with named parameters
             foreach ($params as $param) {
                 $pos = strpos($condition, '?');
                 if ($pos !== false) {
                     $condition = substr($condition, 0, $pos) . $query->createNamedParameter($param) . substr($condition, $pos + 1);
                 }
             }
         }
         $query->andWhere($query->createFunction($condition));
     }
     /**
      * Order and specify the offset
      */
     $sqlSort = $sort === 'asc' ? 'ASC' : 'DESC';
     $headers = $this->setOffsetFromSince($query, $user, $since, $sqlSort);
     $query->orderBy('timestamp', $sqlSort)->addOrderBy('activity_id', $sqlSort);
     $query->setMaxResults($limit + 1);
     $result = $query->execute();
     $hasMore = false;
     while ($row = $result->fetch()) {
         if ($limit === 0) {
             $hasMore = true;
             break;
         }
         $headers['X-Activity-Last-Given'] = (int) $row['activity_id'];
         $groupHelper->addActivity($row);
         $limit--;
     }
     $result->closeCursor();
     return ['data' => $groupHelper->getActivities(), 'has_more' => $hasMore, 'headers' => $headers];
 }
Esempio n. 5
0
 /**
  * @brief Read a list of events from the activity stream
  * @param GroupHelper $groupHelper Allows activities to be grouped
  * @param UserSettings $userSettings Gets the settings of the user
  * @param int $start The start entry
  * @param int $count The number of statements to read
  * @param string $filter Filter the activities
  * @param string $user User for whom we display the stream
  * @param string $objectType
  * @param int $objectId
  * @return array
  */
 public function read(GroupHelper $groupHelper, UserSettings $userSettings, $start, $count, $filter = 'all', $user = '', $objectType = '', $objectId = 0)
 {
     // get current user
     if ($user === '') {
         $user = $this->userSession->getUser();
         if ($user instanceof IUser) {
             $user = $user->getUID();
         } else {
             // No user given and not logged in => no activities
             return [];
         }
     }
     $groupHelper->setUser($user);
     $enabledNotifications = $userSettings->getNotificationTypes($user, 'stream');
     $enabledNotifications = $this->activityManager->filterNotificationTypes($enabledNotifications, $filter);
     $parameters = array_unique($enabledNotifications);
     // We don't want to display any activities
     if (empty($parameters)) {
         return array();
     }
     $placeholders = implode(',', array_fill(0, sizeof($parameters), '?'));
     $limitActivities = " AND `type` IN (" . $placeholders . ")";
     array_unshift($parameters, $user);
     if ($filter === 'self') {
         $limitActivities .= ' AND `user` = ?';
         $parameters[] = $user;
     } else {
         if ($filter === 'by' || $filter === 'all' && !$userSettings->getUserSetting($user, 'setting', 'self')) {
             $limitActivities .= ' AND `user` <> ?';
             $parameters[] = $user;
         } else {
             if ($filter === 'filter') {
                 if (!$userSettings->getUserSetting($user, 'setting', 'self')) {
                     $limitActivities .= ' AND `user` <> ?';
                     $parameters[] = $user;
                 }
                 $limitActivities .= ' AND `object_type` = ?';
                 $parameters[] = $objectType;
                 $limitActivities .= ' AND `object_id` = ?';
                 $parameters[] = $objectId;
             }
         }
     }
     list($condition, $params) = $this->activityManager->getQueryForFilter($filter);
     if (!is_null($condition)) {
         $limitActivities .= ' ';
         $limitActivities .= $condition;
         if (is_array($params)) {
             $parameters = array_merge($parameters, $params);
         }
     }
     return $this->getActivities($count, $start, $limitActivities, $parameters, $groupHelper);
 }