koblog/bl-plugins/tinymce/plugin.php

149 lines
4.3 KiB
PHP
Raw Normal View History

2017-08-03 23:28:32 +02:00
<?php
class pluginTinymce extends Plugin {
2021-03-09 15:55:08 +01:00
private $loadOnViews = array(
'editor' // Load this plugin only in the Editor view
2017-08-03 23:28:32 +02:00
);
2018-07-30 23:43:12 +02:00
public function init()
{
$this->dbFields = array(
2019-04-23 19:05:23 +02:00
'toolbar1'=>'formatselect bold italic forecolor backcolor removeformat | bullist numlist table | blockquote alignleft aligncenter alignright | link unlink pagebreak image code',
2018-07-30 23:43:12 +02:00
'toolbar2'=>'',
2019-04-23 19:05:23 +02:00
'plugins'=>'code autolink image link pagebreak advlist lists textpattern table'
2018-07-30 23:43:12 +02:00
);
}
public function form()
{
global $L;
2018-07-30 23:43:12 +02:00
2021-03-04 18:50:28 +01:00
$html = '<div class="mb-3">';
$html .= '<label class="form-label" for="toolbar1">'.$L->get('Toolbar top').'</label>';
$html .= '<input class="form-control" name="toolbar1" id="toolbar1" type="text" value="'.$this->getValue('toolbar1').'">';
2018-07-30 23:43:12 +02:00
$html .= '</div>';
2021-03-04 18:50:28 +01:00
$html .= '<div class="mb-3">';
$html .= '<label class="form-label" for="toolbar2">'.$L->get('Toolbar bottom').'</label>';
$html .= '<input class="form-control" name="toolbar2" id="toolbar2" type="text" value="'.$this->getValue('toolbar2').'">';
2018-07-30 23:43:12 +02:00
$html .= '</div>';
2021-03-04 18:50:28 +01:00
$html .= '<div class="mb-3">';
$html .= '<label class="form-label" for="plugins">'.$L->get('Plugins').'</label>';
$html .= '<input class="form-control" name="plugins" id="plugins" type="text" value="'.$this->getValue('plugins').'">';
2018-07-30 23:43:12 +02:00
$html .= '</div>';
return $html;
}
2017-08-03 23:28:32 +02:00
public function adminHead()
{
global $site;
2021-03-09 15:55:08 +01:00
// Load the plugin only in the controllers setted in $this->loadOnViews
if (!in_array($GLOBALS['ADMIN_VIEW'], $this->loadOnViews)) {
2018-07-07 12:04:34 +02:00
return false;
2017-08-03 23:28:32 +02:00
}
2021-03-04 18:50:28 +01:00
$html = '<link rel="stylesheet" type="text/css" href="'.$this->htmlPath().'css/lightmode-toolbar.css">'.PHP_EOL;
if ($site->darkModeAdmin()) {
$html = '<link rel="stylesheet" type="text/css" href="'.$this->htmlPath().'css/darkmode-toolbar.css">'.PHP_EOL;
}
2019-06-21 11:01:21 +02:00
$html .= '<script src="'.$this->htmlPath().'tinymce/tinymce.min.js?version='.$this->version().'"></script>';
return $html;
2017-08-03 23:28:32 +02:00
}
public function adminBodyEnd()
{
2018-10-18 22:48:18 +02:00
global $L;
global $site;
2018-10-18 22:48:18 +02:00
2021-03-09 15:55:08 +01:00
// Load the plugin only in the controllers setted in $this->loadOnViews
if (!in_array($GLOBALS['ADMIN_VIEW'], $this->loadOnViews)) {
2018-07-07 12:04:34 +02:00
return false;
}
$toolbar1 = $this->getValue('toolbar1');
$toolbar2 = $this->getValue('toolbar2');
$content_css = $this->htmlPath().'css/lightmode-content.css'.','.$this->htmlPath().'css/default-content.css';
if ($site->darkModeAdmin()) {
$content_css = $this->htmlPath().'css/darkmode-content.css'.','.$this->htmlPath().'css/default-content.css';
}
2018-08-02 22:33:53 +02:00
$plugins = $this->getValue('plugins');
2019-05-28 20:39:37 +02:00
$version = $this->version();
2018-07-30 23:43:12 +02:00
$lang = 'en';
if (file_exists($this->phpPath().'tinymce'.DS.'langs'.DS.$L->currentLanguage().'.js')) {
$lang = $L->currentLanguage();
} elseif (file_exists($this->phpPath().'tinymce'.DS.'langs'.DS.$L->currentLanguageShortVersion().'.js')) {
$lang = $L->currentLanguageShortVersion();
2018-07-30 23:43:12 +02:00
}
2018-10-07 15:54:28 +02:00
if (IMAGE_RELATIVE_TO_ABSOLUTE) {
$document_base_url = 'document_base_url: "'.DOMAIN_UPLOADS.'",';
} else {
$document_base_url = '';
}
$skin = 'oxide';
if ($site->darkModeAdmin()) {
$skin = 'oxide-dark';
}
2021-06-08 23:34:49 +02:00
return <<<EOF
<script>
// Function required for Bludit
// Returns the content of the editor
function editorGetContent() {
return tinymce.get('editor').getContent();
}
// Function required for Bludit
// Insert HTML content at the cursor position
function editorInsertContent(content, type='') {
if (type == 'image') {
var html = '<img src="' + content + '" alt="" />';
} else {
var html = content;
}
tinymce.activeEditor.insertContent(html);
}
tinymce.init({
selector: "#editor",
auto_focus: "editor",
element_format : "html",
entity_encoding : "raw",
skin: "$skin",
schema: "html5",
statusbar: false,
menubar:false,
branding: false,
browser_spellcheck: true,
pagebreak_separator: PAGE_BREAK,
pagebreak_split_block: true,
paste_as_text: true,
remove_script_host: false,
convert_urls: true,
relative_urls: false,
valid_elements: "*[*]",
cache_suffix: "?version=$version",
$document_base_url
plugins: ["$plugins"],
toolbar1: "$toolbar1",
toolbar2: "$toolbar2",
language: "$lang",
content_css: "$content_css",
init_instance_callback: function(editor) {
editor.on("keydown", function(event) {
keypress(event);
2020-11-01 11:55:34 +01:00
});
2021-06-08 23:34:49 +02:00
}
});
2018-07-07 12:04:34 +02:00
2021-06-08 23:34:49 +02:00
</script>
EOF;
2017-08-03 23:28:32 +02:00
}
2017-08-03 23:28:32 +02:00
}