MyBB Community Forums

Full Version: SCEditor jscripts load even for non-members
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

SCeditors 5 jscripts load even for non-members and everybody, how do i make this plugin so it only load for members which i guess will dramatically improve forums performance.

Thankyou
5 js scripts. Not good. If you have template conditionals installed then you can wrap those js in an if else (assuming they are in templates) where if the user is a guest or banned then the scripts will not load.

Plugin is on mybbhacks

http://mybbhacks.zingaburga.com/showthread.php?tid=464
yes, but i dont know how to do it, also i dont want to install another plugin

when sceditor have php files itself - maybe someone can put if else there, so those jscripts only load for members.

here is the php file for the plugin 1.0.9 -

<?php
/**
 @Author: Sam Clarke
 @Created: 22/06/12
 @Version: 1.0.9
 @Contact: [email protected]
*/

if(!defined("IN_MYBB"))
	die("You cannot directly access this file.");

define('SCEDITOR_PLUGIN_VER', '1.0.9');

$plugins->add_hook("pre_output_page", "sceditor_load");
$plugins->add_hook("parse_message", "sceditor_parse");
$plugins->add_hook("newreply_end", "sceditor_fix_quote");

function sceditor_info()
{
	global $lang;

	$lang->load('config_sceditor');

	return array(
		"name"			=> $lang->sceditor_title,
		"description"		=> "$lang->sceditor_desc <br />Blapage : <b>BlaPage.com</b>  <b><a href='http://www.blapage.com'><font color='red'>BlaPage</font></a>",
		"website"		=> "http://sceditor.samclarke.com",
		"author"		=> "Sam Clarke",
		"authorsite"		=> "http://www.samclarke.com/",
		"version"		=> SCEDITOR_PLUGIN_VER,
		"guid" 			=> "aaaec079369b70e0915fdd2b959093e3",
		"compatibility"		=> "16*"
	);
}

function sceditor_install() 
{
	global $db, $lang;

	$lang->load('config_sceditor');

	// clean up any old installation
	sceditor_uninstall();

	$query  = $db->simple_select("settinggroups", "COUNT(*) as rows");
	$dorder = $db->fetch_field($query, "rows") + 1;
	
	$groupid = $db->insert_query("settinggroups", array(
		'name'		=> 'sceditor',
		'title'		=> 'SCEditor BlaPage',
		'description'	=> 'SCEditor WYSIWYG BBCode editor blapage.',
		'disporder'	=> $dorder,
		'isdefault'	=> '0'
	));  
	

	$db->insert_query("settings", array(
		'name'		=> 'enablesceditor',
		'title'		=> $lang->enablesceditor_title,
		'description'	=> $lang->enablesceditor_desc,
		'optionscode'	=> 'onoff',
		'value'		=> '1',
		'disporder'	=> '1',
		'gid'		=> $groupid
	));

	$db->insert_query("settings", array(
		'name'		=> 'enablesceditor_newpost',
		'title'		=> $lang->enablesceditor_newpost_title,
		'description'	=> $lang->enablesceditor_newpost_desc,
		'optionscode'	=> 'yesno',
		'value'		=> '1',
		'disporder'	=> '2',
		'gid'		=> $groupid
	));

	$db->insert_query("settings", array(
		'name'		=> 'enablesceditor_quickreply',
		'title'		=> $lang->enablesceditor_quickreply_title,
		'description'	=> $lang->enablesceditor_quickreply_desc,
		'optionscode'	=> 'yesno',
		'value'		=> '1',
		'disporder'	=> '3',
		'gid'		=> $groupid
	));

	$db->insert_query("settings", array(
		'name'		=> 'enablesceditor_signature',
		'title'		=> $lang->enablesceditor_signature_title,
		'description'	=> $lang->enablesceditor_signature_desc,
		'optionscode'	=> 'yesno',
		'value'		=> '1',
		'disporder'	=> '4',
		'gid'		=> $groupid
	));

	$db->insert_query("settings", array(
		'name'		=> 'enablesceditor_pm',
		'title'		=> $lang->enablesceditor_pm_title,
		'description'	=> $lang->enablesceditor_pm_desc,
		'optionscode'	=> 'yesno',
		'value'		=> '1',
		'disporder'	=> '5',
		'gid'		=> $groupid
	));

	$db->insert_query("settings", array(
		'name'		=> 'enablesceditor_event',
		'title'		=> $lang->enablesceditor_event_title,
		'description'	=> $lang->enablesceditor_event_desc,
		'optionscode'	=> 'yesno',
		'value'		=> '1',
		'disporder'	=> '6',
		'gid'		=> $groupid
	));

	$db->insert_query("settings", array(
		'name'		=> 'sceditor_theme',
		'title'		=> $lang->sceditor_theme_title,
		'description'	=> $lang->sceditor_theme_desc,
		'optionscode'	=> "select\ndefault=Default\nmodern=Modern\noffice-toolbar=Office Toolbar\noffice=Office",
		'value'		=> 'default',
		'disporder'	=> '7',
		'gid'		=> $groupid
	));

	$db->insert_query("settings", array(
		'name'		=> 'sceditor_include_jquery',
		'title'		=> $lang->sceditor_include_jquery_title,
		'description'	=> $lang->sceditor_include_jquery_desc,
		'optionscode'	=> 'yesno',
		'value'		=> '1',
		'disporder'	=> '8',
		'gid'		=> $groupid
	));

	$db->insert_query("settings", array(
		'name'		=> 'sceditor_enable_jquery_noconflict',
		'title'		=> $lang->sceditor_enable_jquery_noconflict_title,
		'description'	=> $lang->sceditor_enable_jquery_noconflict_desc,
		'optionscode'	=> 'yesno',
		'value'		=> '1',
		'disporder'	=> '9',
		'gid'		=> $groupid
	));

	$db->insert_query("settings", array(
		'name'		=> 'sceditor_lang',
		'title'		=> $lang->sceditor_lang_title,
		'description'	=> $lang->sceditor_lang_desc,
		'optionscode'	=> "select\n" . 
					"default=Default\n" .  
					"en=English (GB)\n" . 
					"en-US=English (US)\n" . 
					"de=German\n" . 
					"fr=French\n" . 
					"pt-BR=Brazilian Portuguese\n" . 
					"nl=Dutch\n" . 
					"ru=Russian\n" . 
					"et=Estonian\n" . 
					"no=Norwegian\n" . 
					"sv=Swedish",
		'value'		=> 'default',
		'disporder'	=> '10',
		'gid'		=> $groupid
	));
	
	rebuild_settings();
}

function sceditor_is_installed() 
{
	global $db;

	$query = $db->simple_select("settinggroups", "COUNT(*) as rows", "name = 'sceditor'");
	$rows = $db->fetch_field($query, "rows");

	return ($rows > 0);
}

function sceditor_uninstall()
{
	global $db;
	
	$db->write_query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN(
		'enablesceditor',
		'enablesceditor_newpost',
		'enablesceditor_quickreply',
		'enablesceditor_signature',
		'enablesceditor_pm',
		'enablesceditor_event',
		'sceditor_theme'
	)");

	$db->delete_query("settinggroups", "name = 'sceditor'");
}

function sceditor_activate()
{
}

function sceditor_deactivate()
{
	include_once MYBB_ROOT."inc/adminfunctions_templates.php";
	
	// left to remove old versions, not needed anymore
	find_replace_templatesets(
		"misc_smilies_popup_smilie",
		"#".preg_quote('onclick="insertSmilie(\'{$smilie[\'insert\']}\', \'{$smilie[\'image\']}\');"')."#i",
		'onclick="insertSmilie(\'{$smilie[\'insert\']}\');"',
		0
	);

}

function sceditor_load($page)
{
	global $lang, $mybb, $cache;

	if(!$mybb->settings['enablesceditor'])
		return false;

	if(THIS_SCRIPT == "misc.php" && $mybb->input['action'] == "smilies")
	{
		$page = str_replace("function insertSmilie(code)", "function insertSmilie(code, src)", $page);
		$page = str_replace("editor.performInsert(code, \"\", true, false);", "editor.performInsert(code, src);", $page);

		return $page;
	}

	switch(THIS_SCRIPT)
	{
		case "newreply.php":
		case "newthread.php":
		case "editpost.php":
			if(!$mybb->settings['enablesceditor_newpost'])
				return false;
			break;
		case "showthread.php":
			if(!$mybb->settings['enablesceditor_quickreply'])
				return false;
			break;
		case "usercp.php":
			if($mybb->input['action'] != "editsig" || !$mybb->settings['enablesceditor_signature'])
				return false;
			break;
		case "private.php":
			if($mybb->input['action'] != "send" || !$mybb->settings['enablesceditor_pm'])
				return false;
			break;
		case "calendar.php":
			if($mybb->input['action'] != "addevent" || !$mybb->settings['enablesceditor_event'])
				return false;
			break;
		default:
			return false;
	}


	// sort and output emoticons
	$smilie_cache = $cache->read("smilies");
	$smilies = array();
	foreach($smilie_cache as $smilie)
		$smilies[$smilie['find']] = $smilie['image'];

	function smilie_len_cmp($a, $b)
	{
		if (strlen($a) == strlen($b))
			return 0;

		if (strlen($a) > strlen($b))
			return -1;

		return 1;
	}

	uksort($smilies, "smilie_len_cmp");



	$jquery = ($mybb->settings['sceditor_include_jquery']
			? '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver='.SCEDITOR_PLUGIN_VER.'"></script>'
			: '');

	$jqueryNoConflict = ($mybb->settings['sceditor_enable_jquery_noconflict'] ? '$.noConflict();' : '');



	if($mybb->settings['sceditor_lang'] && $mybb->settings['sceditor_lang'] !== 'default')
		$lang = '<script src="jscripts/sceditor/languages/' . $mybb->settings['sceditor_lang'] . '.js?ver='.SCEDITOR_PLUGIN_VER.'"></script>';
	else
		$lang = '';



	$js = '	' . $jquery . '
		<script>
			' . $jqueryNoConflict  . '
			var sceditor_lang = "' . ($mybb->settings['sceditor_lang'] === 'default'?'en':$mybb->settings['sceditor_lang']) . '";
			var mybb_emoticons = ' . json_encode( array('dropdown' => $smilies) ) . ';
			var sceditor_autofocus = ' . (THIS_SCRIPT!="showthread.php"?'true':'false') . ';
		</script>
		<link rel="stylesheet" href="jscripts/sceditor/themes/' . $mybb->settings['sceditor_theme'] . '.min.css?ver='.SCEDITOR_PLUGIN_VER.'" type="text/css" media="all" />
		<script src="jscripts/sceditor/jquery.sceditor.min.js?ver='.SCEDITOR_PLUGIN_VER.'"></script>
		' . $lang . '
		<script src="jscripts/sceditor/jquery.sceditor.mybb.helper.js?ver='.SCEDITOR_PLUGIN_VER.'"></script>';

	// strip the default editor
	$page = preg_replace(
		'#<script type="text/javascript" src="jscripts/editor.js\?ver=[0-9]{4}"></script>[^<]*<script type="text/javascript">.<!--[^<]*</script>#ism',
		"", 
		$page
	);

	// add the editors JS
	$page = str_replace('</head>', $js . '</head>', $page);

	return $page;
}

function sceditor_parse($message)
{
	// Add support for extra BBCode tags
	$message = preg_replace("/\[sup](.*?)\[\/sup\]/si", '<sup>$1</sup>', $message);
	$message = preg_replace("/\[sub](.*?)\[\/sub\]/si", '<sub>$1</sub>', $message);
	$message = preg_replace("/\[ol](.*?)\[\/ol\]/si", '<ol>$1</ol>', $message);
	$message = preg_replace("/\[ul](.*?)\[\/ul\]/si", '<ul>$1</ul>', $message);
	$message = preg_replace("/\[li](.*?)\[\/li\]/si", '<li>$1</li>', $message);
	$message = preg_replace("/\[youtube](?:http:\/\/)?([a-zA-Z0-9_\-]+)\[\/youtube\]/si", '<iframe width="800" height="415" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $message);

	// Sometimes if text is copied, it can have a font stack which is valid in SCEditor. So add support
	// for fonts with spaces and commas
	$message = preg_replace("/\[font=([a-z0-9 ,\-_]+)](.*?)\[\/font\]/si", '<span style="font-family: $1">$2</span>', $message);

	return $message;
}

function sceditor_fix_quote()
{
	global $message;

	// remove newline after quote tag
	$message = preg_replace("/(\[quote=[^\]]+\])\r?\n?/i", '$1', $message);
}

(2013-01-01, 03:56 AM)james12 Wrote: [ -> ]yes, but i dont know how to do it, also i dont want to install another plugin

Why not? Just do it :\