MyBB Community Forums

Full Version: Syntaxhighlighter implementation to MyBB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Replacing MyBB's [php ] with syntaxhighlighter

first you need to download the syntaxhighlighter

http://alexgorbatchev.com/SyntaxHighligh...sh_current

Then open it up and upload
shCore.js
shBrushPhp.js
shCoreDefault.css
to mybb root/sh/

You probably don't have the folder sh so make it.

Now for the replacing codes part.

1) Go to your admin CP
Templates & Style -> Templates -> Choose the template you use -> Show Thread Templates -> showthread

add
<script type="text/javascript" src="./sh/shCore.js"></script>
<script type="text/javascript" src="./sh/shBrushPhp.js"></script>
<link type="text/css" rel="stylesheet" href="./sh/shCoreDefault.css" />
<script type="text/javascript">SyntaxHighlighter.all();</script>
under {$headerinclude}

Then now go to your mybb/inc and look for class_parser.php

find
function mycode_parse_php

add /* before
if($text_only == true)

add */ after
return "<div class=\"codeblock phpcodeblock\"><div class=\"title\">$lang->php_code\n</div><div class=\"body\">".$code."</div></div>\n";

after the */ make a new line by pressing return and add
return "<pre class=\"brush: php;title:PHP\">$str</pre>";

Now open up functions_post.php in the same folder
find
$post['message'] = $parser->parse_message($post['message'], $parser_options);

then add new line and add
$post['message'] = str_replace("<br />", "", $post['message']);

You probably want to edit the .css file so it matches your theme.
I'm not sure why you'd go through all that trouble when PHP has inbuilt functions to change the highlight colors.

http://community.mybb.com/thread-120200.html

Easily done with no extra javascript, no core edits, no unnecessary resources.
(2012-06-19, 09:51 PM)Nathan Malcolm Wrote: [ -> ]I'm not sure why you'd go through all that trouble when PHP has inbuilt functions to change the highlight colors.

http://community.mybb.com/thread-120200.html

Easily done with no extra javascript, no core edits, no unnecessary resources.

I find it ugly to look at. and I'm too lazy to look up the colors and change the colors, when I can just copy and paste all the codes easily.
(2012-06-19, 09:52 PM)jung3o Wrote: [ -> ]I find it ugly to look at. and I'm too lazy to look up the colors and change the colors, when I can just copy and paste all the codes easily.
This is IMHO more lazy and nasty process then the one which Nathan linked above which is just a 4 line code edit or use his plugin (runs no queries!).
See my thread, http://community.mybb.com/thread-120047.html

One from the SQA team have already made a plugin for this. Simple. Wink

Edit, oh, it was Nathan Malcolm who uploaded it.