Update video.php

This commit is contained in:
habibapp1365 2018-03-06 19:52:01 +03:30 committed by GitHub
parent afff20a06b
commit 661827a7b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 80 additions and 119 deletions

View File

@ -17,25 +17,20 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// //
if ( !canView( 'Events' ) ) {
if ( !canView( 'Events' ) )
{
$view = "error"; $view = "error";
return; return;
} }
require_once('includes/Event.php');
$eid = validInt($_REQUEST['eid']); $eid = validInt($_REQUEST['eid']);
$sql = 'SELECT E.*,M.Name AS MonitorName,M.DefaultRate,M.DefaultScale FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id WHERE E.Id = ?'; $sql = 'SELECT E.*,M.Name AS MonitorName,M.DefaultRate,M.DefaultScale FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id WHERE E.Id = ?';
$sql_values = array( $eid ); $sql_values = array( $eid );
if ( $user['MonitorIds'] ) { if ( $user['MonitorIds'] ) {
$monitor_ids = explode( ',', $user['MonitorIds'] ); $monitor_ids = explode( ',', $user['MonitorIds'] );
$sql .= ' AND MonitorId IN (' .implode( ',', array_fill(0,count($monitor_ids),'?') ) . ')'; $sql .= ' AND MonitorId IN (' .implode( ',', array_fill(0,count($monitor_ids),'?') ) . ')';
$sql_values = array_merge( $sql_values, $monitor_ids ); $sql_values = array_merge( $sql_values, $monitor_ids );
} }
$event = dbFetchOne( $sql, NULL, $sql_values ); $event = dbFetchOne( $sql, NULL, $sql_values );
if ( isset( $_REQUEST['rate'] ) ) if ( isset( $_REQUEST['rate'] ) )
$rate = validInt($_REQUEST['rate']); $rate = validInt($_REQUEST['rate']);
else else
@ -44,53 +39,38 @@ if ( isset( $_REQUEST['scale'] ) )
$scale = validInt($_REQUEST['scale']); $scale = validInt($_REQUEST['scale']);
else else
$scale = reScale( SCALE_BASE, $event['DefaultScale'], ZM_WEB_DEFAULT_SCALE ); $scale = reScale( SCALE_BASE, $event['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
$Event = new Event( $event['Id'] );
$eventPath = ZM_DIR_EVENTS.'/'.getEventPath( $event ); $eventPath = $Event->Path();
$videoFormats = array(); $videoFormats = array();
$ffmpegFormats = preg_split( '/\s+/', ZM_FFMPEG_FORMATS ); $ffmpegFormats = preg_split( '/\s+/', ZM_FFMPEG_FORMATS );
foreach ( $ffmpegFormats as $ffmpegFormat ) foreach ( $ffmpegFormats as $ffmpegFormat ) {
{ if ( preg_match( '/^([^*]+)(\*\*?)$/', $ffmpegFormat, $matches ) ) {
if ( preg_match( '/^([^*]+)(\*\*?)$/', $ffmpegFormat, $matches ) )
{
$videoFormats[$matches[1]] = $matches[1]; $videoFormats[$matches[1]] = $matches[1];
if ( !isset($videoFormat) && $matches[2] == "*" ) if ( !isset($videoFormat) && $matches[2] == '*' ) {
{
$videoFormat = $matches[1]; $videoFormat = $matches[1];
} }
} } else {
else
{
$videoFormats[$ffmpegFormat] = $ffmpegFormat; $videoFormats[$ffmpegFormat] = $ffmpegFormat;
} }
} }
$videoFiles = array(); $videoFiles = array();
if ( $dir = opendir( $eventPath ) ) if ( $dir = opendir( $eventPath ) ) {
{ while ( ($file = readdir( $dir )) !== false ) {
while ( ($file = readdir( $dir )) !== false )
{
$file = $eventPath.'/'.$file; $file = $eventPath.'/'.$file;
if ( is_file( $file ) ) if ( is_file( $file ) ) {
{ if ( preg_match( '/\.(?:'.join( '|', $videoFormats ).')$/', $file ) ) {
if ( preg_match( '/\.(?:'.join( '|', $videoFormats ).')$/', $file ) )
{
$videoFiles[] = $file; $videoFiles[] = $file;
} }
} }
} }
closedir( $dir ); closedir( $dir );
} }
if ( isset($_REQUEST['deleteIndex']) ) {
if ( isset($_REQUEST['deleteIndex']) )
{
$deleteIndex = validInt($_REQUEST['deleteIndex']); $deleteIndex = validInt($_REQUEST['deleteIndex']);
unlink( $videoFiles[$deleteIndex] ); unlink( $videoFiles[$deleteIndex] );
unset( $videoFiles[$deleteIndex] ); unset( $videoFiles[$deleteIndex] );
} }
if ( isset($_REQUEST['downloadIndex']) ) {
if ( isset($_REQUEST['downloadIndex']) )
{
$downloadIndex = validInt($_REQUEST['downloadIndex']); $downloadIndex = validInt($_REQUEST['downloadIndex']);
header( "Pragma: public" ); header( "Pragma: public" );
header( "Expires: 0" ); header( "Expires: 0" );
@ -104,9 +84,7 @@ if ( isset($_REQUEST['downloadIndex']) )
readfile( $videoFiles[$downloadIndex] ); readfile( $videoFiles[$downloadIndex] );
exit; exit;
} }
$focusWindow = true; $focusWindow = true;
xhtmlHeaders(__FILE__, translate('Video') ); xhtmlHeaders(__FILE__, translate('Video') );
?> ?>
<body> <body>
@ -119,8 +97,7 @@ xhtmlHeaders(__FILE__, translate('Video') );
</div> </div>
<div id="content"> <div id="content">
<?php <?php
if ( isset($_REQUEST['showIndex']) ) if ( isset($_REQUEST['showIndex']) ) {
{
$showIndex = validInt($_REQUEST['showIndex']); $showIndex = validInt($_REQUEST['showIndex']);
preg_match( '/([^\/]+)\.([^.]+)$/', $videoFiles[$showIndex], $matches ); preg_match( '/([^\/]+)\.([^.]+)$/', $videoFiles[$showIndex], $matches );
$name = $matches[1]; $name = $matches[1];
@ -129,9 +106,7 @@ if ( isset($_REQUEST['showIndex']) )
<h3 id="videoFile"><?php echo substr( $videoFiles[$showIndex], strlen(ZM_DIR_EVENTS)+1 ) ?></h3> <h3 id="videoFile"><?php echo substr( $videoFiles[$showIndex], strlen(ZM_DIR_EVENTS)+1 ) ?></h3>
<div id="imageFeed"><?php outputVideoStream( 'videoStream', $videoFiles[$showIndex], validInt($_REQUEST['width']), validInt($_REQUEST['height']), $videoFormat, $name ) ?></div> <div id="imageFeed"><?php outputVideoStream( 'videoStream', $videoFiles[$showIndex], validInt($_REQUEST['width']), validInt($_REQUEST['height']), $videoFormat, $name ) ?></div>
<?php <?php
} } else {
else
{
?> ?>
<form name="contentForm" id="contentForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <form name="contentForm" id="contentForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="hidden" name="id" value="<?php echo $event['Id'] ?>"/> <input type="hidden" name="id" value="<?php echo $event['Id'] ?>"/>
@ -158,14 +133,11 @@ else
<input type="button" value="<?php echo translate('GenerateVideo') ?>" onclick="generateVideo( this.form );"<?php if ( !ZM_OPT_FFMPEG ) { ?> disabled="disabled"<?php } ?>/> <input type="button" value="<?php echo translate('GenerateVideo') ?>" onclick="generateVideo( this.form );"<?php if ( !ZM_OPT_FFMPEG ) { ?> disabled="disabled"<?php } ?>/>
</form> </form>
<?php <?php
if ( isset($_REQUEST['generated']) ) if ( isset($_REQUEST['generated']) ) {
{
?> ?>
<h2 id="videoProgress" class="<?php echo $_REQUEST['generated']?'infoText':'errorText' ?>"><span id="videoProgressText"><?php echo $_REQUEST['generated']?translate('VideoGenSucceeded'):translate('VideoGenFailed') ?></span><span id="videoProgressTicker"></span></h2> <h2 id="videoProgress" class="<?php echo $_REQUEST['generated']?'infoText':'errorText' ?>"><span id="videoProgressText"><?php echo $_REQUEST['generated']?translate('VideoGenSucceeded'):translate('VideoGenFailed') ?></span><span id="videoProgressTicker"></span></h2>
<?php <?php
} } else {
else
{
?> ?>
<h2 id="videoProgress" class="hidden warnText"><span id="videoProgressText"><?php echo translate('GeneratingVideo') ?></span><span id="videoProgressTicker"></span></h2> <h2 id="videoProgress" class="hidden warnText"><span id="videoProgressText"><?php echo translate('GeneratingVideo') ?></span><span id="videoProgressTicker"></span></h2>
<?php <?php
@ -173,14 +145,11 @@ else
?> ?>
<h2 id="videoFilesHeader"><?php echo translate('VideoGenFiles') ?></h2> <h2 id="videoFilesHeader"><?php echo translate('VideoGenFiles') ?></h2>
<?php <?php
if ( count($videoFiles) == 0 ) if ( count($videoFiles) == 0 ) {
{
?> ?>
<h3 id="videoNoFiles"><?php echo translate('VideoGenNoFiles') ?></h3> <h3 id="videoNoFiles"><?php echo translate('VideoGenNoFiles') ?></h3>
<?php <?php
} } else {
else
{
?> ?>
<table id="videoTable" class="major" cellspacing="0"> <table id="videoTable" class="major" cellspacing="0">
<thead> <thead>
@ -195,27 +164,19 @@ else
<tbody> <tbody>
<?php <?php
$index = 0; $index = 0;
foreach ( $videoFiles as $file ) foreach ( $videoFiles as $file ) {
{ if ( filesize( $file ) > 0 ) {
if ( filesize( $file ) > 0 )
{
preg_match( '/^(.+)-((?:r[_\d]+)|(?:F[_\d]+))-((?:s[_\d]+)|(?:S[0-9a-z]+))\.([^.]+)$/', $file, $matches ); preg_match( '/^(.+)-((?:r[_\d]+)|(?:F[_\d]+))-((?:s[_\d]+)|(?:S[0-9a-z]+))\.([^.]+)$/', $file, $matches );
if ( preg_match( '/^r(.+)$/', $matches[2], $temp_matches ) ) if ( preg_match( '/^r(.+)$/', $matches[2], $temp_matches ) ) {
{
$rate = (int)(100 * preg_replace( '/_/', '.', $temp_matches[1] ) ); $rate = (int)(100 * preg_replace( '/_/', '.', $temp_matches[1] ) );
$rateText = isset($rates[$rate])?$rates[$rate]:($rate."x"); $rateText = isset($rates[$rate])?$rates[$rate]:($rate."x");
} } elseif ( preg_match( '/^F(.+)$/', $matches[2], $temp_matches ) ) {
elseif ( preg_match( '/^F(.+)$/', $matches[2], $temp_matches ) )
{
$rateText = $temp_matches[1]."fps"; $rateText = $temp_matches[1]."fps";
} }
if ( preg_match( '/^s(.+)$/', $matches[3], $temp_matches ) ) if ( preg_match( '/^s(.+)$/', $matches[3], $temp_matches ) ) {
{
$scale = (int)(100 * preg_replace( '/_/', '.', $temp_matches[1] ) ); $scale = (int)(100 * preg_replace( '/_/', '.', $temp_matches[1] ) );
$scaleText = isset($scales[$scale])?$scales[$scale]:($scale."x"); $scaleText = isset($scales[$scale])?$scales[$scale]:($scale."x");
} } elseif ( preg_match( '/^S(.+)$/', $matches[3], $temp_matches ) ) {
elseif ( preg_match( '/^S(.+)$/', $matches[3], $temp_matches ) )
{
$scaleText = $temp_matches[1]; $scaleText = $temp_matches[1];
} }
$width = $scale?reScale( $event['Width'], $scale ):$event['Width']; $width = $scale?reScale( $event['Width'], $scale ):$event['Width'];