From b09ab84849ae426ab756541dc50d46748b649745 Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Wed, 24 Sep 2008 15:25:30 +0000
Subject: [PATCH] Retour, en plus simple, de l'action Redirect, afin que l'on
 puisse prendre en compte le chgt de titre donc d'URL symbolique quand on
 clique sur le bouton 'Voir en ligne'.

---
 .gitattributes              |  1 +
 ecrire/action/redirect.php  | 29 +++++++++++++++++++++++++++++
 ecrire/inc/presentation.php | 17 ++++++++---------
 3 files changed, 38 insertions(+), 9 deletions(-)
 create mode 100644 ecrire/action/redirect.php

diff --git a/.gitattributes b/.gitattributes
index c2afb17d5a..8ada7183b1 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -89,6 +89,7 @@ ecrire/action/petitionner.php -text
 ecrire/action/poster_forum_prive.php -text
 ecrire/action/preferer.php -text
 ecrire/action/purger.php -text
+ecrire/action/redirect.php -text
 ecrire/action/referencer_traduction.php -text
 ecrire/action/regler_moderation.php -text
 ecrire/action/reorganiser.php -text
diff --git a/ecrire/action/redirect.php b/ecrire/action/redirect.php
new file mode 100644
index 0000000000..0d961566bf
--- /dev/null
+++ b/ecrire/action/redirect.php
@@ -0,0 +1,29 @@
+<?php
+
+/***************************************************************************\
+ *  SPIP, Systeme de publication pour l'internet                           *
+ *                                                                         *
+ *  Copyright (c) 2001-2008                                                *
+ *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
+ *                                                                         *
+ *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
+ *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
+\***************************************************************************/
+
+if (!defined("_ECRIRE_INC_VERSION")) return;
+
+// Un script utile pour recalculer une URLs symbolique des son changement
+
+function action_redirect_dist()
+{
+	$type = _request('type');
+	if (!preg_match('/^\w+$/', $type)) return;
+	$h = generer_url_entite_absolue(intval(_request('id')),
+					$type,
+					"var_mode=" . _request('var_mode'),
+					'',
+					true);
+	redirige_par_entete(str_replace('&amp;', '&', $h));
+}
+
+?>
\ No newline at end of file
diff --git a/ecrire/inc/presentation.php b/ecrire/inc/presentation.php
index aa590524a1..40e2877bdd 100644
--- a/ecrire/inc/presentation.php
+++ b/ecrire/inc/presentation.php
@@ -1095,7 +1095,7 @@ function voir_en_ligne ($type, $id, $statut=false, $image='racine-24.gif', $af =
 
 	$en_ligne = $message = '';
 	switch ($type) {
-		case 'article':
+	case 'article':
 			if ($statut == "publie" AND $GLOBALS['meta']["post_dates"] == 'non') {
 				$n = sql_fetsel("id_article", "spip_articles", "id_article=$id AND date<=NOW()");
 				if (!$n) $statut = 'prop';
@@ -1105,28 +1105,29 @@ function voir_en_ligne ($type, $id, $statut=false, $image='racine-24.gif', $af =
 			else if ($statut == 'prop')
 				$en_ligne = 'preview';
 			break;
-		case 'rubrique':
+	case 'rubrique':
 			if ($id > 0)
 				if ($statut == 'publie')
 					$en_ligne = 'calcul';
 				else
 					$en_ligne = 'preview';
 			break;
-		case 'breve':
-		case 'site':
+	case 'breve':
+	case 'site':
 			if ($statut == 'publie')
 				$en_ligne = 'calcul';
 			else if ($statut == 'prop')
 				$en_ligne = 'preview';
 			break;
-		case 'mot':
+	case 'mot':
 			$en_ligne = 'calcul';
 			break;
-		case 'auteur':
+	case 'auteur':
 			$n = sql_countsel('spip_auteurs_articles AS lien, spip_articles AS articles', "lien.id_auteur=".sql_quote($id)." AND lien.id_article=articles.id_article AND articles.statut='publie'");
 			if ($n) $en_ligne = 'calcul';
 			else $en_ligne = 'preview';
 			break;
+	default: return '';
 	}
 
 	if ($en_ligne == 'calcul')
@@ -1137,9 +1138,7 @@ function voir_en_ligne ($type, $id, $statut=false, $image='racine-24.gif', $af =
 	else
 		return '';
 
-	$h = generer_url_entite_absolue($id, $type, "var_mode=$en_ligne", '', true);
-
-	$h = str_replace('&', '&amp;', $h);
+	$h = generer_url_action('redirect', "type=$type&id=$id&var_mode=$en_ligne");
 
 	return $inline  
 	  ? icone_inline($message, $h, $image, "rien.gif", $GLOBALS['spip_lang_left'])
-- 
GitLab