Completed
Push — spip-3.0 ( ab100a...484b62 )
by cam
06:49
created
ecrire/xml/valider.php 1 patch
Braces   +59 added lines, -36 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
 // Validateur XML en deux passes, fonde sur SAX pour la premiere
16 18
 // Faudrait faire deux classes car pour la premiere passe
@@ -69,16 +71,18 @@  discard block
 block discarded – undo
69 71
 	    }
70 72
 	}
71 73
 	// Init de la suite des balises a memoriser si regle difficile
72
-	if ($this->dtc->regles[$name][0]=='/')
73
-	    $this->fratrie[$depth]='';
74
+	if ($this->dtc->regles[$name][0]=='/') {
75
+		    $this->fratrie[$depth]='';
76
+	}
74 77
 	if (isset($this->dtc->attributs[$name])) {
75 78
 		  foreach ($this->dtc->attributs[$name] as $n => $v)
76
-		    { if (($v[1] == '#REQUIRED') AND (!isset($attrs[$n])))
77
-			coordonnees_erreur($this, " <b>$n</b>"
79
+		    { if (($v[1] == '#REQUIRED') AND (!isset($attrs[$n]))) {
80
+		    			coordonnees_erreur($this, " <b>$n</b>"
78 81
 			  . '&nbsp;:&nbsp;'
79 82
 			  . _T('zxml_obligatoire_attribut')
80 83
 			  . " <b>$name</b>");
81 84
 		    }
85
+		    }
82 86
 	}
83 87
 }
84 88
 
@@ -86,18 +90,20 @@  discard block
 block discarded – undo
86 90
 function validerAttribut($phraseur, $name, $val, $bal)
87 91
 {
88 92
 	// Si la balise est inconnue, eviter d'insister
89
-	if (!isset($this->dtc->attributs[$bal]))
90
-		return ;
93
+	if (!isset($this->dtc->attributs[$bal])) {
94
+			return ;
95
+	}
91 96
 		
92 97
 	$a = $this->dtc->attributs[$bal];
93 98
 	if (!isset($a[$name])) {
94 99
 		$bons = join(', ',array_keys($a));
95
-		if ($bons)
96
-		  $bons = " title=' " .
100
+		if ($bons) {
101
+				  $bons = " title=' " .
97 102
 		    _T('zxml_connus_attributs') .
98 103
 		    '&nbsp;: ' .
99 104
 		    $bons .
100 105
 		    "'";
106
+		}
101 107
 		$bons .= " style='font-weight: bold'";
102 108
 		coordonnees_erreur($this, " <b>$name</b> "
103 109
 		. _T('zxml_inconnu_attribut').' '._T('zxml_de')
@@ -106,11 +112,12 @@  discard block
 block discarded – undo
106 112
 		. ")");
107 113
 	} else{
108 114
 		$type =  $a[$name][0];
109
-		if (!preg_match('/^\w+$/', $type))
110
-			$this->valider_motif($phraseur, $name, $val, $bal, $type);
111
-		else if (method_exists($this, $f = 'validerAttribut_' . $type))
112
-			$this->$f($phraseur, $name, $val, $bal);
113
-#		else spip_log("$type type d'attribut inconnu");
115
+		if (!preg_match('/^\w+$/', $type)) {
116
+					$this->valider_motif($phraseur, $name, $val, $bal, $type);
117
+		} else if (method_exists($this, $f = 'validerAttribut_' . $type)) {
118
+					$this->$f($phraseur, $name, $val, $bal);
119
+		}
120
+		#		else spip_log("$type type d'attribut inconnu");
114 121
 	}
115 122
 }
116 123
 
@@ -172,9 +179,10 @@  discard block
 block discarded – undo
172 179
 // http://doc.spip.org/@valider_idref
173 180
 function valider_idref($nom, $ligne, $col)
174 181
 {
175
-	if (!isset($this->ids[$nom]))
176
-		$this->err[]= array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col);
177
-}
182
+	if (!isset($this->ids[$nom])) {
183
+			$this->err[]= array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col);
184
+	}
185
+	}
178 186
 
179 187
 // http://doc.spip.org/@valider_passe2
180 188
 function valider_passe2()
@@ -186,8 +194,9 @@  discard block
 block discarded – undo
186 194
 		}
187 195
 		foreach ($this->idrefss as $idref) {
188 196
 			list($noms, $ligne, $col) = $idref;
189
-			foreach(preg_split('/\s+/', $noms) as $nom)
190
-				$this->valider_idref($nom, $ligne, $col);
197
+			foreach(preg_split('/\s+/', $noms) as $nom) {
198
+							$this->valider_idref($nom, $ligne, $col);
199
+			}
191 200
 		}
192 201
 	}
193 202
 }
@@ -195,10 +204,13 @@  discard block
 block discarded – undo
195 204
 // http://doc.spip.org/@debutElement
196 205
 function debutElement($phraseur, $name, $attrs)
197 206
 { 
198
-	if ($this->dtc->elements)
199
-		$this->validerElement($phraseur, $name, $attrs);
207
+	if ($this->dtc->elements) {
208
+			$this->validerElement($phraseur, $name, $attrs);
209
+	}
200 210
 
201
-	if ($f = $this->process['debut']) $f($this, $name, $attrs);
211
+	if ($f = $this->process['debut']) {
212
+	    $f($this, $name, $attrs);
213
+	}
202 214
 	$depth = $this->depth;
203 215
 	$this->debuts[$depth] =  strlen($this->res);
204 216
 	foreach ($attrs as $k => $v) {
@@ -220,9 +232,10 @@  discard block
 block discarded – undo
220 232
 	$vide = ($regle  == 'EMPTY');
221 233
 	// controler que les balises devant etre vides le sont 
222 234
 	if ($vide) {
223
-		if ($n <> ($k + $c))
224
-			coordonnees_erreur($this, " <p><b>$name</b> "
235
+		if ($n <> ($k + $c)) {
236
+					coordonnees_erreur($this, " <p><b>$name</b> "
225 237
 					   . _T('zxml_nonvide_balise'));
238
+		}
226 239
 	// pour les regles PCDATA ou iteration de disjonction, tout est fait
227 240
 	} elseif ($regle AND ($regle != '*')) {
228 241
 		if ($regle == '+') {
@@ -244,8 +257,10 @@  discard block
 block discarded – undo
244 257
 		}
245 258
 
246 259
 	}
247
-	if ($f = $this->process['fin']) $f($this, $name, $vide);
248
-}
260
+	if ($f = $this->process['fin']) {
261
+	    $f($this, $name, $vide);
262
+	}
263
+	}
249 264
 
250 265
 // http://doc.spip.org/@textElement
251 266
 function textElement($phraseur, $data)
@@ -260,13 +275,17 @@  discard block
 block discarded – undo
260 275
 			);
261 276
 		}
262 277
 	}
263
-	if ($f = $this->process['text']) $f($this, $data);
264
-}
278
+	if ($f = $this->process['text']) {
279
+	    $f($this, $data);
280
+	}
281
+	}
265 282
 
266 283
 function piElement($phraseur, $target, $data)
267 284
 {
268
-	if ($f = $this->process['pi']) $f($this, $target, $data);
269
-}
285
+	if ($f = $this->process['pi']) {
286
+	    $f($this, $target, $data);
287
+	}
288
+	}
270 289
 
271 290
 // Denonciation des entitees XML inconnues
272 291
 // Pour contourner le bug de conception de SAX qui ne signale pas si elles
@@ -279,14 +298,16 @@  discard block
 block discarded – undo
279 298
 function defaultElement($phraseur, $data)
280 299
 {
281 300
 	if (!preg_match('/^<!--/', $data)
282
-	AND (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)))
283
-		foreach ($r as $m) {
301
+	AND (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER))) {
302
+			foreach ($r as $m) {
284 303
 			list($t,$e) = $m;
285
-			if (!isset($this->dtc->entites[$e]))
286
-				coordonnees_erreur($this, " <b>$e</b> "
304
+	}
305
+			if (!isset($this->dtc->entites[$e])) {
306
+							coordonnees_erreur($this, " <b>$e</b> "
287 307
 				  . _T('zxml_inconnu_entite')
288 308
 				  . ' '
289 309
 				  );
310
+			}
290 311
 		}
291 312
 	if (isset($this->process['default']) AND ($f = $this->process['default'])) {
292 313
 		$f($this, $data);
@@ -307,8 +328,10 @@  discard block
 block discarded – undo
307 328
 
308 329
 // Init
309 330
 function ValidateurXML($process=array()) {
310
-	if (is_array($process)) $this->process = $process;
311
-}
331
+	if (is_array($process)) {
332
+	    $this->process = $process;
333
+	}
334
+	}
312 335
 
313 336
  var $ids = array();
314 337
  var $idrefs = array();
Please login to merge, or discard this patch.
ecrire/xml/interfaces.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
 define('_REGEXP_DOCTYPE',
16 18
 	'/^((?:<\001?[?][^>]*>\s*)*(?:<!--.*?-->\s*)*)*<!DOCTYPE\s+(\w+)\s+(\w+)\s*([^>]*)>\s*/s');
Please login to merge, or discard this patch.
ecrire/base/upgrade.php 1 patch
Braces   +59 added lines, -36 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
  * Programme de mise a jour des tables SQL lors d'un chgt de version.
@@ -30,7 +32,10 @@  discard block
 block discarded – undo
30 32
  */
31 33
 function base_upgrade_dist($titre='', $reprise='')
32 34
 {
33
-	if (!$titre) return; // anti-testeur automatique
35
+	if (!$titre) {
36
+	    return;
37
+	}
38
+	// anti-testeur automatique
34 39
 	if ($GLOBALS['spip_version_base']!=$GLOBALS['meta']['version_installee']) {
35 40
 		if (!is_numeric(_request('reinstall'))) {
36 41
 			include_spip('base/create');
@@ -93,7 +98,9 @@  discard block
 block discarded – undo
93 98
 			    'impt' => 'non'));
94 99
 		return false;
95 100
 	}
96
-	if (!upgrade_test()) return true;
101
+	if (!upgrade_test()) {
102
+	    return true;
103
+	}
97 104
 	
98 105
 	$cible = ($version_cible ? $version_cible : $spip_version_base);
99 106
 
@@ -105,27 +112,31 @@  discard block
 block discarded – undo
105 112
 			if ($f) {
106 113
 				spip_log( "$f repercute les modifications de la version " . ($n/10),"maj."._LOG_INFO_IMPORTANTE);
107 114
 				$f($version_installee, $spip_version_base);
108
-			} else spip_log( "pas de fonction pour la maj $n $nom","maj."._LOG_INFO_IMPORTANTE);
115
+			} else {
116
+			    spip_log( "pas de fonction pour la maj $n $nom","maj."._LOG_INFO_IMPORTANTE);
117
+			}
109 118
 			$n++;
110 119
 		}
111 120
 		include_spip('maj/v019_pre193');
112 121
 		v019_pre193($version_installee, $version_cible);
113 122
 	}
114 123
 	if ($version_installee < 2000) {
115
-		if ($version_installee < 2)
116
-			$version_installee = $version_installee*1000;
124
+		if ($version_installee < 2) {
125
+					$version_installee = $version_installee*1000;
126
+		}
117 127
 		include_spip('maj/v019');
118 128
 	}
119
-	if ($cible < 2)
120
-		$cible = $cible*1000;
129
+	if ($cible < 2) {
130
+			$cible = $cible*1000;
131
+	}
121 132
 
122 133
 	include_spip('maj/svn10000');
123 134
 	ksort($GLOBALS['maj']);
124 135
 	$res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee','meta', $redirect, true);
125 136
 	if ($res) {
126
-		if (!is_array($res))
127
-			spip_log("Pb d'acces SQL a la mise a jour","maj."._LOG_INFO_ERREUR);
128
-		else {
137
+		if (!is_array($res)) {
138
+					spip_log("Pb d'acces SQL a la mise a jour","maj."._LOG_INFO_ERREUR);
139
+		} else {
129 140
 			echo _T('avis_operation_echec') . ' ' . join(' ', $res);
130 141
 			echo install_fin_html();
131 142
 		}
@@ -166,8 +177,9 @@  discard block
 block discarded – undo
166 177
  */
167 178
 function maj_plugin($nom_meta_base_version, $version_cible, $maj, $table_meta='meta'){
168 179
 
169
-	if ($table_meta!=='meta')
170
-		lire_metas($table_meta);
180
+	if ($table_meta!=='meta') {
181
+			lire_metas($table_meta);
182
+	}
171 183
 	if ( (!isset($GLOBALS[$table_meta][$nom_meta_base_version]) )
172 184
 			|| (!spip_version_compare($current_version = $GLOBALS[$table_meta][$nom_meta_base_version],$version_cible,'='))){
173 185
 
@@ -201,9 +213,9 @@  discard block
 block discarded – undo
201 213
 		
202 214
 		$res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect);
203 215
 		if ($res) {
204
-			if (!is_array($res))
205
-				spip_log("Pb d'acces SQL a la mise a jour","maj."._LOG_INFO_ERREUR);
206
-			else {
216
+			if (!is_array($res)) {
217
+							spip_log("Pb d'acces SQL a la mise a jour","maj."._LOG_INFO_ERREUR);
218
+			} else {
207 219
 				echo "<p>"._T('avis_operation_echec') . ' ' . join(' ', $res)."</p>";
208 220
 			}
209 221
 		}
@@ -245,7 +257,9 @@  discard block
 block discarded – undo
245 257
  */
246 258
 function maj_debut_page($installee,$meta,$table){
247 259
 	static $done = false;
248
-	if ($done) return;
260
+	if ($done) {
261
+	    return;
262
+	}
249 263
 	include_spip('inc/minipres');
250 264
 	@ini_set("zlib.output_compression","0"); // pour permettre l'affichage au fur et a mesure
251 265
 	$timeout = _UPGRADE_TIME_OUT*2;
@@ -315,17 +329,22 @@  discard block
 block discarded – undo
315 329
 		if ($v=='init' OR
316 330
 			(spip_version_compare($v,$installee,'>')
317 331
 			AND spip_version_compare($v,$cible,'<='))) {
318
-			if ($debut_page)
319
-				maj_debut_page($v,$meta,$table);
332
+			if ($debut_page) {
333
+							maj_debut_page($v,$meta,$table);
334
+			}
320 335
 			echo "MAJ $v";
321 336
 			$etape = serie_alter($v, $maj[$v], $meta, $table, $redirect);
322 337
 			$trouver_table(''); // vider le cache des descriptions de table
323 338
 			# echec sur une etape en cours ?
324 339
 			# on sort
325
-			if ($etape) return array($v, $etape);
340
+			if ($etape) {
341
+			    return array($v, $etape);
342
+			}
326 343
 			$n = time() - $time;
327 344
 			spip_log( "$table $meta: $v en $n secondes",'maj.'._LOG_INFO_IMPORTANTE);
328
-			if ($meta) ecrire_meta($meta, $installee=$v,'oui', $table);
345
+			if ($meta) {
346
+			    ecrire_meta($meta, $installee=$v,'oui', $table);
347
+			}
329 348
 			echo "<br />";
330 349
 		}
331 350
 		if (time() >= _TIME_OUT) {
@@ -335,7 +354,9 @@  discard block
 block discarded – undo
335 354
 	$trouver_table(''); // vider le cache des descriptions de table
336 355
 	// indispensable pour les chgt de versions qui n'ecrivent pas en base
337 356
 	// tant pis pour la redondance eventuelle avec ci-dessus
338
-	if ($meta) ecrire_meta($meta, $cible,'oui',$table);
357
+	if ($meta) {
358
+	    ecrire_meta($meta, $cible,'oui',$table);
359
+	}
339 360
 	spip_log( "MAJ terminee. $meta: $installee",'maj.'._LOG_INFO_IMPORTANTE);
340 361
 	return array();
341 362
 }
@@ -373,8 +394,9 @@  discard block
 block discarded – undo
373 394
 				// mais pour les fonctions complexes,
374 395
 				// il faut les rejouer jusqu'a achevement.
375 396
 				// C'est a elle d'assurer qu'elles progressent a chaque rappel
376
-				if (strncmp($f,"sql_",4)==0)
377
-					ecrire_meta($meta2, $i+1, 'non', $table);
397
+				if (strncmp($f,"sql_",4)==0) {
398
+									ecrire_meta($meta2, $i+1, 'non', $table);
399
+				}
378 400
 				echo " <span title='$i'>.</span>";
379 401
 				call_user_func_array($f, $r);
380 402
 				// si temps imparti depasse, on relance sans ecrire en meta
@@ -384,12 +406,12 @@  discard block
 block discarded – undo
384 406
 				}
385 407
 				ecrire_meta($meta2, $i+1, 'non', $table);
386 408
 				spip_log( "$meta2: ok", 'maj.'._LOG_INFO_IMPORTANTE);
387
-			}
388
-			else {
389
-				if (!is_array($r))
390
-					spip_log("maj $i format incorrect","maj."._LOG_ERREUR);
391
-				else
392
-					spip_log("maj $i fonction $f non definie","maj."._LOG_ERREUR);
409
+			} else {
410
+				if (!is_array($r)) {
411
+									spip_log("maj $i format incorrect","maj."._LOG_ERREUR);
412
+				} else {
413
+									spip_log("maj $i fonction $f non definie","maj."._LOG_ERREUR);
414
+				}
393 415
 				// en cas d'erreur serieuse, on s'arrete
394 416
 				// mais on permet de passer par dessus en rechargeant la page.
395 417
 				return $i+1;
@@ -408,9 +430,10 @@  discard block
 block discarded – undo
408 430
 // http://doc.spip.org/@upgrade_types_documents
409 431
 function upgrade_types_documents() {
410 432
 	if (include_spip('base/medias')
411
-	AND function_exists('creer_base_types_doc'))
412
-		creer_base_types_doc();
413
-}
433
+	AND function_exists('creer_base_types_doc')) {
434
+			creer_base_types_doc();
435
+	}
436
+	}
414 437
 
415 438
 // http://doc.spip.org/@upgrade_test
416 439
 function upgrade_test() {
@@ -431,9 +454,9 @@  discard block
 block discarded – undo
431 454
 // http://doc.spip.org/@maj_version
432 455
 function maj_version ($version, $test = true) {
433 456
 	if ($test) {
434
-		if ($version>=1.922)
435
-			ecrire_meta('version_installee', $version, 'oui');
436
-		else {
457
+		if ($version>=1.922) {
458
+					ecrire_meta('version_installee', $version, 'oui');
459
+		} else {
437 460
 			// on le fait manuellement, car ecrire_meta utilise le champs impt qui est absent sur les vieilles versions
438 461
 			$GLOBALS['meta']['version_installee'] = $version;
439 462
 			sql_updateq('spip_meta',  array('valeur' => $version), "nom=" . sql_quote('version_installee') );
Please login to merge, or discard this patch.
ecrire/base/trouver_table.php 1 patch
Braces   +24 added lines, -19 removed lines patch added patch discarded remove patch
@@ -15,7 +15,9 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @package SPIP\SQL\Tables
17 17
 **/
18
-if (!defined('_ECRIRE_INC_VERSION')) return;
18
+if (!defined('_ECRIRE_INC_VERSION')) {
19
+    return;
20
+}
19 21
 include_spip('base/objets');
20 22
 
21 23
 /**
@@ -66,8 +68,9 @@  discard block
 block discarded – undo
66 68
 	global $tables_principales, $tables_auxiliaires, $table_des_tables;
67 69
 
68 70
 	if (!spip_connect($serveur)
69
-	OR !preg_match('/^[a-zA-Z0-9._-]*/',$nom))
70
-		return null;
71
+	OR !preg_match('/^[a-zA-Z0-9._-]*/',$nom)) {
72
+			return null;
73
+	}
71 74
 
72 75
 	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
73 76
 	$objets_sql = lister_tables_objets_sql("::md5");
@@ -93,10 +96,11 @@  discard block
 block discarded – undo
93 96
 	}
94 97
 
95 98
 	$nom_sql = $nom;
96
-	if (preg_match('/\.(.*)$/', $nom, $s))
97
-		$nom_sql = $s[1];
98
-	else
99
-		$nom_sql = $nom;
99
+	if (preg_match('/\.(.*)$/', $nom, $s)) {
100
+			$nom_sql = $s[1];
101
+	} else {
102
+			$nom_sql = $nom;
103
+	}
100 104
 
101 105
 	$fdesc = $desc = '';
102 106
 	$connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0];
@@ -117,21 +121,22 @@  discard block
 block discarded – undo
117 121
 	  AND defined('_VAR_MODE') AND _VAR_MODE!=='recalcul'
118 122
 	  AND (!isset($connexion['tables']) OR !$connexion['tables'])) {
119 123
 		if (lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql],$desc_cache)
120
-		  AND $desc_cache=unserialize($desc_cache))
121
-		  $connexion['tables'] = $desc_cache;
124
+		  AND $desc_cache=unserialize($desc_cache)) {
125
+				  $connexion['tables'] = $desc_cache;
126
+		}
122 127
 	}
123 128
 	if ($table_spip AND !isset($connexion['tables'][$nom_sql])) {
124 129
 
125
-		if (isset($tables_principales[$nom_sql]))
126
-			$fdesc = $tables_principales[$nom_sql];
130
+		if (isset($tables_principales[$nom_sql])) {
131
+					$fdesc = $tables_principales[$nom_sql];
132
+		}
127 133
 		// meme si pas d'abreviation declaree, trouver la table spip_$nom
128 134
 		// si c'est une table principale,
129 135
 		// puisqu'on le fait aussi pour les tables auxiliaires
130 136
 		elseif ($nom_sql==$nom AND isset($tables_principales['spip_' .$nom])){
131 137
 			$nom_sql = 'spip_' . $nom;
132 138
 			$fdesc = &$tables_principales[$nom_sql];
133
-		}
134
-		elseif (isset($tables_auxiliaires[$n=$nom])
139
+		} elseif (isset($tables_auxiliaires[$n=$nom])
135 140
 		  OR isset($tables_auxiliaires[$n='spip_'.$nom])) {
136 141
 			$nom_sql = $n;
137 142
 			$fdesc = &$tables_auxiliaires[$n];
@@ -149,8 +154,7 @@  discard block
 block discarded – undo
149 154
 			// on ne sait pas lire la structure de la table :
150 155
 			// on retombe sur la description donnee dans les fichiers spip
151 156
 			$desc = $fdesc;
152
-		}
153
-		else {
157
+		} else {
154 158
 			$desc['exist'] = true;
155 159
 		}
156 160
 
@@ -167,11 +171,12 @@  discard block
 block discarded – undo
167 171
 		$res = &$connexion['tables'][$nom_sql];
168 172
 		// une nouvelle table a ete decrite
169 173
 		// mettons donc a jour le cache des descriptions de ce serveur
170
-		if (is_writeable(_DIR_CACHE))
171
-			ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql],serialize($connexion['tables']),true);
174
+		if (is_writeable(_DIR_CACHE)) {
175
+					ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql],serialize($connexion['tables']),true);
176
+		}
177
+	} else {
178
+			$res = &$connexion['tables'][$nom_sql];
172 179
 	}
173
-	else
174
-		$res = &$connexion['tables'][$nom_sql];
175 180
 
176 181
 	// toujours retourner $nom dans id_table
177 182
 	$res['id_table']=$nom;
Please login to merge, or discard this patch.
ecrire/base/connect_sql.php 1 patch
Braces   +68 added lines, -35 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
 require_once _ROOT_RESTREINT . 'base/objets.php';
15 17
 
16 18
 //
@@ -30,8 +32,12 @@  discard block
 block discarded – undo
30 32
 
31 33
 	$serveur = !is_string($serveur) ? '' : strtolower($serveur);
32 34
 	$index = $serveur ? $serveur : 0;
33
-	if (!$version) $version = $spip_sql_version;
34
-	if (isset($connexions[$index][$version])) return $connexions[$index];
35
+	if (!$version) {
36
+	    $version = $spip_sql_version;
37
+	}
38
+	if (isset($connexions[$index][$version])) {
39
+	    return $connexions[$index];
40
+	}
35 41
 
36 42
 	include_spip('base/abstract_sql');
37 43
 	$install = (_request('exec') == 'install');
@@ -60,11 +66,14 @@  discard block
 block discarded – undo
60 66
 		}
61 67
 		if (!isset($GLOBALS['db_ok'])) {
62 68
 		  // fera mieux la prochaine fois
63
-			if ($install) return false;
64
-			if ($f AND is_readable($f))
65
-				spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
66
-			else
67
-				spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
69
+			if ($install) {
70
+			    return false;
71
+			}
72
+			if ($f AND is_readable($f)) {
73
+							spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
74
+			} else {
75
+							spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
76
+			}
68 77
 			spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS);
69 78
 			// ne plus reessayer si ce n'est pas l'install
70 79
 			return $connexions[$index]=false;
@@ -72,7 +81,9 @@  discard block
 block discarded – undo
72 81
 		$connexions[$index] = $GLOBALS['db_ok'];
73 82
 	}
74 83
 	// si la connexion a deja ete tentee mais a echoue, le dire!
75
-	if (!$connexions[$index]) return false;
84
+	if (!$connexions[$index]) {
85
+	    return false;
86
+	}
76 87
 
77 88
 	// la connexion a reussi ou etait deja faite.
78 89
 	// chargement de la version du jeu de fonctions
@@ -87,7 +98,9 @@  discard block
 block discarded – undo
87 98
 		}
88 99
 	}
89 100
 	$connexions[$index][$version] = $GLOBALS[$jeu];
90
-	if ($old) return $connexions[$index];
101
+	if ($old) {
102
+	    return $connexions[$index];
103
+	}
91 104
 
92 105
 	$connexions[$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0;
93 106
 
@@ -108,14 +121,17 @@  discard block
 block discarded – undo
108 121
 		// C'est le cas d'un dump sqlite par exemple 
109 122
 		if ($connexions[$index]['spip_connect_version']
110 123
 		AND sql_showtable('spip_meta', true, $serveur)
111
-		AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'",'','','','',$serveur))
112
-			$charset = $r;
113
-		else $charset = -1;
124
+		AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'",'','','','',$serveur)) {
125
+					$charset = $r;
126
+		} else {
127
+		    $charset = -1;
128
+		}
114 129
 	}
115 130
 	if ($charset != -1) {
116 131
 		$f = $GLOBALS[$jeu]['set_charset'];
117
-		if (function_exists($f))
118
-			$f($charset, $serveur);
132
+		if (function_exists($f)) {
133
+					$f($charset, $serveur);
134
+		}
119 135
 	}
120 136
 	return $connexions[$index];
121 137
 }
@@ -138,10 +154,15 @@  discard block
 block discarded – undo
138 154
 // http://doc.spip.org/@spip_connect_sql
139 155
 function spip_connect_sql($version, $ins='', $serveur='', $cont=false) {
140 156
 	$desc = spip_connect($serveur, $version);
141
-	if (function_exists($f = @$desc[$version][$ins])) return $f;
142
-	if ($cont) return $desc;
143
-	if ($ins)
144
-		spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
157
+	if (function_exists($f = @$desc[$version][$ins])) {
158
+	    return $f;
159
+	}
160
+	if ($cont) {
161
+	    return $desc;
162
+	}
163
+	if ($ins) {
164
+			spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
165
+	}
145 166
 	include_spip('inc/minipres');
146 167
 	echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'));
147 168
 	exit;
@@ -171,18 +192,20 @@  discard block
 block discarded – undo
171 192
 
172 193
 	// temps avant nouvelle tentative de connexion
173 194
 	// suite a une connection echouee
174
-	if (!defined('_CONNECT_RETRY_DELAY'))
175
-		define('_CONNECT_RETRY_DELAY',30);
195
+	if (!defined('_CONNECT_RETRY_DELAY')) {
196
+			define('_CONNECT_RETRY_DELAY',30);
197
+	}
176 198
 
177 199
 	$f = "";
178 200
 	// un fichier de identifiant par combinaison (type,host,port,db)
179 201
 	// pour ne pas declarer tout indisponible d'un coup
180 202
 	// si en cours d'installation ou si db=@test@ on ne pose rien
181 203
 	// car c'est un test de connexion
182
-	if (!defined('_ECRIRE_INSTALL') AND !$db=="@test@")
183
-		$f = _DIR_TMP . $type . '.' . substr(md5($host.$port.$db),0,8) . '.out';
184
-	elseif ($db=='@test@')
185
-		$db = '';
204
+	if (!defined('_ECRIRE_INSTALL') AND !$db=="@test@") {
205
+			$f = _DIR_TMP . $type . '.' . substr(md5($host.$port.$db),0,8) . '.out';
206
+	} elseif ($db=='@test@') {
207
+			$db = '';
208
+	}
186 209
 
187 210
 	if ($f
188 211
 		AND @file_exists($f)
@@ -191,9 +214,10 @@  discard block
 block discarded – undo
191 214
 		return;
192 215
 	}
193 216
 
194
-	if (!$prefixe)
195
-		$prefixe = isset($GLOBALS['table_prefix'])
217
+	if (!$prefixe) {
218
+			$prefixe = isset($GLOBALS['table_prefix'])
196 219
 		? $GLOBALS['table_prefix'] : $db;
220
+	}
197 221
 	$h = charger_fonction($type, 'req', true);
198 222
 	if (!$h) {
199 223
 		spip_log( "les requetes $type ne sont pas fournies", _LOG_HS);
@@ -238,12 +262,17 @@  discard block
 block discarded – undo
238 262
 		redirige_url_ecrire('upgrade', 'reinstall=oui');
239 263
 	}
240 264
 
241
-	if (!($f = $connexion['select'])) return false;
265
+	if (!($f = $connexion['select'])) {
266
+	    return false;
267
+	}
242 268
 	// en cas d'erreur select retourne la requette (is_string=true donc)
243 269
 	if (!$r = $f('valeur','spip_meta', "nom='charset_sql_connexion'")
244
-	  OR is_string($r))
245
-		return false;
246
-	if (!($f = $connexion['fetch'])) return false;
270
+	  OR is_string($r)) {
271
+			return false;
272
+	}
273
+	if (!($f = $connexion['fetch'])) {
274
+	    return false;
275
+	}
247 276
 	$r = $f($r);
248 277
 	return ($r['valeur'] ? $r['valeur'] : -1);
249 278
 }
@@ -273,8 +302,12 @@  discard block
 block discarded – undo
273 302
 	$ydesc = $trouver_table(table_objet($y));
274 303
 	$ix = @$xdesc['key']["PRIMARY KEY"];
275 304
 	$iy = @$ydesc['key']["PRIMARY KEY"];
276
-	if ($table = $ydesc['tables_jointures'][$ix]) return $table;
277
-	if ($table = $xdesc['tables_jointures'][$iy]) return $table;
305
+	if ($table = $ydesc['tables_jointures'][$ix]) {
306
+	    return $table;
307
+	}
308
+	if ($table = $xdesc['tables_jointures'][$iy]) {
309
+	    return $table;
310
+	}
278 311
 	return '';
279 312
 }
280 313
 
@@ -306,9 +339,9 @@  discard block
 block discarded – undo
306 339
 				break;
307 340
 		}
308 341
 		$query = str_replace($textes,$replace,$query);
342
+	} else {
343
+			$textes = array();
309 344
 	}
310
-	else
311
-		$textes = array();
312 345
 
313 346
 	return array($query, $textes);
314 347
 }
Please login to merge, or discard this patch.
ecrire/base/abstract_sql.php 1 patch
Braces   +289 added lines, -107 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
  * @version 1
25 25
  */
26 26
 
27
-if (!defined('_ECRIRE_INC_VERSION')) return;
27
+if (!defined('_ECRIRE_INC_VERSION')) {
28
+    return;
29
+}
28 30
 
29 31
 /** Version de l'API SQL */
30 32
 define('sql_ABSTRACT_VERSION', 1);
@@ -56,7 +58,9 @@  discard block
 block discarded – undo
56 58
 	static $sql_serveur = array();
57 59
 	if (!isset($sql_serveur[$serveur][$ins_sql])){
58 60
 		$f = spip_connect_sql(sql_ABSTRACT_VERSION, $ins_sql, $serveur, $continue);
59
-		if (!is_string($f) OR !$f) return $f;
61
+		if (!is_string($f) OR !$f) {
62
+		    return $f;
63
+		}
60 64
 		$sql_serveur[$serveur][$ins_sql] = $f;
61 65
 	}
62 66
 	return $sql_serveur[$serveur][$ins_sql];
@@ -86,8 +90,9 @@  discard block
 block discarded – undo
86 90
 	$desc = $desc[sql_ABSTRACT_VERSION];
87 91
 	$c = $desc['charsets'][$charset];
88 92
 	if ($c) {
89
-		if (function_exists($f=@$desc['get_charset'])) 
90
-			if ($f($c, $serveur, $option!==false)) return $c;
93
+		if (function_exists($f=@$desc['get_charset'])) {
94
+					if ($f($c, $serveur, $option!==false)) return $c;
95
+		}
91 96
 	}
92 97
 	spip_log( "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", _LOG_AVERTISSEMENT);
93 98
 	return false;
@@ -117,7 +122,9 @@  discard block
 block discarded – undo
117 122
 **/
118 123
 function sql_set_charset($charset,$serveur='', $option=true){
119 124
 	$f = sql_serveur('set_charset', $serveur,  $option==='continue' OR $option===false);
120
-	if (!is_string($f) OR !$f) return false;
125
+	if (!is_string($f) OR !$f) {
126
+	    return false;
127
+	}
121 128
 	return $f($charset, $serveur, $option!==false);
122 129
 }
123 130
 
@@ -171,14 +178,18 @@  discard block
 block discarded – undo
171 178
 	$groupby = array(), $orderby = array(), $limit = '', $having = array(),
172 179
 	$serveur='', $option=true) {
173 180
 	$f = sql_serveur('select', $serveur,  $option==='continue' OR $option===false);
174
-	if (!is_string($f) OR !$f) return false;
181
+	if (!is_string($f) OR !$f) {
182
+	    return false;
183
+	}
175 184
 
176 185
 	$debug = (defined('_VAR_MODE') AND _VAR_MODE == 'debug');
177 186
 	if (($option !== false) AND !$debug) {
178 187
 		$res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, is_array($option) ? true : $option);
179 188
 	} else {
180 189
 		$query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false);
181
-		if (!$option) return $query;
190
+		if (!$option) {
191
+		    return $query;
192
+		}
182 193
 		// le debug, c'est pour ce qui a ete produit par le compilateur
183 194
 		if (isset($GLOBALS['debug']['aucasou'])) {
184 195
 			list($table, $id,) = $GLOBALS['debug']['aucasou'];
@@ -189,7 +200,9 @@  discard block
 block discarded – undo
189 200
 	}
190 201
 
191 202
 	// en cas d'erreur
192
-	if (!is_string($res)) return $res;
203
+	if (!is_string($res)) {
204
+	    return $res;
205
+	}
193 206
 	// denoncer l'erreur SQL dans sa version brute
194 207
 	spip_sql_erreur($serveur);
195 208
 	// idem dans sa version squelette (prefixe des tables non substitue)
@@ -270,9 +283,13 @@  discard block
 block discarded – undo
270 283
 		      $groupby = array(), $having = array(),
271 284
 	$serveur='', $option=true) {
272 285
 	$f = sql_serveur('countsel', $serveur,  $option==='continue' OR $option===false);
273
-	if (!is_string($f) OR !$f) return false;
286
+	if (!is_string($f) OR !$f) {
287
+	    return false;
288
+	}
274 289
 	$r = $f($from, $where, $groupby, $having, $serveur, $option!==false);
275
-	if ($r===false) spip_sql_erreur($serveur);
290
+	if ($r===false) {
291
+	    spip_sql_erreur($serveur);
292
+	}
276 293
 	return $r;
277 294
 }
278 295
 
@@ -301,9 +318,13 @@  discard block
 block discarded – undo
301 318
 **/
302 319
 function sql_alter($q, $serveur='', $option=true) {
303 320
 	$f = sql_serveur('alter', $serveur,  $option==='continue' OR $option===false);
304
-	if (!is_string($f) OR !$f) return false;
321
+	if (!is_string($f) OR !$f) {
322
+	    return false;
323
+	}
305 324
 	$r = $f($q, $serveur, $option!==false);
306
-	if ($r===false) spip_sql_erreur($serveur);
325
+	if ($r===false) {
326
+	    spip_sql_erreur($serveur);
327
+	}
307 328
 	return $r;
308 329
 }
309 330
 
@@ -328,7 +349,9 @@  discard block
 block discarded – undo
328 349
  */
329 350
 function sql_fetch($res, $serveur='', $option=true) {
330 351
 	$f = sql_serveur('fetch', $serveur,  $option==='continue' OR $option===false);
331
-	if (!is_string($f) OR !$f) return false;
352
+	if (!is_string($f) OR !$f) {
353
+	    return false;
354
+	}
332 355
 	return $f($res, NULL, $serveur, $option!==false);
333 356
 }
334 357
 
@@ -357,11 +380,16 @@  discard block
 block discarded – undo
357 380
  */
358 381
 function sql_fetch_all($res, $serveur='', $option=true){
359 382
 	$rows = array();
360
-	if (!$res) return $rows;
383
+	if (!$res) {
384
+	    return $rows;
385
+	}
361 386
 	$f = sql_serveur('fetch', $serveur,  $option==='continue' OR $option===false);
362
-	if (!is_string($f) OR !$f) return array();
363
-	while ($r = $f($res, NULL, $serveur, $option!==false))
364
-		$rows[] = $r;
387
+	if (!is_string($f) OR !$f) {
388
+	    return array();
389
+	}
390
+	while ($r = $f($res, NULL, $serveur, $option!==false)) {
391
+			$rows[] = $r;
392
+	}
365 393
 	sql_free($res, $serveur);
366 394
 	return $rows;
367 395
 }
@@ -392,9 +420,13 @@  discard block
 block discarded – undo
392 420
 **/
393 421
 function sql_seek($res, $row_number, $serveur='', $option=true) {
394 422
 	$f = sql_serveur('seek', $serveur,  $option==='continue' OR $option===false);
395
-	if (!is_string($f) OR !$f) return false;
423
+	if (!is_string($f) OR !$f) {
424
+	    return false;
425
+	}
396 426
 	$r = $f($res, $row_number, $serveur, $option!==false);
397
-	if ($r===false) spip_sql_erreur($serveur);
427
+	if ($r===false) {
428
+	    spip_sql_erreur($serveur);
429
+	}
398 430
 	return $r;
399 431
 }
400 432
 
@@ -421,9 +453,13 @@  discard block
 block discarded – undo
421 453
 **/
422 454
 function sql_listdbs($serveur='', $option=true) {
423 455
 	$f = sql_serveur('listdbs', $serveur,  $option==='continue' OR $option===false);
424
-	if (!is_string($f) OR !$f) return false;
456
+	if (!is_string($f) OR !$f) {
457
+	    return false;
458
+	}
425 459
 	$r = $f($serveur);
426
-	if ($r===false) spip_sql_erreur($serveur);
460
+	if ($r===false) {
461
+	    spip_sql_erreur($serveur);
462
+	}
427 463
 	return $r;
428 464
 }
429 465
 
@@ -448,9 +484,13 @@  discard block
 block discarded – undo
448 484
 function sql_selectdb($nom, $serveur='', $option=true)
449 485
 {
450 486
 	$f = sql_serveur('selectdb', $serveur,  $option==='continue' OR $option===false);
451
-	if (!is_string($f) OR !$f) return false;
487
+	if (!is_string($f) OR !$f) {
488
+	    return false;
489
+	}
452 490
 	$r = $f($nom, $serveur, $option!==false);
453
-	if ($r===false) spip_sql_erreur($serveur);
491
+	if ($r===false) {
492
+	    spip_sql_erreur($serveur);
493
+	}
454 494
 	return $r;
455 495
 }
456 496
 
@@ -458,9 +498,13 @@  discard block
 block discarded – undo
458 498
 function sql_count($res, $serveur='', $option=true)
459 499
 {
460 500
 	$f = sql_serveur('count', $serveur,  $option==='continue' OR $option===false);
461
-	if (!is_string($f) OR !$f) return false;
501
+	if (!is_string($f) OR !$f) {
502
+	    return false;
503
+	}
462 504
 	$r = $f($res, $serveur, $option!==false);
463
-	if ($r===false) spip_sql_erreur($serveur);
505
+	if ($r===false) {
506
+	    spip_sql_erreur($serveur);
507
+	}
464 508
 	return $r;
465 509
 }
466 510
 
@@ -468,7 +512,9 @@  discard block
 block discarded – undo
468 512
 function sql_free($res, $serveur='', $option=true)
469 513
 {
470 514
 	$f = sql_serveur('free', $serveur,  $option==='continue' OR $option===false);
471
-	if (!is_string($f) OR !$f) return false;
515
+	if (!is_string($f) OR !$f) {
516
+	    return false;
517
+	}
472 518
 	return $f($res);
473 519
 }
474 520
 
@@ -480,9 +526,13 @@  discard block
 block discarded – undo
480 526
 function sql_insert($table, $noms, $valeurs, $desc=array(), $serveur='', $option=true)
481 527
 {
482 528
 	$f = sql_serveur('insert', $serveur,  $option==='continue' OR $option===false);
483
-	if (!is_string($f) OR !$f) return false;
529
+	if (!is_string($f) OR !$f) {
530
+	    return false;
531
+	}
484 532
 	$r = $f($table, $noms, $valeurs, $desc, $serveur, $option!==false);
485
-	if ($r === false) spip_sql_erreur($serveur);
533
+	if ($r === false) {
534
+	    spip_sql_erreur($serveur);
535
+	}
486 536
 	return $r;
487 537
 }
488 538
 
@@ -490,9 +540,13 @@  discard block
 block discarded – undo
490 540
 function sql_insertq($table, $couples=array(), $desc=array(), $serveur='', $option=true)
491 541
 {
492 542
 	$f = sql_serveur('insertq', $serveur,  $option==='continue' OR $option===false);
493
-	if (!is_string($f) OR !$f) return false;
543
+	if (!is_string($f) OR !$f) {
544
+	    return false;
545
+	}
494 546
 	$r = $f($table, $couples, $desc, $serveur, $option!==false);
495
-	if ($r === false) spip_sql_erreur($serveur);
547
+	if ($r === false) {
548
+	    spip_sql_erreur($serveur);
549
+	}
496 550
 	return $r;
497 551
 }
498 552
 
@@ -500,9 +554,13 @@  discard block
 block discarded – undo
500 554
 function sql_insertq_multi($table, $couples=array(), $desc=array(), $serveur='', $option=true)
501 555
 {
502 556
 	$f = sql_serveur('insertq_multi', $serveur,  $option==='continue' OR $option===false);
503
-	if (!is_string($f) OR !$f) return false;
557
+	if (!is_string($f) OR !$f) {
558
+	    return false;
559
+	}
504 560
 	$r = $f($table, $couples, $desc, $serveur, $option!==false);
505
-	if ($r === false) spip_sql_erreur($serveur);
561
+	if ($r === false) {
562
+	    spip_sql_erreur($serveur);
563
+	}
506 564
 	return $r;
507 565
 }
508 566
 
@@ -510,9 +568,13 @@  discard block
 block discarded – undo
510 568
 function sql_update($table, $exp, $where='', $desc=array(), $serveur='', $option=true)
511 569
 {
512 570
 	$f = sql_serveur('update', $serveur,  $option==='continue' OR $option===false);
513
-	if (!is_string($f) OR !$f) return false;
571
+	if (!is_string($f) OR !$f) {
572
+	    return false;
573
+	}
514 574
 	$r = $f($table, $exp, $where, $desc, $serveur, $option!==false);
515
-	if ($r === false) spip_sql_erreur($serveur);
575
+	if ($r === false) {
576
+	    spip_sql_erreur($serveur);
577
+	}
516 578
 	return $r;
517 579
 }
518 580
 
@@ -523,9 +585,13 @@  discard block
 block discarded – undo
523 585
 function sql_updateq($table, $exp, $where='', $desc=array(), $serveur='', $option=true)
524 586
 {
525 587
 	$f = sql_serveur('updateq', $serveur,  $option==='continue' OR $option===false);
526
-	if (!is_string($f) OR !$f) return false;
588
+	if (!is_string($f) OR !$f) {
589
+	    return false;
590
+	}
527 591
 	$r = $f($table, $exp, $where, $desc, $serveur, $option!==false);
528
-	if ($r === false) spip_sql_erreur($serveur);
592
+	if ($r === false) {
593
+	    spip_sql_erreur($serveur);
594
+	}
529 595
 	return $r;
530 596
 }
531 597
 
@@ -533,9 +599,13 @@  discard block
 block discarded – undo
533 599
 function sql_delete($table, $where='', $serveur='', $option=true)
534 600
 {
535 601
 	$f = sql_serveur('delete', $serveur,  $option==='continue' OR $option===false);
536
-	if (!is_string($f) OR !$f) return false;
602
+	if (!is_string($f) OR !$f) {
603
+	    return false;
604
+	}
537 605
 	$r = $f($table, $where, $serveur, $option!==false);
538
-	if ($r === false) spip_sql_erreur($serveur);
606
+	if ($r === false) {
607
+	    spip_sql_erreur($serveur);
608
+	}
539 609
 	return $r;
540 610
 }
541 611
 
@@ -543,9 +613,13 @@  discard block
 block discarded – undo
543 613
 function sql_replace($table, $couples, $desc=array(), $serveur='', $option=true)
544 614
 {
545 615
 	$f = sql_serveur('replace', $serveur,  $option==='continue' OR $option===false);
546
-	if (!is_string($f) OR !$f) return false;
616
+	if (!is_string($f) OR !$f) {
617
+	    return false;
618
+	}
547 619
 	$r = $f($table, $couples, $desc, $serveur, $option!==false);
548
-	if ($r === false) spip_sql_erreur($serveur);
620
+	if ($r === false) {
621
+	    spip_sql_erreur($serveur);
622
+	}
549 623
 	return $r;
550 624
 }
551 625
 
@@ -554,9 +628,13 @@  discard block
 block discarded – undo
554 628
 function sql_replace_multi($table, $tab_couples, $desc=array(), $serveur='', $option=true)
555 629
 {
556 630
 	$f = sql_serveur('replace_multi', $serveur,  $option==='continue' OR $option===false);
557
-	if (!is_string($f) OR !$f) return false;
631
+	if (!is_string($f) OR !$f) {
632
+	    return false;
633
+	}
558 634
 	$r = $f($table, $tab_couples, $desc, $serveur, $option!==false);
559
-	if ($r === false) spip_sql_erreur($serveur);
635
+	if ($r === false) {
636
+	    spip_sql_erreur($serveur);
637
+	}
560 638
 	return $r;
561 639
 }
562 640
 
@@ -564,9 +642,13 @@  discard block
 block discarded – undo
564 642
 function sql_drop_table($table, $exist='', $serveur='', $option=true)
565 643
 {
566 644
 	$f = sql_serveur('drop_table', $serveur,  $option==='continue' OR $option===false);
567
-	if (!is_string($f) OR !$f) return false;
645
+	if (!is_string($f) OR !$f) {
646
+	    return false;
647
+	}
568 648
 	$r = $f($table, $exist, $serveur, $option!==false);
569
-	if ($r === false) spip_sql_erreur($serveur);
649
+	if ($r === false) {
650
+	    spip_sql_erreur($serveur);
651
+	}
570 652
 	return $r;
571 653
 }
572 654
 
@@ -575,9 +657,13 @@  discard block
 block discarded – undo
575 657
 function sql_drop_view($table, $exist='', $serveur='', $option=true)
576 658
 {
577 659
 	$f = sql_serveur('drop_view', $serveur,  $option==='continue' OR $option===false);
578
-	if (!is_string($f) OR !$f) return false;
660
+	if (!is_string($f) OR !$f) {
661
+	    return false;
662
+	}
579 663
 	$r = $f($table, $exist, $serveur, $option!==false);
580
-	if ($r === false) spip_sql_erreur($serveur);
664
+	if ($r === false) {
665
+	    spip_sql_erreur($serveur);
666
+	}
581 667
 	return $r;
582 668
 }
583 669
 
@@ -602,7 +688,9 @@  discard block
 block discarded – undo
602 688
 function sql_showbase($spip=NULL, $serveur='', $option=true)
603 689
 {
604 690
 	$f = sql_serveur('showbase', $serveur,  $option==='continue' OR $option===false);
605
-	if (!is_string($f) OR !$f) return false;
691
+	if (!is_string($f) OR !$f) {
692
+	    return false;
693
+	}
606 694
 
607 695
 	// la globale n'est remplie qu'apres l'appel de sql_serveur.
608 696
 	if ($spip == NULL){
@@ -636,7 +724,10 @@  discard block
 block discarded – undo
636 724
 {
637 725
 	$q = sql_showbase($spip, $serveur, $option);
638 726
 	$r = array();
639
-	if ($q) while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t);}
727
+	if ($q) {
728
+	    while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t);
729
+	}
730
+	}
640 731
 	return $r;
641 732
 }
642 733
 
@@ -644,39 +735,54 @@  discard block
 block discarded – undo
644 735
 function sql_showtable($table, $table_spip = false, $serveur='', $option=true)
645 736
 {
646 737
 	$f = sql_serveur('showtable', $serveur,  $option==='continue' OR $option===false);
647
-	if (!is_string($f) OR !$f) return false;
738
+	if (!is_string($f) OR !$f) {
739
+	    return false;
740
+	}
648 741
 
649 742
 	// la globale n'est remplie qu'apres l'appel de sql_serveur.
650 743
 	if ($table_spip){
651 744
 		$connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
652 745
 		$prefixe = $connexion['prefixe'];
653 746
 		$vraie_table = preg_replace('/^spip/', $prefixe, $table);
654
-	} else $vraie_table = $table;
747
+	} else {
748
+	    $vraie_table = $table;
749
+	}
655 750
 
656 751
 	$f = $f($vraie_table, $serveur, $option!==false);
657
-	if (!$f) return array();
658
-	if (isset($GLOBALS['tables_principales'][$table]['join']))
659
-		$f['join'] = $GLOBALS['tables_principales'][$table]['join'];
660
-	elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join']))
661
-		$f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join'];
752
+	if (!$f) {
753
+	    return array();
754
+	}
755
+	if (isset($GLOBALS['tables_principales'][$table]['join'])) {
756
+			$f['join'] = $GLOBALS['tables_principales'][$table]['join'];
757
+	} elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) {
758
+			$f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join'];
759
+	}
662 760
 	return $f;
663 761
 }
664 762
 
665 763
 // http://doc.spip.org/@sql_create
666 764
 function sql_create($nom, $champs, $cles=array(), $autoinc=false, $temporary=false, $serveur='', $option=true) {
667 765
 	$f = sql_serveur('create', $serveur,  $option==='continue' OR $option===false);
668
-	if (!is_string($f) OR !$f) return false;
766
+	if (!is_string($f) OR !$f) {
767
+	    return false;
768
+	}
669 769
 	$r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option!==false);
670
-	if ($r === false) spip_sql_erreur($serveur);
770
+	if ($r === false) {
771
+	    spip_sql_erreur($serveur);
772
+	}
671 773
 	return $r;
672 774
 }
673 775
 
674 776
 function sql_create_base($nom, $serveur='', $option=true)
675 777
 {
676 778
 	$f = sql_serveur('create_base', $serveur,  $option==='continue' OR $option===false);
677
-	if (!is_string($f) OR !$f) return false;
779
+	if (!is_string($f) OR !$f) {
780
+	    return false;
781
+	}
678 782
 	$r = $f($nom, $serveur, $option!==false);
679
-	if ($r === false) spip_sql_erreur($serveur);
783
+	if ($r === false) {
784
+	    spip_sql_erreur($serveur);
785
+	}
680 786
 	return $r;
681 787
 }
682 788
 
@@ -687,9 +793,13 @@  discard block
 block discarded – undo
687 793
 // http://doc.spip.org/@sql_create_view
688 794
 function sql_create_view($nom, $select_query, $serveur='', $option=true) {
689 795
 	$f = sql_serveur('create_view', $serveur,  $option==='continue' OR $option===false);
690
-	if (!is_string($f) OR !$f) return false;
796
+	if (!is_string($f) OR !$f) {
797
+	    return false;
798
+	}
691 799
 	$r = $f($nom, $select_query, $serveur, $option!==false);
692
-	if ($r === false) spip_sql_erreur($serveur);
800
+	if ($r === false) {
801
+	    spip_sql_erreur($serveur);
802
+	}
693 803
 	return $r;
694 804
 }
695 805
 
@@ -697,7 +807,9 @@  discard block
 block discarded – undo
697 807
 function sql_multi($sel, $lang, $serveur='', $option=true)
698 808
 {
699 809
 	$f = sql_serveur('multi', $serveur,  $option==='continue' OR $option===false);
700
-	if (!is_string($f) OR !$f) return false;
810
+	if (!is_string($f) OR !$f) {
811
+	    return false;
812
+	}
701 813
 	return $f($sel, $lang);
702 814
 }
703 815
 
@@ -714,7 +826,9 @@  discard block
 block discarded – undo
714 826
  */
715 827
 function sql_error($serveur='') {
716 828
 	$f = sql_serveur('error', $serveur, 'continue');
717
-	if (!is_string($f) OR !$f) return false;
829
+	if (!is_string($f) OR !$f) {
830
+	    return false;
831
+	}
718 832
 	return $f('query inconnue', $serveur);
719 833
 }
720 834
 
@@ -730,34 +844,48 @@  discard block
 block discarded – undo
730 844
  */
731 845
 function sql_errno($serveur='') {
732 846
 	$f = sql_serveur('errno', $serveur, 'continue');
733
-	if (!is_string($f) OR !$f) return false;
847
+	if (!is_string($f) OR !$f) {
848
+	    return false;
849
+	}
734 850
 	return $f($serveur);
735 851
 }
736 852
 
737 853
 // http://doc.spip.org/@sql_explain
738 854
 function sql_explain($q, $serveur='', $option=true) {
739 855
 	$f = sql_serveur('explain', $serveur,  'continue');
740
-	if (!is_string($f) OR !$f) return false;
856
+	if (!is_string($f) OR !$f) {
857
+	    return false;
858
+	}
741 859
 	$r = $f($q, $serveur, $option!==false);
742
-	if ($r === false) spip_sql_erreur($serveur);
860
+	if ($r === false) {
861
+	    spip_sql_erreur($serveur);
862
+	}
743 863
 	return $r;
744 864
 }
745 865
 
746 866
 // http://doc.spip.org/@sql_optimize
747 867
 function sql_optimize($table, $serveur='', $option=true) {
748 868
 	$f = sql_serveur('optimize', $serveur,  $option==='continue' OR $option===false);
749
-	if (!is_string($f) OR !$f) return false;
869
+	if (!is_string($f) OR !$f) {
870
+	    return false;
871
+	}
750 872
 	$r = $f($table, $serveur, $option!==false);
751
-	if ($r === false) spip_sql_erreur($serveur);
873
+	if ($r === false) {
874
+	    spip_sql_erreur($serveur);
875
+	}
752 876
 	return $r;
753 877
 }
754 878
 
755 879
 // http://doc.spip.org/@sql_repair
756 880
 function sql_repair($table, $serveur='', $option=true) {
757 881
 	$f = sql_serveur('repair', $serveur,  $option==='continue' OR $option===false);
758
-	if (!is_string($f) OR !$f) return false;
882
+	if (!is_string($f) OR !$f) {
883
+	    return false;
884
+	}
759 885
 	$r = $f($table, $serveur, $option!==false);
760
-	if ($r === false) spip_sql_erreur($serveur);
886
+	if ($r === false) {
887
+	    spip_sql_erreur($serveur);
888
+	}
761 889
 	return $r;
762 890
 }
763 891
 
@@ -767,9 +895,13 @@  discard block
 block discarded – undo
767 895
 // http://doc.spip.org/@sql_query
768 896
 function sql_query($ins, $serveur='', $option=true) {
769 897
 	$f = sql_serveur('query', $serveur,  $option==='continue' OR $option===false);
770
-	if (!is_string($f) OR !$f) return false;
898
+	if (!is_string($f) OR !$f) {
899
+	    return false;
900
+	}
771 901
 	$r = $f($ins, $serveur, $option!==false);
772
-	if ($r === false) spip_sql_erreur($serveur);
902
+	if ($r === false) {
903
+	    spip_sql_erreur($serveur);
904
+	}
773 905
 	return $r;
774 906
 }
775 907
 
@@ -822,8 +954,12 @@  discard block
 block discarded – undo
822 954
 	$groupby = array(), $orderby = array(), $limit = '',
823 955
 	$having = array(), $serveur='', $option=true) {
824 956
 	$q = sql_select($select, $from, $where,	$groupby, $orderby, $limit, $having, $serveur, $option);
825
-	if ($option===false) return $q;
826
-	if (!$q) return array();
957
+	if ($option===false) {
958
+	    return $q;
959
+	}
960
+	if (!$q) {
961
+	    return array();
962
+	}
827 963
 	$r = sql_fetch($q, $serveur, $option);
828 964
 	sql_free($q, $serveur, $option);
829 965
 	return $r;
@@ -886,7 +1022,9 @@  discard block
 block discarded – undo
886 1022
 	$groupby = array(), $orderby = array(), $limit = '',
887 1023
 	$having = array(), $serveur='', $option=true) {
888 1024
 	$q = sql_select($select, $from, $where,	$groupby, $orderby, $limit, $having, $serveur, $option);
889
-	if ($option===false) return $q;
1025
+	if ($option===false) {
1026
+	    return $q;
1027
+	}
890 1028
 	return sql_fetch_all($q, $serveur, $option);
891 1029
 }
892 1030
 
@@ -933,12 +1071,18 @@  discard block
 block discarded – undo
933 1071
 **/
934 1072
 function sql_getfetsel($select, $from = array(), $where = array(), $groupby = array(), 
935 1073
 	$orderby = array(), $limit = '', $having = array(), $serveur='', $option=true) {
936
-	if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) $id = $c[1];
937
-	elseif (!preg_match('/\W/', $select)) $id = $select;
938
-	else {$id = 'n'; $select .= ' AS n';}
1074
+	if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) {
1075
+	    $id = $c[1];
1076
+	} elseif (!preg_match('/\W/', $select)) {
1077
+	    $id = $select;
1078
+	} else {$id = 'n'; $select .= ' AS n';}
939 1079
 	$r = sql_fetsel($select, $from, $where,	$groupby, $orderby, $limit, $having, $serveur, $option);
940
-	if ($option===false) return $r;
941
-	if (!$r) return NULL;
1080
+	if ($option===false) {
1081
+	    return $r;
1082
+	}
1083
+	if (!$r) {
1084
+	    return NULL;
1085
+	}
942 1086
 	return $r[$id]; 
943 1087
 }
944 1088
 
@@ -995,9 +1139,13 @@  discard block
 block discarded – undo
995 1139
 **/
996 1140
 function sql_preferer_transaction($serveur='', $option=true) {
997 1141
 	$f = sql_serveur('preferer_transaction', $serveur,  'continue');
998
-	if (!is_string($f) OR !$f) return false;
1142
+	if (!is_string($f) OR !$f) {
1143
+	    return false;
1144
+	}
999 1145
 	$r = $f($serveur, $option!==false);
1000
-	if ($r === false) spip_sql_erreur($serveur);
1146
+	if ($r === false) {
1147
+	    spip_sql_erreur($serveur);
1148
+	}
1001 1149
 	return $r;
1002 1150
 };
1003 1151
 
@@ -1021,9 +1169,13 @@  discard block
 block discarded – undo
1021 1169
 **/
1022 1170
 function sql_demarrer_transaction($serveur='', $option=true) {
1023 1171
 	$f = sql_serveur('demarrer_transaction', $serveur,  'continue');
1024
-	if (!is_string($f) OR !$f) return false;
1172
+	if (!is_string($f) OR !$f) {
1173
+	    return false;
1174
+	}
1025 1175
 	$r = $f($serveur, $option!==false);
1026
-	if ($r === false) spip_sql_erreur($serveur);
1176
+	if ($r === false) {
1177
+	    spip_sql_erreur($serveur);
1178
+	}
1027 1179
 	return $r;
1028 1180
 };
1029 1181
 
@@ -1047,9 +1199,13 @@  discard block
 block discarded – undo
1047 1199
 **/
1048 1200
 function sql_terminer_transaction($serveur='', $option=true) {
1049 1201
 	$f = sql_serveur('terminer_transaction', $serveur,  'continue');
1050
-	if (!is_string($f) OR !$f) return false;
1202
+	if (!is_string($f) OR !$f) {
1203
+	    return false;
1204
+	}
1051 1205
 	$r = $f($serveur, $option!==false);
1052
-	if ($r === false) spip_sql_erreur($serveur);
1206
+	if ($r === false) {
1207
+	    spip_sql_erreur($serveur);
1208
+	}
1053 1209
 	return $r;
1054 1210
 };
1055 1211
 
@@ -1076,7 +1232,9 @@  discard block
 block discarded – undo
1076 1232
 function sql_hex($val, $serveur='', $option=true)
1077 1233
 {
1078 1234
 	$f = sql_serveur('hex', $serveur,  $option==='continue' OR $option===false);
1079
-	if (!is_string($f) OR !$f) return false;
1235
+	if (!is_string($f) OR !$f) {
1236
+	    return false;
1237
+	}
1080 1238
 	return $f($val);
1081 1239
 }
1082 1240
 
@@ -1103,14 +1261,18 @@  discard block
 block discarded – undo
1103 1261
 function sql_quote($val, $serveur='', $type='')
1104 1262
 {
1105 1263
 	$f = sql_serveur('quote', $serveur, true);
1106
-	if (!is_string($f) OR !$f) $f = '_q';
1264
+	if (!is_string($f) OR !$f) {
1265
+	    $f = '_q';
1266
+	}
1107 1267
 	return $f($val, $type);
1108 1268
 }
1109 1269
 
1110 1270
 function sql_date_proche($champ, $interval, $unite, $serveur='', $option=true)
1111 1271
 {
1112 1272
 	$f = sql_serveur('date_proche', $serveur, true);
1113
-	if (!is_string($f) OR !$f) return false;
1273
+	if (!is_string($f) OR !$f) {
1274
+	    return false;
1275
+	}
1114 1276
 	return $f($champ, $interval, $unite);
1115 1277
 }
1116 1278
 
@@ -1145,13 +1307,21 @@  discard block
 block discarded – undo
1145 1307
 function sql_in($val, $valeurs, $not='', $serveur='', $option=true) {
1146 1308
 	if (is_array($valeurs)) {
1147 1309
 		$f = sql_serveur('quote', $serveur, true);
1148
-		if (!is_string($f) OR !$f) return false;
1310
+		if (!is_string($f) OR !$f) {
1311
+		    return false;
1312
+		}
1149 1313
 		$valeurs = join(',', array_map($f, array_unique($valeurs)));
1150
-	} elseif (isset($valeurs[0]) AND $valeurs[0]===',') $valeurs = substr($valeurs,1);
1151
-	if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1');
1314
+	} elseif (isset($valeurs[0]) AND $valeurs[0]===',') {
1315
+	    $valeurs = substr($valeurs,1);
1316
+	}
1317
+	if (!strlen(trim($valeurs))) {
1318
+	    return ($not ? "0=0" : '0=1');
1319
+	}
1152 1320
 
1153 1321
 	$f = sql_serveur('in', $serveur,  $option==='continue' OR $option===false);
1154
-	if (!is_string($f) OR !$f) return false;
1322
+	if (!is_string($f) OR !$f) {
1323
+	    return false;
1324
+	}
1155 1325
 	return $f($val, $valeurs, $not, $serveur, $option!==false);
1156 1326
 }
1157 1327
 
@@ -1198,18 +1368,21 @@  discard block
 block discarded – undo
1198 1368
  */
1199 1369
 function sql_skip($res, $pos, $saut, $count, $serveur='', $option=true){
1200 1370
 	// pas de saut en arriere qu'on ne sait pas faire sans sql_seek
1201
-	if (($saut=intval($saut))<=0) return $pos;
1371
+	if (($saut=intval($saut))<=0) {
1372
+	    return $pos;
1373
+	}
1202 1374
 
1203 1375
 	$seek = $pos + $saut;
1204 1376
 	// si le saut fait depasser le maxi, on libere la resource
1205 1377
 	// et on sort
1206 1378
 	if ($seek>=$count) {sql_free($res, $serveur, $option); return $count;}
1207 1379
 
1208
-	if (sql_seek($res, $seek))
1209
-		$pos = $seek;
1210
-	else
1211
-		while ($pos<$seek AND sql_fetch($res, $serveur, $option))
1380
+	if (sql_seek($res, $seek)) {
1381
+			$pos = $seek;
1382
+	} else {
1383
+			while ($pos<$seek AND sql_fetch($res, $serveur, $option))
1212 1384
 			$pos++;
1385
+	}
1213 1386
 	return $pos;
1214 1387
 }
1215 1388
 
@@ -1248,8 +1421,12 @@  discard block
 block discarded – undo
1248 1421
 	$annee = sprintf("%04s",$annee);
1249 1422
 	$mois = sprintf("%02s",$mois);
1250 1423
 
1251
-	if ($annee == "0000") $mois = 0;
1252
-	if ($mois == "00") $jour = 0;
1424
+	if ($annee == "0000") {
1425
+	    $mois = 0;
1426
+	}
1427
+	if ($mois == "00") {
1428
+	    $jour = 0;
1429
+	}
1253 1430
 
1254 1431
 	return sprintf("%04u",$annee) . '-' . sprintf("%02u",$mois) . '-'
1255 1432
 		. sprintf("%02u",$jour) . ' ' . sprintf("%02u",$h) . ':'
@@ -1285,18 +1462,23 @@  discard block
 block discarded – undo
1285 1462
 	 car sinon on va se comporter differement selon que la table est declaree
1286 1463
 	 ou non
1287 1464
 	 */
1288
-	if (!$trouver_table) $trouver_table = charger_fonction('trouver_table', 'base');
1289
-	if ($desc = $trouver_table($nom, $serveur))
1290
-		return $desc;
1465
+	if (!$trouver_table) {
1466
+	    $trouver_table = charger_fonction('trouver_table', 'base');
1467
+	}
1468
+	if ($desc = $trouver_table($nom, $serveur)) {
1469
+			return $desc;
1470
+	}
1291 1471
 
1292 1472
 	// sauf a l'installation :
1293 1473
 	include_spip('base/serial');
1294
-	if (isset($tables_principales[$nom]))
1295
-		return $tables_principales[$nom];
1474
+	if (isset($tables_principales[$nom])) {
1475
+			return $tables_principales[$nom];
1476
+	}
1296 1477
 
1297 1478
 	include_spip('base/auxiliaires');
1298
-	if (isset($tables_auxiliaires[$nom]))
1299
-		return $tables_auxiliaires[$nom];
1479
+	if (isset($tables_auxiliaires[$nom])) {
1480
+			return $tables_auxiliaires[$nom];
1481
+	}
1300 1482
 
1301 1483
 	return false;
1302 1484
 }
Please login to merge, or discard this patch.
ecrire/base/create.php 1 patch
Braces   +28 added lines, -20 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
 include_spip('inc/acces');
16 18
 include_spip('base/objets');
@@ -26,11 +28,11 @@  discard block
 block discarded – undo
26 28
  * @return bool
27 29
  */
28 30
 function base_determine_autoinc($table,$desc=array()){
29
-	if ($t=lister_tables_principales() AND isset($t[$table]))
30
-		$autoinc = true;
31
-	elseif ($t=lister_tables_auxiliaires() AND isset($t[$table]))
32
-		$autoinc = false;
33
-	else {
31
+	if ($t=lister_tables_principales() AND isset($t[$table])) {
32
+			$autoinc = true;
33
+	} elseif ($t=lister_tables_auxiliaires() AND isset($t[$table])) {
34
+			$autoinc = false;
35
+	} else {
34 36
 		// essayer de faire au mieux !
35 37
 		$autoinc = (isset($desc['key']['PRIMARY KEY'])
36 38
 						AND strpos($desc['key']['PRIMARY KEY'],',')===false
@@ -60,8 +62,9 @@  discard block
 block discarded – undo
60 62
 	#if (!$sql_desc) $sql_desc = false;
61 63
 	#spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE);
62 64
 	if (!$sql_desc) {
63
-		if ($autoinc==='auto')
64
-			$autoinc = base_determine_autoinc($table,$desc);
65
+		if ($autoinc==='auto') {
66
+					$autoinc = base_determine_autoinc($table,$desc);
67
+		}
65 68
 		#spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE);
66 69
 		sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur);
67 70
 		// verifier la bonne installation de la table (php-fpm es-tu la ?)
@@ -79,23 +82,24 @@  discard block
 block discarded – undo
79 82
 				spip_log("Echec creation table $table","maj"._LOG_CRITIQUE);
80 83
 			}
81 84
 		}
82
-	}
83
-	else {
85
+	} else {
84 86
 		#spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE);
85 87
 		// ajouter les champs manquants
86 88
 		// on ne supprime jamais les champs, car c'est dangereux
87 89
 		// c'est toujours a faire manuellement
88 90
 		$last = '';
89 91
 		foreach($desc['field'] as $field=>$type){
90
-			if (!isset($sql_desc['field'][$field]))
91
-				sql_alter("TABLE $table ADD $field $type".($last?" AFTER $last":""),$serveur);
92
+			if (!isset($sql_desc['field'][$field])) {
93
+							sql_alter("TABLE $table ADD $field $type".($last?" AFTER $last":""),$serveur);
94
+			}
92 95
 			$last = $field;
93 96
 		}
94 97
 		foreach($desc['key'] as $key=>$type){
95 98
 			// Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees
96 99
 			// par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY"
97
-			if (!isset($sql_desc['key'][$key]) AND !isset($sql_desc['key']["$key $type"]))
98
-				sql_alter("TABLE $table ADD $key ($type)",$serveur);
100
+			if (!isset($sql_desc['key'][$key]) AND !isset($sql_desc['key']["$key $type"])) {
101
+							sql_alter("TABLE $table ADD $key ($type)",$serveur);
102
+			}
99 103
 			$last = $field;
100 104
 		}
101 105
 
@@ -125,16 +129,20 @@  discard block
 block discarded – undo
125 129
 		$up = array();
126 130
 	} else {
127 131
 		$old = true;
128
-		if (!is_array($up)) $up = array($up);
132
+		if (!is_array($up)) {
133
+		    $up = array($up);
134
+		}
129 135
 	}
130
-	foreach($tables_inc as $k => $v)
131
-		if (!$old OR in_array($k, $up))
136
+	foreach($tables_inc as $k => $v) {
137
+			if (!$old OR in_array($k, $up))
132 138
 			creer_ou_upgrader_table($k,$v,true,$old,$serveur);
139
+	}
133 140
 
134
-	foreach($tables_noinc as $k => $v)
135
-		if (!$old OR in_array($k, $up))
141
+	foreach($tables_noinc as $k => $v) {
142
+			if (!$old OR in_array($k, $up))
136 143
 			creer_ou_upgrader_table($k,$v,false,$old,$serveur);
137
-}
144
+	}
145
+	}
138 146
 
139 147
 /**
140 148
  * Creer une base de donnee
Please login to merge, or discard this patch.
ecrire/base/auxiliaires.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,9 @@
 block discarded – undo
20 20
  * @package SPIP\SQL\Tables
21 21
 **/
22 22
 
23
-if (!defined('_ECRIRE_INC_VERSION')) return;
23
+if (!defined('_ECRIRE_INC_VERSION')) {
24
+    return;
25
+}
24 26
 
25 27
 include_spip('base/objets');
26 28
 lister_tables_objets_sql();
Please login to merge, or discard this patch.
ecrire/base/objets.php 1 patch
Braces   +208 added lines, -138 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\SQL\Tables
17 17
 **/
18 18
 
19
-if (!defined('_ECRIRE_INC_VERSION')) return;
19
+if (!defined('_ECRIRE_INC_VERSION')) {
20
+    return;
21
+}
20 22
 
21 23
 /**
22 24
  * Merge dans un tableau une de ses clés avec une valeur
@@ -30,11 +32,12 @@  discard block
 block discarded – undo
30 32
  * @return void
31 33
 **/
32 34
 function array_set_merge(&$table,$index,$valeur){
33
-	if (!isset($table[$index]))
34
-		$table[$index] = $valeur;
35
-	else
36
-		$table[$index] = array_merge($table[$index],$valeur);
37
-}
35
+	if (!isset($table[$index])) {
36
+			$table[$index] = $valeur;
37
+	} else {
38
+			$table[$index] = array_merge($table[$index],$valeur);
39
+	}
40
+	}
38 41
 
39 42
 /**
40 43
  * Lister les infos de toutes les tables sql declarées
@@ -342,30 +345,32 @@  discard block
 block discarded – undo
342 345
 			if (is_numeric($t)) {
343 346
 				$all = array_merge_recursive($all,$infos_tables[$t]);
344 347
 				unset($infos_tables[$t]);
348
+			} else {
349
+							$infos_tables[$t] = renseigner_table_objet_sql($t,$infos_tables[$t]);
345 350
 			}
346
-			else
347
-				$infos_tables[$t] = renseigner_table_objet_sql($t,$infos_tables[$t]);
348 351
 		}
349 352
 
350 353
 		// repercuter les proprietes generales communes a tous les objets
351 354
 		foreach(array_keys($infos_tables) as $t) {
352
-			foreach($all as $i=>$v)
353
-				if (in_array($i,array('tables_jointures','champs_versionnes'))){
355
+			foreach($all as $i=>$v) {
356
+							if (in_array($i,array('tables_jointures','champs_versionnes'))){
354 357
 					$add = $all[$i];
358
+			}
355 359
 					// eviter les doublons de declaration de table jointure (ex des mots sur auteurs)
356 360
 					// pour les declarations generiques avec cles numeriques
357 361
 					if ($i=='tables_jointures' AND isset($infos_tables[$t][$i]) AND count($infos_tables[$t][$i])) {
358 362
 						$doublons = array_intersect($infos_tables[$t][$i],$add);
359 363
 						foreach($doublons as $d){
360 364
 							if (is_numeric(array_search($d,$infos_tables[$t][$i]))
361
-								AND is_numeric($k=array_search($d,$add)))
362
-								unset($add[$k]);
365
+								AND is_numeric($k=array_search($d,$add))) {
366
+															unset($add[$k]);
367
+							}
363 368
 						}
364 369
 					}
365 370
 					$infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i])?$infos_tables[$t][$i]:array(),$add);
371
+				} else {
372
+									$infos_tables[$t][$i] = array_merge_recursive(isset($infos_tables[$t][$i])?$infos_tables[$t][$i]:array(),$all[$i]);
366 373
 				}
367
-				else
368
-					$infos_tables[$t][$i] = array_merge_recursive(isset($infos_tables[$t][$i])?$infos_tables[$t][$i]:array(),$all[$i]);
369 374
 		}
370 375
 
371 376
 		// completer les tables principales et auxiliaires
@@ -379,21 +384,23 @@  discard block
 block discarded – undo
379 384
 			// l'ajouter au tableau
380 385
 			$GLOBALS[$principale_ou_auxiliaire][$table] = array();
381 386
 			if (isset($infos['field']) AND isset($infos['key'])){
382
-				foreach(array('field','key','join') as $k)
383
-					if (isset($infos_tables[$table][$k]))
387
+				foreach(array('field','key','join') as $k) {
388
+									if (isset($infos_tables[$table][$k]))
384 389
 						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k];
385
-			}
386
-			else {
390
+				}
391
+			} else {
387 392
 				// ici on ne renvoie que les declarations, donc RIEN
388 393
 				// pour avoir la vrai description en base, il faut passer par trouver_table
389 394
 				$GLOBALS[$principale_ou_auxiliaire][$table] = array();
390 395
 			}
391 396
 			if (count($mem)){
392
-				foreach(array_keys($mem) as $k)
393
-					if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k]))
397
+				foreach(array_keys($mem) as $k) {
398
+									if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k]))
394 399
 						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge($GLOBALS[$principale_ou_auxiliaire][$table][$k],$mem[$k]);
395
-					else
396
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k];
400
+				}
401
+					else {
402
+											$GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k];
403
+					}
397 404
 			}
398 405
 		}
399 406
 
@@ -409,15 +416,17 @@  discard block
 block discarded – undo
409 416
 		// signature
410 417
 		$md5 = md5(serialize($infos_tables));
411 418
 	}
412
-	if ($table_sql==="::md5")
413
-		return $md5;
419
+	if ($table_sql==="::md5") {
420
+			return $md5;
421
+	}
414 422
 	if ($table_sql AND !isset($infos_tables[$table_sql])){
415 423
 		#$desc = renseigner_table_objet_sql($table_sql,$desc);
416 424
 		$desc = renseigner_table_objet_interfaces($table_sql,$desc);
417 425
 		return $desc;
418 426
 	}
419
-	if ($table_sql)
420
-		return isset($infos_tables[$table_sql])?$infos_tables[$table_sql]:array();
427
+	if ($table_sql) {
428
+			return isset($infos_tables[$table_sql])?$infos_tables[$table_sql]:array();
429
+	}
421 430
 
422 431
 	return $infos_tables;
423 432
 }
@@ -587,20 +596,24 @@  discard block
 block discarded – undo
587 596
 			$primary = explode(',',$primary);
588 597
 			$primary = reset($primary);
589 598
 			$infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary);
599
+		} else {
600
+					$infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql);
590 601
 		}
591
-		else
592
-			$infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql);
593 602
 	}
594
-	if (!isset($infos['type_surnoms']))
595
-		$infos['type_surnoms'] = array();
603
+	if (!isset($infos['type_surnoms'])) {
604
+			$infos['type_surnoms'] = array();
605
+	}
596 606
 
597
-	if (!isset($infos['table_objet']))
598
-		$infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql);
599
-	if (!isset($infos['table_objet_surnoms']))
600
-		$infos['table_objet_surnoms'] = array();
607
+	if (!isset($infos['table_objet'])) {
608
+			$infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql);
609
+	}
610
+	if (!isset($infos['table_objet_surnoms'])) {
611
+			$infos['table_objet_surnoms'] = array();
612
+	}
601 613
 
602
-	if (!isset($infos['principale']))
603
-		$infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql])?'oui':false);
614
+	if (!isset($infos['principale'])) {
615
+			$infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql])?'oui':false);
616
+	}
604 617
 
605 618
 	// normaliser pour pouvoir tester en php $infos['principale']?
606 619
 	// et dans une boucle {principale=oui}
@@ -608,67 +621,95 @@  discard block
 block discarded – undo
608 621
 
609 622
 	// declarer et normaliser pour pouvoir tester en php $infos['editable']?
610 623
 	// et dans une boucle {editable=oui}
611
-	if (!isset($infos['editable'])) $infos['editable'] = 'oui';
624
+	if (!isset($infos['editable'])) {
625
+	    $infos['editable'] = 'oui';
626
+	}
612 627
 	$infos['editable'] = (($infos['editable'] AND $infos['editable']!='non')?'oui':false);
613 628
 
614 629
 	// les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres
615 630
 	// seules les exceptions sont donc a declarer
616
-	if (!isset($infos['page']))
617
-		$infos['page'] = ($infos['principale']?$infos['type']:'');
631
+	if (!isset($infos['page'])) {
632
+			$infos['page'] = ($infos['principale']?$infos['type']:'');
633
+	}
618 634
 
619
-	if (!isset($infos['url_voir']))
620
-		$infos['url_voir'] = $infos['type'];
621
-	if (!isset($infos['url_edit']))
622
-		$infos['url_edit'] = $infos['url_voir'].($infos['editable']?"_edit":'');
623
-	if (!isset($infos['icone_objet']))
624
-		$infos['icone_objet'] = $infos['type'];
635
+	if (!isset($infos['url_voir'])) {
636
+			$infos['url_voir'] = $infos['type'];
637
+	}
638
+	if (!isset($infos['url_edit'])) {
639
+			$infos['url_edit'] = $infos['url_voir'].($infos['editable']?"_edit":'');
640
+	}
641
+	if (!isset($infos['icone_objet'])) {
642
+			$infos['icone_objet'] = $infos['type'];
643
+	}
625 644
 
626 645
 	// chaines de langue
627 646
 	// par defaut : objet:icone_xxx_objet
628
-	if (!isset($infos['texte_retour']))
629
-		$infos['texte_retour'] = 'icone_retour';
630
-	if (!isset($infos['texte_modifier']))
631
-		$infos['texte_modifier'] = $infos['type'].':'.'icone_modifier_'.$infos['type'];
632
-	if (!isset($infos['texte_creer']))
633
-		$infos['texte_creer'] = $infos['type'].':'.'icone_creer_'.$infos['type'];
634
-	if (!isset($infos['texte_creer_associer']))
635
-		$infos['texte_creer_associer'] = $infos['type'].':'.'texte_creer_associer_'.$infos['type'];
636
-	if (!isset($infos['texte_ajouter'])) // Ajouter un X
647
+	if (!isset($infos['texte_retour'])) {
648
+			$infos['texte_retour'] = 'icone_retour';
649
+	}
650
+	if (!isset($infos['texte_modifier'])) {
651
+			$infos['texte_modifier'] = $infos['type'].':'.'icone_modifier_'.$infos['type'];
652
+	}
653
+	if (!isset($infos['texte_creer'])) {
654
+			$infos['texte_creer'] = $infos['type'].':'.'icone_creer_'.$infos['type'];
655
+	}
656
+	if (!isset($infos['texte_creer_associer'])) {
657
+			$infos['texte_creer_associer'] = $infos['type'].':'.'texte_creer_associer_'.$infos['type'];
658
+	}
659
+	if (!isset($infos['texte_ajouter'])) {
660
+	    // Ajouter un X
637 661
 		$infos['texte_ajouter'] = $infos['type'].':'.'texte_ajouter_'.$infos['type'];
638
-	if (!isset($infos['texte_objets']))
639
-		$infos['texte_objets'] = $infos['type'].':'.'titre_'.$infos['table_objet'];
640
-	if (!isset($infos['texte_objet']))
641
-		$infos['texte_objet'] = $infos['type'].':'.'titre_'.$infos['type'];
642
-	if (!isset($infos['texte_logo_objet']))  // objet:titre_logo_objet "Logo de ce X"
662
+	}
663
+	if (!isset($infos['texte_objets'])) {
664
+			$infos['texte_objets'] = $infos['type'].':'.'titre_'.$infos['table_objet'];
665
+	}
666
+	if (!isset($infos['texte_objet'])) {
667
+			$infos['texte_objet'] = $infos['type'].':'.'titre_'.$infos['type'];
668
+	}
669
+	if (!isset($infos['texte_logo_objet'])) {
670
+	    // objet:titre_logo_objet "Logo de ce X"
643 671
 		$infos['texte_logo_objet'] = $infos['type'].':'.'titre_logo_'.$infos['type'];
644
-	if (!isset($infos['texte_langue_objet']))  // objet:texte_langue_objet "Langue de ce X"
672
+	}
673
+	if (!isset($infos['texte_langue_objet'])) {
674
+	    // objet:texte_langue_objet "Langue de ce X"
645 675
 		$infos['texte_langue_objet'] = $infos['type'].':'.'titre_langue_'.$infos['type'];
646
-	if (!isset($infos['texte_definir_comme_traduction_objet']))  // "Ce X est une traduction du X numéro :"
676
+	}
677
+	if (!isset($infos['texte_definir_comme_traduction_objet'])) {
678
+	    // "Ce X est une traduction du X numéro :"
647 679
 		$infos['texte_definir_comme_traduction_objet'] = $infos['type'].':'.'texte_definir_comme_traduction_'.$infos['type'];
680
+	}
648 681
 
649 682
 
650 683
 	// objet:info_aucun_objet
651
-	if (!isset($infos['info_aucun_objet']))
652
-		$infos['info_aucun_objet'] = $infos['type'].':'.'info_aucun_'.$infos['type'];
684
+	if (!isset($infos['info_aucun_objet'])) {
685
+			$infos['info_aucun_objet'] = $infos['type'].':'.'info_aucun_'.$infos['type'];
686
+	}
653 687
 	// objet:info_1_objet
654
-	if (!isset($infos['info_1_objet']))
655
-		$infos['info_1_objet'] = $infos['type'].':'.'info_1_'.$infos['type'];
688
+	if (!isset($infos['info_1_objet'])) {
689
+			$infos['info_1_objet'] = $infos['type'].':'.'info_1_'.$infos['type'];
690
+	}
656 691
 	// objet:info_nb_objets
657
-	if (!isset($infos['info_nb_objets']))
658
-		$infos['info_nb_objets'] = $infos['type'].':'.'info_nb_'.$infos['table_objet'];
692
+	if (!isset($infos['info_nb_objets'])) {
693
+			$infos['info_nb_objets'] = $infos['type'].':'.'info_nb_'.$infos['table_objet'];
694
+	}
659 695
 
660 696
 
661
-	if (!isset($infos['champs_editables']))
662
-		$infos['champs_editables'] = array();
663
-	if (!isset($infos['champs_versionnes']))
664
-		$infos['champs_versionnes'] = array();
665
-	if (!isset($infos['rechercher_champs']))
666
-		$infos['rechercher_champs'] = array();
667
-	if (!isset($infos['rechercher_jointures']))
668
-		$infos['rechercher_jointures'] = array();
697
+	if (!isset($infos['champs_editables'])) {
698
+			$infos['champs_editables'] = array();
699
+	}
700
+	if (!isset($infos['champs_versionnes'])) {
701
+			$infos['champs_versionnes'] = array();
702
+	}
703
+	if (!isset($infos['rechercher_champs'])) {
704
+			$infos['rechercher_champs'] = array();
705
+	}
706
+	if (!isset($infos['rechercher_jointures'])) {
707
+			$infos['rechercher_jointures'] = array();
708
+	}
669 709
 
670
-	if (!isset($infos['modeles']))
671
-		$infos['modeles'] = array($infos['type']);
710
+	if (!isset($infos['modeles'])) {
711
+			$infos['modeles'] = array($infos['type']);
712
+	}
672 713
 
673 714
 	return $infos;
674 715
 }
@@ -688,25 +729,29 @@  discard block
 block discarded – undo
688 729
  */
689 730
 function renseigner_table_objet_interfaces($table_sql,&$infos){
690 731
 	if (!isset($infos['titre'])){
691
-		if (isset($infos['table_objet']) AND isset($GLOBALS['table_titre'][$infos['table_objet']]))
692
-			$infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']];
693
-		else {
732
+		if (isset($infos['table_objet']) AND isset($GLOBALS['table_titre'][$infos['table_objet']])) {
733
+					$infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']];
734
+		} else {
694 735
 			$infos['titre'] = ((isset($infos['field']['titre']))?"titre,":"'' as titre,");
695 736
 			$infos['titre'] .= ((isset($infos['field']['lang']))?"lang":"'' as lang");
696 737
 		}
697 738
 	}
698 739
 	if (!isset($infos['date'])){
699
-		if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']]))
700
-			$infos['date'] = $GLOBALS['table_date'][$infos['table_objet']];
701
-		else
702
-			$infos['date'] = ((isset($infos['field']['date']))?"date":'');
740
+		if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) {
741
+					$infos['date'] = $GLOBALS['table_date'][$infos['table_objet']];
742
+		} else {
743
+					$infos['date'] = ((isset($infos['field']['date']))?"date":'');
744
+		}
745
+	}
746
+	if (!isset($infos['statut'])) {
747
+			$infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : '';
748
+	}
749
+	if (!isset($infos['tables_jointures'])) {
750
+			$infos['tables_jointures'] = array();
751
+	}
752
+	if (isset($GLOBALS['tables_jointures'][$table_sql])) {
753
+			$infos['tables_jointures'] = array_merge($infos['tables_jointures'],$GLOBALS['tables_jointures'][$table_sql]);
703 754
 	}
704
-	if (!isset($infos['statut']))
705
-		$infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : '';
706
-	if (!isset($infos['tables_jointures']))
707
-		$infos['tables_jointures'] = array();
708
-	if (isset($GLOBALS['tables_jointures'][$table_sql]))
709
-		$infos['tables_jointures'] = array_merge($infos['tables_jointures'],$GLOBALS['tables_jointures'][$table_sql]);
710 755
 	return $infos;
711 756
 }
712 757
 
@@ -771,9 +816,10 @@  discard block
 block discarded – undo
771 816
 				//$surnoms[$infos['type']] = $infos['table_objet'];
772 817
 				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet'];
773 818
 				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet'];
774
-				if (is_array($infos['table_objet_surnoms']) AND count($infos['table_objet_surnoms']))
775
-					foreach($infos['table_objet_surnoms'] as $surnom)
819
+				if (is_array($infos['table_objet_surnoms']) AND count($infos['table_objet_surnoms'])) {
820
+									foreach($infos['table_objet_surnoms'] as $surnom)
776 821
 						$surnoms[$surnom] = $infos['table_objet'];
822
+				}
777 823
 			}
778 824
 		}
779 825
 		$md5 = lister_tables_objets_sql('::md5');
@@ -802,9 +848,10 @@  discard block
 block discarded – undo
802 848
 				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type'];
803 849
 				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type'];
804 850
 				// surnoms declares
805
-				if (is_array($infos['type_surnoms']) AND count($infos['type_surnoms']))
806
-					foreach($infos['type_surnoms'] as $surnom)
851
+				if (is_array($infos['type_surnoms']) AND count($infos['type_surnoms'])) {
852
+									foreach($infos['type_surnoms'] as $surnom)
807 853
 						$surnoms[$surnom] = $infos['type'];
854
+				}
808 855
 			}
809 856
 		}
810 857
 		$md5 = lister_tables_objets_sql('::md5');
@@ -816,8 +863,9 @@  discard block
 block discarded – undo
816 863
 	static $tables = array();
817 864
 	if (!isset($tables[$serveur])){
818 865
 		$tables[$serveur] = array();
819
-		if (!function_exists("sql_alltable"))
820
-			include_spip("base/abstract_sql");
866
+		if (!function_exists("sql_alltable")) {
867
+					include_spip("base/abstract_sql");
868
+		}
821 869
 		$ts = sql_alltable(null,$serveur); // toutes les tables "spip_" (ou prefixe perso)
822 870
 		$connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
823 871
 		$spip = $connexion['prefixe'] . '_';
@@ -833,8 +881,9 @@  discard block
 block discarded – undo
833 881
 	static $tables = array();
834 882
 	if (!isset($tables[$serveur])){
835 883
 		$tables[$serveur] = array();
836
-		if (!function_exists("sql_alltable"))
837
-			include_spip("base/abstract_sql");
884
+		if (!function_exists("sql_alltable")) {
885
+					include_spip("base/abstract_sql");
886
+		}
838 887
 		$ts = sql_alltable('%',$serveur); // toutes les tables
839 888
 		foreach ($ts as $t){
840 889
 			$tables[$serveur][$t] = $t;
@@ -862,9 +911,12 @@  discard block
 block discarded – undo
862 911
 function table_objet($type,$serveur='') {
863 912
 	$surnoms = lister_tables_objets_surnoms();
864 913
 	$type = preg_replace(',^spip_|^id_|s$,', '', $type);
865
-	if (!$type) return;
866
-	if (isset($surnoms[$type]))
867
-		return $surnoms[$type];
914
+	if (!$type) {
915
+	    return;
916
+	}
917
+	if (isset($surnoms[$type])) {
918
+			return $surnoms[$type];
919
+	}
868 920
 
869 921
 	if ($serveur!==false){
870 922
 		$t=lister_tables_spip($serveur);
@@ -873,13 +925,14 @@  discard block
 block discarded – undo
873 925
 		if (
874 926
 		  (isset($t[$typetrim]) OR in_array($typetrim,$t))
875 927
 		  AND ($desc = $trouver_table(rtrim($type,'s')."s",$serveur))
876
-		  )
877
-			return $desc['id_table'];
878
-		elseif (
928
+		  ) {
929
+					return $desc['id_table'];
930
+		} elseif (
879 931
 			(isset($t[$type]) OR in_array($type,$t))
880 932
 			AND ($desc = $trouver_table($type,$serveur))
881
-		  )
882
-			return $desc['id_table'];
933
+		  ) {
934
+					return $desc['id_table'];
935
+		}
883 936
 
884 937
 		spip_log( 'table_objet('.$type.') calculee sans verification');
885 938
 	}
@@ -906,22 +959,24 @@  discard block
 block discarded – undo
906 959
 function table_objet_sql($type,$serveur='') {
907 960
 	global $table_des_tables;
908 961
 	$nom = table_objet($type, $serveur);
909
-	if (!isset($table_des_tables['articles'])) // eviter de multiples inclusions
962
+	if (!isset($table_des_tables['articles'])) {
963
+	    // eviter de multiples inclusions
910 964
 		include_spip('public/interfaces');
965
+	}
911 966
 	if (isset($table_des_tables[$nom])) {
912 967
 		$nom = $table_des_tables[$nom];
913 968
 		$nom = "spip_$nom";
914
-	}
915
-	else {
969
+	} else {
916 970
 		$infos_tables = lister_tables_objets_sql();
917
-		if (isset($infos_tables["spip_$nom"]))
918
-			$nom = "spip_$nom";
919
-		elseif($serveur!==false) {
971
+		if (isset($infos_tables["spip_$nom"])) {
972
+					$nom = "spip_$nom";
973
+		} elseif($serveur!==false) {
920 974
 			$t=lister_tables_spip($serveur);
921 975
 			if (isset($t[$nom]) OR in_array($nom,$t)){
922 976
 				$trouver_table = charger_fonction('trouver_table', 'base');
923
-				if ($desc = $trouver_table($nom,$serveur))
924
-					return $desc['table_sql'];
977
+				if ($desc = $trouver_table($nom,$serveur)) {
978
+									return $desc['table_sql'];
979
+				}
925 980
 			}
926 981
 		}
927 982
 	}
@@ -947,19 +1002,24 @@  discard block
 block discarded – undo
947 1002
 function id_table_objet($type,$serveur='') {
948 1003
 	static $trouver_table = null;
949 1004
 	$type = objet_type($type,$serveur);
950
-	if (!$type) return;
1005
+	if (!$type) {
1006
+	    return;
1007
+	}
951 1008
 	$t = table_objet($type);
952
-	if (!$trouver_table)
953
-		$trouver_table = charger_fonction('trouver_table', 'base');
1009
+	if (!$trouver_table) {
1010
+			$trouver_table = charger_fonction('trouver_table', 'base');
1011
+	}
954 1012
 
955 1013
 	$ts=lister_tables_spip($serveur);
956 1014
 	if (in_array($t,$ts)
957 1015
 	  OR in_array($t,lister_toutes_tables($serveur))){
958 1016
 		$desc = $trouver_table($t,$serveur);
959
-		if (isset($desc['key']['PRIMARY KEY']))
960
-			return $desc['key']['PRIMARY KEY'];
961
-		if (!$desc OR isset($desc['field']["id_$type"]))
962
-			return "id_$type";
1017
+		if (isset($desc['key']['PRIMARY KEY'])) {
1018
+					return $desc['key']['PRIMARY KEY'];
1019
+		}
1020
+		if (!$desc OR isset($desc['field']["id_$type"])) {
1021
+					return "id_$type";
1022
+		}
963 1023
 		// sinon renvoyer le premier champ de la table...
964 1024
 		$keys = array_keys($desc['field']);
965 1025
 		return array_shift($keys);
@@ -983,7 +1043,9 @@  discard block
 block discarded – undo
983 1043
  *     Type de l'objet
984 1044
 **/
985 1045
 function objet_type($table_objet, $serveur=''){
986
-	if (!$table_objet) return;
1046
+	if (!$table_objet) {
1047
+	    return;
1048
+	}
987 1049
 	$surnoms = lister_types_surnoms();
988 1050
 
989 1051
 	// scenario de base
@@ -991,8 +1053,9 @@  discard block
 block discarded – undo
991 1053
 	// et la marque du pluriel
992 1054
 	// on accepte id_xx en entree aussi
993 1055
 	$type = preg_replace(',^spip_|^id_|s$,', '', $table_objet);
994
-	if (isset($surnoms[$type]))
995
-		return $surnoms[$type];
1056
+	if (isset($surnoms[$type])) {
1057
+			return $surnoms[$type];
1058
+	}
996 1059
 
997 1060
 	// securite : eliminer les caracteres non \w
998 1061
 	$type = preg_replace(',[^\w-],','',$type);
@@ -1001,12 +1064,14 @@  discard block
 block discarded – undo
1001 1064
 	// oui si table_objet ressemblait deja a un type
1002 1065
 	if ( $type==$table_objet
1003 1066
 		OR (table_objet($type,$serveur)==$table_objet)
1004
-	  OR (table_objet_sql($type,$serveur)==$table_objet))
1005
-	  return $type;
1067
+	  OR (table_objet_sql($type,$serveur)==$table_objet)) {
1068
+		  return $type;
1069
+	}
1006 1070
 
1007 1071
 	// si on ne veut pas chercher en base
1008
-	if ($serveur===false)
1009
-		return $type;
1072
+	if ($serveur===false) {
1073
+			return $type;
1074
+	}
1010 1075
 
1011 1076
 	// sinon on passe par la cle primaire id_xx pour trouver le type
1012 1077
 	// car le s a la fin est incertain
@@ -1016,13 +1081,16 @@  discard block
 block discarded – undo
1016 1081
 	// dans le pipeline declarer_tables_objets_surnoms
1017 1082
 	$trouver_table = charger_fonction('trouver_table', 'base');
1018 1083
 	$ts=lister_tables_spip($serveur);
1019
-	if (in_array($table_objet,$ts))
1020
-		$desc = $trouver_table($table_objet);
1021
-	if (!$desc AND in_array($table_objet=table_objet($type,$serveur),$ts))
1022
-		$desc = $trouver_table($table_objet,$serveur);
1084
+	if (in_array($table_objet,$ts)) {
1085
+			$desc = $trouver_table($table_objet);
1086
+	}
1087
+	if (!$desc AND in_array($table_objet=table_objet($type,$serveur),$ts)) {
1088
+			$desc = $trouver_table($table_objet,$serveur);
1089
+	}
1023 1090
 	// si le type est declare : bingo !
1024
-	if ($desc AND isset($desc['type']))
1025
-			return $desc['type'];
1091
+	if ($desc AND isset($desc['type'])) {
1092
+				return $desc['type'];
1093
+	}
1026 1094
 
1027 1095
 	// on a fait ce qu'on a pu
1028 1096
 	return $type;
@@ -1043,8 +1111,9 @@  discard block
 block discarded – undo
1043 1111
 function objet_test_si_publie($objet,$id_objet, $serveur=''){
1044 1112
 	// voir si une fonction est definie pour faire le boulot
1045 1113
 	// elle a la priorite dans ce cas
1046
-	if ($f = charger_fonction($objet."_test_si_publie","base",true))
1047
-		return $f($objet,$id_objet, $serveur);
1114
+	if ($f = charger_fonction($objet."_test_si_publie","base",true)) {
1115
+			return $f($objet,$id_objet, $serveur);
1116
+	}
1048 1117
 
1049 1118
 	// sinon on se fie a la declaration de l'objet si presente
1050 1119
 	$id_table = $table_objet = table_objet($objet);
@@ -1067,8 +1136,9 @@  discard block
 block discarded – undo
1067 1136
 		include_spip('public/composer');
1068 1137
 		instituer_boucle($boucle, false, true);
1069 1138
 		$res = calculer_select($boucle->select,$boucle->from,$boucle->from_type,$boucle->where,$boucle->join,$boucle->group,$boucle->order,$boucle->limit,$boucle->having,$table_objet,$id_table,$serveur);
1070
-		if (sql_fetch($res))
1071
-			return true;
1139
+		if (sql_fetch($res)) {
1140
+					return true;
1141
+		}
1072 1142
 		return false;
1073 1143
 	}
1074 1144
 
Please login to merge, or discard this patch.