Hey guys,
I worked on PCEFX today with Aaron to modernize the Youtube embedding mod a bit to stop using Adobe Flash and instead use Youtube's prescribed way with an "<iframe>" tag where Youtube handles building the video player using HTML5-approved standards. I was annoyed enough about it and I wanted to put my coding skills to use here and help out!
This should stop all the problems in our Youtube thread and eliminate security issues (however small they were). Also, an added result/benefit, our thread will now work for Android and other Operating Systems that don't support Flash, so that's good too!
We had problems trying new Youtube SMF mods, so I wound up editing the one Aaron already had instead. Here is the PHP code I wrote to make this reality (mind you, it was a quick hack job):
Updated for Youtube, Facebook and Audio links (MP3, OGG, WAV)// nightwolve start
$URL = $input[2] . '';
// Handle Youtube
$youtube = strstr($URL, "youtu");
if ( $youtube ) {
if ( ($URL = strstr($youtube, 'youtu.be/')) )
$youtube = substr($URL, 9);
else if ( ($URL = strstr($youtube, 'v=')) )
$youtube = substr($URL, 2);
else
$youtube = $input[3];
return '<P><iframe width="560" height="315" src="https://www.youtube.com/embed/' . $youtube . '" frameborder="0" allowfullscreen></iframe></P>';
}
// Handle Facebook
$facebook = strstr($URL, ".facebook.com");
if ( $facebook ) {
if ( strstr($URL, 'plugins/video.php') )
$facebook = $URL;
else
$facebook = '[url]https://www.facebook.com/plugins/video.php?href='[/url] . URLEncode($URL) . '&show_text=0&width=560';
return '<P><iframe src="' . $facebook . '" width="560" height="315" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allowFullScreen="true"></iframe></P>';
}
// Handle audio (mp3/ogg/wav)
$ext = strtolower(substr($URL, -4));
if ( $ext == ".mp3" || $ext == ".ogg" || $ext == ".wav" )
return '<P><A HREF="' . $URL . '">' . $URL . '</A><BR><AUDIO SRC="' . $URL . '" CONTROLS></AUDIO></P>';
return $URL;
// nightwolve end
I'm building the basic embed tag as prescribed by Youtube, with default width/height of 560x315 and for allowing fullscreen mode.
<iframe width="560" height="315" src="https://www.youtube.com/embed/YPXXslxEyvc" frameborder="0" allowfullscreen></iframe>
The reason I'm showing you this is to speak now or forever hold your peace in terms of adding useful formatting or other tweaks.
For example, I added enclosing '<p></p>' to get similar breaking as before, although it changes things somewhat you notice over time, like you'll only need one break if you have multiple Youtube links and you'll need one less break if you want a sentence above or below it, you'll see what I mean, put it that way.
I'm glad to help give ole PCEFX a little modern boost, took a bit to track the code down and rebuild a packaged mod based on the original to get this going. I actually set this mod up on my site first, tested out hacks/changes, then when it was ready I installed it here. After looking at the whole mod's features, I also disabled support for all other embedding and just left it for Youtube to avoid any problems/security issues.
Anyway, yeah, if you have any thoughts/suggestions on how to tweak, now's your chance while I can and am interested. I think I got it working pretty good so far, but that remains to be seen!
EDIT: So here's an inline test: It behaves as before, if you want auto-embed, you remove the 's', while leaving it to just paste the link.
E.g.
With 's'
Without: