From 696dace43c059c1461085197e6cd48bd3082c3a4 Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Thu, 30 Dec 2004 21:48:03 +0000 Subject: [PATCH] partage de code --- ecrire/inc_calendrier.php | 83 +++++++++++++++------------------------ ecrire/inc_filtres.php3 | 15 +++++++ ecrire/inc_session.php3 | 7 ++-- inc-login_public.php3 | 2 +- inc-messforum.php3 | 62 ++++++++++++++--------------- 5 files changed, 83 insertions(+), 86 deletions(-) diff --git a/ecrire/inc_calendrier.php b/ecrire/inc_calendrier.php index 31a2b43ffb..1f4642a6a8 100644 --- a/ecrire/inc_calendrier.php +++ b/ecrire/inc_calendrier.php @@ -121,7 +121,7 @@ function http_calendrier_ics($evenements, $amj = "") $res .= "\n<div style='$c'>" . $date_affichee . - (!$url ? "$sum $desc" : http_calendrier_href($url, $sum, $desc)) . + (!$url ? "$sum $desc" : http_href($url, $sum, $desc)) . "\n</div>\n"; } } @@ -243,14 +243,14 @@ function http_calendrier_navigation($jour, $mois, $annee, $echelle, $nom, $retour = "<div class='navigation-calendrier'>"; - $retour .= http_calendrier_href($script . "type=$type&echelle=$echelle&$args_pred$ancre", + $retour .= http_href($script . "type=$type&echelle=$echelle&$args_pred$ancre", "<img\nsrc='" . _DIR_IMG_PACK . "/fleche-$spip_lang_left.png' class='format_png' alt='<<<' width='12' height='12' />", 'précédent'); $retour .= " "; $retour .= "<b>$nom</b>"; $retour .= " "; - $retour .= http_calendrier_href(($script . "type=$type&echelle=$echelle&$args_suiv$ancre"), + $retour .= http_href(($script . "type=$type&echelle=$echelle&$args_suiv$ancre"), "<img\nsrc='" . _DIR_IMG_PACK . "/fleche-$spip_lang_right.png' class='format_png' alt='>>>' width='12' height='12' />", 'suivant'); @@ -258,15 +258,15 @@ function http_calendrier_navigation($jour, $mois, $annee, $echelle, $nom, $img_att = ($type == 'jour') ? " class='navigation-bouton-desactive'" : ''; - $retour .= http_calendrier_href(($script . "type=jour&echelle=$echelle&$args"), + $retour .= http_href(($script . "type=jour&echelle=$echelle&$args"), ("<img\nsrc='" . _DIR_IMG_PACK . "/cal-jour.gif' alt='jour' $img_att />"), 'calendrier par jour'); ($type == 'semaine') ? $img_att = " class='navigation-bouton-desactive'" : $img_att = "" ; - $retour .= http_calendrier_href($script . "type=semaine&echelle=$echelle&$args", + $retour .= http_href($script . "type=semaine&echelle=$echelle&$args", ("<img\nsrc='" . _DIR_IMG_PACK . "/cal-semaine.gif' alt='semaine' $img_att />"), 'calendrier par semaine'); ($type == 'mois') ? $img_att = " class='navigation-bouton-desactive'" : $img_att = "" ; - $retour .= http_calendrier_href($script . "type=mois&echelle=$echelle&$args", + $retour .= http_href($script . "type=mois&echelle=$echelle&$args", ("<img\nsrc='" . _DIR_IMG_PACK . "/cal-mois.gif' alt='mois' $img_att />"), 'calendrier par mois'); @@ -285,17 +285,17 @@ function http_calendrier_navigation($jour, $mois, $annee, $echelle, $nom, $condition ? $img_att = " class='navigation-bouton-desactive'" : $img_att = "" ; $retour .= "<span onMouseOver=\"montrer('nav_agenda');\">"; - $retour .= http_calendrier_href($script . "type=$type&echelle=$echelle&$arguments", + $retour .= http_href($script . "type=$type&echelle=$echelle&$arguments", ("<img\nsrc='" . _DIR_IMG_PACK . "/cal-today.gif' alt=\"aujourd\'hui\" $img_att />"), 'aujourd\'hui'); $retour .= "</span>"; if ($type != "mois") { $retour .= " "; - $retour .= http_calendrier_href($script . "type=$type&set_echelle=" . + $retour .= http_href($script . "type=$type&set_echelle=" . floor($echelle * 1.5) . "&$args", "<img\nsrc='" . _DIR_IMG_PACK . "/loupe-moins.gif' alt='zoom-' />"); - $retour .= http_calendrier_href(($script . "type=$type&set_echelle=" . + $retour .= http_href(($script . "type=$type&set_echelle=" . floor($echelle / 1.5) . "&$args"), "<img\nsrc='" . _DIR_IMG_PACK . "/loupe-plus.gif' alt='zoom+' />"); @@ -305,21 +305,21 @@ function http_calendrier_navigation($jour, $mois, $annee, $echelle, $nom, if ($GLOBALS['partie_cal'] == "tout") $img_att = " class='navigation-bouton-desactive'"; else $img_att = ""; - $retour .= "<span$img_att>".http_calendrier_href(($script . "type=$type". + $retour .= "<span$img_att>".http_href(($script . "type=$type". "&set_partie_cal=tout" . "&$args"), "<img\nsrc='" . _DIR_IMG_PACK . "/heures-tout.png' width='13' height='13' alt='tout' class='format_png' />") . "</span>"; if ($GLOBALS['partie_cal'] == "matin") $img_att = " class='navigation-bouton-desactive'"; else $img_att = ""; - $retour .= "<span$img_att>".http_calendrier_href(($script . "type=$type". + $retour .= "<span$img_att>".http_href(($script . "type=$type". "&set_partie_cal=matin" . "&$args"), "<img\nsrc='" . _DIR_IMG_PACK . "/heures-am.png' width='13' height='13' alt='AM' class='format_png' />") . "</span>"; if ($GLOBALS['partie_cal'] == "soir") $img_att = " class='navigation-bouton-desactive'"; else $img_att = ""; - $retour .= "<span$img_att>".http_calendrier_href(($script . "type=$type". + $retour .= "<span$img_att>".http_href(($script . "type=$type". "&set_partie_cal=soir" . "&$args"), "<img\nsrc='" . _DIR_IMG_PACK . "/heures-pm.png' width='13' height='13' alt='PM' class='format_png' />") . "</span>"; @@ -343,11 +343,11 @@ function http_calendrier_navigation($jour, $mois, $annee, $echelle, $nom, $gadget .= "<table cellpadding='0' cellspacing='5' border='0' width='100%'>"; $gadget .= "<tr><td colspan='3' style='text-align:$spip_lang_left;'>"; for ($i=$mois; $i < 13; $i++) { - $gadget .= http_calendrier_href("calendrier.php3?mois=$i&annee=$annee_avant", + $gadget .= http_href("calendrier.php3?mois=$i&annee=$annee_avant", nom_mois("$annee_avant-$i-1"),'','', 'calendrier-annee') ; } for ($i=1; $i < $mois - 1; $i++) { - $gadget .= http_calendrier_href("calendrier.php3?mois=$i&annee=$annee", + $gadget .= http_href("calendrier.php3?mois=$i&annee=$annee", nom_mois("$annee-$i-1"),'','', 'calendrier-annee'); } $gadget .= "</td>"; @@ -363,11 +363,11 @@ function http_calendrier_navigation($jour, $mois, $annee, $echelle, $nom, $gadget .= "</tr>"; $gadget .= "<tr><td colspan='3' style='text-align:$spip_lang_right;'>"; for ($i=$mois+2; $i <= 12; $i++) { - $gadget .= http_calendrier_href("calendrier.php3?mois=$i&annee=$annee", + $gadget .= http_href("calendrier.php3?mois=$i&annee=$annee", nom_mois("$annee-$i-1"),'','', 'calendrier-annee'); } for ($i=1; $i < $mois+1; $i++) { - $gadget .= http_calendrier_href("calendrier.php3?mois=$i&annee=$annee_apres", + $gadget .= http_href("calendrier.php3?mois=$i&annee=$annee_apres", nom_mois("$annee_apres-$i-1"),'','', 'calendrier-annee'); } $gadget .= "</td></tr>"; @@ -585,9 +585,9 @@ function http_calendrier_clics_jour_semaine($annee, $mois, $jour, $clic) $semaine = $m[1] . "S" . date("W", $d) . $m[2]; return "<table width='100%'>\n<tr><td align='left'>". - http_calendrier_href("$commun&type=jour#$ancre", $clic) . + http_href("$commun&type=jour#$ancre", $clic) . "</td><td align='right'>" . - http_calendrier_href("$commun&type=semaine#$ancre",$semaine) . + http_href("$commun&type=semaine#$ancre",$semaine) . "</td></tr>\n</table>"; } @@ -597,20 +597,20 @@ function http_calendrier_clics($annee, $mois, $jour, $clic) $href = "message_edit.php3?rv=$annee-$mois-$jour&new=oui"; return "\n" . - http_calendrier_href("calendrier_jour.php3?jour=$jour&mois=$mois&annee=$annee", $clic) . + http_href("calendrier_jour.php3?jour=$jour&mois=$mois&annee=$annee", $clic) . "\n" . - http_calendrier_href("$href&type=pb", + http_href("$href&type=pb", $bleu, _T("lien_nouvea_pense_bete"), 'color: blue; font-family: Arial, Sans, sans-serif; font-size: 10px; ') . "\n" . - http_calendrier_href("$href&type=normal", + http_href("$href&type=normal", $vert, _T("lien_nouveau_message"), 'color: green; font-family: Arial, Sans, sans-serif; font-size: 10px; ') . (($GLOBALS['connect_statut'] != "0minirezo") ? "" : ("\n" . - http_calendrier_href("$href&type=affich", + http_href("$href&type=affich", $jaune, _T("lien_nouvelle_annonce"), 'color: #ff9900; font-family: Arial, Sans, sans-serif; font-size: 10px; '))); @@ -655,7 +655,7 @@ function http_calendrier_suite_heures($jour_today,$mois_today,$annee_today, 'index' => date("w", $nom)); $intitul[$j] = $v; $liens[$j] = - http_calendrier_href(($script . + http_href(($script . (strpos($script,'?') ? '&' : '?') . "type=jour&jour=" . $v['jour'] . @@ -722,7 +722,7 @@ function http_calendrier_suite_heures($jour_today,$mois_today,$annee_today, function http_calendrier_agenda ($mois, $annee, $jour_ved, $mois_ved, $annee_ved, $semaine = false) { return "<div style='text-align: center; padding: 5px;'>" . - http_calendrier_href("calendrier.php3?mois=$mois&annee=$annee", + http_href("calendrier.php3?mois=$mois&annee=$annee", "<b class='verdana1'>" . affdate_mois_annee("$annee-$mois-1"). "</b>", @@ -742,7 +742,7 @@ function http_calendrier_agenda_href($type, $jour, $mois, $annee, $color) static $scripts = array('jour' => "calendrier_jour.php3?", 'semaine' => "calendrier_semaine.php3?"); - return http_calendrier_href($scripts[$type] . "jour=$jour&mois=$mois&annee=$annee", + return http_href($scripts[$type] . "jour=$jour&mois=$mois&annee=$annee", "<b>$jour</b>", '', "color: $color"); @@ -1067,7 +1067,7 @@ function http_calendrier_jour_ics($debut, $fin, $largeur, $detcolor, $echelle, $ onmouseout=\"this.style.zIndex=" . $i . "\">" . ((!$url) ? $sum : - http_calendrier_href($url, $sum, $desc,"color: $fcolor")) . + http_href($url, $sum, $desc,"color: $fcolor")) . ((!$evenement['LOCATION']) ? '' : ("<br />" . $evenement['LOCATION'])) . "</div>"; @@ -1204,7 +1204,7 @@ function http_calendrier_jour($jour,$mois,$annee,$large = "large", $le_message = if ($large == "col" ) { $entete = "<div align='center' style='padding: 5px;'><b class='verdana1'>" . - http_calendrier_href("calendrier_jour.php3?jour=$jour&mois=$mois&annee=$annee", + http_href("calendrier_jour.php3?jour=$jour&mois=$mois&annee=$annee", affdate_jourcourt("$annee-$mois-$jour"), '', 'color:black;') . @@ -1213,18 +1213,18 @@ function http_calendrier_jour($jour,$mois,$annee,$large = "large", $le_message = else { if ($large == "large") $entete = "<div align='center' style='padding: 5px;'>" . - http_calendrier_href("message_edit.php3?rv=$annee-$mois-$jour&new=oui&type=pb", + http_href("message_edit.php3?rv=$annee-$mois-$jour&new=oui&type=pb", $bleu ._T("lien_nouvea_pense_bete"), '', 'font-family: Arial, Sans, sans-serif; font-size: 10px; color: blue;') . " " . - http_calendrier_href("message_edit.php3?rv=$annee-$mois-$jour&new=oui&type=normal", + http_href("message_edit.php3?rv=$annee-$mois-$jour&new=oui&type=normal", $vert ._T("lien_nouveau_message"), '', 'font-family: Arial, Sans, sans-serif; font-size: 10px; color: green;') . (!($GLOBALS['connect_statut'] == "0minirezo") ? '' : (" " . - http_calendrier_href("message_edit.php3?rv=$annee-$mois-$jour&new=oui&type=affich", + http_href("message_edit.php3?rv=$annee-$mois-$jour&new=oui&type=affich", $jaune ._T("lien_nouvelle_annonce"), '', 'font-family: Arial, Sans, sans-serif; font-size: 10px; color: #ff9900;'))) . @@ -1330,7 +1330,7 @@ function http_calendrier_rv($messages, $type) { } $total .= "<tr><td width='24' valign='middle'>" . - http_calendrier_href($url, + http_href($url, ($rv ? http_img_pack("rv.gif", http_style_background($bouton . '.gif', "no-repeat;' border='0' alt=''")) : @@ -1350,7 +1350,7 @@ function http_calendrier_rv($messages, $type) { "$spip_lang_right center no-repeat; float: $spip_lang_left; line-height: 12px; color: #666666; margin-$spip_lang_right: 3px; padding-$spip_lang_right: 4px; text-align: center;") . heures($date).":".minutes($date)."<br />...</div>" ))) . "<div><b>" . - http_calendrier_href($url, typo($row['titre']), '', + http_href($url, typo($row['titre']), '', 'font-family: Verdana, Arial, Sans, sans-serif; font-size: 10px;') . "</b></div>" . "</td>" . @@ -1386,25 +1386,6 @@ function http_calendrier_rv($messages, $type) { fin_cadre_enfonce(true); } -// Fabrique une balise A, avec un href conforme au validateur W3C -// et une classe uniquement destinee a retirer l'URL lors d'une impression -// attention au cas ou la href est du Javascript avec des "'" - -function http_calendrier_href($href, $clic, $title='', $style='', $class='') { - return '<a href="' . - str_replace('&', '&', $href) . - '"' . # class="forum-repondre-message"' . - (!$style ? '' : (" style=\"" . $style . "\"")) . - (!$title ? '' : (" title=\"" . supprimer_tags($title)."\"")) . - (!$class ? '' : (" class=\"" . $class . "\"")) . - '>' . - $clic . - '</a>'; -} - -function http_calendrier_title($echelle, $href, $clic, $title='', $style='', $class='') { - if ($echelle); -} function sql_calendrier_interval_jour($annee,$mois,$jour) { diff --git a/ecrire/inc_filtres.php3 b/ecrire/inc_filtres.php3 index 840c04b8cf..ed6c52aa04 100644 --- a/ecrire/inc_filtres.php3 +++ b/ecrire/inc_filtres.php3 @@ -100,6 +100,21 @@ function liens_ouvrants ($texte) { "<a \\1 target=\"_blank\">", $texte); } +// Fabrique une balise A, avec un href conforme au validateur W3C +// attention au cas ou la href est du Javascript avec des "'" + +function http_href($href, $clic, $title='', $style='', $class='') { + return '<a href="' . + str_replace('&', '&', $href) . + '"' . + (!$style ? '' : (" style=\"" . $style . "\"")) . + (!$title ? '' : (" title=\"" . supprimer_tags($title)."\"")) . + (!$class ? '' : (" class=\"" . $class . "\"")) . + '>' . + $clic . + '</a>'; +} + // Corrige les caracteres degoutants utilises par les Windozeries function corriger_caracteres($texte) { static $trans; diff --git a/ecrire/inc_session.php3 b/ecrire/inc_session.php3 index d25fa985e9..8c906ed5e1 100644 --- a/ecrire/inc_session.php3 +++ b/ecrire/inc_session.php3 @@ -202,11 +202,12 @@ function verifier_php_auth() { // // entete php_auth // -function ask_php_auth($text_failure, $raison, $retour, $url, $re, $lien) { +function ask_php_auth($pb, $raison, $retour, $url='', $re='', $lien='') { @Header("WWW-Authenticate: Basic realm=\"espace prive\""); @Header("HTTP/1.0 401 Unauthorized"); - echo "<b>$text_failure</b><p>$raison</p>[<a href='./'>$retour</a>] ", - "[<a href='spip_cookie.php3?essai_auth_http=oui&$url'>$re</a>]", + echo "<b>$pb</b><p>$raison</p>[<a href='./'>$retour</a>] ", + (!$url ? '' : + "[<a href='spip_cookie.php3?essai_auth_http=oui&$url'>$re</a>]"), (!$lien ? '' : " [<a href='" . _DIR_RESTREINT_ABS . "'>"._T('login_espace_prive')."</a>]"); exit; } diff --git a/inc-login_public.php3 b/inc-login_public.php3 index bdf83af757..9e599ae064 100644 --- a/inc-login_public.php3 +++ b/inc-login_public.php3 @@ -47,7 +47,7 @@ function login_explicite($login, $cible, $mode) { ($auteur_session['statut']=='0minirezo' OR $auteur_session['statut']=='1comite')) { if (($cible != $action) && !headers_sent()) redirige_par_entete($cible); - return "<a href='$cible'>"._T('login_par_ici')."</a>\n"; + return http_href($cible, _T('login_par_ici')); } return login_pour_tous($login ? $login : $GLOBALS['var_login'], $cible, '', $action, $mode); } diff --git a/inc-messforum.php3 b/inc-messforum.php3 index a18f53233e..9d7298ee99 100644 --- a/inc-messforum.php3 +++ b/inc-messforum.php3 @@ -20,32 +20,30 @@ function prevenir_auteurs($auteur, $email_auteur, $id_article, $texte, $titre) $adresse_site = lire_meta("adresse_site"); $nom_site_spip = lire_meta("nom_site"); $url = "$adresse_site/$url"; - $courr = _T('form_forum_message_auto')."\n\n"; - $parauteur = ''; - if (strlen($auteur) > 2) { - $parauteur = " "._T('forum_par_auteur', - array('auteur' => $auteur)); - if ($email_auteur) - $parauteur .= " <$email_auteur>"; - } - $courr .= _T('forum_poste_par', - array('parauteur' => $parauteur))."\n"; - $courr .= _T('forum_ne_repondez_pas')."\n"; - $courr .= "$url\n"; - $courr .= "\n\n".$titre."\n\n".textebrut(propre($texte)). - "\n\n$nom_site_forum\n$url_site\n"; + $parauteur = (strlen($auteur) <= 2) ? '' : + (" " + ._T('forum_par_auteur', + array('auteur' => $auteur)) . + (!$email_auteur ? '' : (' <' . $email_auteur . '>'))); + $courr = _T('form_forum_message_auto')."\n\n" + . _T('forum_poste_par', + array('parauteur' => $parauteur))."\n" + . _T('forum_ne_repondez_pas')."\n" + . $url + . "\n\n\n".$titre."\n\n".textebrut(propre($texte)) + . "\n\n$nom_site_forum\n$url_site\n"; $sujet = "[$nom_site_spip] ["._T('forum_forum')."] $titre"; - $result = spip_query("SELECT auteurs.* FROM spip_auteurs AS auteurs, + $result = spip_query("SELECT auteurs.email FROM spip_auteurs AS auteurs, spip_auteurs_articles AS lien WHERE lien.id_article='$id_article' AND auteurs.id_auteur=lien.id_auteur"); - while ($row = spip_fetch_array($result)) { - $email_auteur = trim($row["email"]); - if (strlen($email_auteur) < 3) continue; - envoyer_mail($email_auteur, $sujet, $courr); + while (list($email) = spip_fetch_array($result)) { + $email = trim($email); + if (strlen($email) < 3) continue; + envoyer_mail($email, $sujet, $courr); } -} +} $retour_forum = rawurldecode($retour); $forum_id_article = intval($id_article); @@ -59,9 +57,8 @@ $slash_nom_site_forum = addslashes($nom_site_forum); $slash_url_site = addslashes($url_site); $id_message = intval($id_message); -// Nature du forum if (!$id_auteur) - $id_auteur = intval($GLOBALS['auteur_session']['id_auteur']); + $id_auteur = intval($auteur_session['id_auteur']); if ($forum_id_article) { $r = spip_query("SELECT accepter_forum FROM spip_articles WHERE id_article=$forum_id_article"); @@ -78,15 +75,17 @@ if ($forums_publics == "abo") { if ($auteur_session) { $statut = $auteur_session['statut']; if (!$statut OR $statut == '5poubelle') { - die ("<h4>"._T('forum_acces_refuse'). "</h4>" . - _T('forum_cliquer_retour', array('retour_forum' => $retour_forum)). - "<p>"); + ask_php_auth(_T('forum_acces_refuse'), + _T('forum_cliquer_retour', + array('retour_forum' => $retour_forum))); + exit; } } else { - die ("<h4>"._T('forum_non_inscrit'). "</h4>" . - _T('forum_cliquer_retour', array('retour_forum' => $retour_forum)). - "<p>"); + ask_php_auth(_T('forum_non_inscrit'), + _T('forum_cliquer_retour', + array('retour_forum' => $retour_forum))); + exit; } // Ne pas autoriser de changement de nom si forum sur abonnement @@ -98,9 +97,10 @@ $slash_auteur = addslashes($auteur); $slash_email_auteur = addslashes($email_auteur); if ((strlen($slash_texte) + strlen($slash_titre) + strlen($slash_nom_site_forum) + strlen($slash_url_site) + strlen($slash_auteur) + strlen($slash_email_auteur)) > 20 * 1024) { - die ("<h4>"._T('forum_message_trop_long')."</h4>\n" . - _T('forum_cliquer_retour', array('retour_forum' => $retour_forum)). - "<p>"); + ask_php_auth(_T('forum_message_trop_long'), + _T('forum_cliquer_retour', + array('retour_forum' => $retour_forum))); + exit; } spip_query("DELETE FROM spip_mots_forum WHERE id_forum='$id_message'"); -- GitLab