<?php if (!defined('PmWiki')) exit() ;
#---------------------------------------------------------------------------------------
/*
This file is HTML5Video.php.
You can redistribute it and/or modify it under the
terms of the GNU General Public License as
published by the Free Software Foundation
http://www.fsf.org either version 2 of the
License, or (at your option) any later version.

Copyright 2010 GNUZoo

If you find this program useful, you can show your
appreciation by sending a donation. 

    email:guru@gnuzoo.org
    http://www.pmwiki.org/wiki/Profiles/GNUZoo
*/
#---------------------------------------------------------------------------------------
$RecipeInfo['HTML5Video']['Version'] = '20200130' ;

switch ($action) {
	case 'edit'   :
	case 'print'  :
	if (! @$_POST['preview']) break ;
	case 'browse' :
	Markup('HTML5Video', 'fulltext', '/\\(:html5video(\\s.*?)?:\\)/i', 'HTML5Video') ;
}
#---------------------------------------------------------------------------------------
function HTML5Video($m) {
	list($pmwiki_element, $a) = $m ;
	#list($pmwiki_element, $name, $a) = $m ;

	global $HTML5VideoDir ;
	global $HTML5ImageDir ;

	$a = ParseArgs($a) ;

	$filename = $a['filename'] ;
	$poster   = $a['poster'  ] ;
	$width    = $a['width'   ] ;
	$height   = $a['height'  ] ;

	# note - must set id to set volume
	$id       = $a['id'      ] ;
	$volume   = $a['volume'  ] ;

	SDV($HTML5ImageDir, '/uploads/') ; # for poster
	SDV($HTML5VideoDir, '/uploads/') ;

	if ($width  == '') $width  = 480 ;
	if ($height == '') $height = 360 ;

	$html = "\n".'<video ';

	# note - must set id to set volume
	if ($id != '') $html .= 'id="'.$id.'" ' ;

	$html .= 'width="'.$width.'px" height="'.$height.'px" controls="controls" preload="preload" ' ;

	if ($poster != '') $html .= 'poster="'.$HTML5ImageDir.$poster.'.jpg" ' ;

	$html .= rtrim($html).'>' ;

	$html .= "\n\t".'<source src="'.$HTML5VideoDir.$filename.'.mp4"  type="video/mp4"  />' ;
	$html .= "\n\t".'<source src="'.$HTML5VideoDir.$filename.'.ogv"  type="video/ogg"  />' ;

	$html .= "\n\t".'br />Your browser does not allow HTML5 video.' ;

	$html .= "\n".'</video>' ;

	# note - must set id to set volume
	if ($volume != '') $html .= "\n".'<script>document.getElementById("'.$id.'").volume = '.$volume.' ;</script>' ;

	return Keep($html) ;
}
#---------------------------------------------------------------------------------------