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-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>';
|
2018-08-02 22:33:53 +02:00
|
|
|
$html .= '<input name="toolbar" id="jstoolbar" type="text" value="'.$this->getValue('toolbar').'">';
|
2015-09-04 02:46:17 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2017-10-19 16:07:53 +02:00
|
|
|
$html .= '<label>'.$Language->get('tab-size').'</label>';
|
2018-08-02 22:33:53 +02:00
|
|
|
$html .= '<input name="tabSize" id="jstabSize" type="text" value="'.$this->getValue('tabSize').'">';
|
2015-09-04 02:46:17 +02:00
|
|
|
$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-10 18:37:46 +02:00
|
|
|
// Include plugin's CSS files
|
|
|
|
$html = $this->includeCSS('simplemde.min.css');
|
|
|
|
$html .= $this->includeCSS('bludit.css');
|
2018-07-01 14:17:24 +02:00
|
|
|
return $html;
|
2015-08-27 07:05:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function adminBodyEnd()
|
|
|
|
{
|
2018-07-10 18:37:46 +02:00
|
|
|
global $Language;
|
|
|
|
|
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
|
|
|
// Spell Checker
|
2018-08-02 22:33:53 +02:00
|
|
|
$spellCheckerEnable = $this->getValue('spellChecker')?'true':'false';
|
2018-07-01 14:17:24 +02:00
|
|
|
|
2018-07-10 18:37:46 +02:00
|
|
|
// Include plugin's Javascript files
|
|
|
|
$html = $this->includeJS('simplemde.min.js');
|
2018-07-01 14:17:24 +02:00
|
|
|
$html .= '<script>'.PHP_EOL;
|
|
|
|
$html .= 'var simplemde = null;'.PHP_EOL;
|
|
|
|
|
2018-07-10 18:37:46 +02:00
|
|
|
// Include add content to the editor
|
2018-07-01 14:17:24 +02:00
|
|
|
$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,
|
2018-08-02 22:33:53 +02:00
|
|
|
tabSize: '.$this->getValue('tabSize').',
|
2018-07-01 14:17:24 +02:00
|
|
|
spellChecker: '.$spellCheckerEnable.',
|
2018-08-02 22:33:53 +02:00
|
|
|
toolbar: ['.Sanitize::htmlDecode($this->getValue('toolbar')).',
|
2018-07-01 14:17:24 +02:00
|
|
|
"|",
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|