From eda7a890979ccecf455bcca3ea58b24456af2e0b Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Fri, 22 Sep 2006 14:51:17 +0000
Subject: [PATCH] =?UTF-8?q?Un=20ajout=20oubli=C3=A9=20dans=20[7447],=20et?=
 =?UTF-8?q?=20un=20peu=20de=20m=C3=A9nage.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .gitattributes                  |   1 +
 ecrire/fragments/rechercher.php |  27 ++------
 ecrire/inc/discuter.php         |   2 +-
 ecrire/inc/documenter.php       | 112 ++++++++++++++++++++++++++++++++
 4 files changed, 119 insertions(+), 23 deletions(-)
 create mode 100644 ecrire/inc/documenter.php

diff --git a/.gitattributes b/.gitattributes
index c18c3e907d..f4a2263f60 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -424,6 +424,7 @@ ecrire/inc/cookie.php -text
 ecrire/inc/dater.php -text
 ecrire/inc/discuter.php -text
 ecrire/inc/distant.php -text
+ecrire/inc/documenter.php -text
 ecrire/inc/drapeau_edition.php -text
 ecrire/inc/editer_auteurs.php -text
 ecrire/inc/filtres_images.php -text
diff --git a/ecrire/fragments/rechercher.php b/ecrire/fragments/rechercher.php
index 2d4a6e3419..ca96434931 100644
--- a/ecrire/fragments/rechercher.php
+++ b/ecrire/fragments/rechercher.php
@@ -17,25 +17,10 @@ if (!defined("_ECRIRE_INC_VERSION")) return;
 // http://doc.spip.org/@fragments_rechercher_dist
 function fragments_rechercher_dist()
 {
-	global $flag_ob;
+		global $id, $exclus, $type, $rac;
 
-	if ($flag_ob) {			ob_start();		}
-	ajax_page_recherche();
-
-	if ($flag_ob) {
-			$a = ob_get_contents();
-			ob_end_clean();
-			return $a;
-	}
-}
-
-# Un moteur de recherche ?
-// http://doc.spip.org/@ajax_page_recherche
-function ajax_page_recherche()
-{
-	global $id, $exclus, $type, $rac;
-	$id = intval($id);
-	$exclus = intval($exclus);
+		$id = intval($id);
+		$exclus = intval($exclus);
 
 		include_spip('inc/texte');
 		$where = split("[[:space:]]+", $type);
@@ -112,13 +97,11 @@ function ajax_page_recherche()
 				
 		}
 		if ($ret)
-			echo $ret;
+			return $ret;
 		else
-			echo "<div style='padding: 5px; color: red;'><b>"
+			return "<div style='padding: 5px; color: red;'><b>"
 			.htmlentities($type)
 			."</b> :  "._T('avis_aucun_resultat')."</div>";
 
 }
-
-
 ?>
diff --git a/ecrire/inc/discuter.php b/ecrire/inc/discuter.php
index 893751f019..05a6d25655 100644
--- a/ecrire/inc/discuter.php
+++ b/ecrire/inc/discuter.php
@@ -64,7 +64,7 @@ function inc_discuter_dist($id_article, $flag, $debut=1)
 #				   " LIMIT $total_afficher OFFSET $debut" # PG
 
 	  $res = formulaire_discuter($forum, $res, $debut, $total_afficher, 'articles', "id_article=$id_article");
-  }
+  } else $res ='';
 
   return ($flag=='ajax') ? $res : "<div id='forum'>$res</div>";
 }
diff --git a/ecrire/inc/documenter.php b/ecrire/inc/documenter.php
new file mode 100644
index 0000000000..90958e963b
--- /dev/null
+++ b/ecrire/inc/documenter.php
@@ -0,0 +1,112 @@
+<?php
+
+/***************************************************************************\
+ *  SPIP, Systeme de publication pour l'internet                           *
+ *                                                                         *
+ *  Copyright (c) 2001-2006                                                *
+ *  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;
+
+// Affiche le portfolio et les documents lies a l'article (ou a la rubrique)
+// => Nouveau : au lieu de les ignorer, on affiche desormais avec un fond gris
+// les documents et images inclus dans le texte.
+
+// http://doc.spip.org/@afficher_portfolio
+function inc_documenter_dist(
+	$doc,		# tableau des documents ou numero de l'objet attachant
+	$type = "article",	# article ou rubrique ?
+	$ancre = 'portfolio',	# album d'images ou de documents ?
+	$flag_modif = false,	# a-t-on le droit de modifier ?
+	$couleur='',		# couleur des cases du tableau
+	$appelant =''		# pour le rappel (cf plugin)
+) {
+	global $couleur_claire, $spip_lang_left, $spip_lang_right;
+
+	if (is_int($doc)) {
+		if ($ancre == 'portfolio') {
+			$lies = spip_query("SELECT docs.*,l.id_$type FROM spip_documents AS docs, spip_documents_".$type."s AS l, spip_types_documents AS lestypes WHERE l.id_$type=$doc AND l.id_document=docs.id_document AND docs.mode='document' AND docs.id_type=lestypes.id_type AND lestypes.extension IN ('gif', 'jpg', 'png') ORDER BY 0+docs.titre, docs.date");
+			$couleur = $couleur_claire;
+		} else {
+			$lies = spip_query("SELECT docs.*,l.id_$type FROM spip_documents AS docs, spip_documents_".$type."s AS l,spip_types_documents AS lestypes WHERE l.id_$type=$doc AND l.id_document=docs.id_document AND docs.mode='document' AND docs.id_type=lestypes.id_type AND lestypes.extension NOT IN ('gif', 'jpg', 'png') ORDER BY 0+docs.titre, docs.date");
+			$couleur = '#aaaaaa';
+		}
+
+		$documents = array();
+		while ($document = spip_fetch_array($lies))
+			$documents[] = $document;
+	} else $documents = $doc;
+
+	if (!$documents) return '';
+	include_spip('inc/documents');
+	charger_generer_url();
+	// la derniere case d'une rangee
+	$bord_droit = ($ancre == 'portfolio' ? 2 : 1);
+	$case = 0;
+	$res = '';
+
+	foreach ($documents as $document) {
+		$id_document = $document['id_document'];
+
+		if (isset($document['script']))
+			$script = $document['script']; # pour plugin Cedric
+		else
+		  // ref a $exec inutilise en standard
+		  $script = $appelant ? $appelant : $GLOBALS['exec'];
+
+		$style = est_inclus($id_document) ? ' background-color: #cccccc;':'';
+
+		if (!$case)
+			$res .= "<tr style='border-top: 1px solid black;'>";
+		else if ($case == $bord_droit)
+			$style .= " border-$spip_lang_right: 1px solid $couleur;";
+		$res .= "\n<td  style='width:33%; text-align: $spip_lang_left; border-$spip_lang_left: 1px solid $couleur; border-bottom: 1px solid $couleur; $style' valign='top'>";
+
+		$res .= formulaire_tourner($id_document, $document, $script, $flag_modif, $type);
+
+		if ($flag_modif)
+		  $res .= formulaire_legender($id_document, $document, $script, $type, $document["id_$type"], $ancre);
+
+		if (isset($document['info']))
+			$res .= "<div class='verdana1'>".$document['info']."</div>";
+		$res .= "</td>\n";
+		$case++;
+				
+		if ($case > $bord_droit) {
+			  $case = 0;
+			  $res .= "</tr>\n";
+		}
+
+	}
+
+	// fermer la derniere ligne
+	if ($case) {
+		$res .= "<td style='border-$spip_lang_left: 1px solid $couleur;'>&nbsp;</td>";
+		$res .= "</tr>";
+	}
+
+	$s = ($ancre =='documents' ? '': '-');
+	if (is_int($doc)) {
+		$head = "\n<div id='$ancre'>&nbsp;</div>"
+		. "\n<div style='background-color: $couleur; padding: 4px; color: black; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px;' class='verdana2'>\n<b>".majuscules(_T("info_$ancre"))."</b></div>";
+
+		if (count($documents) > 3) {
+			$head .= "<div style='background-color: #dddddd; padding: 4px; color: black; text-align: right' class='arial1'>"
+			  . ajax_action_auteur('documenter', "$s$doc/$type", $GLOBALS['exec'], "id_$type=$doc&s=$s&type=$type",array(_L('Supprimer_tout')))
+			. "</div>\n";
+		}
+	} else $head = '';
+
+	$res = $head
+	. "\n<table width='100%' cellspacing='0' cellpadding='4'>"
+	. $res
+	. "</table>";	  
+
+	return ($flag_modif === 'ajax')
+	? $res
+	: ("<div id='documenter-$s$doc'>$res</div>");
+}
-- 
GitLab