/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
- * Copyright (c) 2001-2012 *
+ * Copyright (c) 2001-2014 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
OR strpbrk($texte, "&\"'<>")==false
) return $texte;
include_spip('inc/texte');
- $texte = htmlspecialchars(echappe_retour(echappe_html($texte,'',true),'','proteger_amp'),$quote?ENT_QUOTES:(ENT_COMPAT|ENT_HTML401));
+ $flags = !defined('PHP_VERSION_ID') OR PHP_VERSION_ID < 50400 ? ENT_COMPAT : ENT_COMPAT|ENT_HTML401;
+ $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $quote?ENT_QUOTES:$flags);
if ($tout)
return corriger_toutes_entites_html($texte);
else
"<a \\1 target=\"_blank\">", $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,"<a")===false)
+ return $texte;
+
+ if (preg_match_all(",<a\b[^>]*>,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){
function vider_url($url, $entites = true) {
# un message pour abs_url
$GLOBALS['mode_abs_url'] = 'url';
-
$url = trim($url);
- if (preg_match(",^(http:?/?/?|mailto:?)$,iS", $url))
- return '';
-
- if ($entites) $url = entites_html($url);
-
- return $url;
+ $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
+ return preg_match($r, $url) ? '': ($entites ? entites_html($url) : $url);
}
// Extraire une date de n'importe quel champ (a completer...)
switch ($vue) {
case 'saison':
+ case 'saison_annee':
$saison = '';
if ($mois > 0){
$saison = 1;
if (($mois == 9 AND $jour >= 21) OR $mois > 9) $saison = 4;
if (($mois == 12 AND $jour >= 21) OR $mois > 12) $saison = 1;
}
- return $saison?_T('date_saison_'.$saison):'';
+ if($vue == 'saison')
+ return $saison?_T('date_saison_'.$saison):'';
+ else
+ return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :'';
case 'court':
if ($avjc) return $annee;
return affdate_base($numdate, 'saison');
}
+// http://doc.spip.org/@saison_annee
+function saison_annee($numdate) {
+ return affdate_base($numdate, 'saison_annee');
+}
+
// http://doc.spip.org/@affdate
function affdate($numdate, $format='entier') {
return affdate_base($numdate, $format);
return $trads;
}
+// Calculer l'initiale d'un nom
+function initiale($nom){
+ return spip_substr(trim(strtoupper(extraire_multi($nom))),0,1);
+}
+
//
// Ce filtre retourne la donnee si c'est la premiere fois qu'il la voit ;
// possibilite de gerer differentes "familles" de donnees |unique{famille}
/**
* 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);
}
//
}
+/**
+ * Vérifie qu'un nom (d'auteur) ne comporte pas d'autres tags que <multi>
+ * et ceux volontairement spécifiés dans la constante
+ *
+ * @param string $nom
+ * Nom (signature) proposé
+ * @return bool
+ * - false si pas conforme,
+ * - true sinon
+**/
+function nom_acceptable($nom) {
+ if (!is_string($nom)) {
+ return false;
+ }
+ if (!defined('_TAGS_NOM_AUTEUR')) define('_TAGS_NOM_AUTEUR','');
+ $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
+ foreach($tags_acceptes as $tag) {
+ if (strlen($tag)) {
+ $remp1[] = '<'.trim($tag).'>';
+ $remp1[] = '</'.trim($tag).'>';
+ $remp2[] = '\x60'.trim($tag).'\x61';
+ $remp2[] = '\x60/'.trim($tag).'\x61';
+ }
+ }
+ $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
+ return str_replace('<', '<', $v_nom) == $nom;
+}
+
// Verifier la conformite d'une ou plusieurs adresses email
// retourne false ou la normalisation de la derniere adresse donnee
// http://doc.spip.org/@email_valide
}
$fichier = basename($url);
return '<a rel="enclosure"'
- . ($url? ' href="'.htmlspecialchars($url).'"' : '')
- . ($type? ' type="'.htmlspecialchars($type).'"' : '')
- . ($length? ' title="'.htmlspecialchars($length).'"' : '')
+ . ($url? ' href="'.spip_htmlspecialchars($url).'"' : '')
+ . ($type? ' type="'.spip_htmlspecialchars($type).'"' : '')
+ . ($length? ' title="'.spip_htmlspecialchars($length).'"' : '')
. '>'.$fichier.'</a>';
}
// La fonction inverse
$length = intval(extraire_attribut($e, 'length')); # vieux data
$fichier = basename($url);
$enclosures[] = '<enclosure'
- . ($url? ' url="'.htmlspecialchars($url).'"' : '')
- . ($type? ' type="'.htmlspecialchars($type).'"' : '')
+ . ($url? ' url="'.spip_htmlspecialchars($url).'"' : '')
+ . ($type? ' type="'.spip_htmlspecialchars($type).'"' : '')
. ($length? ' length="'.$length.'"' : '')
. ' />';
}
}
-// 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{<hr />})] 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 <br /> 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="<br />", $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;
}
* @return string
*/
function timestamp($fichier){
- if (!$fichier) return $fichier;
+ if (!$fichier OR !file_exists($fichier)) return $fichier;
$m = filemtime($fichier);
return "$fichier?$m";
}