bludit/plugins/tinymce/plugin.php

117 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2015-11-30 03:53:44 +01:00
<?php
class pluginTinymce extends Plugin {
private $loadWhenController = array(
'new-post',
'new-page',
'edit-post',
'edit-page'
);
public function init()
{
$this->dbFields = array(
2015-12-10 03:23:21 +01:00
'plugins'=>'autoresize, fullscreen, pagebreak, link, textcolor, code, image, paste',
2015-11-30 03:53:44 +01:00
'toolbar'=>'bold italic underline strikethrough | alignleft aligncenter alignright | bullist numlist | styleselect | link forecolor backcolor removeformat image | pagebreak code fullscreen'
);
}
public function form()
{
global $Language;
$html = '<div>';
$html .= '<label>Tinymce plugins</label>';
$html .= '<input name="plugins" id="jsplugins" type="text" value="'.$this->getDbField('plugins').'">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>Tinymce toolbar</label>';
$html .= '<input name="toolbar" id="jstoolbar" type="text" value="'.$this->getDbField('toolbar').'">';
$html .= '</div>';
return $html;
}
public function adminHead()
{
global $Language;
global $Site;
global $layout;
$html = '';
// Load CSS and JS only on Controllers in array.
if(in_array($layout['controller'], $this->loadWhenController))
{
$language = $Site->shortLanguage();
$pluginPath = $this->htmlPath();
$html = '<script src="'.$pluginPath.'tinymce/tinymce.min.js"></script>';
}
return $html;
}
public function adminBodyEnd()
{
global $Language;
global $Site;
global $layout;
$html = '';
// Load CSS and JS only on Controllers in array.
if(in_array($layout['controller'], $this->loadWhenController))
{
$pluginPath = $this->htmlPath();
2015-12-01 03:57:46 +01:00
$language = '';
if($Site->shortLanguage()!=='en') {
2015-12-09 02:10:46 +01:00
if(file_exists($this->phpPath().'tinymce/langs/'.$Site->shortLanguage().'.js')) {
$language = 'language_url:"'.$pluginPath.'tinymce/langs/'.$Site->shortLanguage().'.js",';
}
2015-12-01 03:57:46 +01:00
}
2015-11-30 03:53:44 +01:00
$html = '<script>$(document).ready(function() { ';
$html .= 'tinymce.init({
selector: "#jscontent",
2015-12-10 03:23:21 +01:00
cache_suffix: "?v='.$this->version().'",
element_format : "html",
entity_encoding : "raw",
schema: "html5",
extended_valid_elements : "a[class|name|href|target|title|onclick|rel],script[type|src],iframe[src|style|width|height|scrolling|marginwidth|marginheight|frameborder],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name]",
2015-11-30 03:53:44 +01:00
plugins: "'.$this->getDbField('plugins').'",
toolbar: "'.$this->getDbField('toolbar').'",
2015-12-10 03:23:21 +01:00
content_css: "'.$pluginPath.'css/editor.css",
2015-11-30 03:53:44 +01:00
theme: "modern",
height:"400px",
width:"100%",
statusbar: false,
menubar:false,
2015-12-01 03:57:46 +01:00
'.$language.'
2015-11-30 03:53:44 +01:00
browser_spellcheck: true,
autoresize_bottom_margin: "50",
pagebreak_separator: "'.PAGE_BREAK.'",
paste_as_text: true,
document_base_url: "'.HTML_PATH_UPLOADS.'"
});';
$html .= '$("#jsaddImage").on("click", function() {
var filename = $("#jsimageList option:selected" ).text();
if(!filename.trim()) {
return false;
}
tinymce.activeEditor.insertContent("<img src=\""+filename+"\" alt=\"\">" + "\n");
});';
$html .= '}); </script>';
}
return $html;
}
}