diff --git a/ecrire/public/criteres.php b/ecrire/public/criteres.php
index cc421e9fcd83db0c821cfa155990c63a0d73cafb..07536f9406cc2265edbb970a1615d480e2ab8a15 100644
--- a/ecrire/public/criteres.php
+++ b/ecrire/public/criteres.php
@@ -672,13 +672,21 @@ function calculer_critere_infixe($idb, &$boucles, $crit) {
 		$val[0] = str_replace('image', 'vignette', $val[0]);
 
 	else  {
-	  $nom = $table_des_tables[$type];
-	  list($nom, $desc) = trouver_def_table($nom ? $nom : $type, $boucle);
-	  if (@!array_key_exists($col, $desc['field'])) {
-		if (isset($exceptions_des_jointures[$col]))
-		  // on ignore la table, quel luxe!
-			list($t, $col) = $exceptions_des_jointures[$col];
-		$table = calculer_critere_externe_init($boucle, $boucle->jointures, $col, $desc, ($crit->cond OR $op !='='), $t);
+		$nom = $table_des_tables[$type];
+		list($nom, $desc) = trouver_def_table($nom ? $nom : $type, $boucle);
+		if (@!array_key_exists($col, $desc['field'])) {
+	  	$calculer_critere_externe = 'calculer_critere_externe_init';
+			// gestion par les plugins des jointures tordues pas automatiques mais necessaires
+			if (isset($exceptions_des_jointures[$table][$col])){
+				if (count($exceptions_des_jointures[$table][$col])==3)
+					list($t, $col, $calculer_critere_externe) = $exceptions_des_jointures[$table][$col];
+				else
+					list($t, $col) = $exceptions_des_jointures[$table][$col];
+			}
+			else if (isset($exceptions_des_jointures[$col]))
+			  // on ignore la table, quel luxe!
+				list($t, $col) = $exceptions_des_jointures[$col];
+			$table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond OR $op !='='), $t);
 	  }
 	}
 	// ajout pour le cas special d'une condition sur le champ statut:
diff --git a/ecrire/public/references.php b/ecrire/public/references.php
index 1da5e418a1563a1c37b6df8f77db52d46e0b8cfe..894db8756b99b9e301cf8b2eb946ca73558020e4 100644
--- a/ecrire/public/references.php
+++ b/ecrire/public/references.php
@@ -154,18 +154,26 @@ function index_exception(&$boucle, $desc, $nom_champ, $excep)
 	global $tables_des_serveurs_sql;
 
 	if (is_array($excep)) {
-
-		list($e, $x) = $excep;	#PHP4 affecte de gauche a droite
-		$excep = $x;		#PHP5 de droite a gauche !
-		if (!$t = array_search($e, $boucle->from)) {
-			$t = 'J' . count($boucle->from);
-			$boucle->from[$t] = $e;
-			$j = $tables_des_serveurs_sql[$desc['serveur']][$e];
-# essayer ca un jour: 	list($nom, $j) = trouver_def_table($e, $boucle);
-			$j = $j['key']['PRIMARY KEY'];
-			$boucle->where[]= array("'='", "'$boucle->id_table." . "$j'", "'$t.$j'");
-			}
-	} else $t = $desc['type'];
+		// permettre aux plugins de gerer eux meme des jointures derogatoire ingérables
+		$t = NULL;
+		if (count($excep)==3){
+			$index_exception_derogatoire = array_pop($excep);
+			$t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep);
+		}
+		if ($t == NULL) {
+			list($e, $x) = $excep;	#PHP4 affecte de gauche a droite
+			$excep = $x;		#PHP5 de droite a gauche !
+			if (!$t = array_search($e, $boucle->from)) {
+				$t = 'J' . count($boucle->from);
+				$boucle->from[$t] = $e;
+				$j = $tables_des_serveurs_sql[$desc['serveur']][$e];
+	# essayer ca un jour: 	list($nom, $j) = trouver_def_table($e, $boucle);
+				$j = $j['key']['PRIMARY KEY'];
+				$boucle->where[]= array("'='", "'$boucle->id_table." . "$j'", "'$t.$j'");
+				}
+		}
+	} 
+	else $t = $desc['type'];
 	// demander a SQL de gerer le synonyme
 	// ca permet que excep soit dynamique (Cedric, 2/3/06)
 	if ($excep != $nom_champ) $excep .= ' AS '. $nom_champ;