diff --git a/ecrire/inc/filtres.php b/ecrire/inc/filtres.php index 57ac93188dd4314a5a184e9c3aa896a45400e357..404da4500ee5d6791707aa6302fc43b86cb6387c 100644 --- a/ecrire/inc/filtres.php +++ b/ecrire/inc/filtres.php @@ -5163,13 +5163,16 @@ function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = fals * @param array $options * string separateur : par défaut, un underscore `_`. * int longueur_maxi : par defaut 60 + * int longueur_mini : par defaut 0 * * @return string */ function identifiant_slug($texte, $type = '', $options = array()) { + $original = $texte; $separateur = (isset($options['separateur'])?$options['separateur']:'_'); $longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60); + $longueur_mini = (isset($options['longueur_mini'])?$options['longueur_mini']:0); if (!function_exists('translitteration')) { include_spip('inc/charsets'); @@ -5215,5 +5218,13 @@ function identifiant_slug($texte, $type = '', $options = array()) { $texte = substr($texte, 0, $longueur_maxi); } + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { + if (preg_match(',^\d,', $texte)) { + $texte = ($type ? substr($type,0,1) : "s") . $texte; + } + $texte .= $separateur . md5($original); + $texte = substr($texte, 0, $longueur_mini); + } + return $texte; }