Skip to content
Extraits de code Groupes Projets
Valider d1d8341f rédigé par cerdic's avatar cerdic Validation de marcimat
Parcourir les fichiers

Une option longueur_mini pour identifiant_slug qui permet de completer par le...

Une option longueur_mini pour identifiant_slug qui permet de completer par le md5 de l'original si on a besoin d'assurer un peu l'unicite sur les textes trop courts
parent e25f7e6b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -5163,13 +5163,16 @@ function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = fals ...@@ -5163,13 +5163,16 @@ function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = fals
* @param array $options * @param array $options
* string separateur : par défaut, un underscore `_`. * string separateur : par défaut, un underscore `_`.
* int longueur_maxi : par defaut 60 * int longueur_maxi : par defaut 60
* int longueur_mini : par defaut 0
* *
* @return string * @return string
*/ */
function identifiant_slug($texte, $type = '', $options = array()) { function identifiant_slug($texte, $type = '', $options = array()) {
$original = $texte;
$separateur = (isset($options['separateur'])?$options['separateur']:'_'); $separateur = (isset($options['separateur'])?$options['separateur']:'_');
$longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60); $longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60);
$longueur_mini = (isset($options['longueur_mini'])?$options['longueur_mini']:0);
if (!function_exists('translitteration')) { if (!function_exists('translitteration')) {
include_spip('inc/charsets'); include_spip('inc/charsets');
...@@ -5215,5 +5218,13 @@ function identifiant_slug($texte, $type = '', $options = array()) { ...@@ -5215,5 +5218,13 @@ function identifiant_slug($texte, $type = '', $options = array()) {
$texte = substr($texte, 0, $longueur_maxi); $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; return $texte;
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter