avatar_Marius P.

Write a web source/new embed for PHPVibe

Started by Marius P.,

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Marius P.Topic starter

How to write a web source/new embed for PHPVibe

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 plugin 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;
}

Now let's provide the embed logic for this new example source:

For v5, v6 versions of PHPVibe
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 old.phpvibe.com/video/1367/ *//
if(!nullval($id)) {
$tembed = ' < iframe(? object, etc) width="' . get_option('video-width') . '" height="' . get_option('video-heigth') . '" src="http://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;
}

For PHPVibe v11+
function EmbednewSourceName($txt =''){
    global $VibeProvider, $VibeLink;
    if (isset($VibeProvider) && isset($VibeLink)) {
        if($VibeProvider == 'yournewsourceDeclaredName' ) {
//make sure you restrict the changes to this source
          
            if(not_empty($VibeLink)) {
                $id =  $VibeLink.' something to prepare it'; //* Id extraction logic. Let's say the url has the id after /video , example old.phpvibe.com/video/1367/ *//
                if(not_empty($id)) {
                    $tembed = ' < iframe(? object, etc) width="' . get_option('video-width') . '" height="' . get_option('video-heigth') . '" src="http://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 that 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:
for PHPVibe 5-6

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;
}

for PHPVibe 11+
function DetailsnewSourceName($zvideo = array())
{
    global $VibeProvider, $VibeLink;
    //expected output
    $xvideo = array();
    $xvideo['description'] = '';
    $xvideo['title'] = '';
    $xvideo['thumbnail'] = '';
    $xvideo['duration'] = '';
    $xvideo['tags'] = '';
    if ($VibeProvider == 'yournewsourceDeclaredName') {
//make sure you restrict the changes to this source

//* Logic to extract info from the link goes here and it's added to $txt *//
        $xvideo .= 'do something to extract details';
    }
    /* End function */
    return array_merge($zvideo, $xvideo);
}

The function gets hooked to the filter EmbedDetails

add_filter('EmbedDetails', 'DetailsnewSourceName');
Now you will be returning video details on the second submission page.



Happy with my help? Buy me a coffee.
Please, always use the search before opening a new topic! We're all here on our (limited) free time! Make sure you help yourself too!
  •  
    The following users thanked this post: fox_mulder

Similar topics (7)

Replies: 0
Views: 980

Replies: 18
Views: 14837

Replies: 0
Views: 1206

Replies: 30
Views: 8739

Replies: 0
Views: 39