+ /* Replace html characters. More can be added but this seems to work */
+ for($i=0;$i<count($description[0]);$i++){
+ $description[0][$i] = preg_replace("/</","<",$description[0][$i]);
+ $description[0][$i] = html_entity_decode($description[0][$i],ENT_QUOTES);
+ }
+
+ /* Store the information found in some local variables */
+ $title = $title[0][0];
+ $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";
+ }
+
+ /* Determine if the video should show related videos or not based on the youtubeShowRelated parameter */
+ $youtubeShowRelatedStr="";
+ if(!strcmp($youtubeShowRelated,"false")) {
+ $youtubeShowRelatedStr="&rel=0";
+ }
+
+ /* Format the description to hold a reference to the embedded video */
+ $description = '<object width="'.$width.'" height="'.$height.'">';
+ $description.= '<param name="movie" ';
+ $description.= 'value="http://www.youtube.com/v/'.$video_id.'"></param>';
+ $description.= '<param name="wmode" value="transparent"></param>';
+ $description.= '<embed src="http://www.youtube.com/v/';
+ $description.= $video_id.$autoStartStr.$youtubeShowRelatedStr;
+ $description.= '" type="application/x-shockwave-flash" wmode="transparent" ';
+ $description.= 'width="'.$width.'" height="'.$height.'"></embed></object>';
+ $description.= "<br>$summary";
+
+ /*
+ **********************************
+ * Embed a Google Video
+ **********************************
+ */
+ } else if(preg_match("/$googleUrlPattern/",$url)) {
+
+ /* Make sure we can extract a docID */
+ if(preg_match("/docid=(.*)/",$url,$matches)) {
+ $doc_id = $matches[1];
+ } else {
+ return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER,__FILE__,__LINE__,
+ "Unable to extract doc 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 */
+ //print "contents: $contents <br>";
+ preg_match('/<meta name="description" content="(.+?)\. \w+ \d+, \d+.*">/i',
+ $contents, $matches);
+ $summary=$matches[1];
+
+ /* Extract the title from the webpage contents */
+ $title="Unknown";
+ if(preg_match('/<title>(.+?)\s+- Google Video<\/title>/i', $contents, $matches)) {
+ $title=$matches[1];
+ } else if(preg_match('/<title>(.+?)<\/title>/i', $contents, $matches)) {
+ $title=$matches[1];
+ }
+
+ /* Extract the thumbnail URL from the webpage contents */
+ preg_match('/<img src="(http:\/\/video\.google\.com\/ThumbnailServer2.+?)" /i',
+ $contents, $matches);
+ $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 = '<embed ';
+ $description.= 'style="width:'.$width.'px; height:'.$height.'px;" id="VideoPlayback" ';
+ $description.= 'type="application/x-shockwave-flash" ';
+ $description.= 'src="'.$googlePlayer.'?docId='.$doc_id.$autoStartStr.'" flashvars=""> ';
+ $description.= '</embed>';
+ $description.= "<br>$summary";
+
+ /*
+ **********************************
+ * Embed a Yahoo Video
+ **********************************
+ * TODO: The autoStart parameter doesn't work with the yahoo video player
+ */
+ } else if(preg_match("/$yahooUrlPattern/",$url)) {
+
+ /* Make sure we can extract a vidID */
+ if(preg_match("/vid=(.*)/",$url,$matches)) {
+ $vid_id = $matches[1];
+ } else {
+ return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER,__FILE__,__LINE__,
+ "Unable to extract vid 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('/Description:<\/em><p>(.+?)<\/p>/', $contents, $matches);
+ $summary=$matches[1];
+
+ /* Extract the title from the webpage contents */
+ $title="Unknown";
+ if(preg_match('/<title>(.+?)\s+- Yahoo! Video<\/title>/i', $contents, $matches)) {
+ $title=$matches[1];
+ } else if(preg_match('/<title>(.+?)<\/title>/i', $contents, $matches)) {
+ $title=$matches[1];
+ }
+
+ /* Build the thumbnail URL from the vid_id */
+ $thumbnail=$yahooThumbnailUrl.$vid_id."_01";
+
+ /* Format the description to hold a reference to the embedded video */
+ preg_match('/(<embed src.+?<\/embed>)/', $contents, $matches);
+ $description=$matches[1];
+ if(!strcmp($useRemoteSize,"false")) {
+ $description=preg_replace("/width='\d+'/","width='".$width."'",$description);
+ $description=preg_replace("/height='\d+'/","height='".$height."'",$description);
+ }
+ $description.= "<br>$summary";
+
+ /*
+ **********************************
+ * Embed a MetaCafe Video
+ **********************************
+ */
+ } else if(preg_match("/$metacafeUrlPattern/",$url)) {
+
+ /* Make sure we can extract a itemID */
+ if(preg_match("/\/watch\/(.+?)\/(.+?)/",$url,$matches)) {
+ $item_id = $matches[1];
+ } 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('/<meta name="description" content="(.+?)" \/>/i', $contents, $matches);
+ $summary=$matches[1];
+
+ /* Extract the title from the webpage contents */
+ preg_match('/<title>(.+?)<\/title>/i', $contents, $matches);
+ $title=$matches[1];
+
+ /* Build the thumbnail URL from the item_id */
+ $thumbnail=$metacafeThumbnailUrl.$item_id.".jpg";
+
+ /* Format the description to hold a reference to the embedded video */
+ preg_match('/(embed src.+?\/embed)/', $contents, $matches);
+ $description="<".$matches[1];
+ $description=preg_replace("/"/","'",$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.= "</embed>";
+ $description.= "<br>$summary";
+
+
+ /*
+ **********************************
+ * Embed a remote .swf file
+ **********************************
+ */
+ } else if(preg_match("/.*\/(.+?)\.swf/i",$url,$matches)) {
+
+ /* Set the title and summary to the name of the file */
+ $title = $matches[1];
+ $summary = $matches[1];
+
+ /*
+ * Set the thumbnail to some generic jpg image,
+ * since we can't extract it from the remote swf file.
+ * If no parameter is set, set it to a default value.
+ */
+ if(preg_match("/\w+/", $flvThumbnail)) {
+ $thumbnail = $flvThumbnail;
+ } else {
+ $thumbnail = $gallery2_url.$gallery2_flv_thumbnail;
+ }
+
+ /*
+ * Check to make sure the URL to the remote swf 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
+ */
+
+ /* Format the description to hold a reference to the embedded video */
+ $description ='<embed src="'.$url.'">';
+
+ /*
+ **********************************
+ * Embed a remote .flv file
+ **********************************
+ */
+ } else if(preg_match("/.*\/(.+?)\.flv/i",$url,$matches)) {
+
+ /* Set the title and summary to the name of the file */
+ $title = $matches[1];
+ $summary = $matches[1];
+
+ /*
+ * Set the thumbnail to some generic jpg image,
+ * since we can't extract it from the remote flv file.
+ * If no parameter is set, set it to a default value.
+ */
+ if(preg_match("/\w+/", $flvThumbnail)) {
+ $thumbnail = $flvThumbnail;
+ } else {
+ $thumbnail = $gallery2_url.$gallery2_flv_thumbnail;
+ }
+
+ /*
+ * 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);
+ }