###############################################################################
# MediaCenter.pl                                                              #
###############################################################################
# YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.2                                                    #
# Packaged:       November 8, 2007                                            #
# Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== #
# Copyright (c) 2000-2007 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            #
#               Your source for web hosting, web design, and domains.         #
###############################################################################

$mediacenterplver = 'YaBB 2.2 $Revision: 1.19 $';
if ($action eq 'detailedversion') { return 1; }

sub embed {
	if($guest_media_disallowed && $iamguest){
		if ($enable_ubbc) {
			$video = qq~[yyoops]~;
		} else {			
			$video = qq~$maintxt{'40'}&nbsp;&nbsp;~;
			$video .= qq~$maintxt{'41'} <a href="$scripturl?action=login">$img{'login'}</a>~;
			if (!$regdisable) { $video .= qq~ $maintxt{'42'} <a href="$scripturl?action=register">$img{'register'}</a> !!~; }
		}
	} else {
		if (!$player_version){$player_version = 6;}
		my ($media_url,$play_pars) = @_;
		if ($media_url !~ m/^http:\/\//){ $media_url = "media://" + $media_url; } else { $media_url =~s~http:~media:~g; }
		&ToHTML($media_url);	## convert url to html
		## file extensions that open windows media player for video
		if ($media_url =~ m/.wmv$/i || $media_url =~ m/.wpl$/i || $media_url =~ m/.asf$/i || $media_url =~ m/.avi$/i || $media_url =~ m/.mpg$/i || $media_url =~ m/.mpeg$/i){
			if ($player_version == 6){
				$video = $embed_wmv6; 
			} elsif ($player_version == 10){
				$video = $embed_wmv10; 
			} else {
				$video = $embed_wmv6; 
			}
			$controlheight = 45;
		## file extensions that open windows media player for audio
		} elsif ($media_url =~ m/.wma$/i || $media_url =~ m/.wax$/i || $media_url =~ m/.asx$/i || $media_url =~ m/.mp3$/i || $media_url =~ m/.mid$/i || $media_url =~ m/.wav$/i || $media_url =~ m/.kar$/i || $media_url =~ m/.rmi$/i){
			if ($player_version == 6){
				$video = $embed_wma6; 
			} elsif ($player_version == 10){
				$video = $embed_wma10; 
			} else {
				$video = $embed_wma6; 
			}
		## file extensions that open flash player
		} elsif ($media_url =~ m/.ra$/i || $media_url =~ m/.ram$/i || $media_url =~ m/.rm$/i){
			$video = $embed_ra;
		} elsif ($media_url =~ m/.swf$/i){
			$video = $embed_flash;
		} elsif ($media_url =~ m/youtube\.com/i){
			$media_url =~ s~watch\?v\=~v\/~g;
			$video = $embed_flash;
			$controlheight = 36;
		## file extensions that open apple quicktime player player
		} elsif ($media_url =~ m/.qt$/ || $media_url =~ m/.qtm$/i || $media_url =~ m/.mov$/i){
			$video = $embed_qt;
			$controlheight = 15;
		}
		if ($play_pars =~ m/loop/){$pl_loop = "true"; } else {$pl_loop = "false"; }
		if ($play_pars =~ m/hide/ || $play_pars =~ m/hidden/){$pl_controls = "false"; $pl_controlheight = 0; $pl_controlwidth = 0;} else {$pl_controls = "true"; $pl_controlheight = 45; $pl_controlwidth = 320;}
		if ($play_pars =~ m/autostart/){$pl_start = "true"; } else {$pl_start = "false"; }
		if ($play_pars =~ m/width\=(\d{2,3})/i){
			$tempwidth= $1;
			if ($tempwidth >= 180 || $tempwidth <= 800){
				$pl_width = int($tempwidth); 
				$pl_height = int(($pl_width*3)/4) + $controlheight; 
			} else {
				$pl_width = 320; 
				$pl_height = 240 + $controlheight; 
			}
		} else {
			$pl_width = 320; 
			$pl_height = 240 + $controlheight; 
		}
		$video =~ s~[\t\r\n]~~g;
		$video =~ s~_width_~$pl_width~ig;
		$video =~ s~_controls_~$pl_controls~ig;
		$video =~ s~_height_~$pl_height~ig;
		$video =~ s~_controlheight_~$pl_controlheight~ig;
		$video =~ s~_controlwidth_~$pl_controlwidth~ig;
		$video =~ s~_media_~$media_url~ig;
		$video =~ s~_loop_~$pl_loop~ig;
		$video =~ s~_autostart_~$pl_start~ig;
	}
	return $video;
}

sub flashconvert{
	my ($fl_url,$fl_size) = @_;
	$fl_size =~ s/ //g;
	my ($fl_width, undef) = split (/\,/ , $fl_size);
	return "\[media width\=$fl_width\]$fl_url\[/media\]"; 
}

## Windows Media Player 6.4 Video
$embed_wmv6 = qq~
      <OBJECT id='mediaPlayer' width="_width_" height="_height_" 
      classid='clsid: 22D6F312-B0F6-11D0-94AB-0080C74C7E95' 
      codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
      standby='Loading Microsoft Windows Media Player 6.4 components...' type='application/x-oleobject'>
      <param name='fileName' value="_media_">
      <param name='autoStart' value="_autostart_">
      <param name='showControls' value="_controls_">
      <param name='loop' value="_loop_">
      <EMBED type='application/x-mplayer2'
        pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
        id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1' 
        TransparantAtStart='true' bgcolor='darkblue' showcontrols="_controls_" showtracker='-1' 
        showdisplay='0' showstatusbar='-1' videoborder3d='-1' width="_width_" height="_height_"
        src="_media_" autostart="_autostart_" designtimesp='5311' loop="_loop_">
      </EMBED>
      </OBJECT>
~;

## Windows Media Player 6.4 Audio
$embed_wma6 = qq~
      <OBJECT id='mediaPlayer' width="_controlwidth_" height="_controlheight_"
      classid='clsid: 22D6F312-B0F6-11D0-94AB-0080C74C7E95' 
      codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
      standby='Loading Microsoft Windows Media Player 6.4 components...' type='application/x-oleobject'>
      <param name='fileName' value="_media_">
      <param name='autoStart' value="_autostart_">
      <param name='showControls' value="_controls_">
      <param name='loop' value="_loop_">
      <EMBED type='application/x-mplayer2'
        pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
        id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1' 
        TransparantAtStart='true' bgcolor='darkblue' showcontrols="_controls_" showtracker='-1' 
        showdisplay='0' showstatusbar='-1' videoborder3d='-1' width="320" height="_controlheight_"
        src="_media_" autostart="_autostart_" designtimesp='5311' loop="_loop_">
      </EMBED>
      </OBJECT>
~;

## Windows Media Player 7,9 or 10 Video
$embed_wmv10 = qq~
      <OBJECT id='mediaPlayer' width="_width_" height="_height_" 
      classid='clsid: 6BF52A52-394A-11d3-B153-00C04F79FAA6' 
      codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'
      standby='Loading Microsoft Windows Media Player 7, 9 or 10 components...' type='application/x-oleobject'>
      <param name='fileName' value="_media_">
      <param name='autoStart' value="_autostart_">
      <param name='showControls' value="_controls_">
      <param name='loop' value="_loop_">
      <EMBED type='application/x-mplayer2'
        pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
        id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1' 
        TransparantAtStart='true' bgcolor='darkblue' showcontrols="_controls_" showtracker='-1' 
        showdisplay='0' showstatusbar='-1' videoborder3d='-1' width="_width_" height="_height_"
        src="_media_" autostart="_autostart_" designtimesp='5311' loop="_loop_">
      </EMBED>
      </OBJECT>
~;

## Windows Media Player 7,9 or 10 Audio
$embed_wma10 = qq~
      <OBJECT id='mediaPlayer' width="_controlwidth_" height="_controlheight_"
      classid='clsid: 6BF52A52-394A-11d3-B153-00C04F79FAA6' 
      codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'
      standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
      <param name='fileName' value="_media_">
      <param name='autoStart' value="_autostart_">
      <param name='showControls' value="_controls_">
      <param name='loop' value="_loop_">
      <EMBED type='application/x-mplayer2'
        pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
        id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1' 
        TransparantAtStart='true' bgcolor='darkblue' showcontrols="_controls_" showtracker='-1' 
        showdisplay='0' showstatusbar='-1' videoborder3d='-1' width="320" height="_controlheight_"
        src="_media_" autostart="_autostart_" designtimesp='5311' loop="_loop_">
      </EMBED>
      </OBJECT>
~;

$embed_ra = qq~
        <OBJECT id='rvocx' classid='clsid: CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA'
        width="320" height="_height_">
        <param name='src' value="_media_">
        <param name='autostart' value="_autostart_">
        <param name='controls' value='imagewindow'>
        <param name='console' value='video'>
        <param name='loop' value="_loop_">
        <EMBED src="_media_" width="_width_" height="_height_" 
        loop="true" type='audio/x-pn-realaudio-plugin' controls='imagewindow' console='video' autostart="_autostart_">
        </EMBED>
        </OBJECT><br />
          <OBJECT id='rvocx' classid='clsid: CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA'
          width="320" height='30'>
          <param name='src' value="_media_">
          <param name='autostart' value="_autostart_">
          <param name='controls' value='ControlPanel'>
          <param name='console' value='video'>
          <EMBED src="_media_" width="_width_" height='30' 
          controls='ControlPanel' type='audio/x-pn-realaudio-plugin' console='video' autostart="_autostart_">
          </EMBED>
          </OBJECT>
~;

$embed_qt = qq~
        <OBJECT classid='clsid: 02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width="_width_"
        height="_height_" codebase='http://www.apple.com/qtactivex/qtplugin.cab'>
        <param name='src' value="_media_">
        <param name='autoplay' value="_autostart_">
        <param name='controller' value="_controls_">
        <param name='loop' value="_loop_">
        <EMBED src="_media_" width="_width_" height="_height_" autoplay="_autostart_" 
        controller="true" loop="_loop_" pluginspage='http://www.apple.com/quicktime/download/'>
        </EMBED>
        </OBJECT>
~;

$embed_flash = qq~
	<object classid="clsid: D27CDB6E-AE6D-11cf-96B8-444553540000"
	codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
	width="_width_" height="_height_" id="myMovieName">
	<param name='movie' value="_media_">
	<param name='quality' value="high">
	<param name='bgcolor' value="#FFFFFF">
        <embed src="_media_" quality="high" bgcolor="#FFFFFF" width="_width_"
        height="_height_" loop="_loop_" type="application/x-shockwave-flash"
	pluginspage="http://www.macromedia.com/go/getflashplayer">
	</embed>
	</object>
~;

1;
