Browse Source

Fix #7 : comme pour le plugin mailshot, on utilise la fonction spip_affiche_mot_de_passe_masque() si elle existe et sinon on a une implementation fallback. L'affichage partiel est reserve aux webmestres

pull/9/head
Cerdic 2 years ago
parent
commit
b9910c38e9
  1. 39
      facteur_fonctions.php
  2. 2
      formulaires/inc-config-facteur-mailer-mailjet.html
  3. 2
      formulaires/inc-config-facteur-mailer-smtp.html
  4. 2
      paquet.xml

39
facteur_fonctions.php

@ -9,17 +9,42 @@
if (!defined("_ECRIRE_INC_VERSION")) return;
function facteur_affiche_password_masque($pass){
$l = strlen($pass);
if ($l<=8){
return str_pad('',$l,'*');
/**
* Afficher partiellement un mot de passe que l'on ne veut pas rendre lisible par un champ hidden
* @param string $passe
* @param bool $afficher_partiellement
* @param int|null $portion_pourcent
* @return string
*/
function facteur_affiche_password_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
if (function_exists('spip_affiche_mot_de_passe_masque')) {
return spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement, $portion_pourcent);
}
$l = strlen($passe);
if ($l<=8 or !$afficher_partiellement){
if (!$l) {
return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
}
return str_pad('',$afficher_partiellement ? $l : 16,'*');
}
if (is_null($portion_pourcent)) {
if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
}
$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
}
if ($portion_pourcent >= 100) {
return $passe;
}
$e = intval(ceil($l/10));
$e = intval(ceil($l * $portion_pourcent / 100 / 2));
$e = max($e, 0);
$mid = str_pad('',$l-2*$e,'*');
if (strlen($mid)>8){
if ($e>0 and strlen($mid)>8){
$mid = '***...***';
}
return substr($pass,0,$e) . $mid . substr($pass,-$e);
return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
}
/**

2
formulaires/inc-config-facteur-mailer-mailjet.html

@ -15,7 +15,7 @@
<label for="#GET{name}">[(#GET{fl}|concat{':label_',#GET{name}}|_T)]</label>[
<span class='erreur_message'>(#GET{erreurs})</span>
]<input type="text" name="#GET{name}" class="text" value="#ENV*{#GET{name},#GET{defaut}}" id="#GET{name}" [(#HTML5|et{#GET{obli}})required='required']
[placeholder="(#ENV*{_#GET{name}}|facteur_affiche_password_masque)"] />
[placeholder="(#ENV*{_#GET{name}}|facteur_affiche_password_masque{#AUTORISER{webmestre}}|attribut_html)"] />
</li>
#SET{name,mailjet_api_version}#SET{obli,''}#SET{defaut,'3'}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}

2
formulaires/inc-config-facteur-mailer-smtp.html

@ -33,7 +33,7 @@
<label for="smtp_password"><:facteur:facteur_smtp_password:></label>[
<span class='erreur_message'>(#ENV**{erreurs}|table_valeur{smtp_password})</span>]
<input type="password" name="smtp_password" class="text" value="#ENV**{smtp_password}" id="smtp_password"
[placeholder="(#ENV**{_smtp_password}|facteur_affiche_password_masque|attribut_html)"] />
[placeholder="(#ENV**{_smtp_password}|facteur_affiche_password_masque{#AUTORISER{webmestre}}|attribut_html)"] />
</div>
</div>
</div>

2
paquet.xml

@ -1,7 +1,7 @@
<paquet
prefix="facteur"
categorie="communication"
version="4.1.0"
version="4.1.1"
etat="test"
compatibilite="[3.1.0;3.3.*]"
logo="prive/themes/spip/images/facteur-32.png"

Loading…
Cancel
Save