xref: /web-php/images/supported-versions.php (revision 6aa42c14)
1<?php
2include_once __DIR__ . '/../include/prepend.inc';
3include_once __DIR__ . '/../include/branches.inc';
4
5// Sizing constants.
6$margin_left = 80;
7$margin_right = 50;
8$header_height = 24;
9$year_width = 120;
10$branch_height = 30;
11$footer_height = 24;
12
13function branches_to_show() {
14    // Basically: show all 5.3+ branches with EOL dates > min_date().
15    $branches = [];
16
17    // Flatten out the majors.
18    foreach (get_all_branches() as $major_branches) {
19        foreach ($major_branches as $branch => $version) {
20            if (version_compare($branch, '5.3', 'ge') && get_branch_security_eol_date($branch) > min_date()) {
21                $branches[$branch] = $version;
22            }
23        }
24    }
25
26    ksort($branches);
27    return $branches;
28}
29
30function min_date(): DateTime
31{
32    $now = new DateTime('January 1');
33    return $now->sub(new DateInterval('P3Y'));
34}
35
36function max_date(): DateTime
37{
38    $now = new DateTime('January 1');
39    return $now->add(new DateInterval('P5Y'));
40}
41
42function date_horiz_coord(DateTime $date) {
43    $diff = $date->diff(min_date());
44    if (!$diff->invert) {
45        return $GLOBALS['margin_left'];
46    }
47    return $GLOBALS['margin_left'] + ($diff->days / (365.24 / $GLOBALS['year_width']));
48}
49
50$branches = branches_to_show();
51$i = 0;
52foreach ($branches as $branch => $version) {
53    $branches[$branch]['top'] = $header_height + ($branch_height * $i++);
54}
55
56if (!isset($non_standalone)) {
57    header('Content-Type: image/svg+xml');
58    echo '<?xml version="1.0"?>';
59}
60
61$years = iterator_to_array(new DatePeriod(min_date(), new DateInterval('P1Y'), max_date()));
62$width = $margin_left + $margin_right + ((count($years) - 1) * $year_width);
63$height = $header_height + $footer_height + (count($branches) * $branch_height);
64?>
65<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 <?php echo $width ?> <?php echo $height ?>" width="<?php echo $width ?>" height="<?php echo $height ?>">
66	<style type="text/css">
67		<![CDATA[
68			@import url(/fonts/Fira/fira.css);
69
70			text {
71				fill: #333;
72				font-family: var(--font-family-sans-serif);
73				font-size: <?php echo (2 / 3) * $header_height; ?>px;
74			}
75
76			g.eol rect,
77			.branches rect.eol {
78				fill: #f33;
79			}
80
81			g.eol text {
82				fill: white;
83			}
84
85			g.security rect,
86			.branches rect.security {
87				fill: #f93;
88			}
89
90			g.stable rect,
91			.branches rect.stable {
92				fill: #9c9;
93			}
94
95			.branch-labels text {
96				dominant-baseline: central;
97				text-anchor: middle;
98			}
99
100			.today line {
101				stroke: #333;
102				stroke-dasharray: 7,7;
103				stroke-width: 3px;
104			}
105
106			.today text {
107				fill: #333;
108				text-anchor: middle;
109			}
110
111			.years line {
112				stroke: black;
113			}
114
115			.years text {
116				text-anchor: middle;
117			}
118		]]>
119	</style>
120
121	<!-- Branch labels -->
122	<g class="branch-labels">
123		<?php foreach ($branches as $branch => $version): ?>
124			<g class="<?php echo get_branch_support_state($branch) ?>">
125				<rect x="0" y="<?php echo $version['top'] ?>" width="<?php echo 0.5 * $margin_left ?>" height="<?php echo $branch_height ?>" />
126				<text x="<?php echo 0.25 * $margin_left ?>" y="<?php echo $version['top'] + (0.5 * $branch_height) ?>">
127					<?php echo htmlspecialchars($branch) ?>
128				</text>
129			</g>
130		<?php endforeach ?>
131	</g>
132
133	<!-- Branch blocks -->
134	<g class="branches">
135		<?php foreach ($branches as $branch => $version): ?>
136			<?php
137            $x_release = date_horiz_coord(get_branch_release_date($branch));
138            $x_bug = date_horiz_coord(get_branch_bug_eol_date($branch));
139            $x_eol = date_horiz_coord(get_branch_security_eol_date($branch));
140            ?>
141			<rect class="stable" x="<?php echo $x_release ?>" y="<?php echo $version['top'] ?>" width="<?php echo $x_bug - $x_release ?>" height="<?php echo $branch_height ?>" />
142			<rect class="security" x="<?php echo $x_bug ?>" y="<?php echo $version['top'] ?>" width="<?php echo $x_eol - $x_bug ?>" height="<?php echo $branch_height ?>" />
143		<?php endforeach ?>
144	</g>
145
146	<!-- Year lines -->
147	<g class="years">
148		<?php foreach ($years as $date): ?>
149			<line x1="<?php echo date_horiz_coord($date) ?>" y1="<?php echo $header_height ?>" x2="<?php echo date_horiz_coord($date) ?>" y2="<?php echo $header_height + (count($branches) * $branch_height) ?>" />
150			<text x="<?php echo date_horiz_coord($date) ?>" y="<?php echo 0.8 * $header_height; ?>">
151				<?php echo $date->format('j M Y') ?>
152			</text>
153		<?php endforeach ?>
154	</g>
155
156	<!-- Today -->
157	<g class="today">
158		<?php
159        $now = new DateTime();
160        $x = date_horiz_coord($now);
161        ?>
162		<line x1="<?php echo $x ?>" y1="<?php echo $header_height ?>" x2="<?php echo $x ?>" y2="<?php echo $header_height + (count($branches) * $branch_height) ?>" />
163		<text x="<?php echo $x ?>" y="<?php echo $header_height + (count($branches) * $branch_height) + (0.8 * $footer_height) ?>">
164			<?php echo 'Today: ' . $now->format('j M Y') ?>
165		</text>
166	</g>
167</svg>
168