From 3244c8ab5b3dcc2bb4c81844ac938afee4eeddb7 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Oct 2019 13:18:09 -0400 Subject: [PATCH] spacing, quotes, remove debug --- web/includes/functions.php | 962 +++++++++++++++++++------------------ 1 file changed, 493 insertions(+), 469 deletions(-) diff --git a/web/includes/functions.php b/web/includes/functions.php index 4a134743d..49896dbfe 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -19,11 +19,11 @@ // // Compatibility functions -if ( version_compare( phpversion(), '4.3.0', '<') ) { +if ( version_compare(phpversion(), '4.3.0', '<') ) { function ob_get_clean() { $buffer = ob_get_contents(); ob_end_clean(); - return( $buffer ); + return $buffer; } } @@ -36,7 +36,7 @@ function noCacheHeaders() { } function CSPHeaders($view, $nonce) { - $additionalScriptSrc = ""; + $additionalScriptSrc = ''; switch ($view) { case 'login': { if (defined('ZM_OPT_USE_GOOG_RECAPTCHA') @@ -101,14 +101,14 @@ function CORSHeaders() { } return; } - foreach( $Servers as $Server ) { + foreach ( $Servers as $Server ) { if ( preg_match('/^(https?:\/\/)?'.preg_quote($Server->Hostname(),'/').'/i', $_SERVER['HTTP_ORIGIN']) or preg_match('/^(https?:\/\/)?'.preg_quote($Server->Name(),'/').'/i', $_SERVER['HTTP_ORIGIN']) ) { $valid = true; - ZM\Logger::Debug("Setting Access-Control-Allow-Origin from " . $_SERVER['HTTP_ORIGIN']); + ZM\Logger::Debug('Setting Access-Control-Allow-Origin from '.$_SERVER['HTTP_ORIGIN']); header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); header('Access-Control-Allow-Headers: x-requested-with,x-request'); break; @@ -122,21 +122,21 @@ function CORSHeaders() { function getMimeType( $file ) { if ( function_exists('mime_content_type') ) { - return( mime_content_type( $file ) ); + return mime_content_type($file); } elseif ( function_exists('finfo_file') ) { - $finfo = finfo_open( FILEINFO_MIME ); - $mimeType = finfo_file( $finfo, $file ); + $finfo = finfo_open(FILEINFO_MIME); + $mimeType = finfo_file($finfo, $file); finfo_close($finfo); - return( $mimeType ); + return $mimeType; } return trim(exec('file -bi '.escapeshellarg($file).' 2>/dev/null')); } -function outputVideoStream( $id, $src, $width, $height, $format, $title='' ) { - echo getVideoStreamHTML( $id, $src, $width, $height, $format, $title ); +function outputVideoStream($id, $src, $width, $height, $format, $title='') { + echo getVideoStreamHTML($id, $src, $width, $height, $format, $title); } -function getVideoStreamHTML( $id, $src, $width, $height, $format, $title='' ) { +function getVideoStreamHTML($id, $src, $width, $height, $format, $title='') { $html = ''; $width = validInt($width); $height = validInt($height); @@ -259,7 +259,7 @@ function getImageStreamHTML( $id, $src, $width, $height, $title='' ) { } } -function outputControlStream( $src, $width, $height, $monitor, $scale, $target ) { +function outputControlStream($src, $width, $height, $monitor, $scale, $target) { ?>
@@ -286,10 +286,10 @@ function outputControlStream( $src, $width, $height, $monitor, $scale, $target ) '; } -function outputImageStill( $id, $src, $width, $height, $title='' ) { - echo getImageStill( $id, $src, $width, $height, $title='' ); +function outputImageStill($id, $src, $width, $height, $title='') { + echo getImageStill($id, $src, $width, $height, $title=''); } -function getImageStill( $id, $src, $width, $height, $title='' ) { - return ''.$title.''; +function getImageStill($id, $src, $width, $height, $title='') { + return ''.$title.''; } -function getWebSiteUrl( $id, $src, $width, $height, $title='' ) { - # Prevent unsightly warnings when php cannot verify the ssl certificate - stream_context_set_default( [ - 'ssl' => [ - 'verify_peer' => false, - 'verify_peer_name' => false, - ], - ]); - # The End User can turn off the following warning under Options -> Web - if ( ZM_WEB_XFRAME_WARN ) { - $header = get_headers($src, 1); - # If the target website has set X-Frame-Options, check it for "sameorigin" and warn the end user - if (array_key_exists('X-Frame-Options', $header)) { - $header = $header['X-Frame-Options']; - if ( stripos($header, 'sameorigin') === 0 ) - ZM\Warning("Web site $src has X-Frame-Options set to sameorigin. An X-Frame-Options browser plugin is required to display this site."); - } +function getWebSiteUrl($id, $src, $width, $height, $title='') { + # Prevent unsightly warnings when php cannot verify the ssl certificate + stream_context_set_default( [ + 'ssl' => [ + 'verify_peer' => false, + 'verify_peer_name' => false, + ], + ]); + # The End User can turn off the following warning under Options -> Web + if ( ZM_WEB_XFRAME_WARN ) { + $header = get_headers($src, 1); + # If the target website has set X-Frame-Options, check it for "sameorigin" and warn the end user + if ( array_key_exists('X-Frame-Options', $header) ) { + $header = $header['X-Frame-Options']; + if ( stripos($header, 'sameorigin') === 0 ) + ZM\Warning("Web site $src has X-Frame-Options set to sameorigin. An X-Frame-Options browser plugin is required to display this site."); } - return ''; + } + return ''; } -function outputControlStill( $src, $width, $height, $monitor, $scale, $target ) { +function outputControlStill($src, $width, $height, $monitor, $scale, $target) { ?> @@ -357,7 +359,7 @@ function outputControlStill( $src, $width, $height, $monitor, $scale, $target ) } // Incoming args are shell-escaped. This function must escape any further arguments it cannot guarantee. -function getZmuCommand( $args ) { +function getZmuCommand($args) { $zmuCommand = ZMU_PATH; if ( ZM_OPT_USE_AUTH ) { @@ -382,14 +384,14 @@ function getEventDefaultVideoPath($event) { function deletePath( $path ) { ZM\Logger::Debug("Deleting $path"); - if ( is_dir( $path ) ) { - system( escapeshellcmd( 'rm -rf '.$path ) ); + if ( is_dir($path) ) { + system(escapeshellcmd('rm -rf '.$path)); } else if ( file_exists($path) ) { - unlink( $path ); + unlink($path); } } -function deleteEvent( $event ) { +function deleteEvent($event) { if ( empty($event) ) { ZM\Error('Empty event passed to deleteEvent.'); @@ -398,7 +400,7 @@ function deleteEvent( $event ) { if ( gettype($event) != 'array' ) { # $event could be an eid, so turn it into an event hash - $event = new ZM\Event( $event ); + $event = new ZM\Event($event); } else { ZM\Logger::Debug("Event type: " . gettype($event)); } @@ -410,7 +412,7 @@ ZM\Logger::Debug("Event type: " . gettype($event)); } # CAN EDIT } -function makeLink( $url, $label, $condition=1, $options='' ) { +function makeLink($url, $label, $condition=1, $options='') { $string = ''; if ( $condition ) { $string .= ''; @@ -419,13 +421,13 @@ function makeLink( $url, $label, $condition=1, $options='' ) { if ( $condition ) { $string .= ''; } - return( $string ); + return $string; } /** * $label must be already escaped. It can't be done here since it sometimes contains HTML tags. */ -function makePopupLink( $url, $winName, $winSize, $label, $condition=1, $options='' ) { +function makePopupLink($url, $winName, $winSize, $label, $condition=1, $options='') { // Avoid double-encoding since some consumers incorrectly pass a pre-escaped URL. $string = ''; - return( $string ); + if ( is_array($winSize) ) { + $string .= ' data-window-tag="' . htmlspecialchars($winSize[0]) . '"'; + $string .= ' data-window-width="' . htmlspecialchars($winSize[1]) . '"'; + $string .= ' data-window-height="' . htmlspecialchars($winSize[2]) . '"'; + } else { + $string .= ' data-window-tag="' . htmlspecialchars($winSize) . '"'; + } + if (!$condition) { + $string .= ' disabled="disabled"'; + } + $string .= ($options ? (' ' . $options) : '') . '/>'; + return $string; } -function htmlSelect( $name, $contents, $values, $behaviours=false ) { +function htmlSelect($name, $contents, $values, $behaviours=false) { $behaviourText = ''; if ( !empty($behaviours) ) { if ( is_array($behaviours) ) { @@ -495,7 +497,6 @@ function htmlOptions($contents, $values) { if ( isset($option['disabled']) ) { $disabled = $option['disabled']; - ZM\Error("Setting to disabled"); } } else if ( is_object($option) ) { $text = $option->Name(); @@ -503,28 +504,28 @@ function htmlOptions($contents, $values) { $text = $option; } $selected = is_array($values) ? in_array($value, $values) : !strcmp($value, $values); - $options_html .= ""; + '>'.htmlspecialchars($text, ENT_COMPAT | ENT_HTML401, ini_get('default_charset'), false).''; } return $options_html; } -function truncText( $text, $length, $deslash=1 ) { - return( preg_replace( '/^(.{'.$length.',}?)\b.*$/', '\\1…', ($deslash?stripslashes($text):$text) ) ); -} +function truncText($text, $length, $deslash=1) { + return preg_replace('/^(.{'.$length.',}?)\b.*$/', '\\1…', ($deslash?stripslashes($text):$text)); +} -function buildSelect( $name, $contents, $behaviours=false ) { +function buildSelect($name, $contents, $behaviours=false) { $value = ''; - if ( preg_match( '/^\s*(\w+)\s*(\[.*\])?\s*$/', $name, $matches ) && count($matches) > 2 ) { + if ( preg_match('/^\s*(\w+)\s*(\[.*\])?\s*$/', $name, $matches) && (count($matches) > 2) ) { $arr = $matches[1]; if ( isset($GLOBALS[$arr]) ) $value = $GLOBALS[$arr]; elseif ( isset($_REQUEST[$arr]) ) $value = $_REQUEST[$arr]; - if ( !preg_match_all( '/\[\s*[\'"]?(\w+)["\']?\s*\]/', $matches[2], $matches ) ) { - ZM\Fatal( "Can't parse selector '$name'" ); + if ( !preg_match_all('/\[\s*[\'"]?(\w+)["\']?\s*\]/', $matches[2], $matches) ) { + ZM\Fatal("Can't parse selector '$name'"); } for ( $i = 0; $i < count($matches[1]); $i++ ) { $idx = $matches[1][$i]; @@ -561,10 +562,10 @@ function buildSelect( $name, $contents, $behaviours=false ) { $html = ob_get_contents(); ob_end_clean(); - return( $html ); + return $html; } -function getFormChanges( $values, $newValues, $types=false, $columns=false ) { +function getFormChanges($values, $newValues, $types=false, $columns=false) { $changes = array(); if ( !$types ) $types = array(); @@ -578,7 +579,6 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) { switch( $types[$key] ) { case 'set' : - { if ( is_array($newValues[$key]) ) { if ( (!isset($values[$key])) or ( join(',',$newValues[$key]) != $values[$key] ) ) { $changes[$key] = "`$key` = ".dbEscape(join(',',$newValues[$key])); @@ -587,9 +587,7 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) { $changes[$key] = "`$key` = ''"; } break; - } case 'image' : - { if ( is_array( $newValues[$key] ) ) { $imageData = getimagesize( $newValues[$key]['tmp_name'] ); $changes[$key.'Width'] = $key.'Width = '.$imageData[0]; @@ -604,9 +602,7 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) { $changes[$key] = "$key = ".dbEscape($value); } break; - } case 'document' : - { if ( is_array( $newValues[$key] ) ) { $imageData = getimagesize( $newValues[$key]['tmp_name'] ); $changes[$key.'Type'] = $key."Type = '".$newValues[$key]['type']."'"; @@ -619,9 +615,7 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) { $changes[$key] = $key . ' = '.dbEscape($value); } break; - } case 'file' : - { $changes[$key.'Type'] = $key.'Type = '.dbEscape($newValues[$key]['type']); $changes[$key.'Size'] = $key.'Size = '.dbEscape($newValues[$key]['size']); ob_start(); @@ -629,14 +623,11 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) { $changes[$key] = $key." = '".dbEscape( ob_get_contents() )."'"; ob_end_clean(); break; - } case 'raw' : - { if ( (!isset($values[$key])) or ($values[$key] != $value) ) { $changes[$key] = $key . ' = '.dbEscape($value); } break; - } case 'toggle' : if ( (!isset($values[$key])) or $values[$key] != $value ) { if ( empty($value) ) { @@ -653,7 +644,6 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) { } break; default : - { if ( !isset($values[$key]) || ($values[$key] != $value) ) { if ( ! isset($value) || $value == '' ) { $changes[$key] = "`$key` = NULL"; @@ -662,10 +652,9 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) { } } break; - } } // end switch } // end foreach newvalues - foreach( $values as $key=>$value ) { + foreach ( $values as $key=>$value ) { if ( !empty($columns[$key]) ) { if ( !empty($types[$key]) ) { if ( $types[$key] == 'toggle' ) { @@ -678,18 +667,22 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) { } } } - return( $changes ); + return $changes; } -function getBrowser( &$browser, &$version ) { +function getBrowser(&$browser, &$version) { if ( isset($_SESSION['browser']) ) { $browser = $_SESSION['browser']; $version = $_SESSION['version']; } else { - if (( preg_match( '/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $logVersion)) || (preg_match( '/.*Trident.*rv:(.*?)(;|\))/', $_SERVER['HTTP_USER_AGENT'], $logVersion))) { + if ( + ( preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $logVersion)) + || + ( preg_match('/.*Trident.*rv:(.*?)(;|\))/', $_SERVER['HTTP_USER_AGENT'], $logVersion)) + ) { $version = $logVersion[1]; $browser = 'ie'; - } elseif ( preg_match( '/Chrome\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { + } else if ( preg_match('/Chrome\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; // Check for old version of Chrome with bug 5876 if ( $version < 7 ) { @@ -697,16 +690,16 @@ function getBrowser( &$browser, &$version ) { } else { $browser = 'chrome'; } - } elseif ( preg_match( '/Safari\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { + } else if ( preg_match('/Safari\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; $browser = 'safari'; - } elseif ( preg_match( '/Opera[ \/]([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { + } else if ( preg_match('/Opera[ \/]([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; $browser = 'opera'; - } elseif ( preg_match( '/Konqueror\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { + } else if ( preg_match('/Konqueror\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; $browser = 'konqueror'; - } elseif ( preg_match( '/Mozilla\/([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { + } else if ( preg_match('/Mozilla\/([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; $browser = 'mozilla'; } else { @@ -719,53 +712,53 @@ function getBrowser( &$browser, &$version ) { } function isMozilla() { - getBrowser( $browser, $version ); + getBrowser($browser, $version); - return( $browser == 'mozilla' ); + return $browser == 'mozilla'; } function isKonqueror() { - getBrowser( $browser, $version ); + getBrowser($browser, $version); - return( $browser == 'konqueror' ); + return $browser == 'konqueror'; } function isInternetExplorer() { - getBrowser( $browser, $version ); + getBrowser($browser, $version); - return( $browser == 'ie' ); + return $browser == 'ie'; } function isOldChrome() { - getBrowser( $browser, $version ); + getBrowser($browser, $version); - return( $browser == 'oldchrome' ); + return $browser == 'oldchrome'; } function isChrome() { - getBrowser( $browser, $version ); + getBrowser($browser, $version); - return( $browser == 'chrome' ); + return $browser == 'chrome'; } function isOpera() { - getBrowser( $browser, $version ); + getBrowser($browser, $version); - return( $browser == 'opera' ); + return $browser == 'opera'; } function isSafari() { - getBrowser( $browser, $version ); + getBrowser($browser, $version); - return( $browser == 'safari' ); + return $browser == 'safari'; } function isWindows() { - return ( preg_match( '/Win/', $_SERVER['HTTP_USER_AGENT'] ) ); + return preg_match('/Win/', $_SERVER['HTTP_USER_AGENT']); } function canStreamIframe() { - return( isKonqueror() ); + return isKonqueror(); } function canStreamNative() { @@ -778,20 +771,20 @@ function canStreamApplet() { ZM\Warning('ZM_OPT_CAMBOZOLA is enabled, but the system cannot find '.ZM_PATH_WEB.'/'.ZM_PATH_CAMBOZOLA); } - return( (ZM_OPT_CAMBOZOLA && file_exists( ZM_PATH_WEB.'/'.ZM_PATH_CAMBOZOLA )) ); + return (ZM_OPT_CAMBOZOLA && file_exists(ZM_PATH_WEB.'/'.ZM_PATH_CAMBOZOLA)); } function canStream() { - return( canStreamNative() | canStreamApplet() ); + return canStreamNative() | canStreamApplet(); } -function packageControl( $command ) { - $string = ZM_PATH_BIN.'/zmpkg.pl '.escapeshellarg( $command ); +function packageControl($command) { + $string = ZM_PATH_BIN.'/zmpkg.pl '.escapeshellarg($command); $string .= ' 2>/dev/null >&- <&- >/dev/null'; - exec( $string ); + exec($string); } -function daemonControl( $command, $daemon=false, $args=false ) { +function daemonControl($command, $daemon=false, $args=false) { $string = escapeshellcmd(ZM_PATH_BIN).'/zmdc.pl '.$command; if ( $daemon ) { $string .= ' ' . $daemon; @@ -799,9 +792,9 @@ function daemonControl( $command, $daemon=false, $args=false ) { $string .= ' ' . $args; } } - $string = escapeshellcmd( $string ); + $string = escapeshellcmd($string); #$string .= ' 2>/dev/null >&- <&- >/dev/null'; -ZM\Logger::Debug("daemonControl $string"); + ZM\Logger::Debug("daemonControl $string"); exec($string); } @@ -828,7 +821,7 @@ function initDaemonStatus() { } } -function daemonStatus( $daemon, $args=false ) { +function daemonStatus($daemon, $args=false) { global $daemon_status; initDaemonStatus(); @@ -836,66 +829,66 @@ function daemonStatus( $daemon, $args=false ) { $string = $daemon; if ( $args ) $string .= ' ' . $args; - return( strpos( $daemon_status, "'$string' running" ) !== false ); + return( strpos($daemon_status, "'$string' running") !== false ); } -function zmcStatus( $monitor ) { +function zmcStatus($monitor) { if ( $monitor['Type'] == 'Local' ) { $zmcArgs = '-d '.$monitor['Device']; } else { $zmcArgs = '-m '.$monitor['Id']; } - return( daemonStatus( 'zmc', $zmcArgs ) ); + return daemonStatus('zmc', $zmcArgs); } -function zmaStatus( $monitor ) { - if ( is_array( $monitor ) ) { +function zmaStatus($monitor) { + if ( is_array($monitor) ) { $monitor = $monitor['Id']; } - return( daemonStatus( 'zma', "-m $monitor" ) ); + return daemonStatus('zma', "-m $monitor"); } -function daemonCheck( $daemon=false, $args=false ) { +function daemonCheck($daemon=false, $args=false) { $string = ZM_PATH_BIN.'/zmdc.pl check'; if ( $daemon ) { $string .= ' ' . $daemon; if ( $args ) $string .= ' '. $args; } - $string = escapeshellcmd( $string ); - $result = exec( $string ); - return( preg_match( '/running/', $result ) ); + $string = escapeshellcmd($string); + $result = exec($string); + return preg_match('/running/', $result); } -function zmcCheck( $monitor ) { +function zmcCheck($monitor) { if ( $monitor['Type'] == 'Local' ) { $zmcArgs = '-d '.$monitor['Device']; } else { $zmcArgs = '-m '.$monitor['Id']; } - return( daemonCheck( 'zmc', $zmcArgs ) ); + return daemonCheck('zmc', $zmcArgs); } -function zmaCheck( $monitor ) { - if ( is_array( $monitor ) ) { +function zmaCheck($monitor) { + if ( is_array($monitor) ) { $monitor = $monitor['Id']; } - return( daemonCheck( 'zma', "-m $monitor" ) ); + return daemonCheck('zma', "-m $monitor"); } -function getImageSrc( $event, $frame, $scale=SCALE_BASE, $captureOnly=false, $overwrite=false ) { - $Event = new ZM\Event( $event ); - return $Event->getImageSrc( $frame, $scale, $captureOnly, $overwrite ); +function getImageSrc($event, $frame, $scale=SCALE_BASE, $captureOnly=false, $overwrite=false) { + $Event = new ZM\Event($event); + return $Event->getImageSrc($frame, $scale, $captureOnly, $overwrite); } -function viewImagePath( $path, $querySep='&' ) { - return( '?view=image'.$querySep.'path='.$path ); +function viewImagePath($path, $querySep='&') { + return '?view=image'.$querySep.'path='.$path; } -function createListThumbnail( $event, $overwrite=false ) { +function createListThumbnail($event, $overwrite=false) { # Load the frame with the highest score to use as a thumbnail - if ( !($frame = dbFetchOne( "SELECT * FROM Frames WHERE EventId=? AND Score=? ORDER BY FrameId LIMIT 1", NULL, array( $event['Id'], $event['MaxScore'] ) )) ) - return( false ); + if ( !($frame = dbFetchOne('SELECT * FROM Frames WHERE EventId=? AND Score=? ORDER BY FrameId LIMIT 1', NULL, array($event['Id'], $event['MaxScore']) )) ) + return false; $frameId = $frame['FrameId']; @@ -908,12 +901,12 @@ function createListThumbnail( $event, $overwrite=false ) { $scale = (SCALE_BASE*ZM_WEB_LIST_THUMB_HEIGHT)/$event['Height']; $thumbWidth = reScale( $event['Width'], $scale ); } else { - ZM\Fatal( "No thumbnail width or height specified, please check in Options->Web" ); + ZM\Fatal('No thumbnail width or height specified, please check in Options->Web'); } - $imageData = getImageSrc( $event, $frame, $scale, false, $overwrite ); - if ( ! $imageData ) { - return ( false ); + $imageData = getImageSrc($event, $frame, $scale, false, $overwrite); + if ( !$imageData ) { + return false; } $thumbData = $frame; @@ -921,24 +914,24 @@ function createListThumbnail( $event, $overwrite=false ) { $thumbData['Width'] = (int)$thumbWidth; $thumbData['Height'] = (int)$thumbHeight; - return( $thumbData ); + return $thumbData; } -function createVideo( $event, $format, $rate, $scale, $overwrite=false ) { - $command = ZM_PATH_BIN."/zmvideo.pl -e ".$event['Id']." -f ".$format." -r ".sprintf( "%.2F", ($rate/RATE_BASE) ); - if ( preg_match( '/\d+x\d+/', $scale ) ) - $command .= " -S ".$scale; +function createVideo($event, $format, $rate, $scale, $overwrite=false) { + $command = ZM_PATH_BIN.'/zmvideo.pl -e '.$event['Id'].' -f '.$format.' -r '.sprintf('%.2F', ($rate/RATE_BASE)); + if ( preg_match('/\d+x\d+/', $scale) ) + $command .= ' -S '.$scale; else - if ( version_compare( phpversion(), "4.3.10", ">=") ) - $command .= " -s ".sprintf( "%.2F", ($scale/SCALE_BASE) ); + if ( version_compare(phpversion(), '4.3.10', '>=') ) + $command .= ' -s '.sprintf('%.2F', ($scale/SCALE_BASE)); else - $command .= " -s ".sprintf( "%.2f", ($scale/SCALE_BASE) ); + $command .= ' -s '.sprintf('%.2f', ($scale/SCALE_BASE)); if ( $overwrite ) - $command .= " -o"; - $command = escapeshellcmd( $command ); - $result = exec( $command, $output, $status ); + $command .= ' -o'; + $command = escapeshellcmd($command); + $result = exec($command, $output, $status); Logger::Debug("generating Video $command: result($result outptu:(".implode("\n", $output )." status($status"); - return( $status?"":rtrim($result) ); + return $status ? '' : rtrim($result); } # This takes more than one scale amount, so it runs through each and alters dimension. @@ -950,38 +943,38 @@ function reScale( $dimension, $dummy ) { if ( !empty($scale) && ($scale != 'auto') && ($scale != SCALE_BASE) ) $new_dimension = (int)(($new_dimension*$scale)/SCALE_BASE); } - return( $new_dimension ); + return $new_dimension; } -function deScale( $dimension, $dummy ) { +function deScale($dimension, $dummy) { $new_dimension = $dimension; for ( $i = 1; $i < func_num_args(); $i++ ) { - $scale = func_get_arg( $i ); + $scale = func_get_arg($i); if ( !empty($scale) && $scale != SCALE_BASE ) $new_dimension = (int)(($new_dimension*SCALE_BASE)/$scale); } - return( $new_dimension ); + return $new_dimension; } function monitorLimitSql() { global $user; if ( !empty($user['MonitorIds']) ) - $midSql = " and MonitorId in (".join( ",", preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) ).")"; + $midSql = ' AND MonitorId IN ('.join(',', preg_split('/["\'\s]*,["\'\s]*/', $user['MonitorIds'])).')'; else $midSql = ''; - return( $midSql ); + return $midSql; } -function parseSort( $saveToSession=false, $querySep='&' ) { +function parseSort($saveToSession=false, $querySep='&') { global $sortQuery, $sortColumn, $sortOrder, $limitQuery; // Outputs - if (isset($_REQUEST['filter']['Query']['sort_field'])) { //Handle both new and legacy filter passing + if ( isset($_REQUEST['filter']['Query']['sort_field']) ) { //Handle both new and legacy filter passing $_REQUEST['sort_field'] = $_REQUEST['filter']['Query']['sort_field']; } - if (isset($_REQUEST['filter']['Query']['sort_asc'])) { + if ( isset($_REQUEST['filter']['Query']['sort_asc']) ) { $_REQUEST['sort_asc'] = $_REQUEST['filter']['Query']['sort_asc']; } - if (isset($_REQUEST['filter']['Query']['limit'])) { + if ( isset($_REQUEST['filter']['Query']['limit']) ) { $_REQUEST['limit'] = $_REQUEST['filter']['Query']['limit']; } if ( empty($_REQUEST['sort_field']) ) { @@ -1059,7 +1052,7 @@ function parseSort( $saveToSession=false, $querySep='&' ) { } if ( !$_REQUEST['sort_asc'] ) $_REQUEST['sort_asc'] = 0; - $sortOrder = $_REQUEST['sort_asc']?'asc':'desc'; + $sortOrder = $_REQUEST['sort_asc'] ? 'asc' : 'desc'; $sortQuery = $querySep.'sort_field='.validHtmlStr($_REQUEST['sort_field']).$querySep.'sort_asc='.validHtmlStr($_REQUEST['sort_asc']); if ( !isset($_REQUEST['limit']) ) $_REQUEST['limit'] = ''; @@ -1068,7 +1061,7 @@ function parseSort( $saveToSession=false, $querySep='&' ) { $_SESSION['sort_asc'] = validHtmlStr($_REQUEST['sort_asc']); } if ($_REQUEST['limit'] != '') { - $limitQuery = "&limit=".validInt($_REQUEST['limit']); + $limitQuery = '&limit='.validInt($_REQUEST['limit']); } } @@ -1088,12 +1081,12 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { $StorageArea = NULL; $terms = isset($filter['Query']) ? $filter['Query']['terms'] : NULL; - if ( ! isset($terms) ) { - $backTrace = debug_backtrace(); - $file = $backTrace[1]['file']; - $line = $backTrace[1]['line']; - ZM\Warning("No terms in filter from $file:$line"); - ZM\Warning(print_r($filter,true)); + if ( !isset($terms) ) { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + ZM\Warning("No terms in filter from $file:$line"); + ZM\Warning(print_r($filter, true)); } if ( isset($terms) && count($terms) ) { for ( $i = 0; $i < count($terms); $i++ ) { @@ -1132,13 +1125,13 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { $filter['sql'] .= 'E.StartTime'; break; case 'Date': - $filter['sql'] .= 'to_days( E.StartTime )'; + $filter['sql'] .= 'to_days(E.StartTime)'; break; case 'Time': - $filter['sql'] .= 'extract( hour_second from E.StartTime )'; + $filter['sql'] .= 'extract(hour_second FROM E.StartTime)'; break; case 'Weekday': - $filter['sql'] .= 'weekday( E.StartTime )'; + $filter['sql'] .= 'weekday(E.StartTime)'; break; # Starting Time case 'StartDateTime': @@ -1148,26 +1141,26 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { $filter['sql'] .= 'F.EventId'; break; case 'StartDate': - $filter['sql'] .= 'to_days( E.StartTime )'; + $filter['sql'] .= 'to_days(E.StartTime)'; break; case 'StartTime': - $filter['sql'] .= 'extract( hour_second from E.StartTime )'; + $filter['sql'] .= 'extract(hour_second FROM E.StartTime)'; break; case 'StartWeekday': - $filter['sql'] .= 'weekday( E.StartTime )'; + $filter['sql'] .= 'weekday(E.StartTime)'; break; # Ending Time case 'EndDateTime': $filter['sql'] .= 'E.EndTime'; break; case 'EndDate': - $filter['sql'] .= 'to_days( E.EndTime )'; + $filter['sql'] .= 'to_days(E.EndTime)'; break; case 'EndTime': - $filter['sql'] .= 'extract( hour_second from E.EndTime )'; + $filter['sql'] .= 'extract(hour_second FROM E.EndTime)'; break; case 'EndWeekday': - $filter['sql'] .= 'weekday( E.EndTime )'; + $filter['sql'] .= 'weekday(E.EndTime)'; break; case 'Id': case 'Name': @@ -1191,7 +1184,13 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { // Need to specify a storage area, so need to look through other terms looking for a storage area, else we default to ZM_EVENTS_PATH if ( ! $StorageArea ) { for ( $j = 0; $j < count($terms); $j++ ) { - if ( isset($terms[$j]['attr']) and $terms[$j]['attr'] == 'StorageId' and isset($terms[$j]['val']) ) { + if ( + isset($terms[$j]['attr']) + and + ($terms[$j]['attr'] == 'StorageId') + and + isset($terms[$j]['val']) + ) { $StorageArea = ZM\Storage::find_one(array('Id'=>$terms[$j]['val'])); break; } @@ -1199,13 +1198,19 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { if ( ! $StorageArea ) $StorageArea = new ZM\Storage(); } // end no StorageArea found yet - $filter['sql'] .= getDiskPercent( $StorageArea->Path() ); + $filter['sql'] .= getDiskPercent($StorageArea->Path()); break; case 'DiskBlocks': // Need to specify a storage area, so need to look through other terms looking for a storage area, else we default to ZM_EVENTS_PATH if ( ! $StorageArea ) { for ( $j = $i; $j < count($terms); $j++ ) { - if ( isset($terms[$j]['attr']) and $terms[$j]['attr'] == 'StorageId' and isset($terms[$j]['val']) ) { + if ( + isset($terms[$j]['attr']) + and + ($terms[$j]['attr'] == 'StorageId') + and + isset($terms[$j]['val']) + ) { $StorageArea = ZM\Storage::find_one(array('Id'=>$terms[$j]['val'])); } } // end foreach remaining term @@ -1217,7 +1222,7 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { break; } $valueList = array(); - foreach ( preg_split( '/["\'\s]*?,["\'\s]*?/', preg_replace( '/^["\']+?(.+)["\']+?$/', '$1', $term['val'] ) ) as $value ) { + foreach ( preg_split('/["\'\s]*?,["\'\s]*?/', preg_replace('/^["\']+?(.+)["\']+?$/', '$1', $term['val'])) as $value ) { switch ( $term['attr'] ) { case 'MonitorName': case 'Name': @@ -1249,19 +1254,19 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { case 'StartDateTime': case 'EndDateTime': if ( $value != 'NULL' ) - $value = "'".strftime( STRF_FMT_DATETIME_DB, strtotime( $value ) )."'"; + $value = '\''.strftime( STRF_FMT_DATETIME_DB, strtotime( $value ) ).'\''; break; case 'Date': case 'StartDate': case 'EndDate': if ( $value != 'NULL' ) - $value = "to_days( '".strftime( STRF_FMT_DATETIME_DB, strtotime( $value ) )."' )"; + $value = 'to_days(\''.strftime(STRF_FMT_DATETIME_DB, strtotime($value)).'\')'; break; case 'Time': case 'StartTime': case 'EndTime': if ( $value != 'NULL' ) - $value = "extract( hour_second from '".strftime( STRF_FMT_DATETIME_DB, strtotime( $value ) )."' )"; + $value = 'extract(hour_second from \''.strftime(STRF_FMT_DATETIME_DB, strtotime($value)).'\')'; break; default : if ( $value != 'NULL' ) @@ -1290,10 +1295,10 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { break; case '=[]' : case 'IN' : - $filter['sql'] .= ' in ('.join( ',', $valueList ).')'; + $filter['sql'] .= ' in ('.join(',', $valueList).')'; break; case '![]' : - $filter['sql'] .= ' not in ('.join( ',', $valueList ).')'; + $filter['sql'] .= ' not in ('.join(',', $valueList).')'; break; case 'IS' : if ( $value == 'Odd' ) { @@ -1320,12 +1325,12 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { } // end if ( isset($term['attr']) ) if ( isset($term['cbr']) && (string)(int)$term['cbr'] == $term['cbr'] ) { $filter['query'] .= $querySep.urlencode("filter[Query][terms][$i][cbr]").'='.urlencode($term['cbr']); - $filter['sql'] .= ' '.str_repeat( ')', $term['cbr'] ).' '; + $filter['sql'] .= ' '.str_repeat(')', $term['cbr']).' '; $filter['fields'] .= "\n"; } } // end foreach term if ( $filter['sql'] ) - $filter['sql'] = ' and ( '.$filter['sql'].' )'; + $filter['sql'] = ' AND ( '.$filter['sql'].' )'; if ( $saveToSession ) { $_SESSION['filter'] = $filter; } @@ -1345,32 +1350,33 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { // Please note that the filter is passed in by copy, so you need to use the return value from this function. // -function addFilterTerm( $filter, $position, $term=false ) { +function addFilterTerm($filter, $position, $term=false) { if ( $position < 0 ) $position = 0; - if ( ! isset( $filter['Query']['terms'] ) ) + if ( !isset($filter['Query']['terms']) ) $filter['Query']['terms'] = array(); - elseif( $position > count($filter['Query']['terms']) ) + else if ( $position > count($filter['Query']['terms']) ) $position = count($filter['Query']['terms']); - if ( $term && $position == 0 ) - unset( $term['cnj'] ); - array_splice( $filter['Query']['terms'], $position, 0, array( $term?$term:array() ) ); - return( $filter ); + if ( $term && $position == 0 ) + unset($term['cnj']); + array_splice($filter['Query']['terms'], $position, 0, array($term ? $term : array())); + + return $filter; } -function delFilterTerm( $filter, $position ) { +function delFilterTerm($filter, $position) { if ( $position < 0 ) $position = 0; - elseif( $position >= count($filter['Query']['terms']) ) + else if ( $position >= count($filter['Query']['terms']) ) $position = count($filter['Query']['terms']); - array_splice( $filter['Query']['terms'], $position, 1 ); + array_splice($filter['Query']['terms'], $position, 1); - return( $filter ); + return $filter; } -function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' ) { +function getPagination($pages, $page, $maxShortcuts, $query, $querySep='&') { global $view; $pageText = ''; @@ -1397,7 +1403,7 @@ function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' if ( $newPage <= 1 ) break; $pagesUsed[$newPage] = true; - array_unshift( $newPages, $newPage ); + array_unshift($newPages, $newPage); } if ( !isset($pagesUsed[1]) ) array_unshift( $newPages, 1 ); @@ -1419,10 +1425,10 @@ function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' if ( $newPage > $pages ) break; $pagesUsed[$newPage] = true; - array_push( $newPages, $newPage ); + array_push($newPages, $newPage); } if ( !isset($pagesUsed[$pages]) ) - array_push( $newPages, $pages ); + array_push($newPages, $pages); foreach ( $newPages as $newPage ) { $pageText .= ' '.$newPage.''; @@ -1437,7 +1443,7 @@ function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' return $pageText; } -function sortHeader( $field, $querySep='&' ) { +function sortHeader($field, $querySep='&') { global $view; return implode($querySep, array( '?view='.$view, @@ -1452,101 +1458,101 @@ function sortHeader( $field, $querySep='&' ) { function sortTag( $field ) { if ( $_REQUEST['sort_field'] == $field ) if ( $_REQUEST['sort_asc'] ) - return( '(^)' ); + return '(^)'; else - return( '(v)' ); - return( false ); + return '(v)'; + return false; } function getLoad() { $load = sys_getloadavg(); - return( $load[0] ); + return $load[0]; } function getDiskPercent($path = ZM_DIR_EVENTS) { $total = disk_total_space($path); if ( $total === false ) { - Error('disk_total_space returned false. Verify the web account user has access to ' . $path ); + Error('disk_total_space returned false. Verify the web account user has access to ' . $path); return 0; } elseif ( $total == 0 ) { - Error('disk_total_space indicates the following path has a filesystem size of zero bytes ' . $path ); + Error('disk_total_space indicates the following path has a filesystem size of zero bytes ' . $path); return 100; } $free = disk_free_space($path); if ( $free === false ) { - Error('disk_free_space returned false. Verify the web account user has access to ' . $path ); + Error('disk_free_space returned false. Verify the web account user has access to ' . $path); } $space = round((($total - $free) / $total) * 100); - return( $space ); + return $space; } function getDiskBlocks() { - if ( ! $StorageArea ) $StorageArea = new ZM\Storage(); - $df = shell_exec( 'df '.escapeshellarg($StorageArea->Path() )); + if ( !$StorageArea ) $StorageArea = new ZM\Storage(); + $df = shell_exec('df '.escapeshellarg($StorageArea->Path())); $space = -1; - if ( preg_match( '/\s(\d+)\s+\d+\s+\d+%/ms', $df, $matches ) ) + if ( preg_match('/\s(\d+)\s+\d+\s+\d+%/ms', $df, $matches) ) $space = $matches[1]; - return( $space ); + return $space; } function systemStats() { - $load = getLoad(); - $diskPercent = getDiskPercent(); - $pathMapPercent = getDiskPercent(ZM_PATH_MAP); - $cpus = getcpus(); + $load = getLoad(); + $diskPercent = getDiskPercent(); + $pathMapPercent = getDiskPercent(ZM_PATH_MAP); + $cpus = getcpus(); - $normalized_load = $load / $cpus; + $normalized_load = $load / $cpus; - # Colorize the system load stat - if ( $normalized_load <= 0.75 ) { - $htmlLoad=$load; - } elseif ( $normalized_load <= 0.9 ) { - $htmlLoad="$load"; - } elseif ( $normalized_load <= 1.1 ) { - $htmlLoad="$load"; + # Colorize the system load stat + if ( $normalized_load <= 0.75 ) { + $htmlLoad = $load; + } else if ( $normalized_load <= 0.9 ) { + $htmlLoad = "$load"; + } else if ( $normalized_load <= 1.1 ) { + $htmlLoad = "$load"; + } else { + $htmlLoad = "$load"; + } + + # Colorize the disk space stat + if ( $diskPercent < 98 ) { + $htmlDiskPercent = $diskPercent.'%'; + } else if ( $diskPercent <= 99 ) { + $htmlDiskPercent = "$diskPercent%"; + } else { + $htmlDiskPercent = "$diskPercent%"; + } + + # Colorize the PATH_MAP (usually /dev/shm) stat + if ( $pathMapPercent < 90 ) { + if ( disk_free_space(ZM_PATH_MAP) > 209715200 ) { # have to always have at least 200MiB free + $htmlPathMapPercent = $pathMapPercent.'%'; } else { - $htmlLoad="$load"; + $htmlPathMapPercent = "$pathMapPercent%"; } + } else if ( $pathMapPercent < 100 ) { + $htmlPathMapPercent = "$pathMapPercent%"; + } else { + $htmlPathMapPercent = "$pathMapPercent%"; + } - # Colorize the disk space stat - if ( $diskPercent < 98 ) { - $htmlDiskPercent="$diskPercent%"; - } elseif ( $diskPercent <= 99 ) { - $htmlDiskPercent="$diskPercent%"; - } else { - $htmlDiskPercent="$diskPercent%"; - } + $htmlString = translate('Load').": $htmlLoad - ".translate('Disk').": $htmlDiskPercent - ".ZM_PATH_MAP.": $htmlPathMapPercent"; - # Colorize the PATH_MAP (usually /dev/shm) stat - if ( $pathMapPercent < 90 ) { - if ( disk_free_space(ZM_PATH_MAP) > 209715200 ) { # have to always have at least 200MiB free - $htmlPathMapPercent="$pathMapPercent%"; - } else { - $htmlPathMapPercent="$pathMapPercent%"; - } - } elseif ( $pathMapPercent < 100 ) { - $htmlPathMapPercent="$pathMapPercent%"; - } else { - $htmlPathMapPercent="$pathMapPercent%"; - } - - $htmlString = translate('Load').": $htmlLoad - ".translate('Disk').": $htmlDiskPercent - ".ZM_PATH_MAP.": $htmlPathMapPercent"; - - return( $htmlString ); + return $htmlString; } function getcpus() { - if (is_readable("/proc/cpuinfo") ) { # Works on Linux - preg_match_all('/^processor/m', file_get_contents('/proc/cpuinfo'), $matches); - $num_cpus = count($matches[0]); - } else { # Works on BSD - $matches = explode(":", shell_exec("sysctl hw.ncpu")); - $num_cpus = trim($matches[1]); - } + if ( is_readable('/proc/cpuinfo') ) { # Works on Linux + preg_match_all('/^processor/m', file_get_contents('/proc/cpuinfo'), $matches); + $num_cpus = count($matches[0]); + } else { # Works on BSD + $matches = explode(':', shell_exec('sysctl hw.ncpu')); + $num_cpus = trim($matches[1]); + } - return( $num_cpus ); + return $num_cpus; } // Function to fix a problem whereby the built in PHP session handling @@ -1554,37 +1560,37 @@ function getcpus() { // fieldset tag, neither of which will work with strict XHTML Basic. function sidField() { if ( SID ) { - list( $sessname, $sessid ) = explode( "=", SID ); + list($sessname, $sessid) = explode('=', SID); ?> '; - return( false ); + return false; } $dx1 = $line1[1]['x'] - $line1[0]['x']; @@ -1639,54 +1645,54 @@ function linesIntersect( $line1, $line2 ) { if ( $x >= $min_x1 && $x <= $max_x1 && $x >= $min_x2 && $x <= $max_x2 ) { if ( $debug ) echo "Intersecting, at x $x
"; - return( true ); + return true; } else { if ( $debug ) echo "Not intersecting, out of range at x $x
"; - return( false ); + return false; } } elseif ( $b1 == $b2 ) { // Colinear, must overlap due to box check, intersect? if ( $debug ) echo 'Intersecting, colinear
'; - return( true ); + return true; } else { // Parallel if ( $debug ) echo 'Not intersecting, parallel
'; - return( false ); + return false; } } elseif ( !$dx1 ) { // Line 1 is vertical $y = ( $m2 * $line1[0]['x'] ) * $b2; if ( $y >= $min_y1 && $y <= $max_y1 ) { if ( $debug ) echo "Intersecting, at y $y
"; - return( true ); + return true; } else { if ( $debug ) echo "Not intersecting, out of range at y $y
"; - return( false ); + return false; } } elseif ( !$dx2 ) { // Line 2 is vertical $y = ( $m1 * $line2[0]['x'] ) * $b1; if ( $y >= $min_y2 && $y <= $max_y2 ) { if ( $debug ) echo "Intersecting, at y $y
"; - return( true ); + return true; } else { if ( $debug ) echo "Not intersecting, out of range at y $y
"; - return( false ); + return false; } } else { // Both lines are vertical if ( $line1[0]['x'] == $line2[0]['x'] ) { // Colinear, must overlap due to box check, intersect? if ( $debug ) echo 'Intersecting, vertical, colinear
'; - return( true ); + return true; } else { // Parallel if ( $debug ) echo 'Not intersecting, vertical, parallel
'; - return( false ); + return false; } } if ( $debug ) echo 'Whoops, unexpected scenario
'; - return( false ); + return false; } -function isSelfIntersecting( $points ) { +function isSelfIntersecting($points) { global $debug; $n_coords = count($points); @@ -1698,20 +1704,20 @@ function isSelfIntersecting( $points ) { for ( $i = 0; $i <= ($n_coords-2); $i++ ) { for ( $j = $i+2; $j < $n_coords+min(0,$i-1); $j++ ) { if ( $debug ) echo "Checking $i and $j
"; - if ( linesIntersect( $edges[$i], $edges[$j] ) ) { + if ( linesIntersect($edges[$i], $edges[$j]) ) { if ( $debug ) echo "Lines $i and $j intersect
"; - return( true ); + return true; } } } - return( false ); + return false; } -function getPolyCentre( $points, $area=0 ) { +function getPolyCentre($points, $area=0) { $cx = 0.0; $cy = 0.0; if ( !$area ) - $area = getPolyArea( $points ); + $area = getPolyArea($points); for ( $i = 0, $j = count($points)-1; $i < count($points); $j = $i++ ) { $ct = ($points[$i]['x'] * $points[$j]['y']) - ($points[$j]['x'] * $points[$i]['y']); $cx += ($points[$i]['x'] + $points[$j]['x']) * ct; @@ -1720,21 +1726,21 @@ function getPolyCentre( $points, $area=0 ) { $cx = intval(round(abs($cx/(6.0*$area)))); $cy = intval(round(abs($cy/(6.0*$area)))); printf( "X:%cx, Y:$cy
" ); - return( array( 'x'=>$cx, 'y'=>$cy ) ); + return array('x'=>$cx, 'y'=>$cy); } -function _CompareXY( $a, $b ) { +function _CompareXY($a, $b) { if ( $a['min_y'] == $b['min_y'] ) - return( intval($a['min_x'] - $b['min_x']) ); + return intval($a['min_x'] - $b['min_x']); else - return( intval($a['min_y'] - $b['min_y']) ); + return intval($a['min_y'] - $b['min_y']); } -function _CompareX( $a, $b ) { - return( intval($a['min_x'] - $b['min_x']) ); +function _CompareX($a, $b) { + return intval($a['min_x'] - $b['min_x']); } -function getPolyArea( $points ) { +function getPolyArea($points) { global $debug; $n_coords = count($points); @@ -1760,11 +1766,16 @@ function getPolyArea( $points ) { ); } - usort( $global_edges, '_CompareXY' ); + usort($global_edges, '_CompareXY'); if ( $debug ) { for ( $i = 0; $i < count($global_edges); $i++ ) { - printf( '%d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f
', $i, $global_edges[$i]['min_y'], $global_edges[$i]['max_y'], $global_edges[$i]['min_x'], $global_edges[$i]['_1_m'] ); + printf('%d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f
', + $i, + $global_edges[$i]['min_y'], + $global_edges[$i]['max_y'], + $global_edges[$i]['min_x'], + $global_edges[$i]['_1_m']); } } @@ -1774,18 +1785,23 @@ function getPolyArea( $points ) { do { for ( $i = 0; $i < count($global_edges); $i++ ) { if ( $global_edges[$i]['min_y'] == $y ) { - if ( $debug ) printf( 'Moving global edge
' ); + if ( $debug ) printf('Moving global edge
'); $active_edges[] = $global_edges[$i]; - array_splice( $global_edges, $i, 1 ); + array_splice($global_edges, $i, 1); $i--; } else { break; } } - usort( $active_edges, '_CompareX' ); + usort($active_edges, '_CompareX'); if ( $debug ) { for ( $i = 0; $i < count($active_edges); $i++ ) { - printf( '%d - %d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f
', $y, $i, $active_edges[$i]['min_y'], $active_edges[$i]['max_y'], $active_edges[$i]['min_x'], $active_edges[$i]['_1_m'] ); + printf('%d - %d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f
', + $y, $i, + $active_edges[$i]['min_y'], + $active_edges[$i]['max_y'], + $active_edges[$i]['min_x'], + $active_edges[$i]['_1_m']); } } $last_x = 0; @@ -1801,23 +1817,23 @@ function getPolyArea( $points ) { $parity = !$parity; $last_x = $x; } - if ( $debug ) printf( '%d: Area:%d
', $y, $row_area ); + if ( $debug ) printf('%d: Area:%d
', $y, $row_area); $y++; for ( $i = 0; $i < count($active_edges); $i++ ) { if ( $y >= $active_edges[$i]['max_y'] ) { // Or >= as per sheets - if ( $debug ) printf( 'Deleting active_edge
' ); - array_splice( $active_edges, $i, 1 ); + if ( $debug ) printf('Deleting active_edge
'); + array_splice($active_edges, $i, 1); $i--; } else { $active_edges[$i]['min_x'] += $active_edges[$i]['_1_m']; } } } while ( count($global_edges) || count($active_edges) ); - if ( $debug ) printf( 'Area:%d
', $area ); - return( $area ); + if ( $debug ) printf('Area:%d
', $area); + return $area; } -function getPolyAreaOld( $points ) { +function getPolyAreaOld($points) { $area = 0.0; $edge = 0.0; for ( $i = 0, $j = count($points)-1; $i < count($points); $j = $i++ ) { @@ -1828,174 +1844,179 @@ function getPolyAreaOld( $points ) { $edge += $trap_edge; $trap_area = ($x_diff * $y_sum ); $area += $trap_area; - printf( "%d->%d, %d-%d=%.2f, %d+%d=%.2f(%.2f), %.2f, %.2f
", i, j, $points[$i]['x'], $points[$j]['x'], $x_diff, $points[$i]['y'], $points[$j]['y'], $y_sum, $y_diff, $trap_area, $trap_edge ); + printf('%d->%d, %d-%d=%.2f, %d+%d=%.2f(%.2f), %.2f, %.2f
', + $i, $j, + $points[$i]['x'], $points[$j]['x'], + $x_diff, + $points[$i]['y'], $points[$j]['y'], + $y_sum, $y_diff, $trap_area, $trap_edge); } $edge = intval(round(abs($edge))); $area = intval(round((abs($area)+$edge)/2)); echo "E:$edge
"; echo "A:$area
"; - return( $area ); + return $area; } -function mapCoords( $a ) { - return( $a['x'].",".$a['y'] ); +function mapCoords($a) { + return $a['x'].','.$a['y']; } -function pointsToCoords( $points ) { - return( join( ' ', array_map( 'mapCoords', $points ) ) ); +function pointsToCoords($points) { + return join(' ', array_map('mapCoords', $points)); } -function coordsToPoints( $coords ) { +function coordsToPoints($coords) { $points = array(); - if ( preg_match_all( '/(\d+,\d+)+/', $coords, $matches ) ) { + if ( preg_match_all('/(\d+,\d+)+/', $coords, $matches) ) { for ( $i = 0; $i < count($matches[1]); $i++ ) { - if ( preg_match( '/(\d+),(\d+)/', $matches[1][$i], $cmatches ) ) { - $points[] = array( 'x'=>$cmatches[1], 'y'=>$cmatches[2] ); + if ( preg_match('/(\d+),(\d+)/', $matches[1][$i], $cmatches) ) { + $points[] = array('x'=>$cmatches[1], 'y'=>$cmatches[2]); } else { - echo( "Bogus coordinates '".$matches[$i]."'" ); - return( false ); + echo("Bogus coordinates '".$matches[$i]."'"); + return false; } } } else { - echo( "Bogus coordinate string '$coords'" ); - return( false ); + echo("Bogus coordinate string '$coords'"); + return false; } - return( $points ); + return $points; } -function limitPoints( &$points, $min_x, $min_y, $max_x, $max_y ) { +function limitPoints(&$points, $min_x, $min_y, $max_x, $max_y) { foreach ( $points as &$point ) { if ( $point['x'] < $min_x ) { - ZM\Logger::Debug('Limiting point x'.$point['x'].' to min_x ' . $min_x ); + ZM\Logger::Debug('Limiting point x'.$point['x'].' to min_x '.$min_x); $point['x'] = $min_x; } else if ( $point['x'] > $max_x ) { - ZM\Logger::Debug('Limiting point x'.$point['x'].' to max_x ' . $max_x ); + ZM\Logger::Debug('Limiting point x'.$point['x'].' to max_x '.$max_x); $point['x'] = $max_x; } if ( $point['y'] < $min_y ) { - ZM\Logger::Debug('Limiting point y'.$point['y'].' to min_y ' . $min_y ); + ZM\Logger::Debug('Limiting point y'.$point['y'].' to min_y '.$min_y); $point['y'] = $min_y; } else if ( $point['y'] > $max_y ) { - ZM\Logger::Debug('Limiting point y'.$point['y'].' to max_y ' . $max_y ); + ZM\Logger::Debug('Limiting point y'.$point['y'].' to max_y '.$max_y); $point['y'] = $max_y; } } // end foreach point } // end function limitPoints( $points, $min_x, $min_y, $max_x, $max_y ) -function scalePoints( &$points, $scale ) { +function scalePoints(&$points, $scale) { foreach ( $points as &$point ) { - $point['x'] = reScale( $point['x'], $scale ); - $point['y'] = reScale( $point['y'], $scale ); + $point['x'] = reScale($point['x'], $scale); + $point['y'] = reScale($point['y'], $scale); } } function getLanguages() { $langs = array(); foreach ( glob('lang/*_*.php') as $file ) { - preg_match( '/([^\/]+_.+)\.php/', $file, $matches ); + preg_match('/([^\/]+_.+)\.php/', $file, $matches); $langs[$matches[1]] = $matches[1]; } - return( $langs ); + return $langs; } -function trimString( $string, $length ) { - return( preg_replace( '/^(.{'.$length.',}?)\b.*$/', '\\1…', $string ) ); +function trimString($string, $length) { + return preg_replace('/^(.{'.$length.',}?)\b.*$/', '\\1…', $string); } -function monitorIdsToNames( $ids ) { +function monitorIdsToNames($ids) { global $mITN_monitors; if ( !$mITN_monitors ) { - $sql = 'select Id, Name from Monitors'; - foreach( dbFetchAll( $sql ) as $monitor ) { + $sql = 'SELECT Id, Name FROM Monitors'; + foreach ( dbFetchAll($sql) as $monitor ) { $mITN_monitors[$monitor['Id']] = $monitor; } } $names = array(); if ( ! is_array($ids) ) { - $ids = preg_split( '/\s*,\s*/', $ids ); + $ids = preg_split('/\s*,\s*/', $ids); } foreach ( $ids as $id ) { - if ( visibleMonitor( $id ) ) { + if ( visibleMonitor($id) ) { if ( isset($mITN_monitors[$id]) ) { $names[] = $mITN_monitors[$id]['Name']; } } } - $name_string = join( ', ', $names ); - return( $name_string ); + $name_string = join(', ', $names); + return $name_string; } function initX10Status() { global $x10_status; if ( !isset($x10_status) ) { - $socket = socket_create( AF_UNIX, SOCK_STREAM, 0 ); + $socket = socket_create(AF_UNIX, SOCK_STREAM, 0); if ( $socket < 0 ) { - ZM\Fatal( 'socket_create() failed: '.socket_strerror($socket) ); + ZM\Fatal('socket_create() failed: '.socket_strerror($socket)); } $sock_file = ZM_PATH_SOCKS.'/zmx10.sock'; - if ( @socket_connect( $socket, $sock_file ) ) { + if ( @socket_connect($socket, $sock_file) ) { $command = 'status'; - if ( !socket_write( $socket, $command ) ) { - ZM\Fatal( "Can't write to control socket: ".socket_strerror(socket_last_error($socket)) ); + if ( !socket_write($socket, $command) ) { + ZM\Fatal("Can't write to control socket: ".socket_strerror(socket_last_error($socket))); } - socket_shutdown( $socket, 1 ); + socket_shutdown($socket, 1); $x10Output = ''; - while ( $x10Response = socket_read( $socket, 256 ) ) { + while ( $x10Response = socket_read($socket, 256) ) { $x10Output .= $x10Response; } - socket_close( $socket ); + socket_close($socket); } else { // Can't connect so use script - $command = ZM_PATH_BIN."/zmx10.pl --command status"; + $command = ZM_PATH_BIN.'/zmx10.pl --command status'; //$command .= " 2>/dev/null >&- <&- >/dev/null"; - $x10Output = exec( escapeshellcmd( $command ) ); + $x10Output = exec(escapeshellcmd($command)); } - foreach ( explode( "\n", $x10Output ) as $x10Response ) { - if ( preg_match( "/^(\d+)\s+(.+)$/", $x10Response, $matches ) ) { + foreach ( explode("\n", $x10Output) as $x10Response ) { + if ( preg_match('/^(\d+)\s+(.+)$/', $x10Response, $matches) ) { $x10_status[$matches[1]] = $matches[2]; } } } } -function getDeviceStatusX10( $key ) { +function getDeviceStatusX10($key) { global $x10_status; initX10Status(); if ( empty($x10_status[$key]) || !($status = $x10_status[$key]) ) $status = 'unknown'; - return( $status ); + return $status; } -function setDeviceStatusX10( $key, $status ) { - $socket = socket_create( AF_UNIX, SOCK_STREAM, 0 ); +function setDeviceStatusX10($key, $status) { + $socket = socket_create(AF_UNIX, SOCK_STREAM, 0); if ( $socket < 0 ) { ZM\Fatal( 'socket_create() failed: '.socket_strerror($socket) ); } $sock_file = ZM_PATH_SOCKS.'/zmx10.sock'; - if ( @socket_connect( $socket, $sock_file ) ) { + if ( @socket_connect($socket, $sock_file) ) { $command = "$status;$key"; - if ( !socket_write( $socket, $command ) ) { - ZM\Fatal( "Can't write to control socket: ".socket_strerror(socket_last_error($socket)) ); + if ( !socket_write($socket, $command) ) { + ZM\Fatal('Can\'t write to control socket: '.socket_strerror(socket_last_error($socket))); } - socket_shutdown( $socket, 1 ); - $x10Response = socket_read( $socket, 256 ); - socket_close( $socket ); + socket_shutdown($socket, 1); + $x10Response = socket_read($socket, 256); + socket_close($socket); } else { // Can't connect so use script - $command = ZM_PATH_BIN.'/zmx10.pl --command '.escapeshellarg( $status ); + $command = ZM_PATH_BIN.'/zmx10.pl --command '.escapeshellarg($status); $command .= ' --unit-code '.escapeshellarg( $key ); //$command .= " 2>/dev/null >&- <&- >/dev/null"; - $x10Response = exec( $command ); + $x10Response = exec($command); } - if ( preg_match( '/^'.$key.'\s+(.*)/', $x10Response, $matches ) ) + if ( preg_match('/^'.$key.'\s+(.*)/', $x10Response, $matches) ) $status = $matches[1]; else $status = 'unknown'; - return( $status ); + return $status; } function logState() { @@ -2029,15 +2050,15 @@ function logState() { return $state; } -function isVector ( &$array ) { +function isVector(&$array) { $next_key = 0; foreach ( array_keys($array) as $key ) { - if ( !is_int( $key ) ) - return( false ); + if ( !is_int($key) ) + return false; if ( $key != $next_key++ ) - return( false ); + return false; } - return( true ); + return true; } function checkJsonError($value) { @@ -2045,62 +2066,62 @@ function checkJsonError($value) { $value = var_export($value,true); switch( json_last_error() ) { case JSON_ERROR_DEPTH : - ZM\Fatal( "Unable to decode JSON string '$value', maximum stack depth exceeded" ); + ZM\Fatal("Unable to decode JSON string '$value', maximum stack depth exceeded"); case JSON_ERROR_CTRL_CHAR : - ZM\Fatal( "Unable to decode JSON string '$value', unexpected control character found" ); + ZM\Fatal("Unable to decode JSON string '$value', unexpected control character found"); case JSON_ERROR_STATE_MISMATCH : - ZM\Fatal( "Unable to decode JSON string '$value', invalid or malformed JSON" ); + ZM\Fatal("Unable to decode JSON string '$value', invalid or malformed JSON"); case JSON_ERROR_SYNTAX : - ZM\Fatal( "Unable to decode JSON string '$value', syntax error" ); + ZM\Fatal("Unable to decode JSON string '$value', syntax error"); default : - ZM\Fatal( "Unable to decode JSON string '$value', unexpected error ".json_last_error() ); + ZM\Fatal("Unable to decode JSON string '$value', unexpected error ".json_last_error()); case JSON_ERROR_NONE: break; } } } -function jsonEncode( &$value ) { +function jsonEncode(&$value) { if ( function_exists('json_encode') ) { $string = json_encode( $value ); checkJsonError($value); - return( $string ); + return $string; } switch ( gettype($value) ) { case 'double': case 'integer': - return( $value ); + return $value; case 'boolean': - return( $value?'true':'false' ); + return $value ? 'true' : 'false'; case 'string': - return( '"'.preg_replace( "/\r?\n/", '\\n', addcslashes($value,'"\\/') ).'"' ); + return '"'.preg_replace("/\r?\n/", '\\n', addcslashes($value,'"\\/')).'"'; case 'NULL': - return( 'null' ); + return 'null'; case 'object': - return( '"Object '.addcslashes(get_class($value),'"\\/').'"' ); + return '"Object '.addcslashes(get_class($value),'"\\/').'"'; case 'array': if ( isVector( $value ) ) - return( '['.join( ',', array_map( 'jsonEncode', $value) ).']' ); + return '['.join(',', array_map('jsonEncode', $value)).']'; else { $result = '{'; foreach ($value as $subkey => $subvalue ) { if ( $result != '{' ) $result .= ','; - $result .= '"'.$subkey.'":'.jsonEncode( $subvalue ); + $result .= '"'.$subkey.'":'.jsonEncode($subvalue); } - return( $result.'}' ); + return $result.'}'; } default: - return( '"'.addcslashes(gettype($value),'"\\/').'"' ); + return '"'.addcslashes(gettype($value),'"\\/').'"'; } } -function jsonDecode( $value ) { +function jsonDecode($value) { if ( function_exists('json_decode') ) { - $object = json_decode( $value, true ); + $object = json_decode($value, true); checkJsonError($value); - return( $object ); + return $object; } $comment = false; @@ -2132,57 +2153,57 @@ function jsonDecode( $value ) { $comment = !$comment; } } - eval( $out.';' ); - return( $result ); + eval($out.';'); + return $result; } -define( 'HTTP_STATUS_OK', 200 ); -define( 'HTTP_STATUS_BAD_REQUEST', 400 ); -define( 'HTTP_STATUS_FORBIDDEN', 403 ); +define('HTTP_STATUS_OK', 200); +define('HTTP_STATUS_BAD_REQUEST', 400); +define('HTTP_STATUS_FORBIDDEN', 403); -function ajaxError( $message, $code=HTTP_STATUS_OK ) { - ZM\Error( $message ); - if ( function_exists( 'ajaxCleanup' ) ) +function ajaxError($message, $code=HTTP_STATUS_OK) { + ZM\Error($message); + if ( function_exists('ajaxCleanup') ) ajaxCleanup(); if ( $code == HTTP_STATUS_OK ) { - $response = array( 'result'=>'Error', 'message'=>$message ); - header( 'Content-type: text/plain' ); - exit( jsonEncode( $response ) ); + $response = array('result'=>'Error', 'message'=>$message); + header('Content-type: text/plain'); + exit(jsonEncode($response)); } - header( "HTTP/1.0 $code $message" ); + header("HTTP/1.0 $code $message"); exit(); } -function ajaxResponse( $result=false ) { - if ( function_exists( 'ajaxCleanup' ) ) +function ajaxResponse($result=false) { + if ( function_exists('ajaxCleanup') ) ajaxCleanup(); - $response = array( 'result'=>'Ok' ); - if ( is_array( $result ) ) { - $response = array_merge( $response, $result ); - } elseif ( !empty($result) ) { + $response = array('result'=>'Ok'); + if ( is_array($result) ) { + $response = array_merge($response, $result); + } else if ( !empty($result) ) { $response['message'] = $result; } - header( 'Content-type: text/plain' ); - exit( jsonEncode( $response ) ); + header('Content-type: text/plain'); + exit(jsonEncode($response)); } function generateConnKey() { - return( rand( 1, 999999 ) ); + return rand(1, 999999); } -function detaintPath( $path ) { +function detaintPath($path) { // Remove any absolute paths, or relative ones that want to go up - $path = preg_replace( '/\.(?:\.+[\\/][\\/]*)+/', '', $path ); - $path = preg_replace( '/^[\\/]+/', '', $path ); - return( $path ); + $path = preg_replace('/\.(?:\.+[\\/][\\/]*)+/', '', $path); + $path = preg_replace('/^[\\/]+/', '', $path); + return $path; } -function cache_bust( $file ) { +function cache_bust($file) { # Use the last modified timestamp to create a link that gets a different filename # To defeat caching. Should probably use md5 hash $parts = pathinfo($file); global $css; - $dirname = preg_replace( '/\//', '_', $parts['dirname'] ); + $dirname = preg_replace('/\//', '_', $parts['dirname']); $cacheFile = $dirname.'_'.$parts['filename'].'-'.$css.'-'.filemtime($file).'.'.$parts['extension']; if ( file_exists(ZM_DIR_CACHE.'/'.$cacheFile) or symlink(ZM_PATH_WEB.'/'.$file, ZM_DIR_CACHE.'/'.$cacheFile) ) { return 'cache/'.$cacheFile; @@ -2192,23 +2213,23 @@ function cache_bust( $file ) { return $file; } -function getSkinFile( $file ) { +function getSkinFile($file) { global $skinBase; $skinFile = false; foreach ( $skinBase as $skin ) { - $tempSkinFile = detaintPath( 'skins'.'/'.$skin.'/'.$file ); - if ( file_exists( $tempSkinFile ) ) + $tempSkinFile = detaintPath('skins'.'/'.$skin.'/'.$file); + if ( file_exists($tempSkinFile) ) $skinFile = $tempSkinFile; } - return $skinFile; + return $skinFile; } -function getSkinIncludes( $file, $includeBase=false, $asOverride=false ) { +function getSkinIncludes($file, $includeBase=false, $asOverride=false) { global $skinBase; $skinFile = false; foreach ( $skinBase as $skin ) { - $tempSkinFile = detaintPath( 'skins'.'/'.$skin.'/'.$file ); - if ( file_exists( $tempSkinFile ) ) + $tempSkinFile = detaintPath('skins'.'/'.$skin.'/'.$file); + if ( file_exists($tempSkinFile) ) $skinFile = $tempSkinFile; } $includeFiles = array(); @@ -2223,11 +2244,11 @@ function getSkinIncludes( $file, $includeBase=false, $asOverride=false ) { if ( $skinFile ) $includeFiles[] = $skinFile; } - return( $includeFiles ); + return $includeFiles; } -function requestVar( $name, $default='' ) { - return( isset($_REQUEST[$name])?validHtmlStr($_REQUEST[$name]):$default ); +function requestVar($name, $default='') { + return isset($_REQUEST[$name]) ? validHtmlStr($_REQUEST[$name]) : $default; } // For numbers etc in javascript or tags etc @@ -2310,48 +2331,48 @@ function getStreamHTML($monitor, $options = array()) { $monitor->Name()); } else { if ( $options['mode'] == 'stream' ) { - ZM\Info( 'The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser.' ); + ZM\Info('The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser.'); } $options['mode'] = 'single'; $streamSrc = $monitor->getStreamSrc($options); - return getImageStill( 'liveStream'.$monitor->Id(), $streamSrc, $options['width'], $options['height'], $monitor->Name()); + return getImageStill('liveStream'.$monitor->Id(), $streamSrc, $options['width'], $options['height'], $monitor->Name()); } } // end function getStreamHTML function getStreamMode( ) { $streamMode = ''; - if ( ZM_WEB_STREAM_METHOD == 'mpeg' && ZM_MPEG_LIVE_FORMAT ) { + if ( (ZM_WEB_STREAM_METHOD == 'mpeg') && ZM_MPEG_LIVE_FORMAT ) { $streamMode = 'mpeg'; } elseif ( canStream() ) { $streamMode = 'jpeg'; } else { $streamMode = 'single'; - ZM\Info( 'The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser.' ); + ZM\Info('The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser.'); } return $streamMode; } // end function getStreamMode function folder_size($dir) { - $size = 0; - foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) { - $size += is_file($each) ? filesize($each) : folder_size($each); - } - return $size; + $size = 0; + foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) { + $size += is_file($each) ? filesize($each) : folder_size($each); + } + return $size; } // end function folder_size function human_filesize($size, $precision = 2) { - $units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); - $step = 1024; - $i = 0; - while (($size / $step) > 0.9) { - $size = $size / $step; - $i++; - } - return round($size, $precision).$units[$i]; + $units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); + $step = 1024; + $i = 0; + while (($size / $step) > 0.9) { + $size = $size / $step; + $i++; + } + return round($size, $precision).$units[$i]; } function csrf_startup() { - csrf_conf('rewrite-js', 'includes/csrf/csrf-magic.js'); + csrf_conf('rewrite-js', 'includes/csrf/csrf-magic.js'); } function check_timezone() { @@ -2359,7 +2380,10 @@ function check_timezone() { $sys_tzoffset = trim(shell_exec('date "+%z"')); $php_tzoffset = trim($now->format('O')); - $mysql_tzoffset = trim(dbFetchOne("SELECT TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),'%H%i');",'TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),\'%H%i\')')); + $mysql_tzoffset = trim(dbFetchOne( + 'SELECT TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),\'%H%i\');', + 'TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),\'%H%i\')' + )); #Logger::Debug("System timezone offset determine to be: $sys_tzoffset,\x20 #PHP timezone offset determine to be: $php_tzoffset,\x20 @@ -2495,7 +2519,7 @@ function format_duration($time, $separator=':') { function array_recursive_diff($aArray1, $aArray2) { $aReturn = array(); - foreach ($aArray1 as $mKey => $mValue) { + foreach ( $aArray1 as $mKey => $mValue ) { if ( array_key_exists($mKey, $aArray2) ) { if ( is_array($mValue) ) { $aRecursiveDiff = array_recursive_diff($mValue, $aArray2[$mKey]);