1
0
mirror of https://github.com/e107inc/e107.git synced 2025-02-13 11:04:38 +01:00

422 lines
12 KiB
PHP
Raw Normal View History

2006-12-22 18:45:32 +00:00
<?php
/*
+ ----------------------------------------------------------------------------+
| e107 website system - Tiny MCE controller file.
|
2011-06-07 12:57:55 +00:00
| $URL$
| $Id$
2006-12-22 18:45:32 +00:00
+----------------------------------------------------------------------------+
*/
$_E107['no_online'] = true;
require_once("../../class2.php");
ob_start();
ob_implicit_flush(0);
header("last-modified: " . gmdate("D, d M Y H:i:s",mktime(0,0,0,15,2,2004)) . " GMT");
header('Content-type: text/javascript', TRUE);
2006-12-22 18:45:32 +00:00
2009-09-21 16:33:32 +00:00
$wy = new wysiwyg();
echo_gzipped_page();
2009-10-12 06:38:01 +00:00
class wysiwyg
2009-09-21 16:33:32 +00:00
{
2009-10-12 06:38:01 +00:00
var $js;
var $config = array();
2009-11-10 01:21:05 +00:00
var $configName;
2011-06-07 12:57:55 +00:00
function __construct($config=FALSE)
2009-10-12 06:38:01 +00:00
{
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
$this->getConfig($config);
2011-06-07 12:57:55 +00:00
$pref = e107::getConfig();
2009-10-12 06:38:01 +00:00
/*
if(strstr(varset($_SERVER["HTTP_ACCEPT_ENCODING"],""), "gzip") && (ini_get("zlib.output_compression") == false) && file_exists(e_PLUGIN."tinymce/tiny_mce_gzip.php"))
{
2011-06-07 12:57:55 +00:00
//unset($tinymce_plugins[7]); // 'zoom' causes an error with the gzip version.
2009-10-12 06:38:01 +00:00
$text = "<script type='text/javascript' src='".e_PLUGIN_ABS."tinymce/tiny_mce_gzip.js'></script>
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
<script type='text/javascript'>
tinyMCE_GZ.init({
plugins : '".implode(",",$tinymce_plugins)."',
themes : 'advanced',
languages : '".$tinylang[$lang]."',
disk_cache : false,
debug : false
});
</script>
";
}
2009-10-12 06:38:01 +00:00
else
{*/
// $text = "<script type='text/javascript' src='".e_PLUGIN_ABS."tinymce/tiny_mce.js'></script>\n";
2009-10-12 06:38:01 +00:00
//}
2011-06-07 12:57:55 +00:00
// $text .= "<script type='text/javascript'>\n";
2009-11-10 01:21:05 +00:00
$text .= "\n /* TinyMce Config: ".$this->configName." */";
2009-10-12 06:38:01 +00:00
$text .= $this->tinyMce_config();
2011-06-07 12:57:55 +00:00
2012-11-24 16:29:38 -08:00
$text .= "\t\t
$(document).ready(function()
{
start_tinyMce(); \n
}); ";
$text .= "
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
function tinymce_e107Paths(type, source) {
2011-05-10 12:41:22 +00:00
";
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
$tp = e107::getParser();
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
$paths = array(
e107::getFolder('images'),
e107::getFolder('plugins'),
// e107::getFolder('media_images'), //XXX Leave disabled - breaks thumb.php={e_MEDIA_IMAGE} which is required.
2011-05-10 12:41:22 +00:00
e107::getFolder('media_files'),
e107::getFolder('media_videos')
);
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
$text .= "
2009-10-12 06:38:01 +00:00
switch (type) {
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
case 'get_from_editor':
// Convert HTML to e107-BBcode
source = source.replace(/target=\"_blank\"/, 'rel=\"external\"');
// source = source.replace(/^\s*|\s*$/g,'');
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
";
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
// Convert TinyMce Paths to e107 paths.
foreach($paths as $k=>$path)
{
//echo "<br />$path = ".$tp->createConstants($path);
2011-06-07 12:57:55 +00:00
$text .= "\t\tsource = source.replace(/(\"|])".str_replace("/","\/",$path)."/g,'$1".$tp->createConstants($path)."');\n";
}
2011-05-10 12:41:22 +00:00
$text .= "
break;
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
case 'insert_to_editor': // Convert e107Paths for TinyMce
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
source = source.replace(/rel=\"external\"/, 'target=\"_blank\"');
2012-05-01 09:42:20 +00:00
2011-05-10 12:41:22 +00:00
";
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
// Convert e107 paths to TinyMce Paths.
foreach($paths as $k=>$path)
{
$const = str_replace("}","\}",$tp->createConstants($path));
2011-06-07 12:57:55 +00:00
$text .= "\t\tsource = source.replace(/".$const."/gi,'".$path."');\n";
2011-05-10 12:41:22 +00:00
}
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
$text .= "
break;
2009-10-12 06:38:01 +00:00
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
return source;
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
// ]]>
function triggerSave()
{
2009-10-12 06:38:01 +00:00
tinyMCE.triggerSave();
}
2011-06-07 12:57:55 +00:00
";
//$text .= "</script>\n";
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
$this->js = $text;
$this->render();
2011-06-07 12:57:55 +00:00
2009-07-01 04:19:55 +00:00
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
function tinymce_lang()
{
2009-10-12 06:38:01 +00:00
$lang = e_LANGUAGE;
$tinylang = array(
"Arabic" => "ar",
2012-11-30 18:15:24 -08:00
"Bulgarian" => "bg",
2009-10-12 06:38:01 +00:00
"Danish" => "da",
"Dutch" => "nl",
"English" => "en",
2012-11-30 18:15:24 -08:00
"Persian" => "fa",
2009-10-12 06:38:01 +00:00
"French" => "fr",
"German" => "de",
"Greek" => "el",
"Hebrew" => " ",
"Hungarian" => "hu",
"Italian" => "it",
"Japanese" => "ja",
"Korean" => "ko",
"Norwegian" => "nb",
"Polish" => "pl",
"Russian" => "ru",
"Slovak" => "sk",
"Spanish" => "es",
"Swedish" => "sv"
);
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
if(!$tinylang[$lang])
{
$tinylang[$lang] = "en";
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
return $tinylang[$lang];
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
function tinyMce_config()
{
2009-10-26 10:55:46 +00:00
$text = "
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
function start_tinyMce()
{
//<![CDATA[
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
tinyMCE.init({ \n\n";
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
$newConfig = array();
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
foreach($this->config as $key=>$val)
2011-05-10 12:41:22 +00:00
{
2011-03-12 11:01:07 +00:00
if($val != 'true' && $val !='false')
{
$val = "'".$val."'";
}
2011-05-10 12:41:22 +00:00
$newConfig[] = "\t\t ".$key." : ".$val;
2009-10-12 06:38:01 +00:00
}
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
$text .= implode(",\n",$newConfig);
2009-10-12 06:38:01 +00:00
$text .= "
});
2011-06-07 12:57:55 +00:00
}
2011-06-07 12:57:55 +00:00
";
2009-10-12 06:38:01 +00:00
return $text;
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
function getConfig($config=FALSE)
2013-03-07 22:42:09 -08:00
{
$tp = e107::getParser();
2013-03-09 00:22:26 -08:00
$fl = e107::getFile();
2013-03-07 22:42:09 -08:00
if(getperms('0'))
{
$template = "mainadmin.xml";
}
elseif(ADMIN)
{
$template = "admin.xml";
}
elseif(USER)
2009-10-12 06:38:01 +00:00
{
$template = "member.xml";
2009-10-12 06:38:01 +00:00
}
else
{
$template = "public.xml";
2009-10-12 06:38:01 +00:00
}
$configPath = (is_readable(THEME."templates/tinymce/".$template)) ? THEME."templates/tinymce/".$template : e_PLUGIN."tinymce/templates/".$template;
$config = e107::getXml()->loadXMLfile($configPath, true);
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
//TODO Cache!
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
$plug_array = explode(",",$config['tinymce_plugins']);
2009-11-10 01:21:05 +00:00
$this->configName = $config['tinymce_name'];
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
$this->config = array(
'language' => $this->tinymce_lang(),
'mode' => 'specific_textareas',
2009-10-12 06:38:01 +00:00
'editor_selector' => 'e-wysiwyg',
'editor_deselector' => 'e-wysiwyg-off',
'theme' => 'advanced',
2013-02-20 13:38:49 -08:00
'skin' => 'bootstrap', // See https://github.com/gtraxx/tinymce-skin-bootstrap
2009-10-12 06:38:01 +00:00
'plugins' => $this->filter_plugins($config['tinymce_plugins'])
);
2011-06-07 12:57:55 +00:00
2013-03-09 00:22:26 -08:00
$cssFiles = $fl->get_files(THEME,"\.css",'',2);
2013-03-09 00:22:26 -08:00
foreach($cssFiles as $val)
{
$css[] = str_replace(THEME,THEME_ABS,$val['path'].$val['fname']);
}
$css[] = "{e_WEB_ABS}js/bootstrap/css/bootstrap.min.css";
2013-03-09 00:22:26 -08:00
$content_css = vartrue($config['content_css'], implode(",",$css));
2013-03-07 22:42:09 -08:00
$content_styles = array('Bootstrap Button' => 'btn btn-primary', 'Bootstrap Table' => 'table');
2009-10-12 06:38:01 +00:00
$this->config += array(
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
'theme_advanced_buttons1' => $config['tinymce_buttons1'],
'theme_advanced_buttons2' => vartrue($config['tinymce_buttons2']),
'theme_advanced_buttons3' => vartrue($config['tinymce_buttons3']),
'theme_advanced_buttons4' => vartrue($config['tinymce_buttons4']),
'theme_advanced_toolbar_location' => vartrue($config['theme_advanced_toolbar_location'],'top'),
'theme_advanced_toolbar_align' => 'left',
2013-03-07 22:42:09 -08:00
'theme_advanced_blockformats' => 'p,h2,h3,h4,h5,h6,blockquote,pre,code',
'theme_advanced_styles' => str_replace(array("+")," ",http_build_query($content_styles)), //'Bootstrap Button=btn btn-primary;Bootstrap Table=table;border=border;fborder=fborder;tbox=tbox;caption=caption;fcaption=fcaption;forumheader=forumheader;forumheader3=forumheader3',
// 'theme_advanced_resize_vertical' => 'true',
'dialog_type' => "modal",
// 'theme_advanced_source_editor_height' => '400',
// ------------- html5 Stuff.
// 'visualblocks_default_state' => 'true',
// Schema is HTML5 instead of default HTML4
// 'schema' => "html5",
// End container block element when pressing enter inside an empty block
// 'end_container_on_empty_block' => true,
// HTML5 formats
/*
'style_formats' => "[
{title : 'h1', block : 'h1'},
{title : 'h2', block : 'h2'},
{title : 'h3', block : 'h3'},
{title : 'h4', block : 'h4'},
{title : 'h5', block : 'h5'},
{title : 'h6', block : 'h6'},
{title : 'p', block : 'p'},
{title : 'div', block : 'div'},
{title : 'pre', block : 'pre'},
{title : 'section', block : 'section', wrapper: true, merge_siblings: false},
{title : 'article', block : 'article', wrapper: true, merge_siblings: false},
{title : 'blockquote', block : 'blockquote', wrapper: true},
{title : 'hgroup', block : 'hgroup', wrapper: true},
{title : 'aside', block : 'aside', wrapper: true},
{title : 'figure', block : 'figure', wrapper: true}
]",
*/
// --------------------------------
2009-10-12 06:38:01 +00:00
// 'theme_advanced_statusbar_location' => 'bottom',
2013-03-02 02:25:14 -08:00
'theme_advanced_resizing' => 'true',
2012-12-02 07:13:56 +02:00
'remove_linebreaks' => 'false',
'extended_valid_elements' => vartrue($config['extended_valid_elements']),
// 'pagebreak_separator' => "[newpage]",
2012-12-02 07:13:56 +02:00
'apply_source_formatting' => 'true',
'invalid_elements' => 'font,align,script,applet',
2009-10-12 06:38:01 +00:00
'auto_cleanup_word' => 'true',
'cleanup' => 'true',
2009-10-12 06:38:01 +00:00
'convert_fonts_to_spans' => 'true',
2013-03-07 22:42:09 -08:00
'content_css' => $tp->replaceConstants($content_css),
'popup_css' => 'false',
2009-10-12 06:38:01 +00:00
'trim_span_elements' => 'true',
'inline_styles' => 'true',
'auto_resize' => 'false',
2009-10-12 06:38:01 +00:00
'debug' => 'false',
2012-05-01 09:42:20 +00:00
'force_br_newlines' => 'true',
'media_strict' => 'false',
'width' => vartrue($config['width'],'100%'),
// 'height' => '90%', // higher causes padding at the top?
2013-03-08 21:48:28 -08:00
'forced_root_block' => 'false', //remain as false or it will mess up some theme layouts.
2012-06-09 04:42:32 +00:00
'convert_newlines_to_brs' => 'true', // will break [list] if set to true
2012-07-07 20:46:59 +00:00
// 'force_p_newlines' => 'false',
2009-10-12 06:38:01 +00:00
'entity_encoding' => 'raw',
'convert_fonts_to_styles' => 'true',
'remove_script_host' => 'true',
'relative_urls' => 'false', //Media Manager prefers it like this.
2012-05-01 09:42:20 +00:00
'preformatted' => 'true',
2009-10-12 06:38:01 +00:00
'document_base_url' => SITEURL,
'verify_css_classes' => 'false'
);
2011-06-07 12:57:55 +00:00
2011-05-10 12:41:22 +00:00
// if(!in_array('e107bbcode',$plug_array))
2009-10-12 06:38:01 +00:00
{
$this->config['cleanup_callback'] = 'tinymce_e107Paths';
2009-10-12 06:38:01 +00:00
}
2011-06-07 12:57:55 +00:00
2009-10-26 10:55:46 +00:00
$paste_plugin = (strpos($config['tinymce_plugins'],'paste')!==FALSE) ? TRUE : FALSE;
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
if($paste_plugin)
{
$this->config += array(
2011-06-07 12:57:55 +00:00
2012-08-18 22:19:37 +00:00
'paste_text_sticky' => 'true',
'paste_text_sticky_default' => 'true',
'paste_text_linebreaktype' => 'br',
2009-10-12 06:38:01 +00:00
'remove_linebreaks' => 'false', // remove line break stripping by tinyMCE so that we can read the HTML
'paste_create_paragraphs' => 'false', // for paste plugin - double linefeeds are converted to paragraph elements
2012-08-18 22:19:37 +00:00
'paste_create_linebreaks' => 'true', // for paste plugin - single linefeeds are converted to hard line break elements
2009-10-12 06:38:01 +00:00
'paste_use_dialog' => 'true', // for paste plugin - Mozilla and MSIE will present a paste dialog if true
'paste_auto_cleanup_on_paste' => 'true', // for paste plugin - word paste will be executed when the user copy/paste content
'paste_convert_middot_lists' => 'false', // for paste plugin - middot lists are converted into UL lists
'paste_unindented_list_class' => 'unindentedList', // for paste plugin - specify what class to assign to the UL list of middot cl's
'paste_convert_headers_to_strong' => 'true', // for paste plugin - converts H1-6 elements to strong elements on paste
'paste_insert_word_content_callback' => 'convertWord', // for paste plugin - This callback is executed when the user pastes word content
'auto_cleanup_word' => 'true' // auto clean pastes from Word
2009-10-12 06:38:01 +00:00
);
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
if(ADMIN)
{
2011-06-07 12:57:55 +00:00
$this->config['external_link_list_url'] = e_PLUGIN_ABS."tiny_mce/filelist.php";
2009-10-12 06:38:01 +00:00
}
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
function filter_plugins($plugs)
{
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
$smile_pref = e107::getConfig()->getPref('smiley_activate');
2011-06-07 12:57:55 +00:00
$admin_only = array("ibrowser");
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
$plug_array = explode(",",$plugs);
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
foreach($plug_array as $val)
{
if(in_array($val,$admin_only) && !ADMIN)
{
continue;
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
if(!$smile_pref && ($val=="emoticons"))
{
continue;
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
$tinymce_plugins[] = $val;
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
return implode(",",$tinymce_plugins);
}
2011-06-07 12:57:55 +00:00
2009-10-12 06:38:01 +00:00
function render()
{
echo $this->js;
}
2006-12-22 18:45:32 +00:00
}
2009-10-12 06:38:01 +00:00
?>