Browse Source

Ne plus passer l'ancre mais les composants pour la créer.

Icones SVG à la place des png.
PSR et améliorations du code.
master
Eric Lupinacci 1 year ago
parent
commit
b224e69fec
  1. 3
      faq_options.php
  2. 110
      faq_pipelines.php
  3. BIN
      icones_barre/faq-16.png
  4. 7
      icones_barre/faq-xx.svg
  5. BIN
      icones_barre/faq_question-16.png
  6. 13
      icones_barre/faq_question-xx.svg
  7. BIN
      icones_barre/faq_titre-16.png
  8. 15
      icones_barre/faq_titre-xx.svg
  9. 1
      inc/faq_formater_tag.php
  10. 7
      inclure/faq_dl.html
  11. 41
      wheels/faq.php

3
faq_options.php

@ -1,8 +1,7 @@
<?php
// Sécurité
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
// Ajout des raccourcis dans la liste des wheels
$GLOBALS['spip_wheels']['raccourcis'][] = 'faq';

110
faq_pipelines.php

@ -4,13 +4,18 @@
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* @param $flux
*
* @return string
*/
function faq_insert_head_css($flux) {
// On inclut systématiquement les CSS de base
$flux .= '<link rel="stylesheet" href="' . find_in_path('css/faq.css') . '" type="text/css" media="all" />';
// On ajoute si la config le demande les CSS propres aux dl
include_spip('inc/config');
$charger_css = lire_config('faq/charger_css') ? true : false;
$charger_css = lire_config('faq/charger_css');
if ($charger_css) {
$flux .= '<link rel="stylesheet" href="' . find_in_path('css/faq_dl.css') . '" type="text/css" media="all" />';
}
@ -18,9 +23,14 @@ function faq_insert_head_css($flux) {
return $flux;
}
/**
* @param $flux
*
* @return mixed|string
*/
function faq_insert_head($flux) {
include_spip('inc/config');
$charger_js = lire_config('faq/charger_js') ? true : false;
$charger_js = lire_config('faq/charger_js');
if ($charger_js) {
$flux .= '<script src="' . find_in_path('js/faq.js') . '" type="text/javascript"></script>';
}
@ -28,11 +38,19 @@ function faq_insert_head($flux) {
return $flux;
}
/**
* @param $barres
*
* @return mixed
*/
function faq_porte_plume_barre_pre_charger($barres) {
// on ajoute les boutons dans la barre d'édition seulement
foreach (array('edition') as $nom) {
$barre = &$barres[$nom];
$barre->ajouterPlusieursApres('grpCaracteres', array(
$nom = 'edition';
$barre = &$barres[$nom];
$barre->ajouterPlusieursApres(
'grpCaracteres',
array(
array(
'id' => 'faq_sep',
'separator' => '---------------',
@ -69,47 +87,57 @@ function faq_porte_plume_barre_pre_charger($barres) {
),
)
)
));
$barre->ajouterFonction("function outil_faq(h, c,recursif) {
if(recursif){
// Cas de la sélection de click sur le bouton de création de faq complète
s = h.selection;
lines = h.selection.split(/\\r?\\n/);
var lines_final = [];
for (j = 0, n = lines.length, i = 0; i < n; i++) {
// si une seule ligne, on se fiche de savoir qu'elle est vide,
// c'est volontaire si on clique le bouton
if (n == 1 || $.trim(lines[i]) !== '') {
if(r = lines[i].match(/^([+-o]) (.*)$/)){
r[1] = r[1].replace(/[+-o]/g, c);
lines_final[j] = r[1]+' '+r[2];
j++;
} else {
lines_final[j] = c + ' '+lines[i];
j++;
}
}
)
);
$barre->ajouterFonction(
"function outil_faq(h, c,recursif) {
if(recursif){
// Cas de la sélection de click sur le bouton de création de faq complète
s = h.selection;
lines = h.selection.split(/\\r?\\n/);
var lines_final = [];
for (j = 0, n = lines.length, i = 0; i < n; i++) {
// si une seule ligne, on se fiche de savoir qu'elle est vide,
// c'est volontaire si on clique le bouton
if (n == 1 || $.trim(lines[i]) !== '') {
if(r = lines[i].match(/^([+-o]) (.*)$/)){
r[1] = r[1].replace(/[+-o]/g, c);
lines_final[j] = r[1]+' '+r[2];
j++;
} else {
lines_final[j] = c + ' '+lines[i];
j++;
}
return lines_final.join('\\n');
}
// Click sur les autres boutons
if ((s = h.selection) && (r = s.match(/^([+-o]) (.*)$/))){
r[1] = r[1].replace(/[+-o]/g, c);
s = r[1]+' '+r[2];
} else {
s = c + ' '+s;
}
return s;
}");
}
}
return lines_final.join('\\n');
}
// Click sur les autres boutons
if ((s = h.selection) && (r = s.match(/^([+-o]) (.*)$/))){
r[1] = r[1].replace(/[+-o]/g, c);
s = r[1]+' '+r[2];
} else {
s = c + ' '+s;
}
return s;
}"
);
return $barres;
}
/**
* @param $flux
*
* @return array
*/
function faq_porte_plume_lien_classe_vers_icone($flux) {
return array_merge($flux, array(
'outil_faq' => 'faq-16.png',
'outil_faq_question'=> 'faq_question-16.png',
'outil_faq_titre' => 'faq_titre-16.png'
));
return array_merge(
$flux,
array(
'outil_faq' => 'faq-xx.svg',
'outil_faq_question'=> 'faq_question-xx.svg',
'outil_faq_titre' => 'faq_titre-xx.svg'
)
);
}

BIN
icones_barre/faq-16.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 709 B

7
icones_barre/faq-xx.svg

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="16" height="16" viewBox="0, 0, 16, 16">
<g id="Calque_1">
<path d="M8,14.667 C4.318,14.667 1.333,11.682 1.333,8 C1.333,4.318 4.318,1.333 8,1.333 C11.682,1.333 14.667,4.318 14.667,8 C14.667,11.682 11.682,14.667 8,14.667 z M8,13.333 C10.946,13.333 13.333,10.946 13.333,8 C13.333,5.054 10.946,2.667 8,2.667 C5.054,2.667 2.667,5.054 2.667,8 C2.667,10.946 5.054,13.333 8,13.333 z M7.333,10 L8.667,10 L8.667,11.333 L7.333,11.333 L7.333,10 z M8.667,8.903 L8.667,9.333 L7.333,9.333 L7.333,8.333 C7.333,7.965 7.632,7.667 8,7.667 C8.527,7.667 8.963,7.258 8.998,6.732 C9.032,6.207 8.653,5.744 8.131,5.675 C7.609,5.606 7.123,5.954 7.019,6.471 L5.711,6.209 C5.936,5.087 6.939,4.294 8.082,4.334 C9.225,4.374 10.17,5.236 10.315,6.37 C10.46,7.504 9.762,8.577 8.667,8.903 z" fill="#666666"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
icones_barre/faq_question-16.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

13
icones_barre/faq_question-xx.svg

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="16" height="16" viewBox="0, 0, 16, 16">
<g id="faq" display="none">
<path d="M8,14.667 C4.318,14.667 1.333,11.682 1.333,8 C1.333,4.318 4.318,1.333 8,1.333 C11.682,1.333 14.667,4.318 14.667,8 C14.667,11.682 11.682,14.667 8,14.667 z M8,13.333 C10.946,13.333 13.333,10.946 13.333,8 C13.333,5.054 10.946,2.667 8,2.667 C5.054,2.667 2.667,5.054 2.667,8 C2.667,10.946 5.054,13.333 8,13.333 z M7.333,10 L8.667,10 L8.667,11.333 L7.333,11.333 L7.333,10 z M8.667,8.903 L8.667,9.333 L7.333,9.333 L7.333,8.333 C7.333,7.965 7.632,7.667 8,7.667 C8.527,7.667 8.963,7.258 8.998,6.732 C9.032,6.207 8.653,5.744 8.131,5.675 C7.609,5.606 7.123,5.954 7.019,6.471 L5.711,6.209 C5.936,5.087 6.939,4.294 8.082,4.334 C9.225,4.374 10.17,5.236 10.315,6.37 C10.46,7.504 9.762,8.577 8.667,8.903 z" fill="#666666"/>
</g>
<g id="question">
<path d="M12.566,4.612 Q12.566,5.5 12.307,6.181 Q12.047,6.862 11.573,7.363 Q11.098,7.864 10.435,8.26 Q9.771,8.655 8.936,8.98 L8.936,10.984 L5.842,10.984 L5.842,8.022 Q6.466,7.855 6.972,7.68 Q7.477,7.504 8.031,7.108 Q8.549,6.757 8.844,6.291 Q9.138,5.825 9.138,5.236 Q9.138,4.357 8.571,3.984 Q8.004,3.61 6.976,3.61 Q6.343,3.61 5.548,3.883 Q4.752,4.155 4.093,4.586 L3.742,4.586 L3.742,1.905 Q4.304,1.668 5.473,1.409 Q6.642,1.149 7.846,1.149 Q10.017,1.149 11.292,2.107 Q12.566,3.065 12.566,4.612 z M9.182,14.5 L5.631,14.5 L5.631,12.18 L9.182,12.18 z" fill="#666666"/>
</g>
<g id="titre" display="none">
<path d="M6.547,3.26 L2.238,3.26 L2.238,1 L13.762,1 L13.762,3.26 L9.48,3.26 L9.48,15 L6.539,15 z" fill="#666666" id="intertitre"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
icones_barre/faq_titre-16.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

15
icones_barre/faq_titre-xx.svg

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="16" height="16" viewBox="0, 0, 16, 16">
<g id="faq" display="none">
<path d="M8,14.667 C4.318,14.667 1.333,11.682 1.333,8 C1.333,4.318 4.318,1.333 8,1.333 C11.682,1.333 14.667,4.318 14.667,8 C14.667,11.682 11.682,14.667 8,14.667 z M8,13.333 C10.946,13.333 13.333,10.946 13.333,8 C13.333,5.054 10.946,2.667 8,2.667 C5.054,2.667 2.667,5.054 2.667,8 C2.667,10.946 5.054,13.333 8,13.333 z M7.333,10 L8.667,10 L8.667,11.333 L7.333,11.333 L7.333,10 z M8.667,8.903 L8.667,9.333 L7.333,9.333 L7.333,8.333 C7.333,7.965 7.632,7.667 8,7.667 C8.527,7.667 8.963,7.258 8.998,6.732 C9.032,6.207 8.653,5.744 8.131,5.675 C7.609,5.606 7.123,5.954 7.019,6.471 L5.711,6.209 C5.936,5.087 6.939,4.294 8.082,4.334 C9.225,4.374 10.17,5.236 10.315,6.37 C10.46,7.504 9.762,8.577 8.667,8.903 z" fill="#666666"/>
</g>
<g id="question" display="none">
<text transform="matrix(1, 0, 0, 1, 8, 8)">
<tspan x="-5.55" y="6.5" font-family="Verdana-Bold" font-size="18" fill="#666666">?</tspan>
</text>
</g>
<g id="titre">
<path d="M6.547,3.26 L2.238,3.26 L2.238,1 L13.762,1 L13.762,3.26 L9.48,3.26 L9.48,15 L6.539,15 z" fill="#666666" id="intertitre"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

1
inc/faq_formater_tag.php

@ -1,5 +1,4 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}

7
inclure/faq_dl.html

@ -1,12 +1,13 @@
#SET{ancre, faq_#ENV{no_bloc}_#ENV{no_faq}}
<B_faq>
[<h3 class="spip">
[<a class="ancre" href="##ENV{ancre}" id="(#ENV{ancre})"></a>]
[<a class="ancre" href="##GET{ancre}" id="(#GET{ancre})"></a>]
(#ENV**{titre})
</h3>]
<dl class="faq[ (#CONFIG{faq/charger_js}|et{#CONFIG{faq/iconifier_js}}|oui)js]">
<BOUCLE_faq(DATA){source table, #ENV{faq}}{par cle}>
<dt>[
[(#CONFIG{faq/ancrer_question}|oui)[<a class="ancre" href="##ENV{ancre}_#CLE" id="(#ENV{ancre})_#CLE"></a>]]
[(#CONFIG{faq/ancrer_question}|oui)[<a class="ancre" href="##GET{ancre}_#CLE" id="(#GET{ancre})_#CLE"></a>]]
(#VALEUR{question})
]</dt>
<dd>
@ -16,7 +17,7 @@
[(#COMPTEUR_BOUCLE|=={#TOTAL_BOUCLE}|oui)</ul>]
</BOUCLE_tags>
[(#VALEUR{reponse})][
(#CONFIG{faq/lier_faq}|oui)[<a class="retour" rel="nofollow" href="#(#ENV{ancre})"><:faq:lien_debut_faq:></a>]
(#CONFIG{faq/lier_faq}|oui)[<a class="retour" rel="nofollow" href="#(#GET{ancre})"><:faq:lien_debut_faq:></a>]
]</dd>
</BOUCLE_faq>
</dl>

41
wheels/faq.php

@ -1,20 +1,24 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
// Regexp permettant de récupérer chacune des informations additionnelles qui peuvent compléter le titre de la tâche :
// - #tag, tag étant un mot. Exemple : #courses ou #перевод-шаблон
// - type:valeur ou type et valeur sont des mots. Pas utilisé pour l'instant
//
if (!defined('_FAQ_REGEXP_INFOS_COMPLEMENTAIRES')) {
/**
* Regexp permettant de récupérer chacune des informations additionnelles qui peuvent compléter le titre de la tâche :
* - #tag, tag étant un mot. Exemple : #courses ou #перевод-шаблон
* - type:valeur ou type et valeur sont des mots. Pas utilisé pour l'instant
*/
define('_FAQ_REGEXP_INFOS_COMPLEMENTAIRES', '%([\w-]+:|#)([\w.-]+)(?:\s|$)%Uu');
}
// Regexp permettant de supprimer les inclusions typographiques d'espace avant le caractère "?" :
// - &nbsp; selon la règle typographique par défaut de SPIP
// - <small class="fine">\xc2\xa0</small> selon la règle typographique du plugin orthotypo
if (!defined('_FAQ_REGEXP_ESPACE_INTERROGATION')) {
/**
* Regexp permettant de supprimer les inclusions typographiques d'espace avant le caractère "?" :
* - `&nbsp;` selon la règle typographique par défaut de SPIP
* - <small class="fine">\xc2\xa0</small> selon la règle typographique du plugin orthotypo
*/
define('_FAQ_REGEXP_ESPACE_INTERROGATION', '#^(&nbsp;|<small[^?]+)(\?.+)#is');
}
@ -26,7 +30,7 @@ if (!defined('_FAQ_REGEXP_ESPACE_INTERROGATION')) {
* une nouvelle ligne avec comme premier caractère ':'.
* Une question commence sur une nouvelle ligne avec comme premier caractère '?'. La réponse est constituée des lignes
* qui suivent la question jusqu'à la prochaine question, le prochain titre ou la fin du bloc.
* Il est possible de choisir le squelette de sortie en utilisant l'attribut format dans la balise <code><faq></code>.
* Il est possible de choisir le squelette de sortie en utilisant l'attribut format dans la balise `<faq>`.
*
* @param array $t l'index 4 représente le contenu du bloc, l'index 3 la valeur du format si il existe.
*
@ -99,8 +103,10 @@ function tw_faq($t) {
$texte = preg_replace(_FAQ_REGEXP_ESPACE_INTERROGATION, '\\2', $texte);
$premier = substr($texte, 0, 1);
if (($premier != '?')
and ($premier != ':')) {
if (
($premier !== '?')
and ($premier !== ':')
) {
// La ligne correspond à un texte de réponse non vide si une question est en cours
if ($question_en_cours) {
$reponse .= $reponse ? "\n" . $texte : $texte;
@ -119,7 +125,7 @@ function tw_faq($t) {
++$index_qr;
}
if ($premier == '?') {
if ($premier === '?') {
// On démarre une nouvelle question
// -- initialisation des variables de la question en cours
$tags = $infos = array();
@ -145,7 +151,7 @@ function tw_faq($t) {
}
} else {
// -- les informations typées
if ($formater = charger_fonction("faq_formater_${type}", 'inc', true)) {
if ($formater = charger_fonction("faq_formater_$type", 'inc', true)) {
$infos[$type] = $formater($valeur);
} else {
$infos[$type] = $valeur;
@ -158,7 +164,7 @@ function tw_faq($t) {
} else {
$question = $texte;
}
} elseif ($premier == ':') {
} else {
// Titre d'une nouvelle faq incluse dans le bloc faq en cours de traitement
++$index_faq;
$titres[$index_faq] = trim(substr($texte, 1, strlen($texte) - 1));
@ -177,14 +183,15 @@ function tw_faq($t) {
// Appel pour chaque FAQ du modèle demandé ou par défaut
if ($faqs) {
$html = '';
$format = $t[3] ? $t[3] : 'dl';
$format = $t[3] ?: 'dl';
foreach ($faqs as $_cle => $_faq) {
if ($_faq) {
$html .= recuperer_fond(
"inclure/faq_${format}",
"inclure/faq_$format",
array(
'titre' => (isset($titres[$_cle]) ? $titres[$_cle] : ''),
'ancre' => "faq_${no_bloc}_${_cle}",
'no_bloc' => $no_bloc,
'no_faq' => $_cle,
'titre' => ($titres[$_cle] ?? ''),
'faq' => $_faq,
'types_info' => $types_info[$_cle]
),

Loading…
Cancel
Save