X-Git-Url: http://git.pippins.net/embedvideo/.git/%27%20%20%20%20.%20%24GLOBALS%5B%27phpgw%27%5D-%3Elink%28%27inc/jquery/jquery.tablesorter.css%27%29.%27?a=blobdiff_plain;f=ItemAddEmbedVideo.inc;h=4e517acb19a0214542a31360beb9b4d74f835ed1;hb=5e1dae2697864b504a086c160a605cfc8a45b9fa;hp=7b79cc28c737b462202c1aa0db93e46de9a9e355;hpb=cb157a9d59eba1eca436730afe1b17b0703d1e38;p=embedvideo%2F.git
diff --git a/ItemAddEmbedVideo.inc b/ItemAddEmbedVideo.inc
index 7b79cc2..4e517ac 100644
--- a/ItemAddEmbedVideo.inc
+++ b/ItemAddEmbedVideo.inc
@@ -18,6 +18,9 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
+GalleryCoreApi::requireOnce('modules/gd/classes/GdToolkitHelper.class');
+
+
/**
* This plugin will handle the addition of embedded video objects
* @package embedVideo
@@ -66,27 +69,78 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
/* Store any Parameters into some simpler, shorter, local variables */
global $debugOutput, $useInternalFlvPlayer, $youtubeDevId;
global $width, $height, $externalFlvPlayer, $externalFlvPlayerVars;
- global $flvThumbnail;
+ global $flvThumbnail, $useRemoteSize, $autoStart;
+ global $watermarkVideos, $watermarkImage, $watermarkAlignment;
+
+ /* Find out what value our parameters should have by looking to see if they
+ * are defined in our overrides section or default section. If they are not
+ * defined in either of these 2 places, pass in a default value to set them to
+ */
+ $debugOutput = $this->getParameter($ItemAddEmbedVideo, 'debugOutput', "false");
+ $useInternalFlvPlayer = $this->getParameter($ItemAddEmbedVideo, 'useInternalFlvPlayer', "true");
+ $youtubeDevId = $this->getParameter($ItemAddEmbedVideo, 'youtubeDevId', "");
+ $youtubeShowRelated = $this->getParameter($ItemAddEmbedVideo, 'youtubeShowRelated', "false");
+ $width = $this->getParameter($ItemAddEmbedVideo, 'width', "320");
+ $height = $this->getParameter($ItemAddEmbedVideo, 'height', "240");
+ $externalFlvPlayer = $this->getParameter($ItemAddEmbedVideo, 'externalFlvPlayer', "");
+ $externalFlvPlayerVars = $this->getParameter($ItemAddEmbedVideo, 'externalFlvPlayerVars', "");
+ $flvThumbnail = $this->getParameter($ItemAddEmbedVideo, 'flvThumbnail', "");
+ $useRemoteSize = $this->getParameter($ItemAddEmbedVideo, 'useRemoteSize', "false");
+ $autoStart = $this->getParameter($ItemAddEmbedVideo, 'autoStart', "false");
+ $watermarkImage = $this->getParameter($ItemAddEmbedVideo, 'watermarkImage', "");
+ $watermarkVideos = $this->getParameter($ItemAddEmbedVideo, 'watermarkVideos', "false");
+ $watermarkAlignment = $this->getParameter($ItemAddEmbedVideo, 'watermarkAlignment', "center");
- $debugOutput = $this->getParameter($ItemAddEmbedVideo, 'debugOutput');
- $useInternalFlvPlayer = $this->getParameter($ItemAddEmbedVideo, 'useInternalFlvPlayer');
- $youtubeDevId = $this->getParameter($ItemAddEmbedVideo, 'youtubeDevId');
- $width = $this->getParameter($ItemAddEmbedVideo, 'width');
- $height = $this->getParameter($ItemAddEmbedVideo, 'height');
- $externalFlvPlayer = $this->getParameter($ItemAddEmbedVideo, 'externalFlvPlayer');
- $externalFlvPlayerVars = $this->getParameter($ItemAddEmbedVideo, 'externalFlvPlayerVars');
- $flvThumbnail = $this->getParameter($ItemAddEmbedVideo, 'flvThumbnail');
+ /* Print our stored/set Parameters */
+ if(!strcmp($debugOutput,"true")) {
+ print "
";
+ print "
Variable Parameters
";
+ print "debugOutput=$debugOutput ";
+ print "useInternalFlvPlayer=$useInternalFlvPlayer ";
+ print "youtubeDevId=$youtubeDevId ";
+ print "youtubeShowRelated=$youtubeShowRelated ";
+ print "width=$width ";
+ print "height=$height ";
+ print "externalFlvPlayer=$externalFlvPlayer ";
+ print "externalFlvPlayerVars=$externalFlvPlayerVars ";
+ print "flvThumbnail=$flvThumbnail ";
+ print "useRemoteSize=$useRemoteSize ";
+ print "autoStart=$autoStart ";
+ print "watermarkVideos=$watermarkVideos ";
+ print "watermarkImage=$watermarkImage ";
+ print "watermarkAlignment=$watermarkAlignment ";
+ print "";
+ }
/* Store other string constants we'll use later */
+
+ /* youtube */
$youtubeUrlPattern="youtube.com";
$youtubeApiUrl="http://www.youtube.com/api2_rest";
+ /* We can't extract the server size from youtube */
+ $youtubeWidth="425";
+ $youtubeHeight="350";
+
+ /* google */
$googleUrlPattern="video.google.com";
$googlePlayer="http://video.google.com/googleplayer.swf";
+ /* We can't extract the server size from google video */
+ $googleWidth="400";
+ $googleHeight="326";
+
+ /* yahoo */
+ $yahooUrlPattern="video.yahoo.com";
+ $yahooThumbnailUrl="http://thmg01.video.search.yahoo.com/image/";
+
+ /* metacafe */
+ $metacafeUrlPattern="metacafe.com";
+ $metacafeThumbnailUrl="http://www.metacafe.com/thumb/";
/* Gallery2 specific paths and variables */
$urlGenerator =& $gallery->getUrlGenerator();
$gallery2_url = $urlGenerator->getCurrentUrlDir();
- $gallery2_flv_thumbnail = "modules/thumbnail/images/G2video.jpg";
+ $gallery2_flv_thumbnail = "modules/embedvideo/images/G2video_thumbnail.jpg";
+ $gallery2_video_watermark = "modules/embedvideo/images/G2video_watermark1.png";
$gallery2_flv_player = "modules/flashvideo/lib/G2flv.swf";
/* Store the passed URL in a shorter local variable */
@@ -123,12 +177,19 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
GalleryCoreApi::fetchWebPage($feed, $extraHeaders);
if (!$successfullyCopied) {
return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
- "Unable to get video information at url: $url"),null,null);
+ "Unable to get video information at url: $url - $response"),null,null);
}
-
+ if(preg_match("/This video is private/",$xml)) {
+ return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER,__FILE__,__LINE__,
+ "Unable to retrieve video information from youtube.".
+ "You cannot embed a private youtube video: $url"),null,null);
+ }
+
if(!strcmp($debugOutput,"true")) {
+ print "
Youtube XML Dump
";
print "$xml";
+ print "";
}
/* Extract certain information from the xml feed */
@@ -151,13 +212,32 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
$summary = $description[0][0];
$thumbnail = $thumbnail[0][0];
+ /* Determine what our width and height should be based on our useRemoteSize parameter */
+ if(!strcmp($useRemoteSize,"true")) {
+ $width = $youtubeWidth;
+ $height = $youtubeHeight;
+ }
+
+ /* Determine if the video should autoplay or not based on the autoStart parameter */
+ $autoStartStr="";
+ if(!strcmp($autoStart,"true")) {
+ $autoStartStr="&autoplay=1";
+ }
+
+ /* Determine if the video should show related videos or not based on the youtubeShowRelated parameter */
+ $youtubeShowRelatedStr="";
+ if(!strcmp($youtubeShowRelated,"false")) {
+ $youtubeShowRelatedStr="&rel=0";
+ }
+
/* Format the description to hold a reference to the embedded video */
$description = '';
$description.= " $summary";
@@ -181,18 +261,22 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
GalleryCoreApi::fetchWebPage($url, $extraHeaders);
if (!$successfullyCopied) {
return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
- "Unable to get video information at url: $url"),null,null);
+ "Unable to get video information at url: $url - $response"),NULL,NULL);
}
/* Extract the summary from the webpage contents */
- preg_match('//i',
+ //print "contents: $contents ";
+ preg_match('//i',
$contents, $matches);
$summary=$matches[1];
/* Extract the title from the webpage contents */
- preg_match('/(.+?)\s+- Google Video<\/title>/i',
- $contents, $matches);
- $title=$matches[1];
+ $title="Unknown";
+ if(preg_match('/(.+?)\s+- Google Video<\/title>/i', $contents, $matches)) {
+ $title=$matches[1];
+ } else if(preg_match('/(.+?)<\/title>/i', $contents, $matches)) {
+ $title=$matches[1];
+ }
/* Extract the thumbnail URL from the webpage contents */
preg_match('/ ';
+ $description.= 'src="'.$googlePlayer.'?docId='.$doc_id.$autoStartStr.'" flashvars=""> ';
$description.= '';
$description.= " $summary";
-
+
+ /*
+ **********************************
+ * Embed a Yahoo Video
+ **********************************
+ * TODO: The autoStart parameter doesn't work with the yahoo video player
+ */
+ } else if(preg_match("/$yahooUrlPattern/",$url)) {
+
+ /* Make sure we can extract a vidID */
+ if(preg_match("/vid=(.*)/",$url,$matches)) {
+ $vid_id = $matches[1];
+ } else {
+ return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER,__FILE__,__LINE__,
+ "Unable to extract vid id from url: $url"),null,null);
+ }
+
+ /* Grab the contents of the webpage used to display the video on video.google.com */
+ list ($successfullyCopied, $contents, $response, $headers) =
+ GalleryCoreApi::fetchWebPage($url, $extraHeaders);
+ if (!$successfullyCopied) {
+ return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+ "Unable to get video information at url: $url - $response"),NULL,NULL);
+ }
+
+ /* Extract the summary from the webpage contents */
+ preg_match('/Description:<\/em>
(.+?)<\/p>/', $contents, $matches);
+ $summary=$matches[1];
+
+ /* Extract the title from the webpage contents */
+ $title="Unknown";
+ if(preg_match('/
(.+?)\s+- Yahoo! Video<\/title>/i', $contents, $matches)) {
+ $title=$matches[1];
+ } else if(preg_match('/(.+?)<\/title>/i', $contents, $matches)) {
+ $title=$matches[1];
+ }
+
+ /* Build the thumbnail URL from the vid_id */
+ $thumbnail=$yahooThumbnailUrl.$vid_id."_01";
+
+ /* Format the description to hold a reference to the embedded video */
+ preg_match('/(";
+ $description.= " $summary";
+
+
+ /*
+ **********************************
+ * Embed a remote .swf file
+ **********************************
+ */
+ } else if(preg_match("/.*\/(.+?)\.swf/i",$url,$matches)) {
+
+ /* Set the title and summary to the name of the file */
+ $title = $matches[1];
+ $summary = $matches[1];
+
+ /*
+ * Set the thumbnail to some generic jpg image,
+ * since we can't extract it from the remote swf file.
+ * If no parameter is set, set it to a default value.
+ */
+ if(preg_match("/\w+/", $flvThumbnail)) {
+ $thumbnail = $flvThumbnail;
+ } else {
+ $thumbnail = $gallery2_url.$gallery2_flv_thumbnail;
+ }
+
+ /*
+ * Check to make sure the URL to the remote swf file is valid
+ * (That the file exists at the URL given)
+ */
+ list ($successfullyCopied, $response, $headers) =
+ $this->fetchWebFileHeaders($url, $extraHeaders);
+ if (!$successfullyCopied) {
+ return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+ "Unable to find the video at url: $url - $response"),NULL,NULL);
+ }
+
+ /*
+ * Format the description to hold a reference to the embedded video
+ */
+
+ /* Format the description to hold a reference to the embedded video */
+ $description ='