Instalacja rozszerzeń w phpBB
11 July 2008
Comments
Teraz zainstalujemy kilka przykładowych modułów. Zanim zabierzesz się za instalację jakiegoś upewnij się że moduł przeznaczony jest dla wersji forum, którą posiadasz.Oto opis instalacji modułu "PHP Syntax Highlighter BBCode" dostępnego na phpbb.com
#-----[ OTWÓRZ ]------------------------------------------
#
includes/bbcode.php
#
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
$bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']);
#-----[ NASTĘPNIE DODAJ ]------------------------------------------
#
<?php
$bbcode_tpl['php_open'] = str_replace('{L_PHP}', $lang['PHPCode'], $bbcode_tpl['php_open']); // PHP MOD
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
$text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);
#-----[ NASTĘPNIE DODAJ ]------------------------------------------
#
<?php
// PHP MOD
// [PHP] and [/PHP] for posting PHP code in your posts.
$text = bbencode_second_pass_php($text, $uid, $bbcode_tpl);
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
$text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, '');
#-----[ NASTĘPNIE DODAJ ]------------------------------------------
#
<?php
// PHP MOD
// [PHP] and [/PHP] for posting PHP code in your posts.
$text = bbencode_first_pass_pda($text, $uid, '[php]', '[/php]', '', true, '');
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
if ($open_tag[0] == '[code]')
{
$text = $before_start_tag . '[code]';
$text .= $between_tags . '[/code]';
}
#-----[ NASTĘPNIE DODAJ ]------------------------------------------
#
<?php
else if ($open_tag[0] == '[php]') // PHP MOD
{
$text = $before_start_tag . '/*php ';
$text .= $between_tags . ' /php*/';
}
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
} // bbencode_second_pass_code()
#-----[ NASTĘPNIE DODAJ ]------------------------------------------
#
/**
* PHP MOD
* Original code/function by phpBB Group
* Modified by JW Frazier / Fubonis < php_fubonis@yahoo.com >
*/
function bbencode_second_pass_php($text, $uid, $bbcode_tpl)
{
$code_start_html = $bbcode_tpl['php_open'];
$code_end_html = $bbcode_tpl['php_close'];
$matches = array();
$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 = trim($matches[1][$i]);
$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);
$after_replace = str_replace('&', '&', $after_replace);
$added = FALSE;
if (preg_match('/^<\?.*?\?>$/si', $after_replace) <= 0)
{
$after_replace = "<?php $after_replace ?>";
$added = TRUE;
}
if(strcmp('4.2.0', phpversion()) > 0)
{
ob_start();
highlight_string($after_replace);
$after_replace = ob_get_contents();
ob_end_clean();
}
else
{
$after_replace = highlight_string($after_replace, TRUE);
}
if ($added == TRUE)
{
$after_replace = str_replace('<font color="#0000BB"><?php ', '<font color="#0000BB">', $after_replace);
$after_replace = str_replace('<font color="#0000BB">?></font>', '', $after_replace);
}
$after_replace = preg_replace('/<font color="(.*?)">/si', '<span style="color: ;">', $after_replace);
$after_replace = str_replace('</font>', '</span>', $after_replace);
$after_replace = str_replace("
", '', $after_replace);
$replacement .= $after_replace;
$replacement .= $code_end_html;
$text = str_replace($str_to_match, $replacement, $text);
}
$text = str_replace("[php:$uid]", $code_start_html, $text);
$text = str_replace("[/php:$uid]", $code_end_html, $text);
return $text;
}
#-----[ OTWÓRZ ]------------------------------------------
#
posting.php
#
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
'L_BBCODE_F_HELP' => $lang['bbcode_f_help'],
#-----[ NASTĘPNIE DODAJ ]------------------------------------------
#
<?php
'L_BBCODE_X_HELP' => $lang['bbcode_x_help'], // PHP MOD
#-----[ OTWÓRZ ]------------------------------------------
#
templates/subSilver/bbcode.tpl
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
<!-- END email -->
#-----[ NASTĘPNIE DODAJ ]------------------------------------------
#
<?php
<!-- 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 -->
#-----[ OTWÓRZ ]------------------------------------------
#
templates/subSilver/posting_body.tpl
#
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
f_help = "{L_BBCODE_F_HELP}";
#-----[ NASTĘPNIE DODAJ ]------------------------------------------
#
<?php
x_help = "{L_BBCODE_X_HELP}";
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
bbtags = new Array(
#-----[ W WIERSZU ZNAJDŹ ]---------------------------------
<?php
'[url]','[/url]'
#-----[ NASTĘPNIE DODAJ DO WIERSZA ]---------------------------------
<?php
,'[php]','[/php]'
#-----[ OTWÓRZ ]------------------------------------------
#
language/lang_polisj/lang_main.php
#
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
$lang['Code']
#-----[ NASTĘPNIE DODAJ (w nowym wierszu)]---------------------------------
#
<?php
$lang['PHPCode'] = 'PHP'; // PHP MOD
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
$lang['bbcode_f_help']
#-----[ NASTĘPNIE DODAJ (w nowym wierszu)]------------------------------------
#
$lang['bbcode_x_help'] = 'Kolorowanie składni PHP. [php]<?php code ?>[/php] (alt+x)'; // PHP MOD
#-----[ OTWÓRZ ]------------------------------------------
#
language/lang_polish/lang_bbcode.php
#
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
//
// This ends the BBCode guide entries
//
#-----[ PRZED POWYŻSZYM DODAJ]------------------------------------------
#
<?php
$faq[] = array('Koloruje składnię php by skrypty były bardziej czytelne.');
#-----[ OTWÓRZ ]------------------------------------------
#
privmsg.php
#
#-----[ ZNAJDŹ ]------------------------------------------
#
<?php
// Load templates
//
$template->set_filenames(array(
'body' => 'posting_body.tpl')
);
make_jumpbox('viewforum.'.$phpEx);
#-----[ NASTĘPNIE DODAJ ]------------------------------------------
#
<?php
// EASYMOD-begin
//NOTE: the first element of each array must be '' Add new elements AFTER the ''
$EMBB_keys = array('', 'x');
$EMBB_widths = array('', '40');
$EMBB_values = array('', $lang['PHPCode']);
for ($i = 1; $i < count($EMBB_values); $i++)
{
// EasyMod BBcode mods
$val = ($i * 2) + 16;
$template->assign_block_vars('E if ($open_tag[0] == '[code]')asyModBB', array(
'KEY' => $EMBB_keys[$i],
'NAME' => "addbbcode$val",
'WIDTH' => $EMBB_widths[$i],
'VALUE' => $EMBB_values[$i],
'STYLE' => "bbstyle($val)")
);
}
// EASYMOD-end
Zapisz i zamknij wszystkie pliki. Teraz umieszczając w poście kod PHP między tagami [PHP] [/PHP] powinniśmy otrzymać kod w ładnych kolorach. :) Powyższy schemat instalacyjny jest standardowym sposobem instalacji i przekazywania modułów do phpBB. Poniżej mała ściągawka z angielskich terminów komend:
OPEN - otwórz
FIND - znajdź
IN-LINE FIND - znajdź w wierszu
IN-LINE AFTER, ADD - dodaj w wierszu po pokazanym kodzie
AFTER, ADD - Dodaj po pokazanym kodzie
REPLACE - zamień pokazany kod na inny
BEFORE, ADD - Dodaj przed pokazanym kodem
RkBlog
Comment article