<?php
/**
* @package MOStlyCE
* @author Chad Auld (hide@address.com)
* @copyright Brilaps, LLC (http://brilaps.com)
* @license GNU Lesser General Public License (LGPL - http://www.gnu.org/licenses/lgpl.html)
*/
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $mosConfig_live_site, $jspath, $mosConfig_absolute_path, $adminside;
include($mosConfig_absolute_path."mambots/editors/mostlyce/jscripts/tiny_mce/mostlyce_config.php");
$_MAMBOTS->registerFunction( 'onInitEditor', 'botmostlyceEditorInit' );
$_MAMBOTS->registerFunction( 'onGetEditorContents', 'botmostlyceEditorGetContents' );
$_MAMBOTS->registerFunction( 'onEditorArea', 'botmostlyceEditorEditorArea' );
// --- Start custom code DHS Informatisering - hide@address.com, www.dhs.nl
// This code makes it possible to use mostlyce in a website that combines normal and SSL-connections
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
$jspath = "https:" . stristr ( $mosConfig_live_site, "//" );
} else {
$jspath = "http:" . stristr ( $mosConfig_live_site, "//" );
}
// Replaced every occurrence of '$mosConfig_live_site' with '$jspath' in this file
// --- End custom code DHS Informatisering ---
//Render Row Buttons
function renderButton($row, $remove_font) {
$row = explode( ',', $row );
foreach( $row as $key => $rowitem ) {
if( strpos( $rowitem, '-' ) === 0) {
unset( $row[$key] );
}
if( $remove_font ){
if( $rowitem == 'fontselect' || $rowitem == 'fontsizeselect' || $rowitem == 'forecolor' || $rowitem == 'backcolor' ) {
unset( $row[$key] );
}
}
}
return $new_row = implode( ',', array_values( $row ) );
}
/**
* TinyMCE WYSIWYG Editor - javascript initialization
*/
function botmostlyceEditorInit() {
global $mosConfig_live_site, $my, $database, $mosConfig_absolute_path, $jspath;
global $adminside, $mosConfig_secret, $mosConfig_cachetime;
include($mosConfig_absolute_path."mambots/editors/mostlyce/jscripts/tiny_mce/mostlyce_config.php");
//Setup a session variable for Image Manager and external list generator security checks
$env = md5($_SERVER['HTTP_USER_AGENT']);
$mostlyceRestoreKey=md5($mosConfig_secret.$env.$_SERVER['REMOTE_ADDR']);
//Determine cookie expiration time. Should match login timeout (though min of 1min).
if (is_numeric($mosConfig_cachetime) && $mosConfig_cachetime>=60) {
$cookieTimeout = $mosConfig_cachetime;
} else {
$cookieTimeout = 60;
}
setcookie("mostlyce[startup_key]", $mostlyceRestoreKey, time()+$cookieTimeout, '/');
setcookie("mostlyce[usertype]", $my->usertype, time()+$cookieTimeout, '/');
//Allows for dynamic editor sizing by apps like Remository
$get_width = mosGetParam($_GET,'width',NULL);
$get_height = mosGetParam($_GET,'height',NULL);
if ($get_width) {
$editor_width = (int) $get_width;
}
if ($get_height) {
$editor_height = (int) $get_height;
}
// Get the default stylesheet
$query = "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'";
$database->setQuery( $query );
$cur_template = $database->loadResult();
// Assigned template
if (isset( $Itemid ) && $Itemid != "" && $Itemid != 0) {
$query = "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='$Itemid' LIMIT 1";
$database->setQuery($query);
$cur_template = $database->loadResult() ? $database->loadResult() : $cur_template;
}
//Plugin settings and Authorization
$invalid_elements[] = 'object,applet';
//Check access level and MOStlyCE Admin preference. Set editor items accordingly.
//Script Elements (Only loads for Admin)
if (($adminside>0) && ($editor_script_acl==='true')) {
$elements[] = "script[$editor_script_elms]";
} else {
$invalid_elements[] = "script";
}
//IFrame Elements (Only loads for Admin)
if (($adminside>0) && ($editor_iframe_acl=='true')) {
$elements[] = "iframe[$editor_iframe_elms]";
}
//Media Plugin
if ($editor_plugin_media_acl==='true') {
$plugins[] = 'media';
}
//Font Options
if ($editor_font_tools_acl==='true') {
$elements[] = "font[face|size|color|style]";
$remove_font = false;
} else {
$remove_font = true;
}
//Emotions Plugin
if ($editor_plugin_emotions_acl==='true') {
$plugins[] = 'emotions';
}
//Print Plugin
if ($editor_plugin_print==='true') {
$plugins[] = 'print';
}
//Search & Replace Plugin
if ($editor_plugin_searchreplace==='true') {
$plugins[] = 'searchreplace';
}
//Table Plugin
if ($editor_plugin_table_acl==='true') {
$plugins[] = 'table';
}
//DateTime Plugin
if ($editor_plugin_datetime_acl==='true') {
$plugins[] = 'insertdatetime';
}
//SpellChecker Plugin (needs Curl)
if ($editor_plugin_spellchecker==='true' && function_exists("curl_init")) {
$plugins[] = 'spellchecker';
$theme_advanced_buttons_add = 'spellchecker';
} else {
$theme_advanced_buttons_add = '';
}
//Layer Plugin
if ($editor_plugin_layer==='true') {
$plugins[] = 'layer';
}
//Image/File Manager Plugin
if ($editor_plugin_img_mgr==='true') {
$file_browser_callback='fileBrowserCallBack';
} else {
//Img/File browser not enabled
$file_browser_callback='';
}
//Paragraphs or breaks
if ($editor_newlines == 'p') {
$p_newlines = "true";
$br_newlines = "false";
}
if ($editor_newlines == 'br') {
$p_newlines = "false";
$br_newlines = "true";
}
$css_template = $mosConfig_live_site."/templates/".$cur_template."/css/";
$content_css = ($editor_css_override === '1' ) ? $css_template.$editor_custom_css : $css_template."template_css.css";
//Plugins List
$plugins[] = $editor_extra_plugins;
$plugins[] = 'safari,pagebreak,style,advhr,advimage,advlink,iespell,inlinepopups,preview,contextmenu,paste,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras'; //These ones are always loaded
$plugins = implode( ',', $plugins );
$elements[] = $editor_xtd_elms;
$elements = implode( ',', $elements );
$invalid_elements = implode( ',', $invalid_elements );
/* Check TinyMCE compression setting & verify requestors compression capabilites and set correct file path
Notes:
* The TinyMCE PHP gzip compressor cannot and will not work if zlib compression is already enabled on the server.
* If they requested editor compression run the checks otherwise don't waste the cycles
*/
$supportsGzip = false;
if ($editor_compression==='true') {
$encodings = '';
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
$encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
}
if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
$enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
$supportsGzip = true;
}
}
$tinyHeader = '';
if ($editor_compression==='true' && $supportsGzip===true) {
$tinyHeader = "<script type=\"text/javascript\" src=\"$jspath/mambots/editors/mostlyce/jscripts/tiny_mce/tiny_mce_gzip.js\"></script>";
$tinyHeader .="<!-- Standard init and GZ init need to be in seperate script tags! -->
<script type=\"text/javascript\">
tinyMCE_GZ.init({
plugins : '$plugins',
themes : '$editor_themes',
languages : '$editor_lang',
disk_cache : true,
debug : false
});
</script>";
} else {
$tinyHeader = "<script type=\"text/javascript\" src=\"$jspath/mambots/editors/mostlyce/jscripts/tiny_mce/tiny_mce.js\"></script>";
}
$external_link_list_url = htmlentities($jspath.'/index2.php?option=com_mostlyce_frontend&task=contentlist&no_html=1', ENT_QUOTES, 'UTF-8');
$external_image_list_url = htmlentities($jspath.'/index2.php?option=com_mostlyce_frontend&task=imagelist&no_html=1', ENT_QUOTES, 'UTF-8');
return <<<EOD
<!--//TinyMCE/MOStlyCE-->
$tinyHeader
<script type="text/javascript" src="$jspath/mambots/editors/mostlyce/jscripts/tiny_mce/mostlyce_functions.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
tinyMCE.init({
//General options
mode : "textareas",
editor_selector : "mceEditor",
theme : "$editor_themes",
plugins : "$plugins",
//Theme options
theme_advanced_buttons1: "styleselect,formatselect,fontselect,fontsizeselect,charmap,help",
theme_advanced_buttons2: "undo,redo,|,newdocument,cut,cleanup,copy,paste,pastetext,pasteword, print,search,replace|,bold,italic,underline,forecolor,backcolor,code,styleprops",
theme_advanced_buttons3: "justifyleft,justifycenter,justifyright,justifyfull,directionality,|,bullist,numlist,outdent,indent,blockquote,|,hr,advhr,|,strikethrough,sub,sup,visualchars,del,ins,attribs",
theme_advanced_buttons4: "link,unlink,anchor,|,tablecontrols,|,removeformat,visualaid",
theme_advanced_buttons5: "image,emotions,media,|,preview,fullscreen,|,insertdate,inserttime,insertlayer,moveforward,movebackward,absolute,cite,abbr,acronym, nonbreaking,template,pagebreak",
theme_advanced_buttons5_add : "$theme_advanced_buttons_add",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
//Drop lists for link/image/media/template dialogs
//template_external_list_url : "",
external_link_list_url : "$external_link_list_url",
external_image_list_url : "$external_image_list_url",
//media_external_list_url : "",
//More MOStlyCE custom settings
file_browser_callback : "$file_browser_callback",
theme_advanced_source_editor_width : "$editor_width",
theme_advanced_source_editor_height : "$editor_height",
miacms_base_url : "$mosConfig_live_site/",
document_base_url : "$mosConfig_live_site/",
plugin_insertdate_dateFormat : "$editor_plugin_dateformat",
plugin_insertdate_timeFormat : "$editor_plugin_timeformat",
content_css : "$content_css",
entity_encoding : "raw",
invalid_elements : "$invalid_elements",
force_br_newlines : "$br_newlines",
force_p_newlines : "$p_newlines",
directionality : "$editor_direction",
language : "$editor_lang",
lang_list : "$editor_lang_list",
pagebreak_separator : "{mospagebreak}",
extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],$elements",
spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv"
});
function fileBrowserCallBack(field_name, url, type, win) {
var connector = "$jspath/mambots/editors/mostlyce/jscripts/tiny_mce/filemanager/browser.php?Connector=connectors/php/connector.php";
var enableAutoTypeSelection = false;
var cType;
tinymcpuk_field = field_name;
tinymcpuk = win;
switch (type) {
case "image":
cType = "Image";
break;
case "flash":
cType = "Flash";
break;
case "file":
cType = "File";
break;
case "media":
cType = "Media";
break;
}
if (enableAutoTypeSelection && cType) {
connector += "&Type=" + cType;
}
window.open(connector, "tinymcpuk", "modal,width=600,height=400");
}
/*]]>*/
</script>
<!-- /tinyMCE -->
EOD;
}
/**
* TinyMCE WYSIWYG Editor - copy editor contents to form field
* @param string The name of the editor area
* @param string The name of the form field
*/
function botmostlyceEditorGetContents($editorArea, $hiddenField) {
global $jspath;
return <<<EOD
tinyMCE.triggerSave();
EOD;
}
/**
* mostlyce WYSIWYG Editor - display the editor
* @param string The name of the editor area
* @param string The content of the field
* @param string The name of the form field
* @param string The width of the editor area
* @param string The height of the editor area
* @param int The number of columns for the editor area
* @param int The number of rows for the editor area
*/
function botmostlyceEditorEditorArea($name, $content, $hiddenField, $width, $height, $col, $row, $showbut=1) {
global $jspath, $_MAMBOTS, $mosConfig_absolute_path;
include($mosConfig_absolute_path."mambots/editors/mostlyce/jscripts/tiny_mce/mostlyce_config.php");
$results = $_MAMBOTS->trigger('onCustomEditorButton');
$buttons = array();
foreach ($results as $result) {
$buttons[] = '<img src="'.$jspath.'/mambots/editors-xtd/'.$result[0].'" alt="custom buttons" onclick="tinyMCE.execCommand(\'mceInsertContent\',false,\''.$result[1].'\')" />';
}
//Hide old {mosimage} button if requested
if ($editor_mosimage_icon == 'false') {
unset($buttons[array_search(0,$buttons)]);
}
$buttons = implode( "", $buttons );
return <<<EOD
<textarea id="$hiddenField" name="$hiddenField" cols="" rows="" style="width:{$width}px; height:{$height}px;" class="mceEditor">$content</textarea>
<br />$buttons
EOD;
}
?>