From 63451aab50cd6ac74e74da6ca9aa1bfd972262e0 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 27 Feb 2016 15:04:07 +1100 Subject: [PATCH 1/8] Fixes validatePath for Windows (DIRECTORY_SEPARATOR is normalized in code above) --- modules/cms/classes/MediaLibrary.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/cms/classes/MediaLibrary.php b/modules/cms/classes/MediaLibrary.php index 76bfa8aee..6af9352e4 100644 --- a/modules/cms/classes/MediaLibrary.php +++ b/modules/cms/classes/MediaLibrary.php @@ -385,8 +385,8 @@ class MediaLibrary return $path; } - $regexDirectorySeparator = preg_quote(DIRECTORY_SEPARATOR, '/'); - $regexDot = preg_quote('.', '/'); + $regexDirectorySeparator = preg_quote('/', '#'); + $regexDot = preg_quote('.', '#'); $regex = [ // Checks for parent or current directory reference at beginning of path '(^'.$regexDot.'+?'.$regexDirectorySeparator.')', @@ -401,7 +401,7 @@ class MediaLibrary /* * Combine everything to one regex */ - $regex = '/'.implode('|', $regex).'/'; + $regex = '#'.implode('|', $regex).'#'; if (preg_match($regex, $path) !== 0 || strpos($path, '//') !== false) { throw new ApplicationException(Lang::get('cms::lang.media.invalid_path', compact('path'))); } From 387c75c5cdf217c461713493e553041df67deefc Mon Sep 17 00:00:00 2001 From: alekseybobkov Date: Mon, 29 Feb 2016 21:50:07 -0800 Subject: [PATCH 2/8] Fixed a bug where changing a letter case in a folder name in Media Manager deletes the folder. Added ability to move files and folders to the root directory in Media Manager. Fixed a bug where numeric folder names are displayed incorrectly in the folder path in Media Manager. Fixes #1765, fixes #1173, fixes #1085. --- modules/cms/classes/MediaLibrary.php | 57 +++++++++++++++++++++++++--- modules/cms/widgets/MediaManager.php | 5 ++- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/modules/cms/classes/MediaLibrary.php b/modules/cms/classes/MediaLibrary.php index 6af9352e4..b7ea73e08 100644 --- a/modules/cms/classes/MediaLibrary.php +++ b/modules/cms/classes/MediaLibrary.php @@ -218,7 +218,7 @@ class MediaLibrary /** * Returns a list of all directories in the Library, optionally excluding some of them. - * @param array $exclude A list of folders to exclude from the result list/ + * @param array $exclude A list of folders to exclude from the result list. * The folder paths should be specified relative to the Library root. * @return array */ @@ -227,21 +227,28 @@ class MediaLibrary $fullPath = $this->getMediaPath('/'); $folders = $this->getStorageDisk()->allDirectories($fullPath); + $folders = array_unique($folders, SORT_LOCALE_STRING); $result = []; foreach ($folders as $folder) { $folder = $this->getMediaRelativePath($folder); - if (!strlen($folder)) + if (!strlen($folder)) { $folder = '/'; + } - if (Str::startsWith($folder, $exclude)) + if (Str::startsWith($folder, $exclude)) { continue; + } $result[] = $folder; } + if (!in_array('/', $result)) { + array_unshift($result, '/'); + } + return $result; } @@ -335,10 +342,34 @@ class MediaLibrary */ public function moveFolder($originalPath, $newPath) { - if (!$this->copyFolder($originalPath, $newPath)) - return false; + if (Str::lower($originalPath) !== Str::lower($newPath)) { + // If there is no risk that the directory was renamed + // by just changing the letter case in the name - + // copy the directory to the destination path and delete + // the source directory. - $this->deleteFolder($originalPath); + if (!$this->copyFolder($originalPath, $newPath)) { + return false; + } + + $this->deleteFolder($originalPath); + } 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. + + $tempraryDirPath = $this->generateRandomTmpFolderName(dirname($originalPath)); + + if (!$this->copyFolder($originalPath, $tempraryDirPath)) { + $this->deleteFolder($tempraryDirPath); + + return false; + } + + $this->deleteFolder($originalPath); + + return $this->moveFolder($tempraryDirPath, $newPath); + } return true; } @@ -638,4 +669,18 @@ class MediaLibrary return true; } + + protected function generateRandomTmpFolderName($location) + { + $temporaryDirBaseName = time(); + + $tmpPath = $location.'/tmp-'.$temporaryDirBaseName; + + while ($this->folderExists($tmpPath)) { + $temporaryDirBaseName++; + $tmpPath = $location.'/tmp-'.$temporaryDirBaseName; + } + + return $tmpPath; + } } diff --git a/modules/cms/widgets/MediaManager.php b/modules/cms/widgets/MediaManager.php index bbeda53d4..17b8adf31 100644 --- a/modules/cms/widgets/MediaManager.php +++ b/modules/cms/widgets/MediaManager.php @@ -702,11 +702,12 @@ class MediaManager extends WidgetBase $folder = array_pop($path); $result[$folder] = implode('/', $path).'/'.$folder; - if (substr($result[$folder], 0, 1) != '/') + if (substr($result[$folder], 0, 1) != '/') { $result[$folder] = '/'.$result[$folder]; + } } - return array_reverse($result); + return array_reverse($result, true); } protected function setViewMode($viewMode) From 51d1f1a684b187135ff1eb9e8d5e53c16447136a Mon Sep 17 00:00:00 2001 From: kaserv Date: Tue, 1 Mar 2016 10:20:20 +0400 Subject: [PATCH 3/8] issue #1819 --- modules/system/models/MailTemplate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system/models/MailTemplate.php b/modules/system/models/MailTemplate.php index 3b155f056..b4a006e98 100644 --- a/modules/system/models/MailTemplate.php +++ b/modules/system/models/MailTemplate.php @@ -96,7 +96,7 @@ class MailTemplate extends Model $template = self::make(); $template->code = $code; $template->description = $description; - $template->is_custom = false; + $template->is_custom = 0; $template->layout_id = isset($categories[$layoutCode]) ? $categories[$layoutCode] : null; $template->forceSave(); } From 27c7f4d0b86978c79a95c461d7c65d03e3c79567 Mon Sep 17 00:00:00 2001 From: alekseybobkov Date: Wed, 2 Mar 2016 21:10:27 -0800 Subject: [PATCH 4/8] Fixes a bug with inserting Media objects to the rich editor in Safari. Closes #1733 --- .../assets/js/mediamanager-browser-min.js | 4 +++- .../widgets/mediamanager/assets/js/mediamanager.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/cms/widgets/mediamanager/assets/js/mediamanager-browser-min.js b/modules/cms/widgets/mediamanager/assets/js/mediamanager-browser-min.js index 4adbb77ae..09304c99e 100644 --- a/modules/cms/widgets/mediamanager/assets/js/mediamanager-browser-min.js +++ b/modules/cms/widgets/mediamanager/assets/js/mediamanager-browser-min.js @@ -173,7 +173,9 @@ if($item.data('item-type')=='folder'){if(!$item.data('clear-search')) this.gotoFolder($item.data('path')) else{this.resetSearch() this.gotoFolder($item.data('path'),true)}} -else if($item.data('item-type')=='file'){this.$el.trigger('popupcommand',['insert'])}} +else if($item.data('item-type')=='file'){var $html=$(document.documentElement) +if($html.hasClass('safari')&&!$html.hasClass('chrome')){return} +this.$el.trigger('popupcommand',['insert'])}} MediaManager.prototype.isPreviewSidebarVisible=function(){return!this.$el.find('[data-control="preview-sidebar"]').hasClass('hide')} MediaManager.prototype.toggleSidebar=function(ev){var isVisible=this.isPreviewSidebarVisible(),$sidebar=this.$el.find('[data-control="preview-sidebar"]'),$button=$(ev.target) if(!isVisible){$sidebar.removeClass('hide') diff --git a/modules/cms/widgets/mediamanager/assets/js/mediamanager.js b/modules/cms/widgets/mediamanager/assets/js/mediamanager.js index 1a35280b9..26fa98e10 100644 --- a/modules/cms/widgets/mediamanager/assets/js/mediamanager.js +++ b/modules/cms/widgets/mediamanager/assets/js/mediamanager.js @@ -414,7 +414,18 @@ } else if ($item.data('item-type') == 'file') { // Trigger the Insert popup command if a file item - // was double clicked. + // was double clicked or Enter key was pressed. + + var $html = $(document.documentElement) + if ($html.hasClass('safari') && !$html.hasClass('chrome')) { + // Inserting media/link in Safari with Enter key and double click + // is buggy. It causes endless recursion inside the rich editor + // third-party code. + // See https://github.com/octobercms/october/issues/1733 + + return + } + this.$el.trigger('popupcommand', ['insert']) } } From ed1c84b8b149abd6980fbe2c12adb1fcf8eb6786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20G=C3=A1bor?= Date: Fri, 4 Mar 2016 16:50:58 +0100 Subject: [PATCH 5/8] PHPDoc fixes. --- modules/cms/classes/CmsController.php | 1 + modules/cms/classes/CmsObject.php | 6 +++--- modules/cms/classes/CmsObjectCollection.php | 4 +++- modules/cms/classes/ComponentManager.php | 4 ++-- modules/cms/classes/Layout.php | 2 +- modules/cms/classes/MediaLibrary.php | 2 +- modules/cms/classes/ThemeManager.php | 7 ++++--- modules/cms/widgets/MediaManager.php | 14 ++++++++------ 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/modules/cms/classes/CmsController.php b/modules/cms/classes/CmsController.php index f3d96604a..a9b9e5599 100644 --- a/modules/cms/classes/CmsController.php +++ b/modules/cms/classes/CmsController.php @@ -30,6 +30,7 @@ class CmsController extends ControllerBase /** * Extend this object properties upon construction. + * @param Closure $callback */ public static function extend(Closure $callback) { diff --git a/modules/cms/classes/CmsObject.php b/modules/cms/classes/CmsObject.php index 8b6bfccaf..2690a2508 100644 --- a/modules/cms/classes/CmsObject.php +++ b/modules/cms/classes/CmsObject.php @@ -74,7 +74,7 @@ class CmsObject implements ArrayAccess /** * Loads the object from a cache. * This method is used by the CMS in the runtime. If the cache is not found, it is created. - * @param $theme Specifies the theme the object belongs to. + * @param \Cms\Classes\Theme $theme Specifies the theme the object belongs to. * @param string $fileName Specifies the file name, with the extension. * @return mixed Returns a CMS object instance or null if the object wasn't found. */ @@ -149,7 +149,7 @@ class CmsObject implements ArrayAccess /** * Loads the object from a file. * This method is used in the CMS back-end. It doesn't use any caching. - * @param $theme Specifies the theme the object belongs to. + * @param \Cms\Classes\Theme $theme Specifies the theme the object belongs to. * @param string $fileName Specifies the file name, with the extension. * The file name can contain only alphanumeric symbols, dashes and dots. * @return mixed Returns a CMS object instance or null if the object wasn't found. @@ -446,7 +446,7 @@ class CmsObject implements ArrayAccess /** * Returns the absolute file path. - * @param $theme Specifies a theme the file belongs to. + * @param \Cms\Classes\Theme $theme Specifies a theme the file belongs to. * @param string$fileName Specifies the file name to return the path to. * @return string */ diff --git a/modules/cms/classes/CmsObjectCollection.php b/modules/cms/classes/CmsObjectCollection.php index 459908a21..1161ed116 100644 --- a/modules/cms/classes/CmsObjectCollection.php +++ b/modules/cms/classes/CmsObjectCollection.php @@ -13,7 +13,8 @@ class CmsObjectCollection extends CollectionBase { /** * Returns objects that use the supplied component. - * @param string|array $components + * @param string|array $components + * @param null|callback $callback * @return static */ public function withComponent($components, $callback = null) @@ -41,6 +42,7 @@ class CmsObjectCollection extends CollectionBase * Returns objects whose properties match the supplied value. * @param string $property * @param string $value + * @param bool $strict * @return static */ public function where($property, $value, $strict = true) diff --git a/modules/cms/classes/ComponentManager.php b/modules/cms/classes/ComponentManager.php index dc922cd88..6afbaede5 100644 --- a/modules/cms/classes/ComponentManager.php +++ b/modules/cms/classes/ComponentManager.php @@ -1,7 +1,6 @@ * + * @param callable $definitions * @return array Array values are class names. */ public function registerComponents(callable $definitions) @@ -189,7 +189,7 @@ class ComponentManager /** * Makes a component object with properties set. - * @param $name A component class name or code. + * @param string $name A component class name or code. * @param CmsObject $cmsObject The Cms object that spawned this component. * @param array $properties The properties set by the Page or Layout. * @return ComponentBase The component object. diff --git a/modules/cms/classes/Layout.php b/modules/cms/classes/Layout.php index 624c6807e..e42157dbf 100644 --- a/modules/cms/classes/Layout.php +++ b/modules/cms/classes/Layout.php @@ -26,7 +26,7 @@ class Layout extends CmsCompoundObject /** * Initializes the fallback layout. - * @param \Cms\ClassesTheme $theme Specifies a theme the file belongs to. + * @param \Cms\Classes\Theme $theme Specifies a theme the file belongs to. * @return \Cms\Classes\Layout */ public static function initFallback($theme) diff --git a/modules/cms/classes/MediaLibrary.php b/modules/cms/classes/MediaLibrary.php index b7ea73e08..603ab0a1a 100644 --- a/modules/cms/classes/MediaLibrary.php +++ b/modules/cms/classes/MediaLibrary.php @@ -500,7 +500,7 @@ class MediaLibrary /** * Initializes a library item from a path and item type. * @param string $path Specifies the item path relative to the storage disk root. - * @param string $type Specifies the item type. + * @param string $itemType Specifies the item type. * @return mixed Returns the MediaLibraryItem object or NULL if the item is not visible. */ protected function initLibraryItem($path, $itemType) diff --git a/modules/cms/classes/ThemeManager.php b/modules/cms/classes/ThemeManager.php index d3042e940..121627aa6 100644 --- a/modules/cms/classes/ThemeManager.php +++ b/modules/cms/classes/ThemeManager.php @@ -40,7 +40,8 @@ class ThemeManager /** * Flags a theme as being installed, so it is not downloaded twice. - * @param string $name Theme code + * @param string $code Theme code + * @param string|null $dirName */ public function setInstalled($code, $dirName = null) { @@ -55,7 +56,7 @@ class ThemeManager /** * Flags a theme as being uninstalled. - * @param string $name Theme code + * @param string $code Theme code */ public function setUninstalled($code) { @@ -89,7 +90,7 @@ class ThemeManager /** * Completely delete a theme from the system. - * @param string $id Theme code/namespace + * @param string $theme Theme code/namespace * @return void */ public function deleteTheme($theme) diff --git a/modules/cms/widgets/MediaManager.php b/modules/cms/widgets/MediaManager.php index 17b8adf31..3953a2eaf 100644 --- a/modules/cms/widgets/MediaManager.php +++ b/modules/cms/widgets/MediaManager.php @@ -671,12 +671,12 @@ class MediaManager extends WidgetBase protected function setSidebarVisible($visible) { - return $this->putSession('sideba_visible', !!$visible); + return $this->putSession('sidebar_visible', !!$visible); } protected function getSidebarVisible() { - return $this->getSession('sideba_visible', true); + return $this->getSession('sidebar_visible', true); } protected function itemTypeToIconClass($item, $itemType) @@ -1020,10 +1020,10 @@ class MediaManager extends WidgetBase /** * Creates a slug form the string. A modified version of Str::slug * with the main difference that it accepts @-signs - * @param string + * @param string $title * @return string */ - protected function cleanFileName($name) + protected function cleanFileName($title) { $title = Str::ascii($title); @@ -1083,7 +1083,8 @@ class MediaManager extends WidgetBase 'url' => $url, 'dimensions' => $dimensions ]; - } else { + } + else { // If the target dimensions are provided, resize the original image and return its URL // and dimensions. @@ -1107,7 +1108,8 @@ class MediaManager extends WidgetBase 'dimensions' => $dimensions ]; } - } catch (Exception $ex) { + } + catch (Exception $ex) { if ($sessionDirectoryCreated) @File::deleteDirectory($fullSessionDirectoryPath); From fcfcb96d0dd90a49b3ca7454e3cb72e65e9cf171 Mon Sep 17 00:00:00 2001 From: Scott Bedard Date: Sun, 6 Mar 2016 02:29:57 -0700 Subject: [PATCH 6/8] Add ctrl+click support for rowlinks Ctrl+click is supported pretty well in the backend, this adds it to rowlinks as well. --- modules/system/assets/ui/js/list.rowlink.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/system/assets/ui/js/list.rowlink.js b/modules/system/assets/ui/js/list.rowlink.js index d61038b81..d7d77207f 100644 --- a/modules/system/assets/ui/js/list.rowlink.js +++ b/modules/system/assets/ui/js/list.rowlink.js @@ -1,6 +1,6 @@ /* * Table row linking plugin - * + * * Data attributes: * - data-control="rowlink" - enables the plugin on an element * @@ -36,9 +36,11 @@ var href = link.attr('href'), onclick = (typeof link.get(0).onclick == "function") ? link.get(0).onclick : null - $(this).find('td').not('.' + options.excludeClass).click(function() { + $(this).find('td').not('.' + options.excludeClass).click(function(e) { if (onclick) onclick.apply(link.get(0)) + else if (e.ctrlKey) + window.open(href); else window.location = href; }) @@ -88,4 +90,4 @@ $('[data-control="rowlink"]').rowLink() }) -}(window.jQuery); \ No newline at end of file +}(window.jQuery); From 4f6d7d69a4d23b4f9c8e224cfe21af17e2b68c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20C=C3=A1nepa?= Date: Tue, 8 Mar 2016 07:14:58 -0300 Subject: [PATCH 7/8] Fix date to 2016 --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b68fa0909..8981616e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ -* **Build 317** (2015-02-24) +* **Build 317** (2016-02-24) - The `/404` route now returns 404 HTTP response code as it should. - Updated the `.htaccess` file with a minor security precaution. -* **Build 316** (2015-02-11) +* **Build 316** (2016-02-11) - Various back-end UI enhancements used for the [Builder plugin](http://octobercms.com/plugin/rainlab-builder). * **Build 313** (2015-12-12) From 2a3a63857c1f6dd403d17908bea6faa0bf0bbb4d Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Mon, 21 Mar 2016 19:13:01 +1100 Subject: [PATCH 8/8] text/javascript is obsolete. Fixes #1847 --- modules/system/classes/CombineAssets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system/classes/CombineAssets.php b/modules/system/classes/CombineAssets.php index dd0081627..b5bd6e19d 100644 --- a/modules/system/classes/CombineAssets.php +++ b/modules/system/classes/CombineAssets.php @@ -175,7 +175,7 @@ class CombineAssets $combiner = $this->prepareCombiner($cacheInfo['files']); $contents = $combiner->dump(); - $mime = ($cacheInfo['extension'] == 'css') ? 'text/css' : 'text/javascript'; + $mime = ($cacheInfo['extension'] == 'css') ? 'text/css' : 'application/javascript'; header_remove(); $response = Response::make($contents);