Esempio n. 1
0
 /**
  * @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>';
 }
Esempio n. 2
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>';
 }
Esempio n. 3
0
 /**
  * Send an event into the activity stream
  *
  * @param IEvent $event
  * @return bool
  */
 public function send(IEvent $event)
 {
     if ($event->getAffectedUser() === '' || $event->getAffectedUser() === null) {
         return false;
     }
     // store in DB
     $queryBuilder = $this->connection->getQueryBuilder();
     $queryBuilder->insert('activity')->values(['app' => $queryBuilder->createParameter('app'), 'subject' => $queryBuilder->createParameter('subject'), 'subjectparams' => $queryBuilder->createParameter('subjectparams'), 'message' => $queryBuilder->createParameter('message'), 'messageparams' => $queryBuilder->createParameter('messageparams'), 'file' => $queryBuilder->createParameter('object_name'), 'link' => $queryBuilder->createParameter('link'), 'user' => $queryBuilder->createParameter('user'), 'affecteduser' => $queryBuilder->createParameter('affecteduser'), 'timestamp' => $queryBuilder->createParameter('timestamp'), 'priority' => $queryBuilder->createParameter('priority'), 'type' => $queryBuilder->createParameter('type'), 'object_type' => $queryBuilder->createParameter('object_type'), 'object_id' => $queryBuilder->createParameter('object_id')])->setParameters(['app' => $event->getApp(), 'type' => $event->getType(), 'affecteduser' => $event->getAffectedUser(), 'user' => $event->getAuthor(), 'timestamp' => (int) $event->getTimestamp(), 'subject' => $event->getSubject(), 'subjectparams' => json_encode($event->getSubjectParameters()), 'message' => $event->getMessage(), 'messageparams' => json_encode($event->getMessageParameters()), 'priority' => IExtension::PRIORITY_MEDIUM, 'object_type' => $event->getObjectType(), 'object_id' => (int) $event->getObjectId(), 'object_name' => $event->getObjectName(), 'link' => $event->getLink()])->execute();
     return true;
 }