MyBB Community Forums

Full Version: use code tag for generating new MYCODE
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello;

I want to generate new MYCODE that when user use it, first a specified picture show and then expression between MYCODE tag put in code tag, please see example:

Regular Expression
\[test\](.*?)\[/test\]

Replacement
<img src="http://test.com/test.png"/>
<br>
$1

Result:
I want to put $1 between [ code] [ /code],

what can I do for doing this?Huh
For replacement, use...

<img src="http://test.com/test.png"/>
<br />
<div class="codeblock">
<div class="title">Code:</div>
<div dir="ltr" class="body"><code>$1</code></div></div>
(2012-02-24, 07:53 AM)kavin Wrote: [ -> ]For replacement, use...

<img src="http://test.com/test.png"/>
<br />
<div class="codeblock">
<div class="title">Code:</div>
<div dir="ltr" class="body"><code>$1</code></div></div>

thank you,
there is a problem with this code, when I user [test]http://test.com[/test] it works fine but when use multiple row between tag like this:
[test]http://test.com
http://test2.com
http://test3.com
[/test]

do not works fine with code tag, as you know all links in code tags are not click-able, when I put multiple row between new mycode tag, only first row is not click-able and other are click-able.
Huh
(2012-02-27, 11:16 AM)CivilEA Wrote: [ -> ]thank you,
there is a problem with this code, when I user [test]http://test.com[/test] it works fine but when use multiple row between tag like this:
[test]http://test.com
http://test2.com
http://test3.com
[/test]

do not works fine with code tag, as you know all links in code tags are not click-able, when I put multiple row between new mycode tag, only first row is not click-able and other are click-able.
Huh

The problem is, inorder to actually make the "code" function to work, we must pass it to mycode_parse_code function in inc/class_parser. But custom MyCode replacement allows only allow HTML.

We can achieve what you asked by editing inc/class_parser.php

Find:
preg_match_all("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER);

Replace with:
preg_match_all("#\[(code|php|test)\](.*?)\[/\\1\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER);

Find:
$message = preg_replace("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", "<mybb-code>\n", $message);

Replace with:
$message = preg_replace("#\[(code|php|test)\](.*?)\[/\\1\](\r\n?|\n?)#si", "<mybb-code>\n", $message);

Find:
if(my_strtolower($text[1]) == "code")
					{
						$code = $this->mycode_parse_code($text[2]);
					}

After that add:
elseif(my_strtolower($text[1]) == "test")
					{
						$code = $this->mycode_parse_test($text[2]);
					}

Find:
return "<div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><code>".$code."</code></div></div>\n";
	}

After that add:
function mycode_parse_test($code, $text_only=false)
	{
		global $lang;

		if($text_only == true)
		{
			return "\n{$lang->code}\n--\n{$code}\n--\n";
		}

		// Clean the string before parsing.
		$code = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $code);
		$code = rtrim($code);
		$original = preg_replace('#^\t*#', '', $code);

		if(empty($original))
		{
			return;
		}

		$code = str_replace('$', '$', $code);
		$code = preg_replace('#\$([0-9])#', '\\\$\\1', $code);
		$code = str_replace('\\', '\', $code);
		$code = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $code);
		$code = str_replace("  ", '&nbsp;&nbsp;', $code);

		return "<img src=\"http://test.com/test.png\"/>
<br /><div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><code>".$code."</code></div></div>\n";
	}
code you please update mentioned codes for MYBB 1.8.?
Please update this modification for Version 1.8
any help?
could you please guide me?
Any Help?