diff options
author | Olivier Paroz <github@oparoz.com> | 2015-06-01 00:10:44 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-06-01 00:10:44 +0300 |
commit | 833b519f984282e42e26e169601a35727d2e4dd0 (patch) | |
tree | a5871c185e6c7bce476b0c43e8c1894a073fd5f4 | |
parent | 80c1016d8cd9bf2ab0e7e516f3074aea5c6a96a5 (diff) |
Merge fixes
-rw-r--r-- | controller/pathmanipulation.php | 55 | ||||
-rw-r--r-- | environment/environment.php | 58 | ||||
-rw-r--r-- | js/gallery.js | 2 | ||||
-rw-r--r-- | js/galleryfileaction.js | 10 | ||||
-rw-r--r-- | js/slideshow.js | 82 | ||||
-rw-r--r-- | service/downloadservice.php | 14 |
6 files changed, 100 insertions, 121 deletions
diff --git a/controller/pathmanipulation.php b/controller/pathmanipulation.php new file mode 100644 index 00000000..2b697a4f --- /dev/null +++ b/controller/pathmanipulation.php @@ -0,0 +1,55 @@ +<?php +/** + * ownCloud - galleryplus + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Olivier Paroz <owncloud@interfasys.ch> + * + * @copyright Olivier Paroz 2015 + */ + +namespace OCA\GalleryPlus\Controller; + +use OCP\AppFramework\Http; + +/** + * @package OCA\GalleryPlus\Controller + */ +trait PathManipulation { + + /** + * Returns a shortened path for the gallery view + * + * We only want to keep one folder between the current folder and the found media file + * /root/folder/sub1/sub2/file.ext + * becomes + * /root/folder/file.ext + * + * @param string $path the full path to a file, which never starts with a slash + * @param string $currFolderPath the current folder, which never starts with a slash + * + * @return string + */ + public function getReducedPath($path, $currFolderPath) { + // Adding a slash to make sure we don't cut a folder in half + if ($currFolderPath) { + $currFolderPath .= '/'; + $relativePath = str_replace($currFolderPath, '', $path); + } else { + $relativePath = $path; + } + + $subFolders = explode('/', $relativePath); + + if (count($subFolders) > 2) { + $reducedPath = $currFolderPath . $subFolders[0] . '/' . array_pop($subFolders); + } else { + $reducedPath = $path; + } + + return $reducedPath; + } + +} diff --git a/environment/environment.php b/environment/environment.php index cc8a29dd..94f5180f 100644 --- a/environment/environment.php +++ b/environment/environment.php @@ -153,7 +153,34 @@ class Environment { return $this->getResourceFromId($node->getId()); } - + + /** + * Returns the Node based on the current user's files folder and a given + * path + * + * @param string $path + * + * @return File|Folder + * + * @throws EnvironmentException + */ + public function getNode($path) { + $node = false; + $folder = $this->userFolder; + if ($folder === null) { + $this->logAndThrowNotFound("Could not access the user's folder"); + } else { + try { + $node = $folder->get($path); + } catch (NotFoundException $exception) { + $message = 'Could not find anything at: ' . $exception->getMessage(); + $this->logAndThrowNotFound($message); + } + } + + return $node; + } + /** * Returns the resource identified by the given ID * @@ -297,33 +324,6 @@ class Environment { } /** - * Returns the Node based on the current user's files folder and a given - * path - * - * @param string $path - * - * @return File|Folder - * - * @throws EnvironmentException - */ - private function getNode($path) { - $node = false; - $folder = $this->userFolder; - if ($folder === null) { - $this->logAndThrowNotFound("Could not access the user's folder"); - } else { - try { - $node = $folder->get($path); - } catch (NotFoundException $exception) { - $message = 'Could not find anything at: ' . $exception->getMessage(); - $this->logAndThrowNotFound($message); - } - } - - return $node; - } - - /** * Returns the path which goes from the file, up to the user folder, based on a path: * parent_folder/current_folder/my_file * @@ -343,7 +343,7 @@ class Environment { return $origShareRelPath; } - + /** * Logs the error and raises an exception * diff --git a/js/gallery.js b/js/gallery.js index c476014a..b3a23944 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -283,7 +283,7 @@ Gallery.slideShow = function (images, startImage, autoPlay) { var start = images.indexOf(startImage); images = images.map(function (image) { var name = OC.basename(image.path); - var previewUrl = Gallery.utility.getPreviewUrl(image.fileId); + var previewUrl = Gallery.utility.getPreviewUrl(image.fileId, image.etag); var downloadUrl = previewUrl + '&download'; return { diff --git a/js/galleryfileaction.js b/js/galleryfileaction.js index 5d2a7c42..e8205f2e 100644 --- a/js/galleryfileaction.js +++ b/js/galleryfileaction.js @@ -69,18 +69,18 @@ var galleryFileAction = { if (galleryFileAction.mediaTypes[file.mimetype]) { /* jshint camelcase: false */ var params = { - file: dir + file.name, + width: width, + height: height, c: file.etag, - x: width, - y: height, requesttoken: oc_requesttoken }; - imageUrl = galleryFileAction.buildGalleryUrl('preview', '', params); - downloadUrl = galleryFileAction.buildGalleryUrl('download', '', params); + imageUrl = galleryFileAction.buildGalleryUrl('preview', '/' + file.id, params); + downloadUrl = imageUrl + '&download'; images.push({ name: file.name, path: dir + file.name, + fileId: file.id, mimeType: file.mimetype, url: imageUrl, downloadUrl: downloadUrl diff --git a/js/slideshow.js b/js/slideshow.js index dee0ed44..ab211b76 100644 --- a/js/slideshow.js +++ b/js/slideshow.js @@ -330,86 +330,4 @@ $(document).ready(function () { }).fail(function () { OC.Notification.show(t('core', 'Error loading slideshow template')); }); - - if (OCA.Files && OCA.Files.fileActions) { - // This is still required in OC8 - var requestToken; - if ($('#filesApp').val() && $('#isPublic').val()) { - // That's the only way to get one with the broken template - requestToken = $('#publicUploadRequestToken').val(); - } else if ($('#gallery').data('requesttoken')) { - requestToken = $('#gallery').data('requesttoken'); - } else { - requestToken = oc_requesttoken; - } - $(document).on('ajaxSend', function (elm, xhr) { - xhr.setRequestHeader('requesttoken', requestToken); - }); - - var prepareFileActions = function (mime) { - return OCA.Files.fileActions.register(mime, 'View', OC.PERMISSION_READ, '', - function (filename, context) { - var imageUrl, downloadUrl; - var fileList = context.fileList; - var files = fileList.files; - var start = 0; - var images = []; - var dir = context.dir + '/'; - var width = Math.floor($(window).width() * window.devicePixelRatio); - var height = Math.floor($(window).height() * window.devicePixelRatio); - - for (var i = 0; i < files.length; i++) { - var file = files[i]; - // We only add images to the slideshow if we think we'll be able - // to generate previews for this media type - if (file.isPreviewAvailable || file.mimetype === 'image/svg+xml') { - var params = { - width: width, - height: height, - requesttoken: requestToken - }; - imageUrl = SlideShow.buildGalleryUrl('preview', '/' + file.id, params); - downloadUrl = imageUrl + '&download'; - - images.push({ - name: file.name, - path: dir + file.name, - fileId: file.id, - mimeType: file.mimetype, - url: imageUrl, - downloadUrl: downloadUrl - }); - } - } - for (i = 0; i < images.length; i++) { - //console.log("Images in the slideshow : ", images[i]); - if (images[i].name === filename) { - start = i; - } - } - var slideShow = new SlideShow($('#slideshow'), images); - slideShow.onStop = function () { - location.hash = ''; - }; - slideShow.init(); - slideShow.show(start); - }); - }; - - var url = SlideShow.buildGalleryUrl('mediatypes', '', {slideshow: 1}); - // We're asking for a list of supported media types. Media files are retrieved through the - // context - $.getJSON(url).then(function (mediaTypes) { - //console.log("enabledPreviewProviders: ", mediaTypes); - SlideShow.mediaTypes = mediaTypes; - - // We only want to create slideshows for supported media types - for (var i = 0, keys = Object.keys(mediaTypes); i < keys.length; i++) { - // Each click handler gets the same function and images array and - // is responsible to load the slideshow - prepareFileActions(keys[i]); - OCA.Files.fileActions.setDefault(keys[i], 'View'); - } - }); - } }); diff --git a/service/downloadservice.php b/service/downloadservice.php index 0914c190..88279170 100644 --- a/service/downloadservice.php +++ b/service/downloadservice.php @@ -34,12 +34,18 @@ class DownloadService extends Service { * * @throws NotFoundServiceException */ - public function downloadFile($file, $base64Encode = false) { - $this->logger->debug( - "[DownloadService] File to Download: {name}", ['name' => $file->getName()] - ); + public function downloadFile($file = null, $base64Encode = false) { $download = false; try { + // If no file is given, we try to get it from the token + if (is_null($file)) { + $this->logger->debug("[DownloadService] File to Download: File linked with token"); + $file = $this->environment->getResourceFromPath(''); + } else { + $this->logger->debug( + "[DownloadService] File to Download: {name}", ['name' => $file->getName()] + ); + } $download = [ 'preview' => $file->getContent(), 'mimetype' => $file->getMimeType() |