How to write a web source/custom embed

13 Jul 2015
@PHPVibe
11307

e1

The PHPVibe cms uses a tone of web sources, through web sources people can easily generate a video autoembed by submitting just the link.

We will be using the logic of the plugins system to achieve a new source without touching the code from lib/class.providers.php

First, let’s add our new source to the supported array of websites.

function newSourceName($hosts = array()){
$hosts[] = 'newsource.com';
return $hosts;
}

And hook it with a simple filter
add_filter('vibe-video-sources', 'newSourceName');

Now let’s provide the embed logic:

function EmbednewSourceName($txt =''){
global $vid;
if(isset($vid)) {
if($vid->VideoProvider($vid->theLink()) == 'newsource.com' ) {
$link = $vid->theLink();
if(!nullval($link)) {
$id = $vid->getVideoId("video/", '/'); //* Id extraction logic. Let's say the url has the id after /video , example www.phpvibe.com/video/1367/ *//
if(!nullval($id)) {
$tembed = ' < iframe(? object, etc) width="' . get_option('video-width') . '" height="' . get_option('video-heigth') . '" src="//newsource.com/player?vid='.$id.'" frameborder="0" allowfullscreen scrolling="no"> ';
$txt .= $tembed;
}
/* End link check */
}
/* End provider check */
}
/* End isset(vid) */
}
/* End function */
return $txt;
}

So now we have the function which gets the link to the external video source and turns it into an iframe embed.
Let’s hook it to the PHPVibe embeds through the filter EmbedModify.
add_filter('EmbedModify', 'EmbednewSourceName');

Now we have a new source of embeds for our visitors.

If you can scrape, or the source returns details (thumbnails, duration, title, description, tags), you can hook this also:

function DetailsnewSourceName($txt = ''){
global $vid,$websLink;
if(!isset($vid) && isset($websLink)) {
$vid = new Vibe_Providers($websLink);
}
if(isset($vid)) {
$link = $vid->theLink();
if(!nullval($link)) {

//* Logic to extract info from the link goes here and it's added to $txt *//

}
/* End isset(vid) */
}
/* End function */
return $txt;
}

The output expected is an array, example:

$video['description'] ='';
$video['title'] ='';
$video['thumbnail'] ='';
$video['duration'] ='';
$video['tags'] ='';

The function gets hooked to the filter EmbedDetails

add_filter('EmbedDetails', 'DetailsnewSourceName');

Now you will be returning video details on the second submission page.

e2

4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *