Browse Source

colors in private area, files cleanup

merge-requests/1/head
JamesRezo 4 years ago
parent
commit
088daa3a2f
  1. 1
      README.md
  2. 288
      inc/branches.php
  3. 56
      inc/supported-versions.php
  4. 1
      modeles/eol.html
  5. 1
      modeles/release-note.html
  6. 1
      paquet.xml
  7. 8
      supportedversions_fonctions.php
  8. 11
      supportedversions_options.php

1
README.md

@ -7,7 +7,6 @@ SPIP Plugin backport of [PHP Supported Versions](http://php.net/supported-versio
- `<table|>` : a table of actively supported versions
- `<supported-versions|>` : a calendar view of the table above
- `<legend|>` : colors and style explanations
- `<eol|>` : list of non-supported versions
## Other usage

288
inc/branches.php

@ -1,288 +0,0 @@
<?php
include_spip('include/releases');
/* Time to keep EOLed branches in the array returned by get_active_branches(),
* which is used on the front page download links and the supported versions
* page. (Currently 28 days.) */
$KEEP_EOL = new DateInterval('P28D');
function format_interval($from, $to) {
try {
$from_obj = $from instanceof DateTime ? $from : new DateTime($from);
$to_obj = $to instanceof DateTime ? $to : new DateTime($to);
$diff = $to_obj->diff($from_obj);
$times = array();
if ($diff->y) {
$times[] = array($diff->y,'year');
if ($diff->m) {
$times[] = array($diff->m,'month');
}
} elseif ($diff->m) {
$times[] = array($diff->m,'month');
} elseif ($diff->d) {
$times[] = array($diff->d,'day');
} else {
$eolPeriod = 'midnight';
}
if ($times) {
$eolPeriod = implode(
', ',
array_map(
function ($t) {
return "$t[0] $t[1]" .
($t[0] != 1 ? 's' : '');
},
$times
)
);
if ($diff->invert) {
$eolPeriod = "$eolPeriod ago";
} else {
$eolPeriod = "in $eolPeriod";
}
}
} catch (Exception $e) {
$eolPeriod = 'unknown';
}
return $eolPeriod;
}
function version_number_to_branch($version) {
$parts = explode('.', $version);
if (count($parts) > 1) {
return "$parts[0].$parts[1]";
}
}
function get_all_branches() {
$branches = array();
foreach ($GLOBALS['OLDRELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
if ($branch = version_number_to_branch($version)) {
if (!isset($branches[$major][$branch]) || version_compare($version, $branches[$major][$branch]['version'], 'gt')) {
$branches[$major][$branch] = $release;
$branches[$major][$branch]['version'] = $version;
}
}
}
}
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
if ($branch = version_number_to_branch($version)) {
if (!isset($branches[$major][$branch]) || version_compare($version, $branches[$major][$branch]['version'], 'gt')) {
$branches[$major][$branch] = $release;
$branches[$major][$branch]['version'] = $version;
}
}
}
}
krsort($branches);
foreach ($branches as $major => &$branch) {
krsort($branch);
}
return $branches;
}
function get_active_branches($include_recent_eols = true) {
$branches = array();
$now = new DateTime;
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
if ($branch = version_number_to_branch($version)) {
$threshold = get_branch_security_eol_date($branch);
if ($include_recent_eols) {
$threshold->add($GLOBALS['KEEP_EOL']);
}
if ($now < $threshold) {
$branches[$major][$branch] = $release;
$branches[$major][$branch]['version'] = $version;
}
}
}
if (!empty($branches[$major])) {
ksort($branches[$major]);
}
}
ksort($branches);
return $branches;
}
/* If you provide an array to $always_include, note that the version numbers
* must be in $RELEASES _and_ must be the full version number, not the branch:
* ie provide array('5.3.29'), not array('5.3'). */
function get_eol_branches($always_include = null) {
$always_include = $always_include ? $always_include : array();
$branches = array();
$now = new DateTime;
// Gather the last release on each branch into a convenient array.
foreach ($GLOBALS['OLDRELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
if ($branch = version_number_to_branch($version)) {
if (!isset($branches[$major][$branch]) || version_compare($version, $branches[$major][$branch]['version'], 'gt')) {
$branches[$major][$branch] = array(
'date' => strtotime($release['date']),
'link' => "/releases#$version",
'version' => $version,
);
}
}
}
}
/* Exclude releases from active branches, where active is defined as "in
* the $RELEASES array and not explicitly marked as EOL there". */
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
if ($branch = version_number_to_branch($version)) {
if ($now < get_branch_security_eol_date($branch)) {
/* This branch isn't EOL: remove it from our array. */
if (isset($branches[$major][$branch])) {
unset($branches[$major][$branch]);
}
} else {
/* Add the release information to the EOL branches array, since it
* should be newer than the information we got from $OLDRELEASES. */
$always_include[] = $version;
}
}
}
}
// Include any release in the always_include list that's in $RELEASES.
if ($always_include) {
foreach ($always_include as $version) {
$parts = explode('.', $version);
$major = $parts[0];
if (isset($GLOBALS['RELEASES'][$major][$version])) {
$release = $GLOBALS['RELEASES'][$major][$version];
if ($branch = version_number_to_branch($version)) {
$branches[$major][$branch] = array(
'date' => strtotime($release['source'][0]['date']),
'link' => "/downloads#v$version",
'version' => $version,
);
}
}
}
}
krsort($branches);
foreach ($branches as $major => &$branch) {
krsort($branch);
}
return $branches;
}
/* $branch is expected to have at least two components: MAJOR.MINOR or
* MAJOR.MINOR.REVISION (the REVISION will be ignored if provided). This will
* return either null (if no release exists on the given branch), or the usual
* version metadata from $RELEASES for a single release. */
function get_initial_release($branch) {
$branch = version_number_to_branch($branch);
if (!$branch) {
return null;
}
$major = substr($branch, 0, strpos($branch, '.'));
if (isset($GLOBALS['OLDRELEASES'][$major]["$branch.0"])) {
return $GLOBALS['OLDRELEASES'][$major]["$branch.0"];
}
/* If there's only been one release on the branch, it won't be in
* $OLDRELEASES yet, so let's check $RELEASES. */
if (isset($GLOBALS['RELEASES'][$major]["$branch.0"])) {
// Fake a date like we have on the oldreleases array.
$release = $GLOBALS['RELEASES'][$major]["$branch.0"];
$release['date'] = $release['source'][0]['date'];
return $release;
}
// Shrug.
return null;
}
function get_final_release($branch) {
$branch = version_number_to_branch($branch);
if (!$branch) {
return null;
}
$major = substr($branch, 0, strpos($branch, '.'));
$last = "$branch.0";
foreach ($GLOBALS['OLDRELEASES'][$major] as $version => $release) {
if (version_number_to_branch($version) == $branch && version_compare($version, $last, '>')) {
$last = $version;
}
}
if (isset($GLOBALS['OLDRELEASES'][$major][$last])) {
return $GLOBALS['OLDRELEASES'][$major][$last];
}
/* If there's only been one release on the branch, it won't be in
* $OLDRELEASES yet, so let's check $RELEASES. */
if (isset($GLOBALS['RELEASES'][$major][$last])) {
// Fake a date like we have on the oldreleases array.
$release = $GLOBALS['RELEASES'][$major][$last];
$release['date'] = $release['source'][0]['date'];
return $release;
}
// Shrug.
return null;
}
function compare_version($arrayA, $versionB) {
static $sortValues = array(
true => 1,
false => -1,
);
$length = count($arrayA);
$arrayB = version_array($versionB, $length);
if (!is_array($arrayA) || !is_array($arrayB)) {
return $sortValues[$arrayA > $arrayB];
}
foreach ($arrayA as $index => $componentA) {
$componentA = $arrayA[$index];
$componentB = $arrayB[$index];
if ($componentA != $componentB) {
return $sortValues[$componentA > $componentB];
}
}
return 0;
}
function version_array($version, $length = null) {
$versionArray = array_map(
'intval',
explode('.', $version)
);
if (is_int($length)) {
$versionArray = count($versionArray) < $length
? array_pad($versionArray, $length, 0)
: array_slice(
$versionArray,
0,
$length
);
}
return $versionArray;
}

56
inc/supported-versions.php

@ -1,56 +0,0 @@
<?php
include_spip('inc/branches');
// Sizing constants.
$margin_left = 80;
$margin_right = 50;
$header_height = 24;
$year_width = 120;
$branch_height = 30;
$footer_height = 24;
function branches_to_show() {
// Basically: show all 5.3+ branches with EOL dates > min_date().
$branches = array();
// Flatten out the majors.
foreach (get_all_branches() as $major => $major_branches) {
foreach ($major_branches as $branch => $version) {
if (version_compare($branch, '5.3', 'ge') && get_branch_security_eol_date($branch) > min_date()) {
$branches[$branch] = $version;
}
}
}
ksort($branches);
return $branches;
}
function min_date() {
$now = new DateTime('January 1');
return $now->sub(new DateInterval('P3Y'));
}
function max_date() {
$now = new DateTime('January 1');
return $now->add(new DateInterval('P5Y'));
}
function date_horiz_coord(DateTime $date) {
$diff = $date->diff(min_date());
if (!$diff->invert) {
return $GLOBALS['margin_left'];
}
return $GLOBALS['margin_left'] + ($diff->days / (365.24 / $GLOBALS['year_width']));
}
$branches = branches_to_show();
$i = 0;
foreach ($branches as $branch => $version) {
$branches[$branch]['top'] = $header_height + ($branch_height * $i++);
}
$years = iterator_to_array(new DatePeriod(min_date(), new DateInterval('P1Y'), max_date()));
$width = $margin_left + $margin_right + ((count($years) - 1) * $year_width);
$height = $header_height + $footer_height + (count($branches) * $branch_height);

1
modeles/eol.html

@ -1 +0,0 @@
eol.html

1
modeles/release-note.html

@ -1 +0,0 @@
release-note.html

1
paquet.xml

@ -7,4 +7,5 @@
>
<nom>SPIP: Supported Versions</nom>
<pipeline nom="insert_head_css" />
<pipeline nom="header_prive_css" />
</paquet>

8
supportedversions_fonctions.php

@ -8,6 +8,10 @@ function supportedversions_insert_head_css($flux) {
return $flux;
}
function supportedversions_header_prive_css($flux) {
return supportedversions_insert_head_css($flux);
}
function state(array $valeurs) {
$now = new DateTime;
$initial = new DateTime($valeurs['initial_release']);
@ -26,3 +30,7 @@ function state(array $valeurs) {
return '';
}
function balise_SVG_dist($p) {
return balise_ENV_dist($p, '$GLOBALS["svg"]');
}

11
supportedversions_options.php

@ -0,0 +1,11 @@
<?php
// Sizing constants.
$GLOBALS['svg'] = [
'margin_left' => 80,
'margin_right' => 50,
'header_height' => 24,
'year_width' => 120,
'branch_height' => 30,
'footer_height' => 24,
];
Loading…
Cancel
Save