WordPress Plugin for Thirdpresence

From ThirdPresence Wiki


ThirdPresence provides a free plugin for WordPress, which makes it even easier to publish mobile video within your WordPress site.

Installing plugin

You can download and install plugin from Wordpress Plugin Directory

Requirements

You have to have cURL module installed at php. Installation of cURL depends about system which you are using. More info can be found from http://www.php.net/manual/en/curl.installation.php

Manual installation

You can install plugin using manual installation method. Here you can find instructions http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation

Using plug-in

After installing the plugin, just use this syntax to embed a video into your WordPress post:

[thirdpresence video="videoid" /]

The parameter "videoid" is the id number of the video that you want. When the post is accessed, a thumbnail image of the video will be displayed inline with the rest of the article.

Alternative parameters

[thirdpresence video="videoid" width="250" playtext="Play Video" controlbar="0" /]
Parameter Value Description
width pixels Width of the thumbnail image and player
playtext Any text If control bar is set non-visible then this text will we shown at below of thumbnail image. For HTML5 players this is ignored.
controlbar 0 = hide, 1 = visible displays controls at player. For HTML5 players this is ignored.


Examples

HTML5
[thirdpresence video="videoid" width="250" playtext="Play Video" controlbar="0" /]


With controlbar
[thirdpresence video="videoid" width="250" playtext="Play Video" controlbar="1" /]


Without controlbar
[thirdpresence video="videoid" width="250" playtext="Play Video" controlbar="0" /]


Source code

You can download source from http://wordpress.org/extend/plugins/thirdpresence/.

<?php

/*
Plugin Name: ThirdPresence mobile video plugin
Version: 0.1
Plugin URI: http://wiki.thirdpresence.com/index.php/Publishing_And_Players_Main#WordPress
Description: WordPress blog.
Author: ThirdPresence Ltd.
Author URI: http://www.thirdpresence.com
*/

//Account id/name
$account = [your thirdpresence account];

//Set width and height for the default video player
$width = 486;
$height = 412;

//Set default video variable
$videoid = 0;

//set default controlbar setting 0 = off, 1 = on
$controlbar = 1;

//set default "play" text
$play_text = "Play";

//set debug 0 = off, 1 = on
$d = 0;

function Thirdpresence_Parse($content)
{
    $content = preg_replace_callback("/\[thirdpresence ([^]]*)\/\]/i", "Thirdpresence_Resolver", $content);
    return $content;
}

function Thirdpresence_Resolver($matches)
{
    global $video, $account, $width, $height, $arguments,$d,$controlbar,$play_text;
    $output = '';
    $matches[1] = str_replace(array('”','″'), '', $matches[1]);
    preg_match_all('/(\w*)=\"(.*?)\"/i', $matches[1], $attributes);
    $arguments = array();

    foreach ( (array) $attributes[1] as $key => $value ) {
        $arguments[$value] = str_replace('"', '', $attributes[2][$key]);
    }

    if($d) {
         print_r( $arguments );
    }

    if (( !array_key_exists('video', $arguments) )) {
        return '<div style="background-color:#f99; padding:10px;">Thirdpresence Widget Error: Required parameter "video" is missing!</div>';
        exit;
    }
    else {
	$video = $arguments['video'];
    }

    if( array_key_exists('width', $arguments) ) {
        $width = $arguments['width'];
    }

    if( array_key_exists('playtext', $arguments) ) {
        $play_text = $arguments['playtext'];
        $play_text = urlencode($play_text);
    }

    if( array_key_exists('controlbar', $arguments) ) {
        $controlbar = $arguments['controlbar'];
    }

    if (function_exists('curl_init')) {
	    $include_url = 'http://' . $account . '.thirdpresence.com/dls/t/wp-plugin-inc.jsp?iid=' . $video . '&w=' . $width . '&pt=' . $play_text . '&b=' . $controlbar;
            if($d) {
	       $output .= '<a href="'. $include_url .'">'. $include_url .'</a>';
            }

	    $ch = curl_init($include_url);
	    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
	    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	    $output .= curl_exec($ch);
	    curl_close($ch);
    } else {
        $output = "ERROR! You have to be cURL mobule installed at php.";
    }

    return $output;
}

add_filter('the_content', 'Thirdpresence_Parse');

?>
This page was last modified on 24 May 2011, at 09:11.