Flash Video Action
This is a simple WikkaWiki plugin to embed flash video from popular sites (YouTube, Vimeo, Google Video, and Blip.tv) with simple wiki syntax. To use it, just drop flashvideo.php (below) in the plugins/actions directory in your wiki.
Contact: Christopher Vo for more details and bug reporting.
Note: This code is licensed under Apache License 2.0 as shown in the graphviz.php header.
flashvideo.php
<?php
/*
Flash Video Action for WikkaWiki
Copyright 2009 Christopher Vo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// get url, width, and height
$url = $vars['url'];
// if the url is not empty, embed a video
if(!empty($url)) {
// get width and height
$video_width = empty($vars['width']) ? 480 : $vars['width'];
$video_height = empty($vars['height']) ? 385 : $vars['height'];
// parse url
$parsed = parse_url($url);
if(!$parsed) {
echo '[ Error: Video URL Malformed ]';
return;
}
parse_str(htmlspecialchars_decode($parsed['query']),$parsed['query']);
// detect host
if(strpos($parsed['host'], 'youtube') !== false)
$type = 'youtube';
else if(strpos($parsed['host'], 'vimeo') !== false)
$type = 'vimeo';
else if(strpos($parsed['host'], 'google') !== false)
$type = 'google';
else if(strpos($parsed['host'], 'blip.tv') !== false)
$type = 'blip';
else {
echo '[ Error: Video type not supported ]';
return;
}
// set up the special stuff for each host
$default_query = '';
switch($type) {
case 'youtube':
$vid_id = $parsed['query']['v'];
$default_query = array(
'fs' => 1,
'rel' => 0,
'hl' => 'en');
$default_query = http_build_query($default_query);
$movie = 'http://www.youtube.com/v/' . $vid_id . '?'. $default_query;
break;
case 'vimeo':
preg_match('/[0-9]+\/?$/', $parsed['path'], $vid_id_matches);
$vid_id = $vid_id_matches[0];
$default_query = array(
'clip_id' => $vid_id,
'server' => 'vimeo.com',
'show_title' => 0,
'show_byline' => 0,
'show_portrait' => 0,
'color' => '00adef',
'fullscreen' => 1);
$default_query = http_build_query($default_query);
$movie = 'http://vimeo.com/moogaloop.swf?' . $default_query;
break;
case 'google':
$vid_id = $parsed['query']['docid'];
$default_query = array(
'docid' => $vid_id,
'hl' => 'en',
'fs' => 'true');
$default_query = http_build_query($default_query);
$movie = 'http://video.google.com/googleplayer.swf?' . $default_query;
break;
case 'blip':
$num_matches = preg_match('/[0-9]+\/?$/', $parsed['path'], $blip_id_matches);
$blip_id = $blip_id_matches[0];
// get api data from blip.tv
$api_data = @file_get_contents('http://blip.tv/file/'.$blip_id.'?skin=api');
if(!$api_data) {
echo '[ Error: Could not communicate with blip.tv to embed video ]';
return;
}
// extract embed URL from api data
$xml = new SimpleXMLElement($api_data);
$movie = $xml->payload->asset->embedUrl[0];
break;
}
// create embed html
$embed_html = '<object width="'.$video_width.'" height="'.$video_height.'">
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="'.$movie.'" />
<embed src="'.$movie.'"
type="application/x-shockwave-flash"
allowscriptaccess="always"
allowfullscreen="true"
width="'.$video_width.'"
height="'.$video_height.'"></embed>
</object>';
// output
echo $embed_html;
}
?>
/*
Flash Video Action for WikkaWiki
Copyright 2009 Christopher Vo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// get url, width, and height
$url = $vars['url'];
// if the url is not empty, embed a video
if(!empty($url)) {
// get width and height
$video_width = empty($vars['width']) ? 480 : $vars['width'];
$video_height = empty($vars['height']) ? 385 : $vars['height'];
// parse url
$parsed = parse_url($url);
if(!$parsed) {
echo '[ Error: Video URL Malformed ]';
return;
}
parse_str(htmlspecialchars_decode($parsed['query']),$parsed['query']);
// detect host
if(strpos($parsed['host'], 'youtube') !== false)
$type = 'youtube';
else if(strpos($parsed['host'], 'vimeo') !== false)
$type = 'vimeo';
else if(strpos($parsed['host'], 'google') !== false)
$type = 'google';
else if(strpos($parsed['host'], 'blip.tv') !== false)
$type = 'blip';
else {
echo '[ Error: Video type not supported ]';
return;
}
// set up the special stuff for each host
$default_query = '';
switch($type) {
case 'youtube':
$vid_id = $parsed['query']['v'];
$default_query = array(
'fs' => 1,
'rel' => 0,
'hl' => 'en');
$default_query = http_build_query($default_query);
$movie = 'http://www.youtube.com/v/' . $vid_id . '?'. $default_query;
break;
case 'vimeo':
preg_match('/[0-9]+\/?$/', $parsed['path'], $vid_id_matches);
$vid_id = $vid_id_matches[0];
$default_query = array(
'clip_id' => $vid_id,
'server' => 'vimeo.com',
'show_title' => 0,
'show_byline' => 0,
'show_portrait' => 0,
'color' => '00adef',
'fullscreen' => 1);
$default_query = http_build_query($default_query);
$movie = 'http://vimeo.com/moogaloop.swf?' . $default_query;
break;
case 'google':
$vid_id = $parsed['query']['docid'];
$default_query = array(
'docid' => $vid_id,
'hl' => 'en',
'fs' => 'true');
$default_query = http_build_query($default_query);
$movie = 'http://video.google.com/googleplayer.swf?' . $default_query;
break;
case 'blip':
$num_matches = preg_match('/[0-9]+\/?$/', $parsed['path'], $blip_id_matches);
$blip_id = $blip_id_matches[0];
// get api data from blip.tv
$api_data = @file_get_contents('http://blip.tv/file/'.$blip_id.'?skin=api');
if(!$api_data) {
echo '[ Error: Could not communicate with blip.tv to embed video ]';
return;
}
// extract embed URL from api data
$xml = new SimpleXMLElement($api_data);
$movie = $xml->payload->asset->embedUrl[0];
break;
}
// create embed html
$embed_html = '<object width="'.$video_width.'" height="'.$video_height.'">
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="'.$movie.'" />
<embed src="'.$movie.'"
type="application/x-shockwave-flash"
allowscriptaccess="always"
allowfullscreen="true"
width="'.$video_width.'"
height="'.$video_height.'"></embed>
</object>';
// output
echo $embed_html;
}
?>
List of Resource Pages in MASC