bludit/bl-plugins/simplemde/plugin.php

122 lines
3.5 KiB
PHP
Raw Permalink Normal View History

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>';
$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>';
$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>';
$html .= '<div>';
$html .= '<label>'.$Language->get('spell-checker').'</label>';
2017-07-02 22:46:05 +02:00
$html .= '<select name="spellChecker">';
$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>';
$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
$spellCheckerEnable = $this->getDbField('spellChecker')?'true':'false';
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,
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
}