<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

function smarty_cms_function_webvideo($params, &$smarty) {
	global $gCms;
	$config =& $gCms->GetConfig();
	
	// get and set the smarty parameters
	$movie = $params['movie'];
	$width = isset($params['width']) ? $params['width']:425;
	$height = isset($params['height']) ? $params['height']:355;
	$lang = isset($params['lang']) ? '&amp;hl='.$params['lang']:'';
	$c1 = $params['color1'];
	$c2 = $params['color2'];
	$class = isset($params['class']) ? 'class="'.$params['class'].'" ':'';
	$id = isset($params['id']) ? 'id="'.$params['id'].'" ':'';
	$border = $params['border'];
	$related = $params['related'];
	$fullscreen = isset($params['fullscreen']) ? $params['fullscreen']:1;
	$script = isset($params['allowscript']) ? $params['allowscript']:1;
	$wmode = isset($params['wmode']) ? $params['wmode']:1;
	$showtitle = isset($params['showtitle']) ? $params['showtitle']:0;
	$by = isset($params['showby']) ? $params['showby']:0;
	$playermode = isset($params['playermode']) ? $params['playermode']:'';
	$autoplay = isset($params['autoplay']) ? $params['autoplay']:0;
	$loop = isset($params['loop']) ? $params['loop']:0;
	$share = isset($params['share']) ? $params['share']:0;
	
	// Common Embed Parameters
	if ($wmode == 1) $wmode = "<param name=\"wmode\" value=\"transparent\"/>\n";
	if ($fullscreen == 1) $fsparam = "<param name=\"allowFullScreen\" value=\"true\"/>\n";
	if ($script == 1) $script = "<param name=\"allowScriptAccess\" value=\"always\"/>\n";
	
	
	// Stream Source Embed URL
	if (isset($movie)) {
		switch($params['src']) {
			case 'dailymotion': // Dailymotion Player
				$url = 'http://www.dailymotion.com/swf/video/'.$movie;
				break;
			case 'google': // Google Player
				if ($fullscreen != 1) $fs = 'false'; else $fs = 'true';
				if ($playermode) $pm = '&amp;playerMode='.$playermode;
				if ($autoplay == 1) $autoplay = '&amp;autoPlay=true'; else $autoplay = '';
				if ($loop == 1) $loop = '&amp;loop=true'; else $loop = '';
				if ($share == 1) $share = '&amp;showShareButtons=true'; else $share = '';
				$url = 'http://video.google.com/googleplayer.swf?docid='.$movie.'&amp;hl='.$lang.'&amp;fs='.$fs.$pm.$autoplay.$loop.$share;
				break;
			case 'metacafe': // Metacafe Player
				$url = 'http://www.metacafe.com/fplayer/'.$movie.'/movie.swf';
				break;
			case 'myspace': // Myspace Player
				$url = 'http://mediaservices.myspace.com/services/media/embed.aspx/m='.$movie.',t=1,mt=video,searchID=,primarycolor='.$c1.',secondarycolor='.$c2;
				break;
			case 'vimeo': // Vimeo Player
				if ($fullscreen != 1) $fs = 0; else $fs = 1;
			    if ($by != 1) $by = 0;
				if ($c1) $c1 = '&amp;color='.$c1;
				$url = 'http://vimeo.com/moogaloop.swf?clip_id='.$movie.'&amp;server=vimeo.com&amp;show_title='.$showtitle.'&amp;show_byline='.$by.'&amp;'.$c1.'&amp;fullscreen='.$fs;
				break;
			default: // YouTube Player
				if ($c1) $c1 = '&amp;color1=0x'.$c1;
				if ($c2) $c2 = '&amp;color2=0x'.$c2;
				if ($border == 1) $b = '&amp;border=1';
				elseif (!is_null($border) && $border == 0) $rel = '&amp;border=0';
				if ($related == 1) $rel = '&amp;rel=1';
				elseif (!is_null($related) && $related == 0) $rel = '&amp;rel=0';
				if ($fullscreen == 1) $fs = '&amp;fs=1';
				elseif (!is_null($fullscreen) && $fullscreen == 0) $rel = '&amp;fs=0';
				$url = 'http://www.youtube.com/v/'.$movie.$lang.$c1.$c2.$b.$fs.$rel;
				break;
		}
		// render valid xhtml
		echo '<object type="application/x-shockwave-flash" '.$class.$id.'style="width:'.$width.'px; height:'.$height.'px;" data="'.$url.'">'."\n".'<param name="movie" value="'.$url.'" />'."\n".$fsparam.$wmode.$script.'</object>'."\n";
		
	} else {
		// error
		echo "<p>The <code>movie</code> parameter must be defined in the <code>{webvideo}</code> tag.";
		if (!isset($params['src'])) echo "<br />\n<strong>Note:</strong>Leaving the <code>src</code> parameter empty will default to using YouTube as the video source.";
		echo "</p>";
	}
	$vars = get_defined_vars();
	foreach($vars as $key=>$val) {
		unset($val);
	}
}

function smarty_cms_help_function_webvideo() {
	global $gCms;
	$config =& $gCms->GetConfig();
	?>
<h3>What does this do?</h3>
    <p>Embeds a <em><strong>valid</strong></em> xhtml streaming video player on your page. This plugin supports multiple video streaming services. See the <code>src</code> parameter for more details.</p>
<h3>How do I use it?</h3>
<p>Just insert the tag <code>{webvideo <em>parameters</em>}</code> into your template or page.
 You must include the <code>movie</code> parameter for the player to work.  The <code>movie</code> parameter value is the video id.
<h4>Examples:</h4>
 <p>To embed this YouTube video:<br />
 http://www.youtube.com/watch?v=<span style="color:#F00">pqfPjBOK2l4</span>&amp;feature=PlayList&amp;p=F8F899D238798193&amp;index=0 </p>
<p> Use the video id (shown above in <span style="color:#F00">red</span>) in the <code>movie</code> parameter on your page:</p>
<p><code>{webvideo movie='pqfPjBOK2l4' width='480' height='385'}</code></p>
<p><em><strong>Note:</strong> YouTube is the default streaming video source so there's no need to declare it in the </em><code>src</code><em> parameter.</em></p>
<p>Using a metacafe video:</p>
<p><code>{webvideo src='metacafe' movie='yt-BN5sYBTg4cQ' width='400' height='345'}</code></p>
<h3>Parameters</h3>
<p>The following smarty parameters are available in all video players.</p>
<ul>
  <li><code>movie</code> <em style="color:#006">(required)</em> - Movie ID.</li>
    <li><code>width</code> <em>(optional)</em> - Width of the video player. (Default width is <strong>425</strong>)</li>
    <li><code>height</code> <em>(optional)</em> - Height of the video player (Default height is <strong>355</strong>)</li>
    <li><code>fullscreen</code> <em>(optional)</em> - Controls full screen viewing of movies. (Disable by changing value to '<strong>0</strong>')</li>
    <li><code>scriptaccess</code> <em>(optional)</em> - Controls script access. (Disable by changing value to '<strong>0</strong>')</li>
    <li><code>wmode</code> <em>(optional)</em> - Controls the background transparency. (Disable by changing value to '<strong>0</strong>')</li>
    <li><code>class</code> <em>(optional)</em> - CSS class. Use commas to separate multiple classes.</li>
    <li><code>id</code> <em>(optional)</em> - CSS ID.</li>
    <li><code>src</code> <em>(optional)</em> - The video stream provider. Each source supports different parameters. Possible values are:
      <ul>
        <li><a href="http://www.dailymotion.com/" target="_blank">dailymotion</a> - Optional parameters: <em>none</em></li>
        <li><a href="http://video.google.com/" target="_blank">google</a> - Optional parameters: <code>playermode, autoplay, loop, share</code></li>
        <li><a href="http://www.metacafe.com/" target="_blank">metacafe</a> - Optional parameters: <em>none</em></li>
        <li><a href="http://vids.myspace.com/" target="_blank">myspace</a> - Optional parameters: <code>color1, color2</code></li>
        <li><a href="http://vimeo.com/" target="_blank">vimeo</a> - Optional parameters: <code>color1, showby, showtitle</code></li>
        <li><a href="http://www.youtube.com/" target="_blank">youtube</a> <em style="color:#006">(default)</em> - Optional parameters: <code>border, color1, color2, lang, related</code></li>
      </ul>
  </li>
</ul>
<br />
<h4>Optional Parameters</h4>
<ul>
  <li><code>autoplay</code> <em>(optional)</em> - Allows video to start upon page load (Enable by changing value to '<strong>1</strong>')</li>
  <li><code>border</code> <em>(optional)</em> - Add a border to the player. (Enable by changing value to '<strong>1</strong>')</li>
  
  <li><code>color1</code> <em>(optional)</em> - Defines the primary player color as a hex value.</li>
  <li><code>color2</code> <em>(optional)</em> - Defines the secondary player color as a hex value.</li>
  <li><code>lang</code> <em>(optional)</em> - Change the player language.</li>
  <li><code>loop</code> <em>(optional)</em> - Allows you to repeat the video indefinitely (Enable by changing value to '<strong>1</strong>')</li>
  <li><code>playermode</code> <em>(optional)</em> - Allows you to change the player skin options
    <ul>
      <li><strong>simple</strong> - Basic player version without progress bar and volume control.</li>
      <li><strong>mini</strong> - Even more basic player version</li>
      <li><strong>clickToPlay</strong> - Used for video ads.</li>
      <li><strong>embedded</strong> - standard skin.</li>
    </ul>
  </li>
  <li><code>related</code> <em>(optional)</em> - Controls the related videos feature. (Disable by changing value to '<strong>0</strong>')</li>
  <li><code>share</code> <em>(optional)</em> - Adds a button that will &quot;Send link to a friend.&quot; (Enable by changing value to '<strong>1</strong>')</li>
  <li><code>showby</code> <em>(optional)</em> - Shows whom the movie was uploaded by. (Enable by changing value to '<strong>1</strong>')</li>
  <li><code>showtitle</code> <em>(optional)</em> - Shows the movie title. (Enable by changing value to '<strong>1</strong>')</li>
</ul>
    <h3>Release Notes</h3>
<p>Version: <strong>beta 0.3</strong>, 4.2.2010<br />
  Renamed the plugin to <em>webvideo</em><br />
    Added support for: dailymotion, google, metacafe, myspace, and vimeo.<br />
Added the <code>autoplay</code> parameter.<br />
Added the <code>loop</code> parameter.<br />
Added the <code>playermode</code> parameter.<br />
Added the <code>share</code> parameter.<br />
    Added the <code>src</code> parameter.<br />
Added the <code>showby</code> parameter.<br />
Added the <code>showtitle</code> parameter.<br />
Added the <code>wmode</code> parameter.<br />
  Changed the default value for <code>fullscreen</code> to <strong>1</strong>.</p>
    <p>Version: <strong>beta 0.2</strong>, 3.4.2010<br />
    Added the <code>fullscreen</code> parameter.<br />
    Added the <code>related</code> parameter.<br /><br />
Please send comments and suggestions to Bryan Buxton &lt;me@bryanbuxton.com&gt;</p>
	<?php
}

function smarty_cms_about_function_webvideo() {
	?>
	<p>Author: Bryan Buxton &lt;me@bryanbuxton.com&gt;<br />
	<br />
    Version: BETA 0.3, 4.2.2010</p>
	<?php
}
?>