Avec l’introduction des fonctions avant_propre()
et apres_propre()
dans ecrire/inc_texte.php3
(depuis la version 1.7.1), on peut maintenant ajouter de nouveaux raccourcis sans plus avoir besoin de modifier le source de spip [1].
Soient les raccourcis suivants :
{1{ |
Ouverture d’un intertitre de 1er niveau (synonyme de {{{ ) [2] |
}1} |
Fermeture d’un intertitre de 1er niveau (synonyme de }}}) |
{2{ |
Ouverture d’un intertitre de 2e niveau |
}2} |
Fermeture d’un intertitre de 2e niveau |
{3{ |
Ouverture d’un intertitre de 3e niveau |
}3} |
Fermeture d’un intertitre de 3e niveau |
[*texte*] |
Texte en petites majuscules (small-caps) [3] |
[^texte^] |
Texte en exposant |
--> |
Flèche à droite (→) |
<-- |
Flèche à gauche (←) |
<--> |
Flèche bilatérale (↔) |
Nous mettons en oeuvre leur utilisation en trois étapes :
1°- Configurer les variables de personnalisation [4] en insérant les lignes suivantes dans le fichier mes_fonctions.php3
, à créer si nécessaire :
# On reprend les deux variables de personnalisation déjà existantes :
$GLOBALS['debut_intertitre'] = '<h3 class="monstyle">';
$GLOBALS['fin_intertitre'] = '</h3>';
# Et on y ajoute quatre nouvelles pour les intertitre :
$GLOBALS['debut_intertitre_2'] = '<h4 class="monstyle">';
$GLOBALS['fin_intertitre_2'] = '</h4>';
$GLOBALS['debut_intertitre_3'] = '<h5 class="monstyle">';
$GLOBALS['fin_intertitre_3'] = '</h5>';
On ajoute également les variables suivantes dans le fichier ecrire/mes_options.php3
, à créer si nécessaire :
# Variables de personnalisation pour les petites majucules:
$GLOBALS['debut_smallcaps'] = '<span style="font-variant: small-caps">';
$GLOBALS['fin_smallcaps'] = '</span>';
# Variables de personnalisation pour le texte en exposant
$GLOBALS['debut_exposant'] = '<sup class="spip">';
$GLOBALS['fin_exposant'] = '</sup>';
Vous pouvez bien sûr adapter ces variables, par exemple remplacer <span style="font-variant: small-caps">
par <span style="nom">
(en définissant la classe nom
dans votre feuille de style comme devant afficher les petites majucules).
2°- Ne pas oublier de configurer la feuille de style du site pour tenir compte de ces modifications (en fonction des variables de personnalisation que vous aurez choisies).
3°- Ajouter les fonctions suivantes dans le fichier ecrire/mes_options.php3
[5] :
function avant_typo($texte) {
$chercher_raccourcis = array(
/* 3 */ "/<-->/",
/* 4 */ "/-->/",
/* 5 */ "/<--/");
$remplacer_raccourcis = array(
/* 3 */ "↔",
/* 4 */ "→",
/* 5 */ "←");
return preg_replace($chercher_raccourcis, $remplacer_raccourcis, $texte);
}
function avant_propre($texte) {
$chercher_raccourcis = array(
# /* 1 */ "/\{0\{/",
# /* 2 */ "/\}0\}/",
/* 3 */ "/\{1\{/",
/* 4 */ "/\}1\}/",
/* 5 */ "/\{2\{/",
/* 6 */ "/\}2\}/",
/* 7 */ "/\{3\{/",
/* 8 */ "/\}3\}/",
/* 9 */ "/\[\*/",
/* 10 */ "/\*\]/",
/* 11 */ "/\[\^/",
/* 12 */ "/\^\]/");
$remplacer_raccourcis = array(
# /* 1 */ "<@@SPIP_debut_intertitre_0@@>",
# /* 2 */ "<@@SPIP_fin_intertitre_0@@>",
/* 3 */ "<@@SPIP_debut_intertitre@@>",
/* 4 */ "<@@SPIP_fin_intertitre@@>",
/* 5 */ "<@@SPIP_debut_intertitre_2@@>",
/* 6 */ "<@@SPIP_fin_intertitre_2@@>",
/* 7 */ "<@@SPIP_debut_intertitre_3@@>",
/* 8 */ "<@@SPIP_fin_intertitre_3@@>",
/* 9 */ "__SPIP_debut_smallcaps__",
/* 10 */ "__SPIP_fin_smallcaps__",
/* 11 */ "__SPIP_debut_exposant__",
/* 12 */ "__SPIP_fin_exposant__");
return preg_replace($chercher_raccourcis, $remplacer_raccourcis, $texte);
}
function apres_propre($texte) {
/*
# Intertitre -1 (intertitre de niveau supérieur à l'intertitre usuel de spip)
global $debut_intertitre_0, $fin_intertitre_0;
tester_variable('debut_intertitre_0', "\n<h2 class=\"spip\">");
tester_variable('fin_intertitre_0', "</h2>");
$texte = ereg_replace('(<p class="spip">)?[[:space:]]*<@@SPIP_debut_intertitre_0@@>', $debut_intertitre_0, $texte);
$texte = ereg_replace('<@@SPIP_fin_intertitre_0@@>[[:space:]]*(</p>)?', $fin_intertitre_0, $texte);
*/
# Intertitre de deuxième niveau
global $debut_intertitre_2, $fin_intertitre_2;
tester_variable('debut_intertitre_2', "\n<h4 class=\"spip\">");
tester_variable('fin_intertitre_2', "</h4>");
$texte = ereg_replace('(<p class="spip">)?[[:space:]]*<@@SPIP_debut_intertitre_2@@>', $debut_intertitre_2, $texte);
$texte = ereg_replace('<@@SPIP_fin_intertitre_2@@>[[:space:]]*(</p>)?', $fin_intertitre_2, $texte);
# Intertitre de troisième niveau
global $debut_intertitre_3, $fin_intertitre_3;
tester_variable('debut_intertitre_3', "\n<h5 class=\"spip\">");
tester_variable('fin_intertitre_3', "</h5>");
$texte = ereg_replace('(<p class="spip">)?[[:space:]]*<@@SPIP_debut_intertitre_3@@>', $debut_intertitre_3, $texte);
$texte = ereg_replace('<@@SPIP_fin_intertitre_3@@>[[:space:]]*(</p>)?', $fin_intertitre_3, $texte);
# Traitement des petites majuscules
global $fin_smallcaps, $debut_smallcaps;
tester_variable('debut_smallcaps', '<span style="font-variant: small-caps">');
tester_variable('fin_smallcaps', '</span>');
$texte = str_replace('__SPIP_debut_smallcaps__', $debut_smallcaps, $texte);
$texte = str_replace('__SPIP_fin_smallcaps__', $fin_smallcaps, $texte);
# Traitement des exposants
global $fin_exposant, $debut_exposant;
tester_variable('debut_exposant', '<sup class="spip">');
tester_variable('fin_exposant', '</sup>');
$texte = str_replace('__SPIP_debut_exposant__', $debut_exposant, $texte);
$texte = str_replace('__SPIP_fin_exposant__', $fin_exposant, $texte);
global $activer_antispam;
if($activer_antispam && function_exists('anti_spam'))
return anti_spam($texte);
else
return $texte;
}
#
# Fonctions anti-spam
#
function crypter ($texte) {
include_ecrire ("inc_acces.php3");
$masque = creer_pass_aleatoire(3);
$texte = ereg_replace("@", "_(".$masque.")_", $texte);
$s="";
for ($i=0;$i<strlen($texte);$i++)
$s .= "&#".ord($texte{$i}).";";
return $s;
}
# Autre possibilité: simplement utiliser la fonction antispam native de spip
# function crypter ($texte) {
# return antispam($texte);
#}
# Attention PHP 4.05 ou supérieur est nécessaire pour la fonction preg-replace-callback
# Voir http://be2.php.net/manual/fr/function.preg-replace-callback.php
function anti_spam ($texte) {
return preg_replace_callback('|(mailto:)?[-\w.]{2,}@[-\w.]{2,}|',
create_function('$match', 'return crypter($match[0]);'),
$texte);
}
4°- Filtre anti-spam générique. Dernière chose à faire : activer, si vous le souhaitez, le filtre anti-spam. Avec la fonction de cryptage proposé ici (que vous pouvez changer très simplement), dans tout lien vers une adresse mail présente dans votre site, l’arobase sera transformé en chaîne aléatoire et le mail sera chiffré. Pour activer cette fonction, il vous suffit d’ajouter la ligne suivante dans votre fichier ecrire/mes_options.php3
:
$activer_antispam = true;
Et voilà, en principe, tout doit fonctionner. Tout ce que vous devez placer dans votre fichier ecrire/mes_options.php3
se trouve dans ce fichier :
Si des gens accrochent à cette contrib et qu’ils ont envie de poursuivre, ce serait bien de modifier la barre d’outils pour qu’elle intègre ces nouveaux raccourcis.
Aucune discussion
Ajouter un commentaire
Avant de faire part d’un problème sur un plugin X, merci de lire ce qui suit :
Merci d’avance pour les personnes qui vous aideront !
Par ailleurs, n’oubliez pas que les contributeurs et contributrices ont une vie en dehors de SPIP.
Suivre les commentaires : |