[2.0.6] PHP Syntax Highlighter BBCode

The cleanup is complete. This forum is now read only.

Rating:

Excellent!
30
60%
Very Good
5
10%
Good
3
6%
Fair
1
2%
Poor
11
22%
 
Total votes: 50

Jordeh
Registered User
Posts: 5
Joined: Thu Apr 25, 2002 11:07 pm
Contact:

Post by Jordeh »

Is it possible to turn off smilies in the php code but not in the rest of the text just like with the code bbcode tag?

Some bits of php code are converted to smilies :(
chadreed
Registered User
Posts: 2
Joined: Sun Jan 11, 2004 2:10 am

error, plz help!

Post by chadreed »

Hi,

All works well but I got this on top of every topic page, how do I fix that????

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at ****/includes/bbcode.php:860) in ***/viewtopic.php on line 555

Warning: Cannot modify header information - headers already sent by (output started at ******/includes/bbcode.php:860) in ********/includes/page_header.php on line 474

Warning: Cannot modify header information - headers already sent by (output started at ********/includes/bbcode.php:860) in ********/includes/page_header.php on line 476

Warning: Cannot modify header information - headers already sent by (output started at ******/includes/bbcode.php:860) in *******/includes/page_header.php on line 477
Even all my Message body B i u etc.. is not clickable ?? it work very well if I typ in it by hand.

/reed
chadreed
Registered User
Posts: 2
Joined: Sun Jan 11, 2004 2:10 am

Post by chadreed »

The Message body bottons work now, and the php code is viewing nice, but I still got the error on the top of each topic, not in the index page at all.

/reed
sander marechal
Registered User
Posts: 66
Joined: Sun Feb 15, 2004 8:45 pm
Location: The Netherlands
Contact:

Post by sander marechal »

Hello,

I have installed the Multiple BBCode Mod (204) and the PHP BBCode Mod. It's all working great except one thing: When composing private messages I do not see the PHP code button. I have added the piece of code in privmsg.php but something must go wrong. If I manually add the BBCode tags, the PHP code boxes do appear, it's just the buttons that don't seem to appear (they do appear in the regular cmposing screens).

If anyone can help me, it's greatly appreciated.

For the rest, excellent mod. I have adepted it to do C/C++ highlighting as well. Piece of cake!
_spin_
Registered User
Posts: 1
Joined: Sun Feb 22, 2004 12:47 am

Post by _spin_ »

sander marechal,
do you mind describing how you managed to convert the mod for C/C++?

I'm afraid I don't have access to php.ini and I am not sure how (and where) to use ini_set.

I need to have syntax highlighting for a rare scpriting language and I can't find where the keywords are defined.

And one last thing: Is it possible to make some keywords look bold?

Thanks in advance.
sander marechal
Registered User
Posts: 66
Joined: Sun Feb 15, 2004 8:45 pm
Location: The Netherlands
Contact:

Post by sander marechal »

_spin_ wrote: sander marechal,
do you mind describing how you managed to convert the mod for C/C++?

I'm afraid I don't have access to php.ini and I am not sure how (and where) to use ini_set.

It's a little more difficult than that. PHP has a built-in function that takes a piece of PHP code and outputs the same code with highlighting. (this is why you need the php.ini file). The core of this PHP mod is just one line. The rest is to tell phpBB about the new tags and add buttons for them. There isn't a standard function like that for C++ code or other languages. You will need to make that for yourself. On the plus side, you don't need the php.ini file at all.

Here's the core of my highlighter. It's a little long but that is because of the long list of keywords that C++ uses.

Code: Select all

/**
 * CPP MOD
 * Original code/function by phpBB Group
 * Modified by JW Frazier / Fubonis < php_fubonis@yahoo.com > for PHP highlighting
 * Modified again by Sander Maréchal < s.marechal@jejik.com > for C/C++ highlighting
 */
function bbencode_second_pass_cpp($text, $uid, $bbcode_tpl)
{
  //split the post up and grab the code blocks
	$code_start_html = $bbcode_tpl['cpp_open'];
	$code_end_html =  $bbcode_tpl['cpp_close'];
	$matches = array();
	$match_count = preg_match_all("#\[cpp:1:$uid\](.*?)\[/cpp:1:$uid\]#si", $text, $matches);

	//this array holds all the C++ keywords. They will be highlighted in blue
  $cppcodearray = array ("__abstract", "__alignof", "__asm", "__assume", 
               "__based", "__box", "__cdecl", "__declspec",
               "__delegate", "__event", "__except", "__fastcall",
               "__finally", "__forceinline", "__gc", "__hook",
               "__identifier", "__if_exists", "__if_not_exists", "__inline",
               "__int8", "__int16", "__int32", "__int64",
               "__interface", "__leave", "__m64", "__m128",
               "__m128d", "__m128i", "__multiple_inheritance", "__nogc",
               "__noop", "__pin", "__property", "__raise",
               "__sealed", "__single_inheritance", "__stdcall", "__super",
               "__try_cast", "__try/__except", "__try/__finally", "__unhook", "__uuid_of",
               "__value", "__virtual_inheritance", "__w64", "asm", "bool",
               "break", "case", "catch", "char",
               "class", "const", "const_cast", "continue",
               "default", "delete", "deprecated", "dllexport",
               "dllimport", "do", "double", "dynamic_cast",
               "else", "enum", "explicit", "extern",
               "false", "float", "for", "friend",
               "goto", "if", "inline", "int",
               "long", "mutable", "naked", "namespace",
               "new", "noinline", "noreturn", "nothrow",
               "novtable", "operator", "private", "property",
               "protected", "public", "register", "reinterpret_cast",
               "return", "selectany", "short", "signed",
               "sizeof", "static", "static_cast", "struct",
               "switch", "template", "this", "thread",
               "throw", "true", "try", "typedef",
               "typeid", "typename", "union", "unsigned",
               "using", "uuid", "virtual", "void",
               "volatile", "__wchar_t", "while",
               "#define", "#error", "#import", "#undef",
               "#elif", "#if", "#include", "#using",
               "#else", "#ifdef", "#line", "#endif",
               "#ifndef", "#pragma");
	
	for ($i = 0; $i < $match_count; $i++)
	{
		$before_replace = $matches[1][$i];
		$after_replace = trim($matches[1][$i]);
		$str_to_match = "[cpp:1:$uid]" . $before_replace . "[/cpp:1:$uid]";
		$replacement = $code_start_html;
		
		//replace the anti-HTML code with the real symbols
		$after_replace = str_replace('<', '<', $after_replace);
		$after_replace = str_replace('>', '>', $after_replace);
		$after_replace = str_replace('&', '&', $after_replace);
		
		//loop though all the keywords in the array and see if it is in the code text. If so,
		//add <span style='color: #0000FF;'></span> to it. This function will match about
		//99.9% of the keywords.
  	foreach ($cppcodearray as $cppcodetag)
  	{
  	  $after_replace = ereg_replace("([^a-zA-Z0-9<>])(".$cppcodetag.")([^a-zA-Z0-9<>])", "\\1<span style='color: #0000FF;'>\\2</span>\\3", $after_replace);
  	}
		
		//start of a block of cpp comments (comment will becode green)
  	$after_replace = ereg_replace("/\\*", "<span style='color: #007700;'>\\0", $after_replace);
  	
		//end of a comment block
		$after_replace = ereg_replace("\\*/", "\\0</span>", $after_replace);
  	
		//a single line comment (green)
		$after_replace = ereg_replace("(//[^\\\n]*)(\\\n)", "<span style='color: #007700;'>\\1</span>\\2", $after_replace);
  	
		//anything between square brackets (for arrays) will be red
		$after_replace = ereg_replace("(\\[)([^]]*)(\\])", "\\1<span style='color: #770000;'>\\2</span>\\3", $after_replace);
		
		//highlights text-strings
		$after_replace = ereg_replace("\"[^\"]*\"", "<span style='color: #007777'>\\0</span>", $after_replace);
		
		// Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines.
		$after_replace = str_replace("  ", "&nbsp; ", $after_replace);
		// now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
		$after_replace = str_replace("  ", " &nbsp;", $after_replace);

		// Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
		$after_replace = str_replace("\t", "&nbsp; &nbsp;", $after_replace);

		// now Replace space occurring at the beginning of a line
		$after_replace = preg_replace("/^ {1}/m", '&nbsp;', $after_replace);

		//piece the post back together
		$replacement .= $after_replace;
		$replacement .= $code_end_html;

		$text = str_replace($str_to_match, $replacement, $text);
	}

	$text = str_replace("[cpp:$uid]", $code_start_html, $text);
	$text = str_replace("[/cpp:$uid]", $code_end_html, $text);

	return $text;
}

Just replace the C++ keyword list with your own list and you have got the basics running. Then add a few more regular expressions to furter beautify the code output. A working implementation of this can be found at my forum at www.jejik.com (follow the forum links from the menu).

EDIT: Updated the source. I forgot code indenting.
User avatar
-=ET=-
Registered User
Posts: 799
Joined: Sun May 25, 2003 5:32 pm

Post by -=ET=- »

Hi, :)

I've build a new 3.0.4 release of this nice MOD to include all the fix and enhancement asked here, plus some more.

So this release...
  • add some code lines to modify the colors used to highlight the syntax, following Fubonis's tip...
    http://www.phpbb.com/phpBB/viewtopic.ph ... 608#705608
  • add a French translation for language entries
  • fix the PHP button not displayed for PM
    In fact, I released a new 1.3.0 version of the Multiple BBCode MOD which now support new BBCodes for PM...
    http://www.phpbb.com/phpBB/viewtopic.ph ... 255#999255
    ...and adapt the PHP Syntax Highlighter MOD to be compliant with it.
  • fix the '<?php' & '?>' not removed if it was not in the php code (as asked by CyanBlue).
  • fix the php code displayed smaller than some code using the 'code' BBCode (by using putaso's fix).
  • remove '<?php' & '?>' from the language entry. This is to improve EM/EMC rules compatibility as ?> was disrupting language entry add with EM. ?> is used for the FIND...
    http://area51.phpbb.com/phpBB22/viewtop ... 25&t=12556
:arrow: You can download the new release here

I have not added any credit for me in the MOD, and add an upgrade MOD from the 3.0.3 version to the 3.0.4 one.
Please note that you NEED to install/upgrade to the 1.3.0 Multiple BBCode MOD BEFORE updating/installing this release!

Moreover, I advise you to install the 1.1.0 release of the BBCodes & smilies enhancement MOD to fix an issue which affect the PHP BBCode when you use it in signature and modify your signature in the ACP > User Admin > Management.
http://www.phpbb.com/phpBB/viewtopic.php?t=175056

Enjoy! :wink:

P.S.: I've PM Fubonis about this release. He'll do what he want with it.
Last edited by -=ET=- on Sun Oct 17, 2004 11:17 pm, edited 2 times in total.
Eternal newbie
AznBoyye
Registered User
Posts: 133
Joined: Fri Aug 09, 2002 1:48 am

Post by AznBoyye »

Code: Select all

Parse error: parse error in /home3/corrupte/public_html/forum/includes/bbcode.php on line 203

Warning: Cannot modify header information - headers already sent by (output started at /home3/corrupte/public_html/forum/includes/bbcode.php:203) in /home3/corrupte/public_html/forum/includes/sessions.php on line 293

Warning: Cannot modify header information - headers already sent by (output started at /home3/corrupte/public_html/forum/includes/bbcode.php:203) in /home3/corrupte/public_html/forum/includes/sessions.php on line 294

Warning: Cannot modify header information - headers already sent by (output started at /home3/corrupte/public_html/forum/includes/bbcode.php:203) in /home3/corrupte/public_html/forum/viewtopic.php on line 563

Warning: Cannot modify header information - headers already sent by (output started at /home3/corrupte/public_html/forum/includes/bbcode.php:203) in /home3/corrupte/public_html/forum/includes/page_header.php on line 474

Warning: Cannot modify header information - headers already sent by (output started at /home3/corrupte/public_html/forum/includes/bbcode.php:203) in /home3/corrupte/public_html/forum/includes/page_header.php on line 476

Warning: Cannot modify header information - headers already sent by (output started at /home3/corrupte/public_html/forum/includes/bbcode.php:203) in /home3/corrupte/public_html/forum/includes/page_header.php on line 477

Code: Select all

Fatal error: Call to undefined function: bbencode_second_pass() in /home3/corrupte/public_html/forum/viewtopic.php on line 1119
ne help will greatly be apreciated...
AznBoyye
Registered User
Posts: 133
Joined: Fri Aug 09, 2002 1:48 am

Post by AznBoyye »

nvm ill download the new version and i will see what i get.. btw will this work with 208?
AznBoyye
Registered User
Posts: 133
Joined: Fri Aug 09, 2002 1:48 am

Post by AznBoyye »

works fine

ok after i upgraded it works perfectly fine on 2.0.8 all hail everyone who worked on this mod!
User avatar
-=ET=-
Registered User
Posts: 799
Joined: Sun May 25, 2003 5:32 pm

Post by -=ET=- »

The last release of this MOD (3.0.4) is phpBB 2.0.10 compliant! :D
Eternal newbie
User avatar
-=ET=-
Registered User
Posts: 799
Joined: Sun May 25, 2003 5:32 pm

Post by -=ET=- »

Hi, :)

Still waiting Fubonis, I've upgraded this BBCode in a release 3.0.5 to be Multiple BBCode 1.4.0c compliant.
:arrow: This last version is available here

Enjoy! :D
Last edited by -=ET=- on Sat Oct 30, 2004 7:38 pm, edited 1 time in total.
Eternal newbie
no_memes
Registered User
Posts: 11
Joined: Fri Oct 01, 2004 11:16 pm
Location: NYC

Post by no_memes »

ET:

Your version works groovy but the help mouse over $lang isn't working. Other than that, works great.

http://thexvector.com/modtestforum/ You can see how the $lang help doesn't work here. However, I am using the

Code: Select all

 syntax color mod, would this make a difference? I don't see how this would affect this version of this mod.

However, would using the same string value of [0] for both the [code] and [php] buttons affect how the $lang would be affected?

[color=red]EDITED[/color]: I made some changes that work for this mod. Although they work, they are a temp fix for the underlying coding fix that might need to be made to EM Mod.
Last edited by no_memes on Fri Oct 22, 2004 2:53 pm, edited 1 time in total.
no_memes
Registered User
Posts: 11
Joined: Fri Oct 01, 2004 11:16 pm
Location: NYC

Post by no_memes »

To ALL:

I made some minor changes until the multi-bbc-1.4.0 MOD can be improved to the onmouseover event for the help and the alt+ hotkey can be fixed.

EDITED: Link is down in favor of the below fix to the multi-bbc mod.
Last edited by no_memes on Sat Oct 23, 2004 8:40 am, edited 1 time in total.
User avatar
-=ET=-
Registered User
Posts: 799
Joined: Sun May 25, 2003 5:32 pm

Post by -=ET=- »

Hi :)

You've pointed out a minor issue of the Multiple BBCode 1.4.0b release.
wGEric is informed of this issue and he will correct it as soon as he can find 5mn to do it.

But your approach to solve the pb temporarily is not the good one.
The PHP Syntax Highlighter 3.0.5 release is correct so there is no need to modify anything in it.

The fix is to apply on the Multiple BBCode 1.4.0b MOD as it affect all new BBCode "Multiple BBCode 1.4.0" compliant (as Hide 1.2.4 for example)...

Code: Select all

# 
#-----[ FIND ]------------------------------------------------ 
#
'HELP' => sprintf($lang['bbcode_help'][(strtolower($EMBB_values[$i]))], $hotkeys[$i]),

# 
#-----[ REPLACE WITH ]---------------------------------------- 
#
'HELP' => sprintf($lang['bbcode_help'][$EMBB_values[$i]], $hotkeys[$i]),
No doubt that an official 1.4.0c will come out soon :wink:
Eternal newbie
Post Reply

Return to “[2.0.x] MOD Database Cleanup”