/** * @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>'; }
/** * @param string $owner * @param int $fileId * @param string $filePath * @return array */ protected function getPreview($owner, $fileId, $filePath) { $info = $this->infoCache->getInfoById($owner, $fileId, $filePath); if (!$info['exists'] || $info['view'] !== '') { return $this->getPreviewFromPath($filePath, $info); } $preview = ['link' => $this->getPreviewLink($info['path'], $info['is_dir'], $info['view']), 'source' => '', 'isMimeTypeIcon' => true]; // show a preview image if the file still exists if ($info['is_dir']) { $preview['source'] = $this->getPreviewPathFromMimeType('dir'); } else { $this->view->chroot('/' . $owner . '/files'); $fileInfo = $this->view->getFileInfo($info['path']); if (!$fileInfo instanceof FileInfo) { $pathPreview = $this->getPreviewFromPath($filePath, $info); $preview['source'] = $pathPreview['source']; } else { if ($this->preview->isAvailable($fileInfo)) { $preview['isMimeTypeIcon'] = false; $preview['source'] = $this->urlGenerator->linkToRoute('core_ajax_preview', ['file' => $info['path'], 'c' => $this->view->getETag($info['path']), 'x' => 150, 'y' => 150]); } else { $preview['source'] = $this->getPreviewPathFromMimeType($fileInfo->getMimetype()); } } } return $preview; }
/** * @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>'; }