Browse Source

PSR via phpcbf

master v4.6.1.0
Cerdic 11 months ago
parent
commit
ce601c1b76
  1. 19
      bootstrap2spip/formulaires/charter.php
  2. 148
      bootstrap2spip/prefixer_css.php
  3. 156
      bootstrap4_fonctions.php
  4. 81
      bootstrap4_options.php
  5. 17
      phpcs.xml.dist
  6. 50
      spip-cli/BootstrapBuildIcons.php

19
bootstrap2spip/formulaires/charter.php

@ -1,6 +1,7 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) { return;
}
/**
* Chargement des valeurs
@ -8,16 +9,16 @@ if (!defined('_ECRIRE_INC_VERSION')) return;
*/
function formulaires_charter_charger_dist() {
$valeurs = array(
$valeurs = [
'text' => '',
'text_obli' => '',
'textarea' => '',
'textarea_pleine_largeur' => '',
'text_long_label' => '',
'radio' => 'non',
'checkbox' => array(1),
'checkbox_long_label' => array(1,2),
);
'checkbox' => [1],
'checkbox_long_label' => [1,2],
];
return $valeurs;
}
@ -28,10 +29,10 @@ function formulaires_charter_charger_dist() {
* @return array
*/
function formulaires_charter_verifier_dist() {
$erreurs = array();
if (_request('cancel')){
$erreurs = [];
if (_request('cancel')) {
$erreurs['message_erreur'] = ('Un long message d\'erreur, long message d\'erreur, long message d\'erreur, long message d\'erreur, long message d\'erreur, long message d\'erreur, long message d\'erreur...');
$erreurs['text'] = ('Erreur<br />'."<input type='checkbox' name='confirm' id='confirm' value='oui' /><label for='confirm'>Confirmez que vous &ecirc;tes sur</label>");
$erreurs['text'] = ('Erreur<br />' . "<input type='checkbox' name='confirm' id='confirm' value='oui' /><label for='confirm'>Confirmez que vous &ecirc;tes sur</label>");
$erreurs['text_obli'] = ('Erreur');
$erreurs['textarea'] = ('Un long message d\'erreur, long message d\'erreur, long message d\'erreur, long message d\'erreur, long message d\'erreur, long message d\'erreur, long message d\'erreur...');
$erreurs['textarea_pleine_largeur'] = ('Erreur');
@ -49,5 +50,5 @@ function formulaires_charter_verifier_dist() {
* Traitement de la saisie
*/
function formulaires_charter_traiter_dist() {
return array('message_ok' => ('Bravo, c\'est une reussite !'));
return ['message_ok' => ('Bravo, c\'est une reussite !')];
}

148
bootstrap2spip/prefixer_css.php

@ -22,7 +22,6 @@ function prefixer_css($source) {
and preg_match(',\.css$,i', $source, $r)
and file_exists($source)
) {
$f = basename($source, $r[0]);
$f = sous_repertoire(_DIR_VAR, 'cache-prefixer')
. preg_replace(
@ -36,14 +35,17 @@ function prefixer_css($source) {
# si la feuille prefixee est plus recente que la feuille source
# l'utiliser sans rien faire, sauf si il y a un var_mode
$changed = false;
if (@filemtime($f) < @filemtime($source)){
if (@filemtime($f) < @filemtime($source)) {
$changed = true;
}
// si pas change ET pas de var_mode du tout, rien a faire (performance)
if (!$changed
AND !defined('_VAR_MODE'))
if (
!$changed
and !defined('_VAR_MODE')
) {
return $f;
}
$contenu = false;
if (!lire_fichier($source, $contenu)) {
@ -58,9 +60,9 @@ function prefixer_css($source) {
// ecrire le fichier destination, en cas d'echec renvoyer la source
// on ecrit sur un fichier
if (ecrire_fichier($f.'.last', $contenu, true)) {
if ($changed or md5_file($f) != md5_file($f.'.last')) {
@copy($f.'.last', $f);
if (ecrire_fichier($f . '.last', $contenu, true)) {
if ($changed or md5_file($f) != md5_file($f . '.last')) {
@copy($f . '.last', $f);
// eviter que PHP ne reserve le vieux timestamp
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
clearstatcache(true, $f);
@ -83,80 +85,80 @@ function prefixer_css_inline($css) {
// les proprietes qu'on veut prefixer par une ou plusieurs variantes
$list = [
"align-items" => ["-ms-flex-align"],
"align-content" => ["-ms-flex-line-pack"],
"align-self" => ["-ms-flex-item-align"],
"animation" => ["-webkit-animation"],
"appearance" => ["-webkit-appearance", "-moz-appearance"],
'align-items' => ['-ms-flex-align'],
'align-content' => ['-ms-flex-line-pack'],
'align-self' => ['-ms-flex-item-align'],
'animation' => ['-webkit-animation'],
'appearance' => ['-webkit-appearance', '-moz-appearance'],
"backdrop-filter" => ["-webkit-backdrop-filter"],
"backface-visibility" => ["-webkit-backface-visibility"],
'backdrop-filter' => ['-webkit-backdrop-filter'],
'backface-visibility' => ['-webkit-backface-visibility'],
"column-count" => ["-webkit-column-count", "-moz-column-count"],
"column-gap" => ["-webkit-column-gap", "-moz-column-gap"],
'column-count' => ['-webkit-column-count', '-moz-column-count'],
'column-gap' => ['-webkit-column-gap', '-moz-column-gap'],
"flex-basis" => ["-ms-flex-preferred-size"],
"flex-grow" => ["-ms-flex-positive"],
"flex-wrap" => ["-ms-flex-wrap"],
"flex-flow" => ["-ms-flex-flow"],
"flex-shrink" => ["-ms-flex-negative"],
"flex-direction" => ["-ms-flex-direction"],
"flex" => ["-ms-flex"],
'flex-basis' => ['-ms-flex-preferred-size'],
'flex-grow' => ['-ms-flex-positive'],
'flex-wrap' => ['-ms-flex-wrap'],
'flex-flow' => ['-ms-flex-flow'],
'flex-shrink' => ['-ms-flex-negative'],
'flex-direction' => ['-ms-flex-direction'],
'flex' => ['-ms-flex'],
"justify-content" => ["-ms-flex-pack"],
'justify-content' => ['-ms-flex-pack'],
"order" => ["-ms-flex-order"],
'order' => ['-ms-flex-order'],
"user-select" => ["-webkit-user-select", "-moz-user-select", "-ms-user-select"],
'user-select' => ['-webkit-user-select', '-moz-user-select', '-ms-user-select'],
"text-decoration" => ["-webkit-text-decoration"],
"text-decoration-skip-ink" => ["-webkit-text-decoration-skip-ink"],
"touch-action" => ["-ms-touch-action"],
"transform" => ["-webkit-transform"],
'text-decoration' => ['-webkit-text-decoration'],
'text-decoration-skip-ink' => ['-webkit-text-decoration-skip-ink'],
'touch-action' => ['-ms-touch-action'],
'transform' => ['-webkit-transform'],
// cas particuliers : la propriete ne change pas, mais on passe par le remplacement de valeurs qui fait le job de prefixage
"display" => ["display"],
"position" => ["position"],
'display' => ['display'],
'position' => ['position'],
];
// les renommages de valeur sur les proprietes remplacees
$values_replacement = [
"-ms-flex-align" => [
"flex-start" => "start",
"flex-end" => "end",
'-ms-flex-align' => [
'flex-start' => 'start',
'flex-end' => 'end',
],
"-ms-flex-item-align" => [
"flex-start" => "start",
"flex-end" => "end",
'-ms-flex-item-align' => [
'flex-start' => 'start',
'flex-end' => 'end',
],
"-ms-flex-line-pack" => [
"flex-start" => "start",
"flex-end" => "end",
"space-between" => "justify",
"space-around" => "distribute",
'-ms-flex-line-pack' => [
'flex-start' => 'start',
'flex-end' => 'end',
'space-between' => 'justify',
'space-around' => 'distribute',
],
"-ms-flex-pack" => [
"flex-start" => "start",
"flex-end" => "end",
"space-between" => "justify",
"space-around" => "distribute",
'-ms-flex-pack' => [
'flex-start' => 'start',
'flex-end' => 'end',
'space-between' => 'justify',
'space-around' => 'distribute',
],
"display" => [
"flex" => "-ms-flexbox",
"inline-flex" => "-ms-inline-flexbox",
'display' => [
'flex' => '-ms-flexbox',
'inline-flex' => '-ms-inline-flexbox',
],
"position" => [
"sticky" => "-webkit-sticky",
'position' => [
'sticky' => '-webkit-sticky',
],
];
// les eventuelles evaluation de condition avant remplacement
$prefix_conditions = [
"-webkit-text-decoration" => "prefixer_is_value_multiple",
'-webkit-text-decoration' => 'prefixer_is_value_multiple',
];
// et on lance
foreach ($list as $property=>$prefixed_list) {
foreach ($list as $property => $prefixed_list) {
$css = prefixer_prefix_property($css, $property, $prefixed_list, $prefix_conditions, $values_replacement);
}
return $css;
@ -168,11 +170,11 @@ function prefixer_css_inline($css) {
* @return bool
*/
function prefixer_is_value_multiple($line) {
$value = explode(':', $line,2)[1];
$value = str_replace("!important", "", $value);
$value = trim($value,';}');
$value = explode(':', $line, 2)[1];
$value = str_replace('!important', '', $value);
$value = trim($value, ';}');
$value = trim($value);
if (count(explode(' ', $value))>1) {
if (count(explode(' ', $value)) > 1) {
return true;
}
return false;
@ -191,10 +193,10 @@ function prefixer_replace_value($line, $replacement) {
if (is_string($prefixed_values)) {
$prefixed_values = [$prefixed_values];
}
foreach($prefixed_values as $prefixed_value) {
foreach ($prefixed_values as $prefixed_value) {
$v = $base_value;
if (strpos($base_value, $standard_value) !== false) {
$v = preg_replace(",(^|[\s]){$standard_value}($|\s|;|\))," , "$1$prefixed_value$2", $v);
$v = preg_replace(",(^|[\s]){$standard_value}($|\s|;|\)),", "$1$prefixed_value$2", $v);
}
if ($v !== $base_value) {
$out .= $base_property . ':' . $v;
@ -218,26 +220,26 @@ function prefixer_replace_value($line, $replacement) {
*/
function prefixer_prefix_property($css, $standard_property, $prefixed_list, $prefix_conditions, $values_replacement) {
$p = 0;
while (($p = strpos($css, $standard_property . ":", $p)) !== false) {
while (($p = strpos($css, $standard_property . ':', $p)) !== false) {
// go back to previous space or { or ;
$pstart = $pend = $p;
while ($pstart>0 && !in_array($css[$pstart-1], array("\r","\n",'{',';','('))) {
while ($pstart > 0 && !in_array($css[$pstart - 1], ["\r","\n",'{',';','('])) {
$pstart--;
if (!in_array($css[$pstart], array(" ", "\t"))) {
$p+=strlen($standard_property);
if (!in_array($css[$pstart], [' ', "\t"])) {
$p += strlen($standard_property);
continue 2;
}
}
while ($p>0 && in_array($css[$pstart-1], array("\r","\n"))) {
while ($p > 0 && in_array($css[$pstart - 1], ["\r","\n"])) {
$pstart--;
}
$len = strlen($css);
$endchars = array(';','}');
if ($css[$pstart-1] == '(') {
$endchars = [';','}'];
if ($css[$pstart - 1] == '(') {
$pstart--;
$endchars[] = ')';
}
while ($pend<$len && !in_array($css[$pend],$endchars)) {
while ($pend < $len && !in_array($css[$pend], $endchars)) {
$pend++;
}
$pend++;
@ -249,12 +251,12 @@ function prefixer_prefix_property($css, $standard_property, $prefixed_list, $pre
$is_expression = false;
// si on est entre des () c'est un @support ()
if (substr($property_line, 0, 1) == '(' && substr($property_line, -1) == ')') {
$property_line = $property_line . " or ";
$property_line = $property_line . ' or ';
$is_expression = true;
}
$insert = "";
$insert = '';
foreach ($prefixed_list as $prefixed) {
$line = str_replace("$standard_property:","$prefixed:", $property_line);
$line = str_replace("$standard_property:", "$prefixed:", $property_line);
if (!isset($prefix_conditions[$prefixed]) or $prefix_conditions[$prefixed]($line)) {
if (isset($values_replacement[$prefixed])) {
$line = prefixer_replace_value($line, $values_replacement[$prefixed]);
@ -280,4 +282,4 @@ function prefixer_prefix_property($css, $standard_property, $prefixed_list, $pre
$p = $pend + strlen($insert);
}
return $css;
}
}

156
bootstrap4_fonctions.php

@ -1,8 +1,10 @@
<?php
if (!defined("_ECRIRE_INC_VERSION")) return;
if (!defined('_ECRIRE_INC_VERSION')) { return;
}
if (!defined('_MENUS_EXTRA_CLASS')) define('_MENUS_EXTRA_CLASS','nav');
if (!defined('_MENUS_EXTRA_CLASS')) { define('_MENUS_EXTRA_CLASS', 'nav');
}
/**
* |prefixer_css a utiliser dans le squelette head pour prefixer BS4 et etendre sa compatibilite
@ -25,46 +27,54 @@ function filtre_prefixer_css_dist($css) {
* @param string $class_collapse nom de la class à plier/déplier
* @return string
*/
function navbar_responsive($nav, $class_collapse = 'nav-collapse-main'){
function navbar_responsive($nav, $class_collapse = 'nav-collapse-main') {
static $navbarcount = 1;
if (strpos($nav,'navbar-collapse')!==false) return $nav;
if (strpos($nav, 'navbar-collapse') !== false) { return $nav;
}
// les classes BS4
$respnav = $nav;
if (strpos($respnav, 'navbar-nav') === false) {
$respnav = str_replace("menu-liste", "menu-liste navbar-nav", $respnav);
$respnav = str_replace('menu-liste', 'menu-liste navbar-nav', $respnav);
}
if (strpos($respnav, 'nav-item') === false){
$respnav = str_replace("menu-entree", "menu-entree nav-item", $respnav);
if (strpos($respnav, 'nav-item') === false) {
$respnav = str_replace('menu-entree', 'menu-entree nav-item', $respnav);
}
if (strpos($respnav, 'nav-link') === false){
$respnav = str_replace("menu-items__lien", "menu-items__lien nav-link", $respnav);
if (strpos($respnav, 'nav-link') === false) {
$respnav = str_replace('menu-items__lien', 'menu-items__lien nav-link', $respnav);
}
$uls = extraire_balises($nav,"ul");
$uls = extraire_balises($nav, 'ul');
$n = 1;
while ($ul = array_shift($uls)
AND strpos($navclass = extraire_attribut($ul,"class"),"nav")===false){
while (
$ul = array_shift($uls)
and strpos($navclass = extraire_attribut($ul, 'class'), 'nav') === false
) {
$n++;
}
if ($ul){
$id = "navbar-".substr(md5($navbarcount . ':' . time() .':' . $nav),0,4);
$p = strpos($respnav,$ul);
$respnav = substr_replace($respnav,
'<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#' . $id . '" aria-controls="'. $id . '" aria-expanded="false" aria-label="Toggle navigation">'
if ($ul) {
$id = 'navbar-' . substr(md5($navbarcount . ':' . time() . ':' . $nav), 0, 4);
$p = strpos($respnav, $ul);
$respnav = substr_replace(
$respnav,
'<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#' . $id . '" aria-controls="' . $id . '" aria-expanded="false" aria-label="Toggle navigation">'
. '<span class="navbar-toggler-icon"></span>'
. '</button>'
. "\n" . '<div class="collapse navbar-collapse ' . $class_collapse . '" id="'.$id.'">',$p,0);
$l=strlen($respnav);$p=$l-1;
while ($n--){
$p = strrpos($respnav,"</ul>",$p-$l);
. "\n" . '<div class="collapse navbar-collapse ' . $class_collapse . '" id="' . $id . '">',
$p,
0
);
$l = strlen($respnav);
$p = $l - 1;
while ($n--) {
$p = strrpos($respnav, '</ul>', $p - $l);
}
if ($p) {
$respnav = substr_replace($respnav, '</div>', $p + 5, 0);
} else { $respnav = $nav;
}
if ($p)
$respnav = substr_replace($respnav,'</div>',$p+5,0);
else
$respnav = $nav;
}
return $respnav;
}
@ -83,34 +93,36 @@ function navbar_responsive($nav, $class_collapse = 'nav-collapse-main'){
* @param string $evt
* @return string
*/
function filtre_lien_ou_expose_dist($url,$libelle=NULL,$on=false,$class="",$title="",$rel="", $evt=''){
function filtre_lien_ou_expose_dist($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
if ($on) {
$bal = 'strong';
$class = "";
$att = "";
$class = '';
$att = '';
// si $on passe la balise et optionnelement une ou ++classe
// a.active span.selected.active etc....
if (is_string($on) AND (strncmp($on,'a',1)==0 OR strncmp($on,'span',4)==0 OR strncmp($on,'strong',6)==0)){
$on = explode(".",$on);
if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
$on = explode('.', $on);
// on verifie que c'est exactement une des 3 balises a, span ou strong
if (in_array(reset($on),array('a','span','strong'))){
if (in_array(reset($on), ['a','span','strong'])) {
$bal = array_shift($on);
$class = implode(" ",$on);
if ($bal=="a")
$class = implode(' ', $on);
if ($bal == 'a') {
$att = 'href="#" ';
}
}
}
$att .= 'class="'.($class?attribut_html($class).' ':'').'on active"';
$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . 'on active"';
} else {
$bal = 'a';
$att = "href='$url'"
.($title?" title='".attribut_html($title)."'":'')
.($class?" class='".attribut_html($class)."'":'')
.($rel?" rel='".attribut_html($rel)."'":'')
.$evt;
. ($title ? " title='" . attribut_html($title) . "'" : '')
. ($class ? " class='" . attribut_html($class) . "'" : '')
. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
. $evt;
}
if ($libelle === NULL)
if ($libelle === null) {
$libelle = $url;
}
return "<$bal $att>$libelle</$bal>";
}
@ -130,28 +142,28 @@ function filtre_lien_ou_expose_dist($url,$libelle=NULL,$on=false,$class="",$titl
* et avant execution de l'action. Si la callback renvoie false, elle annule le declenchement de l'action
* @return string
*/
function filtre_bouton_action_dist($libelle, $url, $class="", $confirm="", $title="", $callback=""){
function filtre_bouton_action_dist($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
if ($confirm) {
$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
if ($callback)
$confirm = 'confirm("' . attribut_html($confirm) . '")';
if ($callback) {
$callback = "$confirm?($callback):false";
else
$callback = $confirm;
} else { $callback = $confirm;
}
}
$ajax = explode(' ', $class);
if (in_array('ajax', $ajax)) {
$ajax = ' ajax';
} else { $ajax = '';
}
$ajax = explode(" ",$class);
if (in_array("ajax",$ajax))
$ajax = " ajax";
else
$ajax = "";
$onclick = $callback?" onclick='return ".addcslashes($callback,"'")."'":"";
$title = $title ? " title='$title'" : "";
$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
$title = $title ? " title='$title'" : '';
// il faut un class btn-xxx pour que le bouton soit style : on ajoute par defaut btn-secondary si rien fourni
// dans les classes passees en arg
if (strpos($class, 'btn-') === false) {
$class = trim("btn-secondary $class");
}
return "<form class='bouton_action_post$ajax' method='post' action='$url'><div>".form_hidden($url)
."<button type='submit' class='submit btn $class'$title$onclick>$libelle</button></div></form>";
return "<form class='bouton_action_post$ajax' method='post' action='$url'><div>" . form_hidden($url)
. "<button type='submit' class='submit btn $class'$title$onclick>$libelle</button></div></form>";
}
@ -162,22 +174,25 @@ function filtre_bouton_action_dist($libelle, $url, $class="", $confirm="", $titl
*/
function bootstrap4_styliser($flux) {
if (test_espace_prive()) {
if (strpos($flux['data'], 'modeles/pagination') !== false
if (
strpos($flux['data'], 'modeles/pagination') !== false
and strpos($flux['data'], 'prive/modeles/') === false
and basename(dirname($flux['data'])) === 'modeles'
and $modele_pagination = basename($flux['data'])){
if ($f = find_in_path("prive/modeles/{$modele_pagination}.html")
or $f = find_in_path("prive/modeles/pagination.html")) {
and basename(dirname($flux['data'])) === 'modeles'
and $modele_pagination = basename($flux['data'])
) {
if (
$f = find_in_path("prive/modeles/{$modele_pagination}.html")
or $f = find_in_path('prive/modeles/pagination.html')
) {
$flux['data'] = substr($f, 0, -5);
}
}
}
return $flux;
}
if (!test_espace_prive()){
if (!test_espace_prive()) {
/**
* Ouvrir une boite
@ -187,15 +202,16 @@ if (!test_espace_prive()){
* @param string $class
* @return <type>
*/
function filtre_boite_ouvrir_dist($titre, $class='', $head_class='', $id=""){
function filtre_boite_ouvrir_dist($titre, $class = '', $head_class = '', $id = '') {
$class = "card card-box $class";
$head_class = "card-header $head_class";
// dans l'espace prive, titrer en h3 si pas de balise <hn>
if (test_espace_prive() AND strlen($titre) AND strpos($titre,'<h')===false)
if (test_espace_prive() and strlen($titre) and strpos($titre, '<h') === false) {
$titre = "<h3>$titre</h3>";
return '<div class="'.$class.($id?"\" id=\"$id":"").'">'
.($titre?'<div class="'.$head_class.'">'.$titre.'</div>':'')
.'<div class="card-body">';
}
return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">'
. ($titre ? '<div class="' . $head_class . '">' . $titre . '</div>' : '')
. '<div class="card-body">';
}
/**
@ -205,10 +221,10 @@ function filtre_boite_ouvrir_dist($titre, $class='', $head_class='', $id=""){
* @param <type> $class
* @return <type>
*/
function filtre_boite_pied_dist($class='act'){
function filtre_boite_pied_dist($class = 'act') {
$class = "card-footer $class";
return '</div>'
.'<div class="'.$class.'">';
. '<div class="' . $class . '">';
}
/**
@ -217,9 +233,9 @@ function filtre_boite_pied_dist($class='act'){
*
* @return <type>
*/
function filtre_boite_fermer_dist(){
function filtre_boite_fermer_dist() {
return '</div>'
.'</div>';
. '</div>';
}
}

81
bootstrap4_options.php

@ -1,62 +1,62 @@
<?php
$GLOBALS['marqueur_skel'] = (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : '').":bootstrap4";
$GLOBALS['marqueur_skel'] = (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : '') . ':bootstrap4';
// la puce sans image si jamais on est pas encore en SPIP 3.3+
$GLOBALS['puce'] = '<span class="spip-puce ltr"><b></b></span>';
$GLOBALS['puce_rtl'] = '<span class="spip-puce rtl"><b></b></span>';
// les icones BS4
// un fichier qui contient toutes les icones, utilise pour la page de demo uniquement
define('_ICON_SPRITE_SVG_FILE', "img/bi-all-symbols.svg");
define('_ICON_SPRITE_SVG_FILE', 'img/bi-all-symbols.svg');
// 2 sprites : celui de base + celui avec les variantes fill
define('_ICON_SPRITE_SVG_NOFILL_FILE', "img/bi-symbols.svg");
define('_ICON_SPRITE_SVG_FILL_FILE', "img/bi-fill-symbols.svg");
define('_ICON_SPRITE_SVG_NOFILL_FILE', 'img/bi-symbols.svg');
define('_ICON_SPRITE_SVG_FILL_FILE', 'img/bi-fill-symbols.svg');
// 1 sprite mini : juste pour les icones de z/spipr
define('_ICON_SPRITE_SVG_MIN_FILE', "img/bi-min-symbols.svg");
define('_ICON_SPRITE_SVG_MIN_FILE', 'img/bi-min-symbols.svg');
define('_ICON_SPRITE_SVG_ID_PREFIX', "bi-");
define('_ICON_SPRITE_SVG_ID_PREFIX', 'bi-');
function filtre_icone_href_class_from_name($name) {
static $sprite_files = [];
if (strpos($name,'#') !== false or strpos($name,'/') !== false or strpos($name,'.svg') !== false){
if (strpos($name, '#') !== false or strpos($name, '/') !== false or strpos($name, '.svg') !== false) {
return filtre_icone_href_class_from_name_dist($name);
}
else {
if (!$name) {
return array(find_in_path(_ICON_SPRITE_SVG_FILE), '');
return [find_in_path(_ICON_SPRITE_SVG_FILE), ''];
}
$icone_anchor_from_name = chercher_filtre("icone_anchor_from_name");
$icone_anchor_from_name = chercher_filtre('icone_anchor_from_name');
$anchor = $icone_anchor_from_name($name);
// on a un petit sprite dedie aux icones utilisees par defaut par Z-core et spipr-xx pour ne pas charger la mule
// c'est un sprite maintenu a la main, lister ici les icones qu'il contient
if (in_array($anchor,['bi-person','bi-calendar','bi-chevron-left','bi-chevron-right','bi-chat','bi-tag','bi-check-box','bi-skip-start','bi-skip-end'])) {
if (!isset($sprite_files['min'])){
if (in_array($anchor, ['bi-person','bi-calendar','bi-chevron-left','bi-chevron-right','bi-chat','bi-tag','bi-check-box','bi-skip-start','bi-skip-end'])) {
if (!isset($sprite_files['min'])) {
$sprite_files['min'] = timestamp(find_in_path(_ICON_SPRITE_SVG_MIN_FILE));
}
$file = $sprite_files['min'];
}
// c'est le sprite par defaut avec un name qui correspond a l'ancre abregee
// et la gestion de quelques historiques de nommage/renommage
elseif (strpos($name, '-fill') !== false){
if (!isset($sprite_files['fill'])){
elseif (strpos($name, '-fill') !== false) {
if (!isset($sprite_files['fill'])) {
$sprite_files['fill'] = timestamp(find_in_path(_ICON_SPRITE_SVG_FILL_FILE));
}
$file = $sprite_files['fill'];
}
else {
if (!isset($sprite_files['nofill'])){
if (!isset($sprite_files['nofill'])) {
$sprite_files['nofill'] = timestamp(find_in_path(_ICON_SPRITE_SVG_NOFILL_FILE));
}
$file = $sprite_files['nofill'];
}
// sanitizer l'ancre pour la class
$class = preg_replace(",[^\w\-],", "", $name);
$class = preg_replace(',[^\w\-],', '', $name);
if (_ICON_SPRITE_SVG_ID_PREFIX) {
$class .= " " . _ICON_SPRITE_SVG_ID_PREFIX . "icon";
$class .= ' ' . _ICON_SPRITE_SVG_ID_PREFIX . 'icon';
}
return array($file . '#' . $anchor, $class);
return [$file . '#' . $anchor, $class];
}
}
@ -67,33 +67,33 @@ function filtre_icone_anchor_from_name($name) {
}
}
switch ($name) {
case "comment":
case "msg":
case 'comment':
case 'msg':
$ancre = 'chat';
break;
case "ok-circle":
case 'ok-circle':
$ancre = 'check-box';
break;
case "user":
case 'user':
$ancre = 'person';
break;
case "end":
case "start":
case 'end':
case 'start':
$ancre = 'skip-' . $name;
break;
case "close":
case 'close':
$ancre = 'x';
break;
case "chevron-top":
case 'chevron-top':
$ancre = 'chevron-up';
break;
case "chevron-bottom":
case 'chevron-bottom':
$ancre = 'chevron-down';
break;
case "caret-top":
case 'caret-top':
$ancre = 'caret-up';
break;
case "caret-bottom":
case 'caret-bottom':
$ancre = 'caret-down';
break;
default:
@ -104,26 +104,27 @@ function filtre_icone_anchor_from_name($name) {
}
function bootstrap4_affichage_final($flux){
function bootstrap4_affichage_final($flux) {
if (
$GLOBALS['html']
AND isset($GLOBALS['visiteur_session']['statut'])
AND $GLOBALS['visiteur_session']['statut']=='0minirezo'
AND $GLOBALS['visiteur_session']['webmestre']=='oui'
AND strpos($flux,"<!-- insert_head -->")!==false
AND $p=stripos($flux,"</body>")
and isset($GLOBALS['visiteur_session']['statut'])
and $GLOBALS['visiteur_session']['statut'] == '0minirezo'
and $GLOBALS['visiteur_session']['webmestre'] == 'oui'
and strpos($flux, '<!-- insert_head -->') !== false
and $p = stripos($flux, '</body>')
) {
if ($f = find_in_path("js/hashgrid.js")){
$flux = substr_replace($flux,'<script type="text/javascript" src="'.$f.'"></script>',$p,0);
if ($f = find_in_path('js/hashgrid.js')) {
$flux = substr_replace($flux, '<script type="text/javascript" src="' . $f . '"></script>', $p, 0);
}
if ((_VAR_MODE === 'debug' || _request('var_profile'))
AND $p=stripos($flux,"</head>")){
if (
(_VAR_MODE === 'debug' || _request('var_profile'))
and $p = stripos($flux, '</head>')
) {
$file_css = direction_css(scss_select_css('css/spip.admin.css'));
$css = file_get_contents($file_css);
$css = "<style type='text/css'>$css</style>";
$flux = substr_replace($flux,$css,$p,0);
$flux = substr_replace($flux, $css, $p, 0);
}
}
return $flux;
}

17
phpcs.xml.dist

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset>
<file>bootstrap2spip/prefixer_css.php</file>
<file>bootstrap2spip/formulaires/</file>
<file>spip-cli</file>
<file>bootstrap4_fonctions.php</file>
<file>bootstrap4_options.php</file>
<rule ref="SPIP40"/>
<rule ref="PSR1"/>
<config name="ignore_warnings_on_exit" value="1"/>
<arg name="cache" value=".php_cs.cache"/>
<arg name="report-full" value=".php_cs.txt"/>
<arg name="report-summary"/>
<arg value="s"/>
</ruleset>

50
spip-cli/BootstrapBuildIcons.php

@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\OutputInterface;
class BootstrapBuildIcons extends Command {
protected $liste_min = ['person', 'calendar', 'chevron-left', 'chevron-right', 'chat', 'tag', 'check-box', 'skip-end', 'skip-start'];
protected function configure(){
protected function configure() {
$this
->setName('bootstrap:build:icons')
->setDescription('Générer les sprites d\'icones Bootstrap à partir du repo bootstrap-icons')
@ -24,7 +24,7 @@ class BootstrapBuildIcons extends Command {
);
}
protected function execute(InputInterface $input, OutputInterface $output){
protected function execute(InputInterface $input, OutputInterface $output) {
$path = $input->getOption('path');
if (!$path) {
@ -33,42 +33,42 @@ class BootstrapBuildIcons extends Command {
$this->io->care("path = $path");
}
}
if (!$path){
$this->io->error("Indiquez un path");
if (!$path) {
$this->io->error('Indiquez un path');
return self::FAILURE;
}
$path = rtrim($path, '/');
$path_icons = $path . '/icons';
if (!is_dir($path_icons)){
$this->io->error("Indiquez un path qui contient le dossier icons/ de TWBS");
if (!is_dir($path_icons)) {
$this->io->error('Indiquez un path qui contient le dossier icons/ de TWBS');
return self::FAILURE;
}
$files = glob($path_icons . '/*.svg');
$sprite = "";
$sprite_fill = "";
$sprite_min = "";
$sprite = '';
$sprite_fill = '';
$sprite_min = '';
foreach ($files as $file){
foreach ($files as $file) {
$svg = file_get_contents($file);
$svg = explode('>', $svg, 2);
$svg[0] = str_replace("width=\"1em\" height=\"1em\" ", "", $svg[0]);
$svg[0] = str_replace("width=\"16\" height=\"16\" ", "", $svg[0]);
$svg[0] = str_replace(" fill=\"currentColor\"", "", $svg[0]);
$svg[0] = str_replace(" xmlns=\"http://www.w3.org/2000/svg\"", "", $svg[0]);
$svg[0] = str_replace("class=\"bi bi-", "id=\"bi-", $svg[0]);
$svg[0] = str_replace("<svg ", "<symbol ", $svg[0]);
$svg[0] = str_replace('width="1em" height="1em" ', '', $svg[0]);
$svg[0] = str_replace('width="16" height="16" ', '', $svg[0]);
$svg[0] = str_replace(' fill="currentColor"', '', $svg[0]);
$svg[0] = str_replace(' xmlns="http://www.w3.org/2000/svg"', '', $svg[0]);
$svg[0] = str_replace('class="bi bi-', 'id="bi-', $svg[0]);
$svg[0] = str_replace('<svg ', '<symbol ', $svg[0]);
$svg = implode('>', $svg);
$svg = str_replace("</svg>", "</symbol>", $svg);
$svg = str_replace('</svg>', '</symbol>', $svg);
if (strpos($file, '-fill')!==false){
if (strpos($file, '-fill') !== false) {
$sprite_fill .= "$svg\n";
} else {
$sprite .= "$svg\n";
}
if (in_array(basename($file, '.svg'), $this->liste_min)){
if (in_array(basename($file, '.svg'), $this->liste_min)) {
$sprite_min .= "$svg\n";
}
}
@ -78,14 +78,14 @@ class BootstrapBuildIcons extends Command {
$sprite_fill = "<svg xmlns=\"http://www.w3.org/2000/svg\">\n$sprite_fill</svg>";
$sprite_min = "<svg xmlns=\"http://www.w3.org/2000/svg\">\n$sprite_min</svg>";
file_put_contents($path . "/bi-all-symbols.svg", $sprite_all);
file_put_contents($path . "/bi-symbols.svg", $sprite);
file_put_contents($path . "/bi-fill-symbols.svg", $sprite_fill);
file_put_contents($path . "/bi-min-symbols.svg", $sprite_min);
file_put_contents($path . '/bi-all-symbols.svg', $sprite_all);
file_put_contents($path . '/bi-symbols.svg', $sprite);
file_put_contents($path . '/bi-fill-symbols.svg', $sprite_fill);
file_put_contents($path . '/bi-min-symbols.svg', $sprite_min);
$this->io->care("Built terminé");
$this->io->care('Built terminé');
passthru("ls -l $path/bi-*.svg");
return self::SUCCESS;
}
}
}

Loading…
Cancel
Save