<?php
/*
Simple:Press Forum
tinymce init
$LastChangedDate: 2010-02-26 04:01:05 -0700 (Fri, 26 Feb 2010) $
$Rev: 3603 $
*/

if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
	die('Access Denied');
}
	if($sfglobals['editor']['sfrtl'] ? $SFDIR='rtl' : $SFDIR='ltr');

	# prepare uploading settings...
	$sfconfig = sf_get_option('sfconfig');
	$canimage = '0';
	$canmedia = '0';
	$canfile  = '0';

	$up_path = SF_STORE_DIR.'/'.$sfconfig['image-uploads'];
	if(file_exists($up_path) && is_writable($up_path) && $current_user->sfuploadimg == true) {
		$canimage = '1';
	}

	$up_path = SF_STORE_DIR.'/'.$sfconfig['media-uploads'];
	if(file_exists($up_path) && is_writable($up_path) && $current_user->sfuploadmedia == true) {
		$canmedia = '1';
	}

	$up_path = SF_STORE_DIR.'/'.$sfconfig['file-uploads'];
	if(file_exists($up_path) && is_writable($up_path) && $current_user->sfuploadfile == true) {
		$canfile = '1';
	}

	echo '<script type="text/javascript" src="'.SFEDITORURL.'tinymce/tiny_mce.js"></script>'. "\n";

	if($canimage || $canmedia || $canfile)
	{
		echo '<script type="text/javascript" src="'.SFEDITORURL.'tinymce/plugins/filemanager/fm-tinymce.js.php"></script>'. "\n";
	}
?>
	<script type="text/javascript">
	tinyMCE.init({
		canimage: <?php echo($canimage); ?>,
		canmedia: <?php echo($canmedia); ?>,
		canfile: <?php echo($canfile); ?>,
		mode : "exact",
		elements : "postitem",
		theme : "advanced",
		theme_advanced_layout_manager : "SimpleLayout",
		skin : "o2k7",
		content_css : "<?php echo(SFEDSTYLE . 'tinymce/'.$sfglobals["editor"]["sftmcontentCSS"]); ?>",
		popup_css : "<?php echo(SFEDSTYLE . 'tinymce/'.$sfglobals["editor"]["sftmdialogCSS"]); ?>",
		editor_css : "<?php echo(SFEDSTYLE . 'tinymce/'.$sfglobals["editor"]["sftmuiCSS"]); ?>",
		language : "<?php echo($sfglobals['editor']['sflang']); ?>",
		directionality : "<?php echo($SFDIR); ?>",
		auto_reset_designmode : true,
		width : "100%",
		height: "360",
		<?php if($canimage || $canmedia || $canfile)
		{ ?>
		file_browser_callback : "sf_filemanager",
		<?php } ?>
		relative_urls : false,
		<?php if(!$sfglobals['editor']['sfrelative'])
		{ ?>
		convert_urls : false,
		<?php } ?>
		extended_valid_elements: "code",
		apply_source_formatting : true,
		paste_convert_middot_lists : true,
		paste_remove_spans : true,
		paste_remove_styles : true,
		paste_convert_headers_to_strong : true,
		paste_strip_class_attributes : "mso",
		remove_redundant_brs : true,
		forced_root_block : '',
		force_p_newlines : true,
		force_br_newlines : false,
		remove_linebreaks: false,
		convert_newlines_to_brs : false,
		remove_redundant_brs : true,
		entities:"38,amp,60,lt,62,gt",
		plugins : "<?php echo(sf_build_tb_plugins()); ?>",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location: "bottom",
		theme_advanced_resizing : true,
		theme_advanced_resizing_use_cookie : false,
		theme_advanced_buttons1 : "<?php echo(sf_build_tb_buttons()); ?>",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons1_add : "<?php echo(sf_build_tb_buttons_add()); ?>",
		plugin_preview_width : "750",
		plugin_preview_height : "400"
	});
	</script>
<?php


# Toolbar Support Routines

function sf_build_tb_plugins()
{
	global $sfglobals;

	$tb = implode(",", $sfglobals['toolbar']['tbar_plugins']);
	if($sfglobals['smileyoptions']['sfsmallow'] && $sfglobals['smileyoptions']['sfsmtype']!=2)
	{
		$tb = str_replace('emotions,', '', $tb);
		$tb = str_replace('emotions', '', $tb);
	}
	return $tb;
}

function sf_build_tb_buttons()
{
	global $sfglobals;

	return implode(",", $sfglobals['toolbar']['tbar_buttons']);
}

function sf_build_tb_buttons_add()
{
	global $sfglobals;

	$tb = implode(",", $sfglobals['toolbar']['tbar_buttons_add']);
	if($sfglobals['smileyoptions']['sfsmallow'] && $sfglobals['smileyoptions']['sfsmtype']!=2)
	{
		$tb = str_replace('emotions,', '', $tb);
		$tb = str_replace('emotions', '', $tb);
	}
	return $tb;
}

?>