From fb6bbd76aee95ff036706a2ee708877ff0836af8 Mon Sep 17 00:00:00 2001
From: Fil <fil@rezo.net>
Date: Fri, 27 Feb 2004 12:13:48 +0000
Subject: [PATCH] =?UTF-8?q?trois=20changements=20:=20*=20parAuteur=20->=20?=
 =?UTF-8?q?par=20Auteur=20(squelettes=20par=20d=C3=A9faut)=20*=20indexatio?=
 =?UTF-8?q?n=20des=20forums,=20par=20thread=20(avec=20getion=20de=20la=20r?=
 =?UTF-8?q?eindexation=20en=20cas=20de=20mod=C3=A9ration)=20*=20m=C3=A9mor?=
 =?UTF-8?q?isation=20de=20la=20pr=C3=A9f=C3=A9rence=20de=20connexion=20(pe?=
 =?UTF-8?q?rmanente=20ou=20temporaire)=20d'une=20fois=20sur=20l'autre?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 auteur-dist.html         |  2 +-
 ecrire/inc.php3          |  7 +++++
 ecrire/inc_index.php3    | 63 +++++++++++++++++++++++++++++++++-------
 ecrire/lang/spip_fr.php3 |  4 +++
 inc-login.php3           |  6 +++-
 rubrique-dist.html       |  2 +-
 site-dist.html           |  2 +-
 sommaire-dist.html       |  2 +-
 spip_cookie.php3         |  7 ++++-
 9 files changed, 78 insertions(+), 17 deletions(-)

diff --git a/auteur-dist.html b/auteur-dist.html
index aa4d3c53b0..9241464561 100644
--- a/auteur-dist.html
+++ b/auteur-dist.html
@@ -80,7 +80,7 @@
 	<h2><a href="#URL_ARTICLE" [title="(#DESCRIPTIF|textebrut|entites_html)"]>#TITRE</a></h2>
 	<div class="detail">
 	[(#DATE|nom_jour)] [(#DATE|affdate)]
-	<B_auteurs><:par_auteur:><BOUCLE_auteurs(AUTEURS) {id_article} {", "}>#NOM</BOUCLE_auteurs>
+	<B_auteurs><:par_auteur:> <BOUCLE_auteurs(AUTEURS) {id_article} {", "}>#NOM</BOUCLE_auteurs>
 	</div>
 	<br>
 </BOUCLE_articles>
diff --git a/ecrire/inc.php3 b/ecrire/inc.php3
index 119ce9479e..b9bda4698d 100644
--- a/ecrire/inc.php3
+++ b/ecrire/inc.php3
@@ -286,6 +286,13 @@ function changer_statut_forum($id_forum, $statut) {
 			spip_query($query);
 		}
 	}
+
+	// signaler au moteur de recherche qu'il faut reindexer le thread
+	// (en fait on se contente de demander une reindexation du parent)
+	include_ecrire('inc_index.php3');
+	marquer_indexer ('forum', $id_parent);
+
+	// changer le statut de toute l'arborescence dependant de ce message
 	$id_messages = array($id_forum);
 	while ($id_messages) {
 		$id_messages = join(',', $id_messages);
diff --git a/ecrire/inc_index.php3 b/ecrire/inc_index.php3
index 2a236972f6..7d62d17eb8 100644
--- a/ecrire/inc_index.php3
+++ b/ecrire/inc_index.php3
@@ -189,15 +189,6 @@ function indexer_objet($type, $id_objet, $forcer_reset = true, $full = true /* f
 		}
 		break;
 
-	case 'forum':
-		indexer_chaine($row['titre'], 3);
-		indexer_chaine($row['texte'], 1);
-		indexer_chaine($row['auteur'], 2);
-		indexer_chaine($row['email_auteur'], 2);
-		indexer_chaine($row['nom_site'], 2);
-		indexer_chaine($row['url_site'], 1);
-		break;
-
 	case 'signature':
 		indexer_chaine($row['nom_email'], 2);
 		indexer_chaine($row['ad_email'], 2);
@@ -212,7 +203,7 @@ function indexer_objet($type, $id_objet, $forcer_reset = true, $full = true /* f
 		if ($full) {
 			// Ajouter les titres des articles syndiques de ce site, le cas echeant
 			if ($row['syndication'] = "oui") {
-				$query_syndic = "SELECT titre FROM spip_syndic_articles WHERE id_syndic=$id_objet ORDER BY date DESC LIMIT 0,100";
+				$query_syndic = "SELECT titre FROM spip_syndic_articles WHERE id_syndic=$id_objet AND statut='publie' ORDER BY date DESC LIMIT 0,100";
 				$result_syndic = spip_query($query_syndic);
 				while ($row_syndic = spip_fetch_array($result_syndic)) {
 					indexer_chaine($row_syndic['titre'], 5);
@@ -227,6 +218,56 @@ function indexer_objet($type, $id_objet, $forcer_reset = true, $full = true /* f
 		}
 		break;
 
+	//
+	// Cas tres particulier du forum :
+	// on indexe le thread comme un tout
+	case 'forum':
+		// 1. chercher la racine du thread
+		$id_forum = $id_objet;
+		while ($row['id_parent']) {
+			$id_forum = $row['id_parent'];
+			$s = spip_query("SELECT id_forum,id_parent FROM spip_forum WHERE id_forum=$id_forum");
+			$row = spip_fetch_array($s);
+		}
+
+		// 2. chercher tous les forums du thread
+		// (attention le forum de depart $id_objet n'appartient pas forcement
+		// a son propre thread car il peut etre le fils d'un forum non 'publie')
+		$thread="$id_forum";
+		$fini = false;
+		while (!$fini) {
+			$s = spip_query("SELECT id_forum FROM spip_forum WHERE id_parent IN ($thread) AND id_forum NOT IN ($thread) AND statut='publie'");
+			if (spip_num_rows($s) == 0) $fini = true;
+			while ($t = spip_fetch_array($s))
+				$thread.=','.$t['id_forum'];
+		}
+		
+		// 3. marquer le thread comme "en cours d'indexation"
+		spip_log("-> indexation thread $thread");
+		spip_query("UPDATE spip_forum SET idx='idx'
+			WHERE id_forum IN ($thread,$id_objet) AND idx!='non'");
+
+		// 4. Indexer le thread
+		$s = spip_query("SELECT * FROM spip_forum
+			WHERE id_forum IN ($thread) AND idx!='non'");
+		while ($row = spip_fetch_array($s)) {
+			indexer_chaine($row['titre'], 3);
+			indexer_chaine($row['texte'], 1);
+			indexer_chaine($row['auteur'], 2);
+			indexer_chaine($row['email_auteur'], 2);
+			indexer_chaine($row['nom_site'], 2);
+			indexer_chaine($row['url_site'], 1);
+		}
+
+		// 5. marquer le thread comme "indexe"
+		spip_query("UPDATE spip_forum SET idx='oui'
+			WHERE id_forum IN ($thread,$id_objet) AND idx!='non'");
+
+		// 6. Changer l'id_objet en id_forum de la racine du thread
+		$id_objet = $id_forum;
+
+		break;
+
 	} // switch
 
 	$query = "DELETE FROM $table_index WHERE $col_id=$id_objet";
@@ -260,7 +301,7 @@ function indexer_objet($type, $id_objet, $forcer_reset = true, $full = true /* f
 function marquer_indexer ($objet, $id_objet) {
 	spip_log ("demande indexation $objet $id_objet");
 	$table = 'spip_'.table_objet($objet);
-	spip_query ("UPDATE $table SET idx='1' WHERE id_$objet=$id_objet");
+	spip_query ("UPDATE $table SET idx='1' WHERE id_$objet=$id_objet AND idx!='non'");
 }
 function indexer_article($id_article) {
 	marquer_indexer('article', $id_article);
diff --git a/ecrire/lang/spip_fr.php3 b/ecrire/lang/spip_fr.php3
index e10435d5bc..a8dbd8df48 100644
--- a/ecrire/lang/spip_fr.php3
+++ b/ecrire/lang/spip_fr.php3
@@ -1249,6 +1249,10 @@ exige d\'avoir un acc&egrave;s FTP au site Web.',
 'mois_non_connu' => 'non connu',
 
 
+// N
+'navigateur_pas_redirige' => 'Si votre navigateur n\'est pas redirig&eacute;, cliquez ici pour continuer.',
+
+
 // O
 'onglet_affacer_base' => 'Effacer la base',
 'onglet_agenda' => 'Agenda',
diff --git a/inc-login.php3 b/inc-login.php3
index 989c5a2035..c681847218 100644
--- a/inc-login.php3
+++ b/inc-login.php3
@@ -117,6 +117,10 @@ function login($cible = '', $prive = 'prive', $message_login='') {
 			$source_auteur = $row['source'];
 			$alea_actuel = $row['alea_actuel'];
 			$alea_futur = $row['alea_futur'];
+			if ($row['prefs']) {
+				$prefs = unserialize($row['prefs']);
+				$rester_checked = ($prefs['cnx'] == 'perma' ? ' checked':'');
+			}
 		} else if (!$flag_autres_sources) {
 			$erreur = _T('login_identifiant_inconnu', array('login' => htmlspecialchars($login)));
 			$login = '';
@@ -175,7 +179,7 @@ function login($cible = '', $prive = 'prive', $message_login='') {
 		echo "<input type='password' name='session_password' class='forml' value=\"\" size='40'>\n";
 		echo "<input type='hidden' name='essai_login' value='oui'>\n";
 
-		echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='session_remember' value='oui' id='session_remember'> ";
+		echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='session_remember' value='oui' id='session_remember'$rester_checked> ";
 		echo "<label for='session_remember'>"._T('login_rester_identifie')."</label>";
 
 		$url = $cible->getUrl();
diff --git a/rubrique-dist.html b/rubrique-dist.html
index 814e15228b..dc9448a5aa 100644
--- a/rubrique-dist.html
+++ b/rubrique-dist.html
@@ -195,7 +195,7 @@
 	<h2><a href="#URL_ARTICLE" [title="(#DESCRIPTIF|textebrut|entites_html)"]>#TITRE</a></h2>
 	<div class="detail">
 	[(#DATE|nom_jour)] [(#DATE|affdate)]
-	<B_auteurs_recents><:par_auteur:><BOUCLE_auteurs_recents(AUTEURS) {id_article} {", "}>#NOM</BOUCLE_auteurs_recents>
+	<B_auteurs_recents><:par_auteur:> <BOUCLE_auteurs_recents(AUTEURS) {id_article} {", "}>#NOM</BOUCLE_auteurs_recents>
 	</div>
 	<br>
 </BOUCLE_articles_recents>
diff --git a/site-dist.html b/site-dist.html
index e6e682755d..2011bb4467 100644
--- a/site-dist.html
+++ b/site-dist.html
@@ -97,7 +97,7 @@
 	<a name="liens_forums">
 	<BOUCLE_forums_liens(FORUMS){id_syndic}{par date}{inverse}>
 		<a href="#forum#ID_FORUM"><img src="puce.gif" border="0">#TITRE</a>
-		<br>[(#DATE|affdate)][, <:par_auteur:>(#NOM)]
+		<br>[(#DATE|affdate)][, <:par_auteur:> (#NOM)]
 		<br>
 	</BOUCLE_forums_liens>
 	</font>
diff --git a/sommaire-dist.html b/sommaire-dist.html
index 3e57ddc3d2..8f821b8ae6 100644
--- a/sommaire-dist.html
+++ b/sommaire-dist.html
@@ -162,7 +162,7 @@
 	<h2><a href="#URL_ARTICLE" [title="(#DESCRIPTIF|textebrut|entites_html)"]>#TITRE</a></h2>
 	<div class="detail">
 	[(#DATE|nom_jour)] [(#DATE|affdate)]
-	<B_auteurs_recents><:par_auteur:><BOUCLE_auteurs_recents(AUTEURS) {id_article} {", "}>#NOM</BOUCLE_auteurs_recents>
+	<B_auteurs_recents><:par_auteur:> <BOUCLE_auteurs_recents(AUTEURS) {id_article} {", "}>#NOM</BOUCLE_auteurs_recents>
 	</div>
 	<br>
 </BOUCLE_articles_recents>
diff --git a/spip_cookie.php3 b/spip_cookie.php3
index b37dafff37..da15b44ae2 100644
--- a/spip_cookie.php3
+++ b/spip_cookie.php3
@@ -170,6 +170,11 @@ if ($cookie_session) {
 		spip_setcookie('spip_session', $cookie_session, time() + 3600 * 24 * 14);
 	else
 		spip_setcookie('spip_session', $cookie_session);
+
+	$prefs = ($row_auteur['prefs']) ? unserialize($row_auteur['prefs']) : array();
+	$prefs['cnx'] = ($session_remember == 'oui') ? 'perma' : '';
+	spip_query ("UPDATE spip_auteurs SET prefs = '".addslashes(serialize($prefs))."' WHERE id_auteur = ".$row_auteur['id_auteur']);
+
 }
 
 // Redirection
@@ -183,7 +188,7 @@ else {
 	echo "<html><head>";
 	echo "<meta http-equiv='Refresh' content='0; url=".$cible->getUrl()."'>";
 	echo "</head>\n";
-	echo "<body>Si votre navigateur n'est pas redirig&eacute;, <a href='".$cible->getUrl()."'>continuer</a>.</body></html>";
+	echo "<body><a href='".$cible->getUrl()."'>"._T('navigateur_pas_redirige')."</a></body></html>";
 }
 
 ?>
-- 
GitLab