Completed
Push — spip-3.0 ( cd2822...016705 )
by cam
08:31
created
ecrire/public/quete.php 1 patch
Braces   +86 added lines, -58 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 //
16 18
 // Fonctions d'appel aux serveurs SQL presentes dans le code compile
@@ -48,18 +50,19 @@  discard block
 block discarded – undo
48 50
 	if (!isset($cache_quete[$connect][$table][$id])) {
49 51
 		if (!isset($cache_quete[$connect][$table]['_select'])){
50 52
 			$trouver_table = charger_fonction('trouver_table','base');
51
-			if (!$desc=$trouver_table($table,$connect) OR !isset($desc['field']['id_rubrique']))
52
-				// pas de parent rubrique, on passe
53
-				$cache_quete[$connect][$table]['_select'] = false; 
54
-			else {
53
+			if (!$desc=$trouver_table($table,$connect) OR !isset($desc['field']['id_rubrique'])) {
54
+							// pas de parent rubrique, on passe
55
+				$cache_quete[$connect][$table]['_select'] = false;
56
+			} else {
55 57
 				$select = ($table=='spip_rubriques'?'id_parent':'id_rubrique');
56 58
 				$select .= isset($desc['field']['lang'])?", lang":"";
57 59
 				$cache_quete[$connect][$table]['_select'] = $select;
58 60
 				$cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
59 61
 			}
60 62
 		}
61
-		if ($cache_quete[$connect][$table]['_select'])
62
-			$cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table,$cache_quete[$connect][$table]['_id']."=".intval($id),'','','','',$connect);
63
+		if ($cache_quete[$connect][$table]['_select']) {
64
+					$cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table,$cache_quete[$connect][$table]['_id']."=".intval($id),'','','','',$connect);
65
+		}
63 66
 	}
64 67
 	return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null;
65 68
 }
@@ -77,8 +80,9 @@  discard block
 block discarded – undo
77 80
  * @return int
78 81
  */
79 82
 function quete_parent($id_rubrique, $connect='') {
80
-	if (!$id_rubrique = intval($id_rubrique))
81
-		return 0;
83
+	if (!$id_rubrique = intval($id_rubrique)) {
84
+			return 0;
85
+	}
82 86
 	$id_parent = quete_parent_lang('spip_rubriques',$id_rubrique,$connect);
83 87
 	return $id_parent['id_parent'];
84 88
 }
@@ -126,8 +130,9 @@  discard block
 block discarded – undo
126 130
  * @return string
127 131
  */
128 132
 function quete_condition_postdates($champ_date, $serveur='', $ignore_previsu=false) {
129
-	if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu)
130
-		return "1=1";
133
+	if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) {
134
+			return "1=1";
135
+	}
131 136
 	return
132 137
 	  (isset($GLOBALS['meta']['date_prochain_postdate'])
133 138
 	     AND $GLOBALS['meta']['date_prochain_postdate'] > time())
@@ -153,19 +158,23 @@  discard block
 block discarded – undo
153 158
 	static $cond = array();
154 159
 	$key = func_get_args();
155 160
 	$key = implode("-",$key);
156
-	if (isset($cond[$key])) return $cond[$key];
161
+	if (isset($cond[$key])) {
162
+	    return $cond[$key];
163
+	}
157 164
 
158 165
 	$liste = $publie;
159
-	if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu)
160
-		$liste = $previsu;
166
+	if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) {
167
+			$liste = $previsu;
168
+	}
161 169
 	$not = false;
162 170
 	if (strncmp($liste,'!',1)==0){
163 171
 		$not = true;
164 172
 	  $liste = substr($liste,1);
165 173
 	}
166 174
 	// '' => ne rien afficher, '!'=> ne rien filtrer
167
-	if (!strlen($liste))
168
-		return $cond[$key]=($not?"1=1":"'0=1'");
175
+	if (!strlen($liste)) {
176
+			return $cond[$key]=($not?"1=1":"'0=1'");
177
+	}
169 178
 
170 179
 	$liste = explode(',',$liste);
171 180
 	$where = array();
@@ -188,8 +197,9 @@  discard block
 block discarded – undo
188 197
 				$where[] = "($mstatut<>".sql_quote($v)." OR $id_table.$primary IN (".sql_get_select("ssss.id_objet","spip_auteurs_liens AS ssss","ssss.objet=".sql_quote($objet)." AND ssss.id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']),'','','','',$serveur)."))";
189 198
 			}
190 199
 			// ignorer ce statut si on ne sait pas comment le filtrer
191
-			else
192
-				$v = "";
200
+			else {
201
+							$v = "";
202
+			}
193 203
 		}
194 204
 		// securite
195 205
 		$liste[$k] = preg_replace(",\W,","",$v);
@@ -197,8 +207,7 @@  discard block
 block discarded – undo
197 207
 	$liste = array_filter($liste);
198 208
   if (count($liste)==1){
199 209
 		$where[] = array('=', $mstatut, sql_quote(reset($liste),$serveur));
200
-  }
201
-  else {
210
+  } else {
202 211
 	  $where[] = sql_in($mstatut,$liste,$not,$serveur);
203 212
   }
204 213
 
@@ -207,8 +216,9 @@  discard block
 block discarded – undo
207 216
 		$where[] = $and;
208 217
 	}
209 218
 	$cond[$key] = reset($where);
210
-	if ($not)
211
-		$cond[$key] = array('NOT',$cond[$key]);
219
+	if ($not) {
220
+			$cond[$key] = array('NOT',$cond[$key]);
221
+	}
212 222
 
213 223
 	return $cond[$key];
214 224
 }
@@ -266,16 +276,17 @@  discard block
 block discarded – undo
266 276
  */
267 277
 function quete_logo($type, $onoff, $id, $id_rubrique, $flag) {
268 278
 	static $chercher_logo;
269
-	if (is_null($chercher_logo))
270
-		$chercher_logo = charger_fonction('chercher_logo', 'inc');
279
+	if (is_null($chercher_logo)) {
280
+			$chercher_logo = charger_fonction('chercher_logo', 'inc');
281
+	}
271 282
 	$nom = strtolower($onoff);
272 283
 
273 284
 	while (1) {
274 285
 		$on = $chercher_logo($id, $type, $nom);
275 286
 		if ($on) {
276
-			if ($flag)
277
-				return "$on[2].$on[3]";
278
-			else {
287
+			if ($flag) {
288
+							return "$on[2].$on[3]";
289
+			} else {
279 290
 				$taille = @getimagesize($on[0]);
280 291
 				$off = ($onoff != 'ON') ? '' :
281 292
 					$chercher_logo($id, $type, 'off');
@@ -286,16 +297,17 @@  discard block
 block discarded – undo
286 297
 					($off ? $off[0] . ($off[4]?"?$off[4]":"") : ''),
287 298
 					(!$taille ? '' : (" ".$taille[3])));
288 299
 			}
289
-		}
290
-        else if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE'))
291
-            return '';
292
-		else if ($id_rubrique) {
300
+		} else if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
301
+                    return '';
302
+        } else if ($id_rubrique) {
293 303
 			$type = 'id_rubrique';
294 304
 			$id = $id_rubrique;
295 305
 			$id_rubrique = 0;
296
-		} else if ($id AND $type == 'id_rubrique')
297
-			$id = quete_parent($id);
298
-		else return '';
306
+		} else if ($id AND $type == 'id_rubrique') {
307
+					$id = quete_parent($id);
308
+		} else {
309
+		    return '';
310
+		}
299 311
 	}
300 312
 }
301 313
 
@@ -311,7 +323,9 @@  discard block
 block discarded – undo
311 323
 function quete_logo_file($row, $connect=NULL) {
312 324
 	include_spip('inc/documents');
313 325
 	$logo = vignette_logo_document($row, $connect);
314
-	if (!$logo) $logo = image_du_document($row);
326
+	if (!$logo) {
327
+	    $logo = image_du_document($row);
328
+	}
315 329
 	if (!$logo){
316 330
 		$f = charger_fonction('vignette','inc');
317 331
 		$logo = $f($row['extension'], false);
@@ -319,8 +333,9 @@  discard block
 block discarded – undo
319 333
 	// si c'est une vignette type doc, la renvoyer direct
320 334
 	if (strcmp($logo,_DIR_PLUGINS)==0
321 335
 		OR strcmp($logo,_DIR_PLUGINS_DIST)==0
322
-		OR strcmp($logo,_DIR_RACINE.'prive/')==0)
323
-		return $logo;
336
+		OR strcmp($logo,_DIR_RACINE.'prive/')==0) {
337
+			return $logo;
338
+	}
324 339
 	return get_spip_doc($logo);
325 340
 }
326 341
 
@@ -350,13 +365,16 @@  discard block
 block discarded – undo
350 365
 function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect=NULL) {
351 366
 	include_spip('inc/documents');
352 367
 	$logo = '';
353
-	if (!in_array($mode_logo,array('icone','apercu')))
354
-		$logo = vignette_logo_document($row, $connect);
368
+	if (!in_array($mode_logo,array('icone','apercu'))) {
369
+			$logo = vignette_logo_document($row, $connect);
370
+	}
355 371
 	// si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
356
-	if ($mode_logo == 'vignette' AND !$logo)
357
-		return '';
358
-	if ($mode_logo == 'icone')
359
-		$row['fichier'] = '';
372
+	if ($mode_logo == 'vignette' AND !$logo) {
373
+			return '';
374
+	}
375
+	if ($mode_logo == 'icone') {
376
+			$row['fichier'] = '';
377
+	}
360 378
 	return vignette_automatique($logo, $row, $lien, $x, $y, $align);
361 379
 }
362 380
 
@@ -371,7 +389,9 @@  discard block
 block discarded – undo
371 389
  */
372 390
 function vignette_logo_document($row, $connect='')
373 391
 {
374
-	if (!$row['id_vignette']) return '';
392
+	if (!$row['id_vignette']) {
393
+	    return '';
394
+	}
375 395
 	$fichier = quete_fichier($row['id_vignette'], $connect);
376 396
 	if ($connect) {
377 397
 		$site = quete_meta('adresse_site', $connect);
@@ -379,8 +399,12 @@  discard block
 block discarded – undo
379 399
 		return "$site/$dir$fichier";
380 400
 	}
381 401
 	$f = get_spip_doc($fichier);
382
-	if ($f AND @file_exists($f)) return $f;
383
-	if ($row['mode'] !== 'vignette') return '';
402
+	if ($f AND @file_exists($f)) {
403
+	    return $f;
404
+	}
405
+	if ($row['mode'] !== 'vignette') {
406
+	    return '';
407
+	}
384 408
 	return generer_url_entite($row['id_document'], 'document','','', $connect);
385 409
 }
386 410
 
@@ -415,12 +439,13 @@  discard block
 block discarded – undo
415 439
 		$parent = 0;
416 440
 		if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
417 441
 			$enfants = array('id_rubrique'=>array('id_article'),'id_groupe'=>array('id_mot'));
418
-			if (isset($enfants[$type]))
419
-				foreach($enfants[$type] as $t)
442
+			if (isset($enfants[$type])) {
443
+							foreach($enfants[$type] as $t)
420 444
 					if (isset($reference[$t])
421 445
 						// cas de la reference donnee dynamiquement par la pagination
422 446
 						OR isset($reference["@$t"])) {
423 447
 						$type = $t;
448
+			}
424 449
 						$principal = isset($reference[$type])?$reference[$type]:$reference["@$type"];
425 450
 						continue;
426 451
 					}
@@ -434,13 +459,14 @@  discard block
 block discarded – undo
434 459
 					if (!$parent) {
435 460
 						$parent = sql_getfetsel('id_groupe','spip_mots',"id_mot=" . intval($principal), '','','','',$connect);
436 461
 					}
437
-					if ($parent)
438
-						$exposer[$m]['id_groupe'][$parent] = true;
439
-				}
440
-				else if ($type != 'id_groupe') {
462
+					if ($parent) {
463
+											$exposer[$m]['id_groupe'][$parent] = true;
464
+					}
465
+				} else if ($type != 'id_groupe') {
441 466
 				  if (!$parent) {
442
-				  	if ($type == 'id_rubrique')
443
-				  		$parent = $principal;
467
+				  	if ($type == 'id_rubrique') {
468
+				  					  		$parent = $principal;
469
+				  	}
444 470
 				  	if ($type == 'id_article') {
445 471
 						$parent = quete_rubrique($principal,$connect);
446 472
 				  	}
@@ -469,16 +495,18 @@  discard block
 block discarded – undo
469 495
 function quete_debut_pagination($primary,$valeur,$pas,$iter){
470 496
 	// on ne devrait pas arriver ici si la cle primaire est inexistante
471 497
 	// ou composee, mais verifions
472
-	if (!$primary OR preg_match('/[,\s]/',$primary))
473
-		return 0;
498
+	if (!$primary OR preg_match('/[,\s]/',$primary)) {
499
+			return 0;
500
+	}
474 501
 
475 502
 	$pos = 0;
476 503
 	while ($row = $iter->fetch() AND $row[$primary]!=$valeur){
477 504
 		$pos++;
478 505
 	}
479 506
 	// si on a pas trouve
480
-	if ($row[$primary]!=$valeur)
481
-		return 0;
507
+	if ($row[$primary]!=$valeur) {
508
+			return 0;
509
+	}
482 510
 
483 511
 	// sinon, calculer le bon numero de page
484 512
 	return floor($pos/$pas)*$pas;
Please login to merge, or discard this patch.
ecrire/public/styliser.php 1 patch
Braces   +30 added lines, -18 removed lines patch added patch discarded remove patch
@@ -11,7 +11,9 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 
14
-if (!defined('_ECRIRE_INC_VERSION')) return;
14
+if (!defined('_ECRIRE_INC_VERSION')) {
15
+    return;
16
+}
15 17
 
16 18
 // Ce fichier doit imperativement definir la fonction ci-dessous:
17 19
 
@@ -36,14 +38,16 @@  discard block
 block discarded – undo
36 38
 
37 39
 	// s'assurer que le fond est licite
38 40
 	// car il peut etre construit a partir d'une variable d'environnement
39
-	if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0)
40
-		$fond = "404";
41
+	if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0) {
42
+			$fond = "404";
43
+	}
41 44
   
42 45
 	// Choisir entre $fond-dist.html, $fond=7.html, etc?
43 46
 	$id_rubrique = 0;
44 47
 	// Chercher le fond qui va servir de squelette
45
-	if ($r = quete_rubrique_fond($contexte))
46
-		list($id_rubrique, $lang) = $r;
48
+	if ($r = quete_rubrique_fond($contexte)) {
49
+			list($id_rubrique, $lang) = $r;
50
+	}
47 51
 
48 52
 	// trouver un squelette du nom demande
49 53
 	// ne rien dire si on ne trouve pas, 
@@ -65,8 +69,9 @@  discard block
 block discarded – undo
65 69
 	);
66 70
 
67 71
 	if (test_espace_prive() OR defined('_ZPIP')) {
68
-		if (!$styliser_par_z)
69
-			$styliser_par_z = charger_fonction('styliser_par_z','public');
72
+		if (!$styliser_par_z) {
73
+					$styliser_par_z = charger_fonction('styliser_par_z','public');
74
+		}
70 75
 		$flux = $styliser_par_z($flux);
71 76
 	}
72 77
 
@@ -87,16 +92,18 @@  discard block
 block discarded – undo
87 92
 			$table = table_objet(substr($flux['args']['fond'],19));
88 93
 			$table_sql = table_objet_sql($table);
89 94
 			$objets = lister_tables_objets_sql();
90
-			if (isset($objets[$table_sql]))
91
-				$flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']);
95
+			if (isset($objets[$table_sql])) {
96
+							$flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']);
97
+			}
92 98
 		}
93 99
 		if (strncmp($flux['args']['fond'],'prive/objets/contenu/',21)==0){
94 100
 			$type = substr($flux['args']['fond'],21);
95 101
 			$table = table_objet($type);
96 102
 			$table_sql = table_objet_sql($table);
97 103
 			$objets = lister_tables_objets_sql();
98
-			if (isset($objets[$table_sql]))
99
-				$flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']);
104
+			if (isset($objets[$table_sql])) {
105
+							$flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']);
106
+			}
100 107
 		}
101 108
 	}
102 109
 	return $flux;
@@ -129,17 +136,21 @@  discard block
 block discarded – undo
129 136
 		array_unshift($l, 'rubrique');
130 137
 		foreach($l as $objet){
131 138
 			$id = id_table_objet($objet);
132
-			if (!isset($liste_objets[$id]))
133
-				$liste_objets[$id] = objet_type($objet,false);
139
+			if (!isset($liste_objets[$id])) {
140
+							$liste_objets[$id] = objet_type($objet,false);
141
+			}
134 142
 		}
135 143
 	}
136 144
 	$c = array_intersect_key($contexte,$liste_objets);
137
-	if (!count($c)) return false;
145
+	if (!count($c)) {
146
+	    return false;
147
+	}
138 148
 
139 149
 	$c = array_map('intval',$c);
140 150
 	$s = serialize($c);
141
-	if (isset($quete[$s]))
142
-		return $quete[$s];
151
+	if (isset($quete[$s])) {
152
+			return $quete[$s];
153
+	}
143 154
 
144 155
 	if (isset($c['id_rubrique']) AND $r = $c['id_rubrique']){
145 156
 		unset($c['id_rubrique']);
@@ -150,8 +161,9 @@  discard block
 block discarded – undo
150 161
 		if ($id
151 162
 		  AND $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]),$id)) {
152 163
 			$lang = isset($row['lang']) ? $row['lang'] : '';
153
-			if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique']))
154
-				return $quete[$s] = array ($id, $lang);
164
+			if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique'])) {
165
+							return $quete[$s] = array ($id, $lang);
166
+			}
155 167
 		}
156 168
 	}
157 169
 	return $quete[$s] = false;
Please login to merge, or discard this patch.
ecrire/public/jointures.php 1 patch
Braces   +91 added lines, -52 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 // deduction automatique d'une chaine de jointures 
16 18
 
@@ -48,12 +50,14 @@  discard block
 block discarded – undo
48 50
 function trouver_champs_decomposes($champ, $desc){
49 51
 	if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table
50 52
 	    OR array_key_exists($champ, $desc['field'])
51
-	)
52
-		return array($champ);
53
+	) {
54
+			return array($champ);
55
+	}
53 56
 	if (is_array($decompose = decompose_champ_id_objet($champ))){
54 57
 		array_pop($decompose);
55
-		if (count(array_intersect($decompose, array_keys($desc['field'])))==count($decompose))
56
-			return $decompose;
58
+		if (count(array_intersect($decompose, array_keys($desc['field'])))==count($decompose)) {
59
+					return $decompose;
60
+		}
57 61
 	}
58 62
 	return array($champ);
59 63
 }
@@ -89,7 +93,9 @@  discard block
 block discarded – undo
89 93
 		$res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max);
90 94
 		$max++;
91 95
 	}
92
-	if (!$res) return "";
96
+	if (!$res) {
97
+	    return "";
98
+	}
93 99
 
94 100
 	list($nom, $desc) = $depart;
95 101
 
@@ -130,15 +136,18 @@  discard block
 block discarded – undo
130 136
 	$cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle];
131 137
 	foreach ($res as $cle => $r){
132 138
 		list($d, $a, $j) = $r;
133
-		if (!$id_table) $id_table = $d;
139
+		if (!$id_table) {
140
+		    $id_table = $d;
141
+		}
134 142
 		$n = ++$cpt;
135 143
 		if (is_array($j)){ // c'est un lien sur un champ du type id_objet,objet,'article'
136 144
 			list($j1, $j2, $obj, $type) = $j;
137 145
 			// trouver de quel cote est (id_objet,objet)
138
-			if ($j1=="id_$obj")
139
-				$obj = "$id_table.$obj";
140
-			else
141
-				$obj = "L$n.$obj";
146
+			if ($j1=="id_$obj") {
147
+							$obj = "$id_table.$obj";
148
+			} else {
149
+							$obj = "L$n.$obj";
150
+			}
142 151
 			// le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure
143 152
 			// en cas d'optimisation
144 153
 			//$boucle->where[] = array("'='","'$obj'","sql_quote('$type')");
@@ -147,9 +156,9 @@  discard block
 block discarded – undo
147 156
 					array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')")
148 157
 					:
149 158
 					array($id_table, $j2, $j1, "$obj=".sql_quote($type));
159
+		} else {
160
+					$boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j);
150 161
 		}
151
-		else
152
-			$boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j);
153 162
 		$boucle->from[$id_table = "L$n"] = $a[0];
154 163
 	}
155 164
 
@@ -171,13 +180,16 @@  discard block
 block discarded – undo
171 180
 	    AND (count($boucle->from)==2)
172 181
 	        AND isset($a[1]['key']['PRIMARY KEY'])
173 182
 	            AND ($j==$a[1]['key']['PRIMARY KEY'])
174
-	)
175
-		$pk = true;
183
+	) {
184
+			$pk = true;
185
+	}
176 186
 
177 187
 	// la clause Group by est en conflit avec ORDER BY, a completer
178 188
 	$groups = liste_champs_jointures($nom, $desc, true);
179
-	if (!$pk) foreach ($groups as $id_prim){
189
+	if (!$pk) {
190
+	    foreach ($groups as $id_prim){
180 191
 		$id_field = $nom.'.'.$id_prim;
192
+	}
181 193
 		if (!in_array($id_field, $boucle->group)){
182 194
 			$boucle->group[] = $id_field;
183 195
 		}
@@ -201,9 +213,14 @@  discard block
 block discarded – undo
201 213
  */
202 214
 function nogroupby_if($depart, $arrivee, $col){
203 215
 	$pk = $arrivee['key']['PRIMARY KEY'];
204
-	if (!$pk) return false;
216
+	if (!$pk) {
217
+	    return false;
218
+	}
205 219
 	$id_primary = $depart['key']['PRIMARY KEY'];
206
-	if (is_array($col)) $col = implode(', *', $col); // cas id_objet, objet
220
+	if (is_array($col)) {
221
+	    $col = implode(', *', $col);
222
+	}
223
+	// cas id_objet, objet
207 224
 	return (preg_match("/^$id_primary, *$col$/", $pk) OR
208 225
 	        preg_match("/^$col, *$id_primary$/", $pk));
209 226
 }
@@ -227,20 +244,26 @@  discard block
 block discarded – undo
227 244
 	static $nojoin = array('idx', 'maj', 'date', 'statut');
228 245
 
229 246
 	// si cle primaire demandee, la privilegier
230
-	if ($primary && isset($desc['key']['PRIMARY KEY']))
231
-		return split_key($desc['key']['PRIMARY KEY']);
247
+	if ($primary && isset($desc['key']['PRIMARY KEY'])) {
248
+			return split_key($desc['key']['PRIMARY KEY']);
249
+	}
232 250
 
233 251
 	// les champs declares explicitement pour les jointures
234
-	if (isset($desc['join'])) return $desc['join'];
252
+	if (isset($desc['join'])) {
253
+	    return $desc['join'];
254
+	}
235 255
 	/*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join'];
236 256
 	elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/
237 257
 
238 258
 	// si pas de cle, c'est fichu
239
-	if (!isset($desc['key'])) return array();
259
+	if (!isset($desc['key'])) {
260
+	    return array();
261
+	}
240 262
 
241 263
 	// si cle primaire
242
-	if (isset($desc['key']['PRIMARY KEY']))
243
-		return split_key($desc['key']['PRIMARY KEY']);
264
+	if (isset($desc['key']['PRIMARY KEY'])) {
265
+			return split_key($desc['key']['PRIMARY KEY']);
266
+	}
244 267
 
245 268
 	// ici on se rabat sur les cles secondaires, 
246 269
 	// en eliminant celles qui sont pas pertinentes (idx, maj)
@@ -248,8 +271,12 @@  discard block
 block discarded – undo
248 271
 	// il faut declarer explicitement le champ 'join' de sa description
249 272
 
250 273
 	$join = array();
251
-	foreach ($desc['key'] as $v) $join = split_key($v, $join);
252
-	foreach ($join as $k) if (in_array($k, $nojoin)) unset($join[$k]);
274
+	foreach ($desc['key'] as $v) {
275
+	    $join = split_key($v, $join);
276
+	}
277
+	foreach ($join as $k) {
278
+	    if (in_array($k, $nojoin)) unset($join[$k]);
279
+	}
253 280
 	return $join;
254 281
 }
255 282
 
@@ -263,7 +290,9 @@  discard block
 block discarded – undo
263 290
  * @return array
264 291
  */
265 292
 function split_key($v, $join = array()){
266
-	foreach (preg_split('/,\s*/', $v) as $k) $join[$k] = $k;
293
+	foreach (preg_split('/,\s*/', $v) as $k) {
294
+	    $join[$k] = $k;
295
+	}
267 296
 	return $join;
268 297
 }
269 298
 
@@ -287,15 +316,18 @@  discard block
 block discarded – undo
287 316
  */
288 317
 function calculer_chaine_jointures(&$boucle, $depart, $arrivee, $vu = array(), $milieu_exclus = array(), $max_liens = 5){
289 318
 	static $trouver_table;
290
-	if (!$trouver_table)
291
-		$trouver_table = charger_fonction('trouver_table', 'base');
319
+	if (!$trouver_table) {
320
+			$trouver_table = charger_fonction('trouver_table', 'base');
321
+	}
292 322
 
293
-	if (is_string($milieu_exclus))
294
-		$milieu_exclus = array($milieu_exclus);
323
+	if (is_string($milieu_exclus)) {
324
+			$milieu_exclus = array($milieu_exclus);
325
+	}
295 326
 	// quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet
296 327
 	// faire une jointure sur objet tout seul n'a pas de sens
297
-	if (in_array('id_objet',$milieu_exclus) AND !in_array('objet',$milieu_exclus))
298
-		$milieu_exclus[] = 'objet';
328
+	if (in_array('id_objet',$milieu_exclus) AND !in_array('objet',$milieu_exclus)) {
329
+			$milieu_exclus[] = 'objet';
330
+	}
299 331
 
300 332
 	list($dnom, $ddesc) = $depart;
301 333
 	list($anom, $adesc) = $arrivee;
@@ -320,8 +352,9 @@  discard block
 block discarded – undo
320 352
 
321 353
 	$v = !$keys ? false : array_intersect(array_values($keys), $akeys);
322 354
 
323
-	if ($v)
324
-		return array(array($dnom, array($adesc['table'], $adesc), array_shift($v)));
355
+	if ($v) {
356
+			return array(array($dnom, array($adesc['table'], $adesc), array_shift($v)));
357
+	}
325 358
 
326 359
 	// regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx
327 360
 	if (count(array_intersect(array('id_objet', 'objet'), $keys))==2){
@@ -337,8 +370,7 @@  discard block
 block discarded – undo
337 370
 				return array(array($dnom, array($adesc['table'], $adesc), $v));
338 371
 			}
339 372
 		}
340
-	}
341
-	else {
373
+	} else {
342 374
 		// regarder si l'une des cles de depart peut se decomposer en 
343 375
 		// id_objet,objet a l'arrivee
344 376
 		// si oui on la prend
@@ -353,7 +385,9 @@  discard block
 block discarded – undo
353 385
 		}
354 386
 	}
355 387
 	// si l'on voulait une jointure direct, c'est rate !
356
-	if ($max_liens<=1) return array();
388
+	if ($max_liens<=1) {
389
+	    return array();
390
+	}
357 391
 
358 392
 	// sinon essayer de passer par une autre table
359 393
 	$new = $vu;
@@ -376,8 +410,7 @@  discard block
 block discarded – undo
376 410
 				if (is_string($milieu)){
377 411
 					$exclure_fin[] = $milieu;
378 412
 					$test_cles[] = $milieu;
379
-				}
380
-				else{
413
+				} else{
381 414
 					$exclure_fin = array_merge($exclure_fin, $milieu);
382 415
 					$test_cles = array_merge($test_cles, $milieu);
383 416
 				}
@@ -406,9 +439,9 @@  discard block
 block discarded – undo
406 439
 function trouver_cles_table($keys){
407 440
 	$res = array();
408 441
 	foreach ($keys as $v){
409
-		if (!strpos($v, ","))
410
-			$res[$v] = 1;
411
-		else {
442
+		if (!strpos($v, ",")) {
443
+					$res[$v] = 1;
444
+		} else {
412 445
 			foreach (preg_split("/\s*,\s*/", $v) as $k){
413 446
 				$res[$k] = 1;
414 447
 			}
@@ -428,15 +461,17 @@  discard block
 block discarded – undo
428 461
  */
429 462
 function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false){
430 463
 	static $trouver_table = '';
431
-	if (!$trouver_table)
432
-		$trouver_table = charger_fonction('trouver_table', 'base');
464
+	if (!$trouver_table) {
465
+			$trouver_table = charger_fonction('trouver_table', 'base');
466
+	}
433 467
 
434 468
 	// support de la recherche multi champ :
435 469
 	// si en seconde etape on a decompose le champ id_xx en id_objet,objet
436 470
 	// on reentre ici soit en cherchant une table les 2 champs id_objet,objet
437 471
 	// soit une table avec les 3 champs id_xx, id_objet, objet
438
-	if (!is_array($cle))
439
-		$cle = array($cle);
472
+	if (!is_array($cle)) {
473
+			$cle = array($cle);
474
+	}
440 475
 
441 476
 	foreach ($joints as $k => $join){
442 477
 		if ($join && $table = $trouver_table($join, $boucle->sql_serveur)){
@@ -445,8 +480,9 @@  discard block
 block discarded – undo
445 480
 			    AND (count(array_intersect($cle, array_keys($table['field'])))==count($cle))
446 481
 			        // si on sait ou on veut arriver, il faut que ca colle
447 482
 			        AND ($checkarrivee==false || $checkarrivee==$table['table'])
448
-			)
449
-				return array($table['table'], $table);
483
+			) {
484
+							return array($table['table'], $table);
485
+			}
450 486
 		}
451 487
 	}
452 488
 
@@ -475,8 +511,9 @@  discard block
 block discarded – undo
475 511
 				$cle[] = array_shift($decompose); // id_objet
476 512
 				$cle[] = array_shift($decompose); // objet
477 513
 				$cle[] = $d;
478
-				if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee))
479
-					return $ext;
514
+				if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) {
515
+									return $ext;
516
+				}
480 517
 			}
481 518
 		}
482 519
 	}
@@ -514,7 +551,9 @@  discard block
 block discarded – undo
514 551
 		$desc = $boucle->show;
515 552
 		$cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $cle, '', $cond);
516 553
 	}
517
-	if ($cle) return $cle;
554
+	if ($cle) {
555
+	    return $cle;
556
+	}
518 557
 	spip_log("trouver_jointure_champ: $champ inconnu");
519 558
 	return '';
520 559
 }
Please login to merge, or discard this patch.
ecrire/public/iterateur.php 1 patch
Braces   +48 added lines, -28 removed lines patch added patch discarded remove patch
@@ -11,7 +11,9 @@  discard block
 block discarded – undo
11 11
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
12 12
 \***************************************************************************/
13 13
 
14
-if (!defined('_ECRIRE_INC_VERSION')) return;
14
+if (!defined('_ECRIRE_INC_VERSION')) {
15
+    return;
16
+}
15 17
 
16 18
 /**
17 19
  * Fabrique d'iterateur
@@ -128,10 +130,12 @@  discard block
 block discarded – undo
128 130
 	 * (select SQL errone, non chargement des DATA, etc)
129 131
 	 */
130 132
 	public function err() {
131
-		if (method_exists($this->iter, 'err'))
132
-			return $this->iter->err();
133
-		if (property_exists($this->iter, 'err'))
134
-			return $this->iter->err;
133
+		if (method_exists($this->iter, 'err')) {
134
+					return $this->iter->err();
135
+		}
136
+		if (property_exists($this->iter, 'err')) {
137
+					return $this->iter->err;
138
+		}
135 139
 		return false;
136 140
 	}
137 141
 
@@ -222,10 +226,16 @@  discard block
 block discarded – undo
222 226
 			$menage = false;
223 227
 			foreach($where as $k => $v) { 
224 228
 				if (is_array($v)){
225
-					if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false;
226
-					elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false;
227
-					else $op = $v[0] ? $v[0] : $v;
228
-				} else $op = $v;
229
+					if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) {
230
+					    $op= false;
231
+					} elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) {
232
+					    $op= false;
233
+					} else {
234
+					    $op = $v[0] ? $v[0] : $v;
235
+					}
236
+				} else {
237
+				    $op = $v;
238
+				}
229 239
 				if ((!$op) OR ($op==1) OR ($op=='0=0')) {
230 240
 					unset($where[$k]);
231 241
 					$menage = true;
@@ -315,11 +325,13 @@  discard block
 block discarded – undo
315 325
 			$op = '';
316 326
 		}
317 327
 	
318
-		if ($op)
319
-			$filtre = $a.$op.str_replace('\"', '"', $valeur);
328
+		if ($op) {
329
+					$filtre = $a.$op.str_replace('\"', '"', $valeur);
330
+		}
320 331
 
321
-		if ($not)
322
-			$filtre = "!($filtre)";
332
+		if ($not) {
333
+					$filtre = "!($filtre)";
334
+		}
323 335
 			
324 336
 		if ($filtre) {
325 337
 			$this->filtre[] = $filtre;
@@ -413,8 +425,9 @@  discard block
 block discarded – undo
413 425
 	 * un par un tous les elements
414 426
 	 */
415 427
 	private function seek_loop($n) {
416
-		if ($this->pos > $n)
417
-			$this->rewind();
428
+		if ($this->pos > $n) {
429
+					$this->rewind();
430
+		}
418 431
 
419 432
 		while ($this->pos < $n AND $this->valid()) {
420 433
 			$this->next();
@@ -431,12 +444,15 @@  discard block
 block discarded – undo
431 444
 	 */
432 445
 	public function skip($saut, $max=null){
433 446
 		// pas de saut en arriere autorise pour cette fonction
434
-		if (($saut=intval($saut))<=0) return $this->pos;
447
+		if (($saut=intval($saut))<=0) {
448
+		    return $this->pos;
449
+		}
435 450
 		$seek = $this->pos + $saut;
436 451
 		// si le saut fait depasser le maxi, on libere la resource
437 452
 		// et on sort
438
-		if (is_null($max))
439
-			$max = $this->count();
453
+		if (is_null($max)) {
454
+					$max = $this->count();
455
+		}
440 456
 
441 457
 		if ($seek>=$max OR $seek>=$this->count()) {
442 458
 			// sortie plus rapide que de faire next() jusqu'a la fin !
@@ -465,15 +481,18 @@  discard block
 block discarded – undo
465 481
 			AND (
466 482
 				!$this->accept()
467 483
 				OR (isset($this->offset) AND $this->fetched++ < $this->offset)
468
-			))
469
-				$this->next();
484
+			)) {
485
+							$this->next();
486
+			}
470 487
 
471
-			if (!$this->valid())
472
-				return false;
488
+			if (!$this->valid()) {
489
+							return false;
490
+			}
473 491
 
474 492
 			if (isset($this->limit)
475
-			AND $this->fetched > $this->offset + $this->limit)
476
-				return false;
493
+			AND $this->fetched > $this->offset + $this->limit) {
494
+							return false;
495
+			}
477 496
 
478 497
 			$r = array();
479 498
 			foreach ($this->select as $nom) {
@@ -495,10 +514,11 @@  discard block
 block discarded – undo
495 514
 		# clone pas proprement (directoryiterator sous php 5.2.2)
496 515
 		# on se rabat sur la version __toString()
497 516
 		if (is_object($v = $this->current())) {
498
-			if (method_exists($v, '__toString'))
499
-				$v = $v->__toString();
500
-			else
501
-				$v = (array) $v;
517
+			if (method_exists($v, '__toString')) {
518
+							$v = $v->__toString();
519
+			} else {
520
+							$v = (array) $v;
521
+			}
502 522
 		}
503 523
 		return $v;
504 524
 	}
Please login to merge, or discard this patch.
ecrire/action/editer_objet.php 1 patch
Braces   +79 added lines, -57 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 /**
16 18
  * Point d'entree d'edition d'un objet
@@ -39,8 +41,9 @@  discard block
 block discarded – undo
39 41
 		$id = objet_inserer($objet, $id_parent);
40 42
 	}
41 43
 
42
-	if (!($id = intval($id))>0)
43
-		return array($id,_L('echec enregistrement en base'));
44
+	if (!($id = intval($id))>0) {
45
+			return array($id,_L('echec enregistrement en base'));
46
+	}
44 47
 
45 48
 	// Enregistre l'envoi dans la BD
46 49
 	$err = objet_modifier($objet, $id, $set);
@@ -59,8 +62,9 @@  discard block
 block discarded – undo
59 62
  */
60 63
 function objet_modifier($objet, $id, $set=null) {
61 64
 	if (include_spip('action/editer_'.$objet)
62
-	  AND function_exists($modifier = $objet."_modifier"))
63
-		return $modifier($id,$set);
65
+	  AND function_exists($modifier = $objet."_modifier")) {
66
+			return $modifier($id,$set);
67
+	}
64 68
 
65 69
 	$table_sql = table_objet_sql($objet);
66 70
 	$trouver_table = charger_fonction('trouver_table','base');
@@ -72,10 +76,11 @@  discard block
 block discarded – undo
72 76
 	include_spip('inc/modifier');
73 77
 
74 78
 	$champ_date = '';
75
-	if (isset($desc['date']) AND $desc['date'])
76
-		$champ_date = $desc['date'];
77
-	elseif (isset($desc['field']['date']))
78
-		$champ_date = 'date';
79
+	if (isset($desc['date']) AND $desc['date']) {
80
+			$champ_date = $desc['date'];
81
+	} elseif (isset($desc['field']['date'])) {
82
+			$champ_date = 'date';
83
+	}
79 84
 
80 85
 	$white = array_keys($desc['field']);
81 86
 	// on ne traite pas la cle primaire par defaut, notamment car
@@ -98,8 +103,7 @@  discard block
 block discarded – undo
98 103
 	if (objet_test_si_publie($objet,$id)){
99 104
 		$invalideur = "id='$objet/$id'";
100 105
 		$indexation = true;
101
-	}
102
-	else {
106
+	} else {
103 107
 		$invalideur = "";
104 108
 		$indexation = false;
105 109
 	}
@@ -113,8 +117,9 @@  discard block
 block discarded – undo
113 117
 			 // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
114 118
 			'date_modif' => (isset($desc['field']['date_modif'])?'date_modif':'')
115 119
 		),
116
-		$c))
117
-		return $err;
120
+		$c)) {
121
+			return $err;
122
+	}
118 123
 
119 124
 	// Modification de statut, changement de rubrique ?
120 125
 	// FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout
@@ -134,14 +139,16 @@  discard block
 block discarded – undo
134 139
  */
135 140
 function objet_inserer($objet, $id_parent=null, $set=null) {
136 141
 	if (include_spip('action/editer_'.$objet)
137
-	  AND function_exists($inserer = $objet."_inserer"))
138
-		return $inserer($id_parent);
142
+	  AND function_exists($inserer = $objet."_inserer")) {
143
+			return $inserer($id_parent);
144
+	}
139 145
 
140 146
 	$table_sql = table_objet_sql($objet);
141 147
 	$trouver_table = charger_fonction('trouver_table','base');
142 148
 	$desc = $trouver_table($table_sql);
143
-	if (!$desc OR !isset($desc['field']))
144
-		return 0;
149
+	if (!$desc OR !isset($desc['field'])) {
150
+			return 0;
151
+	}
145 152
 
146 153
 	$lang_rub = "";
147 154
 	$champs = array();
@@ -151,13 +158,14 @@  discard block
 block discarded – undo
151 158
 		if (!$id_rubrique = intval($id_parent)) {
152 159
 			$row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1");
153 160
 			$id_rubrique = $row['id_rubrique'];
161
+		} else {
162
+					$row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=".intval($id_rubrique));
154 163
 		}
155
-		else
156
-			$row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=".intval($id_rubrique));
157 164
 
158 165
 		$champs['id_rubrique'] = $id_rubrique;
159
-		if (isset($desc['field']['id_secteur']))
160
-			$champs['id_secteur'] = $row['id_secteur'];
166
+		if (isset($desc['field']['id_secteur'])) {
167
+					$champs['id_secteur'] = $row['id_secteur'];
168
+		}
161 169
 		$lang_rub = $row['lang'];
162 170
 	}
163 171
 
@@ -170,11 +178,11 @@  discard block
 block discarded – undo
170 178
 		if (in_array($GLOBALS['spip_lang'],
171 179
 		explode(',', $GLOBALS['meta']['langues_multilingue']))) {
172 180
 			$champs['lang'] = $GLOBALS['spip_lang'];
173
-			if (isset($desc['field']['langue_choisie']))
174
-				$champs['langue_choisie'] = 'oui';
181
+			if (isset($desc['field']['langue_choisie'])) {
182
+							$champs['langue_choisie'] = 'oui';
183
+			}
175 184
 		}
176
-	}
177
-	elseif (isset($desc['field']['lang']) AND isset($desc['field']['langue_choisie'])) {
185
+	} elseif (isset($desc['field']['lang']) AND isset($desc['field']['langue_choisie'])) {
178 186
 		$champs['lang'] = ($lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']);
179 187
 		$champs['langue_choisie'] = 'non';
180 188
 	}
@@ -183,17 +191,19 @@  discard block
 block discarded – undo
183 191
 		if (isset($desc['statut_textes_instituer'])){
184 192
 			$cles_statut = array_keys($desc['statut_textes_instituer']); 
185 193
 			$champs['statut'] = reset($cles_statut);
194
+		} else {
195
+					$champs['statut'] = 'prepa';
186 196
 		}
187
-		else
188
-			$champs['statut'] = 'prepa';
189 197
 	}
190 198
 
191 199
 
192
-	if ((isset($desc['date']) AND $d=$desc['date']) OR isset($desc['field'][$d='date']))
193
-		$champs[$d] = date('Y-m-d H:i:s');
200
+	if ((isset($desc['date']) AND $d=$desc['date']) OR isset($desc['field'][$d='date'])) {
201
+			$champs[$d] = date('Y-m-d H:i:s');
202
+	}
194 203
 
195
-	if ($set)
196
-		$champs = array_merge($champs, $set);
204
+	if ($set) {
205
+			$champs = array_merge($champs, $set);
206
+	}
197 207
 
198 208
 	// Envoyer aux plugins
199 209
 	$champs = pipeline('pre_insertion',
@@ -251,14 +261,16 @@  discard block
 block discarded – undo
251 261
  */
252 262
 function objet_instituer($objet, $id, $c, $calcul_rub=true) {
253 263
 	if (include_spip('action/editer_'.$objet)
254
-	  AND function_exists($instituer = $objet."_instituer"))
255
-		return $instituer($id,$c,$calcul_rub);
264
+	  AND function_exists($instituer = $objet."_instituer")) {
265
+			return $instituer($id,$c,$calcul_rub);
266
+	}
256 267
 
257 268
 	$table_sql = table_objet_sql($objet);
258 269
 	$trouver_table = charger_fonction('trouver_table','base');
259 270
 	$desc = $trouver_table($table_sql);
260
-	if (!$desc OR !isset($desc['field']))
261
-		return _L("Impossible d'instituer $objet : non connu en base");
271
+	if (!$desc OR !isset($desc['field'])) {
272
+			return _L("Impossible d'instituer $objet : non connu en base");
273
+	}
262 274
 
263 275
 	include_spip('inc/autoriser');
264 276
 	include_spip('inc/rubriques');
@@ -268,10 +280,11 @@  discard block
 block discarded – undo
268 280
 	$sel[] = (isset($desc['field']['statut'])?"statut":"'' as statut");
269 281
 
270 282
 	$champ_date = '';
271
-	if (isset($desc['date']) AND $desc['date'])
272
-		$champ_date = $desc['date'];
273
-	elseif (isset($desc['field']['date']))
274
-		$champ_date = 'date';
283
+	if (isset($desc['date']) AND $desc['date']) {
284
+			$champ_date = $desc['date'];
285
+	} elseif (isset($desc['field']['date'])) {
286
+			$champ_date = 'date';
287
+	}
275 288
 
276 289
 	$sel[] = ($champ_date ? "$champ_date as date" : "'' as date");
277 290
 	$sel[] = (isset($desc['field']['id_rubrique'])?'id_rubrique':"0 as id_rubrique");
@@ -292,12 +305,13 @@  discard block
 block discarded – undo
292 305
 				autoriser('publierdans', 'rubrique', $id_rubrique)
293 306
 			:
294 307
 				autoriser('instituer', $objet, $id, null, array('statut'=>$s))
295
-			)
296
-			$statut = $champs['statut'] = $s;
297
-		else if ($s!='publie' AND autoriser('modifier', $objet, $id))
298
-			$statut = $champs['statut'] = $s;
299
-		else
300
-			spip_log("editer_objet $id refus " . join(' ', $c));
308
+			) {
309
+					$statut = $champs['statut'] = $s;
310
+		} else if ($s!='publie' AND autoriser('modifier', $objet, $id)) {
311
+					$statut = $champs['statut'] = $s;
312
+		} else {
313
+					spip_log("editer_objet $id refus " . join(' ', $c));
314
+		}
301 315
 
302 316
 		// En cas de publication, fixer la date a "maintenant"
303 317
 		// sauf si $c commande autre chose
@@ -308,10 +322,11 @@  discard block
 block discarded – undo
308 322
 			 OR ($champs['statut'] == 'prop' AND !in_array($statut_ancien, array('publie', 'prop')))
309 323
 			 OR $d
310 324
 			) {
311
-				if ($d OR strtotime($d=$date)>time())
312
-					$champs[$champ_date] = $date = $d;
313
-				else
314
-					$champs[$champ_date] = $date = date('Y-m-d H:i:s');
325
+				if ($d OR strtotime($d=$date)>time()) {
326
+									$champs[$champ_date] = $date = $d;
327
+				} else {
328
+									$champs[$champ_date] = $date = date('Y-m-d H:i:s');
329
+				}
315 330
 			}
316 331
 		}
317 332
 	}
@@ -328,8 +343,9 @@  discard block
 block discarded – undo
328 343
 		// et que le demandeur n'est pas admin de la rubrique
329 344
 		// repasser l'objet en statut 'propose'.
330 345
 		if ($statut == 'publie'
331
-		AND !autoriser('publierdans', 'rubrique', $id_rubrique))
332
-			$champs['statut'] = 'prop';
346
+		AND !autoriser('publierdans', 'rubrique', $id_rubrique)) {
347
+					$champs['statut'] = 'prop';
348
+		}
333 349
 	}
334 350
 
335 351
 
@@ -348,7 +364,9 @@  discard block
 block discarded – undo
348 364
 		)
349 365
 	);
350 366
 
351
-	if (!count($champs)) return '';
367
+	if (!count($champs)) {
368
+	    return '';
369
+	}
352 370
 
353 371
 	// Envoyer les modifs.
354 372
 	objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
@@ -414,16 +432,20 @@  discard block
 block discarded – undo
414 432
 		$row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=".sql_quote($champs['id_rubrique']));
415 433
 		$langue = $row_rub['lang'];
416 434
 
417
-		if (isset($desc['field']['id_secteur']))
418
-			$champs['id_secteur'] = $row_rub['id_secteur'];
435
+		if (isset($desc['field']['id_secteur'])) {
436
+					$champs['id_secteur'] = $row_rub['id_secteur'];
437
+		}
419 438
 
420
-		if (isset($desc['field']['lang']) AND isset($desc['field']['langue_choisie']))
421
-			if (sql_fetsel('1', $table_sql, id_table_objet($objet)."=".intval($id)." AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) {
439
+		if (isset($desc['field']['lang']) AND isset($desc['field']['langue_choisie'])) {
440
+					if (sql_fetsel('1', $table_sql, id_table_objet($objet)."=".intval($id)." AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) {
422 441
 				$champs['lang'] = $langue;
442
+		}
423 443
 			}
424 444
 	}
425 445
 
426
-	if (!$champs) return;
446
+	if (!$champs) {
447
+	    return;
448
+	}
427 449
 	sql_updateq($table_sql, $champs, id_table_objet($objet).'='.intval($id));
428 450
 
429 451
 	// Changer le statut des rubriques concernees
Please login to merge, or discard this patch.
ecrire/action/inscrire_auteur.php 1 patch
Braces   +66 added lines, -43 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 
16 18
 /**
@@ -30,23 +32,28 @@  discard block
 block discarded – undo
30 32
  * @return array|string
31 33
  */
32 34
 function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = array()){
33
-	if (!is_array($options))
34
-		$options = array('id'=>$options);
35
+	if (!is_array($options)) {
36
+			$options = array('id'=>$options);
37
+	}
35 38
 
36
-	if (function_exists('test_inscription'))
37
-		$f = 'test_inscription';
38
-	else 	$f = 'test_inscription_dist';
39
+	if (function_exists('test_inscription')) {
40
+			$f = 'test_inscription';
41
+	} else {
42
+	    $f = 'test_inscription_dist';
43
+	}
39 44
 	$desc = $f($statut, $mail_complet, $nom, $options);
40 45
 
41 46
 	// erreur ?
42
-	if (!is_array($desc))
43
-		return _T($desc);
47
+	if (!is_array($desc)) {
48
+			return _T($desc);
49
+	}
44 50
 
45 51
 	include_spip('base/abstract_sql');
46 52
 	$res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email']));
47 53
 	// erreur ?
48
-	if (!$res)
49
-		return _T('titre_probleme_technique');
54
+	if (!$res) {
55
+			return _T('titre_probleme_technique');
56
+	}
50 57
 
51 58
 	$row = sql_fetch($res);
52 59
 	sql_free($res);
@@ -54,17 +61,18 @@  discard block
 block discarded – undo
54 61
 		if (isset($options['force_nouveau']) AND $options['force_nouveau']==true){
55 62
 			$desc['id_auteur'] = $row['id_auteur'];
56 63
 			$desc = inscription_nouveau($desc);
64
+		} else {
65
+					$desc = $row;
57 66
 		}
58
-		else
59
-			$desc = $row;
60
-	}
61
-	else
62
-		// s'il n'existe pas deja, creer les identifiants
67
+	} else {
68
+			// s'il n'existe pas deja, creer les identifiants
63 69
 		$desc = inscription_nouveau($desc);
70
+	}
64 71
 
65 72
 	// erreur ?
66
-	if (!is_array($desc))
67
-		return $desc;
73
+	if (!is_array($desc)) {
74
+			return $desc;
75
+	}
68 76
 
69 77
 
70 78
 	// generer le mot de passe (ou le refaire si compte inutilise)
@@ -108,16 +116,20 @@  discard block
 block discarded – undo
108 116
  */
109 117
 function test_inscription_dist($statut, $mail, $nom, $options) {
110 118
 	include_spip('inc/filtres');
111
-	if (!$r = email_valide($mail)) return 'info_email_invalide';
119
+	if (!$r = email_valide($mail)) {
120
+	    return 'info_email_invalide';
121
+	}
112 122
 	$nom = trim(corriger_caracteres($nom));
113 123
 	$res = array('email' => $r, 'nom' => $nom, 'prefs' => $statut);
114 124
 	if (isset($options['login'])) {
115 125
 		$login = trim(corriger_caracteres($options['login']));
116
-		if((strlen ($login) >= _LOGIN_TROP_COURT) AND (strlen($nom) <= 64))
117
-			$res['login'] = $login;
126
+		if((strlen ($login) >= _LOGIN_TROP_COURT) AND (strlen($nom) <= 64)) {
127
+					$res['login'] = $login;
128
+		}
129
+	}
130
+	if(!isset($res['login']) AND ((strlen ($nom) < _LOGIN_TROP_COURT) OR (strlen($nom) > 64))) {
131
+			return 'ecrire:info_login_trop_court';
118 132
 	}
119
-	if(!isset($res['login']) AND ((strlen ($nom) < _LOGIN_TROP_COURT) OR (strlen($nom) > 64)))
120
-		return 'ecrire:info_login_trop_court';
121 133
 	return $res;
122 134
 }
123 135
 
@@ -134,17 +146,21 @@  discard block
 block discarded – undo
134 146
  */
135 147
 function inscription_nouveau($desc)
136 148
 {
137
-	if (!isset($desc['login']) OR !strlen($desc['login']))
138
-		$desc['login'] = test_login($desc['nom'], $desc['email']);
149
+	if (!isset($desc['login']) OR !strlen($desc['login'])) {
150
+			$desc['login'] = test_login($desc['nom'], $desc['email']);
151
+	}
139 152
 
140 153
 	$desc['statut'] = 'nouveau';
141 154
 	include_spip('action/editer_auteur');
142
-	if (isset($desc['id_auteur']))
143
-		$id_auteur = $desc['id_auteur'];
144
-	else
145
-		$id_auteur = auteur_inserer();
155
+	if (isset($desc['id_auteur'])) {
156
+			$id_auteur = $desc['id_auteur'];
157
+	} else {
158
+			$id_auteur = auteur_inserer();
159
+	}
146 160
 
147
-	if (!$id_auteur) return _T('titre_probleme_technique');
161
+	if (!$id_auteur) {
162
+	    return _T('titre_probleme_technique');
163
+	}
148 164
 
149 165
 	include_spip('inc/autoriser');
150 166
 	// lever l'autorisation pour pouvoir modifier le statut
@@ -175,14 +191,16 @@  discard block
 block discarded – undo
175 191
 		$mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail)));
176 192
 		$login_base = preg_replace("/[^\w\d]/", "_", $mail);
177 193
 	}
178
-	if (strlen($login_base) < 3)
179
-		$login_base = 'user';
194
+	if (strlen($login_base) < 3) {
195
+			$login_base = 'user';
196
+	}
180 197
 
181 198
 	$login = $login_base;
182 199
 
183 200
 	for ($i = 1; ; $i++) {
184
-		if (!sql_countsel('spip_auteurs', "login='$login'"))
185
-			return $login;
201
+		if (!sql_countsel('spip_auteurs', "login='$login'")) {
202
+					return $login;
203
+		}
186 204
 		$login = $login_base.$i;
187 205
 	}
188 206
 	return $login;
@@ -249,12 +267,13 @@  discard block
 block discarded – undo
249 267
  */
250 268
 function tester_statut_inscription($statut_tmp, $id){
251 269
 	include_spip('inc/autoriser');
252
-	if ($statut_tmp)
253
-		return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : '';
254
-	elseif (
270
+	if ($statut_tmp) {
271
+			return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : '';
272
+	} elseif (
255 273
 		   autoriser('inscrireauteur', $statut_tmp = "1comite", $id)
256
-	  OR autoriser('inscrireauteur', $statut_tmp = "6forum", $id))
257
-		return $statut_tmp;
274
+	  OR autoriser('inscrireauteur', $statut_tmp = "6forum", $id)) {
275
+			return $statut_tmp;
276
+	}
258 277
 
259 278
 	return '';
260 279
 }
@@ -273,11 +292,14 @@  discard block
 block discarded – undo
273 292
  */
274 293
 function confirmer_statut_inscription($auteur){
275 294
 	// securite
276
-	if ($auteur['statut'] != 'nouveau') return $auteur;
295
+	if ($auteur['statut'] != 'nouveau') {
296
+	    return $auteur;
297
+	}
277 298
 
278 299
 	include_spip('inc/autoriser');
279
-	if (!autoriser('inscrireauteur', $auteur['prefs']))
280
-		return $auteur;
300
+	if (!autoriser('inscrireauteur', $auteur['prefs'])) {
301
+			return $auteur;
302
+	}
281 303
 	$s = $auteur['prefs'];
282 304
 
283 305
 	include_spip('inc/autoriser');
@@ -320,8 +342,9 @@  discard block
 block discarded – undo
320 342
  */
321 343
 function auteur_verifier_jeton($jeton){
322 344
 	// refuser un jeton corrompu
323
-	if (preg_match(',[^0-9a-f.],i',$jeton))
324
-		return false;
345
+	if (preg_match(',[^0-9a-f.],i',$jeton)) {
346
+			return false;
347
+	}
325 348
 
326 349
 	$desc = sql_fetsel('*','spip_auteurs',"cookie_oubli=".sql_quote($jeton, $serveur, 'string'));
327 350
 	return $desc;
Please login to merge, or discard this patch.
ecrire/action/redirect.php 1 patch
Braces   +18 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,28 +10,36 @@
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 // Un script utile pour recalculer une URL symbolique des son changement
16 18
 
17 19
 function action_redirect_dist()
18 20
 {
19 21
 	$type = _request('type');
20
-	if (!preg_match('/^\w+$/', $type)) return;
22
+	if (!preg_match('/^\w+$/', $type)) {
23
+	    return;
24
+	}
21 25
 	if ($m = _request('var_mode')) {
22 26
 		// forcer la mise a jour de l'url de cet objet !
23
-		if (!defined('_VAR_URLS')) define('_VAR_URLS',true);
27
+		if (!defined('_VAR_URLS')) {
28
+		    define('_VAR_URLS',true);
29
+		}
24 30
 		$m = 'var_mode='.urlencode($m);
25 31
 	}
26 32
 	$h = generer_url_entite_absolue(intval(_request('id')), $type, $m, '', true);
27 33
 	$status = '302';
28
-	if (_request('status') AND _request('status')=='301')
29
-		$status = '301';
34
+	if (_request('status') AND _request('status')=='301') {
35
+			$status = '301';
36
+	}
30 37
 
31
-	if ($h)
32
-		redirige_par_entete(str_replace('&amp;', '&', $h),'',$status);
33
-	else
34
-		redirige_par_entete('/','',$status);
35
-}
38
+	if ($h) {
39
+			redirige_par_entete(str_replace('&amp;', '&', $h),'',$status);
40
+	} else {
41
+			redirige_par_entete('/','',$status);
42
+	}
43
+	}
36 44
 
37 45
 ?>
Please login to merge, or discard this patch.
ecrire/action/debloquer_edition.php 1 patch
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 // http://doc.spip.org/@action_instituer_collaboration_dist
16 18
 function action_debloquer_edition_dist() {
@@ -22,8 +24,7 @@  discard block
 block discarded – undo
22 24
 		include_spip('inc/drapeau_edition');
23 25
 		if ($arg == 'tous') {
24 26
 			debloquer_tous($GLOBALS['visiteur_session']['id_auteur']);
25
-		}
26
-		else {
27
+		} else {
27 28
 			$arg = explode("-",$arg);
28 29
 			list($objet,$id_objet) = $arg;
29 30
 			debloquer_edition($GLOBALS['visiteur_session']['id_auteur'], $id_objet, $objet);
Please login to merge, or discard this patch.
ecrire/action/supprimer_lien.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 function action_supprimer_lien_dist($arg=null){
16 18
 	if (is_null($arg)){
Please login to merge, or discard this patch.