+ /* 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=false&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;
+ $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;
+ $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";
+
+ if($debugOutput) {
+ print "thumbnail: $thumbnail <br>";
+ }
+
+ /* Fetch the thumbnail and save it to a local file */
+ if (empty($extraHeaders)) {
+ $extraHeaders = array('Referer' => str_replace('&', '&', $url));
+ }
+ 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"),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($debugOutput) {
+ print "<p><a href=\"".$title."\" target=\"_blank\">";
+ print "<img src=\"".$thumbnail."\">\n</a>".$summary."</p>";
+ print "<p>$description</p>";
+ print "thumbnail: $tmpFile <br>";
+ print "mimeType: $mimeType <br>";
+ print "fileName: $fileName <br>";
+ }
+
+ /* Make the gallery2 call to add this item to the album */
+ list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($tmpFile,
+ $fileName,
+ $title,
+ $summary,
+ $description,
+ $mimeType,
+ $item->getId());
+
+ if ($ret) {
+ return array($ret, null, null);
+ }
+
+ $status['addedFiles'][] = array('fileName' => $url,
+ 'id' => $newItem->getId(),
+ 'warnings' => array());
+ }
+ @$platform->unlink($tmpFile);