bludit/bl-plugins/tinymce/plugin.php

126 lines
3.4 KiB
PHP
Raw Normal View History

2017-08-03 23:28:32 +02:00
<?php
class pluginTinymce 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'
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
$html = '<div>';
$html .= '<label>'.$L->get('Toolbar top').'</label>';
2018-08-02 22:33:53 +02:00
$html .= '<input name="toolbar1" id="jstoolbar1" type="text" value="'.$this->getValue('toolbar1').'">';
2018-07-30 23:43:12 +02:00
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('Toolbar bottom').'</label>';
2018-08-02 22:33:53 +02:00
$html .= '<input name="toolbar2" id="jstoolbar2" type="text" value="'.$this->getValue('toolbar2').'">';
2018-07-30 23:43:12 +02:00
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('Plugins').'</label>';
2018-08-02 22:33:53 +02:00
$html .= '<input name="plugins" id="jsplugins" 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()
{
2018-10-18 22:40:35 +02:00
// Load the plugin only in the controllers setted in $this->loadOnController
2018-07-07 12:04:34 +02:00
if (!in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
return false;
2017-08-03 23:28:32 +02:00
}
2019-06-21 11:01:21 +02:00
$html = '<link rel="stylesheet" type="text/css" href="'.$this->htmlPath().'css/tinymce_toolbar.css">'.PHP_EOL;
$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;
2018-10-18 22:40:35 +02:00
// Load the plugin only in the controllers setted in $this->loadOnController
2018-07-07 12:04:34 +02:00
if (!in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
return false;
}
$toolbar1 = $this->getValue('toolbar1');
$toolbar2 = $this->getValue('toolbar2');
2019-06-21 11:01:21 +02:00
$content_css = $this->htmlPath().'css/tinymce_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 = '';
}
2018-10-18 22:40:35 +02:00
$html = <<<EOF
2018-07-07 12:04:34 +02:00
<script>
2019-02-19 08:38:17 +01:00
// Insert an image in the editor at the cursor position
2018-10-18 22:40:35 +02:00
// Function required for Bludit
function editorInsertMedia(filename) {
tinymce.activeEditor.insertContent("<img src=\""+filename+"\" alt=\"\">");
}
// Returns the content of the editor
// Function required for Bludit
function editorGetContent() {
return tinymce.get('jseditor').getContent();
}
tinymce.init({
selector: "#jseditor",
auto_focus: "jseditor",
element_format : "html",
entity_encoding : "raw",
2019-06-21 11:01:21 +02:00
skin: "oxide",
2018-10-18 22:40:35 +02:00
schema: "html5",
statusbar: false,
menubar:false,
branding: false,
browser_spellcheck: true,
pagebreak_separator: PAGE_BREAK,
paste_as_text: true,
remove_script_host: false,
convert_urls: true,
relative_urls: false,
2019-02-03 14:34:21 +01:00
valid_elements: "*[*]",
2019-05-28 20:39:37 +02:00
cache_suffix: "?version=$version",
2018-10-18 22:40:35 +02:00
$document_base_url
plugins: ["$plugins"],
toolbar1: "$toolbar1",
toolbar2: "$toolbar2",
language: "$lang",
2019-05-28 20:39:37 +02:00
content_css: "$content_css"
2018-10-18 22:40:35 +02:00
});
2018-07-07 12:04:34 +02:00
</script>
EOF;
2018-10-18 22:40:35 +02:00
return $html;
2017-08-03 23:28:32 +02:00
}
2017-08-03 23:28:32 +02:00
}