2018-11-27, 11:51 AM
I would like MyBB community to add this feature because YouTube and Facebook are blocked in China. I already did all the work so I'll post the steps here:
MyBB >= 1.8.21:
In 'jscripts/bbcodes_sceditor.js', add in 'mybbCmd' after 'Twitch' code section:
'Bilibili': {
'match': /https:\/\/www\.bilibili\.com\/video\/([^/]+)\/?/,
'url': '//player.bilibili.com/player.html?bvid=',
'html': '<iframe src="{url}" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" ' +
' style="width: 640px; height: 430px; max-width: 100%" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
}
In Admin CP add custom MyCode:
Title: Bilibili
Short Description: Bilibili videos
Regular Expression: \[video=bilibili\]https:\/\/www\.bilibili\.com\/video\/([^/]+)\/?\[\/video\]
Replacement: <iframe src="//player.bilibili.com/player.html?aid=$1&bvid=$1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" style="width: 640px; height: 430px; max-width: 100%"></iframe>
MyBB < 1.8.21:
1. Create template "video_bilibili_embed" with content:
2. Edit "inc/class_parser.php", find the switch case for videos (search "twitch" for example) and add before the default:
3. Edit "inc/functions.php" and on the function "build_mycode_inserter", on the array "$editor_lang_strings", add the following:
Note: I don't know where this is used and if there are more things necessary to edit.
4. Edit "jscripts/bbcodes_sceditor.js", find:
add below:
find:
add below:
find:
add below:
MyBB >= 1.8.21:
In 'jscripts/bbcodes_sceditor.js', add in 'mybbCmd' after 'Twitch' code section:
'Bilibili': {
'match': /https:\/\/www\.bilibili\.com\/video\/([^/]+)\/?/,
'url': '//player.bilibili.com/player.html?bvid=',
'html': '<iframe src="{url}" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" ' +
' style="width: 640px; height: 430px; max-width: 100%" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
}
In Admin CP add custom MyCode:
Title: Bilibili
Short Description: Bilibili videos
Regular Expression: \[video=bilibili\]https:\/\/www\.bilibili\.com\/video\/([^/]+)\/?\[\/video\]
Replacement: <iframe src="//player.bilibili.com/player.html?aid=$1&bvid=$1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" style="width: 640px; height: 430px; max-width: 100%"></iframe>
MyBB < 1.8.21:
1. Create template "video_bilibili_embed" with content:
<iframe src="//player.bilibili.com/player.html?aid={$id}" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" style="width: 640px; height: 430px; max-width: 100%"></iframe>
2. Edit "inc/class_parser.php", find the switch case for videos (search "twitch" for example) and add before the default:
case "bilibili":
// https://www.bilibili.com/video/av34623787/
$id = substr($path[2], 2);
break;
3. Edit "inc/functions.php" and on the function "build_mycode_inserter", on the array "$editor_lang_strings", add the following:
"editor_insertbilibilivideo" => "Insert a Bilibili video",
"editor_enterbilibiliurl" => "Enter the Bilibli video URL:",
"editor_invalidbilibili" => "Invalid Bilibili video"
Note: I don't know where this is used and if there are more things necessary to edit.
4. Edit "jscripts/bbcodes_sceditor.js", find:
twitch: '<iframe src="{url}" frameborder="0" scrolling="no" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
add below:
bilibili: '<iframe src="{url}" frameborder="0" scrolling="no" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
find:
case 'twitch':
matches = content.match(/twitch\.tv\/(?:[\w+_-]+)\/v\/(\d+)/);
url = matches ? '//player.twitch.tv/?video=v' + matches[1] : false;
break;
add below:
case 'bilibili':
matches = content.match(/bilibili\.com\/video\/av(\d+)($|\/)/);
url = matches ? '//player.bilibili.com/player.html?aid=' + matches[1] : false;
break;
find:
'<option value="twitch">' + editor._('Twitch') + '</option>' +
add below:
'<option value="bilibili">' + editor._('Bilibili') + '</option>' +