From b6d11d5fa256eb95445ddec19c69e7701b9d019c Mon Sep 17 00:00:00 2001 From: Justin Hoffman Date: Mon, 7 Dec 2015 11:00:04 -0600 Subject: [PATCH 1/5] new elfinder instance config variable --- DependencyInjection/Configuration.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a64b209..53056a2 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -47,6 +47,16 @@ public function getConfigTreeBuilder() ->scalarNode('tinymce_popup_path')->defaultValue('')->end() ->booleanNode('relative_path')->defaultTrue()->end() ->scalarNode('path_prefix')->defaultValue('/')->end() + ->arrayNode('visible_mime_types') + ->beforeNormalization() + ->ifTrue(function ($v) { return is_string($v); }) + ->then(function ($v) { + return array_map('trim', explode(',', $v)); + }) + ->end() + ->prototype('scalar')->end() + ->defaultValue(array()) + ->end() ->arrayNode('connector') ->addDefaultsIfNotSet() ->fixXmlConfig('root') From 60123ef9f8f2d6c44ff449a526e579e15f0f5065 Mon Sep 17 00:00:00 2001 From: Justin Hoffman Date: Mon, 7 Dec 2015 11:07:20 -0600 Subject: [PATCH 2/5] convert visible_mime_types variable to JS array, and pass to templates --- Controller/ElFinderController.php | 12 ++++++++++++ Resources/views/Elfinder/ckeditor.html.twig | 1 + Resources/views/Elfinder/elfinder_type.html.twig | 1 + Resources/views/Elfinder/fm_tinymce.html.twig | 1 + Resources/views/Elfinder/simple.html.twig | 3 ++- Resources/views/Elfinder/summernote.html.twig | 1 + Resources/views/Elfinder/tinymce.html.twig | 1 + Resources/views/Elfinder/tinymce4.html.twig | 1 + 8 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Controller/ElFinderController.php b/Controller/ElFinderController.php index b462b1a..ef884f9 100644 --- a/Controller/ElFinderController.php +++ b/Controller/ElFinderController.php @@ -60,6 +60,10 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, $pathPrefix = $parameters['path_prefix']; $includeAssets = $parameters['include_assets']; $theme = $parameters['theme']; + // convert to javascript array + $onlyMimes = count($parameters['visible_mime_types']) + ? "['" . implode("','", $parameters['visible_mime_types']) . "']" + : '[]'; $result = array(); switch ($editor) { @@ -79,6 +83,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'prefix' => $assetsPath, 'theme' => $theme, 'pathPrefix' => $pathPrefix, + 'onlyMimes' => $onlyMimes, ); return $result; @@ -94,6 +99,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'prefix' => $assetsPath, 'theme' => $theme, 'pathPrefix' => $pathPrefix, + 'onlyMimes' => $onlyMimes, ); return $result; @@ -109,6 +115,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'prefix' => $assetsPath, 'theme' => $theme, 'pathPrefix' => $pathPrefix, + 'onlyMimes' => $onlyMimes, ); return $result; @@ -123,6 +130,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'prefix' => $assetsPath, 'theme' => $theme, 'pathPrefix' => $pathPrefix, + 'onlyMimes' => $onlyMimes, ); return $result; @@ -137,6 +145,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'prefix' => $assetsPath, 'theme' => $theme, 'pathPrefix' => $pathPrefix, + 'onlyMimes' => $onlyMimes, ); return $result; @@ -151,6 +160,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'prefix' => $assetsPath, 'theme' => $theme, 'pathPrefix' => $pathPrefix, + 'onlyMimes' => $onlyMimes, ); return $result; @@ -167,6 +177,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'prefix' => $assetsPath, 'theme' => $theme, 'pathPrefix' => $pathPrefix, + 'onlyMimes' => $onlyMimes, ); return $result; @@ -179,6 +190,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'instance' => $instance, 'homeFolder' => $homeFolder, 'prefix' => $assetsPath, + 'onlyMimes' => $onlyMimes, ); return $result; diff --git a/Resources/views/Elfinder/ckeditor.html.twig b/Resources/views/Elfinder/ckeditor.html.twig index 4080b63..eecc9b2 100644 --- a/Resources/views/Elfinder/ckeditor.html.twig +++ b/Resources/views/Elfinder/ckeditor.html.twig @@ -24,6 +24,7 @@ var f = $('.elfinder').elfinder({ url : '{{path('ef_connect', {'instance': instance, 'homeFolder': homeFolder })}}'+'?mode='+mode, lang : '{{locale}}', + onlyMimes: {{ onlyMimes|raw }}, getFileCallback : function(file) { if (funcNum) { {% if relative_path %} diff --git a/Resources/views/Elfinder/elfinder_type.html.twig b/Resources/views/Elfinder/elfinder_type.html.twig index df8ef36..a0b5684 100644 --- a/Resources/views/Elfinder/elfinder_type.html.twig +++ b/Resources/views/Elfinder/elfinder_type.html.twig @@ -14,6 +14,7 @@ var $f = $('.elfinder').elfinder({ url : '{{path('ef_connect', { 'instance': instance, 'homeFolder': homeFolder } )}}', lang : '{{locale}}', + onlyMimes: {{ onlyMimes|raw }}, getFileCallback: function(file) { {% if relative_path %} window.opener.setValue('{{ pathPrefix }}'+file.url.replace("{{ app.request.schemeAndHttpHost }}/", ""), "{{ id }}"); diff --git a/Resources/views/Elfinder/fm_tinymce.html.twig b/Resources/views/Elfinder/fm_tinymce.html.twig index 4c375d2..d6dfb29 100644 --- a/Resources/views/Elfinder/fm_tinymce.html.twig +++ b/Resources/views/Elfinder/fm_tinymce.html.twig @@ -23,6 +23,7 @@ // set your elFinder options here url: '{{ path('ef_connect', {'instance': instance, 'homeFolder': homeFolder }) }}', // connector URL lang : '{{ locale }}', + onlyMimes: {{ onlyMimes|raw }}, getFileCallback: function(file) { // editor callback {% if relative_path %} file.url = '{{ pathPrefix }}' + file.url.replace("{{ app.request.schemeAndHttpHost }}/", ""); diff --git a/Resources/views/Elfinder/simple.html.twig b/Resources/views/Elfinder/simple.html.twig index b866b45..a4071a5 100644 --- a/Resources/views/Elfinder/simple.html.twig +++ b/Resources/views/Elfinder/simple.html.twig @@ -13,7 +13,8 @@ $().ready(function() { var $f = $('.elfinder').elfinder({ url : '{{path('ef_connect', { 'instance': instance, 'homeFolder': homeFolder } )}}', - lang : '{{locale}}' + lang : '{{locale}}', + onlyMimes: {{ onlyMimes|raw }} }); {% if fullscreen %} diff --git a/Resources/views/Elfinder/summernote.html.twig b/Resources/views/Elfinder/summernote.html.twig index d573092..d1362d7 100644 --- a/Resources/views/Elfinder/summernote.html.twig +++ b/Resources/views/Elfinder/summernote.html.twig @@ -14,6 +14,7 @@ var elf = $('.elfinder').elfinder({ url : '{{ path('ef_connect', {'instance': instance, 'homeFolder': homeFolder }) }}', // connector URL lang : '{{locale}}', + onlyMimes: {{ onlyMimes|raw }}, destroyOnClose : true, getFileCallback : function(files, fm) { window.opener.$('.summernote').summernote('editor.insertImage',files.url); diff --git a/Resources/views/Elfinder/tinymce.html.twig b/Resources/views/Elfinder/tinymce.html.twig index 7754a2a..efa7cda 100644 --- a/Resources/views/Elfinder/tinymce.html.twig +++ b/Resources/views/Elfinder/tinymce.html.twig @@ -45,6 +45,7 @@ var f = $('.elfinder').elfinder({ url : '{{ path('ef_connect', {'instance': instance, 'homeFolder': homeFolder }) }}', lang : '{{ locale }}', + onlyMimes: {{ onlyMimes|raw }}, getfile : { onlyURL : true, multiple : false, diff --git a/Resources/views/Elfinder/tinymce4.html.twig b/Resources/views/Elfinder/tinymce4.html.twig index b732b0a..0b7b56c 100644 --- a/Resources/views/Elfinder/tinymce4.html.twig +++ b/Resources/views/Elfinder/tinymce4.html.twig @@ -28,6 +28,7 @@ // set your elFinder options here url: '{{ path('ef_connect', {'instance': instance, 'homeFolder': homeFolder }) }}', // connector URL lang : '{{ locale }}', + onlyMimes: {{ onlyMimes|raw }}, getFileCallback: function(file) { // editor callback {% if relative_path %} FileBrowserDialogue.mySubmit('{{ pathPrefix }}'+file.url.replace("{{ app.request.schemeAndHttpHost }}/", "")); // pass selected file path to TinyMCE From 37a1c365e1ca600539f9ab98e23e66d4045ecd83 Mon Sep 17 00:00:00 2001 From: Justin Hoffman Date: Mon, 7 Dec 2015 11:11:07 -0600 Subject: [PATCH 3/5] update README with new config variable --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 090c30e..a2659d2 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ fm_elfinder: #fullscreen: true|false # defaults true, applies to simple and ckeditor editors #theme: smoothness # jquery theme, default is 'smoothness' include_assets: true # disable if you want to handle loading of the javascript and css assets yourself + #visible_mime_types: ['image/png', 'image/jpg', 'image/jpeg'] # only show these mime types, defaults to show all connector: #debug: true|false # defaults to false roots: # at least one root must be defined From 489be82222213a93aac3e483640d8bd2e928b965 Mon Sep 17 00:00:00 2001 From: Justin Hoffman Date: Mon, 7 Dec 2015 11:27:07 -0600 Subject: [PATCH 4/5] fix StyleCI issue --- Controller/ElFinderController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/ElFinderController.php b/Controller/ElFinderController.php index ef884f9..8871f6d 100644 --- a/Controller/ElFinderController.php +++ b/Controller/ElFinderController.php @@ -62,7 +62,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, $theme = $parameters['theme']; // convert to javascript array $onlyMimes = count($parameters['visible_mime_types']) - ? "['" . implode("','", $parameters['visible_mime_types']) . "']" + ? "['".implode("','", $parameters['visible_mime_types'])."']" : '[]'; $result = array(); From 3ff9a119e109bc6136b1195448316def43b1924f Mon Sep 17 00:00:00 2001 From: Justin Hoffman Date: Mon, 7 Dec 2015 11:38:13 -0600 Subject: [PATCH 5/5] update unit test with new config variable --- Tests/DependencyInjection/ConfigurationLoadTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/DependencyInjection/ConfigurationLoadTest.php b/Tests/DependencyInjection/ConfigurationLoadTest.php index 225da38..a0e4707 100644 --- a/Tests/DependencyInjection/ConfigurationLoadTest.php +++ b/Tests/DependencyInjection/ConfigurationLoadTest.php @@ -39,6 +39,7 @@ public function testSupportsAllConfigFormats($path) 'tinymce_popup_path' => '/pop-up', 'relative_path' => false, 'path_prefix' => '/', + 'visible_mime_types' => array(), 'connector' => array( 'debug' => true, 'binds' => array(),