X-Git-Url: http://git.cyclocoop.org/?p=lhc%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Finc%2Ffiltres.php;h=3a5b7eb4aab2133c74eda12d4ac54d1ce6ca2c8c;hp=f1c2fc520bf00db414372202043dbfc6ce95b892;hb=f08ec3a19775a7a173534b2d5cb7e9920b6253a6;hpb=58a2baa86ad2e12b4ff338d137f826a0a10ccbd7
diff --git a/www/ecrire/inc/filtres.php b/www/ecrire/inc/filtres.php
index f1c2fc52..3a5b7eb4 100644
--- a/www/ecrire/inc/filtres.php
+++ b/www/ecrire/inc/filtres.php
@@ -512,6 +512,29 @@ function liens_ouvrants ($texte) {
"", $texte);
}
+/**
+ * Ajouter un attribut rel="nofollow" sur tous les liens d'un texte
+ * @param string $texte
+ * @return string
+ */
+function liens_nofollow($texte) {
+ if (stripos($texte,"]*>,UimsS",$texte, $regs, PREG_PATTERN_ORDER)){
+ foreach($regs[0] as $a){
+ $rel = extraire_attribut($a,"rel");
+ if (strpos($rel,"nofollow")===false){
+ $rel = "nofollow" . ($rel?" $rel":"");
+ $anofollow = inserer_attribut($a,"rel",$rel);
+ $texte = str_replace($a,$anofollow,$texte);
+ }
+ }
+ }
+
+ return $texte;
+}
+
// Transformer les sauts de paragraphe en simples passages a la ligne
// http://doc.spip.org/@PtoBR
function PtoBR($texte){
@@ -1573,15 +1596,13 @@ function vider_attribut ($balise, $attribut) {
/**
* Un filtre pour determiner le nom du satut des inscrits
*
- * @deprecated a virer en 3.1
- *
* @param void|int $id
* @param string $mode
* @return string
*/
function tester_config($id, $mode='') {
- include_spip('inc/autoriser');
- return autoriser('inscrireauteur', $mode, $id) ? $mode : '';
+ include_spip('action/inscrire_auteur');
+ return tester_statut_inscription($mode, $id);
}
//
@@ -2904,20 +2925,54 @@ function wrap($texte,$wrap) {
}
-// afficher proprement n'importe quoi
-// en cas de table profonde, l'option $join ne s'applique qu'au plus haut niveau
-// c'est VOULU ! Exemple : [(#VALEUR|print{
})] va afficher de gros blocs
-// separes par des lignes, avec a l'interieur des trucs separes par des virgules
-function filtre_print_dist($u, $join=', ') {
- if (is_string($u))
- return typo($u);
-
- if (is_array($u))
- return join($join, array_map('filtre_print_dist', $u));
+/**
+ * afficher proprement n'importe quoi
+ * On affiche in fine un pseudo-yaml qui premet de lire humainement les tableaux et de s'y reperer
+ *
+ * Les textes sont retournes avec simplement mise en forme typo
+ *
+ * le $join sert a separer les items d'un tableau, c'est en general un \n ou
selon si on fait du html ou du texte
+ * les tableaux-listes (qui n'ont que des cles numeriques), sont affiches sous forme de liste separee par des virgules :
+ * c'est VOULU !
+ *
+ * @param $u
+ * @param string $join
+ * @param int $indent
+ * @return array|mixed|string
+ */
+function filtre_print_dist($u, $join="
", $indent=0) {
+ if (is_string($u)){
+ $u = typo($u);
+ return $u;
+ }
+ // caster $u en array si besoin
if (is_object($u))
- return join($join, array_map('filtre_print_dist', (array) $u));
+ $u = (array) $u;
+
+ if (is_array($u)){
+ $out = "";
+ // toutes les cles sont numeriques ?
+ // et aucun enfant n'est un tableau
+ // liste simple separee par des virgules
+ $numeric_keys = array_map('is_numeric',array_keys($u));
+ $array_values = array_map('is_array',$u);
+ $object_values = array_map('is_object',$u);
+ if (array_sum($numeric_keys)==count($numeric_keys)
+ AND !array_sum($array_values)
+ AND !array_sum($object_values)){
+ return join(", ", array_map('filtre_print_dist', $u));
+ }
+
+ // sinon on passe a la ligne et on indente
+ $i_str = str_pad("",$indent,"Â ");
+ foreach($u as $k => $v){
+ $out .= $join . $i_str . "$k: " . filtre_print_dist($v,$join,$indent+2);
+ }
+ return $out;
+ }
+ // on sait pas quoi faire...
return $u;
}
@@ -3061,7 +3116,7 @@ function produire_fond_statique($fond, $contexte=array(), $options = array(), $c
* @return string
*/
function timestamp($fichier){
- if (!$fichier) return $fichier;
+ if (!$fichier OR !file_exists($fichier)) return $fichier;
$m = filemtime($fichier);
return "$fichier?$m";
}