Merge pull request #373 from ex-hentai/bbcode

support more bbcode tags
This commit is contained in:
xiaomlove
2025-09-17 13:55:29 +07:00
committed by GitHub
7 changed files with 143 additions and 10 deletions

View File

@@ -283,6 +283,20 @@ function formatYoutube($src, $width = '', $height = ''): string
));
}
function formatVideo($src, $width, $height) {
if (!$width) {
$width = 560;
}
if (!$height) {
$height = 315;
}
return addTempCode("<video controls width=\"$width\" height=\"$height\"><source src=\"$src\" /><a href=\"$src\">$src</a></video>");
}
function formatAudio($src) {
return addTempCode("<audio controls><source src=\"$src\" /><a href=\"$src\">$src</a></audio>");
}
function formatSpoiler($content, $title = '', $defaultCollapsed = true): string
{
global $lang_functions;
@@ -301,6 +315,11 @@ function formatSpoiler($content, $title = '', $defaultCollapsed = true): string
return addTempCode($HTML);
}
function formatHidden($content): string
{
return addTempCode(sprintf('<span class="hidden-text">%s</span>', $content));
}
function formatTextAlign($text, $align): string
{
return addTempCode(sprintf('<div style="text-align: %s">%s</div>', $align, $text));
@@ -346,8 +365,8 @@ function format_comment($text, $strip_html = true, $xssclean = false, $newtab =
// Linebreaks
$s = nl2br($s);
$originalBbTagArray = array('[siteurl]', '[site]','[*]', '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[pre]', '[/pre]', '[/color]', '[/font]', '[/size]', " ");
$replaceXhtmlTagArray = array(get_protocol_prefix().get_setting('basic.BASEURL'), get_setting('basic.SITENAME'), '<img class="listicon listitem" src="pic/trans.gif" alt="list" />', '<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<pre>', '</pre>', '</span>', '</font>', '</font>', ' &nbsp;');
$originalBbTagArray = array('[siteurl]', '[site]','[*]', '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[s]', '[/s]', '[pre]', '[/pre]', '[/color]', '[/font]', '[/size]', '[hr]', " ");
$replaceXhtmlTagArray = array(get_protocol_prefix().get_setting('basic.BASEURL'), get_setting('basic.SITENAME'), '&#x2022; ', '<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<s>', '</s>', '<pre>', '</pre>', '</span>', '</font>', '</font>', '<hr>', ' &nbsp;');
$s = str_replace($originalBbTagArray, $replaceXhtmlTagArray, $s);
$originalBbTagArray = array("/\[font=([^\[\(&\\;]+?)\]/is", "/\[color=([#0-9a-z]{1,15})\]/is", "/\[color=([a-z]+)\]/is", "/\[size=([1-7])\]/is");
@@ -397,6 +416,17 @@ function format_comment($text, $strip_html = true, $xssclean = false, $newtab =
$s = preg_replace_callback("/\[youtube(\,([1-9][0-9]*)\,([1-9][0-9]*))?\]((http|https):\/\/[^\s'\"<>]+)\[\/youtube\]/i", function ($matches) {
return formatYoutube($matches[4], $matches[2], $matches[3]);
}, $s);
}
if (str_contains($s, "[video")) {
$s = preg_replace_callback("/\[video(\,([1-9][0-9]*)\,([1-9][0-9]*))?\]((http|https):\/\/[^\s'\"<>]+)\[\/video\]/i", function ($matches) {
return formatVideo($matches[4], $matches[2], $matches[3]);
}, $s);
}
if (str_contains($s, "[audio")) {
$s = preg_replace_callback("/\[audio\]((http|https):\/\/[^\s'\"<>]+)\[\/audio\]/i", function ($matches) {
return formatAudio($matches[1]);
}, $s);
}
// [url=http://www.example.com]Text[/url]
@@ -433,6 +463,11 @@ function format_comment($text, $strip_html = true, $xssclean = false, $newtab =
return formatTextAlign($matches[1], 'right');
}, $s);
// [hide]Hidden text[/hide]
$s = preg_replace_callback("/\[hide\](.*)\[\/hide\]/isU", function ($matches) {
return formatHidden($matches[1]);
}, $s);
$s = format_urls($s, $newtab);
// Quotes
@@ -5557,7 +5592,7 @@ function strip_all_tags($text)
{
//替换掉无参数标签
$bbTags = [
'[*]', '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[pre]', '[/pre]', '[quote]', '[/quote]',
'[*]', '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[s]', '[/s]', '[pre]', '[/pre]', '[quote]', '[/quote]',
'[/color]', '[/font]', '[/size]', '[/url]', '[/youtube]', '[/spoiler]',
];
$text = str_replace($bbTags, '', $text);
@@ -6481,4 +6516,8 @@ function can_view_post($uid, $post)
return true;
}
function hide_text($text) {
return '<span class="hidden-text">' . $text . '</span>';
}
?>

View File

@@ -22,6 +22,14 @@ $lang_tags = array
'text_underline_description' => "在文字下加划线",
'text_underline_syntax' => "[u]<i>文字</i>[/u]",
'text_underline_example' => "[u]这是下划线[/u]",
'text_strikethrough' => "删除线",
'text_strikethrough_description' => "为文字添加删除线",
'text_strikethrough_syntax' => "[s]<i>文字</i>[/s]",
'text_strikethrough_example' => "[s]这是删除线[/s]",
'text_hide' => '隐藏',
'text_hide_description' => '使文字隐藏',
'text_hide_syntax' => '[hide]<i>文字</i>[/hide]',
'text_hide_example' => '[hide]I tried so hard and got so far[/hide]',
'text_color_one' => "颜色 (方式1)",
'text_color_one_description' => "改变文字颜色",
'text_color_one_syntax' => "[color=<i>Color</i>]<i>文字</i>[/color]",
@@ -114,7 +122,15 @@ $lang_tags = array
'text_youtube' => "YouTube",
'text_youtube_description' => "在页面内插入YouTube网站的在线视频",
'text_youtube_syntax' => "[youtube,width,height]YouTube视频的URL[/youtube]",
'text_youtube_example' => "[youtube,560,315]https://www.youtube.com/watch?v=DWDL3VTCcCg&ab_channel=ESPNMMA[/youtube]",
'text_youtube_example' => "[youtube,560,315]https://www.youtube.com/watch?v=dQw4w9WgXcQ[/youtube]",
'text_video' => "视频",
'text_video_description' => "在页面内插入HTML5视频播放器",
'text_video_syntax' => "[video,width,height]视频的URL[/video]",
'text_video_example' => "[video]https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm[/video]",
'text_audio' => "音频",
'text_audio_description' => "在页面内插入HTML5音频播放器",
'text_audio_syntax' => "[audio]音频的URL[/audio]",
'text_audio_example' => "[audio]https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3[/audio]",
'text_youku' => "优酷",
'text_youku_description' => "在页面内插入优酷网的在线视频",
'text_youku_syntax' => "[youku]优酷网视频的URL[/youku]",
@@ -132,6 +148,10 @@ $lang_tags = array
'text_spoiler_description' => '在页面插入可展开/收缩的内容',
'text_spoiler_syntax' => '[spoiler=标题]这是被折叠的内容[/spoiler]',
'text_spoiler_example' => '[spoiler=英雄最后的结局怎么样了?]英雄最后死掉了![/spoiler]',
'text_hr' => '水平线',
'text_hr_description' => '在页面内插入水平线',
'text_hr_syntax' => '[hr]',
'text_hr_example' => 'Never gonna give you up[hr]Never gonna let you down',
'text_left' => '靠左对齐',
'text_left_description' => '在页面插入靠左对齐的内容',

View File

@@ -22,6 +22,14 @@ $lang_tags = array
'text_underline_description' => "Makes the enclosed text underlined.",
'text_underline_syntax' => "[u]<i>Text</i>[/u]",
'text_underline_example' => "[u]This is underlined text.[/u]",
'text_strikethrough' => "Strikethrough",
'text_strikethrough_description' => "Makes the enclosed text strikethrough.",
'text_strikethrough_syntax' => "[s]<i>Text</i>[/s]",
'text_strikethrough_example' => "[s]This is strikethrough text.[/s]",
'text_hide' => 'Hidden',
'text_hide_description' => 'Makes the enclosed text hidden',
'text_hide_syntax' => '[hide]<i>Text</i>[/hide]',
'text_hide_example' => '[hide]I tried so hard and got so far[/hide]',
'text_color_one' => "Color (alt. 1)",
'text_color_one_description' => "Changes the color of the enclosed text.",
'text_color_one_syntax' => "[color=<i>Color</i>]<i>Text</i>[/color]",
@@ -114,7 +122,15 @@ $lang_tags = array
'text_youtube' => "YouTube",
'text_youtube_description' => "Insert YouTube online video in webpages",
'text_youtube_syntax' => "[youtube,width,height]Video URL on YouTube[/youtube]",
'text_youtube_example' => "[youtube,560,315]https://www.youtube.com/watch?v=DWDL3VTCcCg&ab_channel=ESPNMMA[/youtube]",
'text_youtube_example' => "[youtube,560,315]https://www.youtube.com/watch?v=dQw4w9WgXcQ[/youtube]",
'text_video' => "Video",
'text_video_description' => "Insert HTML5 video player",
'text_video_syntax' => "[video,width,height]Video URL[/video]",
'text_video_example' => "[video]https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm[/video]",
'text_audio' => "Audio",
'text_audio_description' => "Insert HTML5 audio player",
'text_audio_syntax' => "[audio]Audio URL[/audio]",
'text_audio_example' => "[audio]https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3[/audio]",
'text_youku' => "YouKu",
'text_youku_description' => "Insert YouKu online video in webpages",
'text_youku_syntax' => "[youku]Video URL on YouKu[/youku]",
@@ -132,6 +148,10 @@ $lang_tags = array
'text_spoiler_description' => 'Insert expandable/collapsible content on the page',
'text_spoiler_syntax' => '[spoiler=title]This is the folded content[/spoiler]',
'text_spoiler_example' => '[spoiler=What happened to the final ending of the hero?]The hero died last![/spoiler]',
'text_hr' => 'Horizontal rule',
'text_hr_description' => 'Insert horizontal rule content on the page',
'text_hr_syntax' => '[hr]',
'text_hr_example' => 'Never gonna give you up[hr]Never gonna let you down',
'text_left' => 'Text align left',
'text_left_description' => 'Insert left-justified content on the page',

View File

@@ -96,3 +96,11 @@ img.hitandrun {
.form-control-row input[type=checkbox] {
vertical-align: sub;
}
.hidden-text {
filter: blur(.5em);
transition: filter .15s ease-in-out;
}
.hidden-text:hover {
filter: blur(0);
}

View File

@@ -59,6 +59,22 @@ insert_tag(
""
);
insert_tag(
$lang_tags['text_strikethrough'],
$lang_tags['text_strikethrough_description'],
$lang_tags['text_strikethrough_syntax'],
$lang_tags['text_strikethrough_example'],
""
);
insert_tag(
$lang_tags['text_hide'],
$lang_tags['text_hide_description'],
$lang_tags['text_hide_syntax'],
$lang_tags['text_hide_example'],
""
);
insert_tag(
$lang_tags['text_color_one'],
$lang_tags['text_color_one_description'],
@@ -252,6 +268,24 @@ insert_tag(
$lang_tags['text_youtube_example'],
""
);
insert_tag(
$lang_tags['text_video'],
$lang_tags['text_video_description'],
$lang_tags['text_video_syntax'],
$lang_tags['text_video_example'],
""
);
insert_tag(
$lang_tags['text_audio'],
$lang_tags['text_audio_description'],
$lang_tags['text_audio_syntax'],
$lang_tags['text_audio_example'],
""
);
/*
insert_tag(
$lang_tags['text_youku'],
@@ -286,6 +320,15 @@ insert_tag(
""
);
insert_tag(
$lang_tags['text_hr'],
$lang_tags['text_hr_description'],
$lang_tags['text_hr_syntax'],
$lang_tags['text_hr_example'],
""
);
end_frame();
end_main_frame();
stdfoot();

View File

@@ -992,14 +992,14 @@ tr_small($lang_usercp['row_email_address'], $CURUSER['email'], 1);
$seedBoxIcon = (new \App\Repositories\SeedBoxRepository())->renderIcon($CURUSER['ip'], $CURUSER['id']);
if ($enablelocation_tweak == 'yes'){
list($loc_pub, $loc_mod) = get_ip_location($CURUSER["ip"]);
tr_small($lang_usercp['row_ip_location'], $CURUSER["ip"]." <span title='" . $loc_mod . "'>[" . $loc_pub . "]</span>$seedBoxIcon", 1);
tr_small($lang_usercp['row_ip_location'], hide_text($CURUSER["ip"])." <span title='" . $loc_mod . "'>[" . $loc_pub . "]</span>$seedBoxIcon", 1);
}
else{
tr_small($lang_usercp['row_ip_location'], $CURUSER["ip"] . $seedBoxIcon, 1);
tr_small($lang_usercp['row_ip_location'], hide_text($CURUSER["ip"]) . $seedBoxIcon, 1);
}
if ($CURUSER["avatar"])
tr_small($lang_usercp['row_avatar'], "<img src=\"" . $CURUSER["avatar"] . "\" border=0>", 1);
tr_small($lang_usercp['row_passkey'], $CURUSER["passkey"], 1);
tr_small($lang_usercp['row_passkey'], hide_text($CURUSER["passkey"]), 1);
if (get_setting('security.login_type') == 'passkey' && get_setting('security.login_secret_deadline') > date('Y-m-d H:i:s')) {
tr_small($lang_usercp['row_passkey_login_url'], sprintf('%s/%s/%s', getSchemeAndHttpHost(), get_setting('security.login_secret'), $CURUSER['passkey']), 1);
}

View File

@@ -235,7 +235,8 @@ if (user_can('userprofile') || $user["id"] == $CURUSER["id"])
$locationinfo = "<span title=\"" . $loc_mod . "\">[" . $loc_pub . "]</span>";
}
else $locationinfo = "";
tr_small($lang_userdetails['row_ip_address'], $user['ip'].$locationinfo.$seedBoxIcon, 1);
$ip = $user["id"] == $CURUSER["id"] ? hide_text($user['ip']) : $user['ip'];
tr_small($lang_userdetails['row_ip_address'], $ip.$locationinfo.$seedBoxIcon, 1);
}
$clientselect = '';
$res = sql_query("SELECT peer_id, agent, ipv4, ipv6, port FROM peers WHERE userid = {$user['id']} GROUP BY agent, ipv4, ipv6, port") or sqlerr();
@@ -247,7 +248,9 @@ if (mysql_num_rows($res) > 0)
$clientselect .= "<tr>";
$clientselect .= sprintf('<td>%s</td>', get_agent($arr['peer_id'], $arr['agent']));
if (user_can('userprofile') || $user["id"] == $CURUSER["id"]) {
$clientselect .= sprintf('<td>%s</td><td>%s</td><td>%s</td>', $arr['ipv4'].$seedBoxRep->renderIcon($arr['ipv4'], $user['id']), $arr['ipv6'].$seedBoxRep->renderIcon($arr['ipv6'], $user['id']), $arr['port']);
$v4 = $user["id"] == $CURUSER["id"] ? hide_text($arr['ipv4']) : $arr['ipv4'];
$v6 = $user["id"] == $CURUSER["id"] ? hide_text($arr['ipv6']) : $arr['ipv6'];
$clientselect .= sprintf('<td>%s</td><td>%s</td><td>%s</td>', $v4.$seedBoxRep->renderIcon($arr['ipv4'], $user['id']), $v6.$seedBoxRep->renderIcon($arr['ipv6'], $user['id']), $arr['port']);
} else {
$clientselect .= sprintf('<td>%s</td><td>%s</td><td>%s</td>', '---', '---', '---');
}