[2.0.6] PHP Syntax Highlighter BBCode

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

Rating:

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

no_memes
Registered User
Posts: 11
Joined: Fri Oct 01, 2004 11:16 pm
Location: NYC

Post by no_memes »

ok very cool.

That fix works like a charm, can find a working example on my mod test forum. Thanks a bunch ET.

I'm not a programmer by nature, more on the design end, but I can fumble through the code enough to see things that need to be changed, although changing them correctly is a whole other issue.

I'll post a live link to my standards based forum soon, once I get it modified. I'm working on a xhtml 1.0 template for phpBB. It's been a slow process but it's finally coming along.

The CSS had to be totally changed when converting tables to divs. I'm trying to keep tables to their proper use of forum data output putting the bulk of the layout on CSS, but we will see if I can pull that off or not. So far the overall_header.tpl and overall_footer.tpl are both 100% <div>. The index_body.tpl has been reduced to a few tables for the forum category output and one stubborn table that I'm working on a <div> solution for.

Once I get the bulk of the .tpls finished, then I will stream line the CSS for a core standards based template. (There is a lot of redundant CSS right now)

EDITED: Here is my standards forum with 3 mods - the visual validation mod, the code color mod, and the php syntax mod. I doubt I'll put anymore mods on, only update the existing mods and forum software itself. But this standards compliant template will be the next hurdle. Special Notice: The template will be quirky until its completely renovated.
User avatar
-=ET=-
Registered User
Posts: 825
Joined: Sun May 25, 2003 5:32 pm

Post by -=ET=- »

It's done!
Multiple BBCode 1.4.0c is available :wink:
http://www.phpbb.com/phpBB/viewtopic.php?t=145513
Eternal newbie
the_bunny
Registered User
Posts: 194
Joined: Wed Oct 29, 2003 9:44 am
Location: Germany
Contact:

Post by the_bunny »

hi,

Code: Select all

# 
#-----[ FIND ]---------------------------------
#
$EMBB_keys = array(''
$EMBB_widths = array(''
$EMBB_values = array(''
can't be found in posting.php! i installed multi bbcode 1.4.0c, but even the multi-bbc-1-4-0.txt doesn't have these lines, so HOW should i find the lines?

any hint will be greatly appreciated! :roll:
User avatar
-=ET=-
Registered User
Posts: 825
Joined: Sun May 25, 2003 5:32 pm

Post by -=ET=- »

You don't install the right MODs.
PHP Syntax Highlighter 3.0.5 is Multiple BBCode 1.4.0c compliant.
PHP Syntax Highlighter 3.0.3 & 3.0.4 are both Multiple BBCode 1.2.1 & 1.3.0a compliant.
Eternal newbie
Thoku
Registered User
Posts: 1
Joined: Fri Dec 03, 2004 6:38 pm

Post by Thoku »

I've recently tried to use this MOD to update my forum, but there is a fault...

In posting.php the lines:

$EMBB_keys = array(''

Do not exisit so how can I add the things after it?

Please help!

I've removed it from my site but I would really like to add this Mod.


Thanks all :D
A man on a mission...
StalkR
Registered User
Posts: 17
Joined: Tue Jan 08, 2002 9:58 pm
Location: France
Contact:

Post by StalkR »

Thoku I was encountering the same problem...
I installed, in this order : Multi BBcode 1.40c, then BBCode Buttons Organizer 1.4.0, then PHP Syntax Highlighter BBCode 3.0.3.
And as you said, the line :

Code: Select all

$EMBB_keys = array('' 
can't be find.

And if you have a look at the PHP code, this is perfectly normal, because in the Multi BBcode 1.40c, thoses lines have been replaced by the function:

Code: Select all

Multi_BBCode();
So I put my hands in the PHP code, and now it works :)
I didn't changed Multi BBcode 1.40c
I only changed BBCode Buttons Organizer 1.4.0 and PHP Syntax Highlighter BBCode 3.0.3.

I can give you my version of the MOD install instructions if you want... just ask !

Note: is the author aware of this issue? I solved it, I can send you my files :) And your mods are very good !
User avatar
-=ET=-
Registered User
Posts: 825
Joined: Sun May 25, 2003 5:32 pm

Post by -=ET=- »

StalkR wrote: I installed, in this order : Multi BBcode 1.40c, then BBCode Buttons Organizer 1.4.0, then PHP Syntax Highlighter BBCode 3.0.3.

Only 2 posts before... :roll:
-=ET=- wrote: You don't install the right MODs.
PHP Syntax Highlighter 3.0.5 is Multiple BBCode 1.4.0c compliant.
PHP Syntax Highlighter 3.0.3 & 3.0.4 are both Multiple BBCode 1.2.1 & 1.3.0a compliant.

http://www.phpbb.com/phpBB/viewtopic.ph ... 265#999265
http://www.phpbb.com/phpBB/viewtopic.ph ... 25#1283625
Eternal newbie
StalkR
Registered User
Posts: 17
Joined: Tue Jan 08, 2002 9:58 pm
Location: France
Contact:

Post by StalkR »

hum... you're brilliant dude :D sorry :) but I was thinking that the answer wasn't there because "Thoku" (the post after yours) asked for this problem... scuse me :D

However, mods team should update the mod to its last version, and pple won't be confused any longer 8)


ps: bon désolé ^^ j'avay pas vu! de toute manière jme suis démerdé moi ça marche nikel :P
KI
Registered User
Posts: 32
Joined: Sat Nov 20, 2004 11:46 pm

Post by KI »

sander marechal wrote: 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.
[...]

Your code had a lot of "unintended features" (bugs).
So I decided to write a new one.
Here it is - Have fun. :D The code is well commented.

Code: Select all

// START CPP Syntax Highlighter MOD
/** 
 * CPP MOD 
 * Original code/function by phpBB Group 
 * Modified by JW Frazier / Fubonis < [email protected] > for PHP highlighting 
 * Modified again by KI / Martin Mädler < [email protected] > for nice 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'];
	
	// build the md5-hash of an escaped backslash \\
	// we need this for string highlighting later
	$escaped_backslash_md5 = md5("\\\\\\\\");
	
	$matches = array(); 
	$match_count = preg_match_all("#\[cpp:1:$uid\](.*?)\[/cpp:1:$uid\]#si", $text, $matches); 

	// this array holds all the C++ keywords, which will be highlighted in blue 
	$cppcodearray = array 
	(
	"#define", "defined", "#else", "#elseif", "#endif", "#if", "#ifdef",
	"#ifndef", "#include", "#pragma", "#undef",

	"const_cast", "dynamic_cast", "reinterpret_cast", "static_cast", 

	"_asm", "__asm", "__attribute", "__catch", "__declspec", "__fastcall", 
	"__finally", "__forceinline", "_inline", "__inline", "__interface",
	"__int8", "__int16", "__int32", "__int64", "__property", "__published", 
	"__stdcall", "__try", 

	"asm", "bool", "break", "case", "catch", "char", "class", "const", 
	"continue", "default", "defined", "delete", "dllexport", "dllimport", 
	"do", "double", "else", "enum", "extern", "false", "float", "for", "friend",
	"if", "inline", "int", "interface", "long", "mutable", "namespace", "new", 
	"operator",	"private", "protected", "public", "register", "return", 
	"short", "signed", "static", "switch", "template", "this", "true", 
	"typedef", 	"typename", "try", "union",  "unsigned",  "using",  "void", 
	"volatile", "wchar_t", "while"
	);

for ($i = 0; $i < $match_count; $i++) 
	{ 
		$before_replace = $matches[1][$i]; 
		$after_replace = $matches[1][$i]; 
		$str_to_match = "[cpp:1:$uid]" . $before_replace . "[/cpp:1:$uid]";  
		
		// First of all we need to replace all multiline comments with its approriate md5-hash
		// This prevents highlighting keywords inside of a comment
		// Later the hashes are again replaced by its corresponing multiline comment
		$comment_multi_count = 0;
		
		do
		{
			// preg_match, with a specific multiline comment regex
			$result = preg_match("/(\/\*.*?\*\/)/s", $after_replace, $comment_multi);
			if($result == 0)
				break;// if no more comments are found, leave the loop
			
			$comment_multi_arr[$comment_multi_count] = $comment_multi[1];// this array holds the comments
			$comment_multi_md5[$comment_multi_count] = md5($comment_multi[1]);// this one holds the corresponding md5-hash
			$after_replace = substr_replace($after_replace, $comment_multi_md5[$comment_multi_count], strpos($after_replace, $comment_multi_arr[$comment_multi_count]), strlen($comment_multi_arr[$comment_multi_count]));
			$comment_multi_count += 1;
		}
		while(true);
		
		// Here we need to replace all singleline comments with its approriate md5-hash
		// by using the same method as seen before
		$comment_single_count = 0;
		
		do
		{
			// preg_match, this time with a specific singleline comment regex
			$result = preg_match("/(\/\/.*)/", $after_replace, $comment_single);
			if($result == 0)
				break;// if no more accordances are found, leave the loop
			
			$comment_single_arr[$comment_single_count] = $comment_single[0];
			$comment_single_md5[$comment_single_count] = md5($comment_single[0]);
			$after_replace = substr_replace($after_replace, $comment_single_md5[$comment_single_count], strpos($after_replace, $comment_single_arr[$comment_single_count]), strlen($comment_single_arr[$comment_single_count]));
			$comment_single_count += 1;
		}
		while(true);
		
		// In the next part we are going to find strings within the code
		// strings are characterized by one double quotes (") on each end
		
		// replace all escaped backslashes with its appropriate md5-hash
		// otherwise an escaped backslash at the end of a string would 
		// be interpreted as an escaped double quote
		// That would result in an oversized string
		// Example 1:(we want to prevent such bugs)
		// <span style='color: #00B0B0'>"We don't want this \\" here is some code"</span>beginning of a new string...
		// Example 2:(that's the way it has to be)
		// <span style='color: #00B0B0'>"We want this\\"</span><span style='color: #00B0B0'>"beginning of a new string...
		$after_replace = preg_replace("/(\\\\\\\\)/",$escaped_backslash_md5,$after_replace);
		
		// now we find all strings
		// the look behind feature (?<!\\\\)\") in our regex enables us to find strings with
		// escaped double quotes \"
		// otherwise the string would close at the second double quote from the beginning
		$string_cnt  = preg_match_all("/(\".*?(?<!\\\\)\")/s",  $after_replace, $strings,  PREG_SET_ORDER); 
		if ($string_cnt > 0)
		{ 
			foreach ($strings as $string) 
			{ 
				$after_replace = str_replace($string[0], md5($string[0]), $after_replace); 
			} 
		} 

		// lets come to the highlighting
		// this highlights everything red which is between square brackets
		$after_replace = preg_replace("/(\[)([^\]]*)(\])/", "\\1<span style='color: #FF0000'>\\2</span>\\3", $after_replace); 
		
		// merge the keyword-array to a big regex
		$keyword_regex = "/(?<![A-Za-z0-9_])(" . implode("|", $cppcodearray) . ")(?![A-Za-z0-9_])/"; 
		
		// highlight the keywords
		$after_replace = preg_replace($keyword_regex, "<span style='color: #0000FF'>\\0</span>", $after_replace); 

		// its time to replace all hashes with its corresponing character strings
		// perform multiline comment highlighting
		for($count = 0; $count < $comment_multi_count; $count++)
		{
			$after_replace = str_replace($comment_multi_md5[$count], "<span style='color: #008000'>" . $comment_multi_arr[$count] . "</span>", $after_replace); 
		} 
		
		// perform singleline comment highlighting	
		for($count = 0; $count < $comment_single_count; $count++)
		{
			$after_replace = str_replace($comment_single_md5[$count], "<span style='color: #008000'>" . $comment_single_arr[$count] . "</span>", $after_replace); 
		} 
		
		// perform string highlighting
		if ($string_cnt > 0)
		{ 
			foreach ($strings as $string)
			{ 
				$after_replace = str_replace(md5($string[0]), "<span style='color: #00B0B0'>" . $string[0] . "</span>", $after_replace); 
			} 
		}
		
		// replace all escaped backslash hashes with escaped backslashes
		$after_replace = preg_replace("/(" . $escaped_backslash_md5 . ")/","\\\\\\\\",$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); 

		// make first \r\n to vanish if it exists
		$after_replace = preg_replace("/^(\r\n)*/", "", $after_replace);
		
		// piece the post back together
		$replacement  = $code_start_html;
		$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; 
}
I think, I'm going to release a complete MOD...
sander marechal
Registered User
Posts: 66
Joined: Sun Feb 15, 2004 8:45 pm
Location: The Netherlands
Contact:

Post by sander marechal »

That looks great KI :) Well done and thanks!
DoMoKuN
Registered User
Posts: 2
Joined: Sun Apr 03, 2005 12:57 pm

Post by DoMoKuN »

OK I am lost...
I just installed the multi_bbcode-140c and i can't find anything regarding the

Code: Select all

# 
#-----[ OPEN ]------------------------------------------------
#
includes/bbcode.php

# 
#-----[ FIND ]------------------------------------------------
#
$EMBB_widths = array(''
$EMBB_values = array(''
I have downloaded multi_bbcode-140c & php_syntax_highlighter_3.0.5em as stated by ET
PHP Syntax Highlighter 3.0.5 is Multiple BBCode 1.4.0c compliant.
so does that mean i have to install Easymod aswell to be able to get the PHP BBcode working? If so i think it would be great and beter for people who just start with modding and stuff to make this process much easier and combine these projects into 1 project or 1 mod install file instead of 3 or more diffrent mod installs.

EDIT: I just installed this EM and try to install this php thingy. and it works.
Disturbed One
Registered User
Posts: 129
Joined: Sun Apr 03, 2005 12:31 am

Post by Disturbed One »

Fatal error: Call to undefined function: bbencode_second_pass_php() in /home/hantho07/public_html/forum/includes/bbcode.php on line 197

line 197 is

Code: Select all

// Start add - PHP Syntax Highlighter BBCode MOD
	// [PHP] and [/PHP] for posting PHP code in your posts.
	$text = bbencode_second_pass_php($text, $uid, $bbcode_tpl);
// End add - PHP Syntax Highlighter BBCode MOD
KI
Registered User
Posts: 32
Joined: Sat Nov 20, 2004 11:46 pm

Post by KI »

How can I prevent that smilies are shown in php tags?

8) for example gets to 8)

In code tags, for example, are no smiley pictures:

Code: Select all

 :D  :)  :(  :o  :?  8)  :lol: 
User avatar
-=ET=-
Registered User
Posts: 825
Joined: Sun May 25, 2003 5:32 pm

Post by -=ET=- »

Hum... ok I'll check this issue ASAP but unfortunatly it will not be before the end of next week :roll:
Eternal newbie
KI
Registered User
Posts: 32
Joined: Sat Nov 20, 2004 11:46 pm

Post by KI »

-=ET=- wrote: Hum... ok I'll check this issue ASAP but unfortunatly it will not be before the end of next week :roll:

Did you succeed? Did you occupy yourself with this problem?
Post Reply

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