From 426c88ffc037605e59eee6200f8750de0fac7e57 Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Sun, 16 Oct 2005 19:45:10 +0000
Subject: [PATCH] les auteurs, ca s'exporte beaucoup moins facilement que les
 articles, meme a l'OMC ils sont au courant

---
 ecrire/export.php3     | 89 ++++++------------------------------------
 ecrire/inc_export.php3 | 79 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 91 insertions(+), 77 deletions(-)

diff --git a/ecrire/export.php3 b/ecrire/export.php3
index 9cbc390687..76d32831f6 100644
--- a/ecrire/export.php3
+++ b/ecrire/export.php3
@@ -10,86 +10,23 @@
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
 \***************************************************************************/
 
-
 include ("inc_version.php3");
 
-include_ecrire ("inc_auth.php3");
-include_ecrire ("inc_export.php3");
-include_ecrire ("inc_admin.php3");
-include_ecrire ("inc_presentation.php3");
-
-// Liste un sommaire d'objets de n'importe quel type
-// a la condition d'etre publics et plus recents que $maj
-function liste_objets($result, $type) {
-	global $maj;
-	global $articles;
-	if ($result) while ($row = spip_fetch_array($result)) {
-		$t_id = $row["id_$type"];
-		$t_statut = $row["statut"];
-		$t_maj = mysql_timestamp_to_time($row["maj"]);
-		if ($t_maj > $maj && (!$t_statut || $t_statut == "publie")) {
-			echo "$type $t_id $t_maj\n";
-			if ($type == "article") $articles[]=$t_id;
-		}
-	}
-	spip_free_result($result);
-}
-
-// Liste un sommaire recursif de rubriques
-// a condition que la mise a jour soit plus recente que $maj
-function liste_rubriques($result) {
-	global $maj;
-	global $rubriques;
-	if ($result) while ($row=spip_fetch_array($result)) {
-		$id_rubrique = $row['id_rubrique'];
-		$id_parent = $row['id_parent'];
-		$titre = $row['titre'];
-		$descriptif = $row['descriptif'];
-		$texte = $row['texte'];
-		$rubrique_maj = mysql_timestamp_to_time($row["maj"]);
-		if ($rubrique_maj > $maj) {
-			echo "rubrique $id_rubrique $rubrique_maj\n";
-		}
-		$t_rubriques[] = $id_rubrique;
-	}
-	spip_free_result($result);
- 	if ($t_rubriques) {
- 		$t_rubriques = join(",", $t_rubriques);
- 		$rubriques[] = $t_rubriques;
- 		$query = "SELECT * FROM spip_rubriques WHERE id_parent IN ($t_rubriques)";
-		liste_rubriques(spip_query($query));
-	}
-}
-
+// prendre $var_* comme variables pour eviter les conflits avec les http_vars
 
+$var_nom = "export";
+$var_f = find_in_path('inc_' . $var_nom . '.php');
 
-Header("Content-Type: text/plain");
+if ($var_f) 
+  include($var_f);
+ // ATTENTION PHP3 ici
+elseif (file_exists($var_f = (_DIR_INCLUDE . 'inc_' . $var_nom . '.php3')))
+  include($var_f);
 
-if ($id_rubrique)
-	$query="SELECT * FROM spip_rubriques WHERE id_rubrique='$id_rubrique'";
+if (function_exists($var_nom))
+  $var_nom($id_rubrique, $maj);
+elseif (function_exists($var_f = $var_nom . "_dist"))
+  $var_f($id_rubrique, $maj);
 else
-	$query="SELECT * FROM spip_rubriques WHERE id_parent=0";
-
-liste_rubriques(spip_query($query));
-
-if ($rubriques) {
-	$rubriques = join(",", $rubriques);
-
-	$query = "SELECT id_article, statut, maj FROM spip_articles WHERE id_rubrique IN ($rubriques)";
-	liste_objets(spip_query($query), "article");
-
-	$query = "SELECT id_breve, statut, maj FROM spip_breves WHERE id_rubrique IN ($rubriques)";
-	liste_objets(spip_query($query), "breve");
-
-	if ($articles) {
-		$articles = join(",", $articles);
-
-		$query = "SELECT DISTINCT spip_auteurs.id_auteur, maj FROM spip_auteurs, spip_auteurs_articles AS lien WHERE id_article IN ($articles) AND spip_auteurs.id_auteur=lien.id_auteur";
-		liste_objets(spip_query($query), "auteur");
-	}
-}
-
-
-exit;
-
+   spip_log("fonction $var_nom indisponible");
 ?>
\ No newline at end of file
diff --git a/ecrire/inc_export.php3 b/ecrire/inc_export.php3
index 860d11f2b5..272f51dece 100644
--- a/ecrire/inc_export.php3
+++ b/ecrire/inc_export.php3
@@ -17,7 +17,6 @@ if (defined("_ECRIRE_INC_EXPORT")) return;
 define("_ECRIRE_INC_EXPORT", "1");
 
 
-
 $GLOBALS['version_archive'] = '1.2';
 
 
@@ -209,5 +208,83 @@ function export_objets($query, $type, $file = 0, $gz = false, $etape_en_cours=""
 }
 
 
+// Liste un sommaire d'objets de n'importe quel type
+// a la condition d'etre publics et plus recents que $maj
+function liste_objets($query, $type, $maj) {
+
+	$res = array();
+	if ($result = spip_query($query)) 
+	  while ($row = spip_fetch_array($result)) {
+		$t_id = $row["id_$type"];
+		$t_statut = $row["statut"];
+		$t_maj = mysql_timestamp_to_time($row["maj"]);
+		if (!$maj ||
+			($t_maj > $maj && 
+			 (!$t_statut || $t_statut == "publie"))) {
+		  echo "$type $t_id ", ($maj ? $t_maj : ""), "\n";
+			if ($type == "article") $res[]=$t_id;
+		}
+	}
+	spip_free_result($result);
+	return $res;
+}
+
+// Liste un sommaire recursif de rubriques
+// a condition que la mise a jour soit plus recente que $maj
+function liste_rubriques($id_rubrique) {
+	global $maj;
+	static $rubriques = array();
+	if ($id_rubrique)
+		$query="SELECT * FROM spip_rubriques WHERE id_rubrique='$id_rubrique'";
+	else
+		$query="SELECT * FROM spip_rubriques WHERE id_parent=0";
+	$result = spip_query($query);
+
+	if ($result) while ($row=spip_fetch_array($result)) {
+		$id_rubrique = $row['id_rubrique'];
+		$id_parent = $row['id_parent'];
+		$titre = $row['titre'];
+		$descriptif = $row['descriptif'];
+		$texte = $row['texte'];
+		$rubrique_maj = mysql_timestamp_to_time($row["maj"]);
+		if ($rubrique_maj > $maj) {
+			echo "rubrique $id_rubrique $rubrique_maj\n";
+		}
+		$t_rubriques[] = $id_rubrique;
+		$rubriques[] = $id_rubrique;
+	}
+	spip_free_result($result);
+ 	if ($t_rubriques) {
+ 		$t_rubriques = join(",", $t_rubriques);
+ 		$query = "SELECT * FROM spip_rubriques WHERE id_parent IN ($t_rubriques)";
+		liste_rubriques(spip_query($query));
+	}
+	return $rubriques;
+}
 
+function export_dist($id_rubrique, $maj)
+{
+
+	header("Content-Type: text/plain");
+
+	$rubriques = liste_rubriques($id_rubriques);
+
+	if ($rubriques) {
+		$rubriques = join(",", $rubriques);
+
+		$query = "SELECT id_article, statut, maj FROM spip_articles WHERE id_rubrique IN ($rubriques)";
+		$articles = liste_objets($query, "article", $maj);
+
+		$query = "SELECT id_breve, statut, maj FROM spip_breves WHERE id_rubrique IN ($rubriques)";
+		liste_objets($query, "breve", $maj);
+
+		if ($articles) {
+			$articles = join(",", $articles);
+
+			$query = "SELECT DISTINCT id_auteur FROM spip_auteurs_articles  WHERE id_article IN ($articles)";
+			liste_objets($query, "auteur", 0);
+		}
+	}
+
+}
 ?>
-- 
GitLab