MyBB MYCode - Integrate into a PHP file

Discussion in 'PHP' started by blueparukia, Aug 2, 2007.

  1. #1
    I don't know PHP, and I am starting up a MYBB forum, and have made a spoiler BBCode. While this works, it is a little troublesome for someone to put in if they have no coding knowledge. So i want it in a PHP file.

    Here is a PHP code someone used for a very similar (but uglier) spoiler tag:

    function spoiler_activate()
    {
    }
    function spoiler_deactivate()
    {
    }
    function spoiler_run($message)
    {
    	// Assign pattern and replace values.
    	$pattern = array("#\[spoiler=(?:"|\"|')?(.*?)[\"']?(?:"|\"|')?\](.*?)\[\/spoiler\](\r\n?|\n?)#si", "#\[spoiler\](.*?)\[\/spoiler\](\r\n?|\n?)#si");
    
    	$replace = array("<div><div class=\"quote_header\">$1 <a href=\"javascript:void(0);\" onclick=\"javascript:if(parentNode.parentNode.getElementsByTagName('div')[1].style.display=='block'){parentNode.parentNode.getElementsByTagName('div')[1].style.display='none';this.innerHTML='(Click to View)';}else {parentNode.parentNode.getElementsByTagName('div')[1].style.display='block';this.innerHTML='(Click to Hide)';}\">(Click to View)</a></div><div class=\"quote_body\" style=\"display: none;\">$2</div></div>", "<div><div class=\"quote_header\">Spoiler <a href=\"javascript:void(0);\" onclick=\"javascript:if(parentNode.parentNode.getElementsByTagName('div')[1].style.display=='block'){parentNode.parentNode.getElementsByTagName('div')[1].style.display='none';this.innerHTML='(Click to View)';}else {parentNode.parentNode.getElementsByTagName('div')[1].style.display='block';this.innerHTML='(Click to Hide)';}\">(Click to View)</a></div><div class=\"quote_body\" style=\"display: none;\">$1</div></div>");
    
    	while(preg_match($pattern[0], $message) or preg_match($pattern[1], $message))
    	{
    		$message = preg_replace($pattern, $replace, $message);
    	}
    	$find = array(
    		"#<div class=\"quote_body\">(\r\n?|\n?)#",
    		"#(\r\n?|\n?)</div>#"
    	);
    
    	$replace = array(
    		"<div class=\"quote_body\">",
    		"</div>"
    	);
    	$message = preg_replace($find, $replace, $message);
    	return $message;
    }
    ?>
    Code (markup):

    And here is my spoiler code:
    <small>    <b>Spoiler:</b></small><br /> <div style="border: inset 1px gray; padding: 1px;"><div><button type="button" class="button" onclick="if (this.innerHTML == 'Hide Spoiler'){this.parentNode.parentNode.childNodes[1].style.display = 'none'; this.innerHTML = 'Show Spoiler';}else{this.parentNode.parentNode.childNodes[1].style.display = 'inline'; this.innerHTML = 'Hide Spoiler';}; ""><font color="#000000" size="1"><b>Show Spoiler</b></font></button></div><div id="spoiler" style="display: none;"> $1 </div>
    Code (markup):
    $1 is the post variable.


    Can anyone help me with this?

    Thanks,

    BP
     
    blueparukia, Aug 2, 2007 IP