Completed
Push — master ( fa948f...93df9d )
by cam
06:55 queued 02:09
created
prive/formulaires/editer_logo.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  **/
31 31
 
32 32
 if (!defined('_ECRIRE_INC_VERSION')) {
33
-	return;
33
+    return;
34 34
 }
35 35
 
36 36
 global $logo_libelles;
@@ -49,90 +49,90 @@  discard block
 block discarded – undo
49 49
  * @return array               Variables d'environnement pour le fond
50 50
  */
51 51
 function formulaires_editer_logo_charger_dist($objet, $id_objet, $retour = '', $options = array()) {
52
-	// pas dans une boucle ? formulaire pour le logo du site
53
-	// dans ce cas, il faut chercher un 'siteon0.ext'
54
-	if (!$objet) {
55
-		$objet = 'site';
56
-	}
52
+    // pas dans une boucle ? formulaire pour le logo du site
53
+    // dans ce cas, il faut chercher un 'siteon0.ext'
54
+    if (!$objet) {
55
+        $objet = 'site';
56
+    }
57 57
 
58
-	$objet = objet_type($objet);
59
-	$_id_objet = id_table_objet($objet);
58
+    $objet = objet_type($objet);
59
+    $_id_objet = id_table_objet($objet);
60 60
 
61
-	if (!is_array($options)) {
62
-		$options = unserialize($options);
63
-	}
64
-	$options = spip_sanitize_from_request($options, '*');
61
+    if (!is_array($options)) {
62
+        $options = unserialize($options);
63
+    }
64
+    $options = spip_sanitize_from_request($options, '*');
65 65
 
66
-	if (!isset($options['titre'])) {
67
-		$balise_img = chercher_filtre('balise_img');
68
-		$img = $balise_img(chemin_image('image-24.png'),'', 'cadre-icone');
69
-		$libelles = pipeline('libeller_logo', $GLOBALS['logo_libelles']);
70
-		$libelle = (($id_objet or $objet != 'rubrique') ? $objet : 'racine');
71
-		if (isset($libelles[$libelle])) {
72
-			$libelle = $libelles[$libelle];
73
-		} elseif ($libelle = objet_info($objet, 'texte_logo_objet')) {
74
-			$libelle = _T($libelle);
75
-		} else {
76
-			$libelle = _L('Logo');
77
-		}
78
-		switch ($objet) {
79
-			case 'article':
80
-				$libelle .= ' ' . aider('logoart');
81
-				break;
82
-			case 'breve':
83
-				$libelle .= ' ' . aider('breveslogo');
84
-				break;
85
-			case 'rubrique':
86
-				$libelle .= ' ' . aider('rublogo');
87
-				break;
88
-			default:
89
-				break;
90
-		}
66
+    if (!isset($options['titre'])) {
67
+        $balise_img = chercher_filtre('balise_img');
68
+        $img = $balise_img(chemin_image('image-24.png'),'', 'cadre-icone');
69
+        $libelles = pipeline('libeller_logo', $GLOBALS['logo_libelles']);
70
+        $libelle = (($id_objet or $objet != 'rubrique') ? $objet : 'racine');
71
+        if (isset($libelles[$libelle])) {
72
+            $libelle = $libelles[$libelle];
73
+        } elseif ($libelle = objet_info($objet, 'texte_logo_objet')) {
74
+            $libelle = _T($libelle);
75
+        } else {
76
+            $libelle = _L('Logo');
77
+        }
78
+        switch ($objet) {
79
+            case 'article':
80
+                $libelle .= ' ' . aider('logoart');
81
+                break;
82
+            case 'breve':
83
+                $libelle .= ' ' . aider('breveslogo');
84
+                break;
85
+            case 'rubrique':
86
+                $libelle .= ' ' . aider('rublogo');
87
+                break;
88
+            default:
89
+                break;
90
+        }
91 91
 
92
-		$options['titre'] = $img . $libelle;
93
-	}
94
-	if (!isset($options['editable'])) {
95
-		include_spip('inc/autoriser');
96
-		$options['editable'] = autoriser('iconifier', $objet, $id_objet);
97
-	}
92
+        $options['titre'] = $img . $libelle;
93
+    }
94
+    if (!isset($options['editable'])) {
95
+        include_spip('inc/autoriser');
96
+        $options['editable'] = autoriser('iconifier', $objet, $id_objet);
97
+    }
98 98
 
99
-	$res = array(
100
-		'editable' => ($GLOBALS['meta']['activer_logos'] == 'oui' ? ' ' : '') && (!isset($options['editable']) or $options['editable']),
101
-		'logo_survol' => ($GLOBALS['meta']['activer_logos_survol'] == 'oui' ? ' ' : ''),
102
-		'objet' => $objet,
103
-		'id_objet' => $id_objet,
104
-		'_options' => $options,
105
-		'_show_upload_off' => '',
106
-	);
99
+    $res = array(
100
+        'editable' => ($GLOBALS['meta']['activer_logos'] == 'oui' ? ' ' : '') && (!isset($options['editable']) or $options['editable']),
101
+        'logo_survol' => ($GLOBALS['meta']['activer_logos_survol'] == 'oui' ? ' ' : ''),
102
+        'objet' => $objet,
103
+        'id_objet' => $id_objet,
104
+        '_options' => $options,
105
+        '_show_upload_off' => '',
106
+    );
107 107
 
108
-	// rechercher le logo de l'objet
109
-	// la fonction prend un parametre '_id_objet' etrange :
110
-	// le nom de la cle primaire (et non le nom de la table)
111
-	// ou directement le nom du raccourcis a chercher
112
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
113
-	$etats = $res['logo_survol'] ? array('on', 'off') : array('on');
114
-	foreach ($etats as $etat) {
115
-		$logo = $chercher_logo($id_objet, $_id_objet, $etat);
116
-		if ($logo) {
117
-			$res['logo_' . $etat] = $logo[0];
118
-		}
119
-	}
120
-	// pas de logo_on -> pas de formulaire pour le survol
121
-	if (!isset($res['logo_on'])) {
122
-		$res['logo_survol'] = '';
123
-	} elseif (!isset($res['logo_off']) and _request('logo_up')) {
124
-		$res['_show_upload_off'] = ' ';
125
-	}
108
+    // rechercher le logo de l'objet
109
+    // la fonction prend un parametre '_id_objet' etrange :
110
+    // le nom de la cle primaire (et non le nom de la table)
111
+    // ou directement le nom du raccourcis a chercher
112
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
113
+    $etats = $res['logo_survol'] ? array('on', 'off') : array('on');
114
+    foreach ($etats as $etat) {
115
+        $logo = $chercher_logo($id_objet, $_id_objet, $etat);
116
+        if ($logo) {
117
+            $res['logo_' . $etat] = $logo[0];
118
+        }
119
+    }
120
+    // pas de logo_on -> pas de formulaire pour le survol
121
+    if (!isset($res['logo_on'])) {
122
+        $res['logo_survol'] = '';
123
+    } elseif (!isset($res['logo_off']) and _request('logo_up')) {
124
+        $res['_show_upload_off'] = ' ';
125
+    }
126 126
 
127
-	// si le logo n'est pas editable et qu'il n'y en a pas, on affiche pas du tout le formulaire
128
-	if (!$res['editable']
129
-		and !isset($res['logo_off'])
130
-		and !isset($res['logo_on'])
131
-	) {
132
-		return false;
133
-	}
127
+    // si le logo n'est pas editable et qu'il n'y en a pas, on affiche pas du tout le formulaire
128
+    if (!$res['editable']
129
+        and !isset($res['logo_off'])
130
+        and !isset($res['logo_on'])
131
+    ) {
132
+        return false;
133
+    }
134 134
 
135
-	return $res;
135
+    return $res;
136 136
 }
137 137
 
138 138
 /**
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
  * @return string              Hash du formulaire
147 147
  */
148 148
 function formulaires_editer_logo_identifier_dist($objet, $id_objet, $retour = '', $options = array()) {
149
-	return serialize(array($objet, $id_objet));
149
+    return serialize(array($objet, $id_objet));
150 150
 }
151 151
 
152 152
 /**
@@ -162,29 +162,29 @@  discard block
 block discarded – undo
162 162
  * @return array               Erreurs du formulaire
163 163
  */
164 164
 function formulaires_editer_logo_verifier_dist($objet, $id_objet, $retour = '', $options = array()) {
165
-	$erreurs = array();
166
-	// verifier les extensions
167
-	$sources = formulaire_editer_logo_get_sources();
168
-	include_spip('action/editer_logo');
169
-	$extensions_possibles = $GLOBALS['formats_logos'];
170
-	if (in_array('jpg', $extensions_possibles)) {
171
-		$extensions_possibles[] = 'jpeg';
172
-	}
173
-	foreach ($sources as $etat => $file) {
174
-		// seulement si une reception correcte a eu lieu
175
-		if ($file and $file['error'] == 0) {
176
-			if (!in_array(
177
-				strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)),
178
-				$extensions_possibles
179
-			)) {
180
-				$erreurs['logo_' . $etat] = _L('Extension non reconnue');
181
-			}
182
-		} elseif ($file and $file['error'] != 0 and isset($file['msg'])) {
183
-			$erreurs['message_erreur'] = $file['msg'];
184
-		}
185
-	}
165
+    $erreurs = array();
166
+    // verifier les extensions
167
+    $sources = formulaire_editer_logo_get_sources();
168
+    include_spip('action/editer_logo');
169
+    $extensions_possibles = $GLOBALS['formats_logos'];
170
+    if (in_array('jpg', $extensions_possibles)) {
171
+        $extensions_possibles[] = 'jpeg';
172
+    }
173
+    foreach ($sources as $etat => $file) {
174
+        // seulement si une reception correcte a eu lieu
175
+        if ($file and $file['error'] == 0) {
176
+            if (!in_array(
177
+                strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)),
178
+                $extensions_possibles
179
+            )) {
180
+                $erreurs['logo_' . $etat] = _L('Extension non reconnue');
181
+            }
182
+        } elseif ($file and $file['error'] != 0 and isset($file['msg'])) {
183
+            $erreurs['message_erreur'] = $file['msg'];
184
+        }
185
+    }
186 186
 
187
-	return $erreurs;
187
+    return $erreurs;
188 188
 }
189 189
 
190 190
 /**
@@ -200,47 +200,47 @@  discard block
 block discarded – undo
200 200
  * @return array               Retour des traitements
201 201
  */
202 202
 function formulaires_editer_logo_traiter_dist($objet, $id_objet, $retour = '', $options = array()) {
203
-	$res = array('editable' => ' ');
203
+    $res = array('editable' => ' ');
204 204
 
205
-	// pas dans une boucle ? formulaire pour le logo du site
206
-	// dans ce cas, il faut chercher un 'siteon0.ext'
207
-	if (!$objet) {
208
-		$objet = 'site';
209
-	}
205
+    // pas dans une boucle ? formulaire pour le logo du site
206
+    // dans ce cas, il faut chercher un 'siteon0.ext'
207
+    if (!$objet) {
208
+        $objet = 'site';
209
+    }
210 210
 
211
-	include_spip('action/editer_logo');
211
+    include_spip('action/editer_logo');
212 212
 
213
-	// effectuer la suppression si demandee d'un logo
214
-	$on = _request('supprimer_logo_on');
215
-	if ($on or _request('supprimer_logo_off')) {
216
-		logo_supprimer($objet, $id_objet, $on ? 'on' : 'off');
217
-		$res['message_ok'] = ''; // pas besoin de message : la validation est visuelle
218
-		set_request('logo_up', ' ');
219
-	} // sinon supprimer ancien logo puis copier le nouveau
220
-	else {
221
-		$sources = formulaire_editer_logo_get_sources();
222
-		foreach ($sources as $etat => $file) {
223
-			if ($file and $file['error'] == 0) {
224
-				if ($err = logo_modifier($objet, $id_objet, $etat, $file)) {
225
-					$res['message_erreur'] = $err;
226
-				} else {
227
-					$res['message_ok'] = '';
228
-				} // pas besoin de message : la validation est visuelle
229
-				set_request('logo_up', ' ');
230
-			}
231
-		}
232
-	}
213
+    // effectuer la suppression si demandee d'un logo
214
+    $on = _request('supprimer_logo_on');
215
+    if ($on or _request('supprimer_logo_off')) {
216
+        logo_supprimer($objet, $id_objet, $on ? 'on' : 'off');
217
+        $res['message_ok'] = ''; // pas besoin de message : la validation est visuelle
218
+        set_request('logo_up', ' ');
219
+    } // sinon supprimer ancien logo puis copier le nouveau
220
+    else {
221
+        $sources = formulaire_editer_logo_get_sources();
222
+        foreach ($sources as $etat => $file) {
223
+            if ($file and $file['error'] == 0) {
224
+                if ($err = logo_modifier($objet, $id_objet, $etat, $file)) {
225
+                    $res['message_erreur'] = $err;
226
+                } else {
227
+                    $res['message_ok'] = '';
228
+                } // pas besoin de message : la validation est visuelle
229
+                set_request('logo_up', ' ');
230
+            }
231
+        }
232
+    }
233 233
 
234
-	// Invalider les caches de l'objet
235
-	include_spip('inc/invalideur');
236
-	suivre_invalideur("id='$objet/$id_objet'");
234
+    // Invalider les caches de l'objet
235
+    include_spip('inc/invalideur');
236
+    suivre_invalideur("id='$objet/$id_objet'");
237 237
 
238 238
 
239
-	if ($retour) {
240
-		$res['redirect'] = $retour;
241
-	}
239
+    if ($retour) {
240
+        $res['redirect'] = $retour;
241
+    }
242 242
 
243
-	return $res;
243
+    return $res;
244 244
 }
245 245
 
246 246
 
@@ -252,29 +252,29 @@  discard block
 block discarded – undo
252 252
  *     Sources des fichiers dans les clés `on` ou `off`
253 253
  */
254 254
 function formulaire_editer_logo_get_sources() {
255
-	if (!$_FILES) {
256
-		$_FILES = isset($GLOBALS['HTTP_POST_FILES']) ? $GLOBALS['HTTP_POST_FILES'] : array();
257
-	}
258
-	if (!is_array($_FILES)) {
259
-		return array();
260
-	}
255
+    if (!$_FILES) {
256
+        $_FILES = isset($GLOBALS['HTTP_POST_FILES']) ? $GLOBALS['HTTP_POST_FILES'] : array();
257
+    }
258
+    if (!is_array($_FILES)) {
259
+        return array();
260
+    }
261 261
 
262
-	include_spip('inc/documents');
263
-	$sources = array();
264
-	foreach (array('on', 'off') as $etat) {
265
-		$logo = 'logo_' . $etat;
266
-		if (isset($_FILES[$logo])) {
267
-			if ($_FILES[$logo]['error'] == 0) {
268
-				$sources[$etat] = $_FILES[$logo];
269
-			} elseif ($_FILES[$logo]['error'] != 0) {
270
-				$msg = check_upload_error($_FILES[$logo]['error'], false, true);
271
-				if ($msg and is_string($msg)) {
272
-					$sources[$etat] = $_FILES[$logo];
273
-					$sources[$etat]['msg'] = $msg;
274
-				}
275
-			}
276
-		}
277
-	}
262
+    include_spip('inc/documents');
263
+    $sources = array();
264
+    foreach (array('on', 'off') as $etat) {
265
+        $logo = 'logo_' . $etat;
266
+        if (isset($_FILES[$logo])) {
267
+            if ($_FILES[$logo]['error'] == 0) {
268
+                $sources[$etat] = $_FILES[$logo];
269
+            } elseif ($_FILES[$logo]['error'] != 0) {
270
+                $msg = check_upload_error($_FILES[$logo]['error'], false, true);
271
+                if ($msg and is_string($msg)) {
272
+                    $sources[$etat] = $_FILES[$logo];
273
+                    $sources[$etat]['msg'] = $msg;
274
+                }
275
+            }
276
+        }
277
+    }
278 278
 
279
-	return $sources;
279
+    return $sources;
280 280
 }
Please login to merge, or discard this patch.
prive/formulaires/editer_liens.php 1 patch
Indentation   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Formulaires
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 
@@ -35,25 +35,25 @@  discard block
 block discarded – undo
35 35
  *   ($table_source,$objet,$id_objet,$objet_lien)
36 36
  */
37 37
 function determine_source_lien_objet($a, $b, $c) {
38
-	$table_source = $objet_lien = $objet = $id_objet = null;
39
-	// auteurs, article, 23 :
40
-	// associer des auteurs à l'article 23, sur la table pivot spip_auteurs_liens
41
-	if (is_numeric($c) and !is_numeric($b)) {
42
-		$table_source = table_objet($a);
43
-		$objet_lien = objet_type($a);
44
-		$objet = objet_type($b);
45
-		$id_objet = $c;
46
-	}
47
-	// article, 23, auteurs
48
-	// associer des auteurs à l'article 23, sur la table pivot spip_articles_liens
49
-	if (is_numeric($b) and !is_numeric($c)) {
50
-		$table_source = table_objet($c);
51
-		$objet_lien = objet_type($a);
52
-		$objet = objet_type($a);
53
-		$id_objet = $b;
54
-	}
55
-
56
-	return array($table_source, $objet, $id_objet, $objet_lien);
38
+    $table_source = $objet_lien = $objet = $id_objet = null;
39
+    // auteurs, article, 23 :
40
+    // associer des auteurs à l'article 23, sur la table pivot spip_auteurs_liens
41
+    if (is_numeric($c) and !is_numeric($b)) {
42
+        $table_source = table_objet($a);
43
+        $objet_lien = objet_type($a);
44
+        $objet = objet_type($b);
45
+        $id_objet = $c;
46
+    }
47
+    // article, 23, auteurs
48
+    // associer des auteurs à l'article 23, sur la table pivot spip_articles_liens
49
+    if (is_numeric($b) and !is_numeric($c)) {
50
+        $table_source = table_objet($c);
51
+        $objet_lien = objet_type($a);
52
+        $objet = objet_type($a);
53
+        $id_objet = $b;
54
+    }
55
+
56
+    return array($table_source, $objet, $id_objet, $objet_lien);
57 57
 }
58 58
 
59 59
 /**
@@ -79,91 +79,91 @@  discard block
 block discarded – undo
79 79
  */
80 80
 function formulaires_editer_liens_charger_dist($a, $b, $c, $options = array()) {
81 81
 
82
-	// compat avec ancienne signature ou le 4eme argument est $editable
83
-	if (!is_array($options)) {
84
-		$options = array('editable' => $options);
85
-	} elseif (!isset($options['editable'])) {
86
-		$options['editable'] = true;
87
-	}
88
-
89
-	$editable = $options['editable'];
90
-
91
-	list($table_source, $objet, $id_objet, $objet_lien) = determine_source_lien_objet($a, $b, $c);
92
-	if (!$table_source or !$objet or !$objet_lien or !$id_objet) {
93
-		return false;
94
-	}
95
-
96
-	$objet_source = objet_type($table_source);
97
-	$table_sql_source = table_objet_sql($objet_source);
98
-
99
-	// verifier existence de la table xxx_liens
100
-	include_spip('action/editer_liens');
101
-	if (!objet_associable($objet_lien)) {
102
-		return false;
103
-	}
104
-
105
-	// L'éditabilité :) est définie par un test permanent (par exemple "associermots") ET le 4ème argument
106
-	include_spip('inc/autoriser');
107
-	$editable = ($editable and autoriser('associer' . $table_source, $objet, $id_objet)
108
-		and autoriser('modifier', $objet, $id_objet));
109
-
110
-	if (!$editable and !count(objet_trouver_liens(
111
-		array($objet_lien => '*'),
112
-		array(($objet_lien == $objet_source ? $objet : $objet_source) => $id_objet)
113
-	))) {
114
-		return false;
115
-	}
116
-
117
-	// squelettes de vue et de d'association
118
-	// ils sont différents si des rôles sont définis.
119
-	$skel_vue = $table_source . '_lies';
120
-	$skel_ajout = $table_source . '_associer';
121
-
122
-	// description des roles
123
-	include_spip('inc/roles');
124
-	if ($roles = roles_presents($objet_source, $objet)) {
125
-		// on demande de nouveaux squelettes en conséquence
126
-		$skel_vue = $table_source . '_roles_lies';
127
-		$skel_ajout = $table_source . '_roles_associer';
128
-	}
129
-
130
-	$oups = _request('_oups');
131
-	if (unserialize(base64_decode($oups))) {
132
-		// on est bon, rien a faire
133
-	}
134
-	elseif(unserialize($oups)) {
135
-		// il faut encoder
136
-		$oups = base64_encode($oups);
137
-	}
138
-	else {
139
-		$oups = '';
140
-	}
141
-	$valeurs = array(
142
-		'id' => "$table_source-$objet-$id_objet-$objet_lien", // identifiant unique pour les id du form
143
-		'_vue_liee' => $skel_vue,
144
-		'_vue_ajout' => $skel_ajout,
145
-		'_objet_lien' => $objet_lien,
146
-		'id_lien_ajoute' => _request('id_lien_ajoute'),
147
-		'objet' => $objet,
148
-		'id_objet' => $id_objet,
149
-		'objet_source' => $objet_source,
150
-		'table_source' => $table_source,
151
-		'recherche' => '',
152
-		'visible' => 0,
153
-		'ajouter_lien' => '',
154
-		'supprimer_lien' => '',
155
-		'qualifier_lien' => '',
156
-		'ordonner_lien' => '',
157
-		'desordonner_liens' => '',
158
-		'_roles' => $roles, # description des roles
159
-		'_oups' => $oups,
160
-		'editable' => $editable,
161
-	);
162
-
163
-	// les options non definies dans $valeurs sont passees telles quelles au formulaire html
164
-	$valeurs = array_merge($options, $valeurs);
165
-
166
-	return $valeurs;
82
+    // compat avec ancienne signature ou le 4eme argument est $editable
83
+    if (!is_array($options)) {
84
+        $options = array('editable' => $options);
85
+    } elseif (!isset($options['editable'])) {
86
+        $options['editable'] = true;
87
+    }
88
+
89
+    $editable = $options['editable'];
90
+
91
+    list($table_source, $objet, $id_objet, $objet_lien) = determine_source_lien_objet($a, $b, $c);
92
+    if (!$table_source or !$objet or !$objet_lien or !$id_objet) {
93
+        return false;
94
+    }
95
+
96
+    $objet_source = objet_type($table_source);
97
+    $table_sql_source = table_objet_sql($objet_source);
98
+
99
+    // verifier existence de la table xxx_liens
100
+    include_spip('action/editer_liens');
101
+    if (!objet_associable($objet_lien)) {
102
+        return false;
103
+    }
104
+
105
+    // L'éditabilité :) est définie par un test permanent (par exemple "associermots") ET le 4ème argument
106
+    include_spip('inc/autoriser');
107
+    $editable = ($editable and autoriser('associer' . $table_source, $objet, $id_objet)
108
+        and autoriser('modifier', $objet, $id_objet));
109
+
110
+    if (!$editable and !count(objet_trouver_liens(
111
+        array($objet_lien => '*'),
112
+        array(($objet_lien == $objet_source ? $objet : $objet_source) => $id_objet)
113
+    ))) {
114
+        return false;
115
+    }
116
+
117
+    // squelettes de vue et de d'association
118
+    // ils sont différents si des rôles sont définis.
119
+    $skel_vue = $table_source . '_lies';
120
+    $skel_ajout = $table_source . '_associer';
121
+
122
+    // description des roles
123
+    include_spip('inc/roles');
124
+    if ($roles = roles_presents($objet_source, $objet)) {
125
+        // on demande de nouveaux squelettes en conséquence
126
+        $skel_vue = $table_source . '_roles_lies';
127
+        $skel_ajout = $table_source . '_roles_associer';
128
+    }
129
+
130
+    $oups = _request('_oups');
131
+    if (unserialize(base64_decode($oups))) {
132
+        // on est bon, rien a faire
133
+    }
134
+    elseif(unserialize($oups)) {
135
+        // il faut encoder
136
+        $oups = base64_encode($oups);
137
+    }
138
+    else {
139
+        $oups = '';
140
+    }
141
+    $valeurs = array(
142
+        'id' => "$table_source-$objet-$id_objet-$objet_lien", // identifiant unique pour les id du form
143
+        '_vue_liee' => $skel_vue,
144
+        '_vue_ajout' => $skel_ajout,
145
+        '_objet_lien' => $objet_lien,
146
+        'id_lien_ajoute' => _request('id_lien_ajoute'),
147
+        'objet' => $objet,
148
+        'id_objet' => $id_objet,
149
+        'objet_source' => $objet_source,
150
+        'table_source' => $table_source,
151
+        'recherche' => '',
152
+        'visible' => 0,
153
+        'ajouter_lien' => '',
154
+        'supprimer_lien' => '',
155
+        'qualifier_lien' => '',
156
+        'ordonner_lien' => '',
157
+        'desordonner_liens' => '',
158
+        '_roles' => $roles, # description des roles
159
+        '_oups' => $oups,
160
+        'editable' => $editable,
161
+    );
162
+
163
+    // les options non definies dans $valeurs sont passees telles quelles au formulaire html
164
+    $valeurs = array_merge($options, $valeurs);
165
+
166
+    return $valeurs;
167 167
 }
168 168
 
169 169
 /**
@@ -207,161 +207,161 @@  discard block
 block discarded – undo
207 207
  * @return array
208 208
  */
209 209
 function formulaires_editer_liens_traiter_dist($a, $b, $c, $options = array()) {
210
-	// compat avec ancienne signature ou le 4eme argument est $editable
211
-	if (!is_array($options)) {
212
-		$options = array('editable' => $options);
213
-	} elseif (!isset($options['editable'])) {
214
-		$options['editable'] = true;
215
-	}
216
-
217
-	$editable = $options['editable'];
218
-
219
-	$res = array('editable' => $editable ? true : false);
220
-	list($table_source, $objet, $id_objet, $objet_lien) = determine_source_lien_objet($a, $b, $c);
221
-	if (!$table_source or !$objet or !$objet_lien) {
222
-		return $res;
223
-	}
224
-
225
-
226
-	if (_request('tout_voir')) {
227
-		set_request('recherche', '');
228
-	}
229
-
230
-	include_spip('inc/autoriser');
231
-	if (autoriser('modifier', $objet, $id_objet)) {
232
-		// annuler les suppressions du coup d'avant !
233
-		if (_request('annuler_oups')
234
-			and $oups = _request('_oups')
235
-			and $oups = base64_decode($oups)
236
-			and $oups = unserialize($oups)
237
-		) {
238
-			if ($oups_objets = charger_fonction("editer_liens_oups_{$table_source}_{$objet}_{$objet_lien}", 'action', true)) {
239
-				$oups_objets($oups);
240
-			} else {
241
-				$objet_source = objet_type($table_source);
242
-				include_spip('action/editer_liens');
243
-				foreach ($oups as $oup) {
244
-					if ($objet_lien == $objet_source) {
245
-						objet_associer(array($objet_source => $oup[$objet_source]), array($objet => $oup[$objet]), $oup);
246
-					} else {
247
-						objet_associer(array($objet => $oup[$objet]), array($objet_source => $oup[$objet_source]), $oup);
248
-					}
249
-				}
250
-			}
251
-			# oups ne persiste que pour la derniere action, si suppression
252
-			set_request('_oups');
253
-		}
254
-
255
-		$supprimer = _request('supprimer_lien');
256
-		$ajouter = _request('ajouter_lien');
257
-		$ordonner = _request('ordonner_lien');
258
-
259
-		if (_request('desordonner_liens')) {
260
-			include_spip('action/editer_liens');
261
-			objet_qualifier_liens(array($objet_lien => '*'), array($objet => $id_objet), array('rang_lien' => 0));
262
-		}
263
-
264
-		// il est possible de preciser dans une seule variable un remplacement :
265
-		// remplacer_lien[old][new]
266
-		if ($remplacer = _request('remplacer_lien')) {
267
-			foreach ($remplacer as $k => $v) {
268
-				if ($old = lien_verifier_action($k, '')) {
269
-					foreach (is_array($v) ? $v : array($v) as $kn => $vn) {
270
-						if ($new = lien_verifier_action($kn, $vn)) {
271
-							$supprimer[$old] = 'x';
272
-							$ajouter[$new] = '+';
273
-						}
274
-					}
275
-				}
276
-			}
277
-		}
278
-
279
-		if ($supprimer) {
280
-			if ($supprimer_objets = charger_fonction(
281
-				"editer_liens_supprimer_{$table_source}_{$objet}_{$objet_lien}",
282
-				'action',
283
-				true
284
-			)) {
285
-				$oups = $supprimer_objets($supprimer);
286
-			} else {
287
-				include_spip('action/editer_liens');
288
-				$oups = array();
289
-
290
-				foreach ($supprimer as $k => $v) {
291
-					if ($lien = lien_verifier_action($k, $v)) {
292
-						$lien = explode('-', $lien);
293
-						list($objet_source, $ids, $objet_lie, $idl, $role) = array_pad($lien, 5, null);
294
-						// appliquer une condition sur le rôle si défini ('*' pour tous les roles)
295
-						$cond = (!is_null($role) ? array('role' => $role) : array());
296
-						if ($objet_lien == $objet_source) {
297
-							$oups = array_merge(
298
-								$oups,
299
-								objet_trouver_liens(array($objet_source => $ids), array($objet_lie => $idl), $cond)
300
-							);
301
-							objet_dissocier(array($objet_source => $ids), array($objet_lie => $idl), $cond);
302
-						} else {
303
-							$oups = array_merge(
304
-								$oups,
305
-								objet_trouver_liens(array($objet_lie => $idl), array($objet_source => $ids), $cond)
306
-							);
307
-							objet_dissocier(array($objet_lie => $idl), array($objet_source => $ids), $cond);
308
-						}
309
-					}
310
-				}
311
-			}
312
-			set_request('_oups', $oups ? base64_encode(serialize($oups)) : null);
313
-		}
314
-
315
-		if ($ajouter) {
316
-			if ($ajouter_objets = charger_fonction("editer_liens_ajouter_{$table_source}_{$objet}_{$objet_lien}", 'action', true)
317
-			) {
318
-				$ajout_ok = $ajouter_objets($ajouter);
319
-			} else {
320
-				$ajout_ok = false;
321
-				include_spip('action/editer_liens');
322
-				foreach ($ajouter as $k => $v) {
323
-					if ($lien = lien_verifier_action($k, $v)) {
324
-						$ajout_ok = true;
325
-						list($objet1, $ids, $objet2, $idl) = explode('-', $lien);
326
-						$qualifs = lien_retrouver_qualif($objet_lien, $lien);
327
-						if ($objet_lien == $objet1) {
328
-							lien_ajouter_liaisons($objet1, $ids, $objet2, $idl, $qualifs);
329
-						} else {
330
-							lien_ajouter_liaisons($objet2, $idl, $objet1, $ids, $qualifs);
331
-						}
332
-						set_request('id_lien_ajoute', $ids);
333
-					}
334
-				}
335
-			}
336
-			# oups ne persiste que pour la derniere action, si suppression
337
-			# une suppression suivie d'un ajout dans le meme hit est un remplacement
338
-			# non annulable !
339
-			if ($ajout_ok) {
340
-				set_request('_oups');
341
-			}
342
-		}
343
-
344
-		if ($ordonner) {
345
-			include_spip('action/editer_liens');
346
-			foreach ($ordonner as $k => $rang_lien) {
347
-				if ($lien = lien_verifier_action($k, '')) {
348
-					list($objet1, $ids, $objet2, $idl) = explode('-', $lien);
349
-					$qualif = array('rang_lien' => $rang_lien);
350
-
351
-					if ($objet_lien == $objet1) {
352
-						objet_qualifier_liens(array($objet1 => $ids), array($objet2 => $idl), $qualif);
353
-					} else {
354
-						objet_qualifier_liens(array($objet2 => $idl), array($objet1 => $ids), $qualif);
355
-					}
356
-					set_request('id_lien_ajoute', $ids);
357
-					set_request('_oups');
358
-				}
359
-			}
360
-		}
361
-	}
362
-
363
-
364
-	return $res;
210
+    // compat avec ancienne signature ou le 4eme argument est $editable
211
+    if (!is_array($options)) {
212
+        $options = array('editable' => $options);
213
+    } elseif (!isset($options['editable'])) {
214
+        $options['editable'] = true;
215
+    }
216
+
217
+    $editable = $options['editable'];
218
+
219
+    $res = array('editable' => $editable ? true : false);
220
+    list($table_source, $objet, $id_objet, $objet_lien) = determine_source_lien_objet($a, $b, $c);
221
+    if (!$table_source or !$objet or !$objet_lien) {
222
+        return $res;
223
+    }
224
+
225
+
226
+    if (_request('tout_voir')) {
227
+        set_request('recherche', '');
228
+    }
229
+
230
+    include_spip('inc/autoriser');
231
+    if (autoriser('modifier', $objet, $id_objet)) {
232
+        // annuler les suppressions du coup d'avant !
233
+        if (_request('annuler_oups')
234
+            and $oups = _request('_oups')
235
+            and $oups = base64_decode($oups)
236
+            and $oups = unserialize($oups)
237
+        ) {
238
+            if ($oups_objets = charger_fonction("editer_liens_oups_{$table_source}_{$objet}_{$objet_lien}", 'action', true)) {
239
+                $oups_objets($oups);
240
+            } else {
241
+                $objet_source = objet_type($table_source);
242
+                include_spip('action/editer_liens');
243
+                foreach ($oups as $oup) {
244
+                    if ($objet_lien == $objet_source) {
245
+                        objet_associer(array($objet_source => $oup[$objet_source]), array($objet => $oup[$objet]), $oup);
246
+                    } else {
247
+                        objet_associer(array($objet => $oup[$objet]), array($objet_source => $oup[$objet_source]), $oup);
248
+                    }
249
+                }
250
+            }
251
+            # oups ne persiste que pour la derniere action, si suppression
252
+            set_request('_oups');
253
+        }
254
+
255
+        $supprimer = _request('supprimer_lien');
256
+        $ajouter = _request('ajouter_lien');
257
+        $ordonner = _request('ordonner_lien');
258
+
259
+        if (_request('desordonner_liens')) {
260
+            include_spip('action/editer_liens');
261
+            objet_qualifier_liens(array($objet_lien => '*'), array($objet => $id_objet), array('rang_lien' => 0));
262
+        }
263
+
264
+        // il est possible de preciser dans une seule variable un remplacement :
265
+        // remplacer_lien[old][new]
266
+        if ($remplacer = _request('remplacer_lien')) {
267
+            foreach ($remplacer as $k => $v) {
268
+                if ($old = lien_verifier_action($k, '')) {
269
+                    foreach (is_array($v) ? $v : array($v) as $kn => $vn) {
270
+                        if ($new = lien_verifier_action($kn, $vn)) {
271
+                            $supprimer[$old] = 'x';
272
+                            $ajouter[$new] = '+';
273
+                        }
274
+                    }
275
+                }
276
+            }
277
+        }
278
+
279
+        if ($supprimer) {
280
+            if ($supprimer_objets = charger_fonction(
281
+                "editer_liens_supprimer_{$table_source}_{$objet}_{$objet_lien}",
282
+                'action',
283
+                true
284
+            )) {
285
+                $oups = $supprimer_objets($supprimer);
286
+            } else {
287
+                include_spip('action/editer_liens');
288
+                $oups = array();
289
+
290
+                foreach ($supprimer as $k => $v) {
291
+                    if ($lien = lien_verifier_action($k, $v)) {
292
+                        $lien = explode('-', $lien);
293
+                        list($objet_source, $ids, $objet_lie, $idl, $role) = array_pad($lien, 5, null);
294
+                        // appliquer une condition sur le rôle si défini ('*' pour tous les roles)
295
+                        $cond = (!is_null($role) ? array('role' => $role) : array());
296
+                        if ($objet_lien == $objet_source) {
297
+                            $oups = array_merge(
298
+                                $oups,
299
+                                objet_trouver_liens(array($objet_source => $ids), array($objet_lie => $idl), $cond)
300
+                            );
301
+                            objet_dissocier(array($objet_source => $ids), array($objet_lie => $idl), $cond);
302
+                        } else {
303
+                            $oups = array_merge(
304
+                                $oups,
305
+                                objet_trouver_liens(array($objet_lie => $idl), array($objet_source => $ids), $cond)
306
+                            );
307
+                            objet_dissocier(array($objet_lie => $idl), array($objet_source => $ids), $cond);
308
+                        }
309
+                    }
310
+                }
311
+            }
312
+            set_request('_oups', $oups ? base64_encode(serialize($oups)) : null);
313
+        }
314
+
315
+        if ($ajouter) {
316
+            if ($ajouter_objets = charger_fonction("editer_liens_ajouter_{$table_source}_{$objet}_{$objet_lien}", 'action', true)
317
+            ) {
318
+                $ajout_ok = $ajouter_objets($ajouter);
319
+            } else {
320
+                $ajout_ok = false;
321
+                include_spip('action/editer_liens');
322
+                foreach ($ajouter as $k => $v) {
323
+                    if ($lien = lien_verifier_action($k, $v)) {
324
+                        $ajout_ok = true;
325
+                        list($objet1, $ids, $objet2, $idl) = explode('-', $lien);
326
+                        $qualifs = lien_retrouver_qualif($objet_lien, $lien);
327
+                        if ($objet_lien == $objet1) {
328
+                            lien_ajouter_liaisons($objet1, $ids, $objet2, $idl, $qualifs);
329
+                        } else {
330
+                            lien_ajouter_liaisons($objet2, $idl, $objet1, $ids, $qualifs);
331
+                        }
332
+                        set_request('id_lien_ajoute', $ids);
333
+                    }
334
+                }
335
+            }
336
+            # oups ne persiste que pour la derniere action, si suppression
337
+            # une suppression suivie d'un ajout dans le meme hit est un remplacement
338
+            # non annulable !
339
+            if ($ajout_ok) {
340
+                set_request('_oups');
341
+            }
342
+        }
343
+
344
+        if ($ordonner) {
345
+            include_spip('action/editer_liens');
346
+            foreach ($ordonner as $k => $rang_lien) {
347
+                if ($lien = lien_verifier_action($k, '')) {
348
+                    list($objet1, $ids, $objet2, $idl) = explode('-', $lien);
349
+                    $qualif = array('rang_lien' => $rang_lien);
350
+
351
+                    if ($objet_lien == $objet1) {
352
+                        objet_qualifier_liens(array($objet1 => $ids), array($objet2 => $idl), $qualif);
353
+                    } else {
354
+                        objet_qualifier_liens(array($objet2 => $idl), array($objet1 => $ids), $qualif);
355
+                    }
356
+                    set_request('id_lien_ajoute', $ids);
357
+                    set_request('_oups');
358
+                }
359
+            }
360
+        }
361
+    }
362
+
363
+
364
+    return $res;
365 365
 }
366 366
 
367 367
 
@@ -384,24 +384,24 @@  discard block
 block discarded – undo
384 384
  * @return string Action demandée si trouvée, sinon ''
385 385
  */
386 386
 function lien_verifier_action($k, $v) {
387
-	$action = '';
388
-	if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $k)) {
389
-		$action = $k;
390
-	}
391
-	if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $v)) {
392
-		if (is_numeric($k)) {
393
-			$action = $v;
394
-		}
395
-		if (_request($k)) {
396
-			$action = $v;
397
-		}
398
-	}
399
-	// ajout un role null fictif (plus pratique) si pas défini
400
-	if ($action and count(explode('-', $action)) == 4) {
401
-		$action .= '-';
402
-	}
403
-
404
-	return $action;
387
+    $action = '';
388
+    if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $k)) {
389
+        $action = $k;
390
+    }
391
+    if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $v)) {
392
+        if (is_numeric($k)) {
393
+            $action = $v;
394
+        }
395
+        if (_request($k)) {
396
+            $action = $v;
397
+        }
398
+    }
399
+    // ajout un role null fictif (plus pratique) si pas défini
400
+    if ($action and count(explode('-', $action)) == 4) {
401
+        $action .= '-';
402
+    }
403
+
404
+    return $action;
405 405
 }
406 406
 
407 407
 
@@ -417,65 +417,65 @@  discard block
 block discarded – undo
417 417
  *   Liste des qualifs pour chaque lien. Tableau vide s'il n'y en a pas.
418 418
  **/
419 419
 function lien_retrouver_qualif($objet_lien, $lien) {
420
-	// un role est défini dans la liaison
421
-	$defs = explode('-', $lien);
422
-	list($objet1, , $objet2, , $role) = array_pad($defs, 5, null);
423
-	if ($objet_lien == $objet1) {
424
-		$colonne_role = roles_colonne($objet1, $objet2);
425
-	} else {
426
-		$colonne_role = roles_colonne($objet2, $objet1);
427
-	}
428
-
429
-	// cas ou le role est defini en 5e argument de l'action sur le lien (suppression, ajout rapide sans autre attribut)
430
-	if ($role) {
431
-		return array(
432
-			// un seul lien avec ce role
433
-			array($colonne_role => $role)
434
-		);
435
-	}
436
-
437
-	// retrouver les rôles postés pour cette liaison, s'il y en a.
438
-	$qualifier_lien = _request('qualifier_lien');
439
-	if (!$qualifier_lien or !is_array($qualifier_lien)) {
440
-		return array();
441
-	}
442
-
443
-	// pas avec l'action complete (incluant le role)
444
-	$qualif = array();
445
-	if ((!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien])
446
-		and count($defs) == 5
447
-	) {
448
-		// on tente avec l'action sans le role
449
-		array_pop($defs);
450
-		$lien = implode('-', $defs);
451
-		if (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) {
452
-			$qualif = array();
453
-		}
454
-	}
455
-
456
-	// $qualif de la forme array(role=>array(...),valeur=>array(...),....)
457
-	// on le reforme en array(array(role=>..,valeur=>..,..),array(role=>..,valeur=>..,..),...)
458
-	$qualifs = array();
459
-	while (count($qualif)) {
460
-		$q = array();
461
-		foreach ($qualif as $att => $values) {
462
-			if (is_array($values)) {
463
-				$q[$att] = array_shift($qualif[$att]);
464
-				if (!count($qualif[$att])) {
465
-					unset($qualif[$att]);
466
-				}
467
-			} else {
468
-				$q[$att] = $values;
469
-				unset($qualif[$att]);
470
-			}
471
-		}
472
-		// pas de rôle vide
473
-		if (!$colonne_role or !isset($q[$colonne_role]) or $q[$colonne_role]) {
474
-			$qualifs[] = $q;
475
-		}
476
-	}
477
-
478
-	return $qualifs;
420
+    // un role est défini dans la liaison
421
+    $defs = explode('-', $lien);
422
+    list($objet1, , $objet2, , $role) = array_pad($defs, 5, null);
423
+    if ($objet_lien == $objet1) {
424
+        $colonne_role = roles_colonne($objet1, $objet2);
425
+    } else {
426
+        $colonne_role = roles_colonne($objet2, $objet1);
427
+    }
428
+
429
+    // cas ou le role est defini en 5e argument de l'action sur le lien (suppression, ajout rapide sans autre attribut)
430
+    if ($role) {
431
+        return array(
432
+            // un seul lien avec ce role
433
+            array($colonne_role => $role)
434
+        );
435
+    }
436
+
437
+    // retrouver les rôles postés pour cette liaison, s'il y en a.
438
+    $qualifier_lien = _request('qualifier_lien');
439
+    if (!$qualifier_lien or !is_array($qualifier_lien)) {
440
+        return array();
441
+    }
442
+
443
+    // pas avec l'action complete (incluant le role)
444
+    $qualif = array();
445
+    if ((!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien])
446
+        and count($defs) == 5
447
+    ) {
448
+        // on tente avec l'action sans le role
449
+        array_pop($defs);
450
+        $lien = implode('-', $defs);
451
+        if (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) {
452
+            $qualif = array();
453
+        }
454
+    }
455
+
456
+    // $qualif de la forme array(role=>array(...),valeur=>array(...),....)
457
+    // on le reforme en array(array(role=>..,valeur=>..,..),array(role=>..,valeur=>..,..),...)
458
+    $qualifs = array();
459
+    while (count($qualif)) {
460
+        $q = array();
461
+        foreach ($qualif as $att => $values) {
462
+            if (is_array($values)) {
463
+                $q[$att] = array_shift($qualif[$att]);
464
+                if (!count($qualif[$att])) {
465
+                    unset($qualif[$att]);
466
+                }
467
+            } else {
468
+                $q[$att] = $values;
469
+                unset($qualif[$att]);
470
+            }
471
+        }
472
+        // pas de rôle vide
473
+        if (!$colonne_role or !isset($q[$colonne_role]) or $q[$colonne_role]) {
474
+            $qualifs[] = $q;
475
+        }
476
+    }
477
+
478
+    return $qualifs;
479 479
 }
480 480
 
481 481
 /**
@@ -494,12 +494,12 @@  discard block
 block discarded – undo
494 494
  **/
495 495
 function lien_ajouter_liaisons($objet_source, $ids, $objet_lien, $idl, $qualifs) {
496 496
 
497
-	// retrouver la colonne de roles s'il y en a a lier
498
-	if (is_array($qualifs) and count($qualifs)) {
499
-		foreach ($qualifs as $qualif) {
500
-			objet_associer(array($objet_source => $ids), array($objet_lien => $idl), $qualif);
501
-		}
502
-	} else {
503
-		objet_associer(array($objet_source => $ids), array($objet_lien => $idl));
504
-	}
497
+    // retrouver la colonne de roles s'il y en a a lier
498
+    if (is_array($qualifs) and count($qualifs)) {
499
+        foreach ($qualifs as $qualif) {
500
+            objet_associer(array($objet_source => $ids), array($objet_lien => $idl), $qualif);
501
+        }
502
+    } else {
503
+        objet_associer(array($objet_source => $ids), array($objet_lien => $idl));
504
+    }
505 505
 }
Please login to merge, or discard this patch.
prive/formulaires/traduire.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/actions');
@@ -39,64 +39,64 @@  discard block
 block discarded – undo
39 39
  *     Contexte à transmettre au squelette du formulaire sinon
40 40
  */
41 41
 function formulaires_traduire_charger_dist($objet, $id_objet, $retour = '', $traduire = true) {
42
-	if (!intval($id_objet)) {
43
-		return false;
44
-	}
45
-	$valeurs = formulaires_editer_objet_charger($objet, $id_objet, null, 0, $retour, '');
46
-	// verifier que l'objet indique possede bien des champs id_trad et lang
47
-	// attention, charger renomme lang => langue pour ne pas perturber la langue d'affichage du squelette
48
-	if (!isset($valeurs['langue'])) {
49
-		return false;
50
-	}
51
-
52
-	$valeurs['editable'] = autoriser('changerlangue', $objet, $id_objet);
53
-	$valeurs['_langue'] = '';
54
-	$langue_parent = '';
55
-	$id_parent = '';
56
-	if (isset($valeurs['id_rubrique'])) {
57
-		$id_parent = $valeurs['id_rubrique'];
58
-	}
59
-	if (isset($valeurs['id_parent'])) {
60
-		$id_parent = $valeurs['id_parent'];
61
-	}
62
-	if ($id_parent) {
63
-		$langue_parent = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_parent));
64
-	}
65
-
66
-	if (!$langue_parent) {
67
-		$langue_parent = $GLOBALS['meta']['langue_site'];
68
-	}
69
-	if ($valeurs['editable']
70
-		and in_array(table_objet_sql($objet), explode(',', $GLOBALS['meta']['multi_objets']))
71
-	) {
72
-		$valeurs['_langue'] = $valeurs['langue'];
73
-	}
74
-	$valeurs['langue_parent'] = $langue_parent;
75
-
76
-	$valeurs['_objet'] = $objet;
77
-	$valeurs['_id_objet'] = $id_objet;
78
-	$valeurs['changer_lang'] = '';
79
-
80
-
81
-	$valeurs['_traduisible'] = autoriser('changertraduction', $objet, $id_objet);
82
-	$valeurs['_traduire'] = '';
83
-	if (isset($valeurs['id_trad'])) {
84
-		$valeurs['_traduire'] = ($traduire ? ' ' : '');
85
-		$valeurs['_vue_traductions'] = 'prive/objets/liste/' . (trouver_fond(
86
-			$f = table_objet($objet) . '-trad',
87
-			'prive/objets/liste'
88
-		) ? $f : 'objets-trad');
89
-		// pour afficher la liste des trad sur la base de l'id_trad en base
90
-		// independamment d'une saisie en cours sur id_trad
91
-		$valeurs['_lister_id_trad'] = $valeurs['id_trad'];
92
-		$valeurs['_id_parent'] = $id_parent;
93
-	}
94
-
95
-	$valeurs['_saisie_en_cours'] = (!_request('annuler') and (_request('changer_lang') !== null
96
-		or _request('changer_id_trad') !== null));
97
-	$valeurs['_pipeline'] = array('traduire', array('type' => $objet, 'id' => $id_objet));
98
-
99
-	return $valeurs;
42
+    if (!intval($id_objet)) {
43
+        return false;
44
+    }
45
+    $valeurs = formulaires_editer_objet_charger($objet, $id_objet, null, 0, $retour, '');
46
+    // verifier que l'objet indique possede bien des champs id_trad et lang
47
+    // attention, charger renomme lang => langue pour ne pas perturber la langue d'affichage du squelette
48
+    if (!isset($valeurs['langue'])) {
49
+        return false;
50
+    }
51
+
52
+    $valeurs['editable'] = autoriser('changerlangue', $objet, $id_objet);
53
+    $valeurs['_langue'] = '';
54
+    $langue_parent = '';
55
+    $id_parent = '';
56
+    if (isset($valeurs['id_rubrique'])) {
57
+        $id_parent = $valeurs['id_rubrique'];
58
+    }
59
+    if (isset($valeurs['id_parent'])) {
60
+        $id_parent = $valeurs['id_parent'];
61
+    }
62
+    if ($id_parent) {
63
+        $langue_parent = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_parent));
64
+    }
65
+
66
+    if (!$langue_parent) {
67
+        $langue_parent = $GLOBALS['meta']['langue_site'];
68
+    }
69
+    if ($valeurs['editable']
70
+        and in_array(table_objet_sql($objet), explode(',', $GLOBALS['meta']['multi_objets']))
71
+    ) {
72
+        $valeurs['_langue'] = $valeurs['langue'];
73
+    }
74
+    $valeurs['langue_parent'] = $langue_parent;
75
+
76
+    $valeurs['_objet'] = $objet;
77
+    $valeurs['_id_objet'] = $id_objet;
78
+    $valeurs['changer_lang'] = '';
79
+
80
+
81
+    $valeurs['_traduisible'] = autoriser('changertraduction', $objet, $id_objet);
82
+    $valeurs['_traduire'] = '';
83
+    if (isset($valeurs['id_trad'])) {
84
+        $valeurs['_traduire'] = ($traduire ? ' ' : '');
85
+        $valeurs['_vue_traductions'] = 'prive/objets/liste/' . (trouver_fond(
86
+            $f = table_objet($objet) . '-trad',
87
+            'prive/objets/liste'
88
+        ) ? $f : 'objets-trad');
89
+        // pour afficher la liste des trad sur la base de l'id_trad en base
90
+        // independamment d'une saisie en cours sur id_trad
91
+        $valeurs['_lister_id_trad'] = $valeurs['id_trad'];
92
+        $valeurs['_id_parent'] = $id_parent;
93
+    }
94
+
95
+    $valeurs['_saisie_en_cours'] = (!_request('annuler') and (_request('changer_lang') !== null
96
+        or _request('changer_id_trad') !== null));
97
+    $valeurs['_pipeline'] = array('traduire', array('type' => $objet, 'id' => $id_objet));
98
+
99
+    return $valeurs;
100 100
 }
101 101
 
102 102
 /**
@@ -114,30 +114,30 @@  discard block
 block discarded – undo
114 114
  *     Erreurs des saisies
115 115
  */
116 116
 function formulaires_traduire_verifier_dist($objet, $id_objet, $retour = '', $traduire = true) {
117
-	$erreurs = array();
118
-
119
-	if (null !== _request('changer_lang')) {
120
-		$erreurs = formulaires_editer_objet_verifier($objet, $id_objet, array('changer_lang'));
121
-	}
122
-
123
-	// si id_trad fourni, verifier que cela ne conflicte pas avec un id_trad existant
124
-	// et que ca reference bien un objet existant
125
-	if ($id_trad = _request('id_trad')) {
126
-		$table_objet_sql = table_objet_sql($objet);
127
-		$_id_table_objet = id_table_objet($objet);
128
-		if (sql_getfetsel(
129
-			'id_trad',
130
-			$table_objet_sql,
131
-			"$_id_table_objet=" . intval($id_objet)
132
-		)) {
133
-			// ne devrait jamais arriver sauf concurence de saisie
134
-			$erreurs['id_trad'] = _L('Une traduction est deja referencee');
135
-		} elseif (!sql_getfetsel($_id_table_objet, $table_objet_sql, "$_id_table_objet=" . intval($id_trad))) {
136
-			$erreurs['id_trad'] = _L('Indiquez un contenu existant');
137
-		}
138
-	}
139
-
140
-	return $erreurs;
117
+    $erreurs = array();
118
+
119
+    if (null !== _request('changer_lang')) {
120
+        $erreurs = formulaires_editer_objet_verifier($objet, $id_objet, array('changer_lang'));
121
+    }
122
+
123
+    // si id_trad fourni, verifier que cela ne conflicte pas avec un id_trad existant
124
+    // et que ca reference bien un objet existant
125
+    if ($id_trad = _request('id_trad')) {
126
+        $table_objet_sql = table_objet_sql($objet);
127
+        $_id_table_objet = id_table_objet($objet);
128
+        if (sql_getfetsel(
129
+            'id_trad',
130
+            $table_objet_sql,
131
+            "$_id_table_objet=" . intval($id_objet)
132
+        )) {
133
+            // ne devrait jamais arriver sauf concurence de saisie
134
+            $erreurs['id_trad'] = _L('Une traduction est deja referencee');
135
+        } elseif (!sql_getfetsel($_id_table_objet, $table_objet_sql, "$_id_table_objet=" . intval($id_trad))) {
136
+            $erreurs['id_trad'] = _L('Indiquez un contenu existant');
137
+        }
138
+    }
139
+
140
+    return $erreurs;
141 141
 }
142 142
 
143 143
 
@@ -156,31 +156,31 @@  discard block
 block discarded – undo
156 156
  *     Retour des traitements
157 157
  */
158 158
 function formulaires_traduire_traiter_dist($objet, $id_objet, $retour = '', $traduire = true) {
159
-	$res = array();
160
-	if (!_request('annuler') and autoriser('changerlangue', $objet, $id_objet)) {
161
-		// action/editer_xxx doit traiter la modif de changer_lang
162
-		$res = formulaires_editer_objet_traiter($objet, $id_objet, 0, 0, $retour);
163
-	}
164
-	if (!_request('annuler') and autoriser('changertraduction', $objet, $id_objet)) {
165
-		if ($id_trad = _request('id_trad') or _request('supprimer_trad')) {
166
-			$referencer_traduction = charger_fonction('referencer_traduction', 'action');
167
-			$referencer_traduction($objet, $id_objet, intval($id_trad)); // 0 si supprimer_trad
168
-		} elseif ($new_id_trad = _request('changer_reference_trad')
169
-			and $new_id_trad = array_keys($new_id_trad)
170
-			and $new_id_trad = reset($new_id_trad)
171
-		) {
172
-			$table_objet_sql = table_objet_sql($objet);
173
-			$_id_table_objet = id_table_objet($objet);
174
-			if ($id_trad = sql_getfetsel('id_trad', $table_objet_sql, "$_id_table_objet=" . intval($id_objet))) {
175
-				$referencer_traduction = charger_fonction('referencer_traduction', 'action');
176
-				$referencer_traduction($objet, $id_trad, $new_id_trad);
177
-			}
178
-		}
179
-	}
180
-	$res['editable'] = true;
181
-	if (!isset($res['message_erreur'])) {
182
-		set_request('annuler', 'annuler');
183
-	} // provoquer la fermeture du forumlaire
184
-
185
-	return $res;
159
+    $res = array();
160
+    if (!_request('annuler') and autoriser('changerlangue', $objet, $id_objet)) {
161
+        // action/editer_xxx doit traiter la modif de changer_lang
162
+        $res = formulaires_editer_objet_traiter($objet, $id_objet, 0, 0, $retour);
163
+    }
164
+    if (!_request('annuler') and autoriser('changertraduction', $objet, $id_objet)) {
165
+        if ($id_trad = _request('id_trad') or _request('supprimer_trad')) {
166
+            $referencer_traduction = charger_fonction('referencer_traduction', 'action');
167
+            $referencer_traduction($objet, $id_objet, intval($id_trad)); // 0 si supprimer_trad
168
+        } elseif ($new_id_trad = _request('changer_reference_trad')
169
+            and $new_id_trad = array_keys($new_id_trad)
170
+            and $new_id_trad = reset($new_id_trad)
171
+        ) {
172
+            $table_objet_sql = table_objet_sql($objet);
173
+            $_id_table_objet = id_table_objet($objet);
174
+            if ($id_trad = sql_getfetsel('id_trad', $table_objet_sql, "$_id_table_objet=" . intval($id_objet))) {
175
+                $referencer_traduction = charger_fonction('referencer_traduction', 'action');
176
+                $referencer_traduction($objet, $id_trad, $new_id_trad);
177
+            }
178
+        }
179
+    }
180
+    $res['editable'] = true;
181
+    if (!isset($res['message_erreur'])) {
182
+        set_request('annuler', 'annuler');
183
+    } // provoquer la fermeture du forumlaire
184
+
185
+    return $res;
186 186
 }
Please login to merge, or discard this patch.
ecrire/index.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -19,14 +19,14 @@  discard block
 block discarded – undo
19 19
 /** Drapeau indiquant que l'on est dans l'espace privé */
20 20
 define('_ESPACE_PRIVE', true);
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	include 'inc_version.php';
22
+    include 'inc_version.php';
23 23
 }
24 24
 
25 25
 // Verification anti magic_quotes_sybase, pour qui addslashes("'") = "''"
26 26
 // On prefere la faire ici plutot que dans inc_version, c'est moins souvent et
27 27
 // si le reglage est modifie sur un site en prod, ca fait moins mal
28 28
 if (addslashes("'") !== "\\'") {
29
-	die('SPIP incompatible magic_quotes_sybase');
29
+    die('SPIP incompatible magic_quotes_sybase');
30 30
 }
31 31
 
32 32
 include_spip('inc/cookie');
@@ -42,18 +42,18 @@  discard block
 block discarded – undo
42 42
 // alors il faut blinder les variables d'URL
43 43
 //
44 44
 if (autoriser_sans_cookie($exec, false)) {
45
-	if (!isset($reinstall)) {
46
-		$reinstall = 'non';
47
-	}
48
-	$var_auth = true;
45
+    if (!isset($reinstall)) {
46
+        $reinstall = 'non';
47
+    }
48
+    $var_auth = true;
49 49
 } else {
50
-	// Authentification, redefinissable
51
-	$auth = charger_fonction('auth', 'inc');
52
-	$var_auth = $auth();
53
-	if ($var_auth) {
54
-		echo auth_echec($var_auth);
55
-		exit;
56
-	}
50
+    // Authentification, redefinissable
51
+    $auth = charger_fonction('auth', 'inc');
52
+    $var_auth = $auth();
53
+    if ($var_auth) {
54
+        echo auth_echec($var_auth);
55
+        exit;
56
+    }
57 57
 }
58 58
 
59 59
 // initialiser a la langue par defaut
@@ -64,29 +64,29 @@  discard block
 block discarded – undo
64 64
 
65 65
 
66 66
 if (_request('action') or _request('var_ajax') or _request('formulaire_action')) {
67
-	if (!autoriser_sans_cookie($exec)){
68
-		// Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires
69
-		include_spip('public/aiguiller');
70
-		if (
71
-			// cas des appels actions ?action=xxx
72
-			traiter_appels_actions()
73
-			or
74
-			// cas des hits ajax sur les inclusions ajax
75
-			traiter_appels_inclusions_ajax()
76
-			or
77
-			// cas des formulaires charger/verifier/traiter
78
-			traiter_formulaires_dynamiques()
79
-		){
80
-			exit;
81
-		} // le hit est fini !
82
-	}
67
+    if (!autoriser_sans_cookie($exec)){
68
+        // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires
69
+        include_spip('public/aiguiller');
70
+        if (
71
+            // cas des appels actions ?action=xxx
72
+            traiter_appels_actions()
73
+            or
74
+            // cas des hits ajax sur les inclusions ajax
75
+            traiter_appels_inclusions_ajax()
76
+            or
77
+            // cas des formulaires charger/verifier/traiter
78
+            traiter_formulaires_dynamiques()
79
+        ){
80
+            exit;
81
+        } // le hit est fini !
82
+    }
83 83
 }
84 84
 // securiser les redirect du back-office
85 85
 if (_request('redirect')) {
86
-	if (!function_exists('securiser_redirect_action')){
87
-		include_spip('public/aiguiller');
88
-	}
89
-	set_request('redirect',securiser_redirect_action(_request('redirect')));
86
+    if (!function_exists('securiser_redirect_action')){
87
+        include_spip('public/aiguiller');
88
+    }
89
+    set_request('redirect',securiser_redirect_action(_request('redirect')));
90 90
 }
91 91
 
92 92
 
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
 
97 97
 // Controle de la version, sauf si on est deja en train de s'en occuper
98 98
 if (!$reinstall == 'oui'
99
-	and !_AJAX
100
-	and isset($GLOBALS['meta']['version_installee'])
101
-	and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee'])))
99
+    and !_AJAX
100
+    and isset($GLOBALS['meta']['version_installee'])
101
+    and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee'])))
102 102
 ) {
103
-	$exec = 'demande_mise_a_jour';
103
+    $exec = 'demande_mise_a_jour';
104 104
 }
105 105
 
106 106
 // Quand une action d'administration est en cours (meta "admin"),
@@ -110,44 +110,44 @@  discard block
 block discarded – undo
110 110
 // sinon c'est qu'elle a ete interrompue et il faut la reprendre
111 111
 
112 112
 elseif (isset($GLOBALS['meta']["admin"])) {
113
-	if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']["admin"], $l)) {
114
-		list(, $var_f, $n) = $l;
115
-	}
116
-	if (_AJAX
117
-		or !(
118
-			isset($_COOKIE['spip_admin'])
119
-			or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo')
120
-		)
121
-	) {
122
-		spip_log("Quand la meta admin vaut " .
123
-			$GLOBALS['meta']["admin"] .
124
-			" seul un admin peut se connecter et sans AJAX." .
125
-			" En cas de probleme, detruire cette meta.");
126
-		die(_T('info_travaux_texte'));
127
-	}
128
-	if ($n) {
129
-		list(, $var_f, $n) = $l;
130
-		if (tester_url_ecrire("base_$var_f")) {
131
-			$var_f = "base_$var_f";
132
-		}
133
-		if ($var_f != $exec) {
134
-			spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec");
135
-			$exec = $var_f;
136
-			set_request('exec', $exec);
137
-		}
138
-	}
113
+    if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']["admin"], $l)) {
114
+        list(, $var_f, $n) = $l;
115
+    }
116
+    if (_AJAX
117
+        or !(
118
+            isset($_COOKIE['spip_admin'])
119
+            or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo')
120
+        )
121
+    ) {
122
+        spip_log("Quand la meta admin vaut " .
123
+            $GLOBALS['meta']["admin"] .
124
+            " seul un admin peut se connecter et sans AJAX." .
125
+            " En cas de probleme, detruire cette meta.");
126
+        die(_T('info_travaux_texte'));
127
+    }
128
+    if ($n) {
129
+        list(, $var_f, $n) = $l;
130
+        if (tester_url_ecrire("base_$var_f")) {
131
+            $var_f = "base_$var_f";
132
+        }
133
+        if ($var_f != $exec) {
134
+            spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec");
135
+            $exec = $var_f;
136
+            set_request('exec', $exec);
137
+        }
138
+    }
139 139
 }
140 140
 // si nom pas plausible, prendre le script par defaut
141 141
 // attention aux deux cas 404/403 qui commencent par un 4 !
142 142
 elseif (!preg_match(',^[a-z4_][0-9a-z_-]*$,i', $exec)) {
143
-	$exec = "accueil";
144
-	set_request('exec', $exec);
143
+    $exec = "accueil";
144
+    set_request('exec', $exec);
145 145
 }
146 146
 
147 147
 // compatibilite ascendante : obsolete, ne plus utiliser
148 148
 $GLOBALS['spip_display'] = isset($GLOBALS['visiteur_session']['prefs']['display'])
149
-	? (int) $GLOBALS['visiteur_session']['prefs']['display']
150
-	: 0;
149
+    ? (int) $GLOBALS['visiteur_session']['prefs']['display']
150
+    : 0;
151 151
 $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? preg_replace('/[^a-z0-9]/i', '', $_COOKIE['spip_ecran']) : "etroit";
152 152
 
153 153
 //  si la langue est specifiee par cookie et ne correspond pas
@@ -155,18 +155,18 @@  discard block
 block discarded – undo
155 155
 // on appelle directement la fonction, car un appel d'action peut conduire a une boucle infinie
156 156
 // si le cookie n'est pas pose correctement dans l'action
157 157
 if (!$var_auth and isset($_COOKIE['spip_lang_ecrire'])
158
-	and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang']
158
+    and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang']
159 159
 ) {
160
-	include_spip('action/converser');
161
-	action_converser_post($GLOBALS['visiteur_session']['lang'], true);
160
+    include_spip('action/converser');
161
+    action_converser_post($GLOBALS['visiteur_session']['lang'], true);
162 162
 }
163 163
 
164 164
 if ($var_f = tester_url_ecrire($exec)) {
165
-	$var_f = charger_fonction($var_f);
166
-	$var_f(); // at last
165
+    $var_f = charger_fonction($var_f);
166
+    $var_f(); // at last
167 167
 } else {
168
-	// Rien de connu: rerouter vers exec=404 au lieu d'echouer
169
-	// ce qui permet de laisser la main a un plugin
170
-	$var_f = charger_fonction('404');
171
-	$var_f($exec);
168
+    // Rien de connu: rerouter vers exec=404 au lieu d'echouer
169
+    // ce qui permet de laisser la main a un plugin
170
+    $var_f = charger_fonction('404');
171
+    $var_f($exec);
172 172
 }
Please login to merge, or discard this patch.
ecrire/inc/prepare_recherche.php 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/rechercher');
24 24
 if (!defined('_DELAI_CACHE_resultats')) {
25
-	define('_DELAI_CACHE_resultats', 600);
25
+    define('_DELAI_CACHE_resultats', 600);
26 26
 }
27 27
 
28 28
 /**
@@ -49,111 +49,111 @@  discard block
 block discarded – undo
49 49
  * @return array
50 50
  */
51 51
 function inc_prepare_recherche_dist(
52
-	$recherche,
53
-	$table = 'articles',
54
-	$cond = false,
55
-	$serveur = '',
56
-	$modificateurs = array(),
57
-	$primary = ''
52
+    $recherche,
53
+    $table = 'articles',
54
+    $cond = false,
55
+    $serveur = '',
56
+    $modificateurs = array(),
57
+    $primary = ''
58 58
 ) {
59
-	static $cache = array();
60
-	$delai_fraicheur = min(_DELAI_CACHE_resultats,
61
-		time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0));
62
-
63
-	// si recherche n'est pas dans le contexte, on va prendre en globals
64
-	// ca permet de faire des inclure simple.
65
-	if (!isset($recherche) and isset($GLOBALS['recherche'])) {
66
-		$recherche = $GLOBALS['recherche'];
67
-	}
68
-
69
-	// traiter le cas {recherche?}
70
-	if ($cond and !strlen($recherche)) {
71
-		return array(
72
-			"0 as points" /* as points */, /* where */
73
-			''
74
-		);
75
-	}
76
-
77
-
78
-	$rechercher = false;
79
-
80
-	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND");
81
-	if (!isset($cache[$serveur][$table][$recherche])) {
82
-		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
83
-		$hash = substr(md5($recherche . $table), 0, 16);
84
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
85
-		$row = sql_fetsel('recherche', 'spip_resultats AS resultats',
86
-			$where . " AND $where_resultat_recent", '', '', '0,1');
87
-		if (!$row
88
-			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
89
-		) {
90
-			$rechercher = true;
91
-		}
92
-	}
93
-
94
-	// si on n'a pas encore traite les donnees dans une boucle precedente
95
-	if ($rechercher) {
96
-		//$tables = liste_des_champs();
97
-		$x = objet_type($table);
98
-		$points = recherche_en_base($recherche,
99
-			$x,
100
-			array(
101
-				'score' => true,
102
-				'toutvoir' => true,
103
-				'jointures' => true
104
-			),
105
-			$serveur);
106
-		// pas de résultat, pas de point
107
-		$points = isset($points[$x]) ? $points[$x] : array();
108
-
109
-		// permettre aux plugins de modifier le resultat
110
-		$points = pipeline('prepare_recherche', array(
111
-			'args' => array(
112
-				'type' => $x,
113
-				'recherche' => $recherche,
114
-				'serveur' => $serveur,
115
-				'modificateurs' => $modificateurs
116
-			),
117
-			'data' => $points
118
-		));
119
-
120
-		// supprimer les anciens resultats de cette recherche
121
-		// et les resultats trop vieux avec une marge
122
-		// pas de AS resultats dans un delete (mysql)
123
-		$whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"),
124
-			array("recherche", "table_objet", "serveur"), $where);
125
-
126
-		sql_delete('spip_resultats',
127
-			"NOT($where_resultat_recent) OR ($whered)");
128
-
129
-		// inserer les resultats dans la table de cache des resultats
130
-		if (count($points)) {
131
-			$tab_couples = array();
132
-			foreach ($points as $id => $p) {
133
-				$tab_couples[] = array(
134
-					'recherche' => $hash,
135
-					'id' => $id,
136
-					'points' => $p['score'],
137
-					'table_objet' => $table,
138
-					'serveur' => $hash_serv,
139
-				);
140
-			}
141
-			sql_insertq_multi('spip_resultats', $tab_couples, array());
142
-		}
143
-	}
144
-
145
-	if (!isset($cache[$serveur][$table][$recherche])) {
146
-		if (!$serveur) {
147
-			$cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where);
148
-		} else {
149
-			if (sql_countsel('spip_resultats as resultats', $where)) {
150
-				$rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
151
-			}
152
-			$cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
153
-		}
154
-	}
155
-
156
-	return $cache[$serveur][$table][$recherche];
59
+    static $cache = array();
60
+    $delai_fraicheur = min(_DELAI_CACHE_resultats,
61
+        time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0));
62
+
63
+    // si recherche n'est pas dans le contexte, on va prendre en globals
64
+    // ca permet de faire des inclure simple.
65
+    if (!isset($recherche) and isset($GLOBALS['recherche'])) {
66
+        $recherche = $GLOBALS['recherche'];
67
+    }
68
+
69
+    // traiter le cas {recherche?}
70
+    if ($cond and !strlen($recherche)) {
71
+        return array(
72
+            "0 as points" /* as points */, /* where */
73
+            ''
74
+        );
75
+    }
76
+
77
+
78
+    $rechercher = false;
79
+
80
+    $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND");
81
+    if (!isset($cache[$serveur][$table][$recherche])) {
82
+        $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
83
+        $hash = substr(md5($recherche . $table), 0, 16);
84
+        $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
85
+        $row = sql_fetsel('recherche', 'spip_resultats AS resultats',
86
+            $where . " AND $where_resultat_recent", '', '', '0,1');
87
+        if (!$row
88
+            or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
89
+        ) {
90
+            $rechercher = true;
91
+        }
92
+    }
93
+
94
+    // si on n'a pas encore traite les donnees dans une boucle precedente
95
+    if ($rechercher) {
96
+        //$tables = liste_des_champs();
97
+        $x = objet_type($table);
98
+        $points = recherche_en_base($recherche,
99
+            $x,
100
+            array(
101
+                'score' => true,
102
+                'toutvoir' => true,
103
+                'jointures' => true
104
+            ),
105
+            $serveur);
106
+        // pas de résultat, pas de point
107
+        $points = isset($points[$x]) ? $points[$x] : array();
108
+
109
+        // permettre aux plugins de modifier le resultat
110
+        $points = pipeline('prepare_recherche', array(
111
+            'args' => array(
112
+                'type' => $x,
113
+                'recherche' => $recherche,
114
+                'serveur' => $serveur,
115
+                'modificateurs' => $modificateurs
116
+            ),
117
+            'data' => $points
118
+        ));
119
+
120
+        // supprimer les anciens resultats de cette recherche
121
+        // et les resultats trop vieux avec une marge
122
+        // pas de AS resultats dans un delete (mysql)
123
+        $whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"),
124
+            array("recherche", "table_objet", "serveur"), $where);
125
+
126
+        sql_delete('spip_resultats',
127
+            "NOT($where_resultat_recent) OR ($whered)");
128
+
129
+        // inserer les resultats dans la table de cache des resultats
130
+        if (count($points)) {
131
+            $tab_couples = array();
132
+            foreach ($points as $id => $p) {
133
+                $tab_couples[] = array(
134
+                    'recherche' => $hash,
135
+                    'id' => $id,
136
+                    'points' => $p['score'],
137
+                    'table_objet' => $table,
138
+                    'serveur' => $hash_serv,
139
+                );
140
+            }
141
+            sql_insertq_multi('spip_resultats', $tab_couples, array());
142
+        }
143
+    }
144
+
145
+    if (!isset($cache[$serveur][$table][$recherche])) {
146
+        if (!$serveur) {
147
+            $cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where);
148
+        } else {
149
+            if (sql_countsel('spip_resultats as resultats', $where)) {
150
+                $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
151
+            }
152
+            $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
153
+        }
154
+    }
155
+
156
+    return $cache[$serveur][$table][$recherche];
157 157
 }
158 158
 
159 159
 
@@ -169,22 +169,22 @@  discard block
 block discarded – undo
169 169
  * @return array
170 170
  */
171 171
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
172
-	# calculer le {id_article IN()} et le {... as points}
173
-	if (!count($rows)) {
174
-		return array("''", "0=1");
175
-	} else {
176
-		$listes_ids = array();
177
-		$select = '0';
178
-		foreach ($rows as $r) {
179
-			$listes_ids[$r['points']][] = $r['id'];
180
-		}
181
-
182
-		foreach ($listes_ids as $p => $ids) {
183
-			$select .= "+$p*(" .
184
-				sql_in("$table.$primary", $ids, '', $serveur)
185
-				. ") ";
186
-		}
187
-
188
-		return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur));
189
-	}
172
+    # calculer le {id_article IN()} et le {... as points}
173
+    if (!count($rows)) {
174
+        return array("''", "0=1");
175
+    } else {
176
+        $listes_ids = array();
177
+        $select = '0';
178
+        foreach ($rows as $r) {
179
+            $listes_ids[$r['points']][] = $r['id'];
180
+        }
181
+
182
+        foreach ($listes_ids as $p => $ids) {
183
+            $select .= "+$p*(" .
184
+                sql_in("$table.$primary", $ids, '', $serveur)
185
+                . ") ";
186
+        }
187
+
188
+        return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur));
189
+    }
190 190
 }
Please login to merge, or discard this patch.
ecrire/action/editer_logo.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -30,35 +30,35 @@  discard block
 block discarded – undo
30 30
  *     `on` ou `off`
31 31
  */
32 32
 function logo_supprimer($objet, $id_objet, $etat) {
33
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
34
-	$objet = objet_type($objet);
35
-	$primary = id_table_objet($objet);
36
-	include_spip('inc/chercher_logo');
37
-
38
-	// existe-t-il deja un logo ?
39
-	$logo = $chercher_logo($id_objet, $primary, $etat);
40
-	if ($logo) {
41
-		# TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base
42
-		if (count($logo) < 6) {
43
-			spip_log("Supprimer ancien logo $logo", 'logo');
44
-			spip_unlink($logo[0]);
45
-		}
46
-		elseif ($doc = $logo[5]
47
-			and isset($doc['id_document'])
48
-		  and $id_document = $doc['id_document']) {
49
-
50
-			include_spip('action/editer_liens');
51
-			// supprimer le lien dans la base
52
-			objet_dissocier(array('document' => $id_document), array($objet => $id_objet), array('role' => '*'));
53
-
54
-			// verifier si il reste des liens avec d'autres objets et sinon supprimer
55
-			$liens = objet_trouver_liens(array('document' => $id_document), '*');
56
-			if (!count($liens)) {
57
-				$supprimer_document = charger_fonction('supprimer_document', 'action');
58
-				$supprimer_document($doc['id_document']);
59
-			}
60
-		}
61
-	}
33
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
34
+    $objet = objet_type($objet);
35
+    $primary = id_table_objet($objet);
36
+    include_spip('inc/chercher_logo');
37
+
38
+    // existe-t-il deja un logo ?
39
+    $logo = $chercher_logo($id_objet, $primary, $etat);
40
+    if ($logo) {
41
+        # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base
42
+        if (count($logo) < 6) {
43
+            spip_log("Supprimer ancien logo $logo", 'logo');
44
+            spip_unlink($logo[0]);
45
+        }
46
+        elseif ($doc = $logo[5]
47
+            and isset($doc['id_document'])
48
+          and $id_document = $doc['id_document']) {
49
+
50
+            include_spip('action/editer_liens');
51
+            // supprimer le lien dans la base
52
+            objet_dissocier(array('document' => $id_document), array($objet => $id_objet), array('role' => '*'));
53
+
54
+            // verifier si il reste des liens avec d'autres objets et sinon supprimer
55
+            $liens = objet_trouver_liens(array('document' => $id_document), '*');
56
+            if (!count($liens)) {
57
+                $supprimer_document = charger_fonction('supprimer_document', 'action');
58
+                $supprimer_document($doc['id_document']);
59
+            }
60
+        }
61
+    }
62 62
 }
63 63
 
64 64
 /**
@@ -75,133 +75,133 @@  discard block
 block discarded – undo
75 75
  *     Erreur, sinon ''
76 76
  */
77 77
 function logo_modifier($objet, $id_objet, $etat, $source) {
78
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
79
-	$objet = objet_type($objet);
80
-	$primary = id_table_objet($objet);
81
-	include_spip('inc/chercher_logo');
82
-
83
-	$mode = preg_replace(",\W,", '', $etat);
84
-	if (!$mode){
85
-		spip_log("logo_modifier : etat $etat invalide", 'logo');
86
-		$erreur = 'etat invalide';
87
-
88
-		return $erreur;
89
-	}
90
-	// chercher dans la base
91
-	$mode_document = 'logo' . $mode;
92
-
93
-	include_spip('inc/documents');
94
-	$erreur = '';
95
-
96
-	if (!$source) {
97
-		spip_log('spip_image_ajouter : source inconnue', 'logo');
98
-		$erreur = 'source inconnue';
99
-
100
-		return $erreur;
101
-	}
102
-
103
-	// fichier dans upload/
104
-	if (is_string($source)) {
105
-		$tmp_name = false;
106
-		if (file_exists($source)) {
107
-			$tmp_name = $source;
108
-		} elseif (file_exists($f = determine_upload() . $source)) {
109
-			$tmp_name = $f;
110
-		}
111
-		if (!$tmp_name) {
112
-			spip_log('spip_image_ajouter : source inconnue', 'logo');
113
-			$erreur = 'source inconnue';
114
-
115
-			return $erreur;
116
-		}
117
-		$source = array(
118
-			'tmp_name' => $tmp_name,
119
-			'name' => basename($tmp_name),
120
-		);
121
-	} elseif ($erreur = check_upload_error($source['error'], '', true)) {
122
-		return $erreur;
123
-	}
124
-
125
-	// supprimer le logo eventueel existant
126
-	// TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple)
127
-	// mais de toute facon l'interface actuelle oblige a supprimer + reinserer
128
-	logo_supprimer($objet, $id_objet, $etat);
129
-
130
-
131
-	include_spip('inc/autoriser');
132
-	$source['mode'] = $mode_document;
133
-	$ajouter_documents = charger_fonction('ajouter_documents', 'action');
134
-	autoriser_exception('associerdocuments', $objet, $id_objet);
135
-	$ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document);
136
-	autoriser_exception('associerdocuments', $objet, $id_objet, false);
137
-
138
-	$id_document = reset($ajoutes);
139
-
140
-	if (!is_numeric($id_document)) {
141
-		$erreur = ($id_document ? $id_document : 'Erreur inconnue');
142
-		spip_log("Erreur ajout logo : $erreur pour source=".json_encode($source), 'logo');
143
-		return $erreur;
144
-	}
145
-
146
-	return ''; // tout est bon, pas d'erreur
78
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
79
+    $objet = objet_type($objet);
80
+    $primary = id_table_objet($objet);
81
+    include_spip('inc/chercher_logo');
82
+
83
+    $mode = preg_replace(",\W,", '', $etat);
84
+    if (!$mode){
85
+        spip_log("logo_modifier : etat $etat invalide", 'logo');
86
+        $erreur = 'etat invalide';
87
+
88
+        return $erreur;
89
+    }
90
+    // chercher dans la base
91
+    $mode_document = 'logo' . $mode;
92
+
93
+    include_spip('inc/documents');
94
+    $erreur = '';
95
+
96
+    if (!$source) {
97
+        spip_log('spip_image_ajouter : source inconnue', 'logo');
98
+        $erreur = 'source inconnue';
99
+
100
+        return $erreur;
101
+    }
102
+
103
+    // fichier dans upload/
104
+    if (is_string($source)) {
105
+        $tmp_name = false;
106
+        if (file_exists($source)) {
107
+            $tmp_name = $source;
108
+        } elseif (file_exists($f = determine_upload() . $source)) {
109
+            $tmp_name = $f;
110
+        }
111
+        if (!$tmp_name) {
112
+            spip_log('spip_image_ajouter : source inconnue', 'logo');
113
+            $erreur = 'source inconnue';
114
+
115
+            return $erreur;
116
+        }
117
+        $source = array(
118
+            'tmp_name' => $tmp_name,
119
+            'name' => basename($tmp_name),
120
+        );
121
+    } elseif ($erreur = check_upload_error($source['error'], '', true)) {
122
+        return $erreur;
123
+    }
124
+
125
+    // supprimer le logo eventueel existant
126
+    // TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple)
127
+    // mais de toute facon l'interface actuelle oblige a supprimer + reinserer
128
+    logo_supprimer($objet, $id_objet, $etat);
129
+
130
+
131
+    include_spip('inc/autoriser');
132
+    $source['mode'] = $mode_document;
133
+    $ajouter_documents = charger_fonction('ajouter_documents', 'action');
134
+    autoriser_exception('associerdocuments', $objet, $id_objet);
135
+    $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document);
136
+    autoriser_exception('associerdocuments', $objet, $id_objet, false);
137
+
138
+    $id_document = reset($ajoutes);
139
+
140
+    if (!is_numeric($id_document)) {
141
+        $erreur = ($id_document ? $id_document : 'Erreur inconnue');
142
+        spip_log("Erreur ajout logo : $erreur pour source=".json_encode($source), 'logo');
143
+        return $erreur;
144
+    }
145
+
146
+    return ''; // tout est bon, pas d'erreur
147 147
 
148 148
 }
149 149
 
150 150
 function logo_migrer_en_base($objet, $time_limit) {
151 151
 
152
-	$dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs');
153
-	$dir_logos = sous_repertoire(_DIR_IMG, 'logo');
154
-	$formats_logos = array('jpg', 'png', 'svg', 'gif');
155
-	if (isset($GLOBALS['formats_logos'])) {
156
-		$formats_logos = $GLOBALS['formats_logos'];
157
-	}
158
-
159
-
160
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
161
-	include_spip('inc/chercher_logo');
162
-	$_id_objet = id_table_objet($objet);
163
-	$type = type_du_logo($_id_objet);
164
-
165
-	foreach (['on', 'off'] as $mode) {
166
-		$nom_base = $type . $mode;
167
-		$dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG);
168
-
169
-		$deja = array();
170
-		$files = glob($dir . $nom_base . "*");
171
-
172
-		foreach ($files as $file) {
173
-			$logo = substr($file, strlen($dir . $nom_base));
174
-			$logo = explode('.', $logo);
175
-			if (is_numeric($logo[0])
176
-			  and ($id_objet = intval($logo[0]) or in_array($objet, ['site', 'rubrique']))) {
177
-				if (!isset($deja[$id_objet])) {
178
-					$logo = $chercher_logo($id_objet, $_id_objet, $mode);
179
-					// if no logo in base
180
-					if (!$logo or count($logo)<6) {
181
-						foreach ($formats_logos as $format) {
182
-							if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) {
183
-								// logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre
184
-								@rename($d, $dir_logos . $nom);
185
-								// et on le declare comme nouveau logo
186
-								logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom);
187
-								break;
188
-							}
189
-						}
190
-					}
191
-					$deja[$id_objet] = true;
192
-				}
193
-			}
194
-			// si le fichier est encore la on le move : rien a faire ici
195
-			if (file_exists($file)) {
196
-				@rename($file, $dir_logos_erreurs . basename($file));
197
-			}
198
-
199
-			if ($time_limit and time() > $time_limit) {
200
-				effacer_meta('drapeau_edition');
201
-				return;
202
-			}
203
-		}
204
-
205
-	}
206
-	effacer_meta('drapeau_edition');
152
+    $dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs');
153
+    $dir_logos = sous_repertoire(_DIR_IMG, 'logo');
154
+    $formats_logos = array('jpg', 'png', 'svg', 'gif');
155
+    if (isset($GLOBALS['formats_logos'])) {
156
+        $formats_logos = $GLOBALS['formats_logos'];
157
+    }
158
+
159
+
160
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
161
+    include_spip('inc/chercher_logo');
162
+    $_id_objet = id_table_objet($objet);
163
+    $type = type_du_logo($_id_objet);
164
+
165
+    foreach (['on', 'off'] as $mode) {
166
+        $nom_base = $type . $mode;
167
+        $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG);
168
+
169
+        $deja = array();
170
+        $files = glob($dir . $nom_base . "*");
171
+
172
+        foreach ($files as $file) {
173
+            $logo = substr($file, strlen($dir . $nom_base));
174
+            $logo = explode('.', $logo);
175
+            if (is_numeric($logo[0])
176
+              and ($id_objet = intval($logo[0]) or in_array($objet, ['site', 'rubrique']))) {
177
+                if (!isset($deja[$id_objet])) {
178
+                    $logo = $chercher_logo($id_objet, $_id_objet, $mode);
179
+                    // if no logo in base
180
+                    if (!$logo or count($logo)<6) {
181
+                        foreach ($formats_logos as $format) {
182
+                            if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) {
183
+                                // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre
184
+                                @rename($d, $dir_logos . $nom);
185
+                                // et on le declare comme nouveau logo
186
+                                logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom);
187
+                                break;
188
+                            }
189
+                        }
190
+                    }
191
+                    $deja[$id_objet] = true;
192
+                }
193
+            }
194
+            // si le fichier est encore la on le move : rien a faire ici
195
+            if (file_exists($file)) {
196
+                @rename($file, $dir_logos_erreurs . basename($file));
197
+            }
198
+
199
+            if ($time_limit and time() > $time_limit) {
200
+                effacer_meta('drapeau_edition');
201
+                return;
202
+            }
203
+        }
204
+
205
+    }
206
+    effacer_meta('drapeau_edition');
207 207
 }
208 208
\ No newline at end of file
Please login to merge, or discard this patch.
ecrire/base/trouver_table.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\SQL\Tables
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 include_spip('base/objets');
22 22
 
@@ -64,141 +64,141 @@  discard block
 block discarded – undo
64 64
  *
65 65
  **/
66 66
 function base_trouver_table_dist($nom, $serveur = '', $table_spip = true) {
67
-	static $nom_cache_desc_sql = array();
68
-
69
-	if (!spip_connect($serveur)
70
-		or !preg_match('/^[a-zA-Z0-9._-]*/', $nom)
71
-	) {
72
-		return null;
73
-	}
74
-
75
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
76
-	$objets_sql = lister_tables_objets_sql("::md5");
77
-
78
-	// le nom du cache depend du serveur mais aussi du nom de la db et du prefixe
79
-	// ce qui permet une auto invalidation en cas de modif manuelle du fichier
80
-	// de connexion, et tout risque d'ambiguite
81
-	if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) {
82
-		$nom_cache_desc_sql[$serveur][$objets_sql] =
83
-			_DIR_CACHE . 'sql_desc_'
84
-			. ($serveur ? "{$serveur}_" : "")
85
-			. substr(md5($connexion['db'] . ":" . $connexion['prefixe'] . ":$objets_sql"), 0, 8)
86
-			. '.txt';
87
-		// nouveau nom de cache = nouvelle version en memoire
88
-		unset($connexion['tables']);
89
-	}
90
-
91
-	// un appel avec $nom vide est une demande explicite de vidange du cache des descriptions
92
-	if (!$nom) {
93
-		spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]);
94
-		$connexion['tables'] = array();
95
-
96
-		return null;
97
-	}
98
-
99
-	$nom_sql = $nom;
100
-	if (preg_match('/\.(.*)$/', $nom, $s)) {
101
-		$nom_sql = $s[1];
102
-	} else {
103
-		$nom_sql = $nom;
104
-	}
105
-
106
-	$fdesc = $desc = '';
107
-	$connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0];
108
-
109
-	// base sous SPIP: gerer les abreviations explicites des noms de table
110
-	if ($connexion['spip_connect_version']) {
111
-		if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) {
112
-			$nom = $GLOBALS['table_des_tables'][$nom];
113
-			$nom_sql = 'spip_' . $nom;
114
-		}
115
-	}
116
-
117
-	// si c'est la premiere table qu'on cherche
118
-	// et si on est pas explicitement en recalcul
119
-	// on essaye de recharger le cache des decriptions de ce serveur
120
-	// dans le fichier cache
121
-	if (!isset($connexion['tables'][$nom_sql])
122
-		and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul'
123
-		and (!isset($connexion['tables']) or !$connexion['tables'])
124
-	) {
125
-		if (lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache)
126
-			and $desc_cache = unserialize($desc_cache)
127
-		) {
128
-			$connexion['tables'] = $desc_cache;
129
-		}
130
-	}
131
-	if ($table_spip and !isset($connexion['tables'][$nom_sql])) {
132
-
133
-		if (isset($GLOBALS['tables_principales'][$nom_sql])) {
134
-			$fdesc = $GLOBALS['tables_principales'][$nom_sql];
135
-		}
136
-		// meme si pas d'abreviation declaree, trouver la table spip_$nom
137
-		// si c'est une table principale,
138
-		// puisqu'on le fait aussi pour les tables auxiliaires
139
-		elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) {
140
-			$nom_sql = 'spip_' . $nom;
141
-			$fdesc = &$GLOBALS['tables_principales'][$nom_sql];
142
-		} elseif (isset($GLOBALS['tables_auxiliaires'][$n = $nom])
143
-			or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom])
144
-		) {
145
-			$nom_sql = $n;
146
-			$fdesc = &$GLOBALS['tables_auxiliaires'][$n];
147
-		}  # table locale a cote de SPIP, comme non SPIP:
148
-	}
149
-	if (!isset($connexion['tables'][$nom_sql])) {
150
-
151
-		// La *vraie* base a la priorite
152
-		$desc = sql_showtable($nom_sql, $table_spip, $serveur);
153
-		if (!$desc or !$desc['field']) {
154
-			if (!$fdesc) {
155
-				spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . _LOG_INFO_IMPORTANTE);
156
-
157
-				return null;
158
-			}
159
-			// on ne sait pas lire la structure de la table :
160
-			// on retombe sur la description donnee dans les fichiers spip
161
-			$desc = $fdesc;
162
-			$desc['exist'] = false;
163
-		} else {
164
-			$desc['exist'] = true;
165
-			// gerer le cas des cles vides (echec de l'analyse sur une vue par exemple)
166
-			// pour recuperer la declaration de lister_tables_objets_sql() si il y en a une
167
-			if (! $desc['key']) {
168
-				spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base');
169
-				unset($desc['key']);
170
-			}
171
-		}
172
-
173
-		$desc['table'] = $desc['table_sql'] = $nom_sql;
174
-		$desc['connexion'] = $serveur;
175
-
176
-		// charger les infos declarees pour cette table
177
-		// en lui passant les infos connues
178
-		// $desc est prioritaire pour la description de la table
179
-		$desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc);
180
-		// s'assurer qu'on a toujours un 'key'
181
-		if (!isset($desc['key']) && !empty($fdesc['key'])){
182
-			$desc['key'] = $fdesc['key'];
183
-		}
184
-		if (! isset($desc['key'])) {
185
-			$desc['key'] = array();
186
-		}
187
-
188
-		// si tables_objets_sql est bien fini d'init, on peut cacher
189
-		$connexion['tables'][$nom_sql] = $desc;
190
-		$res = &$connexion['tables'][$nom_sql];
191
-		// une nouvelle table a ete decrite
192
-		// mettons donc a jour le cache des descriptions de ce serveur
193
-		if (is_writeable(_DIR_CACHE)) {
194
-			ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true);
195
-		}
196
-	} else {
197
-		$res = &$connexion['tables'][$nom_sql];
198
-	}
199
-
200
-	// toujours retourner $nom dans id_table
201
-	$res['id_table'] = $nom;
202
-
203
-	return $res;
67
+    static $nom_cache_desc_sql = array();
68
+
69
+    if (!spip_connect($serveur)
70
+        or !preg_match('/^[a-zA-Z0-9._-]*/', $nom)
71
+    ) {
72
+        return null;
73
+    }
74
+
75
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
76
+    $objets_sql = lister_tables_objets_sql("::md5");
77
+
78
+    // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe
79
+    // ce qui permet une auto invalidation en cas de modif manuelle du fichier
80
+    // de connexion, et tout risque d'ambiguite
81
+    if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) {
82
+        $nom_cache_desc_sql[$serveur][$objets_sql] =
83
+            _DIR_CACHE . 'sql_desc_'
84
+            . ($serveur ? "{$serveur}_" : "")
85
+            . substr(md5($connexion['db'] . ":" . $connexion['prefixe'] . ":$objets_sql"), 0, 8)
86
+            . '.txt';
87
+        // nouveau nom de cache = nouvelle version en memoire
88
+        unset($connexion['tables']);
89
+    }
90
+
91
+    // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions
92
+    if (!$nom) {
93
+        spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]);
94
+        $connexion['tables'] = array();
95
+
96
+        return null;
97
+    }
98
+
99
+    $nom_sql = $nom;
100
+    if (preg_match('/\.(.*)$/', $nom, $s)) {
101
+        $nom_sql = $s[1];
102
+    } else {
103
+        $nom_sql = $nom;
104
+    }
105
+
106
+    $fdesc = $desc = '';
107
+    $connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0];
108
+
109
+    // base sous SPIP: gerer les abreviations explicites des noms de table
110
+    if ($connexion['spip_connect_version']) {
111
+        if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) {
112
+            $nom = $GLOBALS['table_des_tables'][$nom];
113
+            $nom_sql = 'spip_' . $nom;
114
+        }
115
+    }
116
+
117
+    // si c'est la premiere table qu'on cherche
118
+    // et si on est pas explicitement en recalcul
119
+    // on essaye de recharger le cache des decriptions de ce serveur
120
+    // dans le fichier cache
121
+    if (!isset($connexion['tables'][$nom_sql])
122
+        and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul'
123
+        and (!isset($connexion['tables']) or !$connexion['tables'])
124
+    ) {
125
+        if (lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache)
126
+            and $desc_cache = unserialize($desc_cache)
127
+        ) {
128
+            $connexion['tables'] = $desc_cache;
129
+        }
130
+    }
131
+    if ($table_spip and !isset($connexion['tables'][$nom_sql])) {
132
+
133
+        if (isset($GLOBALS['tables_principales'][$nom_sql])) {
134
+            $fdesc = $GLOBALS['tables_principales'][$nom_sql];
135
+        }
136
+        // meme si pas d'abreviation declaree, trouver la table spip_$nom
137
+        // si c'est une table principale,
138
+        // puisqu'on le fait aussi pour les tables auxiliaires
139
+        elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) {
140
+            $nom_sql = 'spip_' . $nom;
141
+            $fdesc = &$GLOBALS['tables_principales'][$nom_sql];
142
+        } elseif (isset($GLOBALS['tables_auxiliaires'][$n = $nom])
143
+            or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom])
144
+        ) {
145
+            $nom_sql = $n;
146
+            $fdesc = &$GLOBALS['tables_auxiliaires'][$n];
147
+        }  # table locale a cote de SPIP, comme non SPIP:
148
+    }
149
+    if (!isset($connexion['tables'][$nom_sql])) {
150
+
151
+        // La *vraie* base a la priorite
152
+        $desc = sql_showtable($nom_sql, $table_spip, $serveur);
153
+        if (!$desc or !$desc['field']) {
154
+            if (!$fdesc) {
155
+                spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . _LOG_INFO_IMPORTANTE);
156
+
157
+                return null;
158
+            }
159
+            // on ne sait pas lire la structure de la table :
160
+            // on retombe sur la description donnee dans les fichiers spip
161
+            $desc = $fdesc;
162
+            $desc['exist'] = false;
163
+        } else {
164
+            $desc['exist'] = true;
165
+            // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple)
166
+            // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une
167
+            if (! $desc['key']) {
168
+                spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base');
169
+                unset($desc['key']);
170
+            }
171
+        }
172
+
173
+        $desc['table'] = $desc['table_sql'] = $nom_sql;
174
+        $desc['connexion'] = $serveur;
175
+
176
+        // charger les infos declarees pour cette table
177
+        // en lui passant les infos connues
178
+        // $desc est prioritaire pour la description de la table
179
+        $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc);
180
+        // s'assurer qu'on a toujours un 'key'
181
+        if (!isset($desc['key']) && !empty($fdesc['key'])){
182
+            $desc['key'] = $fdesc['key'];
183
+        }
184
+        if (! isset($desc['key'])) {
185
+            $desc['key'] = array();
186
+        }
187
+
188
+        // si tables_objets_sql est bien fini d'init, on peut cacher
189
+        $connexion['tables'][$nom_sql] = $desc;
190
+        $res = &$connexion['tables'][$nom_sql];
191
+        // une nouvelle table a ete decrite
192
+        // mettons donc a jour le cache des descriptions de ce serveur
193
+        if (is_writeable(_DIR_CACHE)) {
194
+            ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true);
195
+        }
196
+    } else {
197
+        $res = &$connexion['tables'][$nom_sql];
198
+    }
199
+
200
+    // toujours retourner $nom dans id_table
201
+    $res['id_table'] = $nom;
202
+
203
+    return $res;
204 204
 }
Please login to merge, or discard this patch.
ecrire/action/editer_liens.php 1 patch
Indentation   +520 added lines, -520 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  */
30 30
 
31 31
 if (!defined('_ECRIRE_INC_VERSION')) {
32
-	return;
32
+    return;
33 33
 }
34 34
 
35 35
 // charger la gestion les rôles sur les objets
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
  *     - array(clé primaire, nom de la table de lien) si associable
48 48
  */
49 49
 function objet_associable($objet) {
50
-	$trouver_table = charger_fonction('trouver_table', 'base');
51
-	$table_sql = table_objet_sql($objet);
50
+    $trouver_table = charger_fonction('trouver_table', 'base');
51
+    $table_sql = table_objet_sql($objet);
52 52
 
53
-	$l = "";
54
-	if ($primary = id_table_objet($objet)
55
-		and $trouver_table($l = $table_sql . "_liens")
56
-		and !preg_match(',[^\w],', $primary)
57
-		and !preg_match(',[^\w],', $l)
58
-	) {
59
-		return array($primary, $l);
60
-	}
53
+    $l = "";
54
+    if ($primary = id_table_objet($objet)
55
+        and $trouver_table($l = $table_sql . "_liens")
56
+        and !preg_match(',[^\w],', $primary)
57
+        and !preg_match(',[^\w],', $l)
58
+    ) {
59
+        return array($primary, $l);
60
+    }
61 61
 
62
-	spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l");
62
+    spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l");
63 63
 
64
-	return false;
64
+    return false;
65 65
 }
66 66
 
67 67
 /**
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
  * @return bool|int
88 88
  */
89 89
 function objet_associer($objets_source, $objets_lies, $qualif = null) {
90
-	$modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies, $qualif);
90
+    $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies, $qualif);
91 91
 
92
-	if ($qualif) {
93
-		objet_qualifier_liens($objets_source, $objets_lies, $qualif);
94
-	}
92
+    if ($qualif) {
93
+        objet_qualifier_liens($objets_source, $objets_lies, $qualif);
94
+    }
95 95
 
96
-	return $modifs; // pas d'erreur
96
+    return $modifs; // pas d'erreur
97 97
 }
98 98
 
99 99
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
  * @return bool|int
128 128
  */
129 129
 function objet_dissocier($objets_source, $objets_lies, $cond = null) {
130
-	return objet_traiter_liaisons('lien_delete', $objets_source, $objets_lies, $cond);
130
+    return objet_traiter_liaisons('lien_delete', $objets_source, $objets_lies, $cond);
131 131
 }
132 132
 
133 133
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
  * @return bool|int
153 153
  */
154 154
 function objet_qualifier_liens($objets_source, $objets_lies, $qualif) {
155
-	return objet_traiter_liaisons('lien_set', $objets_source, $objets_lies, $qualif);
155
+    return objet_traiter_liaisons('lien_set', $objets_source, $objets_lies, $qualif);
156 156
 }
157 157
 
158 158
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
  *     Liste des trouvailles
188 188
  */
189 189
 function objet_trouver_liens($objets_source, $objets_lies, $cond = null) {
190
-	return objet_traiter_liaisons('lien_find', $objets_source, $objets_lies, $cond);
190
+    return objet_traiter_liaisons('lien_find', $objets_source, $objets_lies, $cond);
191 191
 }
192 192
 
193 193
 
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
  * @return int
212 212
  */
213 213
 function objet_optimiser_liens($objets_source, $objets_lies) {
214
-	spip_log("objet_optimiser_liens : ".json_encode($objets_source) . ', ' . json_encode($objets_lies), 'genie'._LOG_DEBUG);
215
-	return objet_traiter_liaisons('lien_optimise', $objets_source, $objets_lies);
214
+    spip_log("objet_optimiser_liens : ".json_encode($objets_source) . ', ' . json_encode($objets_lies), 'genie'._LOG_DEBUG);
215
+    return objet_traiter_liaisons('lien_optimise', $objets_source, $objets_lies);
216 216
 }
217 217
 
218 218
 
@@ -232,37 +232,37 @@  discard block
 block discarded – undo
232 232
  *     Nombre de liens copiés
233 233
  */
234 234
 function objet_dupliquer_liens($objet, $id_source, $id_cible, $types = null, $exclure_types = null) {
235
-	include_spip('base/objets');
236
-	$tables = lister_tables_objets_sql();
237
-	$n = 0;
238
-	foreach ($tables as $table_sql => $infos) {
239
-		if (
240
-			(is_null($types) or in_array($infos['type'], $types))
241
-			and (is_null($exclure_types) or !in_array($infos['type'], $exclure_types))
242
-		) {
243
-			if (objet_associable($infos['type'])) {
244
-				$liens = (($infos['type'] == $objet) ?
245
-					objet_trouver_liens(array($objet => $id_source), '*')
246
-					:
247
-					objet_trouver_liens(array($infos['type'] => '*'), array($objet => $id_source)));
248
-				foreach ($liens as $lien) {
249
-					$n++;
250
-					if ($infos['type'] == $objet) {
251
-						if (
252
-							(is_null($types) or in_array($lien['objet'], $types))
253
-							and (is_null($exclure_types) or !in_array($lien['objet'], $exclure_types))
254
-						) {
255
-							objet_associer(array($objet => $id_cible), array($lien['objet'] => $lien[$lien['objet']]), $lien);
256
-						}
257
-					} else {
258
-						objet_associer(array($infos['type'] => $lien[$infos['type']]), array($objet => $id_cible), $lien);
259
-					}
260
-				}
261
-			}
262
-		}
263
-	}
264
-
265
-	return $n;
235
+    include_spip('base/objets');
236
+    $tables = lister_tables_objets_sql();
237
+    $n = 0;
238
+    foreach ($tables as $table_sql => $infos) {
239
+        if (
240
+            (is_null($types) or in_array($infos['type'], $types))
241
+            and (is_null($exclure_types) or !in_array($infos['type'], $exclure_types))
242
+        ) {
243
+            if (objet_associable($infos['type'])) {
244
+                $liens = (($infos['type'] == $objet) ?
245
+                    objet_trouver_liens(array($objet => $id_source), '*')
246
+                    :
247
+                    objet_trouver_liens(array($infos['type'] => '*'), array($objet => $id_source)));
248
+                foreach ($liens as $lien) {
249
+                    $n++;
250
+                    if ($infos['type'] == $objet) {
251
+                        if (
252
+                            (is_null($types) or in_array($lien['objet'], $types))
253
+                            and (is_null($exclure_types) or !in_array($lien['objet'], $exclure_types))
254
+                        ) {
255
+                            objet_associer(array($objet => $id_cible), array($lien['objet'] => $lien[$lien['objet']]), $lien);
256
+                        }
257
+                    } else {
258
+                        objet_associer(array($infos['type'] => $lien[$infos['type']]), array($objet => $id_cible), $lien);
259
+                    }
260
+                }
261
+            }
262
+        }
263
+    }
264
+
265
+    return $n;
266 266
 }
267 267
 
268 268
 /**
@@ -304,38 +304,38 @@  discard block
 block discarded – undo
304 304
  * @return bool|int|array
305 305
  */
306 306
 function objet_traiter_liaisons($operation, $objets_source, $objets_lies, $set = null) {
307
-	// accepter une syntaxe minimale pour supprimer tous les liens
308
-	if ($objets_lies == '*') {
309
-		$objets_lies = array('*' => '*');
310
-	}
311
-	$modifs = 0; // compter le nombre de modifications
312
-	$echec = null;
313
-	foreach ($objets_source as $objet => $ids) {
314
-		if ($a = objet_associable($objet)) {
315
-			list($primary, $l) = $a;
316
-			if (!is_array($ids)) {
317
-				$ids = array($ids);
318
-			} elseif (reset($ids) == "NOT") {
319
-				// si on demande un array('NOT',...) => recuperer la liste d'ids correspondants
320
-				$where = lien_where($primary, $ids, '*', '*');
321
-				$ids = sql_allfetsel($primary, $l, $where);
322
-				$ids = array_map('reset', $ids);
323
-			}
324
-			foreach ($ids as $id) {
325
-				$res = $operation($objet, $primary, $l, $id, $objets_lies, $set);
326
-				if ($res === false) {
327
-					spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id", _LOG_ERREUR);
328
-					$echec = true;
329
-				} else {
330
-					$modifs = ($modifs ? (is_array($res) ? array_merge($modifs, $res) : $modifs + $res) : $res);
331
-				}
332
-			}
333
-		} else {
334
-			$echec = true;
335
-		}
336
-	}
337
-
338
-	return ($echec ? false : $modifs); // pas d'erreur
307
+    // accepter une syntaxe minimale pour supprimer tous les liens
308
+    if ($objets_lies == '*') {
309
+        $objets_lies = array('*' => '*');
310
+    }
311
+    $modifs = 0; // compter le nombre de modifications
312
+    $echec = null;
313
+    foreach ($objets_source as $objet => $ids) {
314
+        if ($a = objet_associable($objet)) {
315
+            list($primary, $l) = $a;
316
+            if (!is_array($ids)) {
317
+                $ids = array($ids);
318
+            } elseif (reset($ids) == "NOT") {
319
+                // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants
320
+                $where = lien_where($primary, $ids, '*', '*');
321
+                $ids = sql_allfetsel($primary, $l, $where);
322
+                $ids = array_map('reset', $ids);
323
+            }
324
+            foreach ($ids as $id) {
325
+                $res = $operation($objet, $primary, $l, $id, $objets_lies, $set);
326
+                if ($res === false) {
327
+                    spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id", _LOG_ERREUR);
328
+                    $echec = true;
329
+                } else {
330
+                    $modifs = ($modifs ? (is_array($res) ? array_merge($modifs, $res) : $modifs + $res) : $res);
331
+                }
332
+            }
333
+        } else {
334
+            $echec = true;
335
+        }
336
+    }
337
+
338
+    return ($echec ? false : $modifs); // pas d'erreur
339 339
 }
340 340
 
341 341
 
@@ -364,106 +364,106 @@  discard block
 block discarded – undo
364 364
  *     Nombre d'insertions faites, false si échec.
365 365
  */
366 366
 function lien_insert($objet_source, $primary, $table_lien, $id, $objets, $qualif) {
367
-	$ins = 0;
368
-	$echec = null;
369
-	if (is_null($qualif)) {
370
-		$qualif = array();
371
-	}
372
-
373
-	foreach ($objets as $objet => $id_objets) {
374
-		if (!is_array($id_objets)) {
375
-			$id_objets = array($id_objets);
376
-		}
377
-
378
-		// role, colonne, where par défaut
379
-		list($role, $colonne_role, $cond) =
380
-			roles_trouver_dans_qualif($objet_source, $objet, $qualif);
381
-
382
-		foreach ($id_objets as $id_objet) {
383
-			$objet = (($objet == '*') ? $objet : objet_type($objet)); # securite
384
-
385
-			$insertions = array(
386
-				'id_objet' => $id_objet,
387
-				'objet' => $objet,
388
-				$primary => $id
389
-			);
390
-			// rôle en plus s'il est défini
391
-			if ($role) {
392
-				$insertions += array(
393
-					$colonne_role => $role
394
-				);
395
-			}
396
-
397
-			if (lien_triables($table_lien)) {
398
-				$where = lien_where($primary, $id, $objet, $id_objet);
399
-				// si il y a deja un lien pour ce couple (avec un autre role?) on reprend le meme rang si non nul
400
-				if (!$rang = intval(sql_getfetsel('rang_lien', $table_lien, $where))) {
401
-					$where = lien_where($primary, '*', $objet, $id_objet);
402
-					$rang = intval(sql_getfetsel('max(rang_lien)', $table_lien, $where));
403
-					// si aucun lien n'a de rang, on en introduit pas, on garde zero
404
-					if ($rang>0) {
405
-						$rang = intval($rang) + 1;
406
-					}
407
-				}
408
-				$insertions['rang_lien'] = $rang;
409
-			}
410
-
411
-			$args = array(
412
-				'table_lien' => $table_lien,
413
-				'objet_source' => $objet_source,
414
-				'id_objet_source' => $id,
415
-				'objet' => $objet,
416
-				'id_objet' => $id_objet,
417
-				'role' => $role,
418
-				'colonne_role' => $colonne_role,
419
-				'action' => 'insert',
420
-			);
421
-
422
-			// Envoyer aux plugins
423
-			$insertions = pipeline('pre_edition_lien',
424
-				array(
425
-					'args' => $args,
426
-					'data' => $insertions
427
-				)
428
-			);
429
-			$args['id_objet'] = $insertions['id_objet'];
430
-
431
-			$where = lien_where($primary, $id, $objet, $id_objet, $cond);
432
-
433
-			if (($id_objet = intval($insertions['id_objet']) or in_array($objet, ['site', 'rubrique']))
434
-				and !sql_getfetsel($primary, $table_lien, $where)
435
-			) {
436
-
437
-				if (lien_triables($table_lien) and isset($insertions['rang_lien']) and intval($insertions['rang_lien'])) {
438
-					// on decale les liens de rang_lien>=la valeur inseree pour faire la place
439
-					$w = lien_where($primary, '*', $objet, $id_objet, array('rang_lien>='.intval($insertions['rang_lien']),"$primary!=".intval($id)));
440
-					sql_update($table_lien, array('rang_lien'=>'rang_lien+1'), $w);
441
-				}
442
-
443
-				$e = sql_insertq($table_lien, $insertions);
444
-				if ($e !== false) {
445
-					$ins++;
446
-					lien_propage_date_modif($objet, $id_objet);
447
-					lien_propage_date_modif($objet_source, $id);
448
-					// Envoyer aux plugins
449
-					pipeline('post_edition_lien',
450
-						array(
451
-							'args' => $args,
452
-							'data' => $insertions
453
-						)
454
-					);
455
-				} else {
456
-					$echec = true;
457
-				}
458
-			}
459
-		}
460
-	}
461
-	// si on a fait des insertions, on reordonne les liens concernes
462
-	if ($ins>0) {
463
-		lien_ordonner($objet_source, $primary, $table_lien, $id, $objets);
464
-	}
465
-
466
-	return ($echec ? false : $ins);
367
+    $ins = 0;
368
+    $echec = null;
369
+    if (is_null($qualif)) {
370
+        $qualif = array();
371
+    }
372
+
373
+    foreach ($objets as $objet => $id_objets) {
374
+        if (!is_array($id_objets)) {
375
+            $id_objets = array($id_objets);
376
+        }
377
+
378
+        // role, colonne, where par défaut
379
+        list($role, $colonne_role, $cond) =
380
+            roles_trouver_dans_qualif($objet_source, $objet, $qualif);
381
+
382
+        foreach ($id_objets as $id_objet) {
383
+            $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite
384
+
385
+            $insertions = array(
386
+                'id_objet' => $id_objet,
387
+                'objet' => $objet,
388
+                $primary => $id
389
+            );
390
+            // rôle en plus s'il est défini
391
+            if ($role) {
392
+                $insertions += array(
393
+                    $colonne_role => $role
394
+                );
395
+            }
396
+
397
+            if (lien_triables($table_lien)) {
398
+                $where = lien_where($primary, $id, $objet, $id_objet);
399
+                // si il y a deja un lien pour ce couple (avec un autre role?) on reprend le meme rang si non nul
400
+                if (!$rang = intval(sql_getfetsel('rang_lien', $table_lien, $where))) {
401
+                    $where = lien_where($primary, '*', $objet, $id_objet);
402
+                    $rang = intval(sql_getfetsel('max(rang_lien)', $table_lien, $where));
403
+                    // si aucun lien n'a de rang, on en introduit pas, on garde zero
404
+                    if ($rang>0) {
405
+                        $rang = intval($rang) + 1;
406
+                    }
407
+                }
408
+                $insertions['rang_lien'] = $rang;
409
+            }
410
+
411
+            $args = array(
412
+                'table_lien' => $table_lien,
413
+                'objet_source' => $objet_source,
414
+                'id_objet_source' => $id,
415
+                'objet' => $objet,
416
+                'id_objet' => $id_objet,
417
+                'role' => $role,
418
+                'colonne_role' => $colonne_role,
419
+                'action' => 'insert',
420
+            );
421
+
422
+            // Envoyer aux plugins
423
+            $insertions = pipeline('pre_edition_lien',
424
+                array(
425
+                    'args' => $args,
426
+                    'data' => $insertions
427
+                )
428
+            );
429
+            $args['id_objet'] = $insertions['id_objet'];
430
+
431
+            $where = lien_where($primary, $id, $objet, $id_objet, $cond);
432
+
433
+            if (($id_objet = intval($insertions['id_objet']) or in_array($objet, ['site', 'rubrique']))
434
+                and !sql_getfetsel($primary, $table_lien, $where)
435
+            ) {
436
+
437
+                if (lien_triables($table_lien) and isset($insertions['rang_lien']) and intval($insertions['rang_lien'])) {
438
+                    // on decale les liens de rang_lien>=la valeur inseree pour faire la place
439
+                    $w = lien_where($primary, '*', $objet, $id_objet, array('rang_lien>='.intval($insertions['rang_lien']),"$primary!=".intval($id)));
440
+                    sql_update($table_lien, array('rang_lien'=>'rang_lien+1'), $w);
441
+                }
442
+
443
+                $e = sql_insertq($table_lien, $insertions);
444
+                if ($e !== false) {
445
+                    $ins++;
446
+                    lien_propage_date_modif($objet, $id_objet);
447
+                    lien_propage_date_modif($objet_source, $id);
448
+                    // Envoyer aux plugins
449
+                    pipeline('post_edition_lien',
450
+                        array(
451
+                            'args' => $args,
452
+                            'data' => $insertions
453
+                        )
454
+                    );
455
+                } else {
456
+                    $echec = true;
457
+                }
458
+            }
459
+        }
460
+    }
461
+    // si on a fait des insertions, on reordonne les liens concernes
462
+    if ($ins>0) {
463
+        lien_ordonner($objet_source, $primary, $table_lien, $id, $objets);
464
+    }
465
+
466
+    return ($echec ? false : $ins);
467 467
 }
468 468
 
469 469
 
@@ -476,32 +476,32 @@  discard block
 block discarded – undo
476 476
  * @param array|string $objets
477 477
  */
478 478
 function lien_ordonner($objet_source, $primary, $table_lien, $id, $objets) {
479
-	if (!lien_triables($table_lien)) {
480
-		return;
481
-	}
482
-
483
-	foreach ($objets as $objet => $id_objets) {
484
-		if (!is_array($id_objets)) {
485
-			$id_objets = array($id_objets);
486
-		}
487
-
488
-		foreach ($id_objets as $id_objet) {
489
-			$objet = (($objet == '*') ? $objet : objet_type($objet)); # securite
490
-
491
-			$where = lien_where($primary, '*', $objet, $id_objet);
492
-			$liens = sql_allfetsel("$primary, id_objet, objet, rang_lien", $table_lien, $where, $primary,"rang_lien");
493
-
494
-			$rangs = array_column($liens, 'rang_lien');
495
-			if (count($rangs) and (max($rangs)>0 or min($rangs)<0)) {
496
-				$rang = 1;
497
-				foreach ($liens as $lien) {
498
-					$where = lien_where($primary, $lien[$primary], $objet, $id_objet, array('rang_lien!='.intval($rang)));
499
-					sql_updateq($table_lien, array('rang_lien' => $rang), $where);
500
-					$rang++;
501
-				}
502
-			}
503
-		}
504
-	}
479
+    if (!lien_triables($table_lien)) {
480
+        return;
481
+    }
482
+
483
+    foreach ($objets as $objet => $id_objets) {
484
+        if (!is_array($id_objets)) {
485
+            $id_objets = array($id_objets);
486
+        }
487
+
488
+        foreach ($id_objets as $id_objet) {
489
+            $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite
490
+
491
+            $where = lien_where($primary, '*', $objet, $id_objet);
492
+            $liens = sql_allfetsel("$primary, id_objet, objet, rang_lien", $table_lien, $where, $primary,"rang_lien");
493
+
494
+            $rangs = array_column($liens, 'rang_lien');
495
+            if (count($rangs) and (max($rangs)>0 or min($rangs)<0)) {
496
+                $rang = 1;
497
+                foreach ($liens as $lien) {
498
+                    $where = lien_where($primary, $lien[$primary], $objet, $id_objet, array('rang_lien!='.intval($rang)));
499
+                    sql_updateq($table_lien, array('rang_lien' => $rang), $where);
500
+                    $rang++;
501
+                }
502
+            }
503
+        }
504
+    }
505 505
 }
506 506
 
507 507
 
@@ -512,18 +512,18 @@  discard block
 block discarded – undo
512 512
  * @return mixed
513 513
  */
514 514
 function lien_triables($table_lien) {
515
-	static $triables = array();
516
-	if (!isset($triables[$table_lien])) {
517
-		$trouver_table = charger_fonction('trouver_table', 'base');
518
-		$desc = $trouver_table($table_lien);
519
-		if ($desc and isset($desc['field']['rang_lien'])) {
520
-			$triables[$table_lien] = true;
521
-		}
522
-		else {
523
-			$triables[$table_lien] = false;
524
-		}
525
-	}
526
-	return $triables[$table_lien];
515
+    static $triables = array();
516
+    if (!isset($triables[$table_lien])) {
517
+        $trouver_table = charger_fonction('trouver_table', 'base');
518
+        $desc = $trouver_table($table_lien);
519
+        if ($desc and isset($desc['field']['rang_lien'])) {
520
+            $triables[$table_lien] = true;
521
+        }
522
+        else {
523
+            $triables[$table_lien] = false;
524
+        }
525
+    }
526
+    return $triables[$table_lien];
527 527
 }
528 528
 
529 529
 
@@ -539,45 +539,45 @@  discard block
 block discarded – undo
539 539
  * @return array                        Liste des conditions
540 540
  */
541 541
 function lien_where($primary, $id_source, $objet, $id_objet, $cond = array()) {
542
-	if ((!is_array($id_source) and !strlen($id_source))
543
-		or !strlen($objet)
544
-		or (!is_array($id_objet) and !strlen($id_objet))
545
-	) {
546
-		return array("0=1");
547
-	} // securite
548
-
549
-	$not = "";
550
-	if (is_array($id_source) and reset($id_source) == "NOT") {
551
-		$not = array_shift($id_source);
552
-		$id_source = reset($id_source);
553
-	}
554
-
555
-	$where = $cond;
556
-
557
-	if ($id_source !== '*') {
558
-		$where[] = (is_array($id_source) ? sql_in(addslashes($primary), array_map('intval', $id_source),
559
-			$not) : addslashes($primary) . ($not ? "<>" : "=") . intval($id_source));
560
-	} elseif ($not) {
561
-		$where[] = "0=1";
562
-	} // idiot mais quand meme
563
-
564
-	$not = "";
565
-	if (is_array($id_objet) and reset($id_objet) == "NOT") {
566
-		$not = array_shift($id_objet);
567
-		$id_objet = reset($id_objet);
568
-	}
569
-
570
-	if ($objet !== '*') {
571
-		$where[] = "objet=" . sql_quote($objet);
572
-	}
573
-	if ($id_objet !== '*') {
574
-		$where[] = (is_array($id_objet) ? sql_in('id_objet', array_map('intval', $id_objet),
575
-			$not) : "id_objet" . ($not ? "<>" : "=") . intval($id_objet));
576
-	} elseif ($not) {
577
-		$where[] = "0=1";
578
-	} // idiot mais quand meme
579
-
580
-	return $where;
542
+    if ((!is_array($id_source) and !strlen($id_source))
543
+        or !strlen($objet)
544
+        or (!is_array($id_objet) and !strlen($id_objet))
545
+    ) {
546
+        return array("0=1");
547
+    } // securite
548
+
549
+    $not = "";
550
+    if (is_array($id_source) and reset($id_source) == "NOT") {
551
+        $not = array_shift($id_source);
552
+        $id_source = reset($id_source);
553
+    }
554
+
555
+    $where = $cond;
556
+
557
+    if ($id_source !== '*') {
558
+        $where[] = (is_array($id_source) ? sql_in(addslashes($primary), array_map('intval', $id_source),
559
+            $not) : addslashes($primary) . ($not ? "<>" : "=") . intval($id_source));
560
+    } elseif ($not) {
561
+        $where[] = "0=1";
562
+    } // idiot mais quand meme
563
+
564
+    $not = "";
565
+    if (is_array($id_objet) and reset($id_objet) == "NOT") {
566
+        $not = array_shift($id_objet);
567
+        $id_objet = reset($id_objet);
568
+    }
569
+
570
+    if ($objet !== '*') {
571
+        $where[] = "objet=" . sql_quote($objet);
572
+    }
573
+    if ($id_objet !== '*') {
574
+        $where[] = (is_array($id_objet) ? sql_in('id_objet', array_map('intval', $id_objet),
575
+            $not) : "id_objet" . ($not ? "<>" : "=") . intval($id_objet));
576
+    } elseif ($not) {
577
+        $where[] = "0=1";
578
+    } // idiot mais quand meme
579
+
580
+    return $where;
581 581
 }
582 582
 
583 583
 /**
@@ -608,89 +608,89 @@  discard block
 block discarded – undo
608 608
  */
609 609
 function lien_delete($objet_source, $primary, $table_lien, $id, $objets, $cond = null) {
610 610
 
611
-	$retire = array();
612
-	$dels = 0;
613
-	$echec = false;
614
-	if (is_null($cond)) {
615
-		$cond = array();
616
-	}
617
-
618
-	foreach ($objets as $objet => $id_objets) {
619
-		$objet = ($objet == '*') ? $objet : objet_type($objet); # securite
620
-		if (!is_array($id_objets) or reset($id_objets) == "NOT") {
621
-			$id_objets = array($id_objets);
622
-		}
623
-		foreach ($id_objets as $id_objet) {
624
-			list($cond, $colonne_role, $role) = roles_creer_condition_role($objet_source, $objet, $cond);
625
-			// id_objet peut valoir '*'
626
-			$where = lien_where($primary, $id, $objet, $id_objet, $cond);
627
-
628
-			// lire les liens existants pour propager la date de modif
629
-			$select = "$primary,id_objet,objet";
630
-			if ($colonne_role) {
631
-				$select .= ",$colonne_role";
632
-			}
633
-			$liens = sql_allfetsel($select, $table_lien, $where);
634
-
635
-			// iterer sur les liens pour permettre aux plugins de gerer
636
-			foreach ($liens as $l) {
637
-
638
-				$args = array(
639
-					'table_lien' => $table_lien,
640
-					'objet_source' => $objet_source,
641
-					'id_objet_source' => $l[$primary],
642
-					'objet' => $l['objet'],
643
-					'id_objet' => $l['id_objet'],
644
-					'colonne_role' => $colonne_role,
645
-					'role' => ($colonne_role ? $l[$colonne_role] : ''),
646
-					'action' => 'delete',
647
-				);
648
-
649
-				// Envoyer aux plugins
650
-				$l = pipeline('pre_edition_lien',
651
-					array(
652
-						'args' => $args,
653
-						'data' => $l
654
-					)
655
-				);
656
-				$args['id_objet'] = $id_o = $l['id_objet'];
657
-
658
-				if ($id_o = intval($l['id_objet']) or in_array($l['objet'], ['site', 'rubrique'])) {
659
-					$where = lien_where($primary, $l[$primary], $l['objet'], $id_o, $cond);
660
-					$e = sql_delete($table_lien, $where);
661
-					if ($e !== false) {
662
-						$dels += $e;
663
-						lien_propage_date_modif($l['objet'], $id_o);
664
-						lien_propage_date_modif($objet_source, $l[$primary]);
665
-					} else {
666
-						$echec = true;
667
-					}
668
-					$retire[] = array(
669
-						'source' => array($objet_source => $l[$primary]),
670
-						'lien' => array($l['objet'] => $id_o),
671
-						'type' => $l['objet'],
672
-						'role' => ($colonne_role ? $l[$colonne_role] : ''),
673
-						'id' => $id_o
674
-					);
675
-					// Envoyer aux plugins
676
-					pipeline('post_edition_lien',
677
-						array(
678
-							'args' => $args,
679
-							'data' => $l
680
-						)
681
-					);
682
-				}
683
-			}
684
-		}
685
-	}
686
-	// si on a supprime des liens, on reordonne les liens concernes
687
-	if ($dels) {
688
-		lien_ordonner($objet_source, $primary, $table_lien, $id, $objets);
689
-	}
690
-
691
-	pipeline('trig_supprimer_objets_lies', $retire);
692
-
693
-	return ($echec ? false : $dels);
611
+    $retire = array();
612
+    $dels = 0;
613
+    $echec = false;
614
+    if (is_null($cond)) {
615
+        $cond = array();
616
+    }
617
+
618
+    foreach ($objets as $objet => $id_objets) {
619
+        $objet = ($objet == '*') ? $objet : objet_type($objet); # securite
620
+        if (!is_array($id_objets) or reset($id_objets) == "NOT") {
621
+            $id_objets = array($id_objets);
622
+        }
623
+        foreach ($id_objets as $id_objet) {
624
+            list($cond, $colonne_role, $role) = roles_creer_condition_role($objet_source, $objet, $cond);
625
+            // id_objet peut valoir '*'
626
+            $where = lien_where($primary, $id, $objet, $id_objet, $cond);
627
+
628
+            // lire les liens existants pour propager la date de modif
629
+            $select = "$primary,id_objet,objet";
630
+            if ($colonne_role) {
631
+                $select .= ",$colonne_role";
632
+            }
633
+            $liens = sql_allfetsel($select, $table_lien, $where);
634
+
635
+            // iterer sur les liens pour permettre aux plugins de gerer
636
+            foreach ($liens as $l) {
637
+
638
+                $args = array(
639
+                    'table_lien' => $table_lien,
640
+                    'objet_source' => $objet_source,
641
+                    'id_objet_source' => $l[$primary],
642
+                    'objet' => $l['objet'],
643
+                    'id_objet' => $l['id_objet'],
644
+                    'colonne_role' => $colonne_role,
645
+                    'role' => ($colonne_role ? $l[$colonne_role] : ''),
646
+                    'action' => 'delete',
647
+                );
648
+
649
+                // Envoyer aux plugins
650
+                $l = pipeline('pre_edition_lien',
651
+                    array(
652
+                        'args' => $args,
653
+                        'data' => $l
654
+                    )
655
+                );
656
+                $args['id_objet'] = $id_o = $l['id_objet'];
657
+
658
+                if ($id_o = intval($l['id_objet']) or in_array($l['objet'], ['site', 'rubrique'])) {
659
+                    $where = lien_where($primary, $l[$primary], $l['objet'], $id_o, $cond);
660
+                    $e = sql_delete($table_lien, $where);
661
+                    if ($e !== false) {
662
+                        $dels += $e;
663
+                        lien_propage_date_modif($l['objet'], $id_o);
664
+                        lien_propage_date_modif($objet_source, $l[$primary]);
665
+                    } else {
666
+                        $echec = true;
667
+                    }
668
+                    $retire[] = array(
669
+                        'source' => array($objet_source => $l[$primary]),
670
+                        'lien' => array($l['objet'] => $id_o),
671
+                        'type' => $l['objet'],
672
+                        'role' => ($colonne_role ? $l[$colonne_role] : ''),
673
+                        'id' => $id_o
674
+                    );
675
+                    // Envoyer aux plugins
676
+                    pipeline('post_edition_lien',
677
+                        array(
678
+                            'args' => $args,
679
+                            'data' => $l
680
+                        )
681
+                    );
682
+                }
683
+            }
684
+        }
685
+    }
686
+    // si on a supprime des liens, on reordonne les liens concernes
687
+    if ($dels) {
688
+        lien_ordonner($objet_source, $primary, $table_lien, $id, $objets);
689
+    }
690
+
691
+    pipeline('trig_supprimer_objets_lies', $retire);
692
+
693
+    return ($echec ? false : $dels);
694 694
 }
695 695
 
696 696
 
@@ -713,61 +713,61 @@  discard block
 block discarded – undo
713 713
  * @return bool|int
714 714
  */
715 715
 function lien_optimise($objet_source, $primary, $table_lien, $id, $objets) {
716
-	include_spip('genie/optimiser');
717
-	$echec = false;
718
-	$dels = 0;
719
-	foreach ($objets as $objet => $id_objets) {
720
-		$objet = ($objet == '*') ? $objet : objet_type($objet); # securite
721
-		if (!is_array($id_objets) or reset($id_objets) == "NOT") {
722
-			$id_objets = array($id_objets);
723
-		}
724
-		foreach ($id_objets as $id_objet) {
725
-			$where = lien_where($primary, $id, $objet, $id_objet);
726
-			# les liens vers un objet inexistant
727
-			$r = sql_select("DISTINCT objet", $table_lien, $where);
728
-			while ($t = sql_fetch($r)) {
729
-				$type = $t['objet'];
730
-				$spip_table_objet = table_objet_sql($type);
731
-				$id_table_objet = id_table_objet($type);
732
-				$res = sql_select("L.$primary AS id,L.id_objet",
733
-					// la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes
734
-					// du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN
735
-					// il faut les eliminier en repetant la condition dans le where L.objet='xxx'
736
-					"$table_lien AS L
716
+    include_spip('genie/optimiser');
717
+    $echec = false;
718
+    $dels = 0;
719
+    foreach ($objets as $objet => $id_objets) {
720
+        $objet = ($objet == '*') ? $objet : objet_type($objet); # securite
721
+        if (!is_array($id_objets) or reset($id_objets) == "NOT") {
722
+            $id_objets = array($id_objets);
723
+        }
724
+        foreach ($id_objets as $id_objet) {
725
+            $where = lien_where($primary, $id, $objet, $id_objet);
726
+            # les liens vers un objet inexistant
727
+            $r = sql_select("DISTINCT objet", $table_lien, $where);
728
+            while ($t = sql_fetch($r)) {
729
+                $type = $t['objet'];
730
+                $spip_table_objet = table_objet_sql($type);
731
+                $id_table_objet = id_table_objet($type);
732
+                $res = sql_select("L.$primary AS id,L.id_objet",
733
+                    // la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes
734
+                    // du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN
735
+                    // il faut les eliminier en repetant la condition dans le where L.objet='xxx'
736
+                    "$table_lien AS L
737 737
 									LEFT JOIN $spip_table_objet AS O
738 738
 										ON (O.$id_table_objet=L.id_objet AND L.objet=" . sql_quote($type) . ")",
739
-					"L.objet=" . sql_quote($type) . " AND O.$id_table_objet IS NULL");
740
-				// sur une cle primaire composee, pas d'autres solutions que de virer un a un
741
-				while ($row = sql_fetch($res)) {
742
-					if ($primary === 'id_document' and in_array($type, ['site', 'rubrique']) and !intval($row['id_objet'])) {
743
-						continue; // gaffe, c'est le logo du site ou des rubriques!
744
-					}
745
-					$e = sql_delete($table_lien,
746
-						array("$primary=" . $row['id'], "id_objet=" . $row['id_objet'], "objet=" . sql_quote($type)));
747
-					if ($e != false) {
748
-						$dels += $e;
749
-						spip_log(
750
-							"lien_optimise: Entree " . $row['id'] . "/" . $row['id_objet'] . "/$type supprimee dans la table $table_lien",
751
-							'genie'._LOG_INFO_IMPORTANTE
752
-						);
753
-					}
754
-				}
755
-			}
756
-
757
-			# les liens depuis un objet inexistant
758
-			$table_source = table_objet_sql($objet_source);
759
-			// filtrer selon $id, $objet, $id_objet eventuellement fournis
760
-			// (en general '*' pour chaque)
761
-			$where = lien_where("L.$primary", $id, $objet, $id_objet);
762
-			$where[] = "O.$primary IS NULL";
763
-			$res = sql_select("L.$primary AS id",
764
-				"$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary",
765
-				$where);
766
-			$dels += optimiser_sansref($table_lien, $primary, $res);
767
-		}
768
-	}
769
-
770
-	return ($echec ? false : $dels);
739
+                    "L.objet=" . sql_quote($type) . " AND O.$id_table_objet IS NULL");
740
+                // sur une cle primaire composee, pas d'autres solutions que de virer un a un
741
+                while ($row = sql_fetch($res)) {
742
+                    if ($primary === 'id_document' and in_array($type, ['site', 'rubrique']) and !intval($row['id_objet'])) {
743
+                        continue; // gaffe, c'est le logo du site ou des rubriques!
744
+                    }
745
+                    $e = sql_delete($table_lien,
746
+                        array("$primary=" . $row['id'], "id_objet=" . $row['id_objet'], "objet=" . sql_quote($type)));
747
+                    if ($e != false) {
748
+                        $dels += $e;
749
+                        spip_log(
750
+                            "lien_optimise: Entree " . $row['id'] . "/" . $row['id_objet'] . "/$type supprimee dans la table $table_lien",
751
+                            'genie'._LOG_INFO_IMPORTANTE
752
+                        );
753
+                    }
754
+                }
755
+            }
756
+
757
+            # les liens depuis un objet inexistant
758
+            $table_source = table_objet_sql($objet_source);
759
+            // filtrer selon $id, $objet, $id_objet eventuellement fournis
760
+            // (en general '*' pour chaque)
761
+            $where = lien_where("L.$primary", $id, $objet, $id_objet);
762
+            $where[] = "O.$primary IS NULL";
763
+            $res = sql_select("L.$primary AS id",
764
+                "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary",
765
+                $where);
766
+            $dels += optimiser_sansref($table_lien, $primary, $res);
767
+        }
768
+    }
769
+
770
+    return ($echec ? false : $dels);
771 771
 }
772 772
 
773 773
 
@@ -799,89 +799,89 @@  discard block
 block discarded – undo
799 799
  *     Nombre de modifications faites, false si échec.
800 800
  */
801 801
 function lien_set($objet_source, $primary, $table_lien, $id, $objets, $qualif) {
802
-	$echec = null;
803
-	$ok = 0;
804
-	$reordonner = false;
805
-	if (!$qualif) {
806
-		return false;
807
-	}
808
-	// nettoyer qualif qui peut venir directement d'un objet_trouver_lien :
809
-	unset($qualif[$primary]);
810
-	unset($qualif[$objet_source]);
811
-	if (isset($qualif['objet'])) {
812
-		unset($qualif[$qualif['objet']]);
813
-	}
814
-	unset($qualif['objet']);
815
-	unset($qualif['id_objet']);
816
-	foreach ($objets as $objet => $id_objets) {
817
-
818
-		// role, colonne, where par défaut
819
-		list($role, $colonne_role, $cond) =
820
-			roles_trouver_dans_qualif($objet_source, $objet, $qualif);
821
-
822
-		$objet = ($objet == '*') ? $objet : objet_type($objet); # securite
823
-		if (!is_array($id_objets) or reset($id_objets) == "NOT") {
824
-			$id_objets = array($id_objets);
825
-		}
826
-		foreach ($id_objets as $id_objet) {
827
-
828
-			$args = array(
829
-				'table_lien' => $table_lien,
830
-				'objet_source' => $objet_source,
831
-				'id_objet_source' => $id,
832
-				'objet' => $objet,
833
-				'id_objet' => $id_objet,
834
-				'role' => $role,
835
-				'colonne_role' => $colonne_role,
836
-				'action' => 'modifier',
837
-			);
838
-
839
-			// Envoyer aux plugins
840
-			$qualif = pipeline('pre_edition_lien',
841
-				array(
842
-					'args' => $args,
843
-					'data' => $qualif,
844
-				)
845
-			);
846
-			$args['id_objet'] = $id_objet;
847
-
848
-			if (lien_triables($table_lien) and isset($qualif['rang_lien'])) {
849
-				if (intval($qualif['rang_lien'])) {
850
-					// on decale les liens de rang_lien>=la valeur inseree pour faire la place
851
-					$w = lien_where($primary, '*', $objet, $id_objet, array('rang_lien>='.intval($qualif['rang_lien']),"$primary!=".intval($id)));
852
-					sql_update($table_lien, array('rang_lien'=>'rang_lien+1'), $w);
853
-				}
854
-				// tous les liens de même rôle recoivent le rang indiqué aussi
855
-				if (roles_colonne($objet_source, $objet)) {
856
-					$w = lien_where($primary, $id, $objet, $id_objet);
857
-					sql_updateq($table_lien, array('rang_lien' => intval($qualif['rang_lien'])), $w);
858
-				}
859
-				$reordonner = true;
860
-			}
861
-
862
-			$where = lien_where($primary, $id, $objet, $id_objet, $cond);
863
-			$e = sql_updateq($table_lien, $qualif, $where);
864
-
865
-			if ($e === false) {
866
-				$echec = true;
867
-			} else {
868
-				// Envoyer aux plugins
869
-				pipeline('post_edition_lien',
870
-					array(
871
-						'args' => $args,
872
-						'data' => $qualif
873
-					)
874
-				);
875
-				$ok++;
876
-			}
877
-		}
878
-	}
879
-	// si on a fait des modif de rang, on reordonne les liens concernes
880
-	if ($reordonner) {
881
-		lien_ordonner($objet_source, $primary, $table_lien, $id, $objets);
882
-	}
883
-
884
-	return ($echec ? false : $ok);
802
+    $echec = null;
803
+    $ok = 0;
804
+    $reordonner = false;
805
+    if (!$qualif) {
806
+        return false;
807
+    }
808
+    // nettoyer qualif qui peut venir directement d'un objet_trouver_lien :
809
+    unset($qualif[$primary]);
810
+    unset($qualif[$objet_source]);
811
+    if (isset($qualif['objet'])) {
812
+        unset($qualif[$qualif['objet']]);
813
+    }
814
+    unset($qualif['objet']);
815
+    unset($qualif['id_objet']);
816
+    foreach ($objets as $objet => $id_objets) {
817
+
818
+        // role, colonne, where par défaut
819
+        list($role, $colonne_role, $cond) =
820
+            roles_trouver_dans_qualif($objet_source, $objet, $qualif);
821
+
822
+        $objet = ($objet == '*') ? $objet : objet_type($objet); # securite
823
+        if (!is_array($id_objets) or reset($id_objets) == "NOT") {
824
+            $id_objets = array($id_objets);
825
+        }
826
+        foreach ($id_objets as $id_objet) {
827
+
828
+            $args = array(
829
+                'table_lien' => $table_lien,
830
+                'objet_source' => $objet_source,
831
+                'id_objet_source' => $id,
832
+                'objet' => $objet,
833
+                'id_objet' => $id_objet,
834
+                'role' => $role,
835
+                'colonne_role' => $colonne_role,
836
+                'action' => 'modifier',
837
+            );
838
+
839
+            // Envoyer aux plugins
840
+            $qualif = pipeline('pre_edition_lien',
841
+                array(
842
+                    'args' => $args,
843
+                    'data' => $qualif,
844
+                )
845
+            );
846
+            $args['id_objet'] = $id_objet;
847
+
848
+            if (lien_triables($table_lien) and isset($qualif['rang_lien'])) {
849
+                if (intval($qualif['rang_lien'])) {
850
+                    // on decale les liens de rang_lien>=la valeur inseree pour faire la place
851
+                    $w = lien_where($primary, '*', $objet, $id_objet, array('rang_lien>='.intval($qualif['rang_lien']),"$primary!=".intval($id)));
852
+                    sql_update($table_lien, array('rang_lien'=>'rang_lien+1'), $w);
853
+                }
854
+                // tous les liens de même rôle recoivent le rang indiqué aussi
855
+                if (roles_colonne($objet_source, $objet)) {
856
+                    $w = lien_where($primary, $id, $objet, $id_objet);
857
+                    sql_updateq($table_lien, array('rang_lien' => intval($qualif['rang_lien'])), $w);
858
+                }
859
+                $reordonner = true;
860
+            }
861
+
862
+            $where = lien_where($primary, $id, $objet, $id_objet, $cond);
863
+            $e = sql_updateq($table_lien, $qualif, $where);
864
+
865
+            if ($e === false) {
866
+                $echec = true;
867
+            } else {
868
+                // Envoyer aux plugins
869
+                pipeline('post_edition_lien',
870
+                    array(
871
+                        'args' => $args,
872
+                        'data' => $qualif
873
+                    )
874
+                );
875
+                $ok++;
876
+            }
877
+        }
878
+    }
879
+    // si on a fait des modif de rang, on reordonne les liens concernes
880
+    if ($reordonner) {
881
+        lien_ordonner($objet_source, $primary, $table_lien, $id, $objets);
882
+    }
883
+
884
+    return ($echec ? false : $ok);
885 885
 }
886 886
 
887 887
 /**
@@ -911,23 +911,23 @@  discard block
 block discarded – undo
911 911
  * @return array
912 912
  */
913 913
 function lien_find($objet_source, $primary, $table_lien, $id, $objets, $cond = null) {
914
-	$trouve = array();
915
-	foreach ($objets as $objet => $id_objets) {
916
-		$objet = ($objet == '*') ? $objet : objet_type($objet); # securite
917
-		// gerer les roles s'il y en a dans $cond
918
-		list($cond) = roles_creer_condition_role($objet_source, $objet, $cond, true);
919
-		// lien_where prend en charge les $id_objets sous forme int ou array
920
-		$where = lien_where($primary, $id, $objet, $id_objets, $cond);
921
-		$liens = sql_allfetsel('*', $table_lien, $where);
922
-		// ajouter les entrees objet_source et objet cible par convenance
923
-		foreach ($liens as $l) {
924
-			$l[$objet_source] = $l[$primary];
925
-			$l[$l['objet']] = $l['id_objet'];
926
-			$trouve[] = $l;
927
-		}
928
-	}
929
-
930
-	return $trouve;
914
+    $trouve = array();
915
+    foreach ($objets as $objet => $id_objets) {
916
+        $objet = ($objet == '*') ? $objet : objet_type($objet); # securite
917
+        // gerer les roles s'il y en a dans $cond
918
+        list($cond) = roles_creer_condition_role($objet_source, $objet, $cond, true);
919
+        // lien_where prend en charge les $id_objets sous forme int ou array
920
+        $where = lien_where($primary, $id, $objet, $id_objets, $cond);
921
+        $liens = sql_allfetsel('*', $table_lien, $where);
922
+        // ajouter les entrees objet_source et objet cible par convenance
923
+        foreach ($liens as $l) {
924
+            $l[$objet_source] = $l[$primary];
925
+            $l[$l['objet']] = $l['id_objet'];
926
+            $trouve[] = $l;
927
+        }
928
+    }
929
+
930
+    return $trouve;
931 931
 }
932 932
 
933 933
 /**
@@ -938,25 +938,25 @@  discard block
 block discarded – undo
938 938
  * @param array|int $ids
939 939
  */
940 940
 function lien_propage_date_modif($objet, $ids) {
941
-	static $done = array();
942
-	$hash = md5($objet . serialize($ids));
943
-
944
-	// sql_updateq, peut être un rien lent.
945
-	// On évite de l'appeler 2 fois sur les mêmes choses
946
-	if (isset($done[$hash])) {
947
-		return;
948
-	}
949
-
950
-	$trouver_table = charger_fonction('trouver_table', 'base');
951
-
952
-	$table = table_objet_sql($objet);
953
-	if ($desc = $trouver_table($table)
954
-		and isset($desc['field']['date_modif'])
955
-	) {
956
-		$primary = id_table_objet($objet);
957
-		$where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=" . intval($ids));
958
-		sql_updateq($table, array('date_modif' => date('Y-m-d H:i:s')), $where);
959
-	}
960
-
961
-	$done[$hash] = true;
941
+    static $done = array();
942
+    $hash = md5($objet . serialize($ids));
943
+
944
+    // sql_updateq, peut être un rien lent.
945
+    // On évite de l'appeler 2 fois sur les mêmes choses
946
+    if (isset($done[$hash])) {
947
+        return;
948
+    }
949
+
950
+    $trouver_table = charger_fonction('trouver_table', 'base');
951
+
952
+    $table = table_objet_sql($objet);
953
+    if ($desc = $trouver_table($table)
954
+        and isset($desc['field']['date_modif'])
955
+    ) {
956
+        $primary = id_table_objet($objet);
957
+        $where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=" . intval($ids));
958
+        sql_updateq($table, array('date_modif' => date('Y-m-d H:i:s')), $where);
959
+    }
960
+
961
+    $done[$hash] = true;
962 962
 }
Please login to merge, or discard this patch.
ecrire/public/decompiler.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -11,129 +11,129 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP
18 18
 
19 19
 function decompiler_boucle($struct, $fmt = '', $prof = 0) {
20
-	$nom = $struct->id_boucle;
21
-	$preaff = decompiler_($struct->preaff, $fmt, $prof);
22
-	$avant = decompiler_($struct->avant, $fmt, $prof);
23
-	$apres = decompiler_($struct->apres, $fmt, $prof);
24
-	$altern = decompiler_($struct->altern, $fmt, $prof);
25
-	$milieu = decompiler_($struct->milieu, $fmt, $prof);
26
-	$postaff = decompiler_($struct->postaff, $fmt, $prof);
27
-
28
-	$type = $struct->sql_serveur ? "$struct->sql_serveur:" : '';
29
-	$type .= ($struct->type_requete ? $struct->type_requete :
30
-		$struct->table_optionnelle);
31
-
32
-	if ($struct->jointures_explicites) {
33
-		$type .= " " . $struct->jointures_explicites;
34
-	}
35
-	if ($struct->table_optionnelle) {
36
-		$type .= "?";
37
-	}
38
-	// Revoir le cas de la boucle recursive
39
-
40
-	$crit = $struct->param;
41
-	if ($crit and !is_array($crit[0])) {
42
-		$type = strtolower($type) . array_shift($crit);
43
-	}
44
-	$crit = decompiler_criteres($struct, $fmt, $prof);
45
-
46
-	$f = 'format_boucle_' . $fmt;
47
-
48
-	return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof);
20
+    $nom = $struct->id_boucle;
21
+    $preaff = decompiler_($struct->preaff, $fmt, $prof);
22
+    $avant = decompiler_($struct->avant, $fmt, $prof);
23
+    $apres = decompiler_($struct->apres, $fmt, $prof);
24
+    $altern = decompiler_($struct->altern, $fmt, $prof);
25
+    $milieu = decompiler_($struct->milieu, $fmt, $prof);
26
+    $postaff = decompiler_($struct->postaff, $fmt, $prof);
27
+
28
+    $type = $struct->sql_serveur ? "$struct->sql_serveur:" : '';
29
+    $type .= ($struct->type_requete ? $struct->type_requete :
30
+        $struct->table_optionnelle);
31
+
32
+    if ($struct->jointures_explicites) {
33
+        $type .= " " . $struct->jointures_explicites;
34
+    }
35
+    if ($struct->table_optionnelle) {
36
+        $type .= "?";
37
+    }
38
+    // Revoir le cas de la boucle recursive
39
+
40
+    $crit = $struct->param;
41
+    if ($crit and !is_array($crit[0])) {
42
+        $type = strtolower($type) . array_shift($crit);
43
+    }
44
+    $crit = decompiler_criteres($struct, $fmt, $prof);
45
+
46
+    $f = 'format_boucle_' . $fmt;
47
+
48
+    return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof);
49 49
 }
50 50
 
51 51
 function decompiler_include($struct, $fmt = '', $prof = 0) {
52
-	$res = array();
53
-	foreach ($struct->param ? $struct->param : array() as $couple) {
54
-		array_shift($couple);
55
-		foreach ($couple as $v) {
56
-			$res[] = decompiler_($v, $fmt, $prof);
57
-		}
58
-	}
59
-	$file = is_string($struct->texte) ? $struct->texte :
60
-		decompiler_($struct->texte, $fmt, $prof);
61
-	$f = 'format_inclure_' . $fmt;
62
-
63
-	return $f($file, $res, $prof);
52
+    $res = array();
53
+    foreach ($struct->param ? $struct->param : array() as $couple) {
54
+        array_shift($couple);
55
+        foreach ($couple as $v) {
56
+            $res[] = decompiler_($v, $fmt, $prof);
57
+        }
58
+    }
59
+    $file = is_string($struct->texte) ? $struct->texte :
60
+        decompiler_($struct->texte, $fmt, $prof);
61
+    $f = 'format_inclure_' . $fmt;
62
+
63
+    return $f($file, $res, $prof);
64 64
 }
65 65
 
66 66
 function decompiler_texte($struct, $fmt = '', $prof = 0) {
67
-	$f = 'format_texte_' . $fmt;
67
+    $f = 'format_texte_' . $fmt;
68 68
 
69
-	return strlen($struct->texte) ? $f($struct->texte, $prof) : '';
69
+    return strlen($struct->texte) ? $f($struct->texte, $prof) : '';
70 70
 }
71 71
 
72 72
 function decompiler_polyglotte($struct, $fmt = '', $prof = 0) {
73
-	$f = 'format_polyglotte_' . $fmt;
73
+    $f = 'format_polyglotte_' . $fmt;
74 74
 
75
-	return $f($struct->traductions, $prof);
75
+    return $f($struct->traductions, $prof);
76 76
 }
77 77
 
78 78
 function decompiler_idiome($struct, $fmt = '', $prof = 0) {
79
-	$args = array();
80
-	foreach ($struct->arg as $k => $v) {
81
-		$args[$k] = public_decompiler($v, $fmt, $prof);
82
-	}
79
+    $args = array();
80
+    foreach ($struct->arg as $k => $v) {
81
+        $args[$k] = public_decompiler($v, $fmt, $prof);
82
+    }
83 83
 
84
-	$filtres = decompiler_liste($struct->param, $fmt, $prof);
84
+    $filtres = decompiler_liste($struct->param, $fmt, $prof);
85 85
 
86
-	$f = 'format_idiome_' . $fmt;
86
+    $f = 'format_idiome_' . $fmt;
87 87
 
88
-	return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof);
88
+    return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof);
89 89
 }
90 90
 
91 91
 function decompiler_champ($struct, $fmt = '', $prof = 0) {
92
-	$avant = decompiler_($struct->avant, $fmt, $prof);
93
-	$apres = decompiler_($struct->apres, $fmt, $prof);
94
-	$args = $filtres = '';
95
-	if ($p = $struct->param) {
96
-		if ($p[0][0] === '') {
97
-			$args = decompiler_liste(array(array_shift($p)), $fmt, $prof);
98
-		}
99
-		$filtres = decompiler_liste($p, $fmt, $prof);
100
-	}
101
-	$f = 'format_champ_' . $fmt;
102
-
103
-	return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof);
92
+    $avant = decompiler_($struct->avant, $fmt, $prof);
93
+    $apres = decompiler_($struct->apres, $fmt, $prof);
94
+    $args = $filtres = '';
95
+    if ($p = $struct->param) {
96
+        if ($p[0][0] === '') {
97
+            $args = decompiler_liste(array(array_shift($p)), $fmt, $prof);
98
+        }
99
+        $filtres = decompiler_liste($p, $fmt, $prof);
100
+    }
101
+    $f = 'format_champ_' . $fmt;
102
+
103
+    return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof);
104 104
 }
105 105
 
106 106
 function decompiler_liste($sources, $fmt = '', $prof = 0) {
107
-	if (!is_array($sources)) {
108
-		return '';
109
-	}
110
-	$f = 'format_liste_' . $fmt;
111
-	$res = '';
112
-	foreach ($sources as $arg) {
113
-		if (!is_array($arg)) {
114
-			continue; // ne devrait pas arriver.
115
-		} else {
116
-			$r = array_shift($arg);
117
-		}
118
-		$args = array();
119
-		foreach ($arg as $v) {
120
-			// cas des arguments entoures de ' ou "
121
-			if ((count($v) == 1)
122
-				and $v[0]->type == 'texte'
123
-				and (strlen($v[0]->apres) == 1)
124
-				and $v[0]->apres == $v[0]->avant
125
-			) {
126
-				$args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres;
127
-			} else {
128
-				$args[] = decompiler_($v, $fmt, 0 - $prof);
129
-			}
130
-		}
131
-		if (($r !== '') or $args) {
132
-			$res .= $f($r, $args, $prof);
133
-		}
134
-	}
135
-
136
-	return $res;
107
+    if (!is_array($sources)) {
108
+        return '';
109
+    }
110
+    $f = 'format_liste_' . $fmt;
111
+    $res = '';
112
+    foreach ($sources as $arg) {
113
+        if (!is_array($arg)) {
114
+            continue; // ne devrait pas arriver.
115
+        } else {
116
+            $r = array_shift($arg);
117
+        }
118
+        $args = array();
119
+        foreach ($arg as $v) {
120
+            // cas des arguments entoures de ' ou "
121
+            if ((count($v) == 1)
122
+                and $v[0]->type == 'texte'
123
+                and (strlen($v[0]->apres) == 1)
124
+                and $v[0]->apres == $v[0]->avant
125
+            ) {
126
+                $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres;
127
+            } else {
128
+                $args[] = decompiler_($v, $fmt, 0 - $prof);
129
+            }
130
+        }
131
+        if (($r !== '') or $args) {
132
+            $res .= $f($r, $args, $prof);
133
+        }
134
+    }
135
+
136
+    return $res;
137 137
 }
138 138
 
139 139
 // Decompilation des criteres: on triche et on deroge:
@@ -141,91 +141,91 @@  discard block
 block discarded – undo
141 141
 // - le champ apres signale le critere {"separateur"} ou {'separateur'}
142 142
 // - les champs sont implicitement etendus (crochets implicites mais interdits)
143 143
 function decompiler_criteres($boucle, $fmt = '', $prof = 0) {
144
-	$sources = $boucle->param;
145
-	if (!is_array($sources)) {
146
-		return '';
147
-	}
148
-	$res = '';
149
-	$f = 'format_critere_' . $fmt;
150
-	foreach ($sources as $crit) {
151
-		if (!is_array($crit)) {
152
-			continue;
153
-		} // boucle recursive
154
-		array_shift($crit);
155
-		$args = array();
156
-		foreach ($crit as $i => $v) {
157
-			if ((count($v) == 1)
158
-				and $v[0]->type == 'texte'
159
-				and $v[0]->apres
160
-			) {
161
-				$args[] = array(array('texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)));
162
-			} else {
163
-				$res2 = array();
164
-				foreach ($v as $k => $p) {
165
-					if (isset($p->type)
166
-						and function_exists($d = 'decompiler_' . $p->type)
167
-					) {
168
-						$r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]);
169
-						$res2[] = array($p->type, $r);
170
-					} else {
171
-						spip_log("critere $i / $k mal forme");
172
-					}
173
-				}
174
-				$args[] = $res2;
175
-			}
176
-		}
177
-		$res .= $f($args);
178
-	}
179
-
180
-	return $res;
144
+    $sources = $boucle->param;
145
+    if (!is_array($sources)) {
146
+        return '';
147
+    }
148
+    $res = '';
149
+    $f = 'format_critere_' . $fmt;
150
+    foreach ($sources as $crit) {
151
+        if (!is_array($crit)) {
152
+            continue;
153
+        } // boucle recursive
154
+        array_shift($crit);
155
+        $args = array();
156
+        foreach ($crit as $i => $v) {
157
+            if ((count($v) == 1)
158
+                and $v[0]->type == 'texte'
159
+                and $v[0]->apres
160
+            ) {
161
+                $args[] = array(array('texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)));
162
+            } else {
163
+                $res2 = array();
164
+                foreach ($v as $k => $p) {
165
+                    if (isset($p->type)
166
+                        and function_exists($d = 'decompiler_' . $p->type)
167
+                    ) {
168
+                        $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]);
169
+                        $res2[] = array($p->type, $r);
170
+                    } else {
171
+                        spip_log("critere $i / $k mal forme");
172
+                    }
173
+                }
174
+                $args[] = $res2;
175
+            }
176
+        }
177
+        $res .= $f($args);
178
+    }
179
+
180
+    return $res;
181 181
 }
182 182
 
183 183
 
184 184
 function decompiler_($liste, $fmt = '', $prof = 0) {
185
-	if (!is_array($liste)) {
186
-		return '';
187
-	}
188
-	$prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1);
189
-	$contenu = array();
190
-	foreach ($liste as $k => $p) {
191
-		if (!isset($p->type)) {
192
-			continue;
193
-		} #??????
194
-		$d = 'decompiler_' . $p->type;
195
-		$next = isset($liste[$k + 1]) ? $liste[$k + 1] : false;
196
-		// Forcer le champ etendu si son source (pas les reecritures)
197
-		// contenait des args et s'il est suivi d'espaces,
198
-		// le champ simple les eliminant est un bug helas perenne.
199
-
200
-		if ($next
201
-			and ($next->type == 'texte')
202
-			and $p->type == 'champ'
203
-			and !$p->apres
204
-			and !$p->avant
205
-			and $p->fonctions
206
-		) {
207
-			$n = strlen($next->texte) - strlen(ltrim($next->texte));
208
-			if ($n) {
209
-				$champ = new Texte;
210
-				$champ->texte = substr($next->texte, 0, $n);
211
-				$champ->ligne = $p->ligne;
212
-				$p->apres = array($champ);
213
-				$next->texte = substr($next->texte, $n);
214
-			}
215
-		}
216
-		$contenu[] = array($d($p, $fmt, $prof2), $p->type);
217
-
218
-	}
219
-	$f = 'format_suite_' . $fmt;
220
-
221
-	return $f($contenu);
185
+    if (!is_array($liste)) {
186
+        return '';
187
+    }
188
+    $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1);
189
+    $contenu = array();
190
+    foreach ($liste as $k => $p) {
191
+        if (!isset($p->type)) {
192
+            continue;
193
+        } #??????
194
+        $d = 'decompiler_' . $p->type;
195
+        $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false;
196
+        // Forcer le champ etendu si son source (pas les reecritures)
197
+        // contenait des args et s'il est suivi d'espaces,
198
+        // le champ simple les eliminant est un bug helas perenne.
199
+
200
+        if ($next
201
+            and ($next->type == 'texte')
202
+            and $p->type == 'champ'
203
+            and !$p->apres
204
+            and !$p->avant
205
+            and $p->fonctions
206
+        ) {
207
+            $n = strlen($next->texte) - strlen(ltrim($next->texte));
208
+            if ($n) {
209
+                $champ = new Texte;
210
+                $champ->texte = substr($next->texte, 0, $n);
211
+                $champ->ligne = $p->ligne;
212
+                $p->apres = array($champ);
213
+                $next->texte = substr($next->texte, $n);
214
+            }
215
+        }
216
+        $contenu[] = array($d($p, $fmt, $prof2), $p->type);
217
+
218
+    }
219
+    $f = 'format_suite_' . $fmt;
220
+
221
+    return $f($contenu);
222 222
 }
223 223
 
224 224
 function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') {
225
-	if (!include_spip('public/format_' . $fmt)) {
226
-		return "'$fmt'?";
227
-	}
228
-	$f = 'decompiler_' . $quoi;
225
+    if (!include_spip('public/format_' . $fmt)) {
226
+        return "'$fmt'?";
227
+    }
228
+    $f = 'decompiler_' . $quoi;
229 229
 
230
-	return $f($liste, $fmt, $prof);
230
+    return $f($liste, $fmt, $prof);
231 231
 }
Please login to merge, or discard this patch.