Skip to content

Commit 5d5a1ae

Browse files
committed
Merge branch 'develop'
2 parents 4d1a85e + af1ae16 commit 5d5a1ae

File tree

10 files changed

+82
-64
lines changed

10 files changed

+82
-64
lines changed

Plugin.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace Samuell\ContentEditor;
1+
<?php
2+
3+
namespace Samuell\ContentEditor;
24

35
use System\Classes\PluginBase;
46

components/ContentEditor.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
<?php namespace Samuell\ContentEditor\Components;
1+
<?php
2+
3+
namespace Samuell\ContentEditor\Components;
24

35
use Cache;
46
use File;
57
use BackendAuth;
68
use Cms\Classes\Content;
79
use Cms\Classes\ComponentBase;
10+
use RainLab\Translate\Classes\Translator;
811

912
use Samuell\ContentEditor\Models\Settings;
1013

@@ -73,6 +76,9 @@ public function onRun()
7376
$this->addCss('assets/contenteditor.css');
7477
$this->addJs('assets/content-tools.min.js');
7578
$this->addJs('assets/contenteditor.js');
79+
80+
// Add scripts only once
81+
$this->renderPartial('@scripts.htm');
7682
}
7783
}
7884

@@ -125,7 +131,7 @@ public function getFile()
125131
{
126132
if (Content::load($this->getTheme(), $this->file)) {
127133
return $this->renderContent($this->file);
128-
} else if (Content::load($this->getTheme(), $this->defaultFile)) { // if no locale file exists -> render the default, without language suffix
134+
} elseif (Content::load($this->getTheme(), $this->defaultFile)) { // if no locale file exists -> render the default, without language suffix
129135
return $this->renderContent($this->defaultFile);
130136
}
131137

@@ -144,17 +150,17 @@ public function setFile($file)
144150

145151
public function setTranslateFile($file)
146152
{
147-
$translate = \RainLab\Translate\Classes\Translator::instance();
153+
$translate = Translator::instance();
148154
$defaultLocale = $translate->getDefaultLocale();
149155
$locale = $translate->getLocale();
150156

151157
// Compability with Rainlab.StaticPage
152158
// StaticPages content does not append default locale to file.
153159
if ($this->fileExists($file) && $locale === $defaultLocale) {
154-
return $file;
160+
return $file;
155161
}
156162

157-
return substr_replace($file, '.'.$locale, strrpos($file, '.'), 0);
163+
return substr_replace($file, '.' . $locale, strrpos($file, '.'), 0);
158164
}
159165

160166
public function checkEditor()
@@ -163,12 +169,13 @@ public function checkEditor()
163169
return $backendUser && $backendUser->hasAccess('samuell.contenteditor.editor');
164170
}
165171

166-
public function fileExists($file) {
172+
public function fileExists($file)
173+
{
167174
return File::exists((new Content)->getFilePath($file));
168175
}
169176

170177
public function translateExists()
171178
{
172-
return class_exists('\RainLab\Translate\Classes\Translator');
179+
return class_exists(Translator::class);
173180
}
174181
}

components/contenteditor/default.htm

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,3 @@
66
{% if __SELF__.class %}class="{{ __SELF__.class }}"{% endif %}>
77
{{ __SELF__.content|raw }}
88
</{% if __SELF__.fixture %}{{ __SELF__.fixture }}{% else %}div{% endif %}>
9-
10-
{% if __SELF__.renderCount == 1 %}
11-
{% put scripts %}
12-
<script type="text/javascript">
13-
/* CONTENT EDITOR SCRIPT START */
14-
ContentTools.StylePalette.add([
15-
{% for style in __SELF__.palettes %}
16-
new ContentTools.Style('{{ style.name ? style.name : style.class }}', '{{ style.class }}', {{ style.allowed_tags|json_encode()|raw }}),
17-
{% endfor %}
18-
]);
19-
editor.toolbox().tools([
20-
[
21-
{% for value in __SELF__.buttons %}
22-
'{{ value }}',
23-
{% endfor %}
24-
],
25-
[
26-
'undo',
27-
'redo',
28-
'remove'
29-
]
30-
]);
31-
/* CONTENT EDITOR SCRIPT END */
32-
</script>
33-
{% endput %}
34-
{% put styles %}
35-
<link rel="stylesheet" href="/contenteditor/styles">
36-
{% endput %}
37-
{% endif %}

components/contenteditor/render.htm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{% if __SELF__.fixture %}<{{ __SELF__.fixture }} {% if __SELF__.class %}class="{{ __SELF__.class }}"{% endif %}>{% endif %}
32
{{ content|raw }}
43
{% if __SELF__.fixture %}</{{ __SELF__.fixture }}>{% endif %}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{% put scripts %}
2+
<script type="text/javascript">
3+
/* CONTENT EDITOR SCRIPT START */
4+
ContentTools.StylePalette.add([
5+
{% for style in __SELF__.palettes %}
6+
new ContentTools.Style('{{ style.name ? style.name : style.class }}', '{{ style.class }}', {{ style.allowed_tags|json_encode()|raw }}),
7+
{% endfor %}
8+
]);
9+
editor.toolbox().tools([
10+
[
11+
{% for value in __SELF__.buttons %}
12+
'{{ value }}',
13+
{% endfor %}
14+
],
15+
[
16+
'undo',
17+
'redo',
18+
'remove'
19+
]
20+
]);
21+
/* CONTENT EDITOR SCRIPT END */
22+
</script>
23+
{% endput %}
24+
{% put styles %}
25+
<link rel="stylesheet" href="/contenteditor/styles">
26+
{% endput %}

http/controllers/AdditionalStylesController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace Samuell\ContentEditor\Http\Controllers;
1+
<?php
2+
3+
namespace Samuell\ContentEditor\Http\Controllers;
24

35
use Response;
46
use Illuminate\Routing\Controller;

http/controllers/ImageController.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
<?php namespace Samuell\ContentEditor\Http\Controllers;
1+
<?php
2+
3+
namespace Samuell\ContentEditor\Http\Controllers;
24

35
use File;
6+
use Lang;
47
use Input;
58
use Response;
69
use Exception;
10+
use SystemException;
711
use ApplicationException;
8-
use Cms\Classes\MediaLibrary;
12+
use Media\Classes\MediaLibrary;
13+
use October\Rain\Resize\Resizer;
914
use Illuminate\Routing\Controller;
10-
use October\Rain\Database\Attach\Resizer;
1115
use Samuell\ContentEditor\Models\Settings;
1216
use October\Rain\Filesystem\Definitions as FileDefinitions;
1317

1418
/**
1519
* ImageController
16-
*
20+
*
1721
* Handle content editor image upload
1822
*/
1923
class ImageController extends Controller
@@ -32,7 +36,7 @@ public function upload()
3236
* Convert uppcare case file extensions to lower case
3337
*/
3438
$extension = strtolower($uploadedFile->getClientOriginalExtension());
35-
$fileName = File::name($fileName).'.'.$extension;
39+
$fileName = File::name($fileName) . '.' . $extension;
3640

3741
/*
3842
* File name contains non-latin characters, attempt to slug the value
@@ -54,29 +58,28 @@ public function upload()
5458
$path = MediaLibrary::validatePath($path);
5559

5660
$realPath = empty(trim($uploadedFile->getRealPath()))
57-
? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName()
58-
: $uploadedFile->getRealPath();
61+
? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName()
62+
: $uploadedFile->getRealPath();
5963

6064
MediaLibrary::instance()->put(
61-
$path.'/'.$fileName,
65+
$path . '/' . $fileName,
6266
File::get($realPath)
6367
);
6468

6569
list($width, $height) = getimagesize($uploadedFile);
6670

6771
return Response::json([
68-
'url' => MediaLibrary::instance()->getPathUrl($path.'/'.$fileName),
69-
'filePath' => $path.'/'.$fileName,
72+
'url' => MediaLibrary::instance()->getPathUrl($path . '/' . $fileName),
73+
'filePath' => $path . '/' . $fileName,
7074
'filename' => $fileName,
7175
'size' => [
72-
$width,
73-
$height
74-
]
76+
$width,
77+
$height
78+
]
7579
]);
7680
} catch (Exception $ex) {
7781
throw new ApplicationException($ex);
7882
}
79-
8083
}
8184

8285
public function save()
@@ -86,14 +89,14 @@ public function save()
8689
$width = post('width');
8790
$height = post('height');
8891
$filePath = post('filePath');
89-
$relativeFilePath = config('cms.storage.media.path').$filePath;
92+
$relativeFilePath = config('cms.storage.media.path', config('system.storage.media.path')) . $filePath;
9093

9194
if ($crop && $crop != '0,0,1,1') {
9295
$crop = explode(',', $crop);
9396

9497
$file = MediaLibrary::instance()->get(post('filePath'));
95-
$tempDirectory = temp_path().'/contenteditor';
96-
$tempFilePath = temp_path().post('filePath');
98+
$tempDirectory = temp_path() . '/contenteditor';
99+
$tempFilePath = temp_path() . post('filePath');
97100
File::makeDirectory($tempDirectory, 0777, true, true);
98101

99102
if (!File::put($tempFilePath, $file)) {

models/Settings.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<?php namespace Samuell\ContentEditor\Models;
1+
<?php
2+
3+
namespace Samuell\ContentEditor\Models;
24

35
use File;
4-
use Lang;
56
use Model;
67
use Less_Parser;
78
use Cache;
@@ -19,7 +20,7 @@ class Settings extends Model
1920
public function initSettingsData()
2021
{
2122
$this->additional_styles = File::get(plugins_path() . '/samuell/contenteditor/assets/additional-css.css');
22-
$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"];
23+
$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'];
2324
}
2425

2526
// list of buttons
@@ -91,12 +92,14 @@ public static function renderCss()
9192
if (Cache::has(self::CACHE_KEY)) {
9293
return Cache::get(self::CACHE_KEY);
9394
}
95+
9496
try {
9597
$customCss = self::compileCss();
9698
Cache::forever(self::CACHE_KEY, $customCss);
9799
} catch (Exception $ex) {
98100
$customCss = '/* ' . $ex->getMessage() . ' */';
99101
}
102+
100103
return $customCss;
101104
}
102105

routes.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
22

33
use Samuell\ContentEditor\Http\Middleware\EditorPermissionsMiddleware;
4+
use Samuell\ContentEditor\Http\Controllers\ImageController;
5+
use Samuell\ContentEditor\Http\Controllers\AdditionalStylesController;
46

57
Route::group(['prefix' => 'contenteditor'], function () {
68

7-
Route::middleware(['web', EditorPermissionsMiddleware::class])->group(function () {
8-
Route::post('image/upload', 'Samuell\ContentEditor\Http\Controllers\ImageController@upload');
9-
Route::post('image/save', 'Samuell\ContentEditor\Http\Controllers\ImageController@save');
10-
});
9+
Route::middleware(['web', EditorPermissionsMiddleware::class])
10+
->group(function () {
11+
Route::post('image/upload', [ImageController::class, 'upload']);
12+
Route::post('image/save', [ImageController::class, 'save']);
13+
});
1114

1215
// Additional styles route
13-
Route::get('styles', 'Samuell\ContentEditor\Http\Controllers\AdditionalStylesController@render');
16+
Route::get('styles', [AdditionalStylesController::class, 'render']);
1417
});

updates/version.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@
5555
1.3.3:
5656
- Allow only image extensions for upload
5757
- Fix italic tag name
58+
1.3.4:
59+
- Small fixes & code cleanup

0 commit comments

Comments
 (0)