+ /*
+ * Check to make sure the URL to the remote flv 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
+ * This reference will be embedded using the G2 internal player,
+ * or an external player if provided by the user.
+ */
+ if(!strcmp($useInternalFlvPlayer,"false")) {
+
+ /*
+ * The user has indicated they want to use an external flv player
+ * Make sure one is defined!
+ */
+ if(!preg_match("/\w+/",$externalFlvPlayer)) {
+ return array(GalleryCoreApi::error(ERROR_CONFIGURATION_REQUIRED,__FILE__,__LINE__,
+ "Invalid/missing external player parameter"),null,null);
+ }
+
+ /* Format the description to hold a reference to the embedded video */
+ $description ='<embed src="'.$externalFlvPlayer.'" ';
+ $description.= 'width="'.$width.'" height="'.$height.'" ';
+ $description.= 'bgcolor="#C0C0C0" allowfullscreen="true" ';
+ $description.= 'type="application/x-shockwave-flash" ';
+ $description.= 'pluginspage="http://www.macromedia.com/go/getflashplayer" ';
+ $description.= 'flashvars="file='.$url;
+ $description.= '&fullscreenpage='.$thumbnail;
+ $description.= '&linktarget=_Blank&image='.$thumbnail;
+
+ if(!preg_match("/\w+/",$externalFlvPlayerVars)) {
+ /* Format the flashvars for the internal G2 flv player */
+ $description.= '&showdigits=true&autostart='.$autoStart.'&showfsbutton=true&';
+ $description.= '&repeat=false&lightcolor=0x9999FF';
+ $description.= '&backcolor=0x888888&frontcolor=0x000000"';
+ } else {
+ /* Format the flashvars for the external G2 flv player */
+ $description.= '&'.$externalFlvPlayerVars;
+ }
+ $description.= ' /> </p>';
+
+ /* Internal FLV player */
+ } else {
+ /* Format the description to hold a reference to the embedded video */
+ $macromedia_url = "http://download.macromedia.com/pub/shockwave/cabs/flash/";
+ $description = '<script type="text/javascript">'."\n";
+ $description.= '// <![CDATA['."\n";
+ $description.= 'function divResize(id, nw, nh) {'."\n";
+ $description.= 'var obj = document.getElementById(id);'."\n";
+ $description.= 'obj.style.width = nw + "px";'."\n";
+ $description.= 'obj.style.height = nh + "px";'."\n";
+ $description.= '}'."\n";
+ $description.= '// ]]>'."\n";
+ $description.= '</script>'."\n";
+ $description.= '<div id="flashvideo" style="align:left;width:525px;height:392px">'."\n";
+ $description.= '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000"';
+ $description.= 'codebase="'.$macromedia_url.'swflash.cab#version=8,0,0,0"';
+ $description.= 'width="100%" height="100%" id="IFid1" class="ImageFrame_image">';
+ $description.= '<param name="movie" value="'.$gallery2_url.$gallery2_flv_player.'"/>';
+ $description.= '<param name="FlashVars" value="flvUrl='.$url;
+ $description.= '&Width='.$width.'&Height='.$height.'&title='.$title;
+ $description.= '&allowDl=true&thumbUrl='.$thumbnail.'&autoStart='.$autoStart;
+ $description.= '&langDownload=Download&langLarge=Large&langNormal=Normal"/>';
+ $description.= '<param name="quality" value="high"/>';
+ $description.= '<param name="scale" value="noscale"/>';
+ $description.= '<param name="salign" value="lt"/>';
+ $description.= '<param name="wmode" value="transparent"/>';
+ $description.= '<param name="allowScriptAccess" value="always"/>';
+ $description.= '<embed src="'.$gallery2_url.$gallery2_flv_player.'" ';
+ $description.= 'flashvars="flvUrl='.$url;
+ $description.= '&Width='.$width.'&Height='.$height.'&title='.$title;
+ $description.= '&allowDl=true&thumbUrl='.$thumbnail.'&autoStart='.$autoStart;
+ $description.= '&langDownload=Download&langLarge=Large&langNormal=Normal" ';
+ $description.= 'type="application/x-shockwave-flash" ';
+ $description.= 'width="100%" height="100%" quality="high" scale="noscale" salign="lt" ';
+ $description.= 'wmode="transparent" allowScriptAccess="always" ';
+ $description.= 'pluginspage="http://www.macromedia.com/go/getflashplayer"/>';
+ $description.= '</object></div>';
+ }
+
+ /*
+ **********************************
+ * 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 URL to */
+ $tmpDir = $gallery->getConfig('data.gallery.tmp');
+ $tmpFile = $platform->tempnam($tmpDir, 'add');
+ $tmpFile.= ".jpg";
+
+ /* 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: $thumbnail - $response"),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);
+
+ /* General debug output */
+ if(!strcmp($debugOutput,"true")) {
+ print "<h2>Item Parameters</h2>";
+ print "url: $url <br>";
+ print "title: $title <br>";
+ print "thumbnailUrl: <img src=\"".$thumbnail."\">\n</a>".$summary."</p>";
+ print "description: <p>$description</p>";
+ print "thumbnail: $tmpFile <br>";
+ print "mimeType: $mimeType <br>";
+ print "fileName: $fileName <br>";
+ print "width: $width <br>";
+ print "height: $height <br>";
+ print "<hr>";
+ }
+
+ /* 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. <br>";
+ 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 <br>";
+ break;
+ }
+ }
+ }
+ $debugString.="Resizing thumbnail image to $thumbnailSize: $tmpFile -> $newTmpFile <br>";
+ $toolkit->performOperation($mimeType, 'resize', $tmpFile, $newTmpFile,
+ array($thumbnailSize,$thumbnailSize));
+ }
+ }
+ if(!strcmp($debugOutput,"true")) {
+ print "<h2>Thumbnail Resize</h2>";
+ print "$debugString";
+ print "<hr>";
+ }
+
+ /* Make the gallery2 call to add this item to the album */
+ list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($newTmpFile,
+ $fileName,
+ $title,
+ $summary,
+ $description,
+ $mimeType,
+ $item->getId());
+
+ if ($ret) {
+ return array($ret, null, null);
+ }
+
+ $status['addedFiles'][] = array('fileName' => $url,
+ 'id' => $newItem->getId(),
+ 'warnings' => array());
+
+ if(!strcmp($debugOutput,"true")) {
+ print "<br><br><h2>Video Successfully Added to your Gallery Album</h2><br><br><hr>";
+ }
+ }
+
+ /* Keep the tmpfiles around if we are in debug mode. Otherwise, remove them. */
+ if(!strcmp($debugOutput,"false")) {
+ @$platform->unlink($tmpFile);
+ @$platform->unlink($newTmpFile);
+ }
+