diff --git a/ecrire/articles.php3 b/ecrire/articles.php3
index 7ce8fca0466c606f6e63b9ecb320601070b2d534..16d4c0d7d1f545e8bfbb80f30193d010bc66590a 100644
--- a/ecrire/articles.php3
+++ b/ecrire/articles.php3
@@ -424,11 +424,9 @@ fin_boite_info();
 
 // Logos de l'article
 
-$arton = "arton$id_article";
-$artoff = "artoff$id_article";
-
-if ($id_article>0 AND $flag_editable)
-	afficher_boite_logo($arton, $artoff, _T('logo_article').aide ("logoart"), _T('logo_survol'));
+if ($id_article AND $flag_editable)
+	afficher_boite_logo('art', 'id_article', $id_article,
+	_T('logo_article').aide ("logoart"), _T('logo_survol'));
 
 
 //
diff --git a/ecrire/auteurs_edit.php3 b/ecrire/auteurs_edit.php3
index a884b22689d24144bca0cfff762306b80e66f1b5..319eed7341ad30799fc26f8522fe857aff8effeb 100644
--- a/ecrire/auteurs_edit.php3
+++ b/ecrire/auteurs_edit.php3
@@ -88,11 +88,11 @@ fin_boite_info();
 // Logos de l'auteur
 //
 
-$arton = "auton$id_auteur";
-$artoff = "autoff$id_auteur";
-
-if ($id_auteur>0 AND (($connect_statut == '0minirezo') OR ($connect_id_auteur == $id_auteur)))
-	afficher_boite_logo($arton, $artoff, _T('logo_auteur').aide ("logoart"), _T('logo_survol'));
+if ($id_auteur
+AND (($connect_statut == '0minirezo')
+OR ($connect_id_auteur == $id_auteur)))
+	afficher_boite_logo('aut', 'id_auteur', $id_auteur,
+	_T('logo_auteur').aide ("logoart"), _T('logo_survol'));
 
 
 debut_droite();
diff --git a/ecrire/breves_voir.php3 b/ecrire/breves_voir.php3
index 03e6ec27fd45a2e6cc54b842cc90be96f557a7de..2340a1a78e0a807ae92ba868c37fec490c4b7f9d 100644
--- a/ecrire/breves_voir.php3
+++ b/ecrire/breves_voir.php3
@@ -179,11 +179,9 @@ fin_boite_info();
 // Logos de la breve
 //
 
-$arton = "breveon$id_breve";
-$artoff = "breveoff$id_breve";
-
 if ($id_breve>0 AND ($connect_statut == '0minirezo' AND acces_rubrique($id_rubrique)))
-	afficher_boite_logo($arton, $artoff, _T('logo_breve').aide ("breveslogo"), _T('logo_survol'));
+	afficher_boite_logo('breve', 'id_breve', $id_breve,
+	_T('logo_breve').aide ("breveslogo"), _T('logo_survol'));
 
 debut_raccourcis();
 icone_horizontale(_T('icone_nouvelle_breve'), "breves_edit.php3?new=oui", "breve-24.gif","creer.gif");
diff --git a/ecrire/inc_admin.php3 b/ecrire/inc_admin.php3
index 673a53ed267d9407ec3a42beaea5d801d5d15b3d..b12553b88f69be615f42594c38e492aedf5b22be 100644
--- a/ecrire/inc_admin.php3
+++ b/ecrire/inc_admin.php3
@@ -74,8 +74,11 @@ function calculer_action_auteur($action, $id_auteur = 0) {
 }
 
 function verifier_action_auteur($action, $valeur, $id_auteur = 0) {
-	if ($valeur == _action_auteur($action, $id_auteur, 'alea_ephemere')) return true;
-	if ($valeur == _action_auteur($action, $id_auteur, 'alea_ephemere_ancien')) return true;
+	if ($valeur == _action_auteur($action, $id_auteur, 'alea_ephemere'))
+		return true;
+	if ($valeur == _action_auteur($action, $id_auteur, 'alea_ephemere_ancien'))
+		return true;
+	spip_log("inc_admin: verifier action $action $id_auteur : echec");
 	return false;
 }
 
diff --git a/ecrire/inc_documents.php3 b/ecrire/inc_documents.php3
index 464e1495a395778237c62c6e4f747de3cec1ddfc..21a845820999af92c8acbc0ad80b2272dab57b46 100644
--- a/ecrire/inc_documents.php3
+++ b/ecrire/inc_documents.php3
@@ -425,8 +425,8 @@ function afficher_upload($link, $redirect='', $intitule, $inclus = '', $envoi_mu
 		// afficher le premier
 		echo str_replace('*', '1', $upload);
 
-		// afficher les suivants, masques
-		if ($envoi_multiple) {
+		// afficher les suivants, masques (DESACTIVE)
+		if (false /* $envoi_multiple */) {
 			echo debut_block_invisible ("upload$num_form");
 			for ($i=2; $i<=10; $i++)
 				echo str_replace('*', "$i", $upload);
@@ -479,9 +479,6 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 	if ($id_article) $image_url .= '&id_article='.$id_article;
 	if ($type == "rubrique") $image_url .= '&modifier_rubrique=oui';
 
-	if ($GLOBALS['id_document'] > 0) {
-		$id_document_deplie = $GLOBALS['id_document'];
-	}
 	$redirect_url = $clean_link->getUrl();
 
 	// Afficher portfolio
@@ -520,7 +517,7 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 			$date = $document['date'];
 			$mode = $document['mode'];
 
-			$flag_deplier = ($id_document_deplie == $id_document);
+			$flag_deplie = teste_doc_deplie($id_document);
 
 			if ($case == 0) {
 				echo "<tr style='border-top: 1px solid black;'>";
@@ -558,7 +555,7 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 					$vignette_perso = true;
 					$link = new Link ($image_url);
 					$link->addVar('redirect',
-						$redirect_url.'&id_document='.$id_document);
+						$redirect_url.'&show_docs='.$id_document);
 					$link->addVar('hash',
 						calculer_action_auteur("supp_doc ".$id_vignette));
 					$link->addVar('hash_id_auteur', $connect_id_auteur);
@@ -580,7 +577,7 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 						$link_rot->addVar('hash', calculer_action_auteur("rotate ".$id_document));
 						$link_rot->addVar('hash_id_auteur', $connect_id_auteur);
 						$link_rot->addVar('doc_rotate', $id_document);
-						$link_rot->addVar('vignette_aff', $id_document);
+						$link_rot->addVar('show_docs', $id_document);
 						$link_rot->addVar('var_rot', -90);
 						echo http_href_img($link_rot->getUrl("portfolio"), 'tourner-gauche.gif', "border='0'", "tourner-gauche", '', 'bouton_rotation');
 						echo "<br />";
@@ -589,17 +586,17 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 						$link_rot->addVar('hash', calculer_action_auteur("rotate ".$id_document));
 						$link_rot->addVar('hash_id_auteur', $connect_id_auteur);
 						$link_rot->addVar('doc_rotate', $id_document);
-						$link_rot->addVar('vignette_aff', $id_document);
+						$link_rot->addVar('show_docs', $id_document);
 						$link_rot->addVar('var_rot', 90);
 						echo http_href_img($link_rot->getUrl("portfolio"), 'tourner-droite.gif', "border='0'", "tourner-droite", '', 'bouton_rotation');
 						echo "<br />";
-		
+
 						$link_rot = new Link ($image_url);;
 						$link_rot->addVar('redirect', $redirect_url);
 						$link_rot->addVar('hash', calculer_action_auteur("rotate ".$id_document));
 						$link_rot->addVar('hash_id_auteur', $connect_id_auteur);
 						$link_rot->addVar('doc_rotate', $id_document);
-						$link_rot->addVar('vignette_aff', $id_document);
+						$link_rot->addVar('show_docs', $id_document);
 						$link_rot->addVar('var_rot', 180);
 						echo http_href_img($link_rot->getUrl("portfolio"), 'tourner-180.gif', "border='0'", "tourner-180", '', 'bouton_rotation');
 					}
@@ -660,7 +657,7 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 			}
 
 			if ($flag_modif) {
-				if ($flag_deplier) $triangle = bouton_block_visible("port$id_document");
+				if ($flag_deplie) $triangle = bouton_block_visible("port$id_document");
 				else $triangle = bouton_block_invisible("port$id_document");
 			}
 			if (strlen($titre) > 0) {
@@ -682,12 +679,13 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 			._T('info_largeur_vignette', array('largeur_vignette' => $largeur, 'hauteur_vignette' => $hauteur))."</div>";
 			
 			if ($flag_modif) {
-				if ($flag_deplier) echo debut_block_visible("port$id_document");
+				if ($flag_deplie) echo debut_block_visible("port$id_document");
 				else echo debut_block_invisible("port$id_document");
 				echo "<div class='verdana1' style='color: $couleur_foncee; border: 1px solid $couleur_foncee; padding: 5px; margin-top: 3px;'>";
 				$link = new Link($redirect_url);
 				$link->addVar('modif_document', 'oui');
 				$link->addVar('id_document', $id_document);
+				$link->addVar('show_docs', $id_document);
 				$ancre = "portfolio";
 				if ($flag_modif) {
 					echo $link->getForm('POST', $ancre);
@@ -795,7 +793,7 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 			$date = $document['date'];
 			$mode = $document['mode'];
 			
-			$flag_deplier = ($id_document_deplie == $id_document);
+			$flag_deplie = teste_doc_deplie($id_document);
 			
 			if ($case == 0) {
 				echo "<tr style='border-top: 1px solid black;'>";
@@ -867,7 +865,7 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 			
 			
 			if ($flag_modif) {
-				if ($flag_deplier) $triangle = bouton_block_visible("port$id_document");
+				if ($flag_deplie) $triangle = bouton_block_visible("port$id_document");
 				else $triangle =  bouton_block_invisible("port$id_document");
 			}
 			if (strlen($titre) > 0) {
@@ -884,12 +882,13 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
 			if ($largeur > 0 AND $hauteur > 0) echo "<div class='verdana1' style='text-align: center;'>"._T('info_largeur_vignette', array('largeur_vignette' => $largeur, 'hauteur_vignette' => $hauteur))."</div>";
 			
 			if ($flag_modif) {
-				if ($flag_deplier) echo debut_block_visible("port$id_document");
+				if ($flag_deplie) echo debut_block_visible("port$id_document");
 				else echo debut_block_invisible("port$id_document");
 				echo "<div class='verdana1' style='color: #999999; border: 1px solid #999999; padding: 5px; margin-top: 3px;'>";
 				$link = new Link($redirect_url);
 				$link->addVar('modif_document', 'oui');
 				$link->addVar('id_document', $id_document);
+				$link->addVar('show_docs', $id_document);
 				$ancre = "docs";
 				if ($flag_modif) {
 					echo $link->getForm('POST', $ancre);
@@ -1007,12 +1006,11 @@ function afficher_horizontal_document($id_document, $image_link, $redirect_url =
 	global $connect_id_auteur, $connect_statut;
 	global $couleur_foncee, $couleur_claire;
 	global $clean_link;
-	global $options, $id_document_deplie;
+	global $options;
 
 	$image_url = $image_link->geturl();
 
-	if ($GLOBALS['id_document']) $id_document_deplie = $GLOBALS['id_document'];
-	if ($id_document == $id_document_deplie) $flag_deplie = true;
+	$flag_deplie = teste_doc_deplie($id_document);
 
 	if (!$redirect_url) $redirect_url = $clean_link->getUrl();
 	$ancre = 'doc'.$id_document;
@@ -1159,6 +1157,7 @@ function afficher_horizontal_document($id_document, $image_link, $redirect_url =
 	$link = new Link($redirect_url);
 	$link->addVar('modif_document', 'oui');
 	$link->addVar('id_document', $id_document);
+	$link->addVar('show_docs', $id_document);
 	if ($flag_modif) {
 		echo $link->getForm('POST', $ancre);
 
@@ -1344,11 +1343,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d
 	global $spip_lang_left, $spip_lang_right;
 
 
-	if ($GLOBALS['id_document'] > 0) {
-		$id_document_deplie = $GLOBALS['id_document'];
-	}
-
-	if ($id_document == $id_document_deplie) $flag_deplie = true;
+	$flag_deplie = teste_doc_deplie($id_document);
 
  	$doublons = $id_doublons['documents'].",";
 
@@ -1468,6 +1463,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d
 		$link = new Link($redirect_url);
 		$link->addVar('modif_document', 'oui');
 		$link->addVar('id_document', $id_document);
+		$link->addVar('show_docs', $id_document);
 		echo $link->getForm('POST');
 
 		echo "<b>"._T('entree_titre_document')."</b><br />\n";
@@ -1566,6 +1562,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d
 		$link = new Link($redirect_url);
 		$link->addVar('modif_document', 'oui');
 		$link->addVar('id_document', $id_document);
+		$link->addVar('show_docs', $id_document);
 		echo $link->getForm('POST');
 
 		echo "<div class='verdana1' style='color: #999999; border: 1px solid #999999; padding: 5px; margin-top: 3px; text-align: left; background-color: #eeeeee;'>";
@@ -1601,5 +1598,14 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d
 	}
 }
 
+function teste_doc_deplie($id_document) {
+	global $show_docs;
+	static $deplies;
+
+	if (!$deplies)
+		$deplies = split('-',$show_docs);
+
+	return in_array($id_document, $deplies);
+}
 
 ?>
diff --git a/ecrire/inc_getdocument.php3 b/ecrire/inc_getdocument.php3
index ec215fc19ce7f125a803c8e67936b183900db345..95ad824b668615ad166649246403c86d97d6087a 100644
--- a/ecrire/inc_getdocument.php3
+++ b/ecrire/inc_getdocument.php3
@@ -1,7 +1,7 @@
 <?php
 
 //
-// Fonctions complementaires a spip_image.php3
+// Fonctions de spip_image.php3
 
 //
 // Ce fichier ne sera execute qu'une fois
@@ -9,24 +9,35 @@ if (defined("_ECRIRE_INC_GETDOCUMENT")) return;
 define("_ECRIRE_INC_GETDOCUMENT", "1");
 
 
+// Creer IMG/pdf/
 function creer_repertoire_documents($ext) {
-	global $dossier_squelettes;
-
-# est-il bien raisonnable d'accepter de creer si creer_rep retourne '' ?
 	$rep = _DIR_DOC . creer_repertoire(_DIR_DOC, $ext);
-	// Securite
-	if (!$ext || ($rep == $dossier_squelettes) || (substr($rep,0,-1) == $dossier_squelettes))
-		{
-		  spip_log("creer_repertoire_documents interdit");
-		  exit;
-		}
+
+	if (!$ext OR !$rep) {
+		spip_log("creer_repertoire_documents interdit");
+		exit;
+	}
+
 	if (lire_meta("creer_htaccess") == 'oui') {
 		include_ecrire('inc_acces.php3');
 		verifier_htaccess($rep);
 	}
+
 	return $rep;
 }
 
+// Efface le repertoire de maniere recursive !
+function effacer_repertoire_temporaire($nom) {
+	$d = opendir($nom);
+	while ($f = readdir($d)) {
+		if (is_file("$nom/$f"))
+			@unlink("$nom/$f");
+		else if ($f <> '.' AND $f <> '..'
+		AND is_dir("$nom/$f"))
+			effacer_repertoire_temporaire("$nom/$f");
+	}
+	@rmdir($nom);
+}
 
 function copier_document($ext, $orig, $source) {
 
@@ -36,18 +47,86 @@ function copier_document($ext, $orig, $source) {
 			translitteration(ereg_replace("\.([^.]+)$", "", 
 						      ereg_replace("<[^>]*>", '', basename($orig)))));
 
-	# bien vu ?
-	if ($source == ($dest . '.' . $ext)) return $source;
+	// Si le document "source" est deja au bon endroit, ne rien faire
+	if ($source == ($dest . '.' . $ext))
+		return $source;
+
+	// sinon tourner jusqu'a trouver un numero correct
 	$n = 0;
 	while (@file_exists($newFile = $dest.($n++ ? '-'.$n : '').'.'.$ext));
-	$r = deplacer_fichier_upload($source, $newFile);
-	return (!$r ? '' : $newFile);
+
+	if ($r = deplacer_fichier_upload($source, $newFile))
+		return $newFile;
 }
 
-function verifier_compactes($image_name) {
+//
+// Deplacer un fichier
+//
+
+function deplacer_fichier_upload($source, $dest) {
+	// Securite
+	if (strstr($dest, "..")) { exit; }
+
+	$ok = @copy($source, $dest);
+	if (!$ok) $ok = @move_uploaded_file($source, $dest);
+	if ($ok)
+		@chmod($dest, 0666);
+	else {
+		$f = @fopen($dest,'w');
+		if ($f) {
+			fclose ($f);
+		} else {
+			redirige_par_entete("spip_test_dirs.php3?test_dir=".
+				dirname($dest));
+		}
+		@unlink($dest);
+	}
+
+	return $ok;
+}
 
-	$zip = new PclZip($image_name);
 
+// Erreurs d'upload
+// renvoie false si pas d'erreur
+// et true si erreur = pas de fichier
+// pour les autres erreurs affiche le message d'erreur et meurt
+function check_upload_error($error, $msg='') {
+	switch ($error) {
+		case 0:
+			return false;
+		case 4: /* UPLOAD_ERR_NO_FILE */
+			return true;
+
+		# on peut affiner les differents messages d'erreur
+		case 1: /* UPLOAD_ERR_INI_SIZE */
+			$msg = _T('upload_limit',
+			array('max' => ini_get('upload_max_filesize')));
+			break;
+		case 2: /* UPLOAD_ERR_FORM_SIZE */
+			$msg = _T('upload_limit',
+			array('max' => ini_get('upload_max_filesize')));
+			break;
+		case 3: /* UPLOAD_ERR_PARTIAL  */
+			$msg = _T('upload_limit',
+			array('max' => ini_get('upload_max_filesize')));
+			break;
+	}
+
+	spip_log ("erreur upload $error");
+
+	include_ecrire('inc_presentation.php3');
+	install_debut_html(_T('forum_titre_erreur'));
+	echo "<p>$msg</p>\n";
+
+	install_fin_html(_DIR_RESTREINT_ABS . $GLOBALS['redirect']);
+	exit;
+}
+
+
+//
+// Gestion des fichiers ZIP
+//
+function verifier_compactes($zip) {
 	if ($list = $zip->listContent()) {
 	// si pas possible de decompacter: installer comme fichier zip joint
 	// Verifier si le contenu peut etre uploade (verif extension)
@@ -57,7 +136,7 @@ function verifier_compactes($image_name) {
 			
 				if ($key == "stored_filename") {
 					$f =  $list[$i][$key];
-					  // Regexp des fichiers a ignorer
+					// Regexp des fichiers a ignorer
 					if (!ereg("^(\.|.*/\.|.*__MACOSX/)", $f)) {
 						if (ereg("\.([^.]+)$", $f, $match)) {
 							$result = spip_query("SELECT * FROM spip_types_documents WHERE extension='"
@@ -78,7 +157,7 @@ function verifier_compactes($image_name) {
 	return $aff_fichiers ;
 }
 
-function afficher_compactes($image_name, $fichiers, $link) {
+function afficher_compactes($image_name /* not used */, $fichiers, $link) {
 // presenter une interface pour choisir si fichier joint ou decompacter
 // passer ca en squelette un de ces jours.
 
@@ -108,160 +187,483 @@ function afficher_compactes($image_name, $fichiers, $link) {
 	install_fin_html();
 }
 
+
 //
-// Ajouter un unique document
+// Ajouter un document (au format $_FILES)
 //
-
-function ajout_doc($orig, $source, $mode, $id_document) {
-	global $hash_id_auteur, $hash, $id_article, $type;
-
-	//
-	// Securite
-	//
-	if (!verifier_action_auteur("ajout_doc", $hash, $hash_id_auteur))
-		return;
+function ajouter_un_document ($source, $nom_envoye, $type_lien, $id_lien, $mode, $id_document, &$documents_actifs) {
 
 	// type de document inconnu ?
-	if (!ereg("\.([^.]+)$", $orig, $match)) return;
+	if (!ereg("\.([^.]+)$", $nom_envoye, $match)) return;
 
+	// tester le type de document :
+	// - interdit a l'upload ?
+	// - quel numero dans spip_types_documents ?  =-(
+	// - est-ce "inclus" comme une image ?
 	$ext = corriger_extension(addslashes(strtolower($match[1])));
-	$row = spip_query("SELECT * FROM spip_types_documents WHERE extension='$ext' AND upload='oui'" . (($mode != 'vignette') ? '' : " AND inclus='image'"));
 
-	// type de document invalide ?
-	if (!$row = spip_fetch_array($row)) {return;}
+	if (!$row = spip_fetch_array(spip_query(
+	"SELECT * FROM spip_types_documents
+	WHERE extension='$ext' AND upload='oui'")))
+		return 'o';
+	$id_type = $row['id_type'];	# numero du type dans spip_types_documents :(
+	$type_inclus_image = ($row['inclus'] == 'image');
+
+	// Recopier le fichier a son emplacement definitif
+	$definitif = copier_document($ext, $nom_envoye, $source);
+	if (!$definitif)
+		return;
 
-	// Recopier le fichier sauf si deja fait (zip tel quel)
-	$dest_path = !$source ? $orig : copier_document($ext,$orig, $source);
-	if (!$dest_path) return;
-	$taille = filesize($dest_path);
+	// Quelques infos sur le fichier
+	if (!@file_exists($definitif)
+	OR !$taille = @filesize($definitif))
+		return;
 
-	$size_image = @getimagesize($dest_path);
+	// Est-ce une image ?
+	$size_image = @getimagesize($definitif);
 	$type_image = decoder_type_image($size_image[2]);
 	if ($type_image) {
 		$largeur = $size_image[0];
 		$hauteur = $size_image[1];
 	}
 
-	if ($taille == 0
-	OR ($mode == 'vignette' AND ($largeur == 0 OR $hauteur==0)))
+	// Si on veut uploader une vignette, il faut qu'elle ait ete bien lue
+	if ($mode == 'vignette' AND !($largeur * $hauteur)) {
+		@unlink($definitif);
 		return;
+	}
 
-	// Preparation
-	if ($mode == 'vignette') {
-		$id_document_lie = $id_document;
-		$query = "UPDATE spip_documents SET mode='document' where id_document='$id_document_lie'";
-		spip_query($query); // requete inutile a mon avis (Fil)...
+	// Preparation vignette du document $id_document
+	$id_document=intval($id_document);
+	if ($mode == 'vignette' AND $id_document_lie = $id_document) {
+		# on force le statut "document" de ce fichier (inutile ?)
+		spip_query("UPDATE spip_documents
+			SET mode='document'
+			WHERE id_document=$id_document");
 		$id_document = 0;
 	}
+
+	// Installer le document dans la base
+	// attention piege semantique : les images s'installent en mode 'vignette'
+	// note : la fonction peut "mettre a jour un document" si on lui
+	// passe "mode=document" et "id_document=.." (pas utilise)
 	if (!$id_document) {
-		$id_type = $row['id_type'];
-		$id_document = spip_abstract_insert("spip_documents", "(id_type, titre, date)", "($id_type, '', NOW())");
-		$nouveau = true;
-		if ($id_article && isset($type)) {
-			$query = "INSERT INTO spip_documents_".$type."s (id_document, id_".$type.") VALUES ($id_document, $id_article)";
-			spip_query($query);
-		}
-	}
-	if ($nouveau) {
-		$type_inclus = $row['inclus'];
-		if (!$mode) $mode = ($type_image AND $type_inclus == 'image') ? 'vignette' : 'document';
+		// Inserer le nouveau doc et recuperer son id_
+		$id_document = spip_abstract_insert("spip_documents",
+		"(id_type, titre, date)", "($id_type, '', NOW())");
+
+		if ($id_lien
+		AND ($type_lien == 'article' OR $type_lien == 'rubrique'))
+			spip_query("INSERT INTO spip_documents_".$type_lien."s
+				(id_document, id_".$type_lien.")
+				VALUES ($id_document, $id_lien)");
+
+		// par defaut (upload ZIP ou ftp) integrer
+		// les images en mode 'vignette' et le reste en mode document
+		if (!$mode)
+			if ($type_image AND $type_inclus_image)
+				$mode = 'vignette';
+			else
+				$mode = 'document';
 			$update = "mode='$mode', ";
 	}
 
-	spip_query("UPDATE spip_documents SET $update taille='$taille', largeur='$largeur', hauteur='$hauteur', fichier='$dest_path' WHERE id_document=$id_document");
+	// Mise a jour des donnees
+	spip_query("UPDATE spip_documents
+		SET $update
+		taille='$taille', largeur='$largeur', hauteur='$hauteur',
+		fichier='$definitif'
+		WHERE id_document=$id_document");
 
 	if ($id_document_lie) {
-		$query = "UPDATE spip_documents SET id_vignette=$id_document WHERE id_document=$id_document_lie";
-		spip_query($query);
-		$id_document = $id_document_lie; // pour que le 'return' active le bon doc.
+		spip_query ("UPDATE spip_documents
+		SET id_vignette=$id_document
+		WHERE id_document=$id_document_lie");
+		// hack pour que le retour vers ecrire/ active le bon doc.
+		$documents_actifs[] = $id_document_lie; 
+	}
+	else
+		$documents_actifs[] = $id_document; 
+
+	// Creer la vignette des images
+	if ($mode == 'document'
+	AND ereg(",$ext,", ','.lire_meta('formats_graphiques').',')
+	AND $type_image)
+		creer_fichier_vignette($definitif);
+
+	return true;
+}
+
+
+
+
+//
+// Convertit le type numerique retourne par getimagesize() en extension fichier
+//
+
+function decoder_type_image($type, $strict = false) {
+	switch ($type) {
+	case 1:
+		return "gif";
+	case 2:
+		return "jpg";
+	case 3:
+		return "png";
+	case 4:
+		return $strict ? "" : "swf";
+	case 5:
+		return "psd";
+	case 6:
+		return "bmp";
+	case 7:
+	case 8:
+		return "tif";
+	default:
+		return "";
 	}
+}
+
+
+//
+// Corrige l'extension du fichier dans quelques cas particuliers
+//
 
-	// Creer la vignette
-	if ($mode == 'document' AND ereg(",$ext,", ','.lire_meta('formats_graphiques').',')) {
-		creer_fichier_vignette($dest_path);
+function corriger_extension($ext) {
+	switch ($ext) {
+	case 'htm':
+		return 'html';
+	case 'jpeg':
+		return 'jpg';
+	case 'tiff':
+		return 'tif';
+	default:
+		return $ext;
 	}
 }
 
-// Ajouter un ou plusieurs documents ?
-
-function ajout_doc_zip($image, $image_name, $mode, $forcer_document, $action_zip, $id_document, $hash, $link)
-{
-// image_name n'est valide que par POST http, mais pas par la methode ftp/upload
-// par ailleurs, pour un fichier ftp/upload, il faut effacer l'original nous-memes
-// action_zip indique un rappel par la fonction affiche_compactes
-	if (!$action_zip){
-		// on va se rappeler: copier le fichier car PHP va le virer
-		$image_name = copier_document("zip", $image_name, $image);
-		// anormal, on se tire
-		if (!$image_name) exit;
-		// renvoyer un formulaire demandant si on deballe ou pas
-		require_once(_DIR_RESTREINT . 'pclzip.lib.php');
-		$fichiers = verifier_compactes($image_name);
-		if ($fichiers) {
-			$link->addVar("image_name", $image_name);
-			afficher_compactes($image_name, $fichiers, $link);
-			exit;
-		}
-		// pas possible de deballer, on continue
-		$forcer_document = 'oui';
-		$image = $image_name;
-	  }
-	  else {
-	    // reponse au formulaire
-		if ($action_zip == "telquel") {
-			$forcer_document = 'oui';
-			
-		} else {
-			require_once(_DIR_RESTREINT . 'pclzip.lib.php');
-  			$archive = new PclZip($image_name);
-			$tmp_dir = creer_repertoire_documents($hash);
-			$archive->extract(PCLZIP_OPT_PATH, $tmp_dir, PCLZIP_OPT_REMOVE_ALL_PATH);
-			# virer le zip après le déballage
-			@unlink($image_name);
-			$image_name = $tmp_dir;
 
+//
+// Ajouter un logo
+//
+
+// $source = $_FILES[0]
+// $dest = arton12.xxx
+function ajout_logo($source, $dest) {
+
+	// Intercepter une erreur d'upload
+	if (check_upload_error($source['error'])) return;
+
+	// analyse le type de l'image (on ne fait pas confiance au nom de
+	// fichier envoye par le browser : pour les Macs c'est plus sur)
+	$f =_DIR_DOC . $dest . '.tmp';
+	deplacer_fichier_upload($source['tmp_name'], $f);
+	$size = @getimagesize($f);
+	$type = decoder_type_image($size[2], true);
+
+	if ($type) {
+		$poids = filesize($f);
+		if ($poids > _LOGO_MAX_SIZE*1024) {
+			@unlink ($f);
+			check_upload_error(6,
+			_T('info_logo_max_poids',
+				array('maxi' => taille_en_octets(_LOGO_MAX_SIZE*1024),
+				'actuel' => taille_en_octets($poids))));
 		}
-	  }
-	ajout_doc_s($image, $image_name, $mode, $forcer_document, $id_document, $hash);
+		if (($size[0] > _LOGO_MAX_WIDTH)
+		OR ($size[1] > _LOGO_MAX_HEIGHT)) {
+			@unlink ($f);
+			check_upload_error(6, 
+			_T('info_logo_max_taille',
+				array(
+				'maxi' =>
+					_T('info_largeur_vignette',
+						array('largeur_vignette' => _LOGO_MAX_WIDTH,
+						'hauteur_vignette' => _LOGO_MAX_HEIGHT)),
+				'actuel' =>
+					_T('info_largeur_vignette',
+						array('largeur_vignette' => $size[0],
+						'hauteur_vignette' => $size[1]))
+			)));
+		}
+		@rename ($f, _DIR_DOC . $dest . ".$type");
+	}
+	else {
+		@unlink ($f);
+		check_upload_error(6,
+			_T('info_logo_format_interdit',
+			array ('formats' => 'GIF, JPG, PNG'))
+		);
+	}
 }
 
-function ajout_doc_s($image, $image_name, $mode, $forcer_document, $id_document, $hash, $error=0) {
 
-	if (check_upload_error($error)) return;
+function effacer_logo($nom) {
+	if (!strstr($nom, ".."))
+		@unlink(_DIR_IMG . $nom);
+}
+
 
-	$mode = ($forcer_document == 'oui' ? "document" : $mode);
 
-	if (!is_dir($image_name)) {
-		ajout_doc($image_name,
-			$image,
-			$mode,
-			$id_document);
-	} else {
+//
+// Creation automatique de vignette
+//
+
+// Tester nos capacites
+function tester_vignette ($test_vignette) {
+	global $djpeg_command, $cjpeg_command, $pnmscale_command;
+	// verifier les formats acceptes par GD
+	if ($test_vignette == "gd1") {
+		$gd_formats = Array();
+		if (function_exists('ImageCreateFromJPEG')) {
+			$srcImage = @ImageCreateFromJPEG(_DIR_IMG . "test.jpg");
+			if ($srcImage) {
+				$gd_formats[] = "jpg";
+				ImageDestroy( $srcImage );
+			}
+		}
+		if (function_exists('ImageCreateFromGIF')) {
+			$srcImage = @ImageCreateFromGIF(_DIR_IMG . "test.gif");
+			if ($srcImage) {
+				$gd_formats[] = "gif";
+				ImageDestroy( $srcImage );
+			}
+		}
+		if (function_exists('ImageCreateFromPNG')) {
+			$srcImage = @ImageCreateFromPNG(_DIR_IMG . "test.png");
+			if ($srcImage) {
+				$gd_formats[] = "png";
+				ImageDestroy( $srcImage );
+			}
+		}
+
+		if ($gd_formats) $gd_formats = join(",", $gd_formats);
+		ecrire_meta("gd_formats", $gd_formats);
+		ecrire_metas();
+	}
+	// verifier les formats netpbm
+	else if ($test_vignette == "netpbm") {
+		$netpbm_formats= Array();
+
+		$jpegtopnm_command = str_replace("pnmscale",
+			"jpegtopnm", $pnmscale_command);
+		$pnmtojpeg_command = str_replace("pnmscale",
+			"pnmtojpeg", $pnmscale_command);
+
+		$vignette = _DIR_IMG . "test.jpg";
+		$dest = _DIR_IMG . "test-jpg.jpg";
+		$commande = "$jpegtopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest";
+		spip_log($commande);
+		exec($commande);
+		if ($taille = @getimagesize($dest)) {
+			if ($taille[1] == 10) $netpbm_formats[] = "jpg";
+		}
+		$giftopnm_command = ereg_replace("pnmscale", "giftopnm", $pnmscale_command);
+		$pnmtojpeg_command = ereg_replace("pnmscale", "pnmtojpeg", $pnmscale_command);
+		$vignette = _DIR_IMG . "test.gif";
+		$dest = _DIR_IMG . "test-gif.jpg";
+		$commande = "$giftopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest";
+		spip_log($commande);
+		exec($commande);
+		if ($taille = @getimagesize($dest)) {
+			if ($taille[1] == 10) $netpbm_formats[] = "gif";
+		}
+
+		$pngtopnm_command = ereg_replace("pnmscale", "pngtopnm", $pnmscale_command);
+		$vignette = _DIR_IMG . "test.png";
+		$dest = _DIR_IMG . "test-gif.jpg";
+		$commande = "$pngtopnm_command $vignette | $pnmscale_command -width 10 | $cjpeg_command -outfile $dest";
+		spip_log($commande);
+		exec($commande);
+		if ($taille = @getimagesize($dest)) {
+			if ($taille[1] == 10) $netpbm_formats[] = "png";
+		}
+		
+
+		if ($netpbm_formats) $netpbm_formats = join(",", $netpbm_formats);
+		ecrire_meta("netpbm_formats", $netpbm_formats);
+		ecrire_metas();
+	}
+
+	// et maintenant envoyer la vignette de tests
+	if (ereg("^(gd1|gd2|imagick|convert|netpbm)$", $test_vignette)) {
+		include_ecrire('inc_logos.php3');
+		//$taille_preview = lire_meta("taille_preview");
+		if ($taille_preview < 10) $taille_preview = 120;
+		if ($preview = creer_vignette(_DIR_IMG . 'test_image.jpg', $taille_preview, $taille_preview, 'jpg', '', "test_$test_vignette", $test_vignette, true))
+
+			return ($preview['fichier']);
+	}
+	return '';
+}
+
+// Creation
+function creer_fichier_vignette($vignette, $test_cache_only=false) {
+	if ($vignette && lire_meta("creer_preview") == 'oui') {
+		eregi('\.([a-z0-9]+)$', $vignette, $regs);
+		$ext = $regs[1];
+		$taille_preview = lire_meta("taille_preview");
+		if ($taille_preview < 10) $taille_preview = 120;
+		include_ecrire('inc_logos.php3');
+
+		if ($preview = creer_vignette($vignette, $taille_preview, $taille_preview, $ext, 'vignettes', basename($vignette).'-s', 'AUTO', false, $test_cache_only))
+		{
+			inserer_vignette_base($vignette, $preview['fichier']);
+			return $preview['fichier'];
+		}
 		include_ecrire('inc_documents.php3');
-		$fichiers = fichiers_upload($image_name);
-
-		while (list(,$f) = each($fichiers)) {
-			if (ereg("\.([^.]+)$", $f, $match)) {
-				$ext = strtolower($match[1]);
-				if ($ext == 'jpeg')
-					$ext = 'jpg';
-				$r = spip_query("SELECT extension FROM spip_types_documents WHERE extension='$ext'" . ($inclus ? " AND inclus='$inclus'" : ''));
-				if (spip_fetch_array($r))
-					ajout_doc($f, $f, $mode, false);
+		return vignette_par_defaut($ext ? $ext : 'txt', false);
+	}
+}
+
+// Effacer un doc (et sa vignette)
+function supprime_document_et_vignette($doc_supp) {
+
+	$result = spip_query("SELECT id_vignette, fichier
+		FROM spip_documents
+		WHERE id_document=$doc_supp");
+	if ($row = spip_fetch_array($result)) {
+		$fichier = $row['fichier'];
+		$id_vignette = $row['id_vignette'];
+		spip_query("DELETE FROM spip_documents
+			WHERE id_document=$doc_supp");
+		spip_query("UPDATE spip_documents SET id_vignette=0
+			WHERE id_vignette=$doc_supp");
+		spip_query("DELETE FROM spip_documents_articles
+			WHERE id_document=$doc_supp");
+		spip_query("DELETE FROM spip_documents_rubriques
+			WHERE id_document=$doc_supp");
+		spip_query("DELETE FROM spip_documents_breves
+			WHERE id_document=$doc_supp");
+		@unlink($fichier);
+
+		if ($id_vignette > 0) {
+			$query = "SELECT id_vignette, fichier FROM spip_documents
+				WHERE id_document=$id_vignette";
+			$result = spip_query($query);
+			if ($row = spip_fetch_array($result)) {
+				$fichier = $row['fichier'];
+				@unlink($fichier);
 			}
+			spip_query("DELETE FROM spip_documents
+				WHERE id_document=$id_vignette");
+			spip_query("DELETE FROM spip_documents_articles
+				WHERE id_document=$id_vignette");
+			spip_query("DELETE FROM spip_documents_rubriques
+				WHERE id_document=$id_vignette");
+			spip_query("DELETE FROM spip_documents_breves
+				WHERE id_document=$id_vignette");
 		}
+	}
+}
+
 
-# détruire le repertoire de deballage
-		if ($tmp_dir) effacer_repertoire_temporaire($tmp_dir);
+
+/////////////////////////////////////////////////////////////////////
+//
+// Faire tourner une image
+//
+function gdRotate ($imagePath,$rtt){
+	if(preg_match("/\.(png)/i", $imagePath))
+		$src_img=ImageCreateFromPNG($imagePath);
+	else if(preg_match("/\.(jpg)/i", $imagePath))
+		$src_img=ImageCreateFromJPEG($imagePath);
+	else if(preg_match("/\.(bmp)/i", $imagePath))
+		$src_img=ImageCreateFromWBMP($imagePath);
+	$size=@getimagesize($imagePath);
+
+	// Sous GD2 : ImageCreateTrueColor
+	$process = lire_meta('image_process');
+	if ($process == "gd2")
+		$dst_img=ImageCreateTrueColor($size[1],$size[0]);
+	else
+		$dst_img=ImageCreate($size[1],$size[0]);
+
+	if($rtt==90){
+		$t=0;
+		$b=$size[1]-1;
+		while($t<=$b){
+			$l=0;
+			$r=$size[0]-1;
+			while($l<=$r){
+				imagecopy($dst_img,$src_img,$t,$r,$r,$b,1,1);
+				imagecopy($dst_img,$src_img,$t,$l,$l,$b,1,1);
+				imagecopy($dst_img,$src_img,$b,$r,$r,$t,1,1);
+				imagecopy($dst_img,$src_img,$b,$l,$l,$t,1,1);
+				$l++;
+				$r--;
+			}
+			$t++;
+			$b--;
+		}
+	}
+	elseif($rtt==-90){
+		$t=0;
+		$b=$size[1]-1;
+		while($t<=$b){
+			$l=0;
+			$r=$size[0]-1;
+			while($l<=$r){
+				imagecopy($dst_img,$src_img,$t,$l,$r,$t,1,1);
+				imagecopy($dst_img,$src_img,$t,$r,$l,$t,1,1);
+				imagecopy($dst_img,$src_img,$b,$l,$r,$b,1,1);
+				imagecopy($dst_img,$src_img,$b,$r,$l,$b,1,1);
+				$l++;
+				$r--;
+			}
+			$t++;
+			$b--;
+		}
 	}
+	ImageDestroy($src_img);
+	ImageInterlace($dst_img,0);
+	ImageJPEG($dst_img,$imagePath);
 }
 
-function effacer_repertoire_temporaire($nom) {
-	$d = opendir($nom);
-	while ($f = readdir($d)) {
-		if (is_file($f = "$nom/$f")) @unlink($f);
+function tourner_document($var_rot, $doc_rotate, $convert_command) {
+	
+	$var_rot = intval($var_rot);
+
+	$query = "SELECT id_vignette, fichier FROM spip_documents WHERE id_document=$doc_rotate";
+	$result = spip_query($query);
+	if ($row = spip_fetch_array($result)) {
+		$id_vignette = $row['id_vignette'];
+		$image = $row['fichier'];
+
+		$process = lire_meta('image_process');
+
+		 // imagick (php4-imagemagick)
+		 if ($process == 'imagick') {
+			$handle = imagick_readimage($image);
+			imagick_rotate($handle, $var_rot);
+			imagick_write($handle, $image);
+			if (!@file_exists($image)) return;	// echec imagick
 		}
-	@rmdir($nom);
+		else if ($process == "gd2") { // theoriquement compatible gd1, mais trop forte degradation d'image
+			if ($var_rot == 180) { // 180 = 90+90
+				gdRotate ($image, 90);
+				gdRotate ($image, 90);
+			} else {
+				gdRotate ($image, $var_rot);
+			}
+		}
+		else if ($process = "convert") {
+			$commande = "$convert_command -rotate $var_rot ./"
+				. escapeshellcmd($image).' ./'.escapeshellcmd($image);
+#			spip_log($commande);
+			exec($commande);
+		}
+
+		$size_image = @getimagesize($image);
+		$largeur = $size_image[0];
+		$hauteur = $size_image[1];
+
+		if ($id_vignette > 0) {
+			creer_fichier_vignette($image);
+		}
+
+		spip_query("UPDATE spip_documents SET largeur=$largeur, hauteur=$hauteur WHERE id_document=$doc_rotate");
+
+	}
 }
 
 ?>
diff --git a/ecrire/inc_logos.php3 b/ecrire/inc_logos.php3
index 8daefbbc3970ce95ff56f57e29c8e5881328d675..3ebc555b2fc9f37543a43f76b23e9a5e6fa6055f 100644
--- a/ecrire/inc_logos.php3
+++ b/ecrire/inc_logos.php3
@@ -78,22 +78,25 @@ function resize_logo($limage, $maxi=170) {
 }
 
 
-function afficher_boite_logo($logo, $survol, $texteon, $texteoff) {
+
+function afficher_boite_logo($type, $id_objet, $id, $texteon, $texteoff) {
 	global $options, $spip_display;
 
+	$logon = $type.'on'.$id;
+	$logoff = $type.'off'.$id;
 
 	if ($spip_display != 4) {
 	
 		echo "<p>";
 		debut_cadre_relief("image-24.gif");
 		echo "<div class='verdana1' style='text-align: center;'>";
-		$desc = decrire_logo($logo);
-		afficher_logo($logo, $texteon, $desc);
+		$desc = decrire_logo($logon);
+		afficher_logo($logon, $texteon, $desc, $id_objet, $id);
 
 		if ($desc) {
 			echo "<br /><br />";
-			$desc = decrire_logo($survol);
-			afficher_logo($survol, $texteoff, $desc);   
+			$desc = decrire_logo($logoff);
+			afficher_logo($logoff, $texteoff, $desc, $id_objet, $id);
 		}
 	
 		echo "</div>";
@@ -103,8 +106,8 @@ function afficher_boite_logo($logo, $survol, $texteon, $texteoff) {
 }
 
 
-function afficher_logo($racine, $titre, $logo) {
-	global $id_article, $id_rubrique, $id_breve, $id_auteur, $id_mot, $id_syndic, $connect_id_auteur;
+function afficher_logo($racine, $titre, $logo, $id_objet, $id) {
+	global $connect_id_auteur;
 	global $couleur_foncee, $couleur_claire;
 	global $clean_link;
 
@@ -126,13 +129,8 @@ function afficher_logo($racine, $titre, $logo) {
 		echo debut_block_invisible(md5($titre));
 		echo $taille;
 		echo "\n<br />[<a href='../spip_image.php3?";
-		$elements = array('id_article', 'id_breve', 'id_syndic', 'id_rubrique', 'id_mot', 'id_auteur');
-		while (list(,$element) = each ($elements)) {
-			if ($$element) {
-				echo $element.'='.$$element.'&';
-			}
-		}
-		echo "image_supp=$fichier&hash_id_auteur=$connect_id_auteur&id_auteur=$id_auteur&hash=$hash&redirect=$redirect'>"._T('lien_supprimer')."</A>]";
+		echo "$id_objet=$id&";
+		echo "image_supp=$fichier&hash_id_auteur=$connect_id_auteur&hash=$hash&redirect=$redirect'>"._T('lien_supprimer')."</A>]";
 		echo fin_block();
 		echo "</center></p>";
 	}
@@ -140,14 +138,10 @@ function afficher_logo($racine, $titre, $logo) {
 		$hash = calculer_action_auteur("ajout_logo $racine");
 		echo debut_block_invisible(md5($titre));
 
-		echo "\n\n<FORM ACTION='../spip_image.php3' METHOD='POST' ENCTYPE='multipart/form-data'>";
+		echo "\n\n<FORM ACTION='../spip_image.php3' METHOD='POST'
+			ENCTYPE='multipart/form-data'>";
 		echo "\n<INPUT NAME='redirect' TYPE=Hidden VALUE='$redirect'>";
-		if ($id_auteur > 0) echo "\n<INPUT NAME='id_auteur' TYPE=Hidden VALUE='$id_auteur'>";
-		if ($id_article > 0) echo "\n<INPUT NAME='id_article' TYPE=Hidden VALUE='$id_article'>";
-		if ($id_breve > 0) echo "\n<INPUT NAME='id_breve' TYPE=Hidden VALUE='$id_breve'>";
-		if ($id_mot > 0) echo "\n<INPUT NAME='id_mot' TYPE=Hidden VALUE='$id_mot'>";
-		if ($id_syndic > 0) echo "\n<INPUT NAME='id_syndic' TYPE=Hidden VALUE='$id_syndic'>";
-		if ($id_rubrique > 0) echo "\n<INPUT NAME='id_rubrique' TYPE=Hidden VALUE='$id_rubrique'>";
+		echo "\n<INPUT NAME='$id_objet' TYPE=Hidden VALUE='$id'>";
 		echo "\n<INPUT NAME='hash_id_auteur' TYPE=Hidden VALUE='$connect_id_auteur'>";
 		echo "\n<INPUT NAME='hash' TYPE=Hidden VALUE='$hash'>";
 		echo "\n<INPUT NAME='ajout_logo' TYPE=Hidden VALUE='oui'>";
diff --git a/ecrire/inc_version.php3 b/ecrire/inc_version.php3
index 4955c27c665803962bc0543840698f72d3abd693..f6e67be1aa9ccf52e4a51458abdca828e128fe8a 100644
--- a/ecrire/inc_version.php3
+++ b/ecrire/inc_version.php3
@@ -400,7 +400,7 @@ define_once('_AUTH_USER_FILE', '.htpasswd');
 $spip_version = 1.810;
 
 // version de spip
-$spip_version_affichee = "1.8 beta 3 CVS";
+$spip_version_affichee = "1.8 beta 4 CVS";
 
 // version de spip / tag cvs
 if (ereg('Name: v(.*) ','$Name$', $regs)) $spip_version_affichee = $regs[1];
@@ -779,7 +779,7 @@ class Link {
 				if (!preg_match('/^('.
 				(!_DIR_RESTREINT ?
 					'|lang|set_options|set_couleur|set_disp|set_ecran':
-					'var_mode')
+					'var_mode|show_docs')
 				. ')$/i', $name)) {
 					if (is_array($value))
 						$this->arrays[$name] = $value;
diff --git a/ecrire/mots_edit.php3 b/ecrire/mots_edit.php3
index a235a2bc07e38533d0d1bdd4b0d9d6c64fc5d5ea..ee1d971249df520cb20d870f59aed0f8311693e9 100644
--- a/ecrire/mots_edit.php3
+++ b/ecrire/mots_edit.php3
@@ -122,11 +122,9 @@ echo "</center>";
 // Logos du mot-clef
 //
 
-$arton = "moton$id_mot";
-$artoff = "motoff$id_mot";
-
 if ($id_mot > 0 AND $connect_statut == '0minirezo')
-	afficher_boite_logo($arton, $artoff, _T('logo_mot_cle').aide("breveslogo"), _T('logo_survol'));
+	afficher_boite_logo('mot', 'id_mot', $id_mot,
+	_T('logo_mot_cle').aide("breveslogo"), _T('logo_survol'));
 
 
 //
diff --git a/ecrire/naviguer.php3 b/ecrire/naviguer.php3
index 7616c5b11fc9bb8d82c4a7a619dff5bd81ce45e1..2de8199f3d51ab07715cd93caad903dfa05c648c 100644
--- a/ecrire/naviguer.php3
+++ b/ecrire/naviguer.php3
@@ -331,14 +331,14 @@ if ($spip_display != 4) {
 	// Logos de la rubrique
 	//
 	
-	$rubon = "rubon$id_rubrique";
-	$ruboff = "ruboff$id_rubrique";
-	
 	if ($connect_statut == '0minirezo' AND acces_rubrique($id_rubrique)) {
-		if ($id_rubrique > 0)
-			afficher_boite_logo($rubon, $ruboff, _T('logo_rubrique')." ".aide ("rublogo"), _T('logo_survol'));
+		if ($id_rubrique)
+			afficher_boite_logo('rub', 'id_rubrique', $id_rubrique,
+			_T('logo_rubrique')." ".aide ("rublogo"), _T('logo_survol'));
 		else
-			afficher_boite_logo($rubon, $ruboff, _T('logo_standard_rubrique')." ".aide ("rublogo"), _T('logo_survol'));
+			afficher_boite_logo('rub', 'id_rubrique', 0,
+			_T('logo_standard_rubrique')." ".aide ("rublogo"),
+			_T('logo_survol'));
 	}
 	
 	
diff --git a/ecrire/sites.php3 b/ecrire/sites.php3
index 0a5252242f5c3c0d25938a708b3cc6afc0eae4ea..6e5d35f779abede40c847c583d0d2552bb2b2393 100644
--- a/ecrire/sites.php3
+++ b/ecrire/sites.php3
@@ -272,11 +272,8 @@ echo "<p><center>";
 	icone (_T('icone_voir_sites_references'), "sites_tous.php3", "site-24.gif","rien.gif");
 echo "</center>";
 
-$rubon = "siteon$id_syndic";
-$ruboff = "siteoff$id_syndic";
-
-if ($id_syndic>0 AND $flag_administrable)
-	afficher_boite_logo($rubon, $ruboff, _T('logo_site')." ".aide ("rublogo"), _T('logo_survol'));
+if ($id_syndic AND $flag_administrable)
+	afficher_boite_logo('site', 'id_syndic', $id_syndic, _T('logo_site')." ".aide ("rublogo"), _T('logo_survol'), 'site');
 
 
 debut_droite();
diff --git a/spip_image.php3 b/spip_image.php3
index da2b734595c995355ed9676216afae75a4411928..c9895d18981e6696c1ac474fb5cec02a1bc524ab 100644
--- a/spip_image.php3
+++ b/spip_image.php3
@@ -1,570 +1,247 @@
 <?php
 
+// Uploader un document, une image ou un logo,
+// supprimer cet element, creer les vignettes, etc.
+
 include ("ecrire/inc_version.php3");
-include_ecrire("inc_charsets.php3");
-include_ecrire("inc_meta.php3");
-include_ecrire("inc_admin.php3");
-include_ecrire("inc_abstract_sql.php3");
-include_ecrire('inc_presentation.php3'); # pour regler la langue en cas d'erreur
+include_ecrire('inc_presentation.php3');	# regler la langue en cas d'erreur
+include_ecrire('inc_getdocument.php3');		# diverses fonctions de ce fichier
+include_ecrire("inc_charsets.php3");		# pour le nom de fichier
+include_ecrire("inc_meta.php3");			# ne pas faire confiance au cache
+											# (alea_ephemere a peut-etre change)
+include_ecrire("inc_admin.php3");			# verifier_action_auteur
+include_ecrire("inc_abstract_sql.php3");	# spip_insert
+include_ecrire('inc_documents.php3');		# fichiers_upload()
 
 
 // Recuperer les variables d'upload
 if (!$_FILES)
-$_FILES = &$HTTP_POST_FILES;
-if (is_array($_FILES))
+	$_FILES = &$HTTP_POST_FILES;
+if (!is_array($_FILES))
+	$_FILES = array();
 foreach ($_FILES as $id => $file) {
 	if ($file['error'] == 4 /* UPLOAD_ERR_NO_FILE */)
 		unset ($_FILES[$id]);
 }
 
 
-function effacer_logo($nom) {
-	global $hash_id_auteur, $hash;
-
-	if ((!strstr($nom, "..")) AND
-	    verifier_action_auteur("supp_logo $nom", $hash, $hash_id_auteur))
-		@unlink(_DIR_IMG . $nom);
-}
-
-function tester_vignette ($test_vignette) {
-	global $djpeg_command, $cjpeg_command, $pnmscale_command;
-	// verifier les formats acceptes par GD
-	if ($test_vignette == "gd1") {
-		$gd_formats = Array();
-		if (function_exists('ImageCreateFromJPEG')) {
-			$srcImage = @ImageCreateFromJPEG(_DIR_IMG . "test.jpg");
-			if ($srcImage) {
-				$gd_formats[] = "jpg";
-				ImageDestroy( $srcImage );
-			}
-		}
-		if (function_exists('ImageCreateFromGIF')) {
-			$srcImage = @ImageCreateFromGIF(_DIR_IMG . "test.gif");
-			if ($srcImage) {
-				$gd_formats[] = "gif";
-				ImageDestroy( $srcImage );
-			}
-		}
-		if (function_exists('ImageCreateFromPNG')) {
-			$srcImage = @ImageCreateFromPNG(_DIR_IMG . "test.png");
-			if ($srcImage) {
-				$gd_formats[] = "png";
-				ImageDestroy( $srcImage );
-			}
-		}
-
-		if ($gd_formats) $gd_formats = join(",", $gd_formats);
-		ecrire_meta("gd_formats", $gd_formats);
-		ecrire_metas();
-	}
-	// verifier les formats netpbm
-	else if ($test_vignette == "netpbm") {
-		$netpbm_formats= Array();
-
-		$jpegtopnm_command = ereg_replace("pnmscale", "jpegtopnm", $pnmscale_command);
-		$pnmtojpeg_command = ereg_replace("pnmscale", "pnmtojpeg", $pnmscale_command);
-
-		$vignette = _DIR_IMG . "test.jpg";
-		$dest = _DIR_IMG . "test-jpg.jpg";
-		exec("$jpegtopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest");
-		if ($taille = @getimagesize($dest)) {
-			if ($taille[1] == 10) $netpbm_formats[] = "jpg";
-		}	
-		
-		$giftopnm_command = ereg_replace("pnmscale", "giftopnm", $pnmscale_command);
-		$pnmtojpeg_command = ereg_replace("pnmscale", "pnmtojpeg", $pnmscale_command);
-		$vignette = _DIR_IMG . "test.gif";
-		$dest = _DIR_IMG . "test-gif.jpg";
-		exec("$giftopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest");
-		if ($taille = @getimagesize($dest)) {
-			if ($taille[1] == 10) $netpbm_formats[] = "gif";
-		}
-
-		$pngtopnm_command = ereg_replace("pnmscale", "pngtopnm", $pnmscale_command);
-		$vignette = _DIR_IMG . "test.png";
-		$dest = _DIR_IMG . "test-gif.jpg";
-		exec("$pngtopnm_command $vignette | $pnmscale_command -width 10 | $cjpeg_command -outfile $dest");
-		if ($taille = @getimagesize($dest)) {
-			if ($taille[1] == 10) $netpbm_formats[] = "png";
-		}
-		
-
-		if ($netpbm_formats) $netpbm_formats = join(",", $netpbm_formats);
-		ecrire_meta("netpbm_formats", $netpbm_formats);
-		ecrire_metas();
-	}
-
-	// et maintenant envoyer la vignette de tests
-	if (ereg("^(gd1|gd2|imagick|convert|netpbm)$", $test_vignette)) {
-		include_ecrire('inc_logos.php3');
-		//$taille_preview = lire_meta("taille_preview");
-		if ($taille_preview < 10) $taille_preview = 120;
-		if ($preview = creer_vignette(_DIR_IMG . 'test_image.jpg', $taille_preview, $taille_preview, 'jpg', '', "test_$test_vignette", $test_vignette, true))
-
-			return ($preview['fichier']);
-	}
-	return '';
-}
+// Si on est en mode 'document', les images doivent etre installees
+// comme documents dans le portfolio
+if ($forcer_document) $mode = 'document';
 
 
 //
-// Deplacer un fichier
+// Le switch principal : quelle est l'action demandee
 //
 
-function deplacer_fichier_upload($source, $dest) {
-	// Securite
-	if (strstr($dest, "..")) {
-		exit;
-	}
-
-
-	$ok = @copy($source, $dest);
-	if (!$ok) $ok = @move_uploaded_file($source, $dest);
-	if ($ok)
-		@chmod($dest, 0666);
-	else {
-		$f = @fopen($dest,'w');
-		if ($f)
-			fclose ($f);
-		else {
-			redirige_par_entete("spip_test_dirs.php3?test_dir=".
-					    dirname($dest));
-		}
-		@unlink($dest);
-	}
-
-	return $ok;
-}
 
-// Erreurs d'upload
-// renvoie false si pas d'erreur
-// et true si erreur = pas de fichier
-// pour les autres erreurs affiche le message d'erreur et meurt
-function check_upload_error($error, $msg='') {
-	switch ($error) {
-		case 0:
-			return false;
-		case 4: /* UPLOAD_ERR_NO_FILE */
-			return true;
-
-		# on peut affiner les differents messages d'erreur
-		case 1: /* UPLOAD_ERR_INI_SIZE */
-			$msg = _T('upload_limit',
-			array('max' => ini_get('upload_max_filesize')));
-			break;
-		case 2: /* UPLOAD_ERR_FORM_SIZE */
-			$msg = _T('upload_limit',
-			array('max' => ini_get('upload_max_filesize')));
-			break;
-		case 3: /* UPLOAD_ERR_PARTIAL  */
-			$msg = _T('upload_limit',
-			array('max' => ini_get('upload_max_filesize')));
-			break;
-	}
-
-	spip_log ("erreur upload $error");
-
-	include_ecrire('inc_presentation.php3');
-	install_debut_html(_T('forum_titre_erreur'));
-	echo "<p>$msg</p>\n";
+// appel de config-fonction
+if ($test_vignette)
+	$retour_image = tester_vignette($test_vignette);
 
-	install_fin_html(_DIR_RESTREINT . $GLOBALS['retour']);
-	exit;
+// Creation de vignette depuis le portfolio (ou autre)
+else if ($vignette) {
+	if ($creer_vignette == 'oui' AND
+	verifier_action_auteur("vign $vignette",
+	$hash, $hash_id_auteur))
+		creer_fichier_vignette($vignette);
+	else
+		$retour_image = creer_fichier_vignette($vignette, true); # obsolete
 }
 
 
 //
-// Convertit le type numerique retourne par getimagesize() en extension fichier
+// Ajout d'un document ou d'une image
 //
+else if ($ajout_doc == 'oui') {
 
-function decoder_type_image($type, $strict = false) {
-	switch ($type) {
-	case 1:
-		return "gif";
-	case 2:
-		return "jpg";
-	case 3:
-		return "png";
-	case 4:
-		return $strict ? "" : "swf";
-	case 5:
-		return "psd";
-	case 6:
-		return "bmp";
-	case 7:
-	case 8:
-		return "tif";
-	default:
-		return "";
-	}
-}
+	// Autorisation ?
+	if (!verifier_action_auteur("ajout_doc", $hash, $hash_id_auteur))
+		die ('Interdit');
 
+	//
+	// Cas d'un fichier ou d'un repertoire installe dans ecrire/upload/
+	//
+	if ($_POST['image2']
+	AND !strstr($_POST['image2'], '..')
+	AND $_POST['ok_ftp']
+	) {
+		$upload = _DIR_TRANSFERT.$_POST['image2'];
+
+		// lire le repertoire upload et remplir $_FILES
+		if (is_dir($upload)) {
+			$fichiers = fichiers_upload($upload);
+
+			$_FILES = array();
+			foreach ($fichiers as $fichier) {
+				$_FILES[] = array (
+					'name' => basename($fichier),
+					'tmp_name' => $fichier
+				);
+			}
+		}
 
-//
-// Corrige l'extension du fichier dans quelques cas particuliers
-//
-
-function corriger_extension($ext) {
-	switch ($ext) {
-	case 'htm':
-		return 'html';
-	case 'jpeg':
-		return 'jpg';
-	case 'tiff':
-		return 'tif';
-	default:
-		return $ext;
+		// seul un fichier est demande
+		else
+			$_FILES = array(
+				array ('name' => basename($upload),
+				'tmp_name' => $upload)
+			);
 	}
-}
 
+	//
+	// Upload d'un ZIP
+	//
 
-//
-// Ajouter un logo
-//
-
-// $source = $_FILES[0]
-// $dest = arton12.xxx
-function ajout_logo($source, $dest) {
-	global $redirect_url, $hash_id_auteur, $hash, $num_img, $dossier_squelettes;
-
-	// Securite
-	if (!(verifier_action_auteur("ajout_logo $dest", $hash, $hash_id_auteur)
-	AND _DIR_DOC != $dossier_squelettes)) {
-		spip_log("interdiction ajout_logo($source, $dest)");
-		return;
-	}
-
-	// Intercepter une erreur d'upload
-	if (check_upload_error($source['error'])) return;
-
-	// analyse le type de l'image (on ne fait pas confiance au nom de
-	// fichier envoye par le browser : pour les Macs c'est plus sur)
-	$f =_DIR_DOC . $dest . '.tmp';
-	deplacer_fichier_upload($source['tmp_name'], $f);
-	$size = @getimagesize($f);
-	$type = decoder_type_image($size[2], true);
-	if ($type) {
-		$poids = filesize($f);
-		if ($poids > _LOGO_MAX_SIZE*1024) {
-			@unlink ($f);
-			check_upload_error(6,
-			_T('info_logo_max_poids',
-				array('maxi' => taille_en_octets(_LOGO_MAX_SIZE*1024),
-				'actuel' => taille_en_octets($poids))));
-		}
-		if (($size[0] > _LOGO_MAX_WIDTH)
-		OR ($size[1] > _LOGO_MAX_HEIGHT)) {
-			@unlink ($f);
-			check_upload_error(6, 
-			_T('info_logo_max_taille',
-				array(
-				'maxi' =>
-					_T('info_largeur_vignette',
-						array('largeur_vignette' => _LOGO_MAX_WIDTH,
-						'hauteur_vignette' => _LOGO_MAX_HEIGHT)),
-				'actuel' =>
-					_T('info_largeur_vignette',
-						array('largeur_vignette' => $size[0],
-						'hauteur_vignette' => $size[1]))
-			)));
-		}
-		@rename ($f, _DIR_DOC . $dest . ".$type");
-	}
-	else {
-		@unlink ($f);
-		check_upload_error(6,
-			_T('info_logo_format_interdit',
-			array ('formats' => 'GIF, JPG, PNG'))
+	// traiter la reponse de l'utilisateur
+	if (preg_match('@^IMG/zip/[^. ]+\.zip$@i', $_POST['source_zip'])) {
+		$_FILES = array(
+			array('name' => basename($_POST['source_zip']),
+				'tmp_name' => $_POST['source_zip'])
 		);
 	}
-}
 
-//
-// Faire tourner une image
-//
+	// traiter le zip si c'en est un tout seul
+	if (count($_FILES) == 1
+	AND $action_zip!='telquel') {
+		$desc = array_pop($_FILES); # recuperer la description
+		$_FILES = array($desc);
 
-//$imagePath - path to your image; function will save rotated image overwriting the old one
-//$rtt - should be 90 or -90 - cw/ccw
-function gdRotate($imagePath,$rtt){
-	if(preg_match("/\.(png)/i", $imagePath)) $src_img=ImageCreateFromPNG($imagePath);
-	elseif(preg_match("/\.(jpg)/i", $imagePath)) $src_img=ImageCreateFromJPEG($imagePath);
-	elseif(preg_match("/\.(bmp)/i", $imagePath)) $src_img=ImageCreateFromWBMP($imagePath);
-	$size=@getimagesize($imagePath);
-	//note: to make it work on GD 2.xx properly change ImageCreate to ImageCreateTrueColor
-
-	$process = lire_meta('image_process');
-	if ($process == "gd2") $dst_img=ImageCreateTrueColor($size[1],$size[0]);
-	else  $dst_img=ImageCreate($size[1],$size[0]);
-	if($rtt==90){
-		$t=0;
-		$b=$size[1]-1;
-		while($t<=$b){
-			$l=0;
-			$r=$size[0]-1;
-			while($l<=$r){
-				imagecopy($dst_img,$src_img,$t,$r,$r,$b,1,1);
-				imagecopy($dst_img,$src_img,$t,$l,$l,$b,1,1);
-				imagecopy($dst_img,$src_img,$b,$r,$r,$t,1,1);
-				imagecopy($dst_img,$src_img,$b,$l,$l,$t,1,1);
-				$l++;
-				$r--;
-			}
-			$t++;
-			$b--;
-		}
-	}
-	elseif($rtt==-90){
-		$t=0;
-		$b=$size[1]-1;
-		while($t<=$b){
-			$l=0;
-			$r=$size[0]-1;
-			while($l<=$r){
-				imagecopy($dst_img,$src_img,$t,$l,$r,$t,1,1);
-				imagecopy($dst_img,$src_img,$t,$r,$l,$t,1,1);
-				imagecopy($dst_img,$src_img,$b,$l,$r,$b,1,1);
-				imagecopy($dst_img,$src_img,$b,$r,$l,$b,1,1);
-				$l++;
-				$r--;
-			}
-			$t++;
-			$b--;
-		}
-	}
-	ImageDestroy($src_img);
-	ImageInterlace($dst_img,0);
-	ImageJPEG($dst_img,$imagePath);
-}
+		if (preg_match('/\.zip$/i', $desc['name'])
+		OR ($desc['type'] == 'application/zip')) {
 
-//
-// Creation automatique de vignette new style
-// Normalement le test est vérifié donc on ne rend rien sinon
-
-function creer_fichier_vignette($vignette, $test_cache_only=false) {
-	if ($vignette && lire_meta("creer_preview") == 'oui') {
-		eregi('\.([a-z0-9]+)$', $vignette, $regs);
-		$ext = $regs[1];
-		$taille_preview = lire_meta("taille_preview");
-		if ($taille_preview < 10) $taille_preview = 120;
-		include_ecrire('inc_logos.php3');
-
-		if ($preview = creer_vignette($vignette, $taille_preview, $taille_preview, $ext, 'vignettes', basename($vignette).'-s', 'AUTO', false, $test_cache_only))
-		{
-			inserer_vignette_base($vignette, $preview['fichier']);
-			return $preview['fichier'];
-		}
-		include_ecrire('inc_documents.php3');
-		return vignette_par_defaut($ext ? $ext : 'txt', false);
-	}
-}
-
-function supprime_document_et_vignette($doc_supp) {
-	global $hash_id_auteur, $hash;
-
-
-	// Securite
-	if (verifier_action_auteur("supp_doc $doc_supp", $hash, $hash_id_auteur)) {
-		$query = "SELECT id_vignette, fichier FROM spip_documents WHERE id_document=$doc_supp";
-		$result = spip_query($query);
-		if ($row = spip_fetch_array($result)) {
-			$fichier = $row['fichier'];
-			$id_vignette = $row['id_vignette'];
-			spip_query("DELETE FROM spip_documents WHERE id_document=$doc_supp");
-			spip_query("UPDATE spip_documents SET id_vignette=0 WHERE id_vignette=$doc_supp");
-			spip_query("DELETE FROM spip_documents_articles WHERE id_document=$doc_supp");
-			spip_query("DELETE FROM spip_documents_rubriques WHERE id_document=$doc_supp");
-			spip_query("DELETE FROM spip_documents_breves WHERE id_document=$doc_supp");
-			@unlink($fichier);
-			
-			if ($id_vignette > 0) {
-			  $query = "SELECT id_vignette, fichier FROM spip_documents WHERE id_document=$id_vignette";
-			  $result = spip_query($query);
-			  if ($row = spip_fetch_array($result)) {
-			    $fichier = $row['fichier'];
-			    @unlink($fichier);
-			  }
-			  spip_query("DELETE FROM spip_documents WHERE id_document=$id_vignette");
-			  spip_query("DELETE FROM spip_documents_articles WHERE id_document=$id_vignette");
-			  spip_query("DELETE FROM spip_documents_rubriques WHERE id_document=$id_vignette");
-			  spip_query("DELETE FROM spip_documents_breves WHERE id_document=$id_vignette");
+			// on pose le fichier dans le repertoire zip et on met
+			// a jour $_FILES (nota : copier_document n'ecrase pas
+			// un fichier avec lui-meme : ca autorise a boucler)
+			$zip = copier_document("zip",
+				$desc['name'],
+				$desc['tmp_name']
+			);
+			if (!$zip) die ('Erreur upload zip'); # pathologique
+			$desc['tmp_name'] = $zip;	# nouvel emplacement du fichier
+			$_FILES = array($desc);
+
+			// Est-ce qu'on sait le lire ?
+			require_once(_DIR_RESTREINT . 'pclzip.lib.php');
+			$archive = new PclZip($zip);
+			$contenu = verifier_compactes($archive);
+
+			// si non, on le force comme document
+			if (!$contenu) {
+				$forcer_document = 'oui';
 			}
-		}
-	}
-}
 
-function tourner_document($var_rot, $doc_rotate, $convert_command) {
-	global $hash_id_auteur, $hash;
-	// Securite
-	if (!verifier_action_auteur("rotate $doc_rotate", $hash, $hash_id_auteur)) {
-		return '';
-	}
-	
-	$var_rot = intval($var_rot);
-
-	$query = "SELECT id_vignette, fichier FROM spip_documents WHERE id_document=$doc_rotate";
-	$result = spip_query($query);
-	if ($row = spip_fetch_array($result)) {
-		$id_vignette = $row['id_vignette'];
-		$image = $row['fichier'];
-
-		$process = lire_meta('image_process');
-
-		 // imagick (php4-imagemagick)
-		 if ($process == 'imagick') {
-			$handle = imagick_readimage($image);
-			imagick_rotate($handle, $var_rot);
-			imagick_write($handle, $image);
-			if (!@file_exists($image)) return;	// echec imagick
-		}
-		else if ($process == "gd2") { // theoriquement compatible gd1, mais trop forte degradation d'image
-			if ($var_rot == 180) { // 180 = 90+90
-				gdRotate ($image, 90);
-				gdRotate ($image, 90);
-			} else {
-				gdRotate ($image, $var_rot);
+			// si le deballage est demande
+			else if ($action_zip == 'decompacter') {
+				// 1. on deballe
+				define('_tmp_dir', creer_repertoire_documents($hash));
+				$archive->extract(PCLZIP_OPT_PATH,
+					_tmp_dir,
+					PCLZIP_OPT_REMOVE_ALL_PATH);
+				// 2. on supprime le fichier temporaire
+				$contenu = verifier_compactes($archive);
+				@unlink($zip);
+
+				$_FILES = array();
+				foreach ($contenu as $fichier) {
+					$_FILES[] = array(
+						'name' => basename($fichier),
+						'tmp_name' => _tmp_dir.$fichier);
+				}
 			}
-		}
-		else if ($process = "convert") {
-			$commande = "$convert_command -rotate $var_rot ./"
-				. escapeshellcmd($image).' ./'.escapeshellcmd($image);
-#			spip_log($commande);
-			exec($commande);
-		}
-
-		$size_image = @getimagesize($image);
-		$largeur = $size_image[0];
-		$hauteur = $size_image[1];
-
-		if ($id_vignette > 0) {
-			creer_fichier_vignette($image);
-		}
-
-		spip_query("UPDATE spip_documents SET largeur=$largeur, hauteur=$hauteur WHERE id_document=$doc_rotate");
-
-	}
-}
 
-
-//
-// Le switch principal : quelle est l'action demandee
-//
-
-
-// appel de config-fonction
-if ($test_vignette)
-	$redirect = tester_vignette($test_vignette);
-
-// appels de inc_logo
-else if ($vignette) {
-	if ($creer_vignette == 'oui' AND
-	verifier_action_auteur("vign $vignette", $hash, $hash_id_auteur)) {
-		creer_fichier_vignette($vignette);
-		$retour = $redirect;
-		$redirect = '';
-	}
-	else
-		$redirect = creer_fichier_vignette($vignette, true); # methode obsolete
-}
-else {
-	$retour = $redirect;
-	$redirect = '';
-
-	//
-	// Ajout d'un document ou d'une image
-	//
-	if ($ajout_doc == 'oui') {
-		include_ecrire('inc_getdocument.php3');
-
-		// cas d'un fichier ou d'un repertoire installe dans ecrire/upload/
-		if ($_POST['image2'] AND $_POST['ok_ftp']) {
-			$_FILES = array(
-				array (
-					'name' => _DIR_TRANSFERT . $image2,
-					'tmp_name' => _DIR_TRANSFERT . $image2
-				)
-			);
-		} 
-
-		// Upload d'un ZIP : retour du formulaire demandant
-		/// quelle action il fallait effectuer
-		if ($_POST['action_zip']) {
-			if (!preg_match('@^IMG/zip/[^/]+\.zip$@', $_POST['image_name']))
-				return;
-			$_FILES = array(
-				array (
-					'name' => $_POST['image_name'],
-					'tmp_name' => $_POST['image_name']
-				)
-			);
-		} 
-
-		// Traiter les fichiers uploades
-		if (is_array($_FILES))
-		foreach ($_FILES as $file) {
-			// ajout d'un doc normal
-			if (!eregi("\.zip$",$file['name']) OR count($_FILES) > 1)
-				ajout_doc_s($file['tmp_name'], $file['name'], $mode, $forcer_document, $id_document, $hash, $file['error']);
-			else
-			// ajout d'un doc au format zip
-			{
-				// bizarre: clean_link ne recupere pas les variables
+			// sinon on demande une reponse
+			else {
 				$link = new Link('spip_image.php3');
-				$link->addVar("ajout_doc", "oui");
-				$link->addVar("redirect", $retour);
-				$link->addVar('id_document', $id_document);
+				$link->addVar('ajout_doc', 'oui');
+				$link->addVar('redirect', $redirect);
 				$link->addVar('id_article', $id_article);
 				$link->addVar('mode', $mode);
 				$link->addVar('type', $type);
 				$link->addVar('hash', $hash);
 				$link->addVar('hash_id_auteur', $hash_id_auteur);
-				ajout_doc_zip($file['tmp_name'], $file['name'], $mode,
-					$forcer_document, $action_zip, $id_document, $hash, $link);
+				$link->addVar('source_zip', $zip);
+				afficher_compactes($desc, $contenu, $link);
+				exit;
 			}
-		}	// foreach $_FILES
+		}
 	}
+	// Fin du bloc ZIP
+
+
+	//
+	// Traiter la liste des fichiers
+	//
+	$documents_actifs = array();
+
+	foreach ($_FILES as $file) {
+
+		// afficher l'erreur 'fichier trop gros' ou autre
+		check_upload_error($file['error']);
+
+		spip_log ("ajout du document ".$file['name'].", $mode ($type $id_article)");
+		ajouter_un_document (
+			$file['tmp_name'],	# le fichier sur le serveur (/var/tmp/xyz34)
+			$file['name'],		# son nom chez le client (portequoi.pdf)
+			$type,				# lie a un article ou  une rubrique ?
+			$id_article,		# identifiant de l'article (ou rubrique) lie
+			$mode,				# 'vignette' => vignette personnalisee
+			$id_document,		# pour une vignette, l'id_document de maman
+			$documents_actifs	# tableau des id_document "actifs" (par ref)
+		);
+	}	// foreach $_FILES
+
+	// Nettoyer le repertoire temporaire d'extraction des fichiers
+	if (defined('_tmp_dir'))
+		effacer_repertoire_temporaire(_tmp_dir);
+}
 
-	// Ajout d'un logo
-	else if ($ajout_logo == "oui")
-		ajout_logo($_FILES['image'], $logo);
+// Ajout d'un logo
+else if ($ajout_logo == "oui" and $logo) {
+	if ($desc = array_pop($_FILES)
+	AND verifier_action_auteur("ajout_logo $logo",
+	$hash, $hash_id_auteur))
+		ajout_logo($desc, $logo);
+}
 
-	// Suppression d'un logo
-	else if ($image_supp)
+// Suppression d'un logo
+else if ($image_supp) {
+	if (verifier_action_auteur("supp_logo $nom",
+	$hash, $hash_id_auteur))
 		effacer_logo($image_supp);
+}
 
-	// Suppression d'un document et de sa vignette
-	else if ($doc_supp)
+// Suppression d'un document et de sa vignette
+else if ($doc_supp) {
+	if (verifier_action_auteur("supp_doc $doc_supp",
+	$hash, $hash_id_auteur))
 		supprime_document_et_vignette($doc_supp);
+}
 
-	// Rotation d'une image
-	else if ($doc_rotate)
+// Rotation d'une image
+else if ($doc_rotate) {
+	if (verifier_action_auteur("rotate $doc_rotate",
+	$hash, $hash_id_auteur))
 		tourner_document($var_rot, $doc_rotate, $convert_command);
 }
 
 
-
 //
-// Fin et retour
+// Retour a l'envoyeur
 //
-if (!($redirect)) {
-	if ($_POST) $vars = $_POST;
-	else $vars = $_GET;
-	$redirect = $vars["redirect"];
+
+// si nous sommes diriges vers une vignette
+if ($retour_image) {
+	redirige_par_entete($redirect);
+
+} else {
 	$link = new Link(_DIR_RESTREINT_ABS . $redirect);
-	reset($vars);
-	while (list ($key, $val) = each ($vars)) {
-	  if (!ereg("^(redirect|image.*|hash.*|ajout.*|doc.*|transformer.*|modifier_.*|ok|type|forcer_.*|var_rot|action_zip|mode|ok_.*)$", $key)) {
-	    $link->addVar($key, $val);
-	  }
+	if ($documents_actifs) {
+		$show_docs = join('-',$documents_actifs);
+		$link->addVar('show_docs',$show_docs);
 	}
-	if ($id_document)
-	  $link->addVar('id_document',$id_document);
-	if ($type == 'rubrique')
-	  $link->delVar('id_article');
-	
-	$redirect = $link->getUrl();
- }
 
-
-redirige_par_entete($redirect);
+	redirige_par_entete($link->getUrl());
+}
 
 ?>