|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
我使用的PHPBB没有Flash播放、音乐播放的代码,我想知道金光论坛的这种程序的代码能否适用于PHPbb?
如果不能请大家叫我怎么修改CODE?
下面是CODE的源文件:
// global that holds loaded-and-prepared bbcode templates, so we only have to do
// that stuff once.
$bbcode_tpl = null;
// MULTI BBCODE-begin
function Multi_BBCode()
{
global $template, $lang;
// DO NOT CHANGE THIS ARRAY
$hotkeys = array('', 'd', 'e', 'g', 'h', 'j', 'k', 'm', 'n', 'r', 't', 'v', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0');
//NOTE: the first element of each array must be '' Add new elements AFTER the ''
$EMBB_widths = array('','40') ;
$EMBB_values = array('','intro') ;
for ($i=1; $i<count($EMBB_values); $i++)
{
// load BBcode MODs info
$val = ($i*2)+16 ;
$help_lang = ( !empty($lang['bbcode_help'][(strtolower($EMBB_values[$i]))]) ) ? $lang['bbcode_help'][(strtolower($EMBB_values[$i]))] : $lang['bbcode_help'][$EMBB_values[$i]];
$template->assign_block_vars('MultiBB', array(
'KEY' => $hotkeys[$i],
'NAME' => "addbbcode$val",
'HELP' => sprintf($help_lang, $hotkeys[$i]),
'WIDTH' => $EMBB_widths[$i],
'VALUE' => $EMBB_values[$i],
'STYLE' => "bbstyle($val)")
);
}
}
// MULTI BBCODE-end
/**
* Loads bbcode templates from the bbcode.tpl file of the current template set.
* Creates an array, keys are bbcode names like "b_open" or "url", values
* are the associated template.
* Probably pukes all over the place if there's something really screwed
* with the bbcode.tpl file.
*
* Nathan Codding, Sept 26 2001.
*/
function load_bbcode_template()
{
global $template;
$tpl_filename = $template->make_filename('bbcode.tpl');
$tpl = fread(fopen($tpl_filename, 'r'), filesize($tpl_filename));
// replace \ with \\ and then ' with \'.
$tpl = str_replace('\\', '\\\\', $tpl);
$tpl = str_replace('\'', '\\\'', $tpl);
// strip newlines.
$tpl = str_replace("\n", '', $tpl);
// Turn template blocks into PHP assignment statements for the values of $bbcode_tpls..
$tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . '$bbcode_tpls[\'\\1\'] = \'\\2\';', $tpl);
$bbcode_tpls = array();
eval($tpl);
return $bbcode_tpls;
}
/**
* Prepares the loaded bbcode templates for insertion into preg_replace()
* or str_replace() calls in the bbencode_second_pass functions. This
* means replacing template placeholders with the appropriate preg backrefs
* or with language vars. NOTE: If you change how the regexps work in
* bbencode_second_pass(), you MUST change this function.
*
* Nathan Codding, Sept 26 2001
*
*/
function prepare_bbcode_template($bbcode_tpl)
{
global $lang;
$bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']);
$bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']);
$bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']);
$bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']);
$bbcode_tpl['quote_username_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_username_open']);
$bbcode_tpl['quote_username_open'] = str_replace('{L_WROTE}', $lang['wrote'], $bbcode_tpl['quote_username_open']);
$bbcode_tpl['quote_username_open'] = str_replace('{USERNAME}', '\\1', $bbcode_tpl['quote_username_open']);
$bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']);
$bbcode_tpl['img'] = str_replace('{URL}', '\\1', $bbcode_tpl['img']);
// We do URLs in several different ways..
$bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']);
$bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);
$bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']);
$bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']);
$bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']);
$bbcode_tpl['intro_open'] = str_replace('{L_INTRO}', $lang['Introduction'], $bbcode_tpl['intro_open']);
define("BBCODE_TPL_READY", true);
return $bbcode_tpl;
}
/**
* Does second-pass bbencoding. This should be used before displaying the message in
* a thread. Assumes the message is already first-pass encoded, and we are given the
* correct UID as used in first-pass encoding.
*/
function bbencode_second_pass($text, $uid)
{
global $lang, $bbcode_tpl;
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$text = " " . $text;
// First: If there isn't a "[" and a "]" in the message, don't bother.
if (! (strpos($text, "[") && strpos($text, "]")) )
{
// Remove padding, return.
$text = substr($text, 1);
return $text;
}
// Only load the templates ONCE..
if (!defined("BBCODE_TPL_READY"))
{
// load templates from file into array.
$bbcode_tpl = load_bbcode_template();
// prepare array for use in regexps.
$bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
}
// [intro] and [/intro] for introduction of hidden contents
$text = str_replace("[introuid]", $bbcode_tpl['intro_open'], $text);
$text = str_replace("[/introuid]", $bbcode_tpl['intro_close'], $text);
//for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);
//for posting replies with quote, or just for quoting stuff.
$text = str_replace("[quoteuid]", $bbcode_tpl['quote_open'], $text);
$text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text);
// New one liner to deal with opening quotes with usernames...
// replaces the two line version that I had here before..
$text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text);
// and [list=x] for (un)ordered lists.
// unordered lists
$text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text);
// li tags
$text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text);
// ending tags
$text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text);
$text = str_replace("[/list:$uid]", $bbcode_tpl['olist_close'], $text);
// Ordered lists
$text = preg_replace("/\[list=([a1]):$uid\]/si", $bbcode_tpl['olist_open'], $text);
// colours
$text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text);
$text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text);
// size
$text = preg_replace("/\[size=([1-2]?[0-9]):$uid\]/si", $bbcode_tpl['size_open'], $text);
$text = str_replace("[/size:$uid]", $bbcode_tpl['size_close'], $text);
// and for bolding text.
$text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text);
$text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text);
// and for underlining text.
$text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text);
$text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text);
// and for italicizing text.
$text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text);
$text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text);
// Patterns and replacements for URL and email tags..
$patterns = array();
$replacements = array();
// code..
// This one gets first-passed..
$patterns[] = "#\[img:$uid\]([^?](?:[^\[]+|\[(?!url))*?)\[/img:$uid\]#i";
$replacements[] = $bbcode_tpl['img'];
// matches a xxxx://www.phpbb.com code..
$patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url1'];
// www.phpbb.com code.. (no xxxx:// prefix).
$patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url2'];
// phpBB code..
$patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url3'];
// phpBB code.. (no xxxx:// prefix).
$patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url4'];
// user@domain.tld code..
$patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
$replacements[] = $bbcode_tpl['email'];
$text = preg_replace($patterns, $replacements, $text);
// Remove our padding from the string..
$text = substr($text, 1);
return $text;
} // bbencode_second_pass() |
|