MyBB Community Forums

Full Version: How to add spoiler mycode input button in the post editor.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to insert a button that helps in inserting the spoiler mycode with the other mycode buttons.

Want some help urgently!
You can add buttons using this tutorial: http://community.mybb.com/thread-95808.html
Here try this Sample plugin

Create a file called "spoiler.php" in your "inc/plugins" directory.

And copy this code into that file and active the plugin.

<?php
if(!defined("IN_MYBB"))
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");

function spoiler_info() {
	return array(
		'name'			=>	'Spoiler For MyBB',
		'description'   	=>	'',
		'website'		=>	'https://mybb.com/',
		'author'		=>	'SiDD',
		'authorsite'	        =>	'',
		'version'		=>	'1.0.0',
		'compatibility' => '16*',
	);	
}

$plugins->add_hook("parse_message", "spoiler_add");
$plugins->add_hook("pre_output_page","spoiler_add_script");

function spoiler_activate() {
	//Do nothing...
}

function spoiler_deactivate() {
	//Do nothing...
}

function spoiler_add($content) {
	global $mybb;
		
	if(preg_match("/\[spoiler\](.*)?\[\/spoiler\]/i",$content,$match))
		$content = preg_replace("/\[spoiler\](.*)?\[\/spoiler\]/i","<input id=\"spoiler_showhide\" name=\"show\" value=\"Show Sopiler\" type=\"button\" style=\"font-size:9px\" onclick=\"spoiler_showhide()\" /><input id=\"spoiler_hideshow\" name=\"hide\" value=\"Hide Sopiler\" type=\"button\" style=\"font-size:9px;display:none\" onclick=\"spoiler_hideshow()\" /><div id=\"spoiler_content\" >".$match[1]."</div>",$content);
	
	return $content;
}

function spoiler_add_script($page) {
	global $mybb;
	
	$page = str_replace("</head>","<style type=\"text/css\"> div #spoiler_content { display:none;border:1px solid #999999;padding:2px;margin-top:3px;background-color:#FFFFFF;font-size:10px } </style>
	<script type=\"text/javascript\">
	function spoiler_showhide() {
			document.getElementById(\"spoiler_content\").style.display=\"block\";
			document.getElementById(\"spoiler_hideshow\").style.display=\"block\";
			document.getElementById(\"spoiler_showhide\").style.display=\"none\";
	}
	function spoiler_hideshow() {
			document.getElementById(\"spoiler_content\").style.display=\"none\";
			document.getElementById(\"spoiler_hideshow\").style.display=\"none\";
			document.getElementById(\"spoiler_showhide\").style.display=\"block\";
	}
	</script>
	</head>",$page);
	
	return $page;
}


?>