Completed
Push — master ( 08981b...30650c )
by cam
04:04
created
ecrire/inc/chercher_rubrique.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 if (!defined('_SPIP_SELECT_RUBRIQUES')) {
25
-	/**
26
-	 * @var int Nombre de rubriques maximum du sélecteur de rubriques. 
27
-	 * Au delà, on bascule sur un sélecteur ajax.
28
-	 * mettre 100000 pour desactiver ajax 
29
-	 */
30
-	define('_SPIP_SELECT_RUBRIQUES', 20); 
25
+    /**
26
+     * @var int Nombre de rubriques maximum du sélecteur de rubriques. 
27
+     * Au delà, on bascule sur un sélecteur ajax.
28
+     * mettre 100000 pour desactiver ajax 
29
+     */
30
+    define('_SPIP_SELECT_RUBRIQUES', 20); 
31 31
 }
32 32
 
33 33
 /**
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
  *     Code HTML du sélecteur
56 56
  **/
57 57
 function inc_chercher_rubrique_dist($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') {
58
-	if (sql_countsel('spip_rubriques') < 1) {
59
-		return '';
60
-	}
61
-
62
-	// Mode sans Ajax :
63
-	// - soit parce que le cookie ajax n'est pas la
64
-	// - soit parce qu'il y a peu de rubriques
65
-	if (_SPIP_AJAX < 1
66
-		or $type == 'breve'
67
-		or sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES
68
-	) {
69
-		return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem);
70
-	} else {
71
-		return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do);
72
-	}
58
+    if (sql_countsel('spip_rubriques') < 1) {
59
+        return '';
60
+    }
61
+
62
+    // Mode sans Ajax :
63
+    // - soit parce que le cookie ajax n'est pas la
64
+    // - soit parce qu'il y a peu de rubriques
65
+    if (_SPIP_AJAX < 1
66
+        or $type == 'breve'
67
+        or sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES
68
+    ) {
69
+        return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem);
70
+    } else {
71
+        return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do);
72
+    }
73 73
 
74 74
 }
75 75
 
@@ -87,17 +87,17 @@  discard block
 block discarded – undo
87 87
  **/
88 88
 function style_menu_rubriques($i) {
89 89
 
90
-	$espace = '';
91
-	$style = '';
92
-	for ($count = 1; $count <= $i; $count++) {
93
-		$espace .= "&nbsp;&nbsp;&nbsp;&nbsp;";
94
-	}
95
-	if ($i == 1) {
96
-		$espace = "";
97
-	}
98
-	$class = "niveau_$i";
99
-
100
-	return array($class, $style, $espace);
90
+    $espace = '';
91
+    $style = '';
92
+    for ($count = 1; $count <= $i; $count++) {
93
+        $espace .= "&nbsp;&nbsp;&nbsp;&nbsp;";
94
+    }
95
+    if ($i == 1) {
96
+        $espace = "";
97
+    }
98
+    $class = "niveau_$i";
99
+
100
+    return array($class, $style, $espace);
101 101
 }
102 102
 
103 103
 /**
@@ -121,52 +121,52 @@  discard block
 block discarded – undo
121 121
  *     Code HTML du sélecteur
122 122
  **/
123 123
 function sous_menu_rubriques($id_rubrique, $root, $niv, &$data, &$enfants, $exclus, $restreint, $type) {
124
-	static $decalage_secteur;
125
-
126
-	// Si on a demande l'exclusion ne pas descendre dans la rubrique courante
127
-	if ($exclus > 0
128
-		and $root == $exclus
129
-	) {
130
-		return '';
131
-	}
132
-
133
-	// en fonction du niveau faire un affichage plus ou moins kikoo
134
-
135
-	// selected ?
136
-	$selected = ($root == $id_rubrique) ? ' selected="selected"' : '';
137
-
138
-	// le style en fonction de la profondeur
139
-	list($class, $style, $espace) = style_menu_rubriques($niv);
140
-
141
-	$class .= " selec_rub";
142
-
143
-	// creer l'<option> pour la rubrique $root
144
-
145
-	if (isset($data[$root])) # pas de racine sauf pour les rubriques
146
-	{
147
-		$r = "<option$selected value='$root' class='$class' style='$style'>$espace"
148
-			. $data[$root]
149
-			. '</option>' . "\n";
150
-	} else {
151
-		$r = '';
152
-	}
153
-
154
-	// et le sous-menu pour ses enfants
155
-	$sous = '';
156
-	if (isset($enfants[$root])) {
157
-		foreach ($enfants[$root] as $sousrub) {
158
-			$sous .= sous_menu_rubriques($id_rubrique, $sousrub,
159
-				$niv + 1, $data, $enfants, $exclus, $restreint, $type);
160
-		}
161
-	}
162
-
163
-	// si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques
164
-	if ($restreint and $root != $id_rubrique and !autoriser('publierdans', 'rubrique', $root)) {
165
-		return $sous;
166
-	}
167
-
168
-	// et voila le travail
169
-	return $r . $sous;
124
+    static $decalage_secteur;
125
+
126
+    // Si on a demande l'exclusion ne pas descendre dans la rubrique courante
127
+    if ($exclus > 0
128
+        and $root == $exclus
129
+    ) {
130
+        return '';
131
+    }
132
+
133
+    // en fonction du niveau faire un affichage plus ou moins kikoo
134
+
135
+    // selected ?
136
+    $selected = ($root == $id_rubrique) ? ' selected="selected"' : '';
137
+
138
+    // le style en fonction de la profondeur
139
+    list($class, $style, $espace) = style_menu_rubriques($niv);
140
+
141
+    $class .= " selec_rub";
142
+
143
+    // creer l'<option> pour la rubrique $root
144
+
145
+    if (isset($data[$root])) # pas de racine sauf pour les rubriques
146
+    {
147
+        $r = "<option$selected value='$root' class='$class' style='$style'>$espace"
148
+            . $data[$root]
149
+            . '</option>' . "\n";
150
+    } else {
151
+        $r = '';
152
+    }
153
+
154
+    // et le sous-menu pour ses enfants
155
+    $sous = '';
156
+    if (isset($enfants[$root])) {
157
+        foreach ($enfants[$root] as $sousrub) {
158
+            $sous .= sous_menu_rubriques($id_rubrique, $sousrub,
159
+                $niv + 1, $data, $enfants, $exclus, $restreint, $type);
160
+        }
161
+    }
162
+
163
+    // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques
164
+    if ($restreint and $root != $id_rubrique and !autoriser('publierdans', 'rubrique', $root)) {
165
+        return $sous;
166
+    }
167
+
168
+    // et voila le travail
169
+    return $r . $sous;
170 170
 }
171 171
 
172 172
 /**
@@ -187,67 +187,67 @@  discard block
 block discarded – undo
187 187
  *     Code HTML du sélecteur
188 188
  **/
189 189
 function selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem = 0) {
190
-	$data = array();
191
-	if ($type == 'rubrique' and autoriser('publierdans', 'rubrique', 0)) {
192
-		$data[0] = _T('info_racine_site');
193
-	}
194
-	# premier choix = neant
195
-	# si auteur (rubriques restreintes)
196
-	# ou si creation avec id_rubrique=0
197
-	elseif ($type == 'auteur' or !$id_rubrique) {
198
-		$data[0] = '&nbsp;';
199
-	}
200
-
201
-	//
202
-	// creer une structure contenant toute l'arborescence
203
-	//
204
-
205
-	include_spip('base/abstract_sql');
206
-	$q = sql_select("id_rubrique, id_parent, titre, statut, lang, langue_choisie", "spip_rubriques",
207
-		($type == 'breve' ? ' id_parent=0 ' : ''), '', "0+titre,titre");
208
-	while ($r = sql_fetch($q)) {
209
-		if (autoriser('voir', 'rubrique', $r['id_rubrique'])) {
210
-			// titre largeur maxi a 50
211
-			$titre = couper(supprimer_tags(typo($r['titre'])) . " ", 50);
212
-			if ($GLOBALS['meta']['multi_rubriques'] == 'oui'
213
-				and ($r['langue_choisie'] == "oui" or $r['id_parent'] == 0)
214
-			) {
215
-				$titre .= ' [' . traduire_nom_langue($r['lang']) . ']';
216
-			}
217
-			$data[$r['id_rubrique']] = $titre;
218
-			$enfants[$r['id_parent']][] = $r['id_rubrique'];
219
-			if ($id_rubrique == $r['id_rubrique']) {
220
-				$id_parent = $r['id_parent'];
221
-			}
222
-		}
223
-	}
224
-
225
-	// si une seule rubrique comme choix possible,
226
-	// inutile de mettre le selecteur sur un choix vide par defaut
227
-	// sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas
228
-	if (count($data) == 2
229
-		and isset($data[0])
230
-		and !in_array($type, array('auteur', 'rubrique'))
231
-		and !$id_rubrique
232
-	) {
233
-		unset($data[0]);
234
-	}
235
-
236
-
237
-	$opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type);
238
-	$att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'";
239
-
240
-	if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) {
241
-		$r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2];
242
-	} else {
243
-		$r = "<select" . $att . " size='1'>\n$opt</select>\n";
244
-	}
245
-
246
-	# message pour neuneus (a supprimer ?)
190
+    $data = array();
191
+    if ($type == 'rubrique' and autoriser('publierdans', 'rubrique', 0)) {
192
+        $data[0] = _T('info_racine_site');
193
+    }
194
+    # premier choix = neant
195
+    # si auteur (rubriques restreintes)
196
+    # ou si creation avec id_rubrique=0
197
+    elseif ($type == 'auteur' or !$id_rubrique) {
198
+        $data[0] = '&nbsp;';
199
+    }
200
+
201
+    //
202
+    // creer une structure contenant toute l'arborescence
203
+    //
204
+
205
+    include_spip('base/abstract_sql');
206
+    $q = sql_select("id_rubrique, id_parent, titre, statut, lang, langue_choisie", "spip_rubriques",
207
+        ($type == 'breve' ? ' id_parent=0 ' : ''), '', "0+titre,titre");
208
+    while ($r = sql_fetch($q)) {
209
+        if (autoriser('voir', 'rubrique', $r['id_rubrique'])) {
210
+            // titre largeur maxi a 50
211
+            $titre = couper(supprimer_tags(typo($r['titre'])) . " ", 50);
212
+            if ($GLOBALS['meta']['multi_rubriques'] == 'oui'
213
+                and ($r['langue_choisie'] == "oui" or $r['id_parent'] == 0)
214
+            ) {
215
+                $titre .= ' [' . traduire_nom_langue($r['lang']) . ']';
216
+            }
217
+            $data[$r['id_rubrique']] = $titre;
218
+            $enfants[$r['id_parent']][] = $r['id_rubrique'];
219
+            if ($id_rubrique == $r['id_rubrique']) {
220
+                $id_parent = $r['id_parent'];
221
+            }
222
+        }
223
+    }
224
+
225
+    // si une seule rubrique comme choix possible,
226
+    // inutile de mettre le selecteur sur un choix vide par defaut
227
+    // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas
228
+    if (count($data) == 2
229
+        and isset($data[0])
230
+        and !in_array($type, array('auteur', 'rubrique'))
231
+        and !$id_rubrique
232
+    ) {
233
+        unset($data[0]);
234
+    }
235
+
236
+
237
+    $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type);
238
+    $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'";
239
+
240
+    if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) {
241
+        $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2];
242
+    } else {
243
+        $r = "<select" . $att . " size='1'>\n$opt</select>\n";
244
+    }
245
+
246
+    # message pour neuneus (a supprimer ?)
247 247
 #	if ($type != 'auteur' AND $type != 'breve')
248 248
 #		$r .= "\n<br />"._T('texte_rappel_selection_champs');
249 249
 
250
-	return $r;
250
+    return $r;
251 251
 }
252 252
 
253 253
 /**
@@ -281,26 +281,26 @@  discard block
 block discarded – undo
281 281
  */
282 282
 function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') {
283 283
 
284
-	if ($id_rubrique) {
285
-		$titre = sql_getfetsel("titre", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
286
-	} else {
287
-		if ($type == 'auteur') {
288
-			$titre = '&nbsp;';
289
-		} else {
290
-			$titre = _T('info_racine_site');
291
-		}
292
-	}
284
+    if ($id_rubrique) {
285
+        $titre = sql_getfetsel("titre", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
286
+    } else {
287
+        if ($type == 'auteur') {
288
+            $titre = '&nbsp;';
289
+        } else {
290
+            $titre = _T('info_racine_site');
291
+        }
292
+    }
293 293
 
294
-	$titre = str_replace('&amp;', '&', entites_html(textebrut(typo($titre))));
295
-	$init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'";
294
+    $titre = str_replace('&amp;', '&', entites_html(textebrut(typo($titre))));
295
+    $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'";
296 296
 
297
-	$url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do"
298
-		. (!$idem ? '' : "&exclus=$idem")
299
-		. ($restreint ? "" : "&racine=oui")
300
-		. (isset($GLOBALS['var_profile']) ? '&var_profile=1' : ''));
297
+    $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do"
298
+        . (!$idem ? '' : "&exclus=$idem")
299
+        . ($restreint ? "" : "&racine=oui")
300
+        . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : ''));
301 301
 
302 302
 
303
-	return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique);
303
+    return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique);
304 304
 }
305 305
 
306 306
 /**
@@ -330,26 +330,26 @@  discard block
 block discarded – undo
330 330
  *     Code HTML du sélecteur de rubrique AJAX
331 331
  **/
332 332
 function construire_selecteur($url, $js, $idom, $name, $init = '', $id = 0) {
333
-	$icone = (strpos($idom, 'auteur') !== false) ? 'auteur-24.png' : 'rechercher-20.png';
334
-
335
-	return
336
-		"<div class='rubrique_actuelle'><a href='#' onclick=\""
337
-		. $js
338
-		. "return charger_node_url_si_vide('"
339
-		. $url
340
-		. "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'><img src='"
341
-		. chemin_image($icone)
342
-		. "'\nstyle='vertical-align: middle;' alt='" . attribut_html(_T('titre_image_selecteur')) . "' /></a><img src='"
343
-		. chemin_image('searching.gif')
344
-		. "' id='img_"
345
-		. $idom
346
-		. "'\nstyle='visibility: hidden;' alt='*' />"
347
-		. "<input id='titreparent' name='titreparent'"
348
-		. $init
349
-		. " />"
350
-		. "<input type='hidden' id='$name' name='$name' value='"
351
-		. $id
352
-		. "' /><div class='nettoyeur'></div></div><div id='"
353
-		. $idom
354
-		. "'\nstyle='display: none;'></div>";
333
+    $icone = (strpos($idom, 'auteur') !== false) ? 'auteur-24.png' : 'rechercher-20.png';
334
+
335
+    return
336
+        "<div class='rubrique_actuelle'><a href='#' onclick=\""
337
+        . $js
338
+        . "return charger_node_url_si_vide('"
339
+        . $url
340
+        . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'><img src='"
341
+        . chemin_image($icone)
342
+        . "'\nstyle='vertical-align: middle;' alt='" . attribut_html(_T('titre_image_selecteur')) . "' /></a><img src='"
343
+        . chemin_image('searching.gif')
344
+        . "' id='img_"
345
+        . $idom
346
+        . "'\nstyle='visibility: hidden;' alt='*' />"
347
+        . "<input id='titreparent' name='titreparent'"
348
+        . $init
349
+        . " />"
350
+        . "<input type='hidden' id='$name' name='$name' value='"
351
+        . $id
352
+        . "' /><div class='nettoyeur'></div></div><div id='"
353
+        . $idom
354
+        . "'\nstyle='display: none;'></div>";
355 355
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	{
147 147
 		$r = "<option$selected value='$root' class='$class' style='$style'>$espace"
148 148
 			. $data[$root]
149
-			. '</option>' . "\n";
149
+			. '</option>'."\n";
150 150
 	} else {
151 151
 		$r = '';
152 152
 	}
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	}
167 167
 
168 168
 	// et voila le travail
169
-	return $r . $sous;
169
+	return $r.$sous;
170 170
 }
171 171
 
172 172
 /**
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 	while ($r = sql_fetch($q)) {
209 209
 		if (autoriser('voir', 'rubrique', $r['id_rubrique'])) {
210 210
 			// titre largeur maxi a 50
211
-			$titre = couper(supprimer_tags(typo($r['titre'])) . " ", 50);
211
+			$titre = couper(supprimer_tags(typo($r['titre']))." ", 50);
212 212
 			if ($GLOBALS['meta']['multi_rubriques'] == 'oui'
213 213
 				and ($r['langue_choisie'] == "oui" or $r['id_parent'] == 0)
214 214
 			) {
215
-				$titre .= ' [' . traduire_nom_langue($r['lang']) . ']';
215
+				$titre .= ' ['.traduire_nom_langue($r['lang']).']';
216 216
 			}
217 217
 			$data[$r['id_rubrique']] = $titre;
218 218
 			$enfants[$r['id_parent']][] = $r['id_rubrique'];
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	$att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'";
239 239
 
240 240
 	if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) {
241
-		$r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2];
241
+		$r = "<input$att type='hidden' value='".$r[1]."' />".$r[2];
242 242
 	} else {
243
-		$r = "<select" . $att . " size='1'>\n$opt</select>\n";
243
+		$r = "<select".$att." size='1'>\n$opt</select>\n";
244 244
 	}
245 245
 
246 246
 	# message pour neuneus (a supprimer ?)
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') {
283 283
 
284 284
 	if ($id_rubrique) {
285
-		$titre = sql_getfetsel("titre", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
285
+		$titre = sql_getfetsel("titre", "spip_rubriques", "id_rubrique=".intval($id_rubrique));
286 286
 	} else {
287 287
 		if ($type == 'auteur') {
288 288
 			$titre = '&nbsp;';
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	}
293 293
 
294 294
 	$titre = str_replace('&amp;', '&', entites_html(textebrut(typo($titre))));
295
-	$init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'";
295
+	$init = " disabled='disabled' type='text' value=\"".$titre."\"\nstyle='width:300px;'";
296 296
 
297 297
 	$url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do"
298 298
 		. (!$idem ? '' : "&exclus=$idem")
@@ -337,9 +337,9 @@  discard block
 block discarded – undo
337 337
 		. $js
338 338
 		. "return charger_node_url_si_vide('"
339 339
 		. $url
340
-		. "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'><img src='"
340
+		. "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='".attribut_html(_T('titre_image_selecteur'))."'><img src='"
341 341
 		. chemin_image($icone)
342
-		. "'\nstyle='vertical-align: middle;' alt='" . attribut_html(_T('titre_image_selecteur')) . "' /></a><img src='"
342
+		. "'\nstyle='vertical-align: middle;' alt='".attribut_html(_T('titre_image_selecteur'))."' /></a><img src='"
343 343
 		. chemin_image('searching.gif')
344 344
 		. "' id='img_"
345 345
 		. $idom
Please login to merge, or discard this patch.