phpBB Media Embed PlugIn

Converting old [youtube] bbcode to [media] - phpBB Media Embed PlugIn

Converting old [youtube] bbcode to [media]

by cools » Mon Aug 20, 2018 11:40 am

Just wondering if anyone has any thoughts on this?

I was using an old BBCode that inserted the following into phpbb_posts.post_text:

Code: Select all

<YOUTUBE content="KJ9kqlRVGgc"><s>[youtube]</s>KJ9kqlRVGgc<e>[/youtube]</e></YOUTUBE>
MediaEmbed inserts this:

Code: Select all

<YOUTUBE id="yUFxG-ACTt4" url="https://www.youtube.com/watch?v=yUFxG-ACTt4"><s>[media]</s><URL url="https://www.youtube.com/watch?v=yUFxG-ACTt4">https://www.youtube.com/watch?v=yUFxG-ACTt4</URL><e>[/media]</e></YOUTUBE>
If there's only a single instance of the old BBCode in a post then this works to transform old > new:

Code: Select all

update phpbb_posts
set post_text = regexp_replace(post_text,'<YOUTUBE\\b[^>]*>(.*?)<\\/YOUTUBE>',
concat('<YOUTUBE id="'
,substring_index(substring_index(post_text,'<YOUTUBE content="',-1),'"',1)
,'" url="https://www.youtube.com/watch?v='
,substring_index(substring_index(post_text,'<YOUTUBE content="',-1),'"',1)
,'"><s>[media]</s><URL url="https://www.youtube.com/watch?v='
,substring_index(substring_index(post_text,'<YOUTUBE content="',-1),'"',1)
,'">https://www.youtube.com/watch?v='
,substring_index(substring_index(post_text,'<YOUTUBE content="',-1),'"',1)
,'</URL><e>[/media]</e></YOUTUBE>'))
where post_text like '%[youtube]%' and post_text not like '%[youtube]%[youtube]%';
But it (deliberately, because it won't) won't work for posts with multiple embeds.
cools
Registered User
Posts: 19
Joined: Wed Dec 24, 2008 6:20 pm
Contact:

Re: Converting old [youtube] bbcode to [media]

by neptronix » Mon Oct 22, 2018 2:32 am

Hm.. what would be needed to handle multiple youtubes embeds?

I'd really like to use this media embed plugin. Not being able to change the old posts is a problem..
neptronix
Registered User
Posts: 7
Joined: Fri Jul 06, 2018 3:53 pm
Contact:

Re: Converting old [youtube] bbcode to [media]

by AbaddonOrmuz » Tue Oct 23, 2018 4:21 am

I had to create a small extension to convert some old BBCodes automatically with a cronjob, so if anyone is interested, it can be done with PHP using preg_replace():

Regexp:

Code: Select all

#<YOUTUBE content="(\w+)"><s>\[youtube\]<\/s>\w+<e>\[\/youtube\]<\/e><\/YOUTUBE>#
Replacement:

Code: Select all

<YOUTUBE id="$1" url="https://www.youtube.com/watch?v=$1"><s>[media]</s><URL url="https://www.youtube.com/watch?v=$1">https://www.youtube.com/watch?v=$1</URL><e>[/media]</e></YOUTUBE>
A proudly user of Arch Linux :: /r/sddm_themes
User avatar
AbaddonOrmuz
Registered User
Posts: 411
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: Converting old [youtube] bbcode to [media]

by neptronix » Sun Oct 28, 2018 5:09 pm

Thanks for the code.

We found out a dealbreaker with this plugin. For users that are not logged in, the media embeds show attachment permissions errors. All of our content is meant to be seen by non-logged in users.

Actually rather glad i didn't go and make any modifications to the database content etc..
neptronix
Registered User
Posts: 7
Joined: Fri Jul 06, 2018 3:53 pm
Contact: