2015-08-27 07:05:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class pluginsimpleMDE extends Plugin {
|
|
|
|
|
2017-08-06 00:52:00 +02:00
|
|
|
private $loadOnController = array(
|
2015-08-27 07:05:59 +02:00
|
|
|
'new-page',
|
|
|
|
'edit-page'
|
|
|
|
);
|
|
|
|
|
2015-09-04 02:46:17 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->dbFields = array(
|
|
|
|
'tabSize'=>'2',
|
2016-01-31 00:01:04 +01:00
|
|
|
'toolbar'=>'"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen", "guide"',
|
2017-07-02 22:46:05 +02:00
|
|
|
'autosave'=>true,
|
|
|
|
'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>';
|
|
|
|
$html .= '<label>'.$Language->get('Toolbar').'</label>';
|
|
|
|
$html .= '<input name="toolbar" id="jstoolbar" type="text" value="'.$this->getDbField('toolbar').'">';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
|
|
|
$html .= '<label>'.$Language->get('Tab size').'</label>';
|
|
|
|
$html .= '<input name="tabSize" id="jstabSize" type="text" value="'.$this->getDbField('tabSize').'">';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
2016-01-31 00:01:04 +01:00
|
|
|
$html .= '<div>';
|
2017-07-02 22:46:05 +02:00
|
|
|
$html .= '<label>'.$Language->get('Autosave').'</label>';
|
|
|
|
$html .= '<select name="autosave">';
|
|
|
|
$html .= '<option value="true" '.($this->getValue('autosave')===true?'selected':'').'>Enabled</option>';
|
|
|
|
$html .= '<option value="false" '.($this->getValue('autosave')===false?'selected':'').'>Disabled</option>';
|
|
|
|
$html .= '</select>';
|
2016-01-31 00:01:04 +01:00
|
|
|
$html .= '</div>';
|
2017-06-09 20:30:13 +02:00
|
|
|
|
2016-11-19 09:30:53 +01:00
|
|
|
$html .= '<div>';
|
2017-07-02 22:46:05 +02:00
|
|
|
$html .= '<label>'.$Language->get('Spell Checker').'</label>';
|
|
|
|
$html .= '<select name="spellChecker">';
|
|
|
|
$html .= '<option value="true" '.($this->getValue('spellChecker')===true?'selected':'').'>Enabled</option>';
|
|
|
|
$html .= '<option value="false" '.($this->getValue('spellChecker')===false?'selected':'').'>Disabled</option>';
|
|
|
|
$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()
|
|
|
|
{
|
2017-08-06 00:52:00 +02:00
|
|
|
if (in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
|
|
|
|
$html = '';
|
2015-08-27 07:05:59 +02:00
|
|
|
|
2015-09-04 02:46:17 +02:00
|
|
|
// Path plugin.
|
2015-08-27 07:05:59 +02:00
|
|
|
$pluginPath = $this->htmlPath();
|
|
|
|
|
2015-11-04 01:28:11 +01:00
|
|
|
// SimpleMDE css
|
2015-08-29 07:02:09 +02:00
|
|
|
$html .= '<link rel="stylesheet" href="'.$pluginPath.'css/simplemde.min.css">';
|
|
|
|
|
2015-11-04 01:28:11 +01:00
|
|
|
// SimpleMDE js
|
2015-09-04 02:46:17 +02:00
|
|
|
$html .= '<script src="'.$pluginPath.'js/simplemde.min.js"></script>';
|
2015-08-29 07:02:09 +02:00
|
|
|
|
2015-09-04 02:46:17 +02:00
|
|
|
// Hack for Bludit
|
|
|
|
$html .= '<style>
|
2016-05-28 21:47:54 +02:00
|
|
|
.editor-toolbar { background: #f1f1f1; border-radius: 0 !important; }
|
2015-09-04 02:46:17 +02:00
|
|
|
.editor-toolbar::before { margin-bottom: 2px !important }
|
|
|
|
.editor-toolbar::after { margin-top: 2px !important }
|
2016-05-28 21:47:54 +02:00
|
|
|
.CodeMirror, .CodeMirror-scroll { min-height: 400px !important; border-radius: 0 !important; }
|
2015-09-04 02:46:17 +02:00
|
|
|
</style>';
|
2015-08-27 07:05:59 +02:00
|
|
|
|
2017-08-06 00:52:00 +02:00
|
|
|
return $html;
|
2015-08-27 07:05:59 +02:00
|
|
|
}
|
|
|
|
|
2017-08-06 00:52:00 +02:00
|
|
|
return false;
|
2015-08-27 07:05:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function adminBodyEnd()
|
|
|
|
{
|
2017-08-06 00:52:00 +02:00
|
|
|
if (in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
|
2016-01-31 00:01:04 +01:00
|
|
|
// Autosave
|
2017-08-06 00:52:00 +02:00
|
|
|
global $Page;
|
|
|
|
global $Language;
|
|
|
|
$autosaveID = $GLOBALS['ADMIN_CONTROLLER'];
|
2016-01-31 00:01:04 +01:00
|
|
|
$autosaveEnable = $this->getDbField('autosave')?'true':'false';
|
2017-08-06 00:52:00 +02:00
|
|
|
if (!empty($Page)) {
|
|
|
|
$autosaveID = $Page->key();
|
2016-01-31 00:01:04 +01:00
|
|
|
}
|
|
|
|
|
2016-11-19 09:30:53 +01:00
|
|
|
// Spell Checker
|
|
|
|
$spellCheckerEnable = $this->getDbField('spellChecker')?'true':'false';
|
2017-06-09 20:30:13 +02:00
|
|
|
|
2015-08-27 07:05:59 +02:00
|
|
|
$pluginPath = $this->htmlPath();
|
|
|
|
|
2015-10-19 00:45:58 +02:00
|
|
|
$html = '<script>'.PHP_EOL;
|
2015-12-28 23:28:42 +01:00
|
|
|
|
|
|
|
$html .= 'var simplemde = null;'.PHP_EOL;
|
|
|
|
|
|
|
|
$html .= 'function addContentSimpleMDE(content) {
|
|
|
|
var text = simplemde.value();
|
|
|
|
simplemde.value(text + content + "\n");
|
|
|
|
}'.PHP_EOL;
|
|
|
|
|
2016-02-10 00:18:00 +01:00
|
|
|
// This function is necesary on each Editor, it is used by Bludit Images v8.
|
2016-02-10 00:02:51 +01:00
|
|
|
$html .= 'function editorAddImage(filename) {
|
2016-02-10 00:18:00 +01:00
|
|
|
addContentSimpleMDE("!['.$Language->get('Image description').']("+filename+")");
|
2016-02-10 00:02:51 +01:00
|
|
|
}'.PHP_EOL;
|
|
|
|
|
2015-10-19 00:45:58 +02:00
|
|
|
$html .= '$(document).ready(function() { '.PHP_EOL;
|
2015-12-28 23:28:42 +01:00
|
|
|
$html .= 'simplemde = new SimpleMDE({
|
2015-08-27 07:05:59 +02:00
|
|
|
element: document.getElementById("jscontent"),
|
2015-08-29 07:02:09 +02:00
|
|
|
status: false,
|
2015-08-27 07:05:59 +02:00
|
|
|
toolbarTips: true,
|
|
|
|
toolbarGuideIcon: true,
|
2015-08-29 20:07:47 +02:00
|
|
|
autofocus: false,
|
2017-06-09 20:30:13 +02:00
|
|
|
placeholder: "Content here. Supports Markdown and HTML code.",
|
2015-09-08 02:51:48 +02:00
|
|
|
lineWrapping: true,
|
2015-11-04 01:28:11 +01:00
|
|
|
autoDownloadFontAwesome: false,
|
2015-08-27 07:05:59 +02:00
|
|
|
indentWithTabs: true,
|
2015-09-04 02:46:17 +02:00
|
|
|
tabSize: '.$this->getDbField('tabSize').',
|
2016-11-19 09:30:53 +01:00
|
|
|
spellChecker: '.$spellCheckerEnable.',
|
2016-01-31 00:01:04 +01:00
|
|
|
autosave: {
|
|
|
|
enabled: '.$autosaveEnable.',
|
|
|
|
uniqueId: "'.$autosaveID.'",
|
|
|
|
delay: 1000,
|
|
|
|
},
|
2017-08-10 17:25:43 +02:00
|
|
|
toolbar: [ {
|
|
|
|
name: "pageBreak",
|
|
|
|
action: function addPageBreak(editor){
|
|
|
|
var cm = editor.codemirror;
|
|
|
|
output = "\n<!-- pagebreak -->\n\n";
|
|
|
|
cm.replaceSelection(output);
|
|
|
|
},
|
|
|
|
className: "fa fa-book",
|
|
|
|
title: "Pagebreak",
|
|
|
|
},
|
|
|
|
"|",
|
|
|
|
'.Sanitize::htmlDecode($this->getDbField('toolbar')).'
|
|
|
|
]
|
2015-11-05 03:54:22 +01:00
|
|
|
});';
|
2015-11-04 01:28:11 +01:00
|
|
|
|
2015-08-27 07:05:59 +02:00
|
|
|
$html .= '}); </script>';
|
2017-08-06 00:52:00 +02:00
|
|
|
return $html;
|
2015-08-27 07:05:59 +02:00
|
|
|
}
|
|
|
|
|
2017-08-06 00:52:00 +02:00
|
|
|
return false;
|
2015-08-27 07:05:59 +02:00
|
|
|
}
|
2016-01-19 03:34:33 +01:00
|
|
|
}
|