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=81b5951486c1d97f4002c382bfdcbd0c8eef924e;hpb=4a4f36d3d395d88a19c33a457ec1daeec54cbeb8;p=embedvideo%2F.git
diff --git a/ItemAddEmbedVideo.inc b/ItemAddEmbedVideo.inc
index 81b5951..4e517ac 100644
--- a/ItemAddEmbedVideo.inc
+++ b/ItemAddEmbedVideo.inc
@@ -70,6 +70,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
global $debugOutput, $useInternalFlvPlayer, $youtubeDevId;
global $width, $height, $externalFlvPlayer, $externalFlvPlayerVars;
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
@@ -86,6 +87,9 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
$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");
/* Print our stored/set Parameters */
if(!strcmp($debugOutput,"true")) {
@@ -102,6 +106,9 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
print "flvThumbnail=$flvThumbnail
";
print "useRemoteSize=$useRemoteSize
";
print "autoStart=$autoStart
";
+ print "watermarkVideos=$watermarkVideos
";
+ print "watermarkImage=$watermarkImage
";
+ print "watermarkAlignment=$watermarkAlignment
";
print "
";
}
@@ -132,7 +139,8 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
/* 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 */
@@ -257,7 +265,8 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
}
/* Extract the summary from the webpage contents */
- preg_match('//i',
+ //print "contents: $contents
";
+ preg_match('//i',
$contents, $matches);
$summary=$matches[1];
@@ -624,6 +633,10 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
// Set the thumbnailHeight to the current thumbnailSize
// Set the thumbnailWidth to the appropriate size based on the thumbnailHeight * ratio
$image_data = @getimagesize($tmpFile);
+ if(!$image_data) {
+ return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
+ "Unable to retrieve thumbnail dimensions for: $tmpFile"),null,null);
+ }
$ratio = $image_data[0] / $image_data[1];
$debugString.="Using ratio from original thumbnail of $ratio. ";
$thumbnailHeight=$thumbnailSize;
@@ -638,6 +651,132 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
print "$debugString";
print "
";
}
+
+ /* Watermark the video thumbnail image if indicated by our parameter */
+ if(!strcmp($watermarkVideos,"true")) {
+
+ /*
+ * If no watermarkImage parameter is set, set it to a default value.
+ */
+ if(preg_match("/\w+/", $watermarkImage)) {
+ $watermarkImage = $watermarkImage;
+ } else {
+ $watermarkImage = $gallery2_url.$gallery2_video_watermark;
+ }
+
+ /* Get the watermark Image Extension */
+ preg_match('/\.(...)$/', $watermarkImage, $matches);
+ $watermarkExt=$matches[1];
+
+ /*
+ * Check to make sure the URL to the watermark image file is valid
+ * (That the file exists at the URL given). Skip this part if it is a local path.
+ */
+ if(!preg_match("/^\//", $watermarkImage)) {
+ list ($successfullyCopied, $response, $headers) =
+ $this->fetchWebFileHeaders($watermarkImage, $extraHeaders);
+ if (!$successfullyCopied) {
+ return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+ "Unable to find the watermark image at url: $watermarkImage - $response"),NULL,NULL);
+ }
+
+ /* Download the watermark image to a local file */
+ $tmpDir = $gallery->getConfig('data.gallery.tmp');
+ $watermark = $platform->tempnam($tmpDir, 'wmk_img_');
+ $watermark.= "." . $watermarkExt;
+ list ($successfullyCopied, $response, $headers) =
+ GalleryCoreApi::fetchWebFile($watermarkImage, $watermark, $extraHeaders);
+ if (!$successfullyCopied) {
+ return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
+ "Unable to copy watermark image from url: $watermarkImage - $response"),null,null);
+ }
+ } else {
+ $tmpDir = $gallery->getConfig('data.gallery.tmp');
+ $watermark = $platform->tempnam($tmpDir, 'wmk_img_');
+ $watermark.= "." . $watermarkExt;
+ if(!$platform->copy($watermarkImage, $watermark)) {
+ return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
+ "Unable to copy watermark image from path: $watermarkImage"),null,null);
+ }
+ }
+
+ /* See if there is a toolkit installed that can perform a composite operation */
+ list ($ret, $toolkit) = GalleryCoreApi::getToolkitByOperation($mimeType, 'composite');
+ if ($ret) {
+ return array($ret->wrap(__FILE__, __LINE__,
+ "Unable to locate a toolkit module to perform the 'composite' watermark operation"), null);
+ }
+
+ /* Make sure we can access the toolkit found */
+ if (!isset($toolkit)) {
+ return array(GalleryStatus::error(ERROR_PERMISSION_DENIED, __FILE__, __LINE__,
+ "Unable to access the toolkit module to perform the 'composite' watermark operation"), null);
+ }
+
+ /* Get the image dimensions of the thumbnail */
+ $image_data = @getimagesize($newTmpFile);
+ if(!$image_data) {
+ return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
+ "Unable to retrieve thumbnail dimensions for: $tmpFile"),null,null);
+ }
+ $thumbnailWidth = $image_data[0];
+ $thumbnailHeight = $image_data[1];
+
+ /* Get the image dimensions of the watermark */
+ $image_data = @getimagesize($watermark);
+ if(!$image_data) {
+ return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
+ "Unable to retrieve watermark dimensions for: $tmpFile"),null,null);
+ }
+ $watermarkWidth = $image_data[0];
+ $watermarkHeight = $image_data[1];
+
+ /* Obtain the mimeType of the watermark */
+ list ($ret, $watermarkMimeType) = GalleryCoreApi::getMimeType($watermark);
+
+ /* Remove the gallery base path from the watermark image path */
+ /* This has to be done to satisfy the argument requirement for the toolkit operation */
+ $dataDir = $gallery->getConfig('data.gallery.base');
+ $dataDir=preg_replace("/\//","\\/",$dataDir);
+ if(preg_match("/$dataDir(.*)/", $watermark, $matches)) {
+ $watermark = $matches[1];
+ }
+
+ /* General debug output */
+ if(!strcmp($debugOutput,"true")) {
+ print "Watermark Operation
";
+ print "watermarkImage: $watermarkImage
";
+ print "watermarkTmpImage: $watermark
";
+ print "watermarkMimeType: $watermarkMimeType
";
+ print "watermarkWidth: $watermarkWidth
";
+ print "watermarkHeight: $watermarkHeight
";
+ print "watermarkedWidth: $thumbnailWidth
";
+ print "watermarkedHeight: $thumbnailHeight
";
+ }
+
+ /* Apply the watermark image to the thumbnail */
+ $tmpFile = $platform->tempnam($tmpDir, 'wmk_');
+ list ($ret, $mimeType) = $toolkit->performOperation(
+ $mimeType, 'composite', $newTmpFile, $tmpFile,
+ array($watermark, $watermarkMimeType,
+ $watermarkWidth, $watermarkHeight,
+ $watermarkAlignment, 0, 0));
+
+ /* Check the return code of the composite operation */
+ if ($ret) {
+ return array($ret->wrap(__FILE__, __LINE__,
+ "Unable to apply watermark to the video thumbnail image"), null);
+ }
+
+ if(!strcmp($debugOutput,"true")) {
+ print "watermarked Image: $tmpFile
";
+ print "
";
+ }
+
+ /* Update the path of our thumbnail to point to the new watermarked thumbnail instead */
+ $newTmpFile = $tmpFile;
+
+ }
/* Make the gallery2 call to add this item to the album */
list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($newTmpFile,