quotes, spacing fix some functions that clearly no one uses

This commit is contained in:
Isaac Connor 2020-09-05 12:49:14 -04:00
parent 23505159da
commit c5e4a964cd
1 changed files with 50 additions and 54 deletions

View File

@ -178,7 +178,7 @@ function getVideoStreamHTML($id, $src, $width, $height, $format, $title='') {
$mimeType = 'video/3gpp';
break;
default :
$mimeType = "video/$format";
$mimeType = 'video/'.$format;
break;
}
}
@ -336,7 +336,7 @@ function getWebSiteUrl($id, $src, $width, $height, $title='') {
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.");
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 '<object id="'.$id.'" data="'.$src.'" alt="'.$title.'" width="'.$width.'" height="'.$height.'"></object>';
@ -394,7 +394,7 @@ function getEventDefaultVideoPath($event) {
}
function deletePath( $path ) {
ZM\Logger::Debug("Deleting $path");
ZM\Logger::Debug('Deleting '.$path);
if ( is_dir($path) ) {
system(escapeshellcmd('rm -rf '.$path));
} else if ( file_exists($path) ) {
@ -412,17 +412,15 @@ function deleteEvent($event) {
if ( gettype($event) != 'array' ) {
# $event could be an eid, so turn it into an event hash
$event = new ZM\Event($event);
} else {
ZM\Logger::Debug("Event type: " . gettype($event));
}
global $user;
if ( $event->Archived() ) {
ZM\Info('Cannot delete Archived event.');
return;
} # end if Archived
global $user;
if ( $user['Events'] == 'Edit' ) {
$event->delete();
} # CAN EDIT
@ -496,7 +494,7 @@ function htmlSelect($name, $contents, $values, $behaviours=false) {
}
}
return "<select name=\"$name\" $behaviourText>".htmlOptions($contents, $values).'</select>';
return '<select name="'.$name.'" '.$behaviourText.'>'.htmlOptions($contents, $values).'</select>';
}
function htmlOptions($options, $values) {
@ -531,7 +529,7 @@ function htmlOptions($options, $values) {
';
} # end foreach options
if ( $values and ! $has_selected ) {
ZM\Warning("Specified value $values not in contents: ".print_r($options, true));
ZM\Warning('Specified value '.$values.' not in contents: '.print_r($options, true));
}
return $options_html;
} # end function htmlOptions
@ -616,7 +614,7 @@ function getFormChanges($values, $newValues, $types=false, $columns=false) {
$imageData = getimagesize( $newValues[$key]['tmp_name'] );
$changes[$key.'Width'] = $key.'Width = '.$imageData[0];
$changes[$key.'Height'] = $key.'Height = '.$imageData[1];
$changes[$key.'Type'] = $key."Type = '".$newValues[$key]['type']."'";
$changes[$key.'Type'] = $key.'Type = \''.$newValues[$key]['type'].'\'';
$changes[$key.'Size'] = $key.'Size = '.$newValues[$key]['size'];
ob_start();
readfile( $newValues[$key]['tmp_name'] );
@ -629,7 +627,7 @@ function getFormChanges($values, $newValues, $types=false, $columns=false) {
case 'document' :
if ( is_array( $newValues[$key] ) ) {
$imageData = getimagesize( $newValues[$key]['tmp_name'] );
$changes[$key.'Type'] = $key."Type = '".$newValues[$key]['type']."'";
$changes[$key.'Type'] = $key.'Type = \''.$newValues[$key]['type'].'\'';
$changes[$key.'Size'] = $key.'Size = '.$newValues[$key]['size'];
ob_start();
readfile( $newValues[$key]['tmp_name'] );
@ -644,7 +642,7 @@ function getFormChanges($values, $newValues, $types=false, $columns=false) {
$changes[$key.'Size'] = $key.'Size = '.dbEscape($newValues[$key]['size']);
ob_start();
readfile( $newValues[$key]['tmp_name'] );
$changes[$key] = $key." = '".dbEscape( ob_get_contents() )."'";
$changes[$key] = $key.' = \''.dbEscape( ob_get_contents() ).'\'';
ob_end_clean();
break;
case 'raw' :
@ -655,9 +653,9 @@ function getFormChanges($values, $newValues, $types=false, $columns=false) {
case 'toggle' :
if ( (!isset($values[$key])) or $values[$key] != $value ) {
if ( empty($value) ) {
$changes[$key] = "$key = 0";
$changes[$key] = $key.' = 0';
} else {
$changes[$key] = "$key = 1";
$changes[$key] = $key.' = 1';
//$changes[$key] = $key . ' = '.dbEscape(trim($value));
}
}
@ -684,10 +682,10 @@ function getFormChanges($values, $newValues, $types=false, $columns=false) {
if ( !empty($types[$key]) ) {
if ( $types[$key] == 'toggle' ) {
if ( !isset($newValues[$key]) && !empty($value) ) {
$changes[$key] = "$key = 0";
$changes[$key] = "`$key` = 0";
}
} else if ( $types[$key] == 'set' ) {
$changes[$key] = "$key = ''";
$changes[$key] = "`$key` = ''";
}
}
}
@ -819,7 +817,7 @@ function daemonControl($command, $daemon=false, $args=false) {
}
$string = escapeshellcmd($string);
#$string .= ' 2>/dev/null >&- <&- >/dev/null';
ZM\Logger::Debug("daemonControl $string");
ZM\Logger::Debug('daemonControl '.$string);
exec($string);
}
@ -875,7 +873,7 @@ 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) {
@ -903,7 +901,7 @@ 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) {
@ -1285,20 +1283,20 @@ function systemStats() {
if ( $normalized_load <= 0.75 ) {
$htmlLoad = $load;
} else if ( $normalized_load <= 0.9 ) {
$htmlLoad = "<span class=\"warning\">$load</span>";
$htmlLoad = '<span class="warning">'.$load.'</span>';
} else if ( $normalized_load <= 1.1 ) {
$htmlLoad = "<span class=\"error\">$load</span>";
$htmlLoad = '<span class="error">'.$load.'</span>';
} else {
$htmlLoad = "<span class=\"critical\">$load</span>";
$htmlLoad = '<span class="critical">'.$load.'</span>';
}
# Colorize the disk space stat
if ( $diskPercent < 98 ) {
$htmlDiskPercent = $diskPercent.'%';
} else if ( $diskPercent <= 99 ) {
$htmlDiskPercent = "<span class=\"warning\">$diskPercent%</span>";
$htmlDiskPercent = '<span class="warning">'.$diskPercent.'%</span>';
} else {
$htmlDiskPercent = "<span class=\"error\">$diskPercent%</span>";
$htmlDiskPercent = '<span class="error">'.$diskPercent.'%</span>';
}
# Colorize the PATH_MAP (usually /dev/shm) stat
@ -1306,15 +1304,15 @@ function systemStats() {
if ( disk_free_space(ZM_PATH_MAP) > 209715200 ) { # have to always have at least 200MiB free
$htmlPathMapPercent = $pathMapPercent.'%';
} else {
$htmlPathMapPercent = "<span class=\"warning\">$pathMapPercent%</span>";
$htmlPathMapPercent = '<span class="warning">'.$pathMapPercent.'%</span>';
}
} else if ( $pathMapPercent < 100 ) {
$htmlPathMapPercent = "<span class=\"warning\">$pathMapPercent%</span>";
$htmlPathMapPercent = '<span class="warning">'.$pathMapPercent.'%</span>';
} else {
$htmlPathMapPercent = "<span class=\"critical\">$pathMapPercent%</span>";
$htmlPathMapPercent = '<span class="critical">'.$pathMapPercent.'%</span>';
}
$htmlString = translate('Load').": $htmlLoad - ".translate('Disk').": $htmlDiskPercent - ".ZM_PATH_MAP.": $htmlPathMapPercent";
$htmlString = translate('Load').': '.$htmlLoad.' - '.translate('Disk').': '.$htmlDiskPercent.' - '.ZM_PATH_MAP.': '.$htmlPathMapPercent;
return $htmlString;
}
@ -1497,12 +1495,11 @@ function getPolyCentre($points, $area=0) {
$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;
$cy += ($points[$i]['y'] + $points[$j]['y']) * ct;
$cx += ($points[$i]['x'] + $points[$j]['x']) * $ct;
$cy += ($points[$i]['y'] + $points[$j]['y']) * $ct;
}
$cx = intval(round(abs($cx/(6.0*$area))));
$cy = intval(round(abs($cy/(6.0*$area))));
printf( "X:%cx, Y:$cy<br>" );
return array('x'=>$cx, 'y'=>$cy);
}
@ -1650,12 +1647,12 @@ function coordsToPoints($coords) {
if ( preg_match('/(\d+),(\d+)/', $matches[1][$i], $cmatches) ) {
$points[] = array('x'=>$cmatches[1], 'y'=>$cmatches[2]);
} else {
echo("Bogus coordinates '".$matches[$i]."'");
echo('Bogus coordinates ('.$matches[$i].')');
return false;
}
}
} else {
echo("Bogus coordinate string '$coords'");
echo('Bogus coordinate string '.$coords);
return false;
}
return $points;
@ -1735,7 +1732,7 @@ function initX10Status() {
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)));
ZM\Fatal('Can\'t write to control socket: '.socket_strerror(socket_last_error($socket)));
}
socket_shutdown($socket, 1);
$x10Output = '';
@ -1771,7 +1768,7 @@ function getDeviceStatusX10($key) {
function setDeviceStatusX10($key, $status) {
$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) ) {
@ -1990,7 +1987,7 @@ function cache_bust($file) {
if ( file_exists(ZM_DIR_CACHE.'/'.$cacheFile) or symlink(ZM_PATH_WEB.'/'.$file, ZM_DIR_CACHE.'/'.$cacheFile) ) {
return 'cache/'.$cacheFile;
} else {
ZM\Warning("Failed linking $file to $cacheFile");
ZM\Warning('Failed linking '.$file.' to '.$cacheFile);
}
return $file;
}
@ -2066,7 +2063,7 @@ function getStreamHTML($monitor, $options = array()) {
if ( isset($options['scale']) and $options['scale'] != '' ) {
if ( $options['scale'] != 'auto' && $options['scale'] != '0' ) {
ZM\Warning("Setting dimensions from scale:".$options['scale']);
#ZM\Warning('Setting dimensions from scale:'.$options['scale']);
$options['width'] = reScale($monitor->ViewWidth(), $options['scale']).'px';
$options['height'] = reScale($monitor->ViewHeight(), $options['scale']).'px';
} else if ( ! ( isset($options['width']) or isset($options['height']) ) ) {
@ -2088,10 +2085,10 @@ function getStreamHTML($monitor, $options = array()) {
#$options['height'] = $monitor->ViewHeight().'px';
}
} else {
ZM\Warning("Have width ".$options['width']);
#ZM\Warning("Have width ".$options['width']);
if ( preg_match('/^(\d+)px$/', $options['width'], $matches) ) {
$scale = intval(100*$matches[1]/$monitor->ViewWidth());
ZM\Warning("Scale is $scale");
#ZM\Warning("Scale is $scale");
if ( $scale < $options['scale'] )
$options['scale'] = $scale;
} else if ( preg_match('/^(\d+)%$/', $options['width'], $matches) ) {
@ -2099,9 +2096,9 @@ function getStreamHTML($monitor, $options = array()) {
if ( $scale < $options['scale'] )
$options['scale'] = $scale;
} else {
Warning("Invalid value for width: ".$options['width']);
Warning('Invalid value for width: '.$options['width']);
}
}
}
}
if ( ! isset($options['mode'] ) ) {
$options['mode'] = 'stream';
@ -2205,10 +2202,10 @@ function check_timezone() {
ZM\Error("ZoneMinder is not configured properly: php's date.timezone $php_tzoffset does not match the system timezone $sys_tzoffset! Please check Options->System->Timezone.");
if ( $sys_tzoffset != $mysql_tzoffset )
ZM\Error("ZoneMinder is not configured properly: mysql's timezone does not match the system timezone! Event lists will display incorrect times.");
ZM\Error('ZoneMinder is not configured properly: mysql\'s timezone does not match the system timezone! Event lists will display incorrect times.');
if (!ini_get('date.timezone') || !date_default_timezone_set(ini_get('date.timezone')))
ZM\Error("ZoneMinder is not configured properly: php's date.timezone is not set to a valid timezone. Please check Options->System->Timezone");
ZM\Error('ZoneMinder is not configured properly: php\'s date.timezone is not set to a valid timezone. Please check Options->System->Timezone');
}
@ -2268,12 +2265,12 @@ function do_post_request($url, $data, $optional_headers = null) {
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if ( !$fp ) {
throw new Exception("Problem with $url, "
throw new Exception('Problem with '.$url.', '
.print_r(error_get_last(),true));
}
$response = @stream_get_contents($fp);
if ( $response === false ) {
throw new Exception("Problem reading data from $url, data: ".print_r($params,true)
throw new Exception('Problem reading data from '.$url.', data: '.print_r($params,true)
.print_r(error_get_last(),true));
}
return $response;
@ -2293,7 +2290,7 @@ if ( !function_exists('sem_get') ) {
}
if ( !function_exists('ftok') ) {
function ftok($filename = "", $proj = "") {
function ftok($filename = '', $proj = '') {
if ( empty($filename) || !file_exists($filename) ) {
return -1;
} else {
@ -2330,10 +2327,9 @@ function format_duration($time, $separator=':') {
function array_recursive_diff($aArray1, $aArray2) {
$aReturn = array();
if ( ! (is_array($aArray1) and is_array($aArray2) ) ) {
$backTrace = debug_backtrace();
ZM\Warning("Bad arrays passed 1:" . print_r($aArray1,true) . "\n2: " . print_r($aArray2,true)."\n from: ".print_r($backTrace,true));
return;
$backTrace = debug_backtrace();
ZM\Warning('Bad arrays passed 1:' . print_r($aArray1,true) . PHP_EOL.'2: '.print_r($aArray2,true).PHP_EOL.' from: '.print_r($backTrace,true));
return;
}
foreach ( $aArray1 as $mKey => $mValue ) {
@ -2416,12 +2412,12 @@ function html_radio($name, $values, $selected=null, $options=array(), $attrs=arr
function random_colour() {
return '#'.
str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT).
str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT).
str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT);
str_pad( dechex( mt_rand(0, 255) ), 2, '0', STR_PAD_LEFT).
str_pad( dechex( mt_rand(0, 255) ), 2, '0', STR_PAD_LEFT).
str_pad( dechex( mt_rand(0, 255) ), 2, '0', STR_PAD_LEFT);
}
function zm_random_bytes($length = 32){
function zm_random_bytes($length = 32) {
if ( !isset($length) || intval($length) <= 8 ) {
$length = 32;
}