Skip to content

Commit 4ce48f1

Browse files
committed
First
1 parent dc09ee6 commit 4ce48f1

12 files changed

Lines changed: 273 additions & 0 deletions

File tree

Plugin.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php namespace Samuell\ContentEditor;
2+
3+
use Backend;
4+
use System\Classes\PluginBase;
5+
6+
/**
7+
* ContentEditor Plugin Information File
8+
*/
9+
class Plugin extends PluginBase
10+
{
11+
12+
/**
13+
* Returns information about this plugin.
14+
*
15+
* @return array
16+
*/
17+
public function pluginDetails()
18+
{
19+
return [
20+
'name' => 'ContentEditor',
21+
'description' => 'Frontend content editor',
22+
'author' => 'Samuell',
23+
'icon' => 'icon-edit'
24+
];
25+
}
26+
public function registerComponents()
27+
{
28+
return [
29+
'Samuell\ContentEditor\Components\ContentEditor' => 'contenteditor',
30+
];
31+
}
32+
}

assets/content-tools.min.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/content-tools.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/contenteditor.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var editor = ContentTools.EditorApp.get();
2+
editor.init('*[data-editable]', 'data-file');
3+
4+
editor.addEventListener('saved', function (ev) {
5+
6+
this.busy(true);
7+
regions = ev.detail().regions;
8+
9+
for (name in regions) {
10+
if (regions.hasOwnProperty(name)) {
11+
$.request("contenteditor::onSave", {
12+
data: {
13+
file: name,
14+
content: regions[name]
15+
}
16+
});
17+
}
18+
}
19+
20+
new ContentTools.FlashUI('ok');
21+
setTimeout(function(){
22+
editor.busy(false);
23+
}, 600);
24+
25+
});

assets/icons.woff

6.64 KB
Binary file not shown.

assets/images/drop-horz.svg

Lines changed: 34 additions & 0 deletions
Loading

assets/images/drop-vert-above.svg

Lines changed: 34 additions & 0 deletions
Loading

assets/images/drop-vert-below.svg

Lines changed: 34 additions & 0 deletions
Loading

assets/images/video.svg

Lines changed: 28 additions & 0 deletions
Loading

components/ContentEditor.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php namespace Samuell\ContentEditor\Components;
2+
3+
use File;
4+
use BackendAuth;
5+
use Cms\Classes\Content;
6+
use Cms\Classes\ComponentBase;
7+
8+
class ContentEditor extends ComponentBase
9+
{
10+
public $content;
11+
public $isEditor;
12+
public $file;
13+
14+
public function componentDetails()
15+
{
16+
return [
17+
'name' => 'Content Editor',
18+
'description' => 'Edit your front ent content in page.'
19+
];
20+
}
21+
22+
public function defineProperties()
23+
{
24+
return [
25+
'file' => [
26+
'title' => 'Content file',
27+
'description' => 'Content block filename to edit, optional',
28+
'default' => '',
29+
'type' => 'dropdown',
30+
]
31+
];
32+
}
33+
public function getFileOptions()
34+
{
35+
return Content::sortBy('baseFileName')->lists('baseFileName', 'fileName');
36+
}
37+
public function onRun()
38+
{
39+
$this->isEditor = $this->checkEditor();
40+
if ($this->isEditor) {
41+
$this->addCss('assets/content-tools.min.css');
42+
$this->addJs('assets/content-tools.min.js');
43+
$this->addJs('assets/contenteditor.js');
44+
}
45+
}
46+
public function onRender()
47+
{
48+
$this->file = $this->property('file');
49+
$this->fileMode = File::extension($this->property('file'));
50+
51+
if (!$this->isEditor){
52+
return $this->renderContent($this->file);
53+
}else{
54+
$this->content = $this->renderContent($this->file);
55+
}
56+
}
57+
public function onSave()
58+
{
59+
if ($this->checkEditor()){
60+
$fileName = post('file');
61+
$template = Content::load($this->getTheme(), $fileName);
62+
$template->fill(['markup' => post('content')]);
63+
$template->save();
64+
}
65+
}
66+
public function checkEditor()
67+
{
68+
$backendUser = BackendAuth::getUser();
69+
return $backendUser && $backendUser->hasAccess('cms.manage_content');
70+
}
71+
}

0 commit comments

Comments
 (0)