Videos from Facebook or YouTube

This is the right place to report general bugs, make suggestions or ask for help.
Post Reply
EYUman
Posts: 1
Joined: Thu Apr 18, 2019 6:50 am

Videos from Facebook or YouTube

Post by EYUman » Thu Apr 18, 2019 6:55 am

Hi there

I am looking for a way to make videos run on FlatPress .. until now, noting works.

Thanks in advance for any answer.
Regards
EYUman

User avatar
Arvid
FlatPress Coder
Posts: 40
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Videos from Facebook or YouTube

Post by Arvid » Sat Apr 20, 2019 11:20 am

Hi, welcome to the FlatPress support forum :)

I have no experiences with Facebook videos (anyone else?), but as for Youtube, it's as simple as that:

Code: Select all

[video=https://www.youtube.com/watch?v=mIGfest1b1M]
See also the BBCode documentation on our wiki: https://wiki.flatpress.org/doc:plugins:bbcode

Regards,
Arvid
Helpful FlatPress links: Project blog 📝 - FlatPress wiki 📖 - FlatPress@Twitter 🐦
Stay up to date with our feeds: Forum RSS feed 📜 - Project blog RSS feed 📜


🇩🇪 Oktober 2019: Habe aktuell für meinen Arbeitgeber hier im Ruhrgebiet Stellen zu besetzen! 🇩🇪
- Softwareentwickler (Webanwendungen) - unbefristet, sofort
- Studentische Hilfskraft IT - unbefristet, sofort
- Auszubildender Fachinformatiker Anwendungsentwicklung - Sommer 2020

vodka
Posts: 9
Joined: Tue Mar 12, 2019 8:53 pm

Re: Videos from Facebook or YouTube

Post by vodka » Sun Apr 21, 2019 10:25 am

Replace the script from line 332 in fp-plugin/bbcode/plugin.bbcode.php with this

Code: Select all

function do_bbcode_video($action, $attr, $content, $params, $node_object) {
	if ($action == 'validate') {
		return true;
	}
	$vurl = parse_url($attr['default']);
	if (isset($attr['type'])) {
		$type = $attr['type'];
	} else {
		// is it http://www.MYSITE.com  or http://MYSITE.com ?
		$web = explode('.', $vurl['host']);
		array_pop($web);
		$type = isset($web[1])
			? $web[1]
			: $web[0];
	}
	
		$color = isset($attr['color'])
			? $attr['color']
			: '';
		$width = isset($attr['width'])
			? $attr['width']
			: '560';
		$height = isset($attr['height'])
			? $attr['height']
			: '315';
		$allowfs = isset($attr['allowfullscreen'])
			? $attr['height']
			: 'allowfullscreen';			
		$float = isset($attr['float'])
			? "align=\"{$attr['float']}\" "
			: "style=\"margin: 0 auto; display:block;\" ";

	
	$query = utils_kexplode($vurl['query'], '=&');
	$the_url = null;
	$others = '';
	switch ($type) {
		case 'html5':
			$the_url = "<video style=\"display:block; margin: 0 auto;\" width=\"{$width}\" height=\"{$height}\" controls>"
				."<source src=\"".$attr['default']."\">"
				."Your browser does not support the video tag."
				."</video>";
			break;
		case 'youtube':
			$the_url = "<iframe src=\"https://www.youtube.com/embed/{$query['v']}\" width=\"{$width}\" height=\"{$height}\" frameborder=\"0\" allow=\"accelerometer; autoplay; fullscreen; encrypted-media; gyroscope; picture-in-picture\" {$float}></iframe>";
			break;
		case 'vimeo':
			$vid = isset($query['sec'])? $query['sec'] : str_replace('/', '', $vurl['path']);
			$the_url="<iframe src=\"https://player.vimeo.com/video/{$vid}?color={$vid}&title=0&byline=0&portrait=0\" width=\"{$width}\" height=\"{$height}\" frameborder=\"0\" allow=\"autoplay; fullscreen;\" allowfullscreen {$float}></iframe>";
			break;
		case 'facebook':
			$vid = isset($query['sec'])? $query['sec'] : str_replace('/video/', '', $vurl['path']);
			$the_url="<div id=\"fb-root\"></div>
			<script async defer src=\"https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.2\"></script>
			<div class=\"fb-video\" data-href=\"{$vid}\" data-allowfullscreen=\"true\" data-width=\"{$width}\"></div>";
			break;
		case 'default':
		default:
			$the_url = null;
	}

	if ($the_url) {
		return $the_url;
	}
	return '[unsupported video]';
}
You have support for youtube, vimeo, facebook and html5 (for mp4 you must set the type like in the exemple).

Code: Select all

youtube:

[video=https://www.youtube.com/watch?v=15nPDcuqDTI]

html5:

[video=https://media.w3.org/2010/05/sintel/trailer.mp4 type=html5]

vimeo:

[video=https://vimeo.com/96867408]

facebook:

[video=https://www.facebook.com/facebook/videos/10153231379946729/]
I hope to find a way to auto recognize html5 videos and I will send all in github.

User avatar
B-d-R-D
Posts: 5
Joined: Mon Jul 01, 2019 5:57 am
Contact:

Re: Videos from Facebook or YouTube

Post by B-d-R-D » Mon Jul 01, 2019 4:38 pm

Hello there, hello vodka,

I replaced the script from line 332 in fp-plugin/bbcode/plugin.bbcode.php with your code and I got Error 500...
Nothing to see anymore behalve the Error 500 script error ..

Whats wong now?
I installed the flatpress-master which was offered here in an other thread .. :
Re: White screen after setup of Flatpress
Beitrag von Lubomír Ludvík » Mi Feb 20, 2019 9:05 pm

try dev version 1.1 https://github.com/flatpressblog/flatpr ... master.zip
And now I try to get my website running again ... :roll:

Well, I changed it back to the origin file, now the website is running again, but there is no possibility to run any other video URL than You Tube.

Regards
B-d-R-D
Regards B-d-R-D

vodka
Posts: 9
Joined: Tue Mar 12, 2019 8:53 pm

Re: Videos from Facebook or YouTube

Post by vodka » Mon Jul 08, 2019 10:50 pm

You must replace only the lines for the function (from 332 to 373)

rhays
Posts: 6
Joined: Fri Sep 20, 2019 2:38 pm

Re: Videos from Facebook or YouTube

Post by rhays » Sat Sep 21, 2019 6:05 pm

Thanks, Vodka!

Modified code as stated, and works well. Thanks for the patch.

Rick

User avatar
Arvid
FlatPress Coder
Posts: 40
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Videos from Facebook or YouTube

Post by Arvid » Mon Oct 07, 2019 3:07 pm

Thank you vodka, this is very useful. I slightly adapted your code and added it to the FP sources.

To be mentioned: It does not support uploaded video files yet - please refer to the the Audio and video player plugin in this case. Maybe we could unify this later.
Helpful FlatPress links: Project blog 📝 - FlatPress wiki 📖 - FlatPress@Twitter 🐦
Stay up to date with our feeds: Forum RSS feed 📜 - Project blog RSS feed 📜


🇩🇪 Oktober 2019: Habe aktuell für meinen Arbeitgeber hier im Ruhrgebiet Stellen zu besetzen! 🇩🇪
- Softwareentwickler (Webanwendungen) - unbefristet, sofort
- Studentische Hilfskraft IT - unbefristet, sofort
- Auszubildender Fachinformatiker Anwendungsentwicklung - Sommer 2020

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest