(.+?)<\/div>/i', $contents, $matches);
+ $summary=$matches[1];
+
+ /* Extract the title from the webpage contents */
+ preg_match('/
/i', $contents, $matches);
+ $title=htmlentities($matches[1], ENT_QUOTES, "UTF-8");
+
+ /* Build the thumbnail URL from the item_id */
+ $thumbnail=$dailymotionThumbnailUrl.$item_id;
+
+ /* Format the description to hold a reference to the embedded video */
+ if(preg_match('/Embeddable Player:.+?value="(.+?)"/', $contents, $matches)) {
+ $description=$matches[1];
+ $description=preg_replace("/"/","'",$description);
+ $description=preg_replace("/</","<",$description);
+ $description=preg_replace("/>/",">",$description);
+ if(!strcmp($useRemoteSize,"false")) {
+ $description=preg_replace("/width=\"\d+\"/","width=\"".$width."\"",$description);
+ $description=preg_replace("/height=\"\d+\"/","height=\"".$height."\"",$description);
+ }
+ } else {
+ return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+ "Unable to extract embedded video information from url: $url"),NULL,NULL);
+ }
+
+ /*
+ **********************************
+ * Embed a DivShare Video
+ **********************************
+ */
+ } else if(preg_match("/$divshareUrlPattern/",$url)) {
+
+ /* Make sure we can extract a itemID */
+ if(preg_match("/\/download\/(.+)/",$url,$matches)) {
+ $item_id = $matches[1];
+ $item_id=preg_replace("/\/$/","",$item_id);
+ } else {
+ return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER,__FILE__,__LINE__,
+ "Unable to extract item 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('/
/i', $contents, $matches);
+ //$summary=$matches[1];
+ // Right now, the description is a plug for divshare, nothing user specific about it
+ $summary="";
+
+ /* Extract the title from the webpage contents */
+ preg_match('/
(.+?) - Divshare<\/title>/i', $contents, $matches);
+ $title=$matches[1];
+
+ /* Build the thumbnail URL from the item_id */
+ $thumbnail=$divshareThumbnailUrl.$item_id;
+
+ /* Format the description to hold a reference to the embedded video */
+ if(preg_match('/(";
- $description.= "
$summary";
+ /* Extract the summary from the webpage contents */
+ preg_match('/class="description" id="vid_description">(.+?)<\/div>/i', $contents, $matches);
+ $summary=$matches[1];
+
+ /* Extract the title from the webpage contents */
+ preg_match('/(.+?)<\/h1>/i', $contents, $matches);
+ $title=$matches[1];
+
+ /* Build the thumbnail URL from the item_id */
+ $video_info_url=$myspaceThumbnailUrl.$video_id;
+ list ($successfullyCopied, $video_info, $response, $headers) =
+ GalleryCoreApi::fetchWebPage($video_info_url, $extraHeaders);
+ if (!$successfullyCopied) {
+ return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+ "Unable to get video information at url: $url - $response"),NULL,NULL);
+ }
+ if(preg_match('/thumbnail url="(.+?)"/',$video_info, $matches)) {
+ $thumbnail = $matches[1];
+ } else {
+ return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+ "Unable to extract thumbnail information from url: $url"),NULL,NULL);
+ }
- /*
+ /* Format the description to hold a reference to the embedded video */
+ if(preg_match('/(<embed src.+?\/embed>)/', $contents, $matches)) {
+ $description=$matches[1];
+ $description=preg_replace("/"/","'",$description);
+ $description=preg_replace("/</","<",$description);
+ $description=preg_replace("/>/",">",$description);
+ if(!strcmp($useRemoteSize,"false")) {
+ $description=preg_replace("/width='\d+'/","width='".$width."'",$description);
+ $description=preg_replace("/height='\d+'/","height='".$height."'",$description);
+ }
+ } else {
+ return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+ "Unable to extract embedded video information from url: $url"),NULL,NULL);
+ }
+
+ /*
**********************************
* Embed a remote .swf file
**********************************
@@ -587,19 +950,34 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
$fileName = preg_replace("/'/","",$fileName);
$fileName = preg_replace("/\"/","",$fileName);
$fileName = preg_replace("/\d+;/","",$fileName);
+
+ /* Wordwrap the description or summary as appropriate */
+ $description_summary = $summary;
+
+ if(strcmp($wordwrapSummary,"0")) {
+ $summary = wordwrap($summary,$wordwrapSummary,"
",FALSE);
+ }
+
+ if(strcmp($wordwrapDescription,"0")) {
+ $description_summary = wordwrap($description_summary,$wordwrapDescription,"
",FALSE);
+ }
+
+ /* Tack on the summary to the end of the description */
+ $description.= "
$description_summary";
/* General debug output */
if(!strcmp($debugOutput,"true")) {
- print "Item Parameters
";
- print "url: $url
";
- print "title: $title
";
- print "thumbnailUrl:
\n".$summary."";
- print "description:
$description
";
- print "thumbnail: $tmpFile
";
- print "mimeType: $mimeType
";
- print "fileName: $fileName
";
- print "width: $width
";
- print "height: $height
";
+ print "\nItem Parameters
\n";
+ print "url: $url
\n";
+ print "title: $title
\n";
+ print "thumbnailUrl: $thumbnail
\n";
+ print "summary: $summary
\n";
+ print "description: $description
\n";
+ print "thumbnail: $tmpFile
\n";
+ print "mimeType: $mimeType
\n";
+ print "fileName: $fileName
\n";
+ print "width: $width
\n";
+ print "height: $height
\n";
print "
";
}
@@ -645,9 +1023,9 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
}
}
if(!strcmp($debugOutput,"true")) {
- print "Thumbnail Resize
";
- print "$debugString";
- print "
";
+ print "\nThumbnail Resize
\n";
+ print "$debugString\n";
+ print "
\n";
}
/* Watermark the video thumbnail image if indicated by our parameter */
@@ -661,31 +1039,41 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
} 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)
+ * (That the file exists at the URL given). Skip this part if it is a local path.
*/
- 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);
- }
+ 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);
+ /* 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 */
@@ -726,19 +1114,20 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
/* This has to be done to satisfy the argument requirement for the toolkit operation */
$dataDir = $gallery->getConfig('data.gallery.base');
$dataDir=preg_replace("/\//","\\/",$dataDir);
- preg_match("/$dataDir(.*)/", $watermark, $matches);
- $watermark = $matches[1];
+ 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
";
+ print "\nWatermark Operation
\n";
+ print "watermarkImage: $watermarkImage
\n";
+ print "watermarkTmpImage: $watermark
\n";
+ print "watermarkMimeType: $watermarkMimeType
\n";
+ print "watermarkWidth: $watermarkWidth
\n";
+ print "watermarkHeight: $watermarkHeight
\n";
+ print "watermarkedWidth: $thumbnailWidth
\n";
+ print "watermarkedHeight: $thumbnailHeight
\n";
}
/* Apply the watermark image to the thumbnail */
@@ -747,7 +1136,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
$mimeType, 'composite', $newTmpFile, $tmpFile,
array($watermark, $watermarkMimeType,
$watermarkWidth, $watermarkHeight,
- 'bottom-left', 0, 0));
+ $watermarkAlignment, 0, 0));
/* Check the return code of the composite operation */
if ($ret) {
@@ -756,7 +1145,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
}
if(!strcmp($debugOutput,"true")) {
- print "watermarked Image: $tmpFile
";
+ print "\nwatermarked Image: $tmpFile
";
print "
";
}
@@ -783,7 +1172,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
'warnings' => array());
if(!strcmp($debugOutput,"true")) {
- print "
Video Successfully Added to your Gallery Album
";
+ print "\n
Video Successfully Added to your Gallery Album
";
}
}
@@ -824,7 +1213,8 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
global $gallery;
$requestMethod='GET';
-
+ $requestBody='';
+
/* Convert illegal characters */
$url = str_replace(' ', '%20', $url);