Seite 1 von 1

PHP Syntax Highlighter BBCode

Verfasst: 04.05.2003 23:45
von Kopnic
Hi, ich hab da kürzlich einen Mod gefunden. Jetzt möcht ich die alte "Code"-Funktion mit dieser hier ersetzten. Leider bin ich kein PHP-Ass und weiß demzufolge nicht, was ich entsprechend abändern muss. Es dürften aber nur Kleinigkeiten sein. Zur Info, ich hab momentan das PHPBB 2.0.4

Code: Alles auswählen

########################################################
## Mod Title:	PHP Syntax Highlighter BBCode
## Mod Version:	Beta 2.0.0
## Author:	JW Frazier / Fubonis < php@fubonis.com >
##
## This mod is only for phpBB2
## Tested on RC-3
## ONLY for PHP4+
##
## Description:  This mod creates a new BBCode, "[php]your_code[/php]"
## It simply takes the code and uses the syntax highlighting of PHP
## and makes a pretty presentation of your code!
## To use this, your code MUST have at least the opening PHP tag
## Example: [php]<?php phpinfo(); ?>[/php] is valid
## [php]phpinfo();[/php] is not.
##
##
## Installation Level:	Easy 
## Installation Time:	10 Minutes 
## Files To Edit:	5
## /includes/bbcode.php
## /templates/YOUR_TEMPLATE_NAME/bbcode.tpl
## /templates/YOUR_TEMPLATE_NAME/posting_body.tpl
## /language/lang_YOUR_LANGUAGE/lang_main.php
## /posting.php

########################################################
##
## Installation Notes: 
##
## ALWAYS back up your files.
## Rock the open-source movement!
########################################################
# 
#-----[ ACTION: OPEN /includes/bbcode.php]------------------------------------------
# 
#
#-----[ ACTION: FIND]------------------------------------------
	$bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']);

#
#-----[ ACTION: ADD BELOW]------------------------------------------
	$bbcode_tpl['php_open'] = str_replace('{L_PHP}', $lang['PHPCode'], $bbcode_tpl['php_open']); // PHP MOD
#
#-----[ ACTION: FIND]------------------------------------------
#
	// [code] and 
for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);
#
#-----[ ACTION: ADD BELOW]------------------------------------------
#
// PHP MOD
// [PHP] and [/PHP] for posting PHP code in your posts.
$text = bbencode_second_pass_php($text, $uid, $bbcode_tpl);
#
#-----[ ACTION: FIND]------------------------------------------
#
//

Code: Alles auswählen

 and 
for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_first_pass_pda($text, $uid, '', '', true, '');
#
#-----[ ACTION: ADD BELOW]------------------------------------------
#
// PHP MOD
// [PHP] and [/PHP] for posting PHP code in your posts.
$text = bbencode_first_pass_pda($text, $uid, '[php]', '[/php]', '', true, '');
#
#-----[ ACTION: FIND]------------------------------------------
#
} // bbencode_second_pass_code()
#
#-----[ ACTION: ADD BELOW]------------------------------------------
#
/**
* PHP MOD
* Does second-pass bbencoding of the [php] tags. This includes
* running htmlspecialchars() over the text contained between
* any pair of [php] tags that are at the first level of
* nesting. Tags at the first level of nesting are indicated
* by this format: [php:1:$uid] ... [/php:1:$uid]
* Other tags are in this format: [php:$uid] ... [/php:$uid]
*
* Original code/function by phpBB Group
* Modified by JW Frazier / Fubonis < php@fubonis.com >
*/
function bbencode_second_pass_php($text, $uid, $bbcode_tpl)
{
global $lang;

$html_entities_match = array("#<#", "#>#");
$html_entities_replace = array("<", ">");

$code_start_html = $bbcode_tpl['php_open'];
$code_end_html = $bbcode_tpl['php_close'];

// First, do all the 1st-level matches. These need an htmlspecialchars() run,
// so they have to be handled differently.
$match_count = preg_match_all("#\[php:1:$uid\](.*?)\[/php:1:$uid\]#si", $text, $matches);

for ($i = 0; $i < $match_count; $i++)
{
$before_replace = $matches[1][$i];
$after_replace = $matches[1][$i];

$after_replace = preg_replace($html_entities_match, $html_entities_replace, $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);

$str_to_match = "[php:1:$uid]" . $before_replace . "[/php:1:$uid]";

$replacement = $code_start_html;
$after_replace = str_replace('<', '<', $after_replace);
$after_replace = str_replace('>', '>', $after_replace);
ob_start();
highlight_string($after_replace);
$after_replace = ob_get_contents();
ob_end_clean();
$replacement .= $after_replace;
$replacement .= $code_end_html;

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

// Now, do all the non-first-level matches. These are simple.
$text = str_replace("[php:$uid]", $code_start_html, $text);
$text = str_replace("[/php:$uid]", $code_end_html, $text);
$text = str_replace('&nbsp;', '&nbsp;', $text);
$text = str_replace('&</font><font color="#0000CC">nbsp</font><font color="#006600">;', '&nbsp;', $text);
$text = str_replace('&</font><font color="#0000BB">nbsp</font><font color="#007700">;', '&nbsp;', $text);

return $text;

} // bbencode_second_pass_php()
#
#-----[ ACTION: CLOSE /includes/bbcode.php]------------------------------------------
#
#
#-----[ ACTION: OPEN /templates/YOUR_TEMPLATE_NAME/bbcode.tpl]------------------------------------------
#
#
#-----[ ACTION: FIND]------------------------------------------
#
<!-- END email -->
#
#-----[ ACTION: ADD BELOW]------------------------------------------
#
<!-- BEGIN php_open -->
</span>
<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1">
<tr>
<td><span class="genmed"><b>{L_PHP}:</b></span></td>
</tr>
<tr>
<td class="code">
<!-- END php_open -->
<!-- BEGIN php_close -->
</td>
</tr>
</table>
<span class="postbody">
<!-- END php_close -->
#
#-----[ ACTION: CLOSE /templates/YOUR_TEMPLATE_NAME/bbcode.tpl]------------------------------------------
#
#
#-----[ ACTION: OPEN /templates/YOUR_TEMPLATE_NAME/posting_body.tpl]------------------------------------------
#
#
#-----[ ACTION: FIND]------------------------------------------
#
f_help = "{L_BBCODE_F_HELP}";
#
#-----[ ACTION: ADD BELOW]------------------------------------------
#
h_help = "{L_BBCODE_H_HELP}"; <!-- PHP MOD //-->
#
#-----[ ACTION: FIND]------------------------------------------
#
bbtags = new Array('','','','','','','[quote]','[/quote]','','
  • ','
','
  • ','
','[img]','[/img]','','');
#
#-----[ ACTION: REPLACE WITH]------------------------------------------
#
bbtags = new Array('','','','','','','[quote]','[/quote]','','
  • ','
','
  • ','
','[img]','[/img]','','','[php]<?php\n','\n?>[/php]'); <!-- PHP MOD //-->
#
#-----[ ACTION: FIND]------------------------------------------
#
<td><span class="genmed">
<input type="button" class="button" accesskey="w" name="addbbcode16" value="URL" style="text-decoration: underline; width: 40px" onClick="bbstyle(16)" onMouseOver="helpline('w')" />
</span></td>
#
#-----[ ACTION: ADD BELOW]------------------------------------------
#
<td><span class="genmed">
<input type="button" class="button" accesskey="h" name="addbbcode18" value="PHP" style="width: 40px" onClick="bbstyle(18)" onMouseOver="helpline('h')" />
</span></td> <!-- PHP MOD //-->
#
#-----[ ACTION: FIND]------------------------------------------
#
<select name="addbbcode18" onChange="bbfontstyle('[color=' + this.form.addbbcode18.options[this.form.addbbcode18.selectedIndex].value + ']', '[/color]')" onMouseOver="helpline('s')">
#
#-----[ ACTION: REPLACE WITH]------------------------------------------
#
<select name="addbbcode20" onChange="bbfontstyle('[color=' + this.form.addbbcode20.options[this.form.addbbcode20.selectedIndex].value + ']', '[/color]')" onMouseOver="helpline('s')">
#
#-----[ ACTION: FIND]------------------------------------------
#
<select name="addbbcode20" onChange="bbfontstyle('[size=' + this.form.addbbcode20.options[this.form.addbbcode20.selectedIndex].value + ']', '[/size]')" onMouseOver="helpline('f')">
#
#-----[ ACTION: REPLACE WITH]------------------------------------------
#
<select name="addbbcode22" onChange="bbfontstyle('[size=' + this.form.addbbcode22.options[this.form.addbbcode22.selectedIndex].value + ']', '[/size]')" onMouseOver="helpline('f')">
#
#-----[ ACTION: CLOSE /templates/YOUR_TEMPLATE/posting_body.tpl]------------------------------------------
#
#
#-----[ ACTION: OPEN /language/lang_YOUR_LANGUAGE/lang_main.php]------------------------------------------
#
#
#-----[ ACTION: FIND]------------------------------------------
#
$lang['Code'] = "Code"; // comes before bbcode code output.
#
#-----[ ACTION: ADD BELOW]------------------------------------------
#
$lang['PHPCode'] = "PHP"; // PHP MOD
#
#-----[ ACTION: FIND]------------------------------------------
#
$lang['bbcode_f_help'] = "Font size: [size=x-small]small text[/size]";
#
#-----[ ACTION: ADD BELOW]------------------------------------------
#
$lang['bbcode_h_help'] = "PHP syntax highlighter. [php]<?php code ?>[/php] (alt+h)"; // PHP MOD
#
#-----[ ACTION: CLOSE language/lang_YOUR_LANGUAGE/lang_main.php]------------------------------------------
#
#
#-----[ ACTION: OPEN /posting.php]------------------------------------------
#
#
#-----[ ACTION: FIND]------------------------------------------
#
"L_BBCODE_F_HELP" => $lang['bbcode_f_help'],
#
#-----[ ACTION: ADD BELOW]------------------------------------------
#
"L_BBCODE_H_HELP" => $lang['bbcode_h_help'], // PHP MOD
#
#-----[ ACTION: CLOSE /posting.php]------------------------------------------
#
#
#-----[ ACTION: UPLOAD YOUR FILES]------------------------------------------
#[/code]

Verfasst: 05.05.2003 07:53
von Chaze
Du mußt nur der Anleitung folgen (suche in Datei xy.php die Zeile Z und füge darunter XYZ ein, usw.).

Bedenke, dass die Anleitung für phpBB 2.0.0 geschrieben wurde. D.h. dass evtl. einige Zeilen, die Du suchen sollst, anderst aussehen oder das der Mod so nicht funktioniert.
Wenn Du aber ein Backup der entsprechenden Dateien machst, ist es auf jeden Fall einen Versuch wert.

Verfasst: 06.05.2003 19:57
von Gast
also installiert hab ich den mod schon und er funktioniert auch wunderbar. jetzt hab ich nur einmal eine code- und einmal eine php-funktion. ich möchte jedoch die code mit der php-funktion ersetzen.

erschwerend kommt hinzu, dass ich noch den fisubsilver_codeexp-mod installiert hab. dieser wertet die code-funktion ein bischen auf. sprich: alles was normaler weise ausschaut, ist jetzt in einer art box, die auf- und zugeklappt werden kann. auserdem kann man durch ein kleines icon den gesamten text in der box markieren.

wenn interesse besteht, könnt ich den mod hier mal posten.

Verfasst: 06.05.2003 22:16
von Angela Goldig
*meld* interesse :D

Verfasst: 07.05.2003 22:18
von Gast
ok, in diesem forum gibt es ein beispiel:
http://forum.2lucky.de
dort einfach ins forum und dann unter php2 gehen.

und hier die adresse, wo es den mod gibt:
http://www.forumimages.com/forum/viewto ... highlight=

Verfasst: 07.05.2003 22:23
von Angela Goldig
danke :)