From 3be6dafa6bd982ec8b0fe4740b1a9cec293134a5 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Fri, 2 Jun 2017 20:16:26 +1000 Subject: [PATCH] Fixes int folder name showing as 0 Fixes #2902 Code dusting --- modules/backend/layouts/_browser_detector.htm | 2 +- modules/cms/classes/MediaLibrary.php | 47 ++++++++++++------- modules/cms/widgets/MediaManager.php | 5 +- .../mediamanager/partials/_folder-path.htm | 8 ++-- modules/system/assets/ui/js/drag.scroll.js | 6 +-- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/modules/backend/layouts/_browser_detector.htm b/modules/backend/layouts/_browser_detector.htm index c59afdc0e..8739da66b 100644 --- a/modules/backend/layouts/_browser_detector.htm +++ b/modules/backend/layouts/_browser_detector.htm @@ -43,7 +43,7 @@ if(!preg_match('/opera|webtv/i', $ua) && preg_match('/msie\s(\d)/', $ua, $array) $b[] = $g; } -// platform +// platform if(strstr($ua, 'j2me')) { $b[] = $m . ' j2me'; } else if(strstr($ua, 'iphone')) { diff --git a/modules/cms/classes/MediaLibrary.php b/modules/cms/classes/MediaLibrary.php index c4dbf73eb..6ea0ec655 100644 --- a/modules/cms/classes/MediaLibrary.php +++ b/modules/cms/classes/MediaLibrary.php @@ -156,10 +156,12 @@ class MediaLibrary $folderContents = $this->listFolderContents($folder, $sortBy, $filter); foreach ($folderContents as $item) { - if ($item->type == MediaLibraryItem::TYPE_FOLDER) + if ($item->type == MediaLibraryItem::TYPE_FOLDER) { $findInFolder($item->path); - elseif ($this->pathMatchesSearch($item->path, $words)) - $result[] = $item; + } + elseif ($this->pathMatchesSearch($item->path, $words)) { + $result[] = $item; + } } }; @@ -224,8 +226,9 @@ class MediaLibrary $folders = $this->getStorageDisk()->directories($fullPath); foreach ($folders as $folder) { - if (basename($folder) == $folderName) + if (basename($folder) == $folderName) { return true; + } } return false; @@ -326,21 +329,24 @@ class MediaLibrary $destPath = self::validatePath($destPath); $fullDestPath = $this->getMediaPath($destPath); - if (!$disk->makeDirectory($fullDestPath)) + if (!$disk->makeDirectory($fullDestPath)) { return false; + } $folderContents = $this->scanFolderContents($fullSrcPath); foreach ($folderContents['folders'] as $dirInfo) { - if (!$copyDirectory($dirInfo->path, $destPath.'/'.basename($dirInfo->path))) + if (!$copyDirectory($dirInfo->path, $destPath.'/'.basename($dirInfo->path))) { return false; + } } foreach ($folderContents['files'] as $fileInfo) { $fullFileSrcPath = $this->getMediaPath($fileInfo->path); - if (!$disk->copy($fullFileSrcPath, $fullDestPath.'/'.basename($fileInfo->path))) + if (!$disk->copy($fullFileSrcPath, $fullDestPath.'/'.basename($fileInfo->path))) { return false; + } } return true; @@ -368,7 +374,8 @@ class MediaLibrary } $this->deleteFolder($originalPath); - } else { + } + else { // If there's a risk that the directory name was updated // by changing the letter case - swap source and destination // using a temporary directory with random name. @@ -496,8 +503,9 @@ class MediaLibrary { $path = self::validatePath($path, true); - if (substr($path, 0, $this->storageFolderNameLength) == $this->storageFolder) + if (substr($path, 0, $this->storageFolderNameLength) == $this->storageFolder) { return substr($path, $this->storageFolderNameLength); + } throw new SystemException(sprintf('Cannot convert Media Library path "%s" to a path relative to the Library root.', $path)); } @@ -534,8 +542,9 @@ class MediaLibrary { $relativePath = $this->getMediaRelativePath($path); - if (!$this->isVisible($relativePath)) + if (!$this->isVisible($relativePath)) { return; + } /* * S3 doesn't allow getting the last modified timestamp for folders, @@ -596,14 +605,16 @@ class MediaLibrary $files = $this->getStorageDisk()->files($fullFolderPath); foreach ($files as $file) { - if ($libraryItem = $this->initLibraryItem($file, MediaLibraryItem::TYPE_FILE)) + if ($libraryItem = $this->initLibraryItem($file, MediaLibraryItem::TYPE_FILE)) { $result['files'][] = $libraryItem; + } } $folders = $this->getStorageDisk()->directories($fullFolderPath); foreach ($folders as $folder) { - if ($libraryItem = $this->initLibraryItem($folder, MediaLibraryItem::TYPE_FOLDER)) + if ($libraryItem = $this->initLibraryItem($folder, MediaLibraryItem::TYPE_FOLDER)) { $result['folders'][] = $libraryItem; + } } return $result; @@ -652,8 +663,9 @@ class MediaLibrary $result = []; foreach ($itemList as $item) { - if ($item->getFileType() == $filter) + if ($item->getFileType() == $filter) { $result[] = $item; + } } $itemList = $result; @@ -668,8 +680,9 @@ class MediaLibrary */ protected function getStorageDisk() { - if ($this->storageDisk) + if ($this->storageDisk) { return $this->storageDisk; + } return $this->storageDisk = Storage::disk( Config::get('cms.storage.media.disk', 'local') @@ -688,11 +701,13 @@ class MediaLibrary foreach ($words as $word) { $word = trim($word); - if (!strlen($word)) + if (!strlen($word)) { continue; + } - if (!Str::contains($path, $word)) + if (!Str::contains($path, $word)) { return false; + } } return true; diff --git a/modules/cms/widgets/MediaManager.php b/modules/cms/widgets/MediaManager.php index 5d863c14e..77b08b599 100644 --- a/modules/cms/widgets/MediaManager.php +++ b/modules/cms/widgets/MediaManager.php @@ -50,6 +50,9 @@ class MediaManager extends WidgetBase */ public $cropAndInsertButton = false; + /** + * Constructor. + */ public function __construct($controller, $alias) { $this->alias = $alias; @@ -784,7 +787,7 @@ class MediaManager extends WidgetBase } } - return array_reverse($result); + return array_reverse($result, true); } protected function setViewMode($viewMode) diff --git a/modules/cms/widgets/mediamanager/partials/_folder-path.htm b/modules/cms/widgets/mediamanager/partials/_folder-path.htm index 7a3485254..ab7641534 100644 --- a/modules/cms/widgets/mediamanager/partials/_folder-path.htm +++ b/modules/cms/widgets/mediamanager/partials/_folder-path.htm @@ -1,13 +1,13 @@ \ No newline at end of file diff --git a/modules/system/assets/ui/js/drag.scroll.js b/modules/system/assets/ui/js/drag.scroll.js index 6a9fa95eb..791562be3 100644 --- a/modules/system/assets/ui/js/drag.scroll.js +++ b/modules/system/assets/ui/js/drag.scroll.js @@ -136,7 +136,7 @@ startOffset = self.options.vertical ? $el.scrollTop() : $el.scrollLeft() if (Modernizr.touch) { - $(window).on('touchmove.dragScroll', function(event){ + $(window).on('touchmove.dragScroll', function(event) { var touchEvent = event.originalEvent moveDrag(touchEvent.touches[0]) if (!isNative) { @@ -149,12 +149,12 @@ }) } - $(window).on('mousemove.dragScroll', function(event){ + $(window).on('mousemove.dragScroll', function(event) { moveDrag(event) return false }) - $(window).on('mouseup.dragScroll', function(mouseUpEvent){ + $(window).on('mouseup.dragScroll', function(mouseUpEvent) { var isClick = event.pageX == mouseUpEvent.pageX && event.pageY == mouseUpEvent.pageY stopDrag(isClick) return false