MyBB Community Forums

Full Version: Spoiler
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How Would I make it so when users use [spoiler][/spoiler] they can make a custom title like [spoiler='CustomTitle']SpoilerHere[/spoiler]?
Heres my current mycode


Short Description:

Regular Expression:

<div style="padding: 3px; background-color: #FFFFFF; border: 1px solid #d8d8d8; font-size: 1em; width: 100%;" ><div style="text-transform: uppercase; border-bottom: 1px solid #CCCCCC; margin-bottom: 3px; font-size: 0.8em; font-weight: bold; display: balock;"><span onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerHTML = '<b>Spoiler </b><a href=\'#\' onClick=\'return false;\'>Hide</a>'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerHTML = '<b>Spoiler </b><a href=\'#\' onClick=\'return false;\'>Show</a>'; }" /><b>Spoiler </b><a href="#" onClick="return false;">Show</a></span></div><div class="quotecontent"><div style="display: none;">$1</div></div></div>

I got this stuff from It works but I want to be able to name my spoilers. How?
Bumpity bump bump bump
I tried this earlier, but you cant do it with one mycode, you would have to do 2 mycode, one with and without. Regex cant do it by itself. There is a plugin that allows spoilers to do this though with both options. But to add it to a button you need to add a second plugin "myinsertbuttons" to allow you to add a sceditor button in the editor for it.

spoiler plugin


You might have to change the compatability line in the root file of ./inc/plugins/plugin_name.php to be able to install it...but both work in later versions afterwords as i am using them now.

I edited the CSS and default link value though to fit with our other code/quote/inline code boxes layout, etc.

 * Haz Spoiler
 * Copyright 2015 Hazmole, All Rights Reserved
 * License:
 * Get a Great help of Sephiroth's [Spoiler MyCode] plugin

// Disallow direct access to this file for security reasons
    die("Direct initialization of this file is not allowed.");

function hazSpoiler_info()
    return array(
        "name"          => "Haz Spoiler",
        "description"   => "Add [spoiler] tag",
        "website"       => "",
        "author"        => "Hazmole",
        "authorsite"    => "",
        "version"       => "1.0",
        "guid"          => "",
        "codename"      => str_replace('.php', '', basename(__FILE__)),
        "compatibility" => "*"

$plugins->add_hook("parse_message", "hazspoiler_run");

function hazspoiler_run($message) {
	// Key Define
	$pattern = array("#\[spoiler=(?:&quot;|\"|')?([a-zA-Z0-9!:\#\.\? \',\-\(\)]*?)[\"']?(?:&quot;|\"|')?\](.*?)\[\/spoiler\](\r\n?|\n?)#si", "#\[spoiler\](.*?)\[\/spoiler\](\r\n?|\n?)#si",);
	$replace = array(	hazspoiler_getSpoilerWrap(hazspoiler_getSpoilerHeader("$1"), 		hazspoiler_getSpoilerBody("$2")),
						hazspoiler_getSpoilerWrap(hazspoiler_getSpoilerHeader("Hide/Show"), 	hazspoiler_getSpoilerBody("$1")));
	// Do
	while(preg_match($pattern[0], $message) or preg_match($pattern[1], $message)) {
		$message = preg_replace($pattern, $replace, $message);
	$find = array(
		"#<div class=\"spoiler_body\">(\r\n?|\n?)#",
	$replace = array(
		"<div class=\"spoiler_body\">",
	$message = preg_replace($find, $replace, $message);
	return $message;
// Functions
function hazspoiler_getSpoilerButton($title) {
	$script = "$(this).parent().parent('.spoiler_wrap').children('.spoiler_body').toggle(100);";
	return "<a href=\"javascript:void(0);\" onClick=\"".$script."\">".$title."</a>";
function hazspoiler_getSpoilerBody($content) {
	return "<div class=\"spoiler_body\" style=\"display: none; border-radius:8px;border: 2px #c57d35 solid; padding:5px; width:99%;\">".$content."</div>";
function hazspoiler_getSpoilerHeader($title) {
	return "<div class=\"spoiler_header\">".hazspoiler_getSpoilerButton($title)."</div>";
function hazspoiler_getSpoilerWrap($head, $body) {
	return "<div class=\"spoiler_wrap\">".$head.$body."</div>";