Browse Source

Classe PHP pour rassembler les filtres

merge-requests/3/head
JamesRezo 4 years ago
parent
commit
bfd4f66f5e
  1. 24
      modeles/supportedversions_calendar.html
  2. 2
      modeles/supportedversions_table.html
  3. 112
      supportedversions_fonctions.php

24
modeles/supportedversions_calendar.html

@ -1,7 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg"
viewbox="0 0 [(#SUPPORTED_VERSIONS{svg/margin_left}|supver_width)] [(#SUPPORTED_VERSIONS{svg/header_height}|supver_height)]"
width="[(#SUPPORTED_VERSIONS{svg/margin_left}|supver_width)]"
height="[(#SUPPORTED_VERSIONS{svg/header_height}|supver_height)]"
viewbox="0 0 [(#SUPPORTED_VERSIONS{svg/margin_left}|SupportedVersions::width)] [(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height)]"
width="[(#SUPPORTED_VERSIONS{svg/margin_left}|SupportedVersions::width)]"
height="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height)]"
>
<style type="text/css">
<![CDATA[
@ -63,9 +63,9 @@
<!-- Branch labels -->
<g class="supver_branch-labels">
<BOUCLE_active_branches(DATA){source json, #CHEMIN{data/releases.json}}>[(#EOL|>={#DATE}|ou{#EOL|intval|non})
<g[ class="supver_(#VALEUR|supver_state)"]>
<rect x="0" y="[(#BRANCH|supver_top)]" width="[(#SUPPORTED_VERSIONS{svg/margin_left}|mult{0.5})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />
<text x="[(#SUPPORTED_VERSIONS{svg/margin_left}|mult{0.25})]" y="[(#BRANCH|supver_top|supver_top_for_text)]">
<g[ class="supver_(#VALEUR|SupportedVersions::state)"]>
<rect x="0" y="[(#BRANCH|SupportedVersions::top)]" width="[(#SUPPORTED_VERSIONS{svg/margin_left}|mult{0.5})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />
<text x="[(#SUPPORTED_VERSIONS{svg/margin_left}|mult{0.25})]" y="[(#BRANCH|SupportedVersions::topForText)]">
#BRANCH
</text>
</g>]
@ -75,15 +75,15 @@
<!-- Branch blocks -->
<g class="supver_branches">
<BOUCLE_active_branches_2(DATA){source json, #CHEMIN{data/releases.json}}>[(#EOL|>={#DATE}|ou{#EOL|intval|non})
<rect class="supver_stable" x="[(#INITIAL_RELEASE|supver_horiz_coord)]" y="[(#BRANCH|supver_top)]" width="[(#ACTIVE_SUPPORT|supver_horiz_coord|strmoins{#INITIAL_RELEASE|supver_horiz_coord})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />
<rect class="supver_security" x="[(#ACTIVE_SUPPORT|supver_horiz_coord)]" y="[(#BRANCH|supver_top)]" width="[(#EOL|supver_horiz_coord|strmoins{#ACTIVE_SUPPORT|supver_horiz_coord})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />]
<rect class="supver_stable" x="[(#INITIAL_RELEASE|supver_horiz_coord)]" y="[(#BRANCH|SupportedVersions::top)]" width="[(#ACTIVE_SUPPORT|supver_horiz_coord|strmoins{#INITIAL_RELEASE|supver_horiz_coord})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />
<rect class="supver_security" x="[(#ACTIVE_SUPPORT|supver_horiz_coord)]" y="[(#BRANCH|SupportedVersions::top)]" width="[(#EOL|supver_horiz_coord|strmoins{#ACTIVE_SUPPORT|supver_horiz_coord})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />]
</BOUCLE_active_branches_2>
</g>
<!-- Year lines -->
<g class="supver_years">
<BOUCLE_years(DATA){source table, #NULL|supver_years}>
<line x1="[(#VALEUR|supver_horiz_coord)]" y1="#SUPPORTED_VERSIONS{svg/header_height}" x2="[(#VALEUR|supver_horiz_coord)]" y2="[(#SUPPORTED_VERSIONS{svg/header_height}|supver_height)]" />
<BOUCLE_years(DATA){source table, #NULL|years}>
<line x1="[(#VALEUR|supver_horiz_coord)]" y1="#SUPPORTED_VERSIONS{svg/header_height}" x2="[(#VALEUR|supver_horiz_coord)]" y2="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height)]" />
<text x="[(#VALEUR|supver_horiz_coord)]" y="[(#SUPPORTED_VERSIONS{svg/header_height}|mult{0.8})]">
[(#VALEUR|affdate{M Y})]
</text>
@ -92,8 +92,8 @@
<!-- Today -->
<g class="supver_today">
<line x1="[(#DATE|affdate{Y-m-d}|supver_horiz_coord)]" y1="#SUPPORTED_VERSIONS{svg/header}" x2="[(#DATE|affdate{Y-m-d}|supver_horiz_coord)]" y2="[(#SUPPORTED_VERSIONS{svg/header_height}|supver_height)]" />
<text x="[(#DATE|affdate{Y-m-d}|supver_horiz_coord)]" y="[(#SUPPORTED_VERSIONS{svg/header_height}|supver_height|strplus{#SUPPORTED_VERSIONS{svg/footer_height}|mult{0.8}})]">
<line x1="[(#DATE|affdate{Y-m-d}|supver_horiz_coord)]" y1="#SUPPORTED_VERSIONS{svg/header}" x2="[(#DATE|affdate{Y-m-d}|supver_horiz_coord)]" y2="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height)]" />
<text x="[(#DATE|affdate{Y-m-d}|supver_horiz_coord)]" y="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height|strplus{#SUPPORTED_VERSIONS{svg/footer_height}|mult{0.8}})]">
[<:info_aujourdhui:> (#DATE|affdate)]
</text>
</g>

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

2
modeles/supportedversions_table.html

@ -11,7 +11,7 @@
</thead>
<tbody>
<BOUCLE_active_branches(DATA){source json, #CHEMIN{data/releases.json}}>[(#EOL|>={#DATE}|ou{#EOL|intval|non})
<tr[ class="(#VALEUR|supver_state)"]>
<tr[ class="(#VALEUR|SupportedVersions::state)"]>
<td>#BRANCH</td>
<td>[(#PHP|array_shift)][ - (#PHP|array_pop)]</td>
<td>[(#INITIAL_RELEASE|affdate)]</td>

112
supportedversions_fonctions.php

@ -1,5 +1,7 @@
<?php
// SPIP Standard API
function supportedversions_insert_head_css($flux) {
$flux .= '<link rel="stylesheet" type="text/css" media="all" href="'.
find_in_path('css/supported-versions.css').
@ -12,27 +14,65 @@ function supportedversions_header_prive_css($flux) {
return supportedversions_insert_head_css($flux);
}
function supver_state(array $valeurs) {
$now = new DateTime;
$initial = new DateTime($valeurs['initial_release']);
$bug = $valeurs['active_support'] ? new DateTime($valeurs['active_support']) : null;
$security = $valeurs['eol'] ? new DateTime($valeurs['eol']) : null;
if ($security && $now >= $security) {
return 'eol';
} elseif ($bug && $now >= $bug) {
return 'security';
} elseif ($now >= $initial) {
return 'stable';
} else {
return 'future';
function balise_SUPPORTED_VERSIONS_dist($p) {
return balise_ENV_dist($p, '$GLOBALS["supportedversions"]');
}
// Supported Versions filters class
class SupportedVersions
{
public static function state(array $valeurs) {
$now = new DateTime;
$initial = new DateTime($valeurs['initial_release']);
$bug = $valeurs['active_support'] ? new DateTime($valeurs['active_support']) : null;
$security = $valeurs['eol'] ? new DateTime($valeurs['eol']) : null;
if ($security && $now >= $security) {
$state = 'eol';
} elseif ($bug && $now >= $bug) {
$state = 'security';
} elseif ($now >= $initial) {
$state = 'stable';
} else {
$state = 'future';
}
return $state;
}
return '';
}
public static function top($branch) {
global $supportedversions;
function balise_SUPPORTED_VERSIONS_dist($p) {
return balise_ENV_dist($p, '$GLOBALS["supportedversions"]');
$i = array_search($branch, branches(), true);
return $supportedversions['svg']['header_height'] + ($supportedversions['svg']['branch_height'] * $i++);
}
public static function topForText($branch) {
global $supportedversions;
$top = self::top($branch) + (0.5 * $supportedversions['svg']['branch_height']);
return $top;
}
public static function width($margin_left) {
global $supportedversions;
return $margin_left +
$supportedversions['svg']['margin_right'] +
((count(years()) - 1) * $supportedversions['svg']['year_width']);
}
public static function height($header_height) {
global $supportedversions;
return $header_height +
$supportedversions['svg']['footer_height'] +
(count(branches()) * $supportedversions['svg']['branch_height']);
}
}
function supver_min_date() {
@ -68,7 +108,7 @@ function supver_horiz_coord($date) {
return supver_date_horiz_coord(supver_max_date());
}
function supver_years() {
function years() {
static $years = [];
if (empty($years)) {
@ -83,7 +123,7 @@ function supver_years() {
return $years;
}
function supver_branches() {
function branches() {
static $branches = [];
if (empty($branches)) {
@ -97,35 +137,3 @@ function supver_branches() {
return $branches;
}
function supver_top($branch) {
global $supportedversions;
$i = array_search($branch, supver_branches(), true);
return $supportedversions['svg']['header_height'] + ($supportedversions['svg']['branch_height'] * $i++);
}
function supver_top_for_text($top) {
global $supportedversions;
$top = $top + (0.5 * $supportedversions['svg']['branch_height']);
return $top;
}
function supver_width($margin_left) {
global $supportedversions;
return $margin_left +
$supportedversions['svg']['margin_right'] +
((count(supver_years()) - 1) * $supportedversions['svg']['year_width']);
}
function supver_height($header_height) {
global $supportedversions;
return $header_height +
$supportedversions['svg']['footer_height'] +
(count(supver_branches()) * $supportedversions['svg']['branch_height']);
}

Loading…
Cancel
Save