diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Control/HikVision.pm b/scripts/ZoneMinder/lib/ZoneMinder/Control/HikVision.pm index feca9db7d..8754500fa 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Control/HikVision.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Control/HikVision.pm @@ -53,6 +53,7 @@ use HTTP::Cookies; my $ChannelID = 1; # Usually... my $DefaultFocusSpeed = 50; # Should be between 1 and 100 my $DefaultIrisSpeed = 50; # Should be between 1 and 100 +my ($user,$pass,$host,$port); sub open { my $self = shift; @@ -65,7 +66,6 @@ sub open { # # Extract the username/password host/port from ControlAddress # - my ($user,$pass,$host,$port); if ( $self->{Monitor}{ControlAddress} =~ /^([^:]+):([^@]+)@(.+)/ ) { # user:pass@host... $user = $1; $pass = $2; @@ -126,6 +126,8 @@ sub PutCmd { Control Device should be set to \"$1\". Control Device currently set to \"$self->{Monitor}{ControlDevice}\"."); $self->{Monitor}{ControlDevice} = $1; + $self->{UA}->credentials("$host:$port", $self->{Monitor}{ControlDevice}, $user, $pass); + return PutCmd($self,$cmd,$content); } } } diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Database.pm b/scripts/ZoneMinder/lib/ZoneMinder/Database.pm index 6126ac761..c39a6a73f 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Database.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Database.pm @@ -108,9 +108,18 @@ sub zmDbConnect { , $Config{ZM_DB_PASS} ); }; - Error("Error reconnecting to db: errstr:$DBI::errstr error val:$@") if (! $dbh) or $@; - $dbh->trace(0) if $dbh; - } + if ( !$dbh or $@ ) { + Error("Error reconnecting to db: errstr:$DBI::errstr error val:$@"); + } else { + $dbh->{AutoCommit} = 1; + Fatal('Can\'t set AutoCommit on in database connection') + unless $dbh->{AutoCommit}; + $dbh->{mysql_auto_reconnect} = 1; + Fatal('Can\'t set mysql_auto_reconnect on in database connection') + unless $dbh->{mysql_auto_reconnect}; + $dbh->trace( 0 ); + } # end if success connecting + } # end if ! connected return $dbh; } # end sub zmDbConnect diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index e75fb57cc..8dbcf8efa 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -429,54 +429,10 @@ sub databaseLevel { if ( $this->{databaseLevel} != $databaseLevel ) { if ( $databaseLevel > NOLOG and $this->{databaseLevel} <= NOLOG ) { if ( !$this->{dbh} ) { - my $socket; - my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); - - if ( defined($portOrSocket) ) { - if ( $portOrSocket =~ /^\// ) { - $socket = ';mysql_socket='.$portOrSocket; - } else { - $socket = ';host='.$host.';port='.$portOrSocket; - } - } else { - $socket = ';host='.$Config{ZM_DB_HOST}; - } - my $sslOptions = ''; - if ( $Config{ZM_DB_SSL_CA_CERT} ) { - $sslOptions = join(';','', - 'mysql_ssl=1', - 'mysql_ssl_ca_file='.$Config{ZM_DB_SSL_CA_CERT}, - 'mysql_ssl_client_key='.$Config{ZM_DB_SSL_CLIENT_KEY}, - 'mysql_ssl_client_cert='.$Config{ZM_DB_SSL_CLIENT_CERT} - ); - } - $this->{dbh} = DBI->connect( 'DBI:mysql:database='.$Config{ZM_DB_NAME} - .$socket.$sslOptions - , $Config{ZM_DB_USER} - , $Config{ZM_DB_PASS} - ); - if ( !$this->{dbh} ) { - $databaseLevel = NOLOG; - Error( 'Unable to write log entries to DB, can\'t connect to database ' - .$Config{ZM_DB_NAME} - .' on host ' - .$Config{ZM_DB_HOST} - ); - } else { - $this->{dbh}->{AutoCommit} = 1; - Fatal('Can\'t set AutoCommit on in database connection' ) - unless( $this->{dbh}->{AutoCommit} ); - $this->{dbh}->{mysql_auto_reconnect} = 1; - Fatal('Can\'t set mysql_auto_reconnect on in database connection' ) - unless( $this->{dbh}->{mysql_auto_reconnect} ); - $this->{dbh}->trace( 0 ); - } + $this->{dbh} = ZoneMinder::Database::zmDbConnect(); } } elsif ( $databaseLevel <= NOLOG && $this->{databaseLevel} > NOLOG ) { - if ( $this->{dbh} ) { - $this->{dbh}->disconnect(); - undef($this->{dbh}); - } + undef($this->{dbh}); } $this->{databaseLevel} = $databaseLevel; } @@ -586,7 +542,7 @@ sub logPrint { print(STDERR $message) if $level <= $this->{termLevel}; if ( $level <= $this->{databaseLevel} ) { - if ( ( $this->{dbh} and $this->{dbh}->ping() ) or ( $this->{dbh} = zmDbConnect() ) ) { + if ( ( $this->{dbh} and $this->{dbh}->ping() ) or ( $this->{dbh} = ZoneMinder::Database::zmDbConnect() ) ) { my $sql = 'INSERT INTO Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) VALUES ( ?, ?, ?, ?, ?, ?, ?, NULL )'; $this->{sth} = $this->{dbh}->prepare_cached($sql); diff --git a/scripts/zmdc.pl.in b/scripts/zmdc.pl.in index 3080c6793..7f179db71 100644 --- a/scripts/zmdc.pl.in +++ b/scripts/zmdc.pl.in @@ -453,7 +453,7 @@ sub start { $cmd_hash{$process->{command}} = $pid_hash{$cpid} = $process; sigprocmask(SIG_SETMASK, $sigset) or Fatal("Can't restore SIGCHLD: $!"); - Debug("unblocko child"); + Debug("unblocking child"); } elsif ( defined($cpid) ) { # Force reconnection to the db. $dbh = zmDbConnect(1); diff --git a/src/zm_group.cpp b/src/zm_group.cpp index 734df1c94..7b96920b8 100644 --- a/src/zm_group.cpp +++ b/src/zm_group.cpp @@ -24,7 +24,6 @@ #include #include -#include Group::Group() { Warning("Instantiating default Group Object. Should not happen."); @@ -33,30 +32,31 @@ Group::Group() { strcpy(name, "Default"); } -Group::Group( MYSQL_ROW &dbrow ) { +// The order of columns is: Id, ParentId, Name +Group::Group(MYSQL_ROW &dbrow) { unsigned int index = 0; - id = atoi( dbrow[index++] ); - parent_id = dbrow[index] ? atoi( dbrow[index] ): 0; index++; - strncpy( name, dbrow[index++], sizeof(name)-1 ); + id = atoi(dbrow[index++]); + parent_id = dbrow[index] ? atoi(dbrow[index]): 0; index++; + strncpy(name, dbrow[index++], sizeof(name)-1); } /* If a zero or invalid p_id is passed, then the old default path will be assumed. */ -Group::Group( unsigned int p_id ) { +Group::Group(unsigned int p_id) { id = 0; if ( p_id ) { char sql[ZM_SQL_SML_BUFSIZ]; - snprintf( sql, sizeof(sql), "SELECT Id, ParentId, Name FROM Group WHERE Id=%d", p_id ); - Debug(2,"Loading Group for %d using %s", p_id, sql ); + snprintf(sql, sizeof(sql), "SELECT Id, ParentId, Name FROM Group WHERE Id=%d", p_id); + Debug(2,"Loading Group for %d using %s", p_id, sql); zmDbRow dbrow; - if ( ! dbrow.fetch( sql ) ) { - Error( "Unable to load group for id %d: %s", p_id, mysql_error( &dbconn ) ); + if ( !dbrow.fetch(sql) ) { + Error("Unable to load group for id %d: %s", p_id, mysql_error(&dbconn)); } else { unsigned int index = 0; - id = atoi( dbrow[index++] ); - parent_id = dbrow[index] ? atoi( dbrow[index] ): 0; index++; - strncpy( name, dbrow[index++], sizeof(name)-1 ); - Debug( 1, "Loaded Group area %d '%s'", id, this->Name() ); + id = atoi(dbrow[index++]); + parent_id = dbrow[index] ? atoi(dbrow[index]): 0; index++; + strncpy(name, dbrow[index++], sizeof(name)-1); + Debug(1, "Loaded Group area %d '%s'", id, this->Name()); } } if ( ! id ) { diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 0afa1e7ef..dd8511add 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -2693,19 +2693,21 @@ void Monitor::get_ref_image() { image_buffer[last_write_index].mutex.unlock(); } -std::list Monitor::Groups() { +std::vector Monitor::Groups() { // At the moment, only load groups once. if ( ! groups.size() ) { - std::string sql = stringtf("SELECT GroupId FROM Groups_Monitors WHERE MonitorId=%d",id); + std::string sql = stringtf( + "SELECT Id,ParentId,Name FROM Groups WHERE Groups.Id IN " + "(SELECT GroupId FROM Groups_Monitors WHERE MonitorId=%d)",id); MYSQL_RES *result = zmDbFetch(sql.c_str()); if ( !result ) { Error("Can't load groups: %s", mysql_error(&dbconn)); return groups; } int n_groups = mysql_num_rows(result); - Debug( 1, "Got %d groups", n_groups ); + Debug(1, "Got %d groups", n_groups); while ( MYSQL_ROW dbrow = mysql_fetch_row(result) ) { - groups.push_back( new Group(dbrow) ); + groups.push_back(new Group(dbrow)); } if ( mysql_errno(&dbconn) ) { Error("Can't fetch row: %s", mysql_error(&dbconn)); @@ -2714,3 +2716,13 @@ std::list Monitor::Groups() { } return groups; } + +StringVector Monitor::GroupNames() { + StringVector groupnames; + for(Group * g: Groups()) { + groupnames.push_back(std::string(g->Name())); +Debug(1,"Groups: %s", g->Name()); + } + return groupnames; +} + diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 75e675833..c2905f0d3 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -370,7 +370,7 @@ protected: int n_linked_monitors; MonitorLink **linked_monitors; - std::list groups; + std::vector groups; public: explicit Monitor(); @@ -511,7 +511,8 @@ public: bool DumpSettings( char *output, bool verbose ); void DumpZoneImage( const char *zone_string=0 ); - std::list Groups(); + std::vector Groups(); + StringVector GroupNames(); static int LoadMonitors(std::string sql, Monitor **&monitors, Purpose purpose); // Returns # of Monitors loaded, 0 on failure. #if ZM_HAS_V4L diff --git a/src/zm_utils.cpp b/src/zm_utils.cpp index 8518f8cd7..b56fba22d 100644 --- a/src/zm_utils.cpp +++ b/src/zm_utils.cpp @@ -94,9 +94,8 @@ const std::string stringtf( const std::string format, ... ) return( tempString ); } -bool startsWith( const std::string &haystack, const std::string &needle ) -{ - return( haystack.substr( 0, needle.length() ) == needle ); +bool startsWith(const std::string &haystack, const std::string &needle) { + return( haystack.substr(0, needle.length()) == needle ); } std::vector split(const std::string &s, char delim) { @@ -109,20 +108,18 @@ std::vector split(const std::string &s, char delim) { return elems; } -StringVector split( const std::string &string, const std::string &chars, int limit ) { +StringVector split(const std::string &string, const std::string &chars, int limit) { StringVector stringVector; std::string tempString = string; std::string::size_type startIndex = 0; std::string::size_type endIndex = 0; //Info( "Looking for '%s' in '%s', limit %d", chars.c_str(), string.c_str(), limit ); - do - { + do { // Find delimiters endIndex = string.find_first_of( chars, startIndex ); //Info( "Got endIndex at %d", endIndex ); - if ( endIndex > 0 ) - { + if ( endIndex > 0 ) { //Info( "Adding '%s'", string.substr( startIndex, endIndex-startIndex ).c_str() ); stringVector.push_back( string.substr( startIndex, endIndex-startIndex ) ); } @@ -130,8 +127,7 @@ StringVector split( const std::string &string, const std::string &chars, int lim break; // Find non-delimiters startIndex = tempString.find_first_not_of( chars, endIndex ); - if ( limit && (stringVector.size() == (unsigned int)(limit-1)) ) - { + if ( limit && (stringVector.size() == (unsigned int)(limit-1)) ) { stringVector.push_back( string.substr( startIndex ) ); break; } @@ -139,22 +135,21 @@ StringVector split( const std::string &string, const std::string &chars, int lim } while ( startIndex != std::string::npos ); //Info( "Finished with %d strings", stringVector.size() ); - return( stringVector ); + return stringVector; } -const std::string join(const StringVector &v, const char * delim ) { +const std::string join(const StringVector &v, const char * delim=",") { std::stringstream ss; - for(size_t i = 0; i < v.size(); ++i) { - if(i != 0) - ss << ","; + for (size_t i = 0; i < v.size(); ++i) { + if ( i != 0 ) + ss << delim; ss << v[i]; } return ss.str(); } -const std::string base64Encode( const std::string &inString ) -{ +const std::string base64Encode(const std::string &inString) { static char base64_table[64] = { '\0' }; if ( !base64_table[0] ) diff --git a/web/api/app/Plugin/CakePHP-Enum-Behavior b/web/api/app/Plugin/CakePHP-Enum-Behavior index ca91b87fd..ea90c0cd7 160000 --- a/web/api/app/Plugin/CakePHP-Enum-Behavior +++ b/web/api/app/Plugin/CakePHP-Enum-Behavior @@ -1 +1 @@ -Subproject commit ca91b87fda8e006e4fca2ed870f24f9a29c2905d +Subproject commit ea90c0cd7f6e24333a90885e563b5d30b793db29 diff --git a/web/includes/Event.php b/web/includes/Event.php index 000f55e30..bb89f541d 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -10,9 +10,31 @@ class Event { 'MonitorId', 'StorageId', 'Name', -'DiskSpace', +'Cause', +'StartTime', +'EndTime', +'Width', +'Height', +'Length', +'Frames', +'AlarmFrames', +'DefaultVideo', 'SaveJPEGs', +'TotScore', +'AvgScore', +'MaxScore', +'Archived', +'Videoed', +'Uploaded', +'Emailed', +'Messages', +'Executed', +'Notes', +'StateId', +'Orientation', +'DiskSpace', 'Scheme', +'Locked', ); public function __construct( $IdOrRow = null ) { $row = NULL; diff --git a/web/views/image.php b/web/views/image.php index 6fad955b6..2da92899b 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -60,80 +60,90 @@ $path = null; if ( empty($_REQUEST['path']) ) { - if ( ! empty($_REQUEST['fid']) ) { - if ( $_REQUEST['fid'] == 'snapshot' ) { - $Event = new Event( $_REQUEST['eid'] ); - $Frame = new Frame(); - $Frame->FrameId('snapshot'); - $path = $Event->Path().'/snapshot.jpg'; - } else { + $show = empty($_REQUEST['show']) ? 'capture' : $_REQUEST['show']; - $show = empty($_REQUEST['show']) ? 'capture' : $_REQUEST['show']; - - if ( ! empty($_REQUEST['eid'] ) ) { - $Event = Event::find_one(array('Id'=> $_REQUEST['eid'])); - if ( ! $Event ) { - header('HTTP/1.0 404 Not Found'); - Fatal('Event ' . $_REQUEST['eid'].' Not found'); - return; - } - - $Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'FrameId'=>$_REQUEST['fid'])); - if ( ! $Frame ) { - $previousBulkFrame = dbFetchOne('SELECT * FROM Frames WHERE EventId=? AND FrameId < ? ORDER BY FrameID DESC LIMIT 1', NULL, array($_REQUEST['eid'], $_REQUEST['fid'] ) ); - $nextBulkFrame = dbFetchOne( "SELECT * FROM Frames WHERE EventId=? AND FrameId > ? ORDER BY FrameID ASC LIMIT 1", NULL, array($_REQUEST['eid'], $_REQUEST['fid'] ) ); - if ( $previousBulkFrame and $nextBulkFrame ) { - $Frame = new Frame( $previousBulkFrame ); - $Frame->FrameId( $_REQUEST['fid'] ); - - $percentage = ($Frame->FrameId() - $previousBulkFrame['FrameId']) / ($nextBulkFrame['FrameId'] - $previousBulkFrame['FrameId']); - - $Frame->Delta( $previousBulkFrame['Delta'] + floor( 100* ( $nextBulkFrame['Delta'] - $previousBulkFrame['Delta'] ) * $percentage )/100 ); -Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousBulkFrame['Delta'] . " + nextdelta:" . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage ); - } else { - Fatal("No Frame found for event(".$_REQUEST['eid'].") and frame id(".$_REQUEST['fid'].")"); - } - } - // Frame can be non-existent. We have Bulk frames. So now we should try to load the bulk frame - - } else { -# If we are only specifying fid, then the fid must be the primary key into the frames table. But when the event is specified, then it is the frame # - $Frame = Frame::find_one(array('Id'=>$_REQUEST['fid'])); - if ( ! $Frame ) { - header('HTTP/1.0 404 Not Found'); - Fatal('Frame ' . $_REQUEST['fid'] . ' Not Found'); - return; - } - - $Event = Event::find_one(array('Id'=>$Frame->EventId())); - if ( ! $Event ) { - header('HTTP/1.0 404 Not Found'); - Fatal('Event ' . $Frame->EventId() . ' Not Found'); - return; - } - - } - $path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg'; - } - - } else { + if ( empty($_REQUEST['fid']) ) { header('HTTP/1.0 404 Not Found'); Fatal('No Frame ID specified'); return; } - if ( ! file_exists( $path ) ) { - Logger::Debug( "$path does not exist"); -# Generate the frame JPG + if ( !empty($_REQUEST['eid']) ) { + $Event = Event::find_one(array('Id'=>$_REQUEST['eid'])); + if ( ! $Event ) { + header('HTTP/1.0 404 Not Found'); + Fatal('Event ' . $_REQUEST['eid'].' Not found'); + return; + } + + if ( $_REQUEST['fid'] == 'snapshot' ) { + $Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Score'=>$Event->MaxScore())); + if ( ! $Frame ) + $Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'])); + if ( ! $Frame ) { + $Frame = new Frame(); + $Frame->Delta(1); + $Frame->FrameId('snapshot'); + } + $path = $Event->Path().'/snapshot.jpg'; + } else { + + $Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'FrameId'=>$_REQUEST['fid'])); + if ( ! $Frame ) { + $previousBulkFrame = dbFetchOne( + 'SELECT * FROM Frames WHERE EventId=? AND FrameId < ? ORDER BY FrameID DESC LIMIT 1', + NULL, array($_REQUEST['eid'], $_REQUEST['fid']) + ); + $nextBulkFrame = dbFetchOne( + 'SELECT * FROM Frames WHERE EventId=? AND FrameId > ? ORDER BY FrameID ASC LIMIT 1', + NULL, array($_REQUEST['eid'], $_REQUEST['fid']) + ); + if ( $previousBulkFrame and $nextBulkFrame ) { + $Frame = new Frame($previousBulkFrame); + $Frame->FrameId($_REQUEST['fid']); + + $percentage = ($Frame->FrameId() - $previousBulkFrame['FrameId']) / ($nextBulkFrame['FrameId'] - $previousBulkFrame['FrameId']); + + $Frame->Delta($previousBulkFrame['Delta'] + floor( 100* ( $nextBulkFrame['Delta'] - $previousBulkFrame['Delta'] ) * $percentage )/100); +Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousBulkFrame['Delta'] . " + nextdelta:" . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage ); + } else { + Fatal('No Frame found for event('.$_REQUEST['eid'].') and frame id('.$_REQUEST['fid'].')'); + } + } + // Frame can be non-existent. We have Bulk frames. So now we should try to load the bulk frame + $path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg'; + } + + } else { +# If we are only specifying fid, then the fid must be the primary key into the frames table. But when the event is specified, then it is the frame # + $Frame = Frame::find_one(array('Id'=>$_REQUEST['fid'])); + if ( ! $Frame ) { + header('HTTP/1.0 404 Not Found'); + Fatal('Frame ' . $_REQUEST['fid'] . ' Not Found'); + return; + } + + $Event = Event::find_one(array('Id'=>$Frame->EventId())); + if ( ! $Event ) { + header('HTTP/1.0 404 Not Found'); + Fatal('Event ' . $Frame->EventId() . ' Not Found'); + return; + } + $path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg'; + } # end if have eid + + if ( ! file_exists($path) ) { + Logger::Debug("$path does not exist"); + # Generate the frame JPG if ( $show == 'capture' and $Event->DefaultVideo() ) { if ( ! file_exists($Event->Path().'/'.$Event->DefaultVideo()) ) { header('HTTP/1.0 404 Not Found'); - Fatal("Can't create frame images from video becuase there is no video file for this event at (".$Event->Path().'/'.$Event->DefaultVideo() ); + Fatal("Can't create frame images from video because there is no video file for this event at (".$Event->Path().'/'.$Event->DefaultVideo() ); } $command ='ffmpeg -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -frames:v 1 '.$path; #$command ='ffmpeg -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path; #$command ='ffmpeg -v 0 -i '.$Storage->Path().'/'.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path; - Logger::Debug( "Running $command" ); + Logger::Debug("Running $command"); $output = array(); $retval = 0; exec( $command, $output, $retval ); @@ -142,13 +152,15 @@ Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousB header('HTTP/1.0 404 Not Found'); Fatal("Can't create frame images from video for this event (".$Event->DefaultVideo() ); } - $Event->DiskSpace( null ); + # Generating an image file will use up more disk space, so update the Event record. + $Event->DiskSpace(null); $Event->save(); } else { header('HTTP/1.0 404 Not Found'); - Fatal("Can't create frame images from video becuase there is no video file for this event (".$Event->DefaultVideo() ); + Fatal("Can't create frame $show images from video because there is no video file for this event at ". + $Event->Path().'/'.$Event->DefaultVideo() ); } - } + } # end if ! file_exists($path) } else { Warning('Loading images by path is deprecated'); @@ -157,10 +169,10 @@ Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousB $pos = strpos($path, $dir_events); if ( $pos == 0 && $pos !== false ) { - if ( ! empty( $user['MonitorIds'] ) ) { + if ( ! empty($user['MonitorIds']) ) { $imageOk = false; - $pathMonId = substr( $path, 0, strspn( $path, '1234567890' ) ); - foreach ( preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) as $monId ) { + $pathMonId = substr($path, 0, strspn($path, '1234567890')); + foreach ( preg_split('/["\'\s]*,["\'\s]*/', $user['MonitorIds']) as $monId ) { if ( $pathMonId == $monId ) { $imageOk = true; break; @@ -172,39 +184,39 @@ Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousB } else { $errorText = 'Invalid image path'; } - if ( ! file_exists( $path ) ) { + if ( ! file_exists($path) ) { header('HTTP/1.0 404 Not Found'); Fatal("Image not found at $path"); } } $scale=0; -if( !empty($_REQUEST['scale']) ) { - if (is_numeric($_REQUEST['scale'])) { +if ( !empty($_REQUEST['scale']) ) { + if ( is_numeric($_REQUEST['scale']) ) { $x = $_REQUEST['scale']; - if($x >= 1 and $x <= 400) + if ( $x >= 1 and $x <= 400 ) $scale=$x; } } $width=0; if ( !empty($_REQUEST['width']) ) { - if (is_numeric($_REQUEST['width'])) { + if ( is_numeric($_REQUEST['width']) ) { $x = $_REQUEST['width']; - if($x >= 10 and $x <= 8000) + if ( $x >= 10 and $x <= 8000 ) $width=$x; } } $height=0; -if( !empty($_REQUEST['height']) ) { - if (is_numeric($_REQUEST['height'])) { +if ( !empty($_REQUEST['height']) ) { + if ( is_numeric($_REQUEST['height']) ) { $x = $_REQUEST['height']; - if($x >= 10 and $x <= 8000) + if ( $x >= 10 and $x <= 8000 ) $height=$x; } } -header( 'Content-type: image/jpeg' ); +header('Content-type: image/jpeg'); # This is so that Save Image As give a useful filename if ( $Event ) { @@ -215,19 +227,19 @@ ob_clean(); flush(); if ( $errorText ) { - Error( $errorText ); + Error($errorText); } else { if ( ( $scale==0 || $scale==100 ) && $width==0 && $height==0 ) { - if ( ! readfile( $path ) ) { - Error("No bytes read from ". $path ); + if ( !readfile($path) ) { + Error('No bytes read from '. $path); } } else { Logger::Debug("Doing a scaled image: scale($scale) width($width) height($height)"); $i = 0; if ( ! ( $width && $height ) ) { - $i = imagecreatefromjpeg( $path ); - $oldWidth = imagesx( $i ); - $oldHeight = imagesy( $i ); + $i = imagecreatefromjpeg($path); + $oldWidth = imagesx($i); + $oldHeight = imagesy($i); if ( $width == 0 && $height == 0 ) { // scale has to be set to get here with both zero $width = $oldWidth * $scale / 100.0; $height= $oldHeight * $scale / 100.0; @@ -237,23 +249,23 @@ if ( $errorText ) { $height = ($width * $oldHeight) / $oldWidth; } if ( $width == $oldWidth && $height == $oldHeight) { - Warning( 'No change to width despite scaling.' ); + Warning('No change to width despite scaling.'); } } # Slight optimisation, thumbnails always specify width and height, so we can cache them. $scaled_path = preg_replace('/\.jpg$/', "-${width}x${height}.jpg", $path ); - if ( ! file_exists( $scaled_path ) or ! readfile( $scaled_path ) ) { - Logger::Debug( "Cached scaled image does not exist at $scaled_path or is no good.. Creating it"); + if ( ! file_exists($scaled_path) or ! readfile($scaled_path) ) { + Logger::Debug("Cached scaled image does not exist at $scaled_path or is no good.. Creating it"); ob_start(); if ( ! $i ) - $i = imagecreatefromjpeg( $path ); - $iScale = imagescale( $i, $width, $height ); - imagejpeg( $iScale ); - imagedestroy( $i ); - imagedestroy( $iScale ); + $i = imagecreatefromjpeg($path); + $iScale = imagescale($i, $width, $height); + imagejpeg($iScale); + imagedestroy($i); + imagedestroy($iScale); $scaled_jpeg_data = ob_get_contents(); - file_put_contents( $scaled_path, $scaled_jpeg_data ); + file_put_contents($scaled_path, $scaled_jpeg_data); ob_end_clean(); echo $scaled_jpeg_data; }