Skip to content

Commit 4525803

Browse files
authored
Fix dynamic properties and png rendering deprecations (#279)
* Fix: depreciation png * Fix: depreciation pt2 * Fix depreciation pt3 * Fix: deprecation notification * Fix: date localization on mail notification * Fix for php-cs-fixer * Fix: PHPStan
1 parent 07d5a8f commit 4525803

7 files changed

Lines changed: 66 additions & 57 deletions

File tree

inc/baseclass.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
class PluginMreportingBaseclass
3232
{
3333
protected $sql_date;
34+
protected $sql_closedate;
3435
protected $sql_date_create;
3536
protected $sql_date_solve;
3637
protected $sql_date_closed;

inc/graphpng.class.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public function initGraph($options)
6767
$width = $this->width + 100;
6868

6969
if (!isset($_REQUEST['date1' . $randname])) {
70-
$_REQUEST['date1' . $randname] = strftime('%Y-%m-%d', time()
70+
$_REQUEST['date1' . $randname] = date('Y-m-d', time()
7171
- ($options['delay'] * 24 * 60 * 60));
7272
}
7373
if (!isset($_REQUEST['date2' . $randname])) {
74-
$_REQUEST['date2' . $randname] = strftime('%Y-%m-%d');
74+
$_REQUEST['date2' . $randname] = date('Y-m-d');
7575
}
7676

7777
$backtrace = debug_backtrace();
@@ -404,13 +404,13 @@ public function imageSmoothAlphaLine($image, $x1, $y1, $x2, $y2, $dcol)
404404
continue;
405405
}
406406

407-
$trgb = ImageColorAt($image, $x, (int) floor($y));
407+
$trgb = ImageColorAt($image, (int) floor($x), (int) floor($y));
408408
$tcr = ($trgb >> 16) & 0xFF;
409409
$tcg = ($trgb >> 8) & 0xFF;
410410
$tcb = $trgb & 0xFF;
411411
imagesetpixel(
412412
$image,
413-
$x,
413+
(int) floor($x),
414414
(int) floor($y),
415415
imagecolorallocatealpha(
416416
$image,
@@ -421,13 +421,13 @@ public function imageSmoothAlphaLine($image, $x1, $y1, $x2, $y2, $dcol)
421421
),
422422
);
423423

424-
$trgb = ImageColorAt($image, $x, (int) ceil($y));
424+
$trgb = ImageColorAt($image, (int) ceil($x), (int) ceil($y));
425425
$tcr = ($trgb >> 16) & 0xFF;
426426
$tcg = ($trgb >> 8) & 0xFF;
427427
$tcb = $trgb & 0xFF;
428428
imagesetpixel(
429429
$image,
430-
$x,
430+
(int) ceil($x),
431431
(int) ceil($y),
432432
imagecolorallocatealpha(
433433
$image,
@@ -681,9 +681,9 @@ public function showHbar($params, $dashboard = false, $width = false)
681681
$index = 0;
682682
foreach ($datas as $label => $data) {
683683
$bx1 = 250;
684-
$by1 = ($index + 1) * 1.25 * $height_bar + .05 * $height + 2;
684+
$by1 = round(($index + 1) * 1.25 * $height_bar + .05 * $height + 2);
685685
$bx2 = $bx1 + round(($data * ($width - 300)) / $max);
686-
$by2 = $by1 + $height_bar;
686+
$by2 = round($by1 + $height_bar);
687687

688688
//createbar
689689
ImageFilledRectangle($image, $bx1, (int) $by1, (int) $bx2, (int) $by2, hexdec($palette[$index]));
@@ -922,8 +922,8 @@ public function showPie($params, $dashboard = false, $width = false)
922922

923923
//text associated with pie arc (only for angle > 2°)
924924
if ($angle > 2 && ($show_label == 'always' || $show_label == 'hover')) {
925-
$xtext = $x - 1 + cos(deg2rad(($start_angle + $angle) / 2)) * ($radius / 1.7);
926-
$ytext = $y + 5 - sin(deg2rad(($start_angle + $angle) / 2)) * ($radius / 1.7);
925+
$xtext = round($x - 1 + cos(deg2rad(($start_angle + $angle) / 2)) * ($radius / 1.7));
926+
$ytext = round($y + 5 - sin(deg2rad(($start_angle + $angle) / 2)) * ($radius / 1.7));
927927
imagettftext(
928928
$image,
929929
$this->fontsize,
@@ -1274,12 +1274,12 @@ public function drawSunburstLevel($image, $datas, $params = [])
12741274
//define label position
12751275
if (is_array($data)) {
12761276
//show label inside its arc
1277-
$xtext = $x - $dx * $tw + cos($amr) * (0.5 * $radius - $step / 3);
1278-
$ytext = $y + $dy * $th - sin($amr) * (0.5 * $radius - $step / 4);
1277+
$xtext = round($x - $dx * $tw + cos($amr) * (0.5 * $radius - $step / 3));
1278+
$ytext = round($y + $dy * $th - sin($amr) * (0.5 * $radius - $step / 4));
12791279
} else {
12801280
//show label outside of its arc
1281-
$xtext = $x + 3 - $dx * $tw + cos($amr) * (0.5 * $radius + $step / 16);
1282-
$ytext = $y + $dy * $th - sin($amr) * (0.5 * $radius + $step / 8);
1281+
$xtext = round($x + 3 - $dx * $tw + cos($amr) * (0.5 * $radius + $step / 16));
1282+
$ytext = round($y + $dy * $th - sin($amr) * (0.5 * $radius + $step / 8));
12831283
}
12841284

12851285
//draw label
@@ -1310,8 +1310,8 @@ public function drawSunburstLevel($image, $datas, $params = [])
13101310
$th = abs($box[5] - $box[1]);
13111311

13121312
//define label position
1313-
$xtext = $x - $dx * $tw + cos($samr) * (0.5 * $radius - $step / 8);
1314-
$ytext = $y + $dy * $th - sin($samr) * (0.5 * $radius - $step / 16);
1313+
$xtext = round($x - $dx * $tw + cos($samr) * (0.5 * $radius - $step / 8));
1314+
$ytext = round($y + $dy * $th - sin($samr) * (0.5 * $radius - $step / 16));
13151315

13161316
//draw label
13171317
imagettftext(
@@ -1715,10 +1715,10 @@ public function showVstackbar($params, $dashboard = false, $width = false)
17151715
if ($dashboard) {
17161716
$height = 350;
17171717
}
1718-
$x_bar = (0.85 * $this->width / $nb_bar);
1719-
$width_bar = $x_bar * .85;
1720-
$y_labels_width = .1 * $this->width;
1721-
$x_labels_height = $height - 0.95 * $height;
1718+
$x_bar = round(0.85 * $this->width / $nb_bar);
1719+
$width_bar = round($x_bar * .85);
1720+
$y_labels_width = round(.1 * $this->width);
1721+
$x_labels_height = round($height - 0.95 * $height);
17221722
$legend_height = $nb_labels2 * 15 + 10;
17231723

17241724
//longueur du texte en dessous des barres
@@ -1753,8 +1753,8 @@ public function showVstackbar($params, $dashboard = false, $width = false)
17531753
//draw x-axis grey step line and values ticks
17541754
$xstep = round(($height - $legend_height - $x_labels_height) / 12);
17551755
for ($i = 0; $i <= 12; $i++) {
1756-
$yaxis = $height - $x_labels_height - $xstep * $i;
1757-
imageLine($image, (int) (.9 * $y_labels_width), (int) $yaxis, (int) (0.95 * $this->width), (int) $yaxis, hexdec($this->grey));
1756+
$yaxis = round($height - $x_labels_height - $xstep * $i);
1757+
imageLine($image, (int) round(.9 * $y_labels_width), (int) $yaxis, (int) round(0.95 * $this->width), (int) $yaxis, hexdec($this->grey));
17581758

17591759
//value label
17601760
$val = round($i * $cum / 12, 1);
@@ -1822,7 +1822,7 @@ public function showVstackbar($params, $dashboard = false, $width = false)
18221822
foreach ($data as $subdata) {
18231823
$by1 = $by2;
18241824
$bx1 = $y_labels_width + $index1 * $x_bar;
1825-
$by2 = $by1 - $subdata * ($height - $legend_height - $x_labels_height) / $cum;
1825+
$by2 = round($by1 - $subdata * ($height - $legend_height - $x_labels_height) / $cum);
18261826
$bx2 = $bx1 + $width_bar;
18271827

18281828
if ($by1 != $by2) { // no draw for empty datas
@@ -1855,7 +1855,7 @@ public function showVstackbar($params, $dashboard = false, $width = false)
18551855
$textwidth = abs($box[4] - $box[6]);
18561856
$textwidth = abs(sqrt((pow($textwidth, 2) / 2)));
18571857

1858-
$lx = $y_labels_width + $index1 * $x_bar + ($width_bar / 2.5);
1858+
$lx = round($y_labels_width + $index1 * $x_bar + ($width_bar / 2.5));
18591859
imagettftext(
18601860
$image,
18611861
$this->fontsize - 1,
@@ -2030,7 +2030,7 @@ public function showArea($params, $dashboard = false, $width = false)
20302030
$nb = count($datas);
20312031
$width = $this->width;
20322032
$height = 350;
2033-
$width_line = ($width - 45) / $nb;
2033+
$width_line = (int) round(($width - 45) / $nb);
20342034
$step = ceil($nb / 20);
20352035

20362036
//create image
@@ -2125,9 +2125,9 @@ public function showArea($params, $dashboard = false, $width = false)
21252125

21262126
// determine coords
21272127
$x1 = $index * $width_line - $width_line + 30;
2128-
$y1 = $height - 30 - $old_data * ($height - 85) / $max;
2128+
$y1 = floor($height - 30 - $old_data * ($height - 85) / $max);
21292129
$x2 = $x1 + $width_line;
2130-
$y2 = $height - 30 - $data * ($height - 85) / $max;
2130+
$y2 = floor($height - 30 - $data * ($height - 85) / $max);
21312131
$aCoords[$x1] = $y1;
21322132

21332133
//in case of area chart fill under point space
@@ -2170,9 +2170,9 @@ public function showArea($params, $dashboard = false, $width = false)
21702170

21712171
// determine coords
21722172
$x1 = $index * $width_line - $width_line + 30;
2173-
$y1 = $height - 30 - $old_data * ($height - 85) / $max;
2173+
$y1 = (int) floor($height - 30 - $old_data * ($height - 85) / $max);
21742174
$x2 = $x1 + $width_line;
2175-
$y2 = $height - 30 - $data * ($height - 85) / $max;
2175+
$y2 = (int) floor($height - 30 - $data * ($height - 85) / $max);
21762176

21772177
//trace dots
21782178
$color_rbg = self::colorHexToRGB($darkerpalette[0]);
@@ -2372,7 +2372,7 @@ public function showGArea($params, $dashboard = false, $width = false)
23722372
$nb_bar = count($labels2);
23732373
$nb_labels2 = count($datas);
23742374

2375-
$width_line = ($this->width - 45) / $nb;
2375+
$width_line = (int) floor(($this->width - 45) / $nb);
23762376
$index1 = 0;
23772377
$index3 = 1;
23782378
$step = ceil($nb / 21);
@@ -2479,10 +2479,10 @@ public function showGArea($params, $dashboard = false, $width = false)
24792479
}
24802480

24812481
// determine coords
2482-
$x1 = $index2 * $width_line - $width_line + $x_bar;
2483-
$y1 = $height - $x_labels_height - $old_data * ($height - $legend_height - $x_labels_height) / $max;
2482+
$x1 = $index2 * $width_line - $width_line + $x_bar;
2483+
$y1 = (int) round($height - $x_labels_height - $old_data * ($height - $legend_height - $x_labels_height) / $max);
24842484
$x2 = $x1 + $width_line;
2485-
$y2 = $height - $x_labels_height - $subdata * ($height - $legend_height - $x_labels_height) / $max;
2485+
$y2 = (int) round($height - $x_labels_height - $subdata * ($height - $legend_height - $x_labels_height) / $max);
24862486

24872487
//in case of area chart fill under point space
24882488
if ($area > 0) {

inc/helpdesk.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ public function reportVstackbarTicketStatusByTechnician($config = [])
918918
foreach ($technicians as $technician) {
919919
$datas['datas'][$current_status][$technician['username']] = 0;
920920

921-
$fullname = trim($technician['fullname']);
921+
$fullname = trim($technician['fullname'] ?? "");
922922
if (!empty($fullname)) {
923923
$datas['labels2'][$technician['username']] = $fullname;
924924
} else {

inc/notificationtargetnotification.class.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,25 @@ private function buildPDF($user_name = '')
154154
$image_width = imagesx($image);
155155
$image_height = imagesy($image);
156156

157-
$format = '%e';
158-
if (strftime('%Y', strtotime($graph['start'])) != strftime('%Y', strtotime($graph['end']))) {
159-
$format .= ' %B %Y';
160-
} elseif (strftime('%B', strtotime($graph['start'])) != strftime('%B', strtotime($graph['end']))) {
161-
$format .= ' %B';
157+
$start = new DateTime($graph['start']);
158+
$end = new DateTime($graph['end']);
159+
160+
$format = 'd';
161+
if ($start->format('Y') != $end->format('Y')) {
162+
$format .= ' MMMM y';
163+
} elseif ($start->format('F') != $end->format('F')) {
164+
$format .= ' MMMM';
162165
}
163166

167+
$language = $_SESSION['glpilanguage'] ?? 'en_GB';
164168
$image_title = $LANG['plugin_mreporting'][$graph['class']][$graph['method']]['title'];
165-
$image_title .= ' du ' . strftime($format, strtotime($graph['start']));
166-
$image_title .= ' au ' . strftime('%e %B %Y', strtotime($graph['end']));
167-
169+
$image_title .= ' ' . lcfirst(
170+
sprintf(
171+
__('From %1$s to %2$s'),
172+
IntlDateFormatter::formatObject($start, $format, $language),
173+
IntlDateFormatter::formatObject($end, 'd MMMM Y', $language),
174+
),
175+
);
168176
array_push($images, ['title' => $image_title,
169177
'base64' => $image_base64,
170178
'width' => $image_width,

lib/cubic_splines/classes/CubicSplines.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private function funcInterp($x)
110110
$i = 0;
111111
$j = $n - 1;
112112
while ($i + 1 < $j) {
113-
$k = $i + ($j - $i) / 2;
113+
$k = floor($i + ($j - $i) / 2);
114114
if ($x <= $this->aSplines[$k]['x']) {
115115
$j = $k;
116116
} else {

lib/cubic_splines/classes/Plot.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function drawAxis($vImage, $vColor, $iPosX = 0, $iPosY = false)
4848
imageline($vImage, $iPosX, $iPosY, $iPosX, 0, $vColor);
4949
imageline($vImage, $iPosX, $iPosY, $vImageWidth, $iPosY, $vColor);
5050

51-
imagefilledpolygon($vImage, [$iPosX, 0, $iPosX - 3, 5, $iPosX + 3, 5], 3, $vColor);
52-
imagefilledpolygon($vImage, [$vImageWidth, $iPosY, $vImageWidth - 5, $iPosY - 3, $vImageWidth - 5, $iPosY + 3], 3, $vColor);
51+
imagefilledpolygon($vImage, [$iPosX, 0, $iPosX - 3, 5, $iPosX + 3, 5], $vColor);
52+
imagefilledpolygon($vImage, [$vImageWidth, $iPosY, $vImageWidth - 5, $iPosY - 3, $vImageWidth - 5, $iPosY + 3], $vColor);
5353
}
5454
}

0 commit comments

Comments
 (0)