From 13c9e0fcbb1289fbe4fead7441e61659d63631f0 Mon Sep 17 00:00:00 2001 From: Samuell Date: Sun, 26 Dec 2021 10:27:42 +0100 Subject: [PATCH 1/8] Code formatting --- Plugin.php | 4 ++- components/ContentEditor.php | 11 ++++--- components/contenteditor/render.htm | 1 - .../AdditionalStylesController.php | 4 ++- http/controllers/ImageController.php | 31 ++++++++++--------- models/Settings.php | 9 ++++-- 6 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Plugin.php b/Plugin.php index d64a5a9..0191c5d 100644 --- a/Plugin.php +++ b/Plugin.php @@ -1,4 +1,6 @@ -fileExists($file) && $locale === $defaultLocale) { - return $file; + return $file; } - return substr_replace($file, '.'.$locale, strrpos($file, '.'), 0); + return substr_replace($file, '.' . $locale, strrpos($file, '.'), 0); } public function checkEditor() @@ -163,7 +165,8 @@ public function checkEditor() return $backendUser && $backendUser->hasAccess('samuell.contenteditor.editor'); } - public function fileExists($file) { + public function fileExists($file) + { return File::exists((new Content)->getFilePath($file)); } diff --git a/components/contenteditor/render.htm b/components/contenteditor/render.htm index 4b46174..a6ee2d9 100644 --- a/components/contenteditor/render.htm +++ b/components/contenteditor/render.htm @@ -1,4 +1,3 @@ - {% if __SELF__.fixture %}<{{ __SELF__.fixture }} {% if __SELF__.class %}class="{{ __SELF__.class }}"{% endif %}>{% endif %} {{ content|raw }} {% if __SELF__.fixture %}{% endif %} diff --git a/http/controllers/AdditionalStylesController.php b/http/controllers/AdditionalStylesController.php index c5dc5c1..4c0aaa8 100644 --- a/http/controllers/AdditionalStylesController.php +++ b/http/controllers/AdditionalStylesController.php @@ -1,4 +1,6 @@ -getClientOriginalExtension()); - $fileName = File::name($fileName).'.'.$extension; + $fileName = File::name($fileName) . '.' . $extension; /* * File name contains non-latin characters, attempt to slug the value @@ -54,29 +56,28 @@ public function upload() $path = MediaLibrary::validatePath($path); $realPath = empty(trim($uploadedFile->getRealPath())) - ? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName() - : $uploadedFile->getRealPath(); + ? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName() + : $uploadedFile->getRealPath(); MediaLibrary::instance()->put( - $path.'/'.$fileName, + $path . '/' . $fileName, File::get($realPath) ); list($width, $height) = getimagesize($uploadedFile); return Response::json([ - 'url' => MediaLibrary::instance()->getPathUrl($path.'/'.$fileName), - 'filePath' => $path.'/'.$fileName, + 'url' => MediaLibrary::instance()->getPathUrl($path . '/' . $fileName), + 'filePath' => $path . '/' . $fileName, 'filename' => $fileName, 'size' => [ - $width, - $height - ] + $width, + $height + ] ]); } catch (Exception $ex) { throw new ApplicationException($ex); } - } public function save() @@ -86,14 +87,14 @@ public function save() $width = post('width'); $height = post('height'); $filePath = post('filePath'); - $relativeFilePath = config('cms.storage.media.path').$filePath; + $relativeFilePath = config('cms.storage.media.path') . $filePath; if ($crop && $crop != '0,0,1,1') { $crop = explode(',', $crop); $file = MediaLibrary::instance()->get(post('filePath')); - $tempDirectory = temp_path().'/contenteditor'; - $tempFilePath = temp_path().post('filePath'); + $tempDirectory = temp_path() . '/contenteditor'; + $tempFilePath = temp_path() . post('filePath'); File::makeDirectory($tempDirectory, 0777, true, true); if (!File::put($tempFilePath, $file)) { diff --git a/models/Settings.php b/models/Settings.php index 8307542..775254c 100644 --- a/models/Settings.php +++ b/models/Settings.php @@ -1,7 +1,8 @@ -additional_styles = File::get(plugins_path() . '/samuell/contenteditor/assets/additional-css.css'); - $this->enabled_buttons = ["bold", "italic", "link", "align-left", "align-center", "align-right", "heading", "subheading", "subheading3", "subheading4", "subheading5", "paragraph", "unordered-list", "ordered-list", "table", "indent", "unindent", "line-break", "image", "video", "preformatted"]; + $this->enabled_buttons = ['bold', 'italic', 'link', 'align-left', 'align-center', 'align-right', 'heading', 'subheading', 'subheading3', 'subheading4', 'subheading5', 'paragraph', 'unordered-list', 'ordered-list', 'table', 'indent', 'unindent', 'line-break', 'image', 'video', 'preformatted']; } // list of buttons @@ -91,12 +92,14 @@ public static function renderCss() if (Cache::has(self::CACHE_KEY)) { return Cache::get(self::CACHE_KEY); } + try { $customCss = self::compileCss(); Cache::forever(self::CACHE_KEY, $customCss); } catch (Exception $ex) { $customCss = '/* ' . $ex->getMessage() . ' */'; } + return $customCss; } From 1429a5d68bb21c2afb870b438e9c430cab6eb4e0 Mon Sep 17 00:00:00 2001 From: Pixinside Date: Thu, 17 Mar 2022 13:45:07 +0100 Subject: [PATCH 2/8] Update ImageController.php media path will work with v2 and should still be compatible with v1 --- http/controllers/ImageController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http/controllers/ImageController.php b/http/controllers/ImageController.php index 3a788aa..ad79b8d 100644 --- a/http/controllers/ImageController.php +++ b/http/controllers/ImageController.php @@ -86,7 +86,7 @@ public function save() $width = post('width'); $height = post('height'); $filePath = post('filePath'); - $relativeFilePath = config('cms.storage.media.path').$filePath; + $relativeFilePath = config('cms.storage.media.path', config('system.storage.media.path')).$filePath; if ($crop && $crop != '0,0,1,1') { $crop = explode(',', $crop); From 155207226d449fbba1ba70c13700b0bebc1ec8e3 Mon Sep 17 00:00:00 2001 From: Alex <55833027+PubliAlex@users.noreply.github.com> Date: Thu, 23 Jun 2022 11:50:16 +0200 Subject: [PATCH 3/8] Update default.htm Remove scripts from default partial --- components/contenteditor/default.htm | 29 ---------------------------- 1 file changed, 29 deletions(-) diff --git a/components/contenteditor/default.htm b/components/contenteditor/default.htm index e87f8be..a3feadc 100644 --- a/components/contenteditor/default.htm +++ b/components/contenteditor/default.htm @@ -6,32 +6,3 @@ {% if __SELF__.class %}class="{{ __SELF__.class }}"{% endif %}> {{ __SELF__.content|raw }} - -{% if __SELF__.renderCount == 1 %} - {% put scripts %} - - {% endput %} - {% put styles %} - - {% endput %} -{% endif %} From 7cf020b7bce720b7d7f73b2f4eef2f5f334ff649 Mon Sep 17 00:00:00 2001 From: Alex <55833027+PubliAlex@users.noreply.github.com> Date: Thu, 23 Jun 2022 11:51:16 +0200 Subject: [PATCH 4/8] Create scripts.htm Add scripts to dedicated partial --- components/contenteditor/scripts.htm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 components/contenteditor/scripts.htm diff --git a/components/contenteditor/scripts.htm b/components/contenteditor/scripts.htm new file mode 100644 index 0000000..087dff8 --- /dev/null +++ b/components/contenteditor/scripts.htm @@ -0,0 +1,26 @@ +{% put scripts %} + +{% endput %} +{% put styles %} + +{% endput %} From 5a9143ad00ac2fadba547b5c9c3510aff161839d Mon Sep 17 00:00:00 2001 From: Alex <55833027+PubliAlex@users.noreply.github.com> Date: Thu, 23 Jun 2022 11:52:14 +0200 Subject: [PATCH 5/8] Update ContentEditor.php Inject scripts onRun in a dedicated partial instead of onRender --- components/ContentEditor.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/ContentEditor.php b/components/ContentEditor.php index 399e2a3..4165bcb 100644 --- a/components/ContentEditor.php +++ b/components/ContentEditor.php @@ -74,6 +74,9 @@ public function onRun() $this->addJs('assets/content-tools.min.js'); $this->addJs('assets/contenteditor.js'); } + + // Add scripts only once + $this->renderPartial('@scripts.htm'); } public function onRender() From 36838ad73aafd038a26736ef2fae55499a567b85 Mon Sep 17 00:00:00 2001 From: Samuell Date: Sun, 10 Jul 2022 22:03:59 +0200 Subject: [PATCH 6/8] Update ContentEditor.php --- components/ContentEditor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/ContentEditor.php b/components/ContentEditor.php index 311608b..cc71f88 100644 --- a/components/ContentEditor.php +++ b/components/ContentEditor.php @@ -75,10 +75,10 @@ public function onRun() $this->addCss('assets/contenteditor.css'); $this->addJs('assets/content-tools.min.js'); $this->addJs('assets/contenteditor.js'); - } - // Add scripts only once - $this->renderPartial('@scripts.htm'); + // Add scripts only once + $this->renderPartial('@scripts.htm'); + } } public function onRender() From 7744af3559eaa250fb7139d1d6da75c1294d9711 Mon Sep 17 00:00:00 2001 From: Samuell Date: Sun, 10 Jul 2022 22:14:39 +0200 Subject: [PATCH 7/8] Correct imports --- components/ContentEditor.php | 7 ++++--- http/controllers/ImageController.php | 6 ++++-- routes.php | 13 ++++++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/components/ContentEditor.php b/components/ContentEditor.php index cc71f88..e0b91f2 100644 --- a/components/ContentEditor.php +++ b/components/ContentEditor.php @@ -7,6 +7,7 @@ use BackendAuth; use Cms\Classes\Content; use Cms\Classes\ComponentBase; +use RainLab\Translate\Classes\Translator; use Samuell\ContentEditor\Models\Settings; @@ -130,7 +131,7 @@ public function getFile() { if (Content::load($this->getTheme(), $this->file)) { return $this->renderContent($this->file); - } else if (Content::load($this->getTheme(), $this->defaultFile)) { // if no locale file exists -> render the default, without language suffix + } elseif (Content::load($this->getTheme(), $this->defaultFile)) { // if no locale file exists -> render the default, without language suffix return $this->renderContent($this->defaultFile); } @@ -149,7 +150,7 @@ public function setFile($file) public function setTranslateFile($file) { - $translate = \RainLab\Translate\Classes\Translator::instance(); + $translate = Translator::instance(); $defaultLocale = $translate->getDefaultLocale(); $locale = $translate->getLocale(); @@ -175,6 +176,6 @@ public function fileExists($file) public function translateExists() { - return class_exists('\RainLab\Translate\Classes\Translator'); + return class_exists(Translator::class); } } diff --git a/http/controllers/ImageController.php b/http/controllers/ImageController.php index 10e2bd0..f0f91b9 100644 --- a/http/controllers/ImageController.php +++ b/http/controllers/ImageController.php @@ -3,13 +3,15 @@ namespace Samuell\ContentEditor\Http\Controllers; use File; +use Lang; use Input; use Response; use Exception; +use SystemException; use ApplicationException; -use Cms\Classes\MediaLibrary; +use Media\Classes\MediaLibrary; +use October\Rain\Resize\Resizer; use Illuminate\Routing\Controller; -use October\Rain\Database\Attach\Resizer; use Samuell\ContentEditor\Models\Settings; use October\Rain\Filesystem\Definitions as FileDefinitions; diff --git a/routes.php b/routes.php index 5033f46..3ba13a4 100644 --- a/routes.php +++ b/routes.php @@ -1,14 +1,17 @@ 'contenteditor'], function () { - Route::middleware(['web', EditorPermissionsMiddleware::class])->group(function () { - Route::post('image/upload', 'Samuell\ContentEditor\Http\Controllers\ImageController@upload'); - Route::post('image/save', 'Samuell\ContentEditor\Http\Controllers\ImageController@save'); - }); + Route::middleware(['web', EditorPermissionsMiddleware::class]) + ->group(function () { + Route::post('image/upload', [ImageController::class, 'upload']); + Route::post('image/save', [ImageController::class, 'save']); + }); // Additional styles route - Route::get('styles', 'Samuell\ContentEditor\Http\Controllers\AdditionalStylesController@render'); + Route::get('styles', [AdditionalStylesController::class, 'render']); }); From af1ae16f7a6d3038051711d2698616775ba89faf Mon Sep 17 00:00:00 2001 From: Samuell Date: Sun, 10 Jul 2022 22:16:03 +0200 Subject: [PATCH 8/8] Update version.yaml --- updates/version.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/updates/version.yaml b/updates/version.yaml index ecf04aa..afe8626 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -55,3 +55,5 @@ 1.3.3: - Allow only image extensions for upload - Fix italic tag name +1.3.4: + - Small fixes & code cleanup