From c0344b0ae293dd796b7ef02a78b682c2dade762e Mon Sep 17 00:00:00 2001
From: Antoine Pitrou <pitrou@free.fr>
Date: Sat, 16 Feb 2002 01:49:50 +0000
Subject: [PATCH] Antoine :
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Bcp de petites modifs, notamment :

- fin des conversions <? -> <?php
- correction problème email contenant un '.' pour l'inscription auto
- correction problème addslashes dans génération inc_meta_cache
(guillemets encadrants au lieu d'apostrophes)
...
---
 article-dist.html            | 19 +++++----------
 ecrire/inc.php3              |  3 ++-
 ecrire/inc_acces.php3        | 27 ++++++++++++++-------
 ecrire/inc_mail.php3         |  2 +-
 ecrire/inc_meta.php3         |  2 +-
 ecrire/inc_presentation.php3 | 46 ++++++++++++++++++------------------
 ecrire/index.php             |  2 +-
 ecrire/install.php3          |  7 +++---
 inc-calcul-squel.php3        | 12 +++++-----
 inc-formulaires.php3         | 35 +++++++++++----------------
 inc-forum.php3               |  5 ++--
 inc-public.php3              | 15 +++++-------
 inc-stats.php3               |  2 +-
 index.php                    |  2 +-
 14 files changed, 87 insertions(+), 92 deletions(-)

diff --git a/article-dist.html b/article-dist.html
index 55915f9d66..13ae663141 100644
--- a/article-dist.html
+++ b/article-dist.html
@@ -228,7 +228,7 @@
 <B_documents>
 <ul>
 <p align="left">
-<BOUCLE_documents(DOCUMENTS){id_article}{par titre}{inclus=non}>
+<BOUCLE_documents(DOCUMENTS){id_article}{par titre}{mode=document}{id_vignette=0}>
 <li><font size=1>[(#LOGO_DOCUMENT|#URL_DOCUMENT)]<a href="IMG/#FICHIER_DOCUMENT">DOCUMENT [(#TYPE|majuscules)]</a></font> <b>#TITRE,</b> [(#TAILLE_DOCUMENT|taille_en_octets)]
 [<br>(#DESCRIPTIF)]
 </BOUCLE_documents>
@@ -236,8 +236,8 @@
 </B_documents>
 
 
-	</FONT>
-	<BR><BR>
+</FONT>
+<BR><BR>
 
 </TD>
 </TR>
@@ -325,11 +325,6 @@
 	<P>#TEXTE
 	
 	
-	<BOUCLE_mots_forum(MOTS){id_forum}{par type, titre}>
-		<li><b>#TYPE :</b> #TITRE
-	</BOUCLE_mots_forum>
-	
-	
 	<P align='right'>[<font size=1><A HREF="forum.php3?#PARAMETRES_FORUM">R&eacute;pondre &agrave; ce message</A></font>]</div>
 	</font>
 	</TD></TR></TABLE>
@@ -370,23 +365,21 @@
 	<P>
 
 	</BOUCLE_Forums>
+
 </TD>
 </TR>
 </TABLE>
 <P>
-</B_forums_liens>
+<!--/B_forums_liens-->
 
 
 </CENTER>
 
 
+</BOUCLE_principale>
 
 
 
-
-
-</BOUCLE_principale>
-
 <CENTER>
 
 <TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0 BORDER=0>
diff --git a/ecrire/inc.php3 b/ecrire/inc.php3
index c9f9cab3db..e11cf566f8 100644
--- a/ecrire/inc.php3
+++ b/ecrire/inc.php3
@@ -86,10 +86,11 @@ function integre_image($id_document, $align, $affichage_detaille = false) {
 	return $retour;
 }
 
-include_local ("inc_presentation.php3");
 include_local ("inc_connect.php3");
 include_local ("inc_meta.php3");
 include_local ("inc_auth.php3");
+
+include_local ("inc_presentation.php3");
 include_local ("inc_texte.php3");
 include_local ("inc_filtres.php3");
 include_local ("inc_urls.php3");
diff --git a/ecrire/inc_acces.php3 b/ecrire/inc_acces.php3
index 005fc4a4ff..e8e99726f9 100644
--- a/ecrire/inc_acces.php3
+++ b/ecrire/inc_acces.php3
@@ -9,25 +9,36 @@ define("_ECRIRE_INC_ACCES", "1");
 $GLOBALS['htaccess'] = $GLOBALS['dir_ecrire'].'.htaccess';
 $GLOBALS['htpasswd'] = $GLOBALS['dir_ecrire'].'data/.htpasswd';
 
-function initialiser_sel() {
-	global $htsalt, $flag_mt_rand;
 
+function creer_pass_aleatoire($longueur = 8, $sel = "") {
+	global $flag_mt_rand;
 	$seed = (double) (microtime() + 1) * time();
 	if ($flag_mt_rand) mt_srand($seed);
 	srand($seed);
 
-	$htsalt = '$1$';
-	for ($i = 0; $i < 8; $i++) {
-		$x = 0;
-		if ($flag_mt_rand) $x = mt_rand() & 63;
-		if (!$x) $x = rand() & 63;
+	for ($i = 0; $i < $longueur; $i++) {
+		if (!$s) {
+			if ($flag_mt_rand) $s = mt_rand();
+			if (!$s) $s = rand();
+			$s = substr(md5(uniqid($s).$sel), 0, 15);
+		}
+		$r = unpack("Cr", pack("H2", $s));
+		$x = $r['r'] & 63;
 		if ($x < 10) $x = chr($x + 48);
 		else if ($x < 36) $x = chr($x + 55);
 		else if ($x < 62) $x = chr($x + 61);
 		else if ($x == 63) $x = '/';
 		else $x = '.';
-		$htsalt .= $x;
+		$pass .= $x;
+		$s = substr($s, 1);
 	}
+	return $pass;
+}
+
+function initialiser_sel() {
+	global $htsalt;
+
+	$htsalt = '$1$'.creer_pass_aleatoire();
 }
 
 
diff --git a/ecrire/inc_mail.php3 b/ecrire/inc_mail.php3
index 7fefb94331..b3632acb23 100644
--- a/ecrire/inc_mail.php3
+++ b/ecrire/inc_mail.php3
@@ -40,7 +40,7 @@ function envoyer_mail($email, $sujet, $texte, $from = "", $headers = "") {
 	global $hebergeur, $queue_mails, $flag_wordwrap;
 
 	if (!$from) $from = $email;
-	if (! ereg(".@.", $email)) return;
+	if (!ereg(".@.", $email)) return;
 	if ($email == "vous@fournisseur.com") return;
 
 	$headers = "From: $from\n".
diff --git a/ecrire/inc_meta.php3 b/ecrire/inc_meta.php3
index a37bb38b37..dac667fdf4 100644
--- a/ecrire/inc_meta.php3
+++ b/ecrire/inc_meta.php3
@@ -70,7 +70,7 @@ function lire_meta_maj($nom) {
 		while (list($key, $val) = each($meta)) {
 			$key = addslashes($key);
 			$val = addslashes($val);
-			$s .= "\$GLOBALS['meta']['$key'] = '$val';\n";
+			$s .= "\$GLOBALS['meta']['$key'] = \"$val\";\n";
 		}
 		$s .= "\n";
 	}
diff --git a/ecrire/inc_presentation.php3 b/ecrire/inc_presentation.php3
index 31b05ae0ee..3b19e730b6 100644
--- a/ecrire/inc_presentation.php3
+++ b/ecrire/inc_presentation.php3
@@ -793,7 +793,7 @@ afficher_script_layer();
 	}
 	?></td></tr>
 		<tr><td><?php global $activer_breves;
-		if ($activer_breves!="non"){ ?><A HREF="breves.php3" onMouseOver="fond.src='IMG2/breves-texte.gif'" onMouseOut="fond.src='IMG2/rien.gif'"><img src="IMG2/breves-off.gif" name="breves" alt="Les br&egrave;ves" width="78" height="45" border="0"></A><?}else{ ?><img src="IMG2/breves-non.gif" name="breves" alt="Les br&egrave;ves" width="78" height="45" border="0"><?} ?></TD></TR>
+		if ($activer_breves!="non"){ ?><A HREF="breves.php3" onMouseOver="fond.src='IMG2/breves-texte.gif'" onMouseOut="fond.src='IMG2/rien.gif'"><img src="IMG2/breves-off.gif" name="breves" alt="Les br&egrave;ves" width="78" height="45" border="0"></A><?php }else{ ?><img src="IMG2/breves-non.gif" name="breves" alt="Les br&egrave;ves" width="78" height="45" border="0"><?php } ?></TD></TR>
 		</table></td>
 		<td valign="top">
 		<table cellpadding=0 cellspacing=0 border=0>
@@ -875,7 +875,7 @@ afficher_script_layer();
 	}
 	?></td></tr>
 		<tr><td><?php global $activer_breves;
-		if ($activer_breves!="non"){ ?><A HREF="breves.php3" onMouseOver="breves.src='IMG2/breves-on.gif'; fond.src='IMG2/breves-texte.gif'" onMouseOut="breves.src='IMG2/breves-off.gif'; fond.src='IMG2/rien.gif'"><img src="IMG2/breves-off.gif" name="breves" alt="Les br&egrave;ves" width="78" height="45" border="0"></A><?}else{ ?><img src="IMG2/breves-non.gif" name="breves" alt="Les br&egrave;ves" width="78" height="45" border="0"><?} ?></TD></TR>
+		if ($activer_breves!="non"){ ?><A HREF="breves.php3" onMouseOver="breves.src='IMG2/breves-on.gif'; fond.src='IMG2/breves-texte.gif'" onMouseOut="breves.src='IMG2/breves-off.gif'; fond.src='IMG2/rien.gif'"><img src="IMG2/breves-off.gif" name="breves" alt="Les br&egrave;ves" width="78" height="45" border="0"></A><?php }else{ ?><img src="IMG2/breves-non.gif" name="breves" alt="Les br&egrave;ves" width="78" height="45" border="0"><?php } ?></TD></TR>
 		</table></td>
 		<td valign="top">
 		<table cellpadding=0 cellspacing=0 border=0>
@@ -1134,13 +1134,13 @@ function fin_page() {
 //
 function install_debut_html($titre="Installation du syst&egrave;me de publication...") {
 	?>
-<HTML>
-<HEAD>
-<TITLE><?php echo $titre; ?></TITLE>
-<META HTTP-EQUIV="Expires" CONTENT="0">
-<META HTTP-EQUIV="cache-control" CONTENT="no-cache,no-store">
-<META HTTP-EQUIV="pragma" CONTENT="no-cache">
-<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
+<html>
+<head>
+<title><?php echo $titre; ?></title>
+<meta http-equiv="Expires" content="0">
+<meta http-equiv="cache-control" content="no-cache,no-store">
+<meta http-equiv="pragma" content="no-cache">
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
 <style>
 <!--
@@ -1153,29 +1153,29 @@ function install_debut_html($titre="Installation du syst&egrave;me de publicatio
 	.fondf {background-color: #FFFFFF; border-style: solid ; border-width: 1; border-color: #E86519; color: #E86519}
 -->
 </style>
-</HEAD>
+</head>
 
-<body bgcolor="#FFFFFF" text="#000000" link="#E86519" vlink="#6E003A" alink="#FF9900" TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
+<body bgcolor="#FFFFFF" text="#000000" link="#E86519" vlink="#6E003A" alink="#FF9900" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
 
-<BR><BR><BR>
-<CENTER>
-<TABLE WIDTH=450>
-<TR><TD WIDTH=450>
-<FONT FACE="Verdana,Arial,Helvetica,sans-serif" SIZE=4 COLOR="#970038"><B><?php 
+<br><br><br>
+<center>
+<table width="450">
+<tr><td width="450">
+<font face="Verdana,Arial,Helvetica,sans-serif" size="4" color="#970038"><B><?php 
 	echo $titre; 
-?></B></FONT>
-<FONT FACE="Georgia,Garamond,Times,serif" SIZE=3>
+?></b></font>
+<font face="Georgia,Garamond,Times,serif" size="3">
 	<?php
 }
 
 function install_fin_html() {
 
 	echo '
-	</FONT>
-	</TD></TR></TABLE>
-	</CENTER>
-	</BODY>
-	</HTML>
+	</font>
+	</td></tr></table>
+	</center>
+	</body>
+	</html>
 	';
 }
 
diff --git a/ecrire/index.php b/ecrire/index.php
index 24cf09ca0c..b05855ebca 100644
--- a/ecrire/index.php
+++ b/ecrire/index.php
@@ -1,4 +1,4 @@
-<?
+<?php
 	// pour hebergeurs ayant oublie de configurer DirectoryIndex index.php3
 	include ("index.php3");
 ?>
diff --git a/ecrire/install.php3 b/ecrire/install.php3
index 0e3d5febca..fb54424628 100644
--- a/ecrire/install.php3
+++ b/ecrire/install.php3
@@ -55,14 +55,14 @@ if (!file_exists("inc_connect.php3")) {
 		fputs($myFile, $protec);
 		fclose($myFile);
 
-		$conn = "<?\n";
+		$conn = "<?php\n";
 		$conn .= "if (defined(\"_ECRIRE_INC_CONNECT\")) return;\n";
 		$conn .= "define(\"_ECRIRE_INC_CONNECT\", \"1\");\n";
 		$conn .= "\$GLOBALS['db_ok'] = true;\n";
 		$conn .= "\$GLOBALS['db_ok'] &= !!@mysql_connect(\"$adresse_db\",\"$login_db\",\"$pass_db\");\n";
 		$conn .= "\$GLOBALS['db_ok'] &= !!@mysql_select_db(\"$sel_db\");\n";
 		$conn .= "?".">";
-		$myFile = fopen("inc_connect.php3", "w");
+		$myFile = fopen("inc_connect.php3", "wb");
 		fputs($myFile, $conn);
 		fclose($myFile);
 
@@ -331,7 +331,8 @@ if (!file_exists("inc_connect.php3")) {
 	else {
 		header("Location: ../spip_test_dirs.php3");
 	}
-}else{
+}
+else {
 	install_debut_html();
 	echo "<FONT FACE='Verdana,Arial,Helvetica,sans-serif' SIZE=4><B>Espace interdit</B></FONT>";
 	install_fin_html();
diff --git a/inc-calcul-squel.php3 b/inc-calcul-squel.php3
index 303c002831..fce9bca1ab 100644
--- a/inc-calcul-squel.php3
+++ b/inc-calcul-squel.php3
@@ -1275,7 +1275,7 @@ function calculer_champ($id_champ, $id_boucle, $nom_var)
 		$accepter_inscriptions = lire_meta("accepter_inscriptions");
 
 		if ($accepter_inscriptions == "oui") {
-			$'.$nom_var.' = "<"."? include_local(\"inc-formulaires.php3\"); formulaire_inscription(); ?".">";
+			$'.$nom_var.' = "<"."?php include_local(\"inc-formulaires.php3\"); formulaire_inscription(); ?".">";
 		}
 		else {
 			$'.$nom_var.' = "";
@@ -1314,7 +1314,7 @@ function calculer_champ($id_champ, $id_boucle, $nom_var)
  		$result_petition = mysql_query($query_petition);
 
 		if ($row_petition = mysql_fetch_array($result_petition)) {
-			$'.$nom_var.' = "<"."? include_local(\"inc-formulaires.php3\"); formulaire_signature($contexte[id_article]); ?".">";
+			$'.$nom_var.' = "<"."?php include_local(\"inc-formulaires.php3\"); formulaire_signature($contexte[id_article]); ?".">";
 		}
 		else {
 			$'.$nom_var.' = "";
@@ -1334,7 +1334,7 @@ function calculer_champ($id_champ, $id_boucle, $nom_var)
 		$proposer_sites = lire_meta("proposer_sites");
 
 		if ($proposer_sites == "2") {
-			$'.$nom_var.' = "<"."? include_local(\"inc-formulaires.php3\"); formulaire_site($contexte[id_rubrique]); ?".">";
+			$'.$nom_var.' = "<"."?php include_local(\"inc-formulaires.php3\"); formulaire_site($contexte[id_rubrique]); ?".">";
 		}
 		else {
 			$'.$nom_var.' = "";
@@ -1950,11 +1950,11 @@ function calculer_squelette($squelette, $fichier) {
 	$define = strtoupper("_SKEL_$squelette_nom");
 
 	// Debut du fichier
-	$texte .= "<"."?\n\n";
+	$texte .= "<"."?php\n\n";
 	$texte .= "\$func_squelette_executer = '$func';\n\n";
 	$texte .= "if (defined(\"$define\")) return;\n";
 	$texte .= "define(\"$define\", \"1\");\n\n\n";
-	
+
 	// Calculer le code PHP des boucles
 	if ($boucles) {
 		reset($boucles);
@@ -1973,7 +1973,7 @@ function calculer_squelette($squelette, $fichier) {
 	// Fin du fichier
 	$texte .= "?>";
 
-	$f = fopen($fichier, "w");
+	$f = fopen($fichier, "wb");
 	fwrite($f, $texte);
 	fclose($f);
 }
diff --git a/inc-formulaires.php3 b/inc-formulaires.php3
index efbd9e2c2a..c77d8c7ec6 100644
--- a/inc-formulaires.php3
+++ b/inc-formulaires.php3
@@ -6,31 +6,26 @@ if (defined("_INC_FORMULAIRES")) return;
 define("_INC_FORMULAIRES", "1");
 
 
+function test_pass() {
+	include_local("ecrire/inc_acces.php3");
 
-function test_pass(){
-	$passw=$prop_nom.$prop_email.$prop_bio.$prop_nom_site.$prop_url_site;
-	srand(time());
-	$passw=md5($passw.rand(11,1000));
-	$passw=crypt($passw,rand(11,10000));
-	$passw=ereg_replace("\.","",$passw);
-	$passw=ereg_replace("\/","",$passw);
-	$passw=ereg_replace("I","L",$passw);
-	$passw=ereg_replace("l","L",$passw);
-	$passw=substr($passw,0,8);
-
-	$query="SELECT * FROM spip_signatures WHERE statut='$passw'";
-	$result=mysql_query($query);
-	if (mysql_num_rows($result)>0){
-		$passw = test_pass();
-	} else {
-		return $passw;
+	for (;;) {
+		$passw = creer_pass_aleatoire();
+		$query = "SELECT statut FROM spip_signatures WHERE statut='$passw'";
+		$result = mysql_query($query);
+		if (!mysql_num_rows($result)) break;
 	}	
+	return $passw;
 }
 
 function test_login($mail) {
 	if (strpos($mail, "@") > 0) $login_base = substr($mail, 0, strpos($mail, "@"));
 	else $login_base = $mail;
 
+	$login_base = strtolower($login_base);
+	$login_base = ereg_replace("[^a-zA-Z0-9]", "", $login_base);
+	if (!$login_base) $login_base = "user";
+
 	for ($i = 0; ; $i++) {
 		if ($i) $login = $login_base.$i;
 		else $login = $login_base;
@@ -347,7 +342,7 @@ function formulaire_inscription() {
 			}
 			else {
 				//echo "<FONT FACE='verdana,arial,helvetica,sans-serif'>";
-				echo "Probl&eagrave; de mail&nbsp;: l'identifiant ne peut pas &ecirc;tre envoy&eacute;.";
+				echo "Probl&egrave;me de mail&nbsp;: l'identifiant ne peut pas &ecirc;tre envoy&eacute;.";
 				//echo "</FONT>";
 			}
 		}
@@ -373,7 +368,6 @@ function formulaire_site($la_rubrique) {
 	global $description_site;
 
 	if ($nom_site) {
-	
 		// Tester le nom du site
 		if (strlen ($nom_site) < 2){
 			$reponse_signature .= erreur("Veuillez indiquer le nom du site.");
@@ -388,7 +382,6 @@ function formulaire_site($la_rubrique) {
 		}
 
 		// Integrer a la base de donnees
-	
 		echo "<div class='reponse_formulaire'>";
 		
 		if ($refus !="oui"){
@@ -430,7 +423,7 @@ function ecrire_auteur($id_auteur,$email_auteur) {
 	if ($GLOBALS[texte_message_auteur]) {
 		if ($GLOBALS[sujet_message_auteur] == "")
 			$erreur .= erreur("Veuillez indiquer un sujet");
-		else if (! ereg(".@.", $GLOBALS[email_message_auteur]))
+		else if (!ereg(".@.", $GLOBALS[email_message_auteur]))
 			$erreur .= erreur("Veuillez indiquer votre email");
 		else if ($GLOBALS[valide_message_auteur]) {  // verifier hash ?
 			include_local("ecrire/inc_mail.php3");
diff --git a/inc-forum.php3 b/inc-forum.php3
index 7045b91c62..9b35ff1aa4 100644
--- a/inc-forum.php3
+++ b/inc-forum.php3
@@ -22,11 +22,10 @@ else {
 
 
 function generer_pass_forum($email = '') {
-	$passw = generer_htpass(md5($email.rand().$passw));
-	$passw = ereg_replace("[./]", "", $passw);
+	$passw = creer_pass_aleatoire(9, $email);
+	$passw = ereg_replace("[./]", "a", $passw);
 	$passw = ereg_replace("[I1l]", "L", $passw);
 	$passw = ereg_replace("[0O]", "o", $passw);
-	$passw = substr($passw, -8);
 	return $passw;
 }
 
diff --git a/inc-public.php3 b/inc-public.php3
index 493eb48167..8aadb172c3 100644
--- a/inc-public.php3
+++ b/inc-public.php3
@@ -255,7 +255,7 @@ if ($use_cache && file_exists('CACHE/.purge')) {
 // Afficher un bouton 
 //
 
-function bouton($titre, $lien){
+function bouton($titre, $lien) {
 	$lapage=substr($lien, 0, strpos($lien,"?"));
 	$lesvars=substr($lien, strpos($lien,"?") + 1, strlen($lien));
 
@@ -296,14 +296,11 @@ if ($admin_ok AND !$flag_preserver) {
 		bouton("Modifier cet auteur ($id_auteur)", "./ecrire/auteurs_edit.php3?id_auteur=$id_auteur");
 	}
 
-	$fich = substr($fichier_requete, strrpos($fichier_requete, '/') + 1);
-	if (strpos($fich, '?'))
-		$fich = "./$fich&";
-	else
-		$fich = "./$fich?";
-
-	bouton ('Recalculer cette page', $fich.'recalcul=oui');
-//	bouton ('Recalculer le squelette', $fich.'recalcul=oui&recalcul_squelettes=oui');
+	$link = new Link;
+	$link->addVar('recalcul', 'oui');
+	echo $link->getForm('GET');
+	echo "<input type='submit' class='spip_bouton' name='submit' value='Recalculer cette page'>";
+	echo "</form>\n";
 }
 
 
diff --git a/inc-stats.php3 b/inc-stats.php3
index 9346baab00..90c128086d 100644
--- a/inc-stats.php3
+++ b/inc-stats.php3
@@ -13,7 +13,7 @@ function ecrire_stats() {
 	$my_ref = $HTTP_REFERER;
 	$my_ref = "\n".substr(md5($my_ref), 0, 15);
 
-	$query = "SELECT visites, referers FROM spip_articles WHERE id_article=$id_article";
+	$query = "SELECT visites, referers FROM spip_articles WHERE id_article=$id_article AND statut='publie'";
 	$result = mysql_query($query);
 
 	if ($row = mysql_fetch_array($result)) {
diff --git a/index.php b/index.php
index 24cf09ca0c..b05855ebca 100644
--- a/index.php
+++ b/index.php
@@ -1,4 +1,4 @@
-<?
+<?php
 	// pour hebergeurs ayant oublie de configurer DirectoryIndex index.php3
 	include ("index.php3");
 ?>
-- 
GitLab