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