* @version $Revision: 1.1 $
*/
class ItemAddEmbedVideo extends ItemAddPlugin {
/**
* @see ItemAddPlugin::handleRequest
*/
function handleRequest($form, &$item) {
global $gallery;
$status = $error = array();
if (isset($form['action']['addEmbedVideoPage'])) {
$platform =& $gallery->getPlatform();
if(isset($form['webPage']['URL'])) {
$url = $form['webPage']['URL'];
// Load any stored/set Parameters
list ($ret, $params) =
GalleryCoreApi::fetchAllPluginParameters('module', 'embedvideo');
if ($ret) {
return array($ret, null, null);
}
foreach (array('default', 'override') as $type) {
$ItemAddUploadApplet[$type] = array();
if (!empty($params['embedvideo' . $type . 'Variables'])) {
$variablesArray = explode('|', $params['embedvideo' . $type . 'Variables']);
foreach ($variablesArray as $variable) {
list ($name, $value) = explode('=', $variable);
$ItemAddEmbedVideo[$type][$name] = $value;
}
}
}
// Store any Parameters into some simpler, shorter, local variables
$debug=0;
$use_internal_flv_player = $ItemAddEmbedVideo['default']['useInternalFlvPlayer'];
$youtube_dev_id = $ItemAddEmbedVideo['default']['youtubeDevId'];
$width=$ItemAddEmbedVideo['default']['width'];
$height=$ItemAddEmbedVideo['default']['height'];
$external_flv_player = $ItemAddEmbedVideo['default']['externalFlvPlayer'];
$external_flv_player_vars = $ItemAddEmbedVideo['default']['externalFlvPlayerVars'];
///////////////////////////////
// Embed a Youtube Video
///////////////////////////////
if(preg_match("/www.youtube.com/",$url)) {
if(preg_match("/watch\?v=(.*)/",$url,$matches)) {
$video_id = $matches[1];
} else {
return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER,__FILE__,__LINE__,
"Unable to extract video id from url: $url"),null,null);
}
// Youtube Developer ID
$dev_id = $youtube_dev_id;
if(!preg_match("/\w+/",$dev_id)) {
return array(GalleryCoreApi::error(ERROR_CONFIGURATION_REQUIRED,__FILE__,__LINE__,
"Invalid/missing YouTube developer ID: $dev_id"),null,null);
}
// Youtube api feed
$feed = "http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=$dev_id&video_id=$video_id";
//get the feed as a string data source
$xml = get_feed($feed);
preg_match_all("/\
(.+?)\<\/title\>/smi",$xml, $title);
preg_match_all("/\(.+?)\<\/description\>/smi",$xml, $description);
preg_match_all("/\(.+?)\<\/thumbnail_url\>/smi",$xml, $thumbnail);
array_shift($title);
array_shift($thumbnail);
array_shift($description);
// Replace html characters. More can be added but this seems to work for me across the board.
for($i=0;$i';
$description.= '';
$description.= '';
$description.= '';
$description.= " $summary";
}
///////////////////////////////////
// Embed a Google Video
///////////////////////////////////
else if(preg_match("/video.google.com/",$url)) {
if(preg_match("/docid=(.*)/",$url,$matches)) {
$doc_id = $matches[1];
} else {
return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER,__FILE__,__LINE__,
"Unable to extract doc id from url: $url"),null,null);
}
$link="$url";
$contents=file_get_contents($link);
preg_match('//i', $contents, $matches);
$summary=$matches[1];
preg_match('/(.+?)\s+- Google Video<\/title>/i', $contents, $matches);
$title=$matches[1];
preg_match('/ ';
$description.= '';
$description.= " $summary";
}
///////////////////////////
// Embed a remote .flv file
///////////////////////////
else if(preg_match("/.*\/(.+?)\.flv/i",$url,$matches)) {
$title = $matches[1];
$summary = $matches[1];
$thumbnail = 'http://www.pippins.net/images/flv_thumb.jpg';
if (empty($extraHeaders)) {
$extraHeaders = array('Referer' => str_replace('&', '&', $url));
}
list ($successfullyCopied, $response, $headers) =
GalleryCoreApi::fetchWebPage($url, $extraHeaders);
if (!$successfullyCopied) {
return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
"Unable to locate a video at url: $url"),null,null);
}
// External FLV player
if(!$use_internal_flv_player) {
if(!preg_match("/\w+/",$external_flv_player)) {
return array(GalleryCoreApi::error(ERROR_CONFIGURATION_REQUIRED,__FILE__,__LINE__,
"Invalid/missing external player parameter"),null,null);
}
$description =' ';
}
// Internal FLV player
else {
$description = ''."\n";
$description.= '
'."\n";
$description.= '
';
}
}
////////////////////////////
// Unsupported URL to embed
////////////////////////////
else {
return array(GalleryCoreApi::error(ERROR_UNSUPPORTED_FILE_TYPE,__FILE__,__LINE__,
"Unable to embed video from: $url"),null,null);
}
////////////////////////////
// Add the video to Gallery
////////////////////////////
// Get a local tmp file to save the thumbnail to
$tmpDir = $gallery->getConfig('data.gallery.tmp');
$tmpFile = $platform->tempnam($tmpDir, 'add');
$tmpFile.= ".jpg";
if($debug) {
print "thumbnail: $thumbnail ";
}
// Fetch the thumbnail and save it to a local file
if (empty($extraHeaders)) {
$extraHeaders = array('Referer' => str_replace('&', '&', $url));
}
list ($successfullyCopied, $response, $headers) =
GalleryCoreApi::fetchWebFile($thumbnail, $tmpFile, $extraHeaders);
if (!$successfullyCopied) {
return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
"Unable to copy thumbnail from url: $url"),null,null);
}
// Obtain the mimeType of the thumbnail
list ($ret, $mimeType) = GalleryCoreApi::getMimeType($tmpFile);
// Set the filename for the item we want to add
$fileName = $title;
$fileName = preg_replace("/\s+/","_",$fileName);
$fileName = preg_replace("/'/","",$fileName);
$fileName = preg_replace("/\"/","",$fileName);
$fileName = preg_replace("/\d+;/","",$fileName);
// DEBUG OUTPUT
if($debug) {
print "