示例#1
0
 /**
  * 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
 /**
  * Gets a thumbnail of the specified file
  *
  * @since API version 1.0
  *
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @param int $x
  * @param int $y
  * @param string $file URL-encoded filename
  * @return DataResponse|DataDisplayResponse
  */
 public function getThumbnail($x, $y, $file)
 {
     if ($x < 1 || $y < 1) {
         return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
     }
     $preview = $this->previewManager->createPreview('files/' . $file, $x, $y, true);
     if ($preview->valid()) {
         return new DataDisplayResponse($preview->data(), Http::STATUS_OK, ['Content-Type' => 'image/png']);
     } else {
         return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
     }
 }
示例#3
0
 /**
  * @dataProvider dataGetPreview
  *
  * @param string $author
  * @param int $fileId
  * @param string $path
  * @param string $returnedPath
  * @param bool $isDir
  * @param bool $isMimeSup
  * @param string $source
  * @param bool $isMimeTypeIcon
  */
 public function testGetPreview($author, $fileId, $path, $returnedPath, $isDir, $isMimeSup, $source, $isMimeTypeIcon)
 {
     $controller = $this->getController(['getPreviewLink', 'getPreviewPathFromMimeType']);
     $this->infoCache->expects($this->once())->method('getInfoById')->with($author, $fileId, $path)->willReturn(['path' => $returnedPath, 'exists' => true, 'is_dir' => $isDir, 'view' => '']);
     $controller->expects($this->once())->method('getPreviewLink')->with($returnedPath, $isDir)->willReturnCallback(function ($path) {
         return '/preview' . $path;
     });
     if ($isDir) {
         $controller->expects($this->once())->method('getPreviewPathFromMimeType')->with('dir')->willReturn('/preview/dir');
     } else {
         $fileInfo = $this->getMockBuilder('OCP\\Files\\FileInfo')->disableOriginalConstructor()->getMock();
         $this->view->expects($this->once())->method('chroot')->with('/' . $author . '/files');
         $this->view->expects($this->once())->method('getFileInfo')->with($returnedPath)->willReturn($fileInfo);
         $this->preview->expects($this->once())->method('isAvailable')->with($fileInfo)->willReturn($isMimeSup);
         if (!$isMimeSup) {
             $fileInfo->expects($this->once())->method('getMimetype')->willReturn('audio/mp3');
             $controller->expects($this->once())->method('getPreviewPathFromMimeType')->with('audio/mp3')->willReturn('/preview/mpeg');
         } else {
             $this->urlGenerator->expects($this->once())->method('linkToRoute')->with('core_ajax_preview', $this->anything())->willReturnCallback(function () use($returnedPath) {
                 return '/preview' . $returnedPath;
             });
         }
     }
     $this->assertSame(['link' => '/preview' . $returnedPath, 'source' => $source, 'isMimeTypeIcon' => $isMimeTypeIcon], $this->invokePrivate($controller, 'getPreview', [$author, $fileId, $path]));
 }
示例#4
0
 /**
  * @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 string $owner
  * @param int $fileId
  * @param string $filePath
  * @return array
  */
 protected function getPreview($owner, $fileId, $filePath)
 {
     $this->view->chroot('/' . $owner . '/files');
     $path = $this->view->getPath($fileId);
     if ($path === null || $path === '' || !$this->view->file_exists($path)) {
         return $this->getPreviewFromPath($filePath);
     }
     $is_dir = $this->view->is_dir($path);
     $preview = ['link' => $this->getPreviewLink($path, $is_dir), 'source' => '', 'isMimeTypeIcon' => true];
     // show a preview image if the file still exists
     if ($is_dir) {
         $preview['source'] = $this->getPreviewPathFromMimeType('dir');
     } else {
         $fileInfo = $this->view->getFileInfo($path);
         if ($this->preview->isAvailable($fileInfo)) {
             $preview['isMimeTypeIcon'] = false;
             $preview['source'] = $this->urlGenerator->linkToRoute('core_ajax_preview', ['file' => $path, 'c' => $this->view->getETag($path), 'x' => 150, 'y' => 150]);
         } else {
             $preview['source'] = $this->getPreviewPathFromMimeType($fileInfo->getMimetype());
         }
     }
     return $preview;
 }
示例#6
0
 public function testGetThumbnail()
 {
     $this->preview->expects($this->once())->method('createPreview')->with('files/known.jpg', 10, 10, true)->willReturn(new Image(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
     $ret = $this->apiController->getThumbnail(10, 10, 'known.jpg');
     $this->assertEquals(Http::STATUS_OK, $ret->getStatus());
 }
示例#7
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $token
  * @param string $path
  * @return TemplateResponse|RedirectResponse
  * @throws NotFoundException
  */
 public function showShare($token, $path = '')
 {
     \OC_User::setIncognitoMode(true);
     // Check whether share exists
     try {
         $share = $this->shareManager->getShareByToken($token);
     } catch (\OC\Share20\Exception\ShareNotFound $e) {
         return new NotFoundResponse();
     }
     // Share is password protected - check whether the user is permitted to access the share
     if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
         return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token)));
     }
     // We can't get the path of a file share
     if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
         throw new NotFoundException();
     }
     $rootFolder = null;
     if ($share->getNode() instanceof \OCP\Files\Folder) {
         /** @var \OCP\Files\Folder $rootFolder */
         $rootFolder = $share->getNode();
         try {
             $path = $rootFolder->get($path);
         } catch (\OCP\Files\NotFoundException $e) {
             throw new NotFoundException();
         }
     }
     $shareTmpl = [];
     $shareTmpl['displayName'] = $share->getShareOwner()->getDisplayName();
     $shareTmpl['owner'] = $share->getShareOwner()->getUID();
     $shareTmpl['filename'] = $share->getNode()->getName();
     $shareTmpl['directory_path'] = $share->getTarget();
     $shareTmpl['mimetype'] = $share->getNode()->getMimetype();
     $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
     $shareTmpl['dirToken'] = $token;
     $shareTmpl['sharingToken'] = $token;
     $shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled();
     $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
     $shareTmpl['dir'] = '';
     $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
     $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
     // Show file list
     if ($share->getNode() instanceof \OCP\Files\Folder) {
         $shareTmpl['dir'] = $rootFolder->getRelativePath($path->getPath());
         /*
          * The OC_Util methods require a view. This just uses the node API
          */
         $freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath());
         if ($freeSpace !== \OCP\Files\FileInfo::SPACE_UNKNOWN) {
             $freeSpace = max($freeSpace, 0);
         } else {
             $freeSpace = INF > 0 ? INF : PHP_INT_MAX;
             // work around https://bugs.php.net/bug.php?id=69188
         }
         $uploadLimit = Util::uploadLimit();
         $maxUploadFilesize = min($freeSpace, $uploadLimit);
         $folder = new Template('files', 'list', '');
         $folder->assign('dir', $rootFolder->getRelativePath($path->getPath()));
         $folder->assign('dirToken', $token);
         $folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
         $folder->assign('isPublic', true);
         $folder->assign('publicUploadEnabled', 'no');
         $folder->assign('uploadMaxFilesize', $maxUploadFilesize);
         $folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
         $folder->assign('freeSpace', $freeSpace);
         $folder->assign('uploadLimit', $uploadLimit);
         // PHP upload limit
         $folder->assign('usedSpacePercent', 0);
         $folder->assign('trash', false);
         $shareTmpl['folder'] = $folder->fetchPage();
     }
     $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
     $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
     $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
     $csp = new OCP\AppFramework\Http\ContentSecurityPolicy();
     $csp->addAllowedFrameDomain('\'self\'');
     $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
     $response->setContentSecurityPolicy($csp);
     return $response;
 }