From 9f43830a748e7d81ba1466285e0fe207a8e3a69b Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 19 Oct 2022 11:22:14 +0200 Subject: [PATCH 1/2] PHP8 Compatibility: Fix issues to enable PHP8 support - avoid using depreceated APIs --- src/admin/groups.php | 6 +++--- src/include/functions_common.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/admin/groups.php b/src/admin/groups.php index 41e8548..11fe23f 100644 --- a/src/admin/groups.php +++ b/src/admin/groups.php @@ -118,7 +118,7 @@ if ( isset($_GET['op']) ) " WHERE " . DB_GROUPMEMBERS . ".groupid = " . $content['GROUPID']; $result = DB_Query($sqlquery); $tmparray = DB_GetAllRows($result, true); - if ( count($tmparray) > 0 ) + if ( isset($tmparray) && count($tmparray) > 0 ) { // Add UserID's to where clause! foreach ($tmparray as $datarow) @@ -449,7 +449,7 @@ if ( !isset($_POST['op']) && !isset($_GET['op']) ) $result = DB_Query($sqlquery); $content['GROUPS'] = DB_GetAllRows($result, true); - if ( count($content['GROUPS']) > 0 ) + if ( isset($content['GROUPS']) && count($content['GROUPS']) > 0 ) { // --- Process Groups for($i = 0; $i < count($content['GROUPS']); $i++) @@ -476,7 +476,7 @@ if ( !isset($_POST['op']) && !isset($_GET['op']) ) $result = DB_Query($sqlquery); $content['GROUPS'][$i]['USERS'] = DB_GetAllRows($result, true); - if ( count($content['GROUPS'][$i]['USERS']) > 0 ) + if ( isset($content['GROUPS'][$i]['USERS']) && count($content['GROUPS'][$i]['USERS']) > 0 ) { // Enable Groupmembers $content['GROUPS'][$i]['GROUPMEMBERS'] = true; diff --git a/src/include/functions_common.php b/src/include/functions_common.php index 1599c39..918861c 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -624,7 +624,7 @@ function CheckAndSetRunMode() */ function RemoveMagicQuotes() { - if (get_magic_quotes_gpc()) { + if(function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) { $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { From 9da2abc94b3a5ba5cbf87524f00ad6287ef43d98 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 19 Oct 2022 11:26:33 +0200 Subject: [PATCH 2/2] ThirdParty: Updated jpgraph to 4.4.1 for PHP8 compatibility closes: https://github.com/rsyslog/loganalyzer/issues/75 --- src/classes/jpgraph/README | 4 +-- src/classes/jpgraph/gd_image.inc.php | 36 ++++++++++++++------- src/classes/jpgraph/jpgraph.php | 11 +++---- src/classes/jpgraph/jpgraph_date.php | 8 ++++- src/classes/jpgraph/jpgraph_gantt.php | 41 ++++++++++++------------ src/classes/jpgraph/jpgraph_rgb.inc.php | 2 +- src/classes/jpgraph/jpgraph_windrose.php | 2 +- 7 files changed, 61 insertions(+), 43 deletions(-) diff --git a/src/classes/jpgraph/README b/src/classes/jpgraph/README index 51d0943..e610c37 100644 --- a/src/classes/jpgraph/README +++ b/src/classes/jpgraph/README @@ -1,7 +1,7 @@ -README FOR JPGRAPH 4.3.1 +README FOR JPGRAPH 4.4.1 ========================= -This package contains the JpGraph PHP library version 4.3.1 +This package contains the JpGraph PHP library version 4.4.1 The library is Copyright (C) 2000-2010 Asial Corporatoin and released under dual license QPL 1.0 for open source and educational diff --git a/src/classes/jpgraph/gd_image.inc.php b/src/classes/jpgraph/gd_image.inc.php index 58abab0..055f18e 100644 --- a/src/classes/jpgraph/gd_image.inc.php +++ b/src/classes/jpgraph/gd_image.inc.php @@ -126,7 +126,7 @@ class Image { } $this->img = @imagecreatetruecolor($aWidth, $aHeight); - if( $this->img < 1 ) { + if( !$this->img ) { JpGraphError::RaiseL(25126); //die("Can't create truecolor image. Check that you really have GD2 library installed."); } @@ -188,7 +188,7 @@ class Image { else { $f = 'imagecopyresampled'; } - $f($aToHdl,$aFromHdl,$aToX,$aToY,$aFromX,$aFromY, $aWidth,$aHeight,$aw,$ah); + $f($aToHdl,$aFromHdl,(int)$aToX,(int)$aToY,(int)$aFromX,(int)$aFromY, (int)$aWidth,(int)$aHeight,(int)$aw,(int)$ah); } function Copy($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth=-1,$fromHeight=-1) { @@ -285,7 +285,7 @@ class Image { // Get the specific height for a text string function GetTextHeight($txt="",$angle=0) { - $tmp = preg_split('/\n/',$txt); + $tmp = preg_split('/\n/',$txt ?: ''); $n = count($tmp); $m=0; for($i=0; $i< $n; ++$i) { @@ -333,7 +333,7 @@ class Image { // etxt width. function GetTextWidth($txt,$angle=0) { - $tmp = preg_split('/\n/',$txt); + $tmp = preg_split('/\n/',$txt ?: ''); $n = count($tmp); if( $this->font_family <= FF_FONT2+1 ) { @@ -648,7 +648,7 @@ class Image { $use_font = $this->font_family; if( $dir==90 ) { - imagestringup($this->img,$use_font,$x,$y,$txt,$this->current_color); + imagestringup($this->img,$use_font,(int)$x,(int)$y,$txt,$this->current_color); $aBoundingBox = array(round($x),round($y),round($x),round($y-$w),round($x+$h),round($y-$w),round($x+$h),round($y)); if( $aDebug ) { // Draw bounding box @@ -658,7 +658,7 @@ class Image { } } else { - if( preg_match('/\n/',$txt) ) { + if( preg_match('/\n/',$txt ?: '') ) { $tmp = preg_split('/\n/',$txt); for($i=0; $i < count($tmp); ++$i) { $w1 = $this->GetTextWidth($tmp[$i]); @@ -675,7 +675,7 @@ class Image { } else { //Put the text - imagestring($this->img,$use_font,$x,$y-$h+1,$txt,$this->current_color); + imagestring($this->img,$use_font,(int)$x,(int)($y-$h+1),$txt ?: '',$this->current_color); } if( $aDebug ) { // Draw the bounding rectangle and the bounding box @@ -931,7 +931,7 @@ class Image { // Do nothing the text is drawn at baseline by default } } - ImageTTFText ($this->img, $this->font_size, $dir, $x, $y, + ImageTTFText ($this->img, $this->font_size, $dir, (int)$x, (int)$y, $this->current_color,$this->font_file,$txt); // Calculate and return the co-ordinates for the bounding box @@ -1038,7 +1038,7 @@ class Image { $xl -= $bbox[0]/2; $yl = $y - $yadj; //$xl = $xl- $xadj; - ImageTTFText($this->img, $this->font_size, $dir, $xl, $yl-($h-$fh)+$fh*$i, + ImageTTFText($this->img, $this->font_size, $dir, (int)$xl, (int)($yl-($h-$fh)+$fh*$i), $this->current_color,$this->font_file,$tmp[$i]); // echo "xl=$xl,".$tmp[$i]."
"; @@ -1437,7 +1437,11 @@ class Image { } $old = $this->line_weight; imagesetthickness($this->img,1); - imagefilledpolygon($this->img,$pts,count($pts)/2,$this->current_color); + if (CheckPHPVersion('8.1.0')) { + imagefilledpolygon($this->img,$pts,$this->current_color); + } else { + imagefilledpolygon($this->img,$pts,count($pts)/2,$this->current_color); + } $this->line_weight = $old; imagesetthickness($this->img,$old); } @@ -1768,7 +1772,11 @@ class Image { $p4y=ceil(($y1 - $dist_y)); $array=array($p1x,$p1y,$p2x,$p2y,$p3x,$p3y,$p4x,$p4y); - imagefilledpolygon ( $im, $array, (count($array)/2), $color ); + if (CheckPHPVersion('8.1.0')) { + imagefilledpolygon ( $im, $array, $color ); + } else { + imagefilledpolygon ( $im, $array, (count($array)/2), $color ); + } // for antialias imageline($im, $p1x, $p1y, $p2x, $p2y, $color); @@ -1829,7 +1837,11 @@ class Image { } imagesetthickness($im, 1); - imagefilledpolygon($im, $pts,count($pts)/2, $color); + if (CheckPHPVersion('8.1.0')) { + imagefilledpolygon($im, $pts, $color); + } else { + imagefilledpolygon($im, $pts,count($pts)/2, $color); + } $weight *= 2; diff --git a/src/classes/jpgraph/jpgraph.php b/src/classes/jpgraph/jpgraph.php index 02656d2..f9419da 100644 --- a/src/classes/jpgraph/jpgraph.php +++ b/src/classes/jpgraph/jpgraph.php @@ -19,7 +19,7 @@ require_once('jpgraph_theme.inc.php'); require_once('gd_image.inc.php'); // Version info -define('JPG_VERSION','4.3.1'); +define('JPG_VERSION','4.4.1'); // Minimum required PHP version define('MIN_PHPVERSION','5.1.0'); @@ -392,15 +392,15 @@ class DateLocale { } $this->iLocale = $aLocale; - for( $i = 0, $ofs = 0 - strftime('%w'); $i < 7; $i++, $ofs++ ) { - $day = strftime('%a', strtotime("$ofs day")); + for( $i = 0, $ofs = 0 - date('w'); $i < 7; $i++, $ofs++ ) { + $day = date('D', strtotime("$ofs day")); $day[0] = strtoupper($day[0]); $this->iDayAbb[$aLocale][]= $day[0]; $this->iShortDay[$aLocale][]= $day; } for($i=1; $i<=12; ++$i) { - list($short ,$full) = explode('|', strftime("%b|%B",strtotime("2001-$i-01"))); + list($short ,$full) = explode('|', date("M|F",strtotime("2001-$i-01"))); $this->iShortMonth[$aLocale][] = ucfirst($short); $this->iMonthName [$aLocale][] = ucfirst($full); } @@ -3642,7 +3642,6 @@ class Grid { // assumption offset==0 so we might end up drawing one // to many gridlines $i=0; - $x=$aTicksPos[$i]; while( $iimg->Line($x,$yl,$x,$yu); elseif( $aType == 'dotted' ) $this->img->DashedLineForGrid($x,$yl,$x,$yu,1,6); @@ -4060,7 +4059,7 @@ class Axis extends AxisPrototype { // that holds the labels set by the user. If the user hasn't // specified any values we use whats in the automatically asigned // labels in the maj_ticks_label - if( isset($this->ticks_label[$i*$m]) ) { + if( isset($this->ticks_label[$i *(int)$m]) ) { $label=$this->ticks_label[$i*$m]; } else { diff --git a/src/classes/jpgraph/jpgraph_date.php b/src/classes/jpgraph/jpgraph_date.php index db4c441..bfb5ddb 100644 --- a/src/classes/jpgraph/jpgraph_date.php +++ b/src/classes/jpgraph/jpgraph_date.php @@ -406,10 +406,16 @@ class DateScale extends LinearScale { // identical to LinearScale::AutoScale if( $aStartTime == $aEndTime ) { // Special case when we only have one data point. - // Create a small artifical intervall to do the autoscaling + // Create a small artificial interval to do the autoscaling $aStartTime -= 10; $aEndTime += 10; } + if( abs($aEndTime - $aStartTime) <= 1 ) { + // Special case when we only have one second. + // Create a small artificial interval to do the autoscaling + $aStartTime -= 1; + $aEndTime += 1; + } $done=false; $i=0; while( ! $done && $i < 5) { diff --git a/src/classes/jpgraph/jpgraph_gantt.php b/src/classes/jpgraph/jpgraph_gantt.php index d5afa65..a9268f7 100644 --- a/src/classes/jpgraph/jpgraph_gantt.php +++ b/src/classes/jpgraph/jpgraph_gantt.php @@ -2128,8 +2128,8 @@ class GanttScale { } // Get day in week for start and ending date (Sun==0) - $ds=strftime("%w",$this->iStartDate); - $de=strftime("%w",$this->iEndDate); + $ds=date("w",$this->iStartDate); + $de=date("w",$this->iEndDate); // We want to start on iWeekStart day. But first we subtract a week // if the startdate is "behind" the day the week start at. @@ -2278,17 +2278,17 @@ class GanttScale { // Get day in month function GetMonthDayNbr($aDate) { - return 0+strftime("%d",$aDate); + return 0+date("d",$aDate); } // Get day in year function GetYearDayNbr($aDate) { - return 0+strftime("%j",$aDate); + return 0+date("z",$aDate); } // Get month number function GetMonthNbr($aDate) { - return 0+strftime("%m",$aDate); + return 0+date("m",$aDate); } // Translate a date to screen coordinates (horizontal scale) @@ -2599,63 +2599,63 @@ class GanttScale { $x+$daywidth,$yb-$this->day->iFrameWeight); } - $mn = strftime('%m',$datestamp); + $mn = date('m',$datestamp); if( $mn[0]=='0' ) $mn = $mn[1]; switch( $this->day->iStyle ) { case DAYSTYLE_LONG: // "Monday" - $txt = strftime('%A',$datestamp); + $txt = date('l',$datestamp); break; case DAYSTYLE_SHORT: // "Mon" - $txt = strftime('%a',$datestamp); + $txt = date('D',$datestamp); break; case DAYSTYLE_SHORTDAYDATE1: // "Mon 23/6" - $txt = strftime('%a %d/'.$mn,$datestamp); + $txt = date('D d/'.$mn,$datestamp); break; case DAYSTYLE_SHORTDAYDATE2: // "Mon 23 Jun" - $txt = strftime('%a %d %b',$datestamp); + $txt = date('D d M',$datestamp); break; case DAYSTYLE_SHORTDAYDATE3: // "Mon 23 Jun 2003" - $txt = strftime('%a %d %b %Y',$datestamp); + $txt = date('D d M Y',$datestamp); break; case DAYSTYLE_LONGDAYDATE1: // "Monday 23 Jun" - $txt = strftime('%A %d %b',$datestamp); + $txt = date('l d M',$datestamp); break; case DAYSTYLE_LONGDAYDATE2: // "Monday 23 Jun 2003" - $txt = strftime('%A %d %b %Y',$datestamp); + $txt = date('l d M Y',$datestamp); break; case DAYSTYLE_SHORTDATE1: // "23/6" - $txt = strftime('%d/'.$mn,$datestamp); + $txt = date('d/'.$mn,$datestamp); break; case DAYSTYLE_SHORTDATE2: // "23 Jun" - $txt = strftime('%d %b',$datestamp); + $txt = date('d M',$datestamp); break; case DAYSTYLE_SHORTDATE3: // "Mon 23" - $txt = strftime('%a %d',$datestamp); + $txt = date('D d',$datestamp); break; case DAYSTYLE_SHORTDATE4: // "23" - $txt = strftime('%d',$datestamp); + $txt = date('d',$datestamp); break; case DAYSTYLE_CUSTOM: // Custom format - $txt = strftime($this->day->iLabelFormStr,$datestamp); + $txt = date($this->day->iLabelFormStr,$datestamp); break; case DAYSTYLE_ONELETTER: default: // "M" - $txt = strftime('%A',$datestamp); + $txt = date('l',$datestamp); $txt = strtoupper($txt[0]); break; } @@ -2808,7 +2808,7 @@ class GanttScale { $img->SetLineWeight($this->month->grid->iWeight); $img->SetColor($this->month->iTextColor); - $year = 0+strftime("%Y",$this->iStartDate); + $year = 0+date("Y",$this->iStartDate); $img->SetTextAlign("center"); if( $this->GetMonthNbr($this->iStartDate) == $this->GetMonthNbr($this->iEndDate) && $this->GetYear($this->iStartDate)==$this->GetYear($this->iEndDate) ) { @@ -3634,6 +3634,7 @@ class GanttVLine extends GanttPlotObject { $this->iLine->SetColor($aColor); $this->iLine->SetWeight($aWeight); $this->iLine->SetStyle($aStyle); + $this->iLine->Show(); $this->iStart = $aDate; $this->title = new TextPropertyBelow(); $this->title->Set($aTitle); diff --git a/src/classes/jpgraph/jpgraph_rgb.inc.php b/src/classes/jpgraph/jpgraph_rgb.inc.php index 5389261..a7f485b 100644 --- a/src/classes/jpgraph/jpgraph_rgb.inc.php +++ b/src/classes/jpgraph/jpgraph_rgb.inc.php @@ -559,7 +559,7 @@ class RGB { if( $aAlpha < 0 || $aAlpha > 1 ) { JpGraphError::RaiseL(25080);//('Alpha parameter for color must be between 0.0 and 1.0'); } - return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127)); + return imagecolorresolvealpha($this->img, (int)$r, (int)$g, (int)$b, (int)round($aAlpha * 127)); } // Try to convert an array with three valid numbers to the corresponding hex array diff --git a/src/classes/jpgraph/jpgraph_windrose.php b/src/classes/jpgraph/jpgraph_windrose.php index 8eef2cb..6ff205c 100644 --- a/src/classes/jpgraph/jpgraph_windrose.php +++ b/src/classes/jpgraph/jpgraph_windrose.php @@ -570,7 +570,7 @@ class WindrosePlot { $this->iCircGridWeight = 1; } - function _ThickCircle($aImg,$aXC,$aYC,$aRad,$aWeight=2,$aColor) { + function _ThickCircle($aImg,$aXC,$aYC,$aRad,$aWeight,$aColor) { $aImg->SetColor($aColor); $aRad *= 2 ;