Skip to content

Commit 152bbf0

Browse files
authored
Merge pull request #10 from RiverVanRain/master
Added Vimeo Channels and Instagram
2 parents adda8da + 9c3551f commit 152bbf0

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

lib/embed_extender.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ function embed_extender_parser($input, $view, $context)
3030
}
3131
}
3232
$patterns = array('#(((http://)?)|(^./))(((www.)?)|(^./))youtube\.com/watch[?]v=([^\[\]()<.,\s\n\t\r]+)#i'
33-
,'#(((http://)?)|(^./))(((www.)?)|(^./))youtu\.be/([^\[\]()<.,\s\n\t\r]+)#i'
34-
,'/(http:\/\/)?(www\.)?(vimeo\.com\/groups)(.*)(\/videos\/)([0-9]*)(\/)?/'
35-
,'/(http:\/\/)(www\.)?(metacafe\.com\/watch\/)([0-9a-zA-Z_-]*)(\/[0-9a-zA-Z_-]*)(\/)/'
36-
,'/(http:\/\/)?(www\.)?(vimeo.com\/)([^a-zA-Z][0-9]*)(\/)?/');
33+
,'#(((http://)?)|(^./))(((www.)?)|(^./))youtu\.be/([^\[\]()<.,\s\n\t\r]+)#i'
34+
,'/(http:\/\/)?(www\.)?(vimeo\.com\/groups)(.*)(\/videos\/)([0-9]*)(\/)?/'
35+
,'/(http:\/\/)(www\.)?(metacafe\.com\/watch\/)([0-9a-zA-Z_-]*)(\/[0-9a-zA-Z_-]*)(\/)/'
36+
,'/(http:\/\/)?(www\.)?(vimeo.com\/)([^a-zA-Z][0-9]*)(\/)?/'
37+
,'/(http:\/\/)?(www\.)?(vimeo\.com\/channels)(.*)(\/)([0-9]*)(\/)?/'
38+
,'/(http:\/\/)?(www\.)?(instagram\.com\/p\/)([0-9a-zA-Z_-]*)(\/)?/'
39+
,'/(http:\/\/)?(www\.)?(instagr\.am\/p\/)([0-9a-zA-Z_-]*)(\/)?/');
3740

3841
$custom_provider = elgg_get_plugin_setting('custom_provider', 'embed_extender');
3942

lib/embedvideo.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ function videoembed_create_embed_object($url, $guid, $videowidth=0, $input) {
5959
return videoembed_teachertube_handler($url, $guid, $videowidth);
6060
} else if (strpos($url, 'hulu.com') != false) {
6161
return videoembed_hulu_handler($url, $guid, $videowidth);
62+
} else if (strpos($url, 'instagram.com') != false) {
63+
return videoembed_instagram_handler($url, $guid, $videowidth);
64+
} else if (strpos($url, 'instagr.am') != false) {
65+
return videoembed_instagram_shortener_parse_url($url, $guid, $videowidth);
6266
}
6367

6468
if (!$input) {
@@ -130,6 +134,8 @@ function videoembed_add_object($type, $url, $guid, $width, $height) {
130134
case 'hulu':
131135
$videodiv .= "<object width=\"{$width}\" height=\"{$height}\"><param name=\"movie\" value=\"http://www.hulu.com/embed/{$url}\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.hulu.com/embed/{$url}\" type=\"application/x-shockwave-flash\" allowFullScreen=\"true\" width=\"{$width}\" height=\"{$height}\"></embed></object>";
132136
break;
137+
case 'instagram':
138+
$videodiv .= "<iframe src=\"{$url}embed/\" width=\"$width\" height=\"$height\" frameborder=\"0\" scrolling=\"no\" allowtransparency=\"true\"></iframe>";
133139
}
134140

135141
$videodiv .= "</div>";
@@ -751,3 +757,30 @@ function videoembed_hulu_parse_url($url) {
751757

752758
return $hash;
753759
}
760+
761+
function videoembed_instagram_handler($url, $guid, $videowidth) {
762+
if (!isset($url)) {
763+
return '<p><b>' . elgg_echo('embedvideo:parseerror', array('instagram')) . '</b></p>';
764+
}
765+
766+
videoembed_calc_size($videowidth, $videoheight, 425/320, 24);
767+
768+
$embed_object = videoembed_add_css($guid, $videowidth, $videoheight);
769+
770+
$embed_object .= videoembed_add_object('instagram', $url, $guid, $videowidth, $videoheight);
771+
772+
return $embed_object;
773+
}
774+
775+
function videoembed_instagram_shortener_parse_url($url, $guid, $videowidth) {
776+
$path = parse_url($url, PHP_URL_PATH);
777+
$videourl = 'https://instagram.com' . $path;
778+
779+
videoembed_calc_size($videowidth, $videoheight, 425/320, 24);
780+
781+
$embed_object = videoembed_add_css($guid, $videowidth, $videoheight);
782+
783+
$embed_object .= videoembed_add_object('instagram', $videourl, $guid, $videowidth, $videoheight);
784+
785+
return $embed_object;
786+
}

0 commit comments

Comments
 (0)