X-Git-Url: http://git.pippins.net/embedvideo/.git/static/gitweb.js?a=blobdiff_plain;f=ItemAddEmbedVideo.inc;h=983ec79d041f82e00dcbb2c4968928f06d7ade98;hb=26f4eaa28c1a947b5e1f8f58f1cd653596e2253d;hp=e5eecd1552acde47caac0a76b47401ee4c5086a8;hpb=f61667e91c20c89758911f384ec30ff9f92c49e1;p=embedvideo%2F.git diff --git a/ItemAddEmbedVideo.inc b/ItemAddEmbedVideo.inc index e5eecd1..983ec79 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,56 @@ 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; - $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'); + /* 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', ""); + $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"); + + /* Print our stored/set Parameters */ + if(!strcmp($debugOutput,"true")) { + print "
"; + print "

Variable Parameters

"; + print "debugOutput=$debugOutput
"; + print "useInternalFlvPlayer=$useInternalFlvPlayer
"; + print "youtubeDevId=$youtubeDevId
"; + print "width=$width
"; + print "height=$height
"; + print "externalFlvPlayer=$externalFlvPlayer
"; + print "externalFlvPlayerVars=$externalFlvPlayerVars
"; + print "flvThumbnail=$flvThumbnail
"; + print "useRemoteSize=$useRemoteSize
"; + print "autoStart=$autoStart
"; + 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/"; @@ -138,9 +170,10 @@ class ItemAddEmbedVideo extends ItemAddPlugin { "Unable to get video information at url: $url - $response"),null,null); } - if(!strcmp($debugOutput,"true")) { + print "

Youtube XML Dump

"; print "$xml"; + print "
"; } /* Extract certain information from the xml feed */ @@ -163,12 +196,24 @@ 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"; + } + /* Format the description to hold a reference to the embedded video */ $description = ''; $description.= ''; $description.= ''; - $description.= ''; $description.= "
$summary"; @@ -215,11 +260,23 @@ class ItemAddEmbedVideo extends ItemAddPlugin { $thumbnail=$matches[1]; $thumbnail=preg_replace("/offsetms=0/","offsetms=0",$thumbnail); + /* Determine what our width and height should be based on our useRemoteSize parameter */ + if(!strcmp($useRemoteSize,"true")) { + $width = $googleWidth; + $height = $googleHeight; + } + + /* Determine if the video should autoplay or not based on the autoStart parameter */ + $autoStartStr=""; + if(!strcmp($autoStart,"true")) { + $autoStartStr="&autoplay=1"; + } + /* Format the description to hold a reference to the embedded video */ - $description = ' '; + $description.= 'src="'.$googlePlayer.'?docId='.$doc_id.$autoStartStr.'" flashvars=""> '; $description.= ''; $description.= "
$summary"; @@ -227,6 +284,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin { ********************************** * Embed a Yahoo Video ********************************** + * TODO: The autoStart parameter doesn't work with the yahoo video player */ } else if(preg_match("/$yahooUrlPattern/",$url)) { @@ -264,8 +322,10 @@ class ItemAddEmbedVideo extends ItemAddPlugin { /* Format the description to hold a reference to the embedded video */ preg_match('/()/', $contents, $matches); $description=$matches[1]; - $description=preg_replace("/width='\d+'/","width='".$width."'",$description); - $description=preg_replace("/height='\d+'/","height='".$height."'",$description); + if(!strcmp($useRemoteSize,"false")) { + $description=preg_replace("/width='\d+'/","width='".$width."'",$description); + $description=preg_replace("/height='\d+'/","height='".$height."'",$description); + } $description.= "
$summary"; /* @@ -306,8 +366,13 @@ class ItemAddEmbedVideo extends ItemAddPlugin { preg_match('/(embed src.+?\/embed)/', $contents, $matches); $description="<".$matches[1]; $description=preg_replace("/"/","'",$description); - $description=preg_replace("/width='\d+'/","width='".$width."'",$description); - $description=preg_replace("/height='\d+'/","height='".$height."'",$description); + if(!strcmp($useRemoteSize,"false")) { + $description=preg_replace("/width='\d+'/","width='".$width."'",$description); + $description=preg_replace("/height='\d+'/","height='".$height."'",$description); + } + if(!strcmp($autoStart,"true")) { + $description=preg_replace("/\.swf/",".swf?playerVars=autoPlay=yes",$description); + } $description.= ""; $description.= "
$summary"; @@ -372,7 +437,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin { if(!preg_match("/\w+/",$externalFlvPlayerVars)) { /* Format the flashvars for the internal G2 flv player */ - $description.= '&showdigits=true&autostart=false&showfsbutton=true&'; + $description.= '&showdigits=true&autostart='.$autoStart.'&showfsbutton=true&'; $description.= '&repeat=false&lightcolor=0x9999FF'; $description.= '&backcolor=0x888888&frontcolor=0x000000"'; } else { @@ -401,7 +466,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin { $description.= ''; $description.= ''; $description.= ''; $description.= ''; @@ -411,7 +476,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin { $description.= 'getConfig('data.gallery.tmp'); $tmpFile = $platform->tempnam($tmpDir, 'add'); $tmpFile.= ".jpg"; - - if(!strcmp($debugOutput,"true")) { - print "thumbnail: $thumbnail
"; - } - + /* Fetch the thumbnail and save it to a local file */ 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 - $response"),null,null); + "Unable to copy thumbnail from url: $thumbnail - $response"),null,null); } /* Obtain the mimeType of the thumbnail */ @@ -466,18 +527,53 @@ class ItemAddEmbedVideo extends ItemAddPlugin { /* General debug output */ if(!strcmp($debugOutput,"true")) { + print "

Item Parameters

"; + print "url: $url
"; print "title: $title
"; - print "

"; - print "\n".$summary."

"; - print "

$description

"; + print "thumbnailUrl: \n".$summary."

"; + print "description:

$description

"; print "thumbnail: $tmpFile
"; print "mimeType: $mimeType
"; print "fileName: $fileName
"; - print "

Video Successfully Added to your Gallery Album

"; + print "width: $width
"; + print "height: $height
"; + print "
"; } + /* Resize the thumbnail image to the size indicated by our album */ + $debugString=""; + list ($ret, $toolkit) = GalleryCoreApi::getToolkitByOperation($mimeType, 'resize'); + if (!$ret) { + $debugString.="Checking to see if a toolkit that can resize images was found.
"; + if (isset($toolkit)) { + $newTmpFile = $platform->tempnam($tmpDir, 'add'); + $newTmpFile.= ".jpg"; + $thumbnailSize = 150; + list ($ret, $preferences) = + GalleryCoreApi::fetchDerivativePreferencesForItem($item->getId()); + if(!$ret) { + foreach ($preferences as $preference) { + if (preg_match('/thumbnail\|(\d+)/', + $preference['derivativeOperations'], $matches)) { + $thumbnailSize = $matches[1]; + $debugString.="Found thumbnail size in album preferences: $thumbnailSize
"; + break; + } + } + } + $debugString.="Resizing thumbnail image to $thumbnailSize: $tmpFile -> $newTmpFile
"; + $toolkit->performOperation($mimeType, 'resize', $tmpFile, $newTmpFile, + array($thumbnailSize,$thumbnailSize)); + } + } + if(!strcmp($debugOutput,"true")) { + print "

Thumbnail Resize

"; + print "$debugString"; + print "
"; + } + /* Make the gallery2 call to add this item to the album */ - list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($tmpFile, + list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($newTmpFile, $fileName, $title, $summary, @@ -492,8 +588,18 @@ class ItemAddEmbedVideo extends ItemAddPlugin { $status['addedFiles'][] = array('fileName' => $url, 'id' => $newItem->getId(), 'warnings' => array()); + + if(!strcmp($debugOutput,"true")) { + print "

Video Successfully Added to your Gallery Album




"; + } } - @$platform->unlink($tmpFile); + + /* Keep the tmpfiles around if we are in debug mode. Otherwise, remove them. */ + if(!strcmp($debugOutput,"false")) { + @$platform->unlink($tmpFile); + @$platform->unlink($newTmpFile); + } + } return array(null, $error, $status); @@ -501,19 +607,25 @@ class ItemAddEmbedVideo extends ItemAddPlugin { /** * A simple function to resolve the value of a parameter from - * the default or override value if it exists. + * the default or override value if it exists, or set it + * to the default passed as an argument. */ - function getParameter($params, $name) { + function getParameter($params, $name, $default="") { if(isset($params['override'][$name])) { + /* print "override $name = ".$params['override'][$name]."
"; */ return($params['override'][$name]); - } else { + } else if(isset($params['default'][$name])) { + /* print "default $name = ".$params['default'][$name] ."
"; */ return($params['default'][$name]); + } else { + /* print "$name = $default
"; */ + return($default); } } /** * A simple function to get the headers only (no body) for a given URL - * + * This was taken from GalleryCoreApi::requestWebPage */ function fetchWebFileHeaders($url, $requestHeaders=array()) { global $gallery;