2015-08-27 07:05:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class pluginsimpleMDE extends Plugin {
|
|
|
|
|
2017-08-06 00:52:00 +02:00
|
|
|
private $loadOnController = array(
|
2017-10-02 22:42:18 +02:00
|
|
|
'new-content',
|
|
|
|
'edit-content'
|
2015-08-27 07:05:59 +02:00
|
|
|
);
|
|
|
|
|
2015-09-04 02:46:17 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->dbFields = array(
|
|
|
|
'tabSize'=>'2',
|
2017-08-10 19:55:50 +02:00
|
|
|
'toolbar'=>'"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen"',
|
2017-10-04 23:42:14 +02:00
|
|
|
'autosave'=>false,
|
2017-07-02 22:46:05 +02:00
|
|
|
'spellChecker'=>true
|
2015-09-04 02:46:17 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function form()
|
2015-08-27 07:05:59 +02:00
|
|
|
{
|
|
|
|
global $Language;
|
2015-09-04 02:46:17 +02:00
|
|
|
|
|
|
|
$html = '<div>';
|
2017-10-19 16:07:53 +02:00
|
|
|
$html .= '<label>'.$Language->get('toolbar').'</label>';
|
2015-09-04 02:46:17 +02:00
|
|
|
$html .= '<input name="toolbar" id="jstoolbar" type="text" value="'.$this->getDbField('toolbar').'">';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2017-10-19 16:07:53 +02:00
|
|
|
$html .= '<label>'.$Language->get('tab-size').'</label>';
|
2015-09-04 02:46:17 +02:00
|
|
|
$html .= '<input name="tabSize" id="jstabSize" type="text" value="'.$this->getDbField('tabSize').'">';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
2016-11-19 09:30:53 +01:00
|
|
|
$html .= '<div>';
|
2017-10-19 16:07:53 +02:00
|
|
|
$html .= '<label>'.$Language->get('spell-checker').'</label>';
|
2017-07-02 22:46:05 +02:00
|
|
|
$html .= '<select name="spellChecker">';
|
2017-10-19 16:07:53 +02:00
|
|
|
$html .= '<option value="true" '.($this->getValue('spellChecker')===true?'selected':'').'>'.$Language->get('enabled').'</option>';
|
|
|
|
$html .= '<option value="false" '.($this->getValue('spellChecker')===false?'selected':'').'>'.$Language->get('disabled').'</option>';
|
2017-07-02 22:46:05 +02:00
|
|
|
$html .= '</select>';
|
2016-11-19 09:30:53 +01:00
|
|
|
$html .= '</div>';
|
2016-01-31 00:01:04 +01:00
|
|
|
|
2015-09-04 02:46:17 +02:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function adminHead()
|
|
|
|
{
|
2018-07-01 14:17:24 +02:00
|
|
|
if (!in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-27 07:05:59 +02:00
|
|
|
|
2018-07-01 14:17:24 +02:00
|
|
|
$html = '';
|
2015-08-29 07:02:09 +02:00
|
|
|
|
2018-07-01 14:17:24 +02:00
|
|
|
// Path plugin.
|
|
|
|
$pluginPath = $this->htmlPath();
|
2015-08-29 07:02:09 +02:00
|
|
|
|
2018-07-01 14:17:24 +02:00
|
|
|
// SimpleMDE css
|
|
|
|
$html .= '<link rel="stylesheet" href="'.$pluginPath.'css/simplemde.min.css">';
|
2015-08-27 07:05:59 +02:00
|
|
|
|
2018-07-01 14:17:24 +02:00
|
|
|
// Hack for Bludit
|
|
|
|
$html .= '<style>
|
|
|
|
.editor-toolbar { background: #f1f1f1; border-radius: 0 !important; }
|
|
|
|
.editor-toolbar::before { margin-bottom: 2px !important }
|
|
|
|
.editor-toolbar::after { margin-top: 2px !important }
|
2018-07-07 12:04:34 +02:00
|
|
|
.CodeMirror, .CodeMirror-scroll { min-height: 450px !important; border-radius: 0 !important; }
|
2018-07-01 14:17:24 +02:00
|
|
|
</style>';
|
2015-08-27 07:05:59 +02:00
|
|
|
|
2018-07-01 14:17:24 +02:00
|
|
|
return $html;
|
2015-08-27 07:05:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function adminBodyEnd()
|
|
|
|
{
|
2018-07-01 14:17:24 +02:00
|
|
|
if (!in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
|
|
|
|
return false;
|
2015-08-27 07:05:59 +02:00
|
|
|
}
|
|
|
|
|
2018-07-01 14:17:24 +02:00
|
|
|
// Autosave
|
|
|
|
global $Page;
|
|
|
|
global $Language;
|
|
|
|
$autosaveID = $GLOBALS['ADMIN_CONTROLLER'];
|
|
|
|
$autosaveEnable = $this->getDbField('autosave')?'true':'false';
|
|
|
|
if (!empty($Page)) {
|
|
|
|
$autosaveID = $Page->key();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spell Checker
|
|
|
|
$spellCheckerEnable = $this->getDbField('spellChecker')?'true':'false';
|
|
|
|
|
|
|
|
$pluginPath = $this->htmlPath();
|
|
|
|
|
|
|
|
// SimpleMDE js
|
|
|
|
$html = '<script src="'.$pluginPath.'js/simplemde.min.js"></script>';
|
|
|
|
|
|
|
|
$html .= '<script>'.PHP_EOL;
|
|
|
|
|
|
|
|
$html .= 'var simplemde = null;'.PHP_EOL;
|
|
|
|
|
|
|
|
$html .= 'function addContentSimpleMDE(content) {
|
|
|
|
var text = simplemde.value();
|
|
|
|
simplemde.value(text + content + "\n");
|
2018-07-07 12:04:34 +02:00
|
|
|
simplemde.codemirror.refresh();
|
2018-07-01 14:17:24 +02:00
|
|
|
}'.PHP_EOL;
|
|
|
|
|
2018-07-03 23:04:08 +02:00
|
|
|
// Function required for Autosave function
|
2018-07-07 12:04:34 +02:00
|
|
|
// Returns the content of the editor
|
2018-07-03 23:04:08 +02:00
|
|
|
$html .= 'function editorGetContent(content) {
|
|
|
|
return simplemde.value();
|
|
|
|
}'.PHP_EOL;
|
|
|
|
|
2018-07-07 12:04:34 +02:00
|
|
|
// Function required for Media Manager
|
|
|
|
// Insert an image on the editor in the cursor position
|
2018-07-03 23:04:08 +02:00
|
|
|
$html .= 'function editorInsertMedia(filename) {
|
2018-07-01 14:17:24 +02:00
|
|
|
addContentSimpleMDE("!['.$Language->get('Image description').']("+filename+")");
|
|
|
|
}'.PHP_EOL;
|
|
|
|
|
|
|
|
$html .= '$(document).ready(function() { '.PHP_EOL;
|
|
|
|
|
|
|
|
$html .= '
|
|
|
|
simplemde = new SimpleMDE({
|
2018-07-03 23:04:08 +02:00
|
|
|
element: document.getElementById("jseditor"),
|
2018-07-01 14:17:24 +02:00
|
|
|
status: false,
|
|
|
|
toolbarTips: true,
|
|
|
|
toolbarGuideIcon: true,
|
|
|
|
autofocus: false,
|
|
|
|
placeholder: "'.$Language->get('content-here-supports-markdown-and-html-code').'",
|
|
|
|
lineWrapping: true,
|
2018-07-07 12:04:34 +02:00
|
|
|
autoDownloadFontAwesome: false,
|
2018-07-01 14:17:24 +02:00
|
|
|
indentWithTabs: true,
|
|
|
|
tabSize: '.$this->getDbField('tabSize').',
|
|
|
|
spellChecker: '.$spellCheckerEnable.',
|
|
|
|
toolbar: ['.Sanitize::htmlDecode($this->getDbField('toolbar')).',
|
|
|
|
"|",
|
|
|
|
{
|
|
|
|
name: "pageBreak",
|
|
|
|
action: function addPageBreak(editor){
|
|
|
|
var cm = editor.codemirror;
|
|
|
|
output = "\n'.PAGE_BREAK.'\n";
|
|
|
|
cm.replaceSelection(output);
|
|
|
|
},
|
2018-07-07 12:04:34 +02:00
|
|
|
className: "oi oi-crop",
|
2018-07-01 14:17:24 +02:00
|
|
|
title: "'.$Language->get('Pagebreak').'",
|
|
|
|
}]
|
|
|
|
});';
|
|
|
|
|
|
|
|
$html .= '}); </script>';
|
|
|
|
return $html;
|
2015-08-27 07:05:59 +02:00
|
|
|
}
|
2017-10-16 11:11:07 +02:00
|
|
|
}
|