Completed
Push — master ( 806d95...65f8ba )
by cam
04:19
created
ecrire/xml/valider.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -319,7 +319,7 @@
 block discarded – undo
319 319
 	/**
320 320
 	 * Constructeur
321 321
 	 *
322
-	 * @param array $process ?
322
+	 * @param boolean $process ?
323 323
 	 **/
324 324
 	public function __construct($process = array()) {
325 325
 		if (is_array($process)) {
Please login to merge, or discard this patch.
Indentation   +331 added lines, -331 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 /**
@@ -23,333 +23,333 @@  discard block
 block discarded – undo
23 23
  **/
24 24
 class ValidateurXML {
25 25
 
26
-	// http://code.spip.net/@validerElement
27
-	public function validerElement($phraseur, $name, $attrs) {
28
-		if (!($p = isset($this->dtc->elements[$name]))) {
29
-			if ($p = strpos($name, ':')) {
30
-				$name = substr($name, $p + 1);
31
-				$p = isset($this->dtc->elements[$name]);
32
-			}
33
-			if (!$p) {
34
-				coordonnees_erreur($this, " <b>$name</b>&nbsp;: "
35
-					. _T('zxml_inconnu_balise'));
36
-
37
-				return;
38
-			}
39
-		}
40
-		// controler les filles illegitimes, ca suffit 
41
-		$depth = $this->depth;
42
-		$ouvrant = $this->ouvrant;
43
-		#spip_log("trouve $name apres " . $ouvrant[$depth]);
44
-		if (isset($ouvrant[$depth])) {
45
-			if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) {
46
-				$pere = $r[1];
47
-				#spip_log("pere $pere");
48
-				if (isset($this->dtc->elements[$pere])) {
49
-					$fils = $this->dtc->elements[$pere];
50
-					#spip_log("rejeton $name fils " . @join(',',$fils));
51
-					if (!($p = @in_array($name, $fils))) {
52
-						if ($p = strpos($name, ':')) {
53
-							$p = substr($name, $p + 1);
54
-							$p = @in_array($p, $fils);
55
-						}
56
-					}
57
-					if (!$p) {
58
-						$bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]);
59
-						coordonnees_erreur($this, " <b>$name</b> "
60
-							. _T('zxml_non_fils')
61
-							. ' <b>'
62
-							. $pere
63
-							. '</b>'
64
-							. (!$bons_peres ? ''
65
-								: ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>')));
66
-					} elseif ($this->dtc->regles[$pere][0] == '/') {
67
-						$frat = substr($depth, 2);
68
-						if (!isset($this->fratrie[$frat])) {
69
-							$this->fratrie[$frat] = '';
70
-						}
71
-						$this->fratrie[$frat] .= "$name ";
72
-					}
73
-				}
74
-			}
75
-		}
76
-		// Init de la suite des balises a memoriser si regle difficile
77
-		if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') {
78
-			$this->fratrie[$depth] = '';
79
-		}
80
-		if (isset($this->dtc->attributs[$name])) {
81
-			foreach ($this->dtc->attributs[$name] as $n => $v) {
82
-				if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) {
83
-					coordonnees_erreur($this, " <b>$n</b>"
84
-						. '&nbsp;:&nbsp;'
85
-						. _T('zxml_obligatoire_attribut')
86
-						. " <b>$name</b>");
87
-				}
88
-			}
89
-		}
90
-	}
91
-
92
-	// http://code.spip.net/@validerAttribut
93
-	public function validerAttribut($phraseur, $name, $val, $bal) {
94
-		// Si la balise est inconnue, eviter d'insister
95
-		if (!isset($this->dtc->attributs[$bal])) {
96
-			return;
97
-		}
98
-
99
-		$a = $this->dtc->attributs[$bal];
100
-		if (!isset($a[$name])) {
101
-			$bons = join(', ', array_keys($a));
102
-			if ($bons) {
103
-				$bons = " title=' " .
104
-					_T('zxml_connus_attributs') .
105
-					'&nbsp;: ' .
106
-					$bons .
107
-					"'";
108
-			}
109
-			$bons .= " style='font-weight: bold'";
110
-			coordonnees_erreur($this, " <b>$name</b> "
111
-				. _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de')
112
-				. " <a$bons>$bal</a> ("
113
-				. _T('zxml_survoler')
114
-				. ")");
115
-		} else {
116
-			$type = $a[$name][0];
117
-			if (!preg_match('/^\w+$/', $type)) {
118
-				$this->valider_motif($phraseur, $name, $val, $bal, $type);
119
-			} else {
120
-				if (method_exists($this, $f = 'validerAttribut_' . $type)) {
121
-					$this->$f($phraseur, $name, $val, $bal);
122
-				}
123
-			}
124
-			#		else spip_log("$type type d'attribut inconnu");
125
-		}
126
-	}
127
-
128
-	public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) {
129
-		$this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN);
130
-	}
131
-
132
-	public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) {
133
-		$this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS);
134
-	}
135
-
136
-	// http://code.spip.net/@validerAttribut_ID
137
-	public function validerAttribut_ID($phraseur, $name, $val, $bal) {
138
-		if (isset($this->ids[$val])) {
139
-			list($l, $c) = $this->ids[$val];
140
-			coordonnees_erreur($this, " <p><b>$val</b> "
141
-				. _T('zxml_valeur_attribut')
142
-				. " <b>$name</b> "
143
-				. _T('zxml_de')
144
-				. " <b>$bal</b> "
145
-				. _T('zxml_vu')
146
-				. " (L$l,C$c)");
147
-		} else {
148
-			$this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID);
149
-			$this->ids[$val] = array(xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur));
150
-		}
151
-	}
152
-
153
-	// http://code.spip.net/@validerAttribut_IDREF
154
-	public function validerAttribut_IDREF($phraseur, $name, $val, $bal) {
155
-		$this->idrefs[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur));
156
-	}
157
-
158
-	// http://code.spip.net/@validerAttribut_IDREFS
159
-	public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) {
160
-		$this->idrefss[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur));
161
-	}
162
-
163
-	// http://code.spip.net/@valider_motif
164
-	public function valider_motif($phraseur, $name, $val, $bal, $motif) {
165
-		if (!preg_match($motif, $val)) {
166
-			coordonnees_erreur($this, "<b>$val</b> "
167
-				. _T('zxml_valeur_attribut')
168
-				. " <b>$name</b> "
169
-				. _T('zxml_de')
170
-				. " <b>$bal</b> "
171
-				. _T('zxml_non_conforme')
172
-				. "</p><p>"
173
-				. "<b>" . $motif . "</b>");
174
-		}
175
-	}
176
-
177
-	// http://code.spip.net/@valider_idref
178
-	public function valider_idref($nom, $ligne, $col) {
179
-		if (!isset($this->ids[$nom])) {
180
-			$this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col);
181
-		}
182
-	}
183
-
184
-	// http://code.spip.net/@valider_passe2
185
-	public function valider_passe2() {
186
-		if (!$this->err) {
187
-			foreach ($this->idrefs as $idref) {
188
-				list($nom, $ligne, $col) = $idref;
189
-				$this->valider_idref($nom, $ligne, $col);
190
-			}
191
-			foreach ($this->idrefss as $idref) {
192
-				list($noms, $ligne, $col) = $idref;
193
-				foreach (preg_split('/\s+/', $noms) as $nom) {
194
-					$this->valider_idref($nom, $ligne, $col);
195
-				}
196
-			}
197
-		}
198
-	}
199
-
200
-	// http://code.spip.net/@debutElement
201
-	public function debutElement($phraseur, $name, $attrs) {
202
-		if ($this->dtc->elements) {
203
-			$this->validerElement($phraseur, $name, $attrs);
204
-		}
205
-
206
-		if ($f = $this->process['debut']) {
207
-			$f($this, $name, $attrs);
208
-		}
209
-		$depth = $this->depth;
210
-		$this->debuts[$depth] = strlen($this->res);
211
-		foreach ($attrs as $k => $v) {
212
-			$this->validerAttribut($phraseur, $k, $v, $name);
213
-		}
214
-	}
215
-
216
-	// http://code.spip.net/@finElement
217
-	public function finElement($phraseur, $name) {
218
-		$depth = $this->depth;
219
-		$contenu = $this->contenu;
220
-
221
-		$n = strlen($this->res);
222
-		$c = strlen(trim($contenu[$depth]));
223
-		$k = $this->debuts[$depth];
224
-
225
-		$regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false;
226
-		$vide = ($regle == 'EMPTY');
227
-		// controler que les balises devant etre vides le sont 
228
-		if ($vide) {
229
-			if ($n <> ($k + $c)) {
230
-				coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise'));
231
-			}
232
-			// pour les regles PCDATA ou iteration de disjonction, tout est fait
233
-		} elseif ($regle and ($regle != '*')) {
234
-			if ($regle == '+') {
235
-				// iteration de disjonction non vide: 1 balise au -
236
-				if ($n == $k) {
237
-					coordonnees_erreur($this, "<p>\n<b>$name</b> "
238
-						. _T('zxml_vide_balise'));
239
-				}
240
-			} else {
241
-				$f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null;
242
-				if (is_null($f) or !preg_match($regle, $f)) {
243
-					coordonnees_erreur($this,
244
-						" <p>\n<b>$name</b> "
245
-						. _T('zxml_succession_fils_incorrecte')
246
-						. '&nbsp;: <b>'
247
-						. $f
248
-						. '</b>');
249
-				}
250
-			}
251
-
252
-		}
253
-		if ($f = $this->process['fin']) {
254
-			$f($this, $name, $vide);
255
-		}
256
-	}
257
-
258
-	// http://code.spip.net/@textElement
259
-	public function textElement($phraseur, $data) {
260
-		if (trim($data)) {
261
-			$d = $this->depth;
262
-			$d = $this->ouvrant[$d];
263
-			preg_match('/^\s*(\S+)/', $d, $m);
264
-			if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) {
265
-				coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> "
266
-					. _T('zxml_nonvide_balise') // message a affiner
267
-				);
268
-			}
269
-		}
270
-		if ($f = $this->process['text']) {
271
-			$f($this, $data);
272
-		}
273
-	}
274
-
275
-	public function piElement($phraseur, $target, $data) {
276
-		if ($f = $this->process['pi']) {
277
-			$f($this, $target, $data);
278
-		}
279
-	}
280
-
281
-	// Denonciation des entitees XML inconnues
282
-	// Pour contourner le bug de conception de SAX qui ne signale pas si elles
283
-	// sont dans un attribut, les  entites les plus frequentes ont ete
284
-	// transcodees au prealable  (sauf & < > " que SAX traite correctement).
285
-	// On ne les verra donc pas passer a cette etape, contrairement a ce que 
286
-	// le source de la page laisse legitimement supposer. 
287
-
288
-	// http://code.spip.net/@defautElement
289
-	public function defaultElement($phraseur, $data) {
290
-		if (!preg_match('/^<!--/', $data)
291
-			and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER))
292
-		) {
293
-			foreach ($r as $m) {
294
-				list($t, $e) = $m;
295
-				if (!isset($this->dtc->entites[$e])) {
296
-					coordonnees_erreur($this, " <b>$e</b> "
297
-						. _T('zxml_inconnu_entite')
298
-						. ' '
299
-					);
300
-				}
301
-			}
302
-		}
303
-		if (isset($this->process['default']) and ($f = $this->process['default'])) {
304
-			$f($this, $data);
305
-		}
306
-	}
307
-
308
-	// http://code.spip.net/@phraserTout
309
-	public function phraserTout($phraseur, $data) {
310
-		xml_parsestring($this, $data);
311
-
312
-		if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) {
313
-			$this->err[] = array('DOCTYPE ?', 0, 0);
314
-		} else {
315
-			$this->valider_passe2($this);
316
-		}
317
-	}
318
-
319
-	/**
320
-	 * Constructeur
321
-	 *
322
-	 * @param array $process ?
323
-	 **/
324
-	public function __construct($process = array()) {
325
-		if (is_array($process)) {
326
-			$this->process = $process;
327
-		}
328
-	}
329
-
330
-	public $ids = array();
331
-	public $idrefs = array();
332
-	public $idrefss = array();
333
-	public $debuts = array();
334
-	public $fratrie = array();
335
-
336
-	public $dtc = null;
337
-	public $sax = null;
338
-	public $depth = "";
339
-	public $entete = '';
340
-	public $page = '';
341
-	public $res = "";
342
-	public $err = array();
343
-	public $contenu = array();
344
-	public $ouvrant = array();
345
-	public $reperes = array();
346
-	public $process = array(
347
-		'debut' => 'xml_debutElement',
348
-		'fin' => 'xml_finElement',
349
-		'text' => 'xml_textElement',
350
-		'pi' => 'xml_piElement',
351
-		'default' => 'xml_defaultElement'
352
-	);
26
+    // http://code.spip.net/@validerElement
27
+    public function validerElement($phraseur, $name, $attrs) {
28
+        if (!($p = isset($this->dtc->elements[$name]))) {
29
+            if ($p = strpos($name, ':')) {
30
+                $name = substr($name, $p + 1);
31
+                $p = isset($this->dtc->elements[$name]);
32
+            }
33
+            if (!$p) {
34
+                coordonnees_erreur($this, " <b>$name</b>&nbsp;: "
35
+                    . _T('zxml_inconnu_balise'));
36
+
37
+                return;
38
+            }
39
+        }
40
+        // controler les filles illegitimes, ca suffit 
41
+        $depth = $this->depth;
42
+        $ouvrant = $this->ouvrant;
43
+        #spip_log("trouve $name apres " . $ouvrant[$depth]);
44
+        if (isset($ouvrant[$depth])) {
45
+            if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) {
46
+                $pere = $r[1];
47
+                #spip_log("pere $pere");
48
+                if (isset($this->dtc->elements[$pere])) {
49
+                    $fils = $this->dtc->elements[$pere];
50
+                    #spip_log("rejeton $name fils " . @join(',',$fils));
51
+                    if (!($p = @in_array($name, $fils))) {
52
+                        if ($p = strpos($name, ':')) {
53
+                            $p = substr($name, $p + 1);
54
+                            $p = @in_array($p, $fils);
55
+                        }
56
+                    }
57
+                    if (!$p) {
58
+                        $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]);
59
+                        coordonnees_erreur($this, " <b>$name</b> "
60
+                            . _T('zxml_non_fils')
61
+                            . ' <b>'
62
+                            . $pere
63
+                            . '</b>'
64
+                            . (!$bons_peres ? ''
65
+                                : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>')));
66
+                    } elseif ($this->dtc->regles[$pere][0] == '/') {
67
+                        $frat = substr($depth, 2);
68
+                        if (!isset($this->fratrie[$frat])) {
69
+                            $this->fratrie[$frat] = '';
70
+                        }
71
+                        $this->fratrie[$frat] .= "$name ";
72
+                    }
73
+                }
74
+            }
75
+        }
76
+        // Init de la suite des balises a memoriser si regle difficile
77
+        if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') {
78
+            $this->fratrie[$depth] = '';
79
+        }
80
+        if (isset($this->dtc->attributs[$name])) {
81
+            foreach ($this->dtc->attributs[$name] as $n => $v) {
82
+                if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) {
83
+                    coordonnees_erreur($this, " <b>$n</b>"
84
+                        . '&nbsp;:&nbsp;'
85
+                        . _T('zxml_obligatoire_attribut')
86
+                        . " <b>$name</b>");
87
+                }
88
+            }
89
+        }
90
+    }
91
+
92
+    // http://code.spip.net/@validerAttribut
93
+    public function validerAttribut($phraseur, $name, $val, $bal) {
94
+        // Si la balise est inconnue, eviter d'insister
95
+        if (!isset($this->dtc->attributs[$bal])) {
96
+            return;
97
+        }
98
+
99
+        $a = $this->dtc->attributs[$bal];
100
+        if (!isset($a[$name])) {
101
+            $bons = join(', ', array_keys($a));
102
+            if ($bons) {
103
+                $bons = " title=' " .
104
+                    _T('zxml_connus_attributs') .
105
+                    '&nbsp;: ' .
106
+                    $bons .
107
+                    "'";
108
+            }
109
+            $bons .= " style='font-weight: bold'";
110
+            coordonnees_erreur($this, " <b>$name</b> "
111
+                . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de')
112
+                . " <a$bons>$bal</a> ("
113
+                . _T('zxml_survoler')
114
+                . ")");
115
+        } else {
116
+            $type = $a[$name][0];
117
+            if (!preg_match('/^\w+$/', $type)) {
118
+                $this->valider_motif($phraseur, $name, $val, $bal, $type);
119
+            } else {
120
+                if (method_exists($this, $f = 'validerAttribut_' . $type)) {
121
+                    $this->$f($phraseur, $name, $val, $bal);
122
+                }
123
+            }
124
+            #		else spip_log("$type type d'attribut inconnu");
125
+        }
126
+    }
127
+
128
+    public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) {
129
+        $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN);
130
+    }
131
+
132
+    public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) {
133
+        $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS);
134
+    }
135
+
136
+    // http://code.spip.net/@validerAttribut_ID
137
+    public function validerAttribut_ID($phraseur, $name, $val, $bal) {
138
+        if (isset($this->ids[$val])) {
139
+            list($l, $c) = $this->ids[$val];
140
+            coordonnees_erreur($this, " <p><b>$val</b> "
141
+                . _T('zxml_valeur_attribut')
142
+                . " <b>$name</b> "
143
+                . _T('zxml_de')
144
+                . " <b>$bal</b> "
145
+                . _T('zxml_vu')
146
+                . " (L$l,C$c)");
147
+        } else {
148
+            $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID);
149
+            $this->ids[$val] = array(xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur));
150
+        }
151
+    }
152
+
153
+    // http://code.spip.net/@validerAttribut_IDREF
154
+    public function validerAttribut_IDREF($phraseur, $name, $val, $bal) {
155
+        $this->idrefs[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur));
156
+    }
157
+
158
+    // http://code.spip.net/@validerAttribut_IDREFS
159
+    public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) {
160
+        $this->idrefss[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur));
161
+    }
162
+
163
+    // http://code.spip.net/@valider_motif
164
+    public function valider_motif($phraseur, $name, $val, $bal, $motif) {
165
+        if (!preg_match($motif, $val)) {
166
+            coordonnees_erreur($this, "<b>$val</b> "
167
+                . _T('zxml_valeur_attribut')
168
+                . " <b>$name</b> "
169
+                . _T('zxml_de')
170
+                . " <b>$bal</b> "
171
+                . _T('zxml_non_conforme')
172
+                . "</p><p>"
173
+                . "<b>" . $motif . "</b>");
174
+        }
175
+    }
176
+
177
+    // http://code.spip.net/@valider_idref
178
+    public function valider_idref($nom, $ligne, $col) {
179
+        if (!isset($this->ids[$nom])) {
180
+            $this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col);
181
+        }
182
+    }
183
+
184
+    // http://code.spip.net/@valider_passe2
185
+    public function valider_passe2() {
186
+        if (!$this->err) {
187
+            foreach ($this->idrefs as $idref) {
188
+                list($nom, $ligne, $col) = $idref;
189
+                $this->valider_idref($nom, $ligne, $col);
190
+            }
191
+            foreach ($this->idrefss as $idref) {
192
+                list($noms, $ligne, $col) = $idref;
193
+                foreach (preg_split('/\s+/', $noms) as $nom) {
194
+                    $this->valider_idref($nom, $ligne, $col);
195
+                }
196
+            }
197
+        }
198
+    }
199
+
200
+    // http://code.spip.net/@debutElement
201
+    public function debutElement($phraseur, $name, $attrs) {
202
+        if ($this->dtc->elements) {
203
+            $this->validerElement($phraseur, $name, $attrs);
204
+        }
205
+
206
+        if ($f = $this->process['debut']) {
207
+            $f($this, $name, $attrs);
208
+        }
209
+        $depth = $this->depth;
210
+        $this->debuts[$depth] = strlen($this->res);
211
+        foreach ($attrs as $k => $v) {
212
+            $this->validerAttribut($phraseur, $k, $v, $name);
213
+        }
214
+    }
215
+
216
+    // http://code.spip.net/@finElement
217
+    public function finElement($phraseur, $name) {
218
+        $depth = $this->depth;
219
+        $contenu = $this->contenu;
220
+
221
+        $n = strlen($this->res);
222
+        $c = strlen(trim($contenu[$depth]));
223
+        $k = $this->debuts[$depth];
224
+
225
+        $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false;
226
+        $vide = ($regle == 'EMPTY');
227
+        // controler que les balises devant etre vides le sont 
228
+        if ($vide) {
229
+            if ($n <> ($k + $c)) {
230
+                coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise'));
231
+            }
232
+            // pour les regles PCDATA ou iteration de disjonction, tout est fait
233
+        } elseif ($regle and ($regle != '*')) {
234
+            if ($regle == '+') {
235
+                // iteration de disjonction non vide: 1 balise au -
236
+                if ($n == $k) {
237
+                    coordonnees_erreur($this, "<p>\n<b>$name</b> "
238
+                        . _T('zxml_vide_balise'));
239
+                }
240
+            } else {
241
+                $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null;
242
+                if (is_null($f) or !preg_match($regle, $f)) {
243
+                    coordonnees_erreur($this,
244
+                        " <p>\n<b>$name</b> "
245
+                        . _T('zxml_succession_fils_incorrecte')
246
+                        . '&nbsp;: <b>'
247
+                        . $f
248
+                        . '</b>');
249
+                }
250
+            }
251
+
252
+        }
253
+        if ($f = $this->process['fin']) {
254
+            $f($this, $name, $vide);
255
+        }
256
+    }
257
+
258
+    // http://code.spip.net/@textElement
259
+    public function textElement($phraseur, $data) {
260
+        if (trim($data)) {
261
+            $d = $this->depth;
262
+            $d = $this->ouvrant[$d];
263
+            preg_match('/^\s*(\S+)/', $d, $m);
264
+            if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) {
265
+                coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> "
266
+                    . _T('zxml_nonvide_balise') // message a affiner
267
+                );
268
+            }
269
+        }
270
+        if ($f = $this->process['text']) {
271
+            $f($this, $data);
272
+        }
273
+    }
274
+
275
+    public function piElement($phraseur, $target, $data) {
276
+        if ($f = $this->process['pi']) {
277
+            $f($this, $target, $data);
278
+        }
279
+    }
280
+
281
+    // Denonciation des entitees XML inconnues
282
+    // Pour contourner le bug de conception de SAX qui ne signale pas si elles
283
+    // sont dans un attribut, les  entites les plus frequentes ont ete
284
+    // transcodees au prealable  (sauf & < > " que SAX traite correctement).
285
+    // On ne les verra donc pas passer a cette etape, contrairement a ce que 
286
+    // le source de la page laisse legitimement supposer. 
287
+
288
+    // http://code.spip.net/@defautElement
289
+    public function defaultElement($phraseur, $data) {
290
+        if (!preg_match('/^<!--/', $data)
291
+            and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER))
292
+        ) {
293
+            foreach ($r as $m) {
294
+                list($t, $e) = $m;
295
+                if (!isset($this->dtc->entites[$e])) {
296
+                    coordonnees_erreur($this, " <b>$e</b> "
297
+                        . _T('zxml_inconnu_entite')
298
+                        . ' '
299
+                    );
300
+                }
301
+            }
302
+        }
303
+        if (isset($this->process['default']) and ($f = $this->process['default'])) {
304
+            $f($this, $data);
305
+        }
306
+    }
307
+
308
+    // http://code.spip.net/@phraserTout
309
+    public function phraserTout($phraseur, $data) {
310
+        xml_parsestring($this, $data);
311
+
312
+        if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) {
313
+            $this->err[] = array('DOCTYPE ?', 0, 0);
314
+        } else {
315
+            $this->valider_passe2($this);
316
+        }
317
+    }
318
+
319
+    /**
320
+     * Constructeur
321
+     *
322
+     * @param array $process ?
323
+     **/
324
+    public function __construct($process = array()) {
325
+        if (is_array($process)) {
326
+            $this->process = $process;
327
+        }
328
+    }
329
+
330
+    public $ids = array();
331
+    public $idrefs = array();
332
+    public $idrefss = array();
333
+    public $debuts = array();
334
+    public $fratrie = array();
335
+
336
+    public $dtc = null;
337
+    public $sax = null;
338
+    public $depth = "";
339
+    public $entete = '';
340
+    public $page = '';
341
+    public $res = "";
342
+    public $err = array();
343
+    public $contenu = array();
344
+    public $ouvrant = array();
345
+    public $reperes = array();
346
+    public $process = array(
347
+        'debut' => 'xml_debutElement',
348
+        'fin' => 'xml_finElement',
349
+        'text' => 'xml_textElement',
350
+        'pi' => 'xml_piElement',
351
+        'default' => 'xml_defaultElement'
352
+    );
353 353
 }
354 354
 
355 355
 
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
  *
360 360
  **/
361 361
 function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) {
362
-	$f = new ValidateurXML($process);
363
-	$sax = charger_fonction('sax', 'xml');
362
+    $f = new ValidateurXML($process);
363
+    $sax = charger_fonction('sax', 'xml');
364 364
 
365
-	return $sax($page, $apply, $f, $doctype, $charset);
365
+    return $sax($page, $apply, $f, $doctype, $charset);
366 366
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 							. $pere
63 63
 							. '</b>'
64 64
 							. (!$bons_peres ? ''
65
-								: ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>')));
65
+								: ('<p style="font-size: 80%"> '._T('zxml_mais_de').' <b>'.$bons_peres.'</b></p>')));
66 66
 					} elseif ($this->dtc->regles[$pere][0] == '/') {
67 67
 						$frat = substr($depth, 2);
68 68
 						if (!isset($this->fratrie[$frat])) {
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 		if (!isset($a[$name])) {
101 101
 			$bons = join(', ', array_keys($a));
102 102
 			if ($bons) {
103
-				$bons = " title=' " .
104
-					_T('zxml_connus_attributs') .
105
-					'&nbsp;: ' .
106
-					$bons .
103
+				$bons = " title=' ".
104
+					_T('zxml_connus_attributs').
105
+					'&nbsp;: '.
106
+					$bons.
107 107
 					"'";
108 108
 			}
109 109
 			$bons .= " style='font-weight: bold'";
110 110
 			coordonnees_erreur($this, " <b>$name</b> "
111
-				. _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de')
111
+				. _T('zxml_inconnu_attribut').' '._T('zxml_de')
112 112
 				. " <a$bons>$bal</a> ("
113 113
 				. _T('zxml_survoler')
114 114
 				. ")");
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 			if (!preg_match('/^\w+$/', $type)) {
118 118
 				$this->valider_motif($phraseur, $name, $val, $bal, $type);
119 119
 			} else {
120
-				if (method_exists($this, $f = 'validerAttribut_' . $type)) {
120
+				if (method_exists($this, $f = 'validerAttribut_'.$type)) {
121 121
 					$this->$f($phraseur, $name, $val, $bal);
122 122
 				}
123 123
 			}
@@ -170,14 +170,14 @@  discard block
 block discarded – undo
170 170
 				. " <b>$bal</b> "
171 171
 				. _T('zxml_non_conforme')
172 172
 				. "</p><p>"
173
-				. "<b>" . $motif . "</b>");
173
+				. "<b>".$motif."</b>");
174 174
 		}
175 175
 	}
176 176
 
177 177
 	// http://code.spip.net/@valider_idref
178 178
 	public function valider_idref($nom, $ligne, $col) {
179 179
 		if (!isset($this->ids[$nom])) {
180
-			$this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col);
180
+			$this->err[] = array(" <p><b>$nom</b> "._T('zxml_inconnu_id'), $ligne, $col);
181 181
 		}
182 182
 	}
183 183
 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		// controler que les balises devant etre vides le sont 
228 228
 		if ($vide) {
229 229
 			if ($n <> ($k + $c)) {
230
-				coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise'));
230
+				coordonnees_erreur($this, " <p><b>$name</b> "._T('zxml_nonvide_balise'));
231 231
 			}
232 232
 			// pour les regles PCDATA ou iteration de disjonction, tout est fait
233 233
 		} elseif ($regle and ($regle != '*')) {
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 			$d = $this->ouvrant[$d];
263 263
 			preg_match('/^\s*(\S+)/', $d, $m);
264 264
 			if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) {
265
-				coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> "
265
+				coordonnees_erreur($this, " <p><b>".$m[1]."</b> "
266 266
 					. _T('zxml_nonvide_balise') // message a affiner
267 267
 				);
268 268
 			}
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	public function phraserTout($phraseur, $data) {
310 310
 		xml_parsestring($this, $data);
311 311
 
312
-		if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) {
312
+		if (!$this->dtc or preg_match(',^'._MESSAGE_DOCTYPE.',', $data)) {
313 313
 			$this->err[] = array('DOCTYPE ?', 0, 0);
314 314
 		} else {
315 315
 			$this->valider_passe2($this);
Please login to merge, or discard this patch.
ecrire/action/editer_article.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
  * @param int $id_rubrique
161 161
  *     Identifiant de la rubrique parente
162 162
  * @param array|null $set
163
- * @return int
163
+ * @return boolean|string
164 164
  *     Identifiant du nouvel article
165 165
  *
166 166
  */
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
  *
534 534
  * @param int $id_rubrique
535 535
  *     Identifiant de la rubrique
536
- * @return int
536
+ * @return boolean|string
537 537
  *     Identifiant du nouvel article
538 538
  */
539 539
 function insert_article($id_rubrique) {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	);
107 107
 
108 108
 	// Si l'article est publie, invalider les caches et demander sa reindexation
109
-	$t = sql_getfetsel("statut", "spip_articles", "id_article=" . intval($id_article));
109
+	$t = sql_getfetsel("statut", "spip_articles", "id_article=".intval($id_article));
110 110
 	$invalideur = $indexation = false;
111 111
 	if ($t == 'publie') {
112 112
 		$invalideur = "id='article/$id_article'";
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	if ($err = objet_modifier_champs('article', $id_article,
117 117
 		array(
118 118
 			'data' => $set,
119
-			'nonvide' => array('titre' => _T('info_nouvel_article') . " " . _T('info_numero_abbreviation') . $id_article),
119
+			'nonvide' => array('titre' => _T('info_nouvel_article')." "._T('info_numero_abbreviation').$id_article),
120 120
 			'invalideur' => $invalideur,
121 121
 			'indexation' => $indexation,
122 122
 			'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 			if (autoriser('modifier', 'article', $id_article) and $s != 'publie') {
299 299
 				$statut = $champs['statut'] = $s;
300 300
 			} else {
301
-				spip_log("editer_article $id_article refus " . join(' ', $c));
301
+				spip_log("editer_article $id_article refus ".join(' ', $c));
302 302
 			}
303 303
 		}
304 304
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	if (isset($c['id_parent'])
323 323
 		and $id_parent = $c['id_parent']
324 324
 		and $id_parent != $id_rubrique
325
-		and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent)))
325
+		and (sql_fetsel('1', "spip_rubriques", "id_rubrique=".intval($id_parent)))
326 326
 	) {
327 327
 		$champs['id_rubrique'] = $id_parent;
328 328
 
@@ -419,12 +419,12 @@  discard block
 block discarded – undo
419 419
 	//  changer aussi son secteur et sa langue (si heritee)
420 420
 	if (isset($champs['id_rubrique'])) {
421 421
 
422
-		$row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique']));
422
+		$row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=".sql_quote($champs['id_rubrique']));
423 423
 
424 424
 		$langue = $row_rub['lang'];
425 425
 		$champs['id_secteur'] = $row_rub['id_secteur'];
426 426
 		if (sql_fetsel('1', 'spip_articles',
427
-			"id_article=" . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) {
427
+			"id_article=".intval($id_article)." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue))) {
428 428
 			$champs['lang'] = $langue;
429 429
 		}
430 430
 	}
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 		return;
434 434
 	}
435 435
 
436
-	sql_updateq('spip_articles', $champs, "id_article=" . intval($id_article));
436
+	sql_updateq('spip_articles', $champs, "id_article=".intval($id_article));
437 437
 
438 438
 	// Changer le statut des rubriques concernees 
439 439
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 		foreach ($plus as $n => $t) {
455 455
 			$plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", "", $t);
456 456
 		}
457
-		set_request('texte', join('', $plus) . _request('texte'));
457
+		set_request('texte', join('', $plus)._request('texte'));
458 458
 	}
459 459
 }
460 460
 
Please login to merge, or discard this patch.
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -40,36 +40,36 @@  discard block
 block discarded – undo
40 40
  *     Liste (identifiant de l'article, Texte d'erreur éventuel)
41 41
  */
42 42
 function action_editer_article_dist($arg = null) {
43
-	include_spip('inc/autoriser');
44
-	$err = "";
45
-	if (is_null($arg)) {
46
-		$securiser_action = charger_fonction('securiser_action', 'inc');
47
-		$arg = $securiser_action();
48
-	}
49
-
50
-	// si id_article n'est pas un nombre, c'est une creation 
51
-	// mais on verifie qu'on a toutes les donnees qu'il faut.
52
-	if (!$id_article = intval($arg)) {
53
-		$id_parent = _request('id_parent');
54
-		if (!$id_parent) {
55
-			$err = _L("creation interdite d'un article sans rubrique");
56
-		} elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) {
57
-			$err = _T("info_creerdansrubrique_non_autorise");
58
-		} else {
59
-			$id_article = article_inserer($id_parent);
60
-		}
61
-	}
62
-
63
-	// Enregistre l'envoi dans la BD
64
-	if ($id_article > 0) {
65
-		$err = article_modifier($id_article);
66
-	}
67
-
68
-	if ($err) {
69
-		spip_log("echec editeur article: $err", _LOG_ERREUR);
70
-	}
71
-
72
-	return array($id_article, $err);
43
+    include_spip('inc/autoriser');
44
+    $err = "";
45
+    if (is_null($arg)) {
46
+        $securiser_action = charger_fonction('securiser_action', 'inc');
47
+        $arg = $securiser_action();
48
+    }
49
+
50
+    // si id_article n'est pas un nombre, c'est une creation 
51
+    // mais on verifie qu'on a toutes les donnees qu'il faut.
52
+    if (!$id_article = intval($arg)) {
53
+        $id_parent = _request('id_parent');
54
+        if (!$id_parent) {
55
+            $err = _L("creation interdite d'un article sans rubrique");
56
+        } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) {
57
+            $err = _T("info_creerdansrubrique_non_autorise");
58
+        } else {
59
+            $id_article = article_inserer($id_parent);
60
+        }
61
+    }
62
+
63
+    // Enregistre l'envoi dans la BD
64
+    if ($id_article > 0) {
65
+        $err = article_modifier($id_article);
66
+    }
67
+
68
+    if ($err) {
69
+        spip_log("echec editeur article: $err", _LOG_ERREUR);
70
+    }
71
+
72
+    return array($id_article, $err);
73 73
 }
74 74
 
75 75
 /**
@@ -91,46 +91,46 @@  discard block
 block discarded – undo
91 91
  */
92 92
 function article_modifier($id_article, $set = null) {
93 93
 
94
-	// unifier $texte en cas de texte trop long
95
-	trop_longs_articles();
96
-
97
-	include_spip('inc/modifier');
98
-	include_spip('inc/filtres');
99
-	$c = collecter_requests(
100
-	// white list
101
-		objet_info('article', 'champs_editables'),
102
-		// black list
103
-		array('date', 'statut', 'id_parent'),
104
-		// donnees eventuellement fournies
105
-		$set
106
-	);
107
-
108
-	// Si l'article est publie, invalider les caches et demander sa reindexation
109
-	$t = sql_getfetsel("statut", "spip_articles", "id_article=" . intval($id_article));
110
-	$invalideur = $indexation = false;
111
-	if ($t == 'publie') {
112
-		$invalideur = "id='article/$id_article'";
113
-		$indexation = true;
114
-	}
115
-
116
-	if ($err = objet_modifier_champs('article', $id_article,
117
-		array(
118
-			'data' => $set,
119
-			'nonvide' => array('titre' => _T('info_nouvel_article') . " " . _T('info_numero_abbreviation') . $id_article),
120
-			'invalideur' => $invalideur,
121
-			'indexation' => $indexation,
122
-			'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
123
-		),
124
-		$c)
125
-	) {
126
-		return $err;
127
-	}
128
-
129
-	// Modification de statut, changement de rubrique ?
130
-	$c = collecter_requests(array('date', 'statut', 'id_parent'), array(), $set);
131
-	$err = article_instituer($id_article, $c);
132
-
133
-	return $err;
94
+    // unifier $texte en cas de texte trop long
95
+    trop_longs_articles();
96
+
97
+    include_spip('inc/modifier');
98
+    include_spip('inc/filtres');
99
+    $c = collecter_requests(
100
+    // white list
101
+        objet_info('article', 'champs_editables'),
102
+        // black list
103
+        array('date', 'statut', 'id_parent'),
104
+        // donnees eventuellement fournies
105
+        $set
106
+    );
107
+
108
+    // Si l'article est publie, invalider les caches et demander sa reindexation
109
+    $t = sql_getfetsel("statut", "spip_articles", "id_article=" . intval($id_article));
110
+    $invalideur = $indexation = false;
111
+    if ($t == 'publie') {
112
+        $invalideur = "id='article/$id_article'";
113
+        $indexation = true;
114
+    }
115
+
116
+    if ($err = objet_modifier_champs('article', $id_article,
117
+        array(
118
+            'data' => $set,
119
+            'nonvide' => array('titre' => _T('info_nouvel_article') . " " . _T('info_numero_abbreviation') . $id_article),
120
+            'invalideur' => $invalideur,
121
+            'indexation' => $indexation,
122
+            'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
123
+        ),
124
+        $c)
125
+    ) {
126
+        return $err;
127
+    }
128
+
129
+    // Modification de statut, changement de rubrique ?
130
+    $c = collecter_requests(array('date', 'statut', 'id_parent'), array(), $set);
131
+    $err = article_instituer($id_article, $c);
132
+
133
+    return $err;
134 134
 }
135 135
 
136 136
 /**
@@ -166,89 +166,89 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function article_inserer($id_rubrique, $set = null) {
168 168
 
169
-	// Si id_rubrique vaut 0 ou n'est pas definie, creer l'article
170
-	// dans la premiere rubrique racine
171
-	if (!$id_rubrique = intval($id_rubrique)) {
172
-		$row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1");
173
-		$id_rubrique = $row['id_rubrique'];
174
-	} else {
175
-		$row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique");
176
-	}
177
-
178
-	// eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue 
179
-	// cas de id_rubrique = -1 par exemple avec plugin "pages"
180
-	$id_secteur = isset($row['id_secteur']) ? $row['id_secteur'] : 0;
181
-	$lang_rub = isset($row['lang']) ? $row['lang'] : '';
182
-
183
-	$lang = "";
184
-	$choisie = 'non';
185
-	// La langue a la creation : si les liens de traduction sont autorises
186
-	// dans les rubriques, on essaie avec la langue de l'auteur,
187
-	// ou a defaut celle de la rubrique
188
-	// Sinon c'est la langue de la rubrique qui est choisie + heritee
189
-	if (!empty($GLOBALS['meta']['multi_objets']) and in_array('spip_articles',
190
-			explode(',', $GLOBALS['meta']['multi_objets']))
191
-	) {
192
-		lang_select($GLOBALS['visiteur_session']['lang']);
193
-		if (in_array($GLOBALS['spip_lang'],
194
-			explode(',', $GLOBALS['meta']['langues_multilingue']))) {
195
-			$lang = $GLOBALS['spip_lang'];
196
-			$choisie = 'oui';
197
-		}
198
-	}
199
-
200
-	if (!$lang) {
201
-		$choisie = 'non';
202
-		$lang = $lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site'];
203
-	}
204
-
205
-	$champs = array(
206
-		'id_rubrique' => $id_rubrique,
207
-		'id_secteur' => $id_secteur,
208
-		'statut' => 'prepa',
209
-		'date' => date('Y-m-d H:i:s'),
210
-		'lang' => $lang,
211
-		'langue_choisie' => $choisie
212
-	);
213
-
214
-	if ($set) {
215
-		$champs = array_merge($champs, $set);
216
-	}
217
-
218
-	// Envoyer aux plugins
219
-	$champs = pipeline('pre_insertion',
220
-		array(
221
-			'args' => array(
222
-				'table' => 'spip_articles',
223
-			),
224
-			'data' => $champs
225
-		)
226
-	);
227
-
228
-	$id_article = sql_insertq("spip_articles", $champs);
229
-
230
-	// controler si le serveur n'a pas renvoye une erreur
231
-	if ($id_article > 0) {
232
-		$id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
233
-			$GLOBALS['visiteur_session']['id_auteur']
234
-			: _request('id_auteur'));
235
-		if ($id_auteur) {
236
-			include_spip('action/editer_auteur');
237
-			auteur_associer($id_auteur, array('article' => $id_article));
238
-		}
239
-	}
240
-
241
-	pipeline('post_insertion',
242
-		array(
243
-			'args' => array(
244
-				'table' => 'spip_articles',
245
-				'id_objet' => $id_article
246
-			),
247
-			'data' => $champs
248
-		)
249
-	);
250
-
251
-	return $id_article;
169
+    // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article
170
+    // dans la premiere rubrique racine
171
+    if (!$id_rubrique = intval($id_rubrique)) {
172
+        $row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1");
173
+        $id_rubrique = $row['id_rubrique'];
174
+    } else {
175
+        $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique");
176
+    }
177
+
178
+    // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue 
179
+    // cas de id_rubrique = -1 par exemple avec plugin "pages"
180
+    $id_secteur = isset($row['id_secteur']) ? $row['id_secteur'] : 0;
181
+    $lang_rub = isset($row['lang']) ? $row['lang'] : '';
182
+
183
+    $lang = "";
184
+    $choisie = 'non';
185
+    // La langue a la creation : si les liens de traduction sont autorises
186
+    // dans les rubriques, on essaie avec la langue de l'auteur,
187
+    // ou a defaut celle de la rubrique
188
+    // Sinon c'est la langue de la rubrique qui est choisie + heritee
189
+    if (!empty($GLOBALS['meta']['multi_objets']) and in_array('spip_articles',
190
+            explode(',', $GLOBALS['meta']['multi_objets']))
191
+    ) {
192
+        lang_select($GLOBALS['visiteur_session']['lang']);
193
+        if (in_array($GLOBALS['spip_lang'],
194
+            explode(',', $GLOBALS['meta']['langues_multilingue']))) {
195
+            $lang = $GLOBALS['spip_lang'];
196
+            $choisie = 'oui';
197
+        }
198
+    }
199
+
200
+    if (!$lang) {
201
+        $choisie = 'non';
202
+        $lang = $lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site'];
203
+    }
204
+
205
+    $champs = array(
206
+        'id_rubrique' => $id_rubrique,
207
+        'id_secteur' => $id_secteur,
208
+        'statut' => 'prepa',
209
+        'date' => date('Y-m-d H:i:s'),
210
+        'lang' => $lang,
211
+        'langue_choisie' => $choisie
212
+    );
213
+
214
+    if ($set) {
215
+        $champs = array_merge($champs, $set);
216
+    }
217
+
218
+    // Envoyer aux plugins
219
+    $champs = pipeline('pre_insertion',
220
+        array(
221
+            'args' => array(
222
+                'table' => 'spip_articles',
223
+            ),
224
+            'data' => $champs
225
+        )
226
+    );
227
+
228
+    $id_article = sql_insertq("spip_articles", $champs);
229
+
230
+    // controler si le serveur n'a pas renvoye une erreur
231
+    if ($id_article > 0) {
232
+        $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
233
+            $GLOBALS['visiteur_session']['id_auteur']
234
+            : _request('id_auteur'));
235
+        if ($id_auteur) {
236
+            include_spip('action/editer_auteur');
237
+            auteur_associer($id_auteur, array('article' => $id_article));
238
+        }
239
+    }
240
+
241
+    pipeline('post_insertion',
242
+        array(
243
+            'args' => array(
244
+                'table' => 'spip_articles',
245
+                'id_objet' => $id_article
246
+            ),
247
+            'data' => $champs
248
+        )
249
+    );
250
+
251
+    return $id_article;
252 252
 }
253 253
 
254 254
 
@@ -276,120 +276,120 @@  discard block
 block discarded – undo
276 276
  */
277 277
 function article_instituer($id_article, $c, $calcul_rub = true) {
278 278
 
279
-	include_spip('inc/autoriser');
280
-	include_spip('inc/rubriques');
281
-	include_spip('inc/modifier');
282
-
283
-	$row = sql_fetsel("statut, date, id_rubrique", "spip_articles", "id_article=$id_article");
284
-	$id_rubrique = $row['id_rubrique'];
285
-	$statut_ancien = $statut = $row['statut'];
286
-	$date_ancienne = $date = $row['date'];
287
-	$champs = array();
288
-
289
-	$d = isset($c['date']) ? $c['date'] : null;
290
-	$s = isset($c['statut']) ? $c['statut'] : $statut;
291
-
292
-	// cf autorisations dans inc/instituer_article
293
-	if ($s != $statut or ($d and $d != $date)) {
294
-		if (autoriser('publierdans', 'rubrique', $id_rubrique)) {
295
-			$statut = $champs['statut'] = $s;
296
-		} else {
297
-			if (autoriser('modifier', 'article', $id_article) and $s != 'publie') {
298
-				$statut = $champs['statut'] = $s;
299
-			} else {
300
-				spip_log("editer_article $id_article refus " . join(' ', $c));
301
-			}
302
-		}
303
-
304
-		// En cas de publication, fixer la date a "maintenant"
305
-		// sauf si $c commande autre chose
306
-		// ou si l'article est deja date dans le futur
307
-		// En cas de proposition d'un article (mais pas depublication), idem
308
-		if ($champs['statut'] == 'publie'
309
-			or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, array('publie', 'prop'))))
310
-		) {
311
-			if ($d or strtotime($d = $date) > time()) {
312
-				$champs['date'] = $date = $d;
313
-			} else {
314
-				$champs['date'] = $date = date('Y-m-d H:i:s');
315
-			}
316
-		}
317
-	}
318
-
319
-	// Verifier que la rubrique demandee existe et est differente
320
-	// de la rubrique actuelle
321
-	if (isset($c['id_parent'])
322
-		and $id_parent = $c['id_parent']
323
-		and $id_parent != $id_rubrique
324
-		and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent)))
325
-	) {
326
-		$champs['id_rubrique'] = $id_parent;
327
-
328
-		// si l'article etait publie
329
-		// et que le demandeur n'est pas admin de la rubrique de destination
330
-		// repasser l'article en statut 'propose'.
331
-		if ($statut == 'publie'
332
-			and !autoriser('publierdans', 'rubrique', $id_parent)
333
-		) {
334
-			$champs['statut'] = 'prop';
335
-		}
336
-	}
337
-
338
-	// Envoyer aux plugins
339
-	$champs = pipeline('pre_edition',
340
-		array(
341
-			'args' => array(
342
-				'table' => 'spip_articles',
343
-				'id_objet' => $id_article,
344
-				'action' => 'instituer',
345
-				'statut_ancien' => $statut_ancien,
346
-				'date_ancienne' => $date_ancienne,
347
-			),
348
-			'data' => $champs
349
-		)
350
-	);
351
-
352
-	if (!count($champs)) {
353
-		return '';
354
-	}
355
-
356
-	// Envoyer les modifs.
357
-	editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
358
-
359
-	// Invalider les caches
360
-	include_spip('inc/invalideur');
361
-	suivre_invalideur("id='article/$id_article'");
362
-
363
-	if ($date) {
364
-		$t = strtotime($date);
365
-		$p = @$GLOBALS['meta']['date_prochain_postdate'];
366
-		if ($t > time() and (!$p or ($t < $p))) {
367
-			ecrire_meta('date_prochain_postdate', $t);
368
-		}
369
-	}
370
-
371
-	// Pipeline
372
-	pipeline('post_edition',
373
-		array(
374
-			'args' => array(
375
-				'table' => 'spip_articles',
376
-				'id_objet' => $id_article,
377
-				'action' => 'instituer',
378
-				'statut_ancien' => $statut_ancien,
379
-				'date_ancienne' => $date_ancienne,
380
-			),
381
-			'data' => $champs
382
-		)
383
-	);
384
-
385
-	// Notifications
386
-	if ($notifications = charger_fonction('notifications', 'inc')) {
387
-		$notifications('instituerarticle', $id_article,
388
-			array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne)
389
-		);
390
-	}
391
-
392
-	return ''; // pas d'erreur
279
+    include_spip('inc/autoriser');
280
+    include_spip('inc/rubriques');
281
+    include_spip('inc/modifier');
282
+
283
+    $row = sql_fetsel("statut, date, id_rubrique", "spip_articles", "id_article=$id_article");
284
+    $id_rubrique = $row['id_rubrique'];
285
+    $statut_ancien = $statut = $row['statut'];
286
+    $date_ancienne = $date = $row['date'];
287
+    $champs = array();
288
+
289
+    $d = isset($c['date']) ? $c['date'] : null;
290
+    $s = isset($c['statut']) ? $c['statut'] : $statut;
291
+
292
+    // cf autorisations dans inc/instituer_article
293
+    if ($s != $statut or ($d and $d != $date)) {
294
+        if (autoriser('publierdans', 'rubrique', $id_rubrique)) {
295
+            $statut = $champs['statut'] = $s;
296
+        } else {
297
+            if (autoriser('modifier', 'article', $id_article) and $s != 'publie') {
298
+                $statut = $champs['statut'] = $s;
299
+            } else {
300
+                spip_log("editer_article $id_article refus " . join(' ', $c));
301
+            }
302
+        }
303
+
304
+        // En cas de publication, fixer la date a "maintenant"
305
+        // sauf si $c commande autre chose
306
+        // ou si l'article est deja date dans le futur
307
+        // En cas de proposition d'un article (mais pas depublication), idem
308
+        if ($champs['statut'] == 'publie'
309
+            or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, array('publie', 'prop'))))
310
+        ) {
311
+            if ($d or strtotime($d = $date) > time()) {
312
+                $champs['date'] = $date = $d;
313
+            } else {
314
+                $champs['date'] = $date = date('Y-m-d H:i:s');
315
+            }
316
+        }
317
+    }
318
+
319
+    // Verifier que la rubrique demandee existe et est differente
320
+    // de la rubrique actuelle
321
+    if (isset($c['id_parent'])
322
+        and $id_parent = $c['id_parent']
323
+        and $id_parent != $id_rubrique
324
+        and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent)))
325
+    ) {
326
+        $champs['id_rubrique'] = $id_parent;
327
+
328
+        // si l'article etait publie
329
+        // et que le demandeur n'est pas admin de la rubrique de destination
330
+        // repasser l'article en statut 'propose'.
331
+        if ($statut == 'publie'
332
+            and !autoriser('publierdans', 'rubrique', $id_parent)
333
+        ) {
334
+            $champs['statut'] = 'prop';
335
+        }
336
+    }
337
+
338
+    // Envoyer aux plugins
339
+    $champs = pipeline('pre_edition',
340
+        array(
341
+            'args' => array(
342
+                'table' => 'spip_articles',
343
+                'id_objet' => $id_article,
344
+                'action' => 'instituer',
345
+                'statut_ancien' => $statut_ancien,
346
+                'date_ancienne' => $date_ancienne,
347
+            ),
348
+            'data' => $champs
349
+        )
350
+    );
351
+
352
+    if (!count($champs)) {
353
+        return '';
354
+    }
355
+
356
+    // Envoyer les modifs.
357
+    editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
358
+
359
+    // Invalider les caches
360
+    include_spip('inc/invalideur');
361
+    suivre_invalideur("id='article/$id_article'");
362
+
363
+    if ($date) {
364
+        $t = strtotime($date);
365
+        $p = @$GLOBALS['meta']['date_prochain_postdate'];
366
+        if ($t > time() and (!$p or ($t < $p))) {
367
+            ecrire_meta('date_prochain_postdate', $t);
368
+        }
369
+    }
370
+
371
+    // Pipeline
372
+    pipeline('post_edition',
373
+        array(
374
+            'args' => array(
375
+                'table' => 'spip_articles',
376
+                'id_objet' => $id_article,
377
+                'action' => 'instituer',
378
+                'statut_ancien' => $statut_ancien,
379
+                'date_ancienne' => $date_ancienne,
380
+            ),
381
+            'data' => $champs
382
+        )
383
+    );
384
+
385
+    // Notifications
386
+    if ($notifications = charger_fonction('notifications', 'inc')) {
387
+        $notifications('instituerarticle', $id_article,
388
+            array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne)
389
+        );
390
+    }
391
+
392
+    return ''; // pas d'erreur
393 393
 }
394 394
 
395 395
 /**
@@ -414,33 +414,33 @@  discard block
 block discarded – undo
414 414
  */
415 415
 function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) {
416 416
 
417
-	// Si on deplace l'article
418
-	//  changer aussi son secteur et sa langue (si heritee)
419
-	if (isset($champs['id_rubrique'])) {
417
+    // Si on deplace l'article
418
+    //  changer aussi son secteur et sa langue (si heritee)
419
+    if (isset($champs['id_rubrique'])) {
420 420
 
421
-		$row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique']));
421
+        $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique']));
422 422
 
423
-		$langue = $row_rub['lang'];
424
-		$champs['id_secteur'] = $row_rub['id_secteur'];
425
-		if (sql_fetsel('1', 'spip_articles',
426
-			"id_article=" . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) {
427
-			$champs['lang'] = $langue;
428
-		}
429
-	}
423
+        $langue = $row_rub['lang'];
424
+        $champs['id_secteur'] = $row_rub['id_secteur'];
425
+        if (sql_fetsel('1', 'spip_articles',
426
+            "id_article=" . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) {
427
+            $champs['lang'] = $langue;
428
+        }
429
+    }
430 430
 
431
-	if (!$champs) {
432
-		return;
433
-	}
431
+    if (!$champs) {
432
+        return;
433
+    }
434 434
 
435
-	sql_updateq('spip_articles', $champs, "id_article=" . intval($id_article));
435
+    sql_updateq('spip_articles', $champs, "id_article=" . intval($id_article));
436 436
 
437
-	// Changer le statut des rubriques concernees 
437
+    // Changer le statut des rubriques concernees 
438 438
 
439
-	if ($cond) {
440
-		include_spip('inc/rubriques');
441
-		$postdate = ($GLOBALS['meta']["post_dates"] == "non" and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false;
442
-		calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate);
443
-	}
439
+    if ($cond) {
440
+        include_spip('inc/rubriques');
441
+        $postdate = ($GLOBALS['meta']["post_dates"] == "non" and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false;
442
+        calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate);
443
+    }
444 444
 }
445 445
 
446 446
 /**
@@ -449,12 +449,12 @@  discard block
 block discarded – undo
449 449
  * @return void
450 450
  */
451 451
 function trop_longs_articles() {
452
-	if (is_array($plus = _request('texte_plus'))) {
453
-		foreach ($plus as $n => $t) {
454
-			$plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", "", $t);
455
-		}
456
-		set_request('texte', join('', $plus) . _request('texte'));
457
-	}
452
+    if (is_array($plus = _request('texte_plus'))) {
453
+        foreach ($plus as $n => $t) {
454
+            $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", "", $t);
455
+        }
456
+        set_request('texte', join('', $plus) . _request('texte'));
457
+    }
458 458
 }
459 459
 
460 460
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
  *     Chaîne contenant un texte d'erreur sinon.
480 480
  */
481 481
 function revisions_articles($id_article, $c = false) {
482
-	return article_modifier($id_article, $c);
482
+    return article_modifier($id_article, $c);
483 483
 }
484 484
 
485 485
 /**
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
  *     Chaîne contenant un texte d'erreur sinon.
501 501
  */
502 502
 function revision_article($id_article, $c = false) {
503
-	return article_modifier($id_article, $c);
503
+    return article_modifier($id_article, $c);
504 504
 }
505 505
 
506 506
 /**
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
  *     Chaîne contenant un texte d'erreur sinon.
522 522
  */
523 523
 function articles_set($id_article, $set = null) {
524
-	return article_modifier($id_article, $set);
524
+    return article_modifier($id_article, $set);
525 525
 }
526 526
 
527 527
 /**
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
  *     Identifiant du nouvel article
537 537
  */
538 538
 function insert_article($id_rubrique) {
539
-	return article_inserer($id_rubrique);
539
+    return article_inserer($id_rubrique);
540 540
 }
541 541
 
542 542
 /**
@@ -558,5 +558,5 @@  discard block
 block discarded – undo
558 558
  *     Chaîne vide
559 559
  */
560 560
 function instituer_article($id_article, $c, $calcul_rub = true) {
561
-	return article_instituer($id_article, $c, $calcul_rub);
561
+    return article_instituer($id_article, $c, $calcul_rub);
562 562
 }
Please login to merge, or discard this patch.
ecrire/inc/idna_convert.class.php 2 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      * the constructor
89 89
      *
90 90
      * @param array $options
91
-     * @return boolean
91
+     * @return boolean|null
92 92
      * @since 0.5.2
93 93
      */
94 94
     public function __construct($options = false)
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
     /**
394 394
      * Use this method to get the last error ocurred
395 395
      * @param    void
396
-     * @return   string   The last error, that occured
396
+     * @return   boolean   The last error, that occured
397 397
      */
398 398
     public function get_last_error()
399 399
     {
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
     /**
404 404
      * The actual decoding algorithm
405 405
      * @param string
406
-     * @return mixed
406
+     * @return false|string
407 407
      */
408 408
     protected function _decode($encoded)
409 409
     {
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
     /**
465 465
      * The actual encoding algorithm
466 466
      * @param  string
467
-     * @return mixed
467
+     * @return false|string
468 468
      */
469 469
     protected function _encode($decoded)
470 470
     {
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
      * Decomposes a Hangul syllable
700 700
      * (see http://www.unicode.org/unicode/reports/tr15/#Hangul
701 701
      * @param    integer  32bit UCS4 code point
702
-     * @return   array    Either Hangul Syllable decomposed or original 32bit value as one value array
702
+     * @return   integer[]    Either Hangul Syllable decomposed or original 32bit value as one value array
703 703
      */
704 704
     protected function _hangul_decompose($char)
705 705
     {
Please login to merge, or discard this patch.
Spacing   +43 added lines, -46 removed lines patch added patch discarded remove patch
@@ -73,16 +73,16 @@  discard block
 block discarded – undo
73 73
     protected $_lcount = 19;
74 74
     protected $_vcount = 21;
75 75
     protected $_tcount = 28;
76
-    protected $_ncount = 588;   // _vcount * _tcount
76
+    protected $_ncount = 588; // _vcount * _tcount
77 77
     protected $_scount = 11172; // _lcount * _tcount * _vcount
78 78
     protected $_error = false;
79 79
     protected static $_mb_string_overload = null;
80 80
     // See {@link set_paramter()} for details of how to change the following
81 81
     // settings from within your script / application
82
-    protected $_api_encoding = 'utf8';   // Default input charset is UTF-8
83
-    protected $_allow_overlong = false;  // Overlong UTF-8 encodings are forbidden
84
-    protected $_strict_mode = false;     // Behave strict or not
85
-    protected $_idn_version = 2003;      // Can be either 2003 (old, default) or 2008
82
+    protected $_api_encoding = 'utf8'; // Default input charset is UTF-8
83
+    protected $_allow_overlong = false; // Overlong UTF-8 encodings are forbidden
84
+    protected $_strict_mode = false; // Behave strict or not
85
+    protected $_idn_version = 2003; // Can be either 2003 (old, default) or 2008
86 86
 
87 87
     /**
88 88
      * the constructor
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                             $this->_api_encoding = $v;
141 141
                             break;
142 142
                         default:
143
-                            $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k);
143
+                            $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k);
144 144
                             return false;
145 145
                     }
146 146
                     break;
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                     if (in_array($v, array('2003', '2008'))) {
155 155
                         $this->_idn_version = $v;
156 156
                     } else {
157
-                        $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k);
157
+                        $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k);
158 158
                     }
159 159
                     break;
160 160
                 case 'encode_german_sz': // Deprecated
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                     }
166 166
                     break;
167 167
                 default:
168
-                    $this->_error('Set Parameter: Unknown option ' . $k);
168
+                    $this->_error('Set Parameter: Unknown option '.$k);
169 169
                     return false;
170 170
             }
171 171
         }
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
                 case 'ucs4_array':
189 189
                     break;
190 190
                 default:
191
-                    $this->_error('Unknown encoding ' . $one_time_encoding);
191
+                    $this->_error('Unknown encoding '.$one_time_encoding);
192 192
                     return false;
193 193
             }
194 194
         }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             list ($email_pref, $input) = explode('@', $input, 2);
207 207
             $arr = explode('.', $input);
208 208
             foreach ($arr as $k => $v) {
209
-                if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) {
209
+                if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
210 210
                     $conv = $this->_decode($v);
211 211
                     if ($conv) {
212 212
                         $arr[$k] = $conv;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
             $input = join('.', $arr);
217 217
             $arr = explode('.', $email_pref);
218 218
             foreach ($arr as $k => $v) {
219
-                if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) {
219
+                if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
220 220
                     $conv = $this->_decode($v);
221 221
                     if ($conv) {
222 222
                         $arr[$k] = $conv;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
                 }
225 225
             }
226 226
             $email_pref = join('.', $arr);
227
-            $return = $email_pref . '@' . $input;
227
+            $return = $email_pref.'@'.$input;
228 228
         } elseif (preg_match('![:\./]!', $input)) { // Or a complete domain name (with or without paths / parameters)
229 229
             // No no in strict mode
230 230
             if ($this->_strict_mode) {
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
                     }
242 242
                 }
243 243
                 $parsed['host'] = join('.', $arr);
244
-                $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
245
-                        (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@').
244
+                $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
245
+                        (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@').
246 246
                         $parsed['host'].
247
-                        (empty($parsed['port']) ? '' : ':' . $parsed['port']).
247
+                        (empty($parsed['port']) ? '' : ':'.$parsed['port']).
248 248
                         (empty($parsed['path']) ? '' : $parsed['path']).
249
-                        (empty($parsed['query']) ? '' : '?' . $parsed['query']).
250
-                        (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']);
249
+                        (empty($parsed['query']) ? '' : '?'.$parsed['query']).
250
+                        (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']);
251 251
             } else { // parse_url seems to have failed, try without it
252 252
                 $arr = explode('.', $input);
253 253
                 foreach ($arr as $k => $v) {
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
         // The output is UTF-8 by default, other output formats need conversion here
266 266
         // If one time encoding is given, use this, else the objects property
267 267
         switch (($one_time_encoding) ? $one_time_encoding : $this->_api_encoding) {
268
-            case 'utf8':        return $return; // break;
269
-            case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return));  // break;
268
+            case 'utf8' : return $return; // break;
269
+            case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return)); // break;
270 270
             case 'ucs4_array':  return $this->_utf8_to_ucs4($return); // break;
271 271
             default:            $this->_error('Unsupported output format'); return false;
272 272
         }
@@ -283,15 +283,14 @@  discard block
 block discarded – undo
283 283
         // Forcing conversion of input to UCS4 array
284 284
         // If one time encoding is given, use this, else the objects property
285 285
         switch ($one_time_encoding ? $one_time_encoding : $this->_api_encoding) {
286
-            case 'utf8':
287
-                $decoded = $this->_utf8_to_ucs4($decoded);
286
+            case 'utf8' : $decoded = $this->_utf8_to_ucs4($decoded);
288 287
                 break;
289 288
             case 'ucs4_string':
290 289
                 $decoded = $this->_ucs4_string_to_ucs4($decoded);
291 290
             case 'ucs4_array':
292 291
                 break;
293 292
             default:
294
-                $this->_error('Unsupported input format: ' . ($one_time_encoding ? $one_time_encoding : $this->_api_encoding));
293
+                $this->_error('Unsupported input format: '.($one_time_encoding ? $one_time_encoding : $this->_api_encoding));
295 294
                 return false;
296 295
         }
297 296
 
@@ -380,13 +379,13 @@  discard block
 block discarded – undo
380 379
             }
381 380
         }
382 381
         $parsed['host'] = join('.', $arr);
383
-        $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
384
-                (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@').
382
+        $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
383
+                (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@').
385 384
                 $parsed['host'].
386
-                (empty($parsed['port']) ? '' : ':' . $parsed['port']).
385
+                (empty($parsed['port']) ? '' : ':'.$parsed['port']).
387 386
                 (empty($parsed['path']) ? '' : $parsed['path']).
388
-                (empty($parsed['query']) ? '' : '?' . $parsed['query']).
389
-                (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']);
387
+                (empty($parsed['query']) ? '' : '?'.$parsed['query']).
388
+                (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']);
390 389
         return $return;
391 390
     }
392 391
 
@@ -409,11 +408,11 @@  discard block
 block discarded – undo
409 408
     {
410 409
         $decoded = array();
411 410
         // find the Punycode prefix
412
-        if (!preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $encoded)) {
411
+        if (!preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $encoded)) {
413 412
             $this->_error('This is not a punycode string');
414 413
             return false;
415 414
         }
416
-        $encode_test = preg_replace('!^' . preg_quote($this->_punycode_prefix, '!') . '!', '', $encoded);
415
+        $encode_test = preg_replace('!^'.preg_quote($this->_punycode_prefix, '!').'!', '', $encoded);
417 416
         // If nothing left after removing the prefix, it is hopeless
418 417
         if (!$encode_test) {
419 418
             $this->_error('The given encoded string was empty');
@@ -439,8 +438,7 @@  discard block
 block discarded – undo
439 438
             for ($old_idx = $idx, $w = 1, $k = $this->_base; 1; $k += $this->_base) {
440 439
                 $digit = $this->_decode_digit($encoded[$enco_idx++]);
441 440
                 $idx += $digit * $w;
442
-                $t = ($k <= $bias) ? $this->_tmin :
443
-                        (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias));
441
+                $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias));
444 442
                 if ($digit < $t) {
445 443
                     break;
446 444
                 }
@@ -513,7 +511,7 @@  discard block
 block discarded – undo
513 511
             return $encoded; // All codepoints were basic ones
514 512
         }
515 513
         // Start with the prefix; copy it to output
516
-        $encoded = $this->_punycode_prefix . $encoded;
514
+        $encoded = $this->_punycode_prefix.$encoded;
517 515
         // If we have basic code points in output, add an hyphen to the end
518 516
         if ($codecount) {
519 517
             $encoded .= '-';
@@ -540,8 +538,7 @@  discard block
 block discarded – undo
540 538
                     $delta++;
541 539
                 } elseif ($decoded[$i] == $cur_code) {
542 540
                     for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) {
543
-                        $t = ($k <= $bias) ? $this->_tmin :
544
-                                (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias);
541
+                        $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias);
545 542
                         if ($q < $t) {
546 543
                             break;
547 544
                         }
@@ -628,12 +625,12 @@  discard block
 block discarded – undo
628 625
             }
629 626
             // Try to find prohibited input
630 627
             if (in_array($v, self::$NP['prohibit']) || in_array($v, self::$NP['general_prohibited'])) {
631
-                $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v));
628
+                $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
632 629
                 return false;
633 630
             }
634 631
             foreach (self::$NP['prohibit_ranges'] as $range) {
635 632
                 if ($range[0] <= $v && $v <= $range[1]) {
636
-                    $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v));
633
+                    $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
637 634
                     return false;
638 635
                 }
639 636
             }
@@ -869,7 +866,7 @@  discard block
 block discarded – undo
869 866
                 $output[$out_len] = $v;
870 867
                 ++$out_len;
871 868
                 if ('add' == $mode) {
872
-                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k);
869
+                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
873 870
                     return false;
874 871
                 }
875 872
                 continue;
@@ -894,7 +891,7 @@  discard block
 block discarded – undo
894 891
                     $next_byte = 4;
895 892
                     $v = ($v - 252) << 30;
896 893
                 } else {
897
-                    $this->_error('This might be UTF-8, but I don\'t understand it at byte ' . $k);
894
+                    $this->_error('This might be UTF-8, but I don\'t understand it at byte '.$k);
898 895
                     return false;
899 896
                 }
900 897
                 if ('add' == $mode) {
@@ -907,7 +904,7 @@  discard block
 block discarded – undo
907 904
                 if (!$this->_allow_overlong && $test == 'range') {
908 905
                     $test = 'none';
909 906
                     if (($v < 0xA0 && $start_byte == 0xE0) || ($v < 0x90 && $start_byte == 0xF0) || ($v > 0x8F && $start_byte == 0xF4)) {
910
-                        $this->_error('Bogus UTF-8 character detected (out of legal range) at byte ' . $k);
907
+                        $this->_error('Bogus UTF-8 character detected (out of legal range) at byte '.$k);
911 908
                         return false;
912 909
                     }
913 910
                 }
@@ -916,7 +913,7 @@  discard block
 block discarded – undo
916 913
                     $output[($out_len - 1)] += $v;
917 914
                     --$next_byte;
918 915
                 } else {
919
-                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k);
916
+                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
920 917
                     return false;
921 918
                 }
922 919
                 if ($next_byte < 0) {
@@ -940,13 +937,13 @@  discard block
 block discarded – undo
940 937
             if ($v < 128) { // 7bit are transferred literally
941 938
                 $output .= chr($v);
942 939
             } elseif ($v < (1 << 11)) { // 2 bytes
943
-                $output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
940
+                $output .= chr(192 + ($v >> 6)).chr(128 + ($v & 63));
944 941
             } elseif ($v < (1 << 16)) { // 3 bytes
945
-                $output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
942
+                $output .= chr(224 + ($v >> 12)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63));
946 943
             } elseif ($v < (1 << 21)) { // 4 bytes
947
-                $output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
944
+                $output .= chr(240 + ($v >> 18)).chr(128 + (($v >> 12) & 63)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63));
948 945
             } else {
949
-                $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte ' . $k);
946
+                $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k);
950 947
                 return false;
951 948
             }
952 949
         }
@@ -965,7 +962,7 @@  discard block
 block discarded – undo
965 962
         // Take array values and split output to 4 bytes per value
966 963
         // The bit mask is 255, which reads &11111111
967 964
         foreach ($input as $v) {
968
-            $output .= chr(($v >> 24) & 255) . chr(($v >> 16) & 255) . chr(($v >> 8) & 255) . chr($v & 255);
965
+            $output .= chr(($v >> 24) & 255).chr(($v >> 16) & 255).chr(($v >> 8) & 255).chr($v & 255);
969 966
         }
970 967
         return $output;
971 968
     }
@@ -995,7 +992,7 @@  discard block
 block discarded – undo
995 992
                 $out_len++;
996 993
                 $output[$out_len] = 0;
997 994
             }
998
-            $output[$out_len] += ord($input[$i]) << (8 * (3 - ($i % 4) ) );
995
+            $output[$out_len] += ord($input[$i]) << (8 * (3 - ($i % 4)));
999 996
         }
1000 997
         return $output;
1001 998
     }
Please login to merge, or discard this patch.
ecrire/action/editer_auteur.php 3 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
  * @param string|null $source
86 86
  *     D'où provient l'auteur créé ? par défaut 'spip', mais peut être 'ldap' ou autre.
87 87
  * @param array|null $set
88
- * @return int
88
+ * @return boolean|string
89 89
  *     Identifiant de l'auteur créé
90 90
  */
91 91
 function auteur_inserer($source = null, $set = null) {
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
  * @param bool $force_update
141 141
  *   Permet de forcer la maj en base des champs fournis, sans passer par instancier.
142 142
  *   Utilise par auth/spip
143
- * @return string|null
143
+ * @return string|false
144 144
  *
145 145
  *     - Chaîne vide si aucune erreur,
146 146
  *     - Chaîne contenant un texte d'erreur sinon.
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
  *     Couples (colonne => valeur) des données à instituer
305 305
  * @param bool $force_webmestre
306 306
  *     Autoriser un auteur à passer webmestre (force l'autorisation)
307
- * @return bool|string
307
+ * @return false|string
308 308
  */
309 309
 function auteur_instituer($id_auteur, $c, $force_webmestre = false) {
310 310
 	if (!$id_auteur = intval($id_auteur)) {
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
  * @see auteur_inserer()
450 450
  *
451 451
  * @param string|null $source
452
- * @return int
452
+ * @return boolean|string
453 453
  */
454 454
 function insert_auteur($source = null) {
455 455
 	return auteur_inserer($source);
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
  *
464 464
  * @param int $id_auteur
465 465
  * @param array|null $set
466
- * @return string|null
466
+ * @return string|false
467 467
  */
468 468
 function auteurs_set($id_auteur, $set = null) {
469 469
 	return auteur_modifier($id_auteur, $set);
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
  * @param int $id_auteur
479 479
  * @param array $c
480 480
  * @param bool $force_webmestre
481
- * @return bool|string
481
+ * @return false|string
482 482
  */
483 483
 function instituer_auteur($id_auteur, $c, $force_webmestre = false) {
484 484
 	return auteur_instituer($id_auteur, $c, $force_webmestre);
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
  *
493 493
  * @param int $id_auteur
494 494
  * @param array $c
495
- * @return string|null
495
+ * @return string|false
496 496
  */
497 497
 function revision_auteur($id_auteur, $c = false) {
498 498
 	return auteur_modifier($id_auteur, $c);
Please login to merge, or discard this patch.
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -37,43 +37,43 @@  discard block
 block discarded – undo
37 37
  */
38 38
 function action_editer_auteur_dist($arg = null) {
39 39
 
40
-	if (is_null($arg)) {
41
-		$securiser_action = charger_fonction('securiser_action', 'inc');
42
-		$arg = $securiser_action();
43
-	}
44
-
45
-
46
-	// si id_auteur n'est pas un nombre, c'est une creation
47
-	if (!$id_auteur = intval($arg)) {
48
-
49
-		if (($id_auteur = auteur_inserer()) > 0) {
50
-
51
-			# cf. GROS HACK
52
-			# recuperer l'eventuel logo charge avant la creation
53
-			# ils ont un id = 0-id_auteur de la session
54
-			$id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur'];
55
-			$chercher_logo = charger_fonction('chercher_logo', 'inc');
56
-			foreach (array('on', 'off') as $type) {
57
-				if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) {
58
-					if ($logo = reset($logo)) {
59
-						rename($logo, str_replace($id_hack, $id_auteur, $logo));
60
-					}
61
-				}
62
-			}
63
-		}
64
-	}
65
-
66
-	// Enregistre l'envoi dans la BD
67
-	$err = "";
68
-	if ($id_auteur > 0) {
69
-		$err = auteur_modifier($id_auteur);
70
-	}
71
-
72
-	if ($err) {
73
-		spip_log("echec editeur auteur: $err", _LOG_ERREUR);
74
-	}
75
-
76
-	return array($id_auteur, $err);
40
+    if (is_null($arg)) {
41
+        $securiser_action = charger_fonction('securiser_action', 'inc');
42
+        $arg = $securiser_action();
43
+    }
44
+
45
+
46
+    // si id_auteur n'est pas un nombre, c'est une creation
47
+    if (!$id_auteur = intval($arg)) {
48
+
49
+        if (($id_auteur = auteur_inserer()) > 0) {
50
+
51
+            # cf. GROS HACK
52
+            # recuperer l'eventuel logo charge avant la creation
53
+            # ils ont un id = 0-id_auteur de la session
54
+            $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur'];
55
+            $chercher_logo = charger_fonction('chercher_logo', 'inc');
56
+            foreach (array('on', 'off') as $type) {
57
+                if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) {
58
+                    if ($logo = reset($logo)) {
59
+                        rename($logo, str_replace($id_hack, $id_auteur, $logo));
60
+                    }
61
+                }
62
+            }
63
+        }
64
+    }
65
+
66
+    // Enregistre l'envoi dans la BD
67
+    $err = "";
68
+    if ($id_auteur > 0) {
69
+        $err = auteur_modifier($id_auteur);
70
+    }
71
+
72
+    if ($err) {
73
+        spip_log("echec editeur auteur: $err", _LOG_ERREUR);
74
+    }
75
+
76
+    return array($id_auteur, $err);
77 77
 }
78 78
 
79 79
 /**
@@ -90,39 +90,39 @@  discard block
 block discarded – undo
90 90
  */
91 91
 function auteur_inserer($source = null, $set = null) {
92 92
 
93
-	// Ce qu'on va demander comme modifications
94
-	$champs = array();
95
-	$champs['source'] = $source ? $source : 'spip';
96
-
97
-	$champs['login'] = '';
98
-	$champs['statut'] = '5poubelle';  // inutilisable tant qu'il n'a pas ete renseigne et institue
99
-	$champs['webmestre'] = 'non';
100
-
101
-	if ($set) {
102
-		$champs = array_merge($champs, $set);
103
-	}
104
-
105
-	// Envoyer aux plugins
106
-	$champs = pipeline('pre_insertion',
107
-		array(
108
-			'args' => array(
109
-				'table' => 'spip_auteurs',
110
-			),
111
-			'data' => $champs
112
-		)
113
-	);
114
-	$id_auteur = sql_insertq("spip_auteurs", $champs);
115
-	pipeline('post_insertion',
116
-		array(
117
-			'args' => array(
118
-				'table' => 'spip_auteurs',
119
-				'id_objet' => $id_auteur
120
-			),
121
-			'data' => $champs
122
-		)
123
-	);
124
-
125
-	return $id_auteur;
93
+    // Ce qu'on va demander comme modifications
94
+    $champs = array();
95
+    $champs['source'] = $source ? $source : 'spip';
96
+
97
+    $champs['login'] = '';
98
+    $champs['statut'] = '5poubelle';  // inutilisable tant qu'il n'a pas ete renseigne et institue
99
+    $champs['webmestre'] = 'non';
100
+
101
+    if ($set) {
102
+        $champs = array_merge($champs, $set);
103
+    }
104
+
105
+    // Envoyer aux plugins
106
+    $champs = pipeline('pre_insertion',
107
+        array(
108
+            'args' => array(
109
+                'table' => 'spip_auteurs',
110
+            ),
111
+            'data' => $champs
112
+        )
113
+    );
114
+    $id_auteur = sql_insertq("spip_auteurs", $champs);
115
+    pipeline('post_insertion',
116
+        array(
117
+            'args' => array(
118
+                'table' => 'spip_auteurs',
119
+                'id_objet' => $id_auteur
120
+            ),
121
+            'data' => $champs
122
+        )
123
+    );
124
+
125
+    return $id_auteur;
126 126
 }
127 127
 
128 128
 
@@ -147,66 +147,66 @@  discard block
 block discarded – undo
147 147
  */
148 148
 function auteur_modifier($id_auteur, $set = null, $force_update = false) {
149 149
 
150
-	include_spip('inc/modifier');
151
-	include_spip('inc/filtres');
152
-	$c = collecter_requests(
153
-	// white list
154
-		objet_info('auteur', 'champs_editables'),
155
-		// black list
156
-		$force_update ? array() : array('webmestre', 'pass', 'login'),
157
-		// donnees eventuellement fournies
158
-		$set
159
-	);
160
-
161
-	if ($err = objet_modifier_champs('auteur', $id_auteur,
162
-		array(
163
-			'data' => $set,
164
-			'nonvide' => array('nom' => _T('ecrire:item_nouvel_auteur'))
165
-		),
166
-		$c)
167
-	) {
168
-		return $err;
169
-	}
170
-	$session = $c;
171
-
172
-	$err = '';
173
-	if (!$force_update) {
174
-		// Modification de statut, changement de rubrique ?
175
-		$c = collecter_requests(
176
-		// white list
177
-			array(
178
-				'statut',
179
-				'new_login',
180
-				'new_pass',
181
-				'login',
182
-				'pass',
183
-				'webmestre',
184
-				'restreintes',
185
-				'id_parent'
186
-			),
187
-			// black list
188
-			array(),
189
-			// donnees eventuellement fournies
190
-			$set
191
-		);
192
-		if (isset($c['new_login']) and !isset($c['login'])) {
193
-			$c['login'] = $c['new_login'];
194
-		}
195
-		if (isset($c['new_pass']) and !isset($c['pass'])) {
196
-			$c['pass'] = $c['new_pass'];
197
-		}
198
-		$err = auteur_instituer($id_auteur, $c);
199
-		$session = array_merge($session, $c);
200
-	}
201
-
202
-	// .. mettre a jour les sessions de cet auteur
203
-	include_spip('inc/session');
204
-	$session['id_auteur'] = $id_auteur;
205
-	unset($session['new_login']);
206
-	unset($session['new_pass']);
207
-	actualiser_sessions($session);
208
-
209
-	return $err;
150
+    include_spip('inc/modifier');
151
+    include_spip('inc/filtres');
152
+    $c = collecter_requests(
153
+    // white list
154
+        objet_info('auteur', 'champs_editables'),
155
+        // black list
156
+        $force_update ? array() : array('webmestre', 'pass', 'login'),
157
+        // donnees eventuellement fournies
158
+        $set
159
+    );
160
+
161
+    if ($err = objet_modifier_champs('auteur', $id_auteur,
162
+        array(
163
+            'data' => $set,
164
+            'nonvide' => array('nom' => _T('ecrire:item_nouvel_auteur'))
165
+        ),
166
+        $c)
167
+    ) {
168
+        return $err;
169
+    }
170
+    $session = $c;
171
+
172
+    $err = '';
173
+    if (!$force_update) {
174
+        // Modification de statut, changement de rubrique ?
175
+        $c = collecter_requests(
176
+        // white list
177
+            array(
178
+                'statut',
179
+                'new_login',
180
+                'new_pass',
181
+                'login',
182
+                'pass',
183
+                'webmestre',
184
+                'restreintes',
185
+                'id_parent'
186
+            ),
187
+            // black list
188
+            array(),
189
+            // donnees eventuellement fournies
190
+            $set
191
+        );
192
+        if (isset($c['new_login']) and !isset($c['login'])) {
193
+            $c['login'] = $c['new_login'];
194
+        }
195
+        if (isset($c['new_pass']) and !isset($c['pass'])) {
196
+            $c['pass'] = $c['new_pass'];
197
+        }
198
+        $err = auteur_instituer($id_auteur, $c);
199
+        $session = array_merge($session, $c);
200
+    }
201
+
202
+    // .. mettre a jour les sessions de cet auteur
203
+    include_spip('inc/session');
204
+    $session['id_auteur'] = $id_auteur;
205
+    unset($session['new_login']);
206
+    unset($session['new_pass']);
207
+    actualiser_sessions($session);
208
+
209
+    return $err;
210 210
 }
211 211
 
212 212
 /**
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
  * @return string
228 228
  */
229 229
 function auteur_associer($id_auteur, $objets, $qualif = null) {
230
-	include_spip('action/editer_liens');
230
+    include_spip('action/editer_liens');
231 231
 
232
-	return objet_associer(array('auteur' => $id_auteur), $objets, $qualif);
232
+    return objet_associer(array('auteur' => $id_auteur), $objets, $qualif);
233 233
 }
234 234
 
235 235
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
  * @return string
245 245
  */
246 246
 function auteur_referent($id_auteur, $c) {
247
-	return auteur_associer($id_auteur, $c);
247
+    return auteur_associer($id_auteur, $c);
248 248
 }
249 249
 
250 250
 /**
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
  * @return string
264 264
  */
265 265
 function auteur_dissocier($id_auteur, $objets) {
266
-	include_spip('action/editer_liens');
266
+    include_spip('action/editer_liens');
267 267
 
268
-	return objet_dissocier(array('auteur' => $id_auteur), $objets);
268
+    return objet_dissocier(array('auteur' => $id_auteur), $objets);
269 269
 }
270 270
 
271 271
 /**
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
  * @return bool|int
287 287
  */
288 288
 function auteur_qualifier($id_auteur, $objets, $qualif) {
289
-	include_spip('action/editer_liens');
289
+    include_spip('action/editer_liens');
290 290
 
291
-	return objet_qualifier_liens(array('auteur' => $id_auteur), $objets, $qualif);
291
+    return objet_qualifier_liens(array('auteur' => $id_auteur), $objets, $qualif);
292 292
 }
293 293
 
294 294
 
@@ -307,133 +307,133 @@  discard block
 block discarded – undo
307 307
  * @return bool|string
308 308
  */
309 309
 function auteur_instituer($id_auteur, $c, $force_webmestre = false) {
310
-	if (!$id_auteur = intval($id_auteur)) {
311
-		return false;
312
-	}
313
-	$erreurs = array(); // contiendra les differentes erreurs a traduire par _T()
314
-	$champs = array();
315
-
316
-	// les memoriser pour les faire passer dans le pipeline pre_edition
317
-	if (isset($c['login']) and strlen($c['login'])) {
318
-		$champs['login'] = $c['login'];
319
-	}
320
-	if (isset($c['pass']) and strlen($c['pass'])) {
321
-		$champs['pass'] = $c['pass'];
322
-	}
323
-
324
-	$statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
325
-
326
-	if (isset($c['statut'])
327
-		and (autoriser('modifier', 'auteur', $id_auteur, null, array('statut' => $c['statut'])))
328
-	) {
329
-		$statut = $champs['statut'] = $c['statut'];
330
-	}
331
-
332
-	// Restreindre avant de declarer l'auteur
333
-	// (section critique sur les droits)
334
-	if (isset($c['id_parent']) and $c['id_parent']) {
335
-		if (is_array($c['restreintes'])) {
336
-			$c['restreintes'][] = $c['id_parent'];
337
-		} else {
338
-			$c['restreintes'] = array($c['id_parent']);
339
-		}
340
-	}
341
-
342
-	if (isset($c['webmestre'])
343
-		and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, array('webmestre' => '?')))
344
-	) {
345
-		$champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non';
346
-	}
347
-
348
-	// si statut change et n'est pas 0minirezo, on force webmestre a non
349
-	if (isset($c['statut']) and $c['statut'] !== '0minirezo') {
350
-		$champs['webmestre'] = $c['webmestre'] = 'non';
351
-	}
352
-
353
-	// Envoyer aux plugins
354
-	$champs = pipeline('pre_edition',
355
-		array(
356
-			'args' => array(
357
-				'table' => 'spip_auteurs',
358
-				'id_objet' => $id_auteur,
359
-				'action' => 'instituer',
360
-				'statut_ancien' => $statut_ancien,
361
-			),
362
-			'data' => $champs
363
-		)
364
-	);
365
-
366
-	if (isset($c['restreintes']) and is_array($c['restreintes'])
367
-		and autoriser('modifier', 'auteur', $id_auteur, null, array('restreint' => $c['restreintes']))
368
-	) {
369
-		$rubriques = array_map('intval', $c['restreintes']);
370
-		$rubriques = array_unique($rubriques);
371
-		$rubriques = array_diff($rubriques, array(0));
372
-		auteur_dissocier($id_auteur, array('rubrique' => '*'));
373
-		auteur_associer($id_auteur, array('rubrique' => $rubriques));
374
-	}
375
-
376
-	$flag_ecrire_acces = false;
377
-	// commencer par traiter les cas particuliers des logins et pass
378
-	// avant les autres ecritures en base
379
-	if (isset($champs['login']) or isset($champs['pass'])) {
380
-		$auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
381
-		include_spip('inc/auth');
382
-		if (isset($champs['login']) and strlen($champs['login'])) {
383
-			if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) {
384
-				$erreurs[] = 'ecrire:impossible_modifier_login_auteur';
385
-			}
386
-		}
387
-		if (isset($champs['pass']) and strlen($champs['pass'])) {
388
-			$champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
389
-			if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) {
390
-				$erreurs[] = 'ecrire:impossible_modifier_pass_auteur';
391
-			}
392
-		}
393
-		unset($champs['login']);
394
-		unset($champs['pass']);
395
-		$flag_ecrire_acces = true;
396
-	}
397
-
398
-	if (!count($champs)) {
399
-		return implode(' ', array_map('_T', $erreurs));
400
-	}
401
-	sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur);
402
-
403
-	// .. mettre a jour les fichiers .htpasswd et .htpasswd-admin
404
-	if ($flag_ecrire_acces
405
-		or isset($champs['statut'])
406
-	) {
407
-		include_spip('inc/acces');
408
-		ecrire_acces();
409
-	}
410
-
411
-	// Invalider les caches
412
-	include_spip('inc/invalideur');
413
-	suivre_invalideur("id='auteur/$id_auteur'");
414
-
415
-	// Pipeline
416
-	pipeline('post_edition',
417
-		array(
418
-			'args' => array(
419
-				'table' => 'spip_auteurs',
420
-				'id_objet' => $id_auteur,
421
-				'action' => 'instituer',
422
-				'statut_ancien' => $statut_ancien,
423
-			),
424
-			'data' => $champs
425
-		)
426
-	);
427
-
428
-
429
-	// Notifications
430
-	if ($notifications = charger_fonction('notifications', 'inc')) {
431
-		$notifications('instituerauteur', $id_auteur,
432
-			array('statut' => $statut, 'statut_ancien' => $statut_ancien)
433
-		);
434
-	}
435
-
436
-	return implode(' ', array_map('_T', $erreurs));
310
+    if (!$id_auteur = intval($id_auteur)) {
311
+        return false;
312
+    }
313
+    $erreurs = array(); // contiendra les differentes erreurs a traduire par _T()
314
+    $champs = array();
315
+
316
+    // les memoriser pour les faire passer dans le pipeline pre_edition
317
+    if (isset($c['login']) and strlen($c['login'])) {
318
+        $champs['login'] = $c['login'];
319
+    }
320
+    if (isset($c['pass']) and strlen($c['pass'])) {
321
+        $champs['pass'] = $c['pass'];
322
+    }
323
+
324
+    $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
325
+
326
+    if (isset($c['statut'])
327
+        and (autoriser('modifier', 'auteur', $id_auteur, null, array('statut' => $c['statut'])))
328
+    ) {
329
+        $statut = $champs['statut'] = $c['statut'];
330
+    }
331
+
332
+    // Restreindre avant de declarer l'auteur
333
+    // (section critique sur les droits)
334
+    if (isset($c['id_parent']) and $c['id_parent']) {
335
+        if (is_array($c['restreintes'])) {
336
+            $c['restreintes'][] = $c['id_parent'];
337
+        } else {
338
+            $c['restreintes'] = array($c['id_parent']);
339
+        }
340
+    }
341
+
342
+    if (isset($c['webmestre'])
343
+        and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, array('webmestre' => '?')))
344
+    ) {
345
+        $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non';
346
+    }
347
+
348
+    // si statut change et n'est pas 0minirezo, on force webmestre a non
349
+    if (isset($c['statut']) and $c['statut'] !== '0minirezo') {
350
+        $champs['webmestre'] = $c['webmestre'] = 'non';
351
+    }
352
+
353
+    // Envoyer aux plugins
354
+    $champs = pipeline('pre_edition',
355
+        array(
356
+            'args' => array(
357
+                'table' => 'spip_auteurs',
358
+                'id_objet' => $id_auteur,
359
+                'action' => 'instituer',
360
+                'statut_ancien' => $statut_ancien,
361
+            ),
362
+            'data' => $champs
363
+        )
364
+    );
365
+
366
+    if (isset($c['restreintes']) and is_array($c['restreintes'])
367
+        and autoriser('modifier', 'auteur', $id_auteur, null, array('restreint' => $c['restreintes']))
368
+    ) {
369
+        $rubriques = array_map('intval', $c['restreintes']);
370
+        $rubriques = array_unique($rubriques);
371
+        $rubriques = array_diff($rubriques, array(0));
372
+        auteur_dissocier($id_auteur, array('rubrique' => '*'));
373
+        auteur_associer($id_auteur, array('rubrique' => $rubriques));
374
+    }
375
+
376
+    $flag_ecrire_acces = false;
377
+    // commencer par traiter les cas particuliers des logins et pass
378
+    // avant les autres ecritures en base
379
+    if (isset($champs['login']) or isset($champs['pass'])) {
380
+        $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
381
+        include_spip('inc/auth');
382
+        if (isset($champs['login']) and strlen($champs['login'])) {
383
+            if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) {
384
+                $erreurs[] = 'ecrire:impossible_modifier_login_auteur';
385
+            }
386
+        }
387
+        if (isset($champs['pass']) and strlen($champs['pass'])) {
388
+            $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
389
+            if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) {
390
+                $erreurs[] = 'ecrire:impossible_modifier_pass_auteur';
391
+            }
392
+        }
393
+        unset($champs['login']);
394
+        unset($champs['pass']);
395
+        $flag_ecrire_acces = true;
396
+    }
397
+
398
+    if (!count($champs)) {
399
+        return implode(' ', array_map('_T', $erreurs));
400
+    }
401
+    sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur);
402
+
403
+    // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin
404
+    if ($flag_ecrire_acces
405
+        or isset($champs['statut'])
406
+    ) {
407
+        include_spip('inc/acces');
408
+        ecrire_acces();
409
+    }
410
+
411
+    // Invalider les caches
412
+    include_spip('inc/invalideur');
413
+    suivre_invalideur("id='auteur/$id_auteur'");
414
+
415
+    // Pipeline
416
+    pipeline('post_edition',
417
+        array(
418
+            'args' => array(
419
+                'table' => 'spip_auteurs',
420
+                'id_objet' => $id_auteur,
421
+                'action' => 'instituer',
422
+                'statut_ancien' => $statut_ancien,
423
+            ),
424
+            'data' => $champs
425
+        )
426
+    );
427
+
428
+
429
+    // Notifications
430
+    if ($notifications = charger_fonction('notifications', 'inc')) {
431
+        $notifications('instituerauteur', $id_auteur,
432
+            array('statut' => $statut, 'statut_ancien' => $statut_ancien)
433
+        );
434
+    }
435
+
436
+    return implode(' ', array_map('_T', $erreurs));
437 437
 
438 438
 }
439 439
 
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
  * @return int
453 453
  */
454 454
 function insert_auteur($source = null) {
455
-	return auteur_inserer($source);
455
+    return auteur_inserer($source);
456 456
 }
457 457
 
458 458
 /**
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
  * @return string|null
467 467
  */
468 468
 function auteurs_set($id_auteur, $set = null) {
469
-	return auteur_modifier($id_auteur, $set);
469
+    return auteur_modifier($id_auteur, $set);
470 470
 }
471 471
 
472 472
 /**
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
  * @return bool|string
482 482
  */
483 483
 function instituer_auteur($id_auteur, $c, $force_webmestre = false) {
484
-	return auteur_instituer($id_auteur, $c, $force_webmestre);
484
+    return auteur_instituer($id_auteur, $c, $force_webmestre);
485 485
 }
486 486
 
487 487
 /**
@@ -495,5 +495,5 @@  discard block
 block discarded – undo
495 495
  * @return string|null
496 496
  */
497 497
 function revision_auteur($id_auteur, $c = false) {
498
-	return auteur_modifier($id_auteur, $c);
498
+    return auteur_modifier($id_auteur, $c);
499 499
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	$champs['source'] = $source ? $source : 'spip';
96 96
 
97 97
 	$champs['login'] = '';
98
-	$champs['statut'] = '5poubelle';  // inutilisable tant qu'il n'a pas ete renseigne et institue
98
+	$champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue
99 99
 	$champs['webmestre'] = 'non';
100 100
 
101 101
 	if ($set) {
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 		$champs['pass'] = $c['pass'];
322 322
 	}
323 323
 
324
-	$statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
324
+	$statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur='.intval($id_auteur));
325 325
 
326 326
 	if (isset($c['statut'])
327 327
 		and (autoriser('modifier', 'auteur', $id_auteur, null, array('statut' => $c['statut'])))
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 	// commencer par traiter les cas particuliers des logins et pass
378 378
 	// avant les autres ecritures en base
379 379
 	if (isset($champs['login']) or isset($champs['pass'])) {
380
-		$auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
380
+		$auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur='.intval($id_auteur));
381 381
 		include_spip('inc/auth');
382 382
 		if (isset($champs['login']) and strlen($champs['login'])) {
383 383
 			if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) {
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 			}
386 386
 		}
387 387
 		if (isset($champs['pass']) and strlen($champs['pass'])) {
388
-			$champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
388
+			$champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur));
389 389
 			if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) {
390 390
 				$erreurs[] = 'ecrire:impossible_modifier_pass_auteur';
391 391
 			}
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	if (!count($champs)) {
399 399
 		return implode(' ', array_map('_T', $erreurs));
400 400
 	}
401
-	sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur);
401
+	sql_updateq('spip_auteurs', $champs, 'id_auteur='.$id_auteur);
402 402
 
403 403
 	// .. mettre a jour les fichiers .htpasswd et .htpasswd-admin
404 404
 	if ($flag_ecrire_acces
Please login to merge, or discard this patch.
ecrire/action/editer_rubrique.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
  *     Identifiant de la rubrique parente.
74 74
  *     0 pour la racine.
75 75
  * @param array|null $set
76
- * @return int
76
+ * @return boolean|string
77 77
  *     Identifiant de la rubrique crée
78 78
  */
79 79
 function rubrique_inserer($id_parent, $set = null) {
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
  *     Identifiant de la rubrique modifiée
121 121
  * @param array|null $set
122 122
  *     Tableau qu'on peut proposer en lieu et place de _request()
123
- * @return bool|string
123
+ * @return string|false
124 124
  *     - false  : Aucune modification, aucun champ n'est à modifier
125 125
  *     - chaîne vide : Vide si tout s'est bien passé
126 126
  *     - chaîne : Texte d'un message d'erreur
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
  * @param int $id_parent
278 278
  *     Identifiant de la rubrique parente.
279 279
  *     0 pour la racine.
280
- * @return int
280
+ * @return boolean|string
281 281
  *     Identifiant de la rubrique crée
282 282
  **/
283 283
 function insert_rubrique($id_parent) {
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
  *     Identifiant de la rubrique à instituer
297 297
  * @param array|null $set
298 298
  *     Tableau qu'on peut proposer en lieu et place de _request()
299
- * @return bool|string
299
+ * @return string|false
300 300
  *     - false  : Aucune modification, aucun champ n'est à modifier
301 301
  *     - chaîne vide : Vide si tout s'est bien passé
302 302
  *     - chaîne : Texte d'un message d'erreur
Please login to merge, or discard this patch.
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Rubriques\Edition
17 17
  */
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/rubriques');
@@ -38,31 +38,31 @@  discard block
 block discarded – undo
38 38
  */
39 39
 function action_editer_rubrique_dist($arg = null) {
40 40
 
41
-	if (is_null($arg)) {
42
-		$securiser_action = charger_fonction('securiser_action', 'inc');
43
-		$arg = $securiser_action();
44
-	}
41
+    if (is_null($arg)) {
42
+        $securiser_action = charger_fonction('securiser_action', 'inc');
43
+        $arg = $securiser_action();
44
+    }
45 45
 
46
-	if (!$id_rubrique = intval($arg)) {
47
-		if ($arg != 'oui') {
48
-			include_spip('inc/headers');
49
-			redirige_url_ecrire();
50
-		}
51
-		$id_rubrique = rubrique_inserer(_request('id_parent'));
52
-	}
46
+    if (!$id_rubrique = intval($arg)) {
47
+        if ($arg != 'oui') {
48
+            include_spip('inc/headers');
49
+            redirige_url_ecrire();
50
+        }
51
+        $id_rubrique = rubrique_inserer(_request('id_parent'));
52
+    }
53 53
 
54
-	$err = rubrique_modifier($id_rubrique);
54
+    $err = rubrique_modifier($id_rubrique);
55 55
 
56
-	if (_request('redirect')) {
57
-		$redirect = parametre_url(
58
-			urldecode(_request('redirect')),
59
-			'id_rubrique', $id_rubrique, '&');
56
+    if (_request('redirect')) {
57
+        $redirect = parametre_url(
58
+            urldecode(_request('redirect')),
59
+            'id_rubrique', $id_rubrique, '&');
60 60
 
61
-		include_spip('inc/headers');
62
-		redirige_par_entete($redirect);
63
-	}
61
+        include_spip('inc/headers');
62
+        redirige_par_entete($redirect);
63
+    }
64 64
 
65
-	return array($id_rubrique, $err);
65
+    return array($id_rubrique, $err);
66 66
 }
67 67
 
68 68
 
@@ -77,40 +77,40 @@  discard block
 block discarded – undo
77 77
  *     Identifiant de la rubrique crée
78 78
  */
79 79
 function rubrique_inserer($id_parent, $set = null) {
80
-	$champs = array(
81
-		'titre' => _T('item_nouvelle_rubrique'),
82
-		'id_parent' => intval($id_parent),
83
-		'statut' => 'prepa'
84
-	);
85
-
86
-	if ($set) {
87
-		$champs = array_merge($champs, $set);
88
-	}
89
-
90
-	// Envoyer aux plugins
91
-	$champs = pipeline('pre_insertion',
92
-		array(
93
-			'args' => array(
94
-				'table' => 'spip_rubriques',
95
-			),
96
-			'data' => $champs
97
-		)
98
-	);
99
-
100
-	$id_rubrique = sql_insertq("spip_rubriques", $champs);
101
-	pipeline('post_insertion',
102
-		array(
103
-			'args' => array(
104
-				'table' => 'spip_rubriques',
105
-				'id_objet' => $id_rubrique
106
-			),
107
-			'data' => $champs
108
-		)
109
-	);
110
-	propager_les_secteurs();
111
-	calculer_langues_rubriques();
112
-
113
-	return $id_rubrique;
80
+    $champs = array(
81
+        'titre' => _T('item_nouvelle_rubrique'),
82
+        'id_parent' => intval($id_parent),
83
+        'statut' => 'prepa'
84
+    );
85
+
86
+    if ($set) {
87
+        $champs = array_merge($champs, $set);
88
+    }
89
+
90
+    // Envoyer aux plugins
91
+    $champs = pipeline('pre_insertion',
92
+        array(
93
+            'args' => array(
94
+                'table' => 'spip_rubriques',
95
+            ),
96
+            'data' => $champs
97
+        )
98
+    );
99
+
100
+    $id_rubrique = sql_insertq("spip_rubriques", $champs);
101
+    pipeline('post_insertion',
102
+        array(
103
+            'args' => array(
104
+                'table' => 'spip_rubriques',
105
+                'id_objet' => $id_rubrique
106
+            ),
107
+            'data' => $champs
108
+        )
109
+    );
110
+    propager_les_secteurs();
111
+    calculer_langues_rubriques();
112
+
113
+    return $id_rubrique;
114 114
 }
115 115
 
116 116
 /**
@@ -126,42 +126,42 @@  discard block
 block discarded – undo
126 126
  *     - chaîne : Texte d'un message d'erreur
127 127
  */
128 128
 function rubrique_modifier($id_rubrique, $set = null) {
129
-	include_spip('inc/autoriser');
130
-	include_spip('inc/filtres');
131
-
132
-	include_spip('inc/modifier');
133
-	$c = collecter_requests(
134
-	// white list
135
-		objet_info('rubrique', 'champs_editables'),
136
-		// black list
137
-		array('id_parent', 'confirme_deplace'),
138
-		// donnees eventuellement fournies
139
-		$set
140
-	);
141
-
142
-	if ($err = objet_modifier_champs('rubrique', $id_rubrique,
143
-		array(
144
-			'data' => $set,
145
-			'nonvide' => array('titre' => _T('titre_nouvelle_rubrique') . " " . _T('info_numero_abbreviation') . $id_rubrique)
146
-		),
147
-		$c)
148
-	) {
149
-		return $err;
150
-	}
151
-
152
-	$c = collecter_requests(array('id_parent', 'confirme_deplace'), array(), $set);
153
-	// Deplacer la rubrique
154
-	if (isset($c['id_parent'])) {
155
-		$err = rubrique_instituer($id_rubrique, $c);
156
-	}
157
-
158
-	// invalider les caches marques de cette rubrique
159
-	include_spip('inc/invalideur');
160
-	suivre_invalideur("id='rubrique/$id_rubrique'");
161
-	// et celui de menu_rubriques 
162
-	effacer_meta("date_calcul_rubriques");
163
-
164
-	return $err;
129
+    include_spip('inc/autoriser');
130
+    include_spip('inc/filtres');
131
+
132
+    include_spip('inc/modifier');
133
+    $c = collecter_requests(
134
+    // white list
135
+        objet_info('rubrique', 'champs_editables'),
136
+        // black list
137
+        array('id_parent', 'confirme_deplace'),
138
+        // donnees eventuellement fournies
139
+        $set
140
+    );
141
+
142
+    if ($err = objet_modifier_champs('rubrique', $id_rubrique,
143
+        array(
144
+            'data' => $set,
145
+            'nonvide' => array('titre' => _T('titre_nouvelle_rubrique') . " " . _T('info_numero_abbreviation') . $id_rubrique)
146
+        ),
147
+        $c)
148
+    ) {
149
+        return $err;
150
+    }
151
+
152
+    $c = collecter_requests(array('id_parent', 'confirme_deplace'), array(), $set);
153
+    // Deplacer la rubrique
154
+    if (isset($c['id_parent'])) {
155
+        $err = rubrique_instituer($id_rubrique, $c);
156
+    }
157
+
158
+    // invalider les caches marques de cette rubrique
159
+    include_spip('inc/invalideur');
160
+    suivre_invalideur("id='rubrique/$id_rubrique'");
161
+    // et celui de menu_rubriques 
162
+    effacer_meta("date_calcul_rubriques");
163
+
164
+    return $err;
165 165
 }
166 166
 
167 167
 /**
@@ -184,21 +184,21 @@  discard block
 block discarded – undo
184 184
  *     false si la confirmation du déplacement n'est pas présente
185 185
  */
186 186
 function editer_rubrique_breves($id_rubrique, $id_parent, $c = array()) {
187
-	if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
188
-		return true;
189
-	}
187
+    if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
188
+        return true;
189
+    }
190 190
 
191
-	if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
192
-		return false;
193
-	}
191
+    if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
192
+        return false;
193
+    }
194 194
 
195
-	if ($id_secteur = sql_getfetsel("id_secteur",
196
-		"spip_rubriques", "id_rubrique=$id_parent")
197
-	) {
198
-		sql_updateq("spip_breves", array("id_rubrique" => $id_secteur), "id_rubrique=$id_rubrique");
199
-	}
195
+    if ($id_secteur = sql_getfetsel("id_secteur",
196
+        "spip_rubriques", "id_rubrique=$id_parent")
197
+    ) {
198
+        sql_updateq("spip_breves", array("id_rubrique" => $id_secteur), "id_rubrique=$id_rubrique");
199
+    }
200 200
 
201
-	return true;
201
+    return true;
202 202
 }
203 203
 
204 204
 
@@ -220,51 +220,51 @@  discard block
 block discarded – undo
220 220
  *     Chaîne : Texte du message d'erreur
221 221
  */
222 222
 function rubrique_instituer($id_rubrique, $c) {
223
-	// traitement de la rubrique parente
224
-	// interdiction de deplacer vers ou a partir d'une rubrique
225
-	// qu'on n'administre pas.
226
-
227
-	if (null !== ($id_parent = $c['id_parent'])) {
228
-		$id_parent = intval($id_parent);
229
-		$filles = calcul_branche_in($id_rubrique);
230
-		if (strpos(",$id_parent,", ",$filles,") !== false) {
231
-			spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
232
-		} else {
233
-			$s = sql_fetsel("id_parent, statut", "spip_rubriques", "id_rubrique=$id_rubrique");
234
-			$old_parent = $s['id_parent'];
235
-
236
-			if (!($id_parent != $old_parent
237
-				and autoriser('publierdans', 'rubrique', $id_parent)
238
-				and autoriser('creerrubriquedans', 'rubrique', $id_parent)
239
-				and autoriser('publierdans', 'rubrique', $old_parent)
240
-			)
241
-			) {
242
-				if ($s['statut'] != 'new') {
243
-					spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
244
-				}
245
-			} elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
246
-				$statut_ancien = $s['statut'];
247
-				sql_updateq('spip_rubriques', array('id_parent' => $id_parent), "id_rubrique=$id_rubrique");
248
-
249
-
250
-				propager_les_secteurs();
251
-
252
-				// Deplacement d'une rubrique publiee ==> chgt general de leur statut
253
-				if ($statut_ancien == 'publie') {
254
-					calculer_rubriques_if($old_parent, array('id_rubrique' => $id_parent), $statut_ancien);
255
-				}
256
-				// Creation ou deplacement d'une rubrique non publiee
257
-				// invalider le cache de leur menu
258
-				elseif (!$statut_ancien || $old_parent != $id_parent) {
259
-					effacer_meta("date_calcul_rubriques");
260
-				}
261
-
262
-				calculer_langues_rubriques();
263
-			}
264
-		}
265
-	}
266
-
267
-	return ''; // pas d'erreur
223
+    // traitement de la rubrique parente
224
+    // interdiction de deplacer vers ou a partir d'une rubrique
225
+    // qu'on n'administre pas.
226
+
227
+    if (null !== ($id_parent = $c['id_parent'])) {
228
+        $id_parent = intval($id_parent);
229
+        $filles = calcul_branche_in($id_rubrique);
230
+        if (strpos(",$id_parent,", ",$filles,") !== false) {
231
+            spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
232
+        } else {
233
+            $s = sql_fetsel("id_parent, statut", "spip_rubriques", "id_rubrique=$id_rubrique");
234
+            $old_parent = $s['id_parent'];
235
+
236
+            if (!($id_parent != $old_parent
237
+                and autoriser('publierdans', 'rubrique', $id_parent)
238
+                and autoriser('creerrubriquedans', 'rubrique', $id_parent)
239
+                and autoriser('publierdans', 'rubrique', $old_parent)
240
+            )
241
+            ) {
242
+                if ($s['statut'] != 'new') {
243
+                    spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
244
+                }
245
+            } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
246
+                $statut_ancien = $s['statut'];
247
+                sql_updateq('spip_rubriques', array('id_parent' => $id_parent), "id_rubrique=$id_rubrique");
248
+
249
+
250
+                propager_les_secteurs();
251
+
252
+                // Deplacement d'une rubrique publiee ==> chgt general de leur statut
253
+                if ($statut_ancien == 'publie') {
254
+                    calculer_rubriques_if($old_parent, array('id_rubrique' => $id_parent), $statut_ancien);
255
+                }
256
+                // Creation ou deplacement d'une rubrique non publiee
257
+                // invalider le cache de leur menu
258
+                elseif (!$statut_ancien || $old_parent != $id_parent) {
259
+                    effacer_meta("date_calcul_rubriques");
260
+                }
261
+
262
+                calculer_langues_rubriques();
263
+            }
264
+        }
265
+    }
266
+
267
+    return ''; // pas d'erreur
268 268
 }
269 269
 
270 270
 /**
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
  *     Identifiant de la rubrique crée
282 282
  **/
283 283
 function insert_rubrique($id_parent) {
284
-	return rubrique_inserer($id_parent);
284
+    return rubrique_inserer($id_parent);
285 285
 }
286 286
 
287 287
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
  *     - chaîne : Texte d'un message d'erreur
303 303
  **/
304 304
 function revisions_rubriques($id_rubrique, $set = null) {
305
-	return rubrique_modifier($id_rubrique, $set);
305
+    return rubrique_modifier($id_rubrique, $set);
306 306
 }
307 307
 
308 308
 /**
@@ -321,5 +321,5 @@  discard block
 block discarded – undo
321 321
  *     Chaîne : Texte du message d'erreur
322 322
  **/
323 323
 function instituer_rubrique($id_rubrique, $c) {
324
-	return rubrique_instituer($id_rubrique, $c);
324
+    return rubrique_instituer($id_rubrique, $c);
325 325
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	if ($err = objet_modifier_champs('rubrique', $id_rubrique,
143 143
 		array(
144 144
 			'data' => $set,
145
-			'nonvide' => array('titre' => _T('titre_nouvelle_rubrique') . " " . _T('info_numero_abbreviation') . $id_rubrique)
145
+			'nonvide' => array('titre' => _T('titre_nouvelle_rubrique')." "._T('info_numero_abbreviation').$id_rubrique)
146 146
 		),
147 147
 		$c)
148 148
 	) {
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 			)
241 241
 			) {
242 242
 				if ($s['statut'] != 'new') {
243
-					spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
243
+					spip_log("deplacement de $id_rubrique vers $id_parent refuse a ".$GLOBALS['visiteur_session']['id_auteur'].' '.$GLOBALS['visiteur_session']['statut']);
244 244
 				}
245 245
 			} elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
246 246
 				$statut_ancien = $s['statut'];
Please login to merge, or discard this patch.
ecrire/action/inscrire_auteur.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -369,7 +369,7 @@
 block discarded – undo
369 369
  * Effacer le jeton d'un auteur apres utilisation
370 370
  *
371 371
  * @param int $id_auteur
372
- * @return bool
372
+ * @return boolean|string
373 373
  */
374 374
 function auteur_effacer_jeton($id_auteur) {
375 375
 	return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur));
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	}
56 56
 
57 57
 	include_spip('base/abstract_sql');
58
-	$res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email']));
58
+	$res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=".sql_quote($desc['email']));
59 59
 	// erreur ?
60 60
 	if (!$res) {
61 61
 		return _T('titre_probleme_technique');
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 		if (!sql_countsel('spip_auteurs', "login='$login'")) {
209 209
 			return $login;
210 210
 		}
211
-		$login = $login_base . $i;
211
+		$login = $login_base.$i;
212 212
 	}
213 213
 
214 214
 	return $login;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	$contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']);
238 238
 
239 239
 	$modele_mail = 'modeles/mail_inscription';
240
-	if (isset($options['modele_mail']) and $options['modele_mail']){
240
+	if (isset($options['modele_mail']) and $options['modele_mail']) {
241 241
 		$modele_mail = $options['modele_mail'];
242 242
 	}
243 243
 	$message = recuperer_fond($modele_mail, $contexte);
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
 	// s'assurer de l'unicite du jeton pour le couple (email,cookie)
342 342
 	do {
343 343
 		$jeton = creer_uniqid();
344
-		sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur));
345
-	} while (sql_countsel("spip_auteurs", "cookie_oubli=" . sql_quote($jeton)) > 1);
344
+		sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=".intval($id_auteur));
345
+	} while (sql_countsel("spip_auteurs", "cookie_oubli=".sql_quote($jeton)) > 1);
346 346
 
347 347
 	return $jeton;
348 348
 }
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	}
361 361
 
362 362
 	// on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter
363
-	$desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=" . sql_quote($jeton, '', 'string'));
363
+	$desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=".sql_quote($jeton, '', 'string'));
364 364
 
365 365
 	return $desc;
366 366
 }
@@ -372,5 +372,5 @@  discard block
 block discarded – undo
372 372
  * @return bool
373 373
  */
374 374
 function auteur_effacer_jeton($id_auteur) {
375
-	return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur));
375
+	return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=".intval($id_auteur));
376 376
 }
Please login to merge, or discard this patch.
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Inscription
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -38,68 +38,68 @@  discard block
 block discarded – undo
38 38
  * @return array|string
39 39
  */
40 40
 function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = array()) {
41
-	if (!is_array($options)) {
42
-		$options = array('id' => $options);
43
-	}
44
-
45
-	if (function_exists('test_inscription')) {
46
-		$f = 'test_inscription';
47
-	} else {
48
-		$f = 'test_inscription_dist';
49
-	}
50
-	$desc = $f($statut, $mail_complet, $nom, $options);
51
-
52
-	// erreur ?
53
-	if (!is_array($desc)) {
54
-		return _T($desc);
55
-	}
56
-
57
-	include_spip('base/abstract_sql');
58
-	$res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email']));
59
-	// erreur ?
60
-	if (!$res) {
61
-		return _T('titre_probleme_technique');
62
-	}
63
-
64
-	$row = sql_fetch($res);
65
-	sql_free($res);
66
-	if ($row) {
67
-		if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) {
68
-			$desc['id_auteur'] = $row['id_auteur'];
69
-			$desc = inscription_nouveau($desc);
70
-		} else {
71
-			$desc = $row;
72
-		}
73
-	} else // s'il n'existe pas deja, creer les identifiants
74
-	{
75
-		$desc = inscription_nouveau($desc);
76
-	}
77
-
78
-	// erreur ?
79
-	if (!is_array($desc)) {
80
-		return $desc;
81
-	}
82
-
83
-
84
-	// generer le mot de passe (ou le refaire si compte inutilise)
85
-	$desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']);
86
-
87
-	// attribuer un jeton pour confirmation par clic sur un lien
88
-	$desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']);
89
-
90
-	// charger de suite cette fonction, pour ses utilitaires
91
-	$envoyer_inscription = charger_fonction("envoyer_inscription", "");
92
-	list($sujet, $msg, $from, $head) = $envoyer_inscription($desc, $nom, $statut, $options);
93
-
94
-	$notifications = charger_fonction('notifications', 'inc');
95
-	notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head);
96
-
97
-	// Notifications
98
-	$notifications('inscription', $desc['id_auteur'],
99
-		array('nom' => $desc['nom'], 'email' => $desc['email'])
100
-	);
101
-
102
-	return $desc;
41
+    if (!is_array($options)) {
42
+        $options = array('id' => $options);
43
+    }
44
+
45
+    if (function_exists('test_inscription')) {
46
+        $f = 'test_inscription';
47
+    } else {
48
+        $f = 'test_inscription_dist';
49
+    }
50
+    $desc = $f($statut, $mail_complet, $nom, $options);
51
+
52
+    // erreur ?
53
+    if (!is_array($desc)) {
54
+        return _T($desc);
55
+    }
56
+
57
+    include_spip('base/abstract_sql');
58
+    $res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email']));
59
+    // erreur ?
60
+    if (!$res) {
61
+        return _T('titre_probleme_technique');
62
+    }
63
+
64
+    $row = sql_fetch($res);
65
+    sql_free($res);
66
+    if ($row) {
67
+        if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) {
68
+            $desc['id_auteur'] = $row['id_auteur'];
69
+            $desc = inscription_nouveau($desc);
70
+        } else {
71
+            $desc = $row;
72
+        }
73
+    } else // s'il n'existe pas deja, creer les identifiants
74
+    {
75
+        $desc = inscription_nouveau($desc);
76
+    }
77
+
78
+    // erreur ?
79
+    if (!is_array($desc)) {
80
+        return $desc;
81
+    }
82
+
83
+
84
+    // generer le mot de passe (ou le refaire si compte inutilise)
85
+    $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']);
86
+
87
+    // attribuer un jeton pour confirmation par clic sur un lien
88
+    $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']);
89
+
90
+    // charger de suite cette fonction, pour ses utilitaires
91
+    $envoyer_inscription = charger_fonction("envoyer_inscription", "");
92
+    list($sujet, $msg, $from, $head) = $envoyer_inscription($desc, $nom, $statut, $options);
93
+
94
+    $notifications = charger_fonction('notifications', 'inc');
95
+    notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head);
96
+
97
+    // Notifications
98
+    $notifications('inscription', $desc['id_auteur'],
99
+        array('nom' => $desc['nom'], 'email' => $desc['email'])
100
+    );
101
+
102
+    return $desc;
103 103
 }
104 104
 
105 105
 
@@ -122,23 +122,23 @@  discard block
 block discarded – undo
122 122
  *
123 123
  */
124 124
 function test_inscription_dist($statut, $mail, $nom, $options) {
125
-	include_spip('inc/filtres');
126
-	if (!$r = email_valide($mail)) {
127
-		return 'info_email_invalide';
128
-	}
129
-	$nom = trim(corriger_caracteres($nom));
130
-	$res = array('email' => $r, 'nom' => $nom, 'prefs' => $statut);
131
-	if (isset($options['login'])) {
132
-		$login = trim(corriger_caracteres($options['login']));
133
-		if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) {
134
-			$res['login'] = $login;
135
-		}
136
-	}
137
-	if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) {
138
-		return 'ecrire:info_login_trop_court';
139
-	}
140
-
141
-	return $res;
125
+    include_spip('inc/filtres');
126
+    if (!$r = email_valide($mail)) {
127
+        return 'info_email_invalide';
128
+    }
129
+    $nom = trim(corriger_caracteres($nom));
130
+    $res = array('email' => $r, 'nom' => $nom, 'prefs' => $statut);
131
+    if (isset($options['login'])) {
132
+        $login = trim(corriger_caracteres($options['login']));
133
+        if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) {
134
+            $res['login'] = $login;
135
+        }
136
+    }
137
+    if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) {
138
+        return 'ecrire:info_login_trop_court';
139
+    }
140
+
141
+    return $res;
142 142
 }
143 143
 
144 144
 
@@ -151,33 +151,33 @@  discard block
 block discarded – undo
151 151
  * @return mixed|string
152 152
  */
153 153
 function inscription_nouveau($desc) {
154
-	if (!isset($desc['login']) or !strlen($desc['login'])) {
155
-		$desc['login'] = test_login($desc['nom'], $desc['email']);
156
-	}
154
+    if (!isset($desc['login']) or !strlen($desc['login'])) {
155
+        $desc['login'] = test_login($desc['nom'], $desc['email']);
156
+    }
157 157
 
158
-	$desc['statut'] = 'nouveau';
159
-	include_spip('action/editer_auteur');
160
-	if (isset($desc['id_auteur'])) {
161
-		$id_auteur = $desc['id_auteur'];
162
-	} else {
163
-		$id_auteur = auteur_inserer();
164
-	}
158
+    $desc['statut'] = 'nouveau';
159
+    include_spip('action/editer_auteur');
160
+    if (isset($desc['id_auteur'])) {
161
+        $id_auteur = $desc['id_auteur'];
162
+    } else {
163
+        $id_auteur = auteur_inserer();
164
+    }
165 165
 
166
-	if (!$id_auteur) {
167
-		return _T('titre_probleme_technique');
168
-	}
166
+    if (!$id_auteur) {
167
+        return _T('titre_probleme_technique');
168
+    }
169 169
 
170
-	$desc['lang'] = $GLOBALS['spip_lang'];
170
+    $desc['lang'] = $GLOBALS['spip_lang'];
171 171
 
172
-	include_spip('inc/autoriser');
173
-	// lever l'autorisation pour pouvoir modifier le statut
174
-	autoriser_exception('modifier', 'auteur', $id_auteur);
175
-	auteur_modifier($id_auteur, $desc);
176
-	autoriser_exception('modifier', 'auteur', $id_auteur, false);
172
+    include_spip('inc/autoriser');
173
+    // lever l'autorisation pour pouvoir modifier le statut
174
+    autoriser_exception('modifier', 'auteur', $id_auteur);
175
+    auteur_modifier($id_auteur, $desc);
176
+    autoriser_exception('modifier', 'auteur', $id_auteur, false);
177 177
 
178
-	$desc['id_auteur'] = $id_auteur;
178
+    $desc['id_auteur'] = $id_auteur;
179 179
 
180
-	return $desc;
180
+    return $desc;
181 181
 }
182 182
 
183 183
 
@@ -189,29 +189,29 @@  discard block
 block discarded – undo
189 189
  * @return string
190 190
  */
191 191
 function test_login($nom, $mail) {
192
-	include_spip('inc/charsets');
193
-	$nom = strtolower(translitteration($nom));
194
-	$login_base = preg_replace("/[^\w\d_]/", "_", $nom);
195
-
196
-	// il faut eviter que le login soit vraiment trop court
197
-	if (strlen($login_base) < 3) {
198
-		$mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail)));
199
-		$login_base = preg_replace("/[^\w\d]/", "_", $mail);
200
-	}
201
-	if (strlen($login_base) < 3) {
202
-		$login_base = 'user';
203
-	}
204
-
205
-	$login = $login_base;
206
-
207
-	for ($i = 1; ; $i++) {
208
-		if (!sql_countsel('spip_auteurs', "login='$login'")) {
209
-			return $login;
210
-		}
211
-		$login = $login_base . $i;
212
-	}
213
-
214
-	return $login;
192
+    include_spip('inc/charsets');
193
+    $nom = strtolower(translitteration($nom));
194
+    $login_base = preg_replace("/[^\w\d_]/", "_", $nom);
195
+
196
+    // il faut eviter que le login soit vraiment trop court
197
+    if (strlen($login_base) < 3) {
198
+        $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail)));
199
+        $login_base = preg_replace("/[^\w\d]/", "_", $mail);
200
+    }
201
+    if (strlen($login_base) < 3) {
202
+        $login_base = 'user';
203
+    }
204
+
205
+    $login = $login_base;
206
+
207
+    for ($i = 1; ; $i++) {
208
+        if (!sql_countsel('spip_auteurs', "login='$login'")) {
209
+            return $login;
210
+        }
211
+        $login = $login_base . $i;
212
+    }
213
+
214
+    return $login;
215 215
 }
216 216
 
217 217
 
@@ -229,22 +229,22 @@  discard block
 block discarded – undo
229 229
  */
230 230
 function envoyer_inscription_dist($desc, $nom, $mode, $options = array()) {
231 231
 
232
-	$contexte = array_merge($desc, $options);
233
-	$contexte['nom'] = $nom;
234
-	$contexte['mode'] = $mode;
235
-	$contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true);
236
-	$contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']);
237
-	$contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']);
238
-
239
-	$modele_mail = 'modeles/mail_inscription';
240
-	if (isset($options['modele_mail']) and $options['modele_mail']){
241
-		$modele_mail = $options['modele_mail'];
242
-	}
243
-	$message = recuperer_fond($modele_mail, $contexte);
244
-	$from = (isset($options['from']) ? $options['from'] : null);
245
-	$head = null;
246
-
247
-	return array("", $message, $from, $head);
232
+    $contexte = array_merge($desc, $options);
233
+    $contexte['nom'] = $nom;
234
+    $contexte['mode'] = $mode;
235
+    $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true);
236
+    $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']);
237
+    $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']);
238
+
239
+    $modele_mail = 'modeles/mail_inscription';
240
+    if (isset($options['modele_mail']) and $options['modele_mail']){
241
+        $modele_mail = $options['modele_mail'];
242
+    }
243
+    $message = recuperer_fond($modele_mail, $contexte);
244
+    $from = (isset($options['from']) ? $options['from'] : null);
245
+    $head = null;
246
+
247
+    return array("", $message, $from, $head);
248 248
 }
249 249
 
250 250
 
@@ -255,12 +255,12 @@  discard block
 block discarded – undo
255 255
  * @return string
256 256
  */
257 257
 function creer_pass_pour_auteur($id_auteur) {
258
-	include_spip('inc/acces');
259
-	$pass = creer_pass_aleatoire(16, $id_auteur);
260
-	include_spip('action/editer_auteur');
261
-	auteur_instituer($id_auteur, array('pass' => $pass));
258
+    include_spip('inc/acces');
259
+    $pass = creer_pass_aleatoire(16, $id_auteur);
260
+    include_spip('action/editer_auteur');
261
+    auteur_instituer($id_auteur, array('pass' => $pass));
262 262
 
263
-	return $pass;
263
+    return $pass;
264 264
 }
265 265
 
266 266
 /**
@@ -273,17 +273,17 @@  discard block
 block discarded – undo
273 273
  * @return string
274 274
  */
275 275
 function tester_statut_inscription($statut_tmp, $id) {
276
-	include_spip('inc/autoriser');
277
-	if ($statut_tmp) {
278
-		return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : '';
279
-	} elseif (
280
-		autoriser('inscrireauteur', $statut_tmp = "1comite", $id)
281
-		or autoriser('inscrireauteur', $statut_tmp = "6forum", $id)
282
-	) {
283
-		return $statut_tmp;
284
-	}
285
-
286
-	return '';
276
+    include_spip('inc/autoriser');
277
+    if ($statut_tmp) {
278
+        return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : '';
279
+    } elseif (
280
+        autoriser('inscrireauteur', $statut_tmp = "1comite", $id)
281
+        or autoriser('inscrireauteur', $statut_tmp = "6forum", $id)
282
+    ) {
283
+        return $statut_tmp;
284
+    }
285
+
286
+    return '';
287 287
 }
288 288
 
289 289
 
@@ -297,35 +297,35 @@  discard block
 block discarded – undo
297 297
  * @return array
298 298
  */
299 299
 function confirmer_statut_inscription($auteur) {
300
-	// securite
301
-	if ($auteur['statut'] != 'nouveau') {
302
-		return $auteur;
303
-	}
304
-
305
-	$s = $auteur['prefs'];
306
-	// securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize)
307
-	if (!preg_match(',^\w+$,', $s)) {
308
-		$s = '6forum';
309
-	}
310
-	include_spip('inc/autoriser');
311
-	if (!autoriser('inscrireauteur', $s)) {
312
-		return $auteur;
313
-	}
314
-
315
-	include_spip('inc/autoriser');
316
-	// accorder l'autorisation de modif du statut auteur
317
-	autoriser_exception('modifier', 'auteur', $auteur['id_auteur']);
318
-	include_spip('action/editer_auteur');
319
-	// changer le statut
320
-	auteur_modifier($auteur['id_auteur'], array('statut' => $s));
321
-	unset($_COOKIE['spip_session']); // forcer la maj de la session
322
-	// lever l'autorisation de modif du statut auteur
323
-	autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false);
324
-
325
-	// mettre a jour le statut
326
-	$auteur['statut'] = $s;
327
-
328
-	return $auteur;
300
+    // securite
301
+    if ($auteur['statut'] != 'nouveau') {
302
+        return $auteur;
303
+    }
304
+
305
+    $s = $auteur['prefs'];
306
+    // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize)
307
+    if (!preg_match(',^\w+$,', $s)) {
308
+        $s = '6forum';
309
+    }
310
+    include_spip('inc/autoriser');
311
+    if (!autoriser('inscrireauteur', $s)) {
312
+        return $auteur;
313
+    }
314
+
315
+    include_spip('inc/autoriser');
316
+    // accorder l'autorisation de modif du statut auteur
317
+    autoriser_exception('modifier', 'auteur', $auteur['id_auteur']);
318
+    include_spip('action/editer_auteur');
319
+    // changer le statut
320
+    auteur_modifier($auteur['id_auteur'], array('statut' => $s));
321
+    unset($_COOKIE['spip_session']); // forcer la maj de la session
322
+    // lever l'autorisation de modif du statut auteur
323
+    autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false);
324
+
325
+    // mettre a jour le statut
326
+    $auteur['statut'] = $s;
327
+
328
+    return $auteur;
329 329
 }
330 330
 
331 331
 
@@ -337,14 +337,14 @@  discard block
 block discarded – undo
337 337
  * @return string
338 338
  */
339 339
 function auteur_attribuer_jeton($id_auteur) {
340
-	include_spip('inc/acces');
341
-	// s'assurer de l'unicite du jeton pour le couple (email,cookie)
342
-	do {
343
-		$jeton = creer_uniqid();
344
-		sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur));
345
-	} while (sql_countsel("spip_auteurs", "cookie_oubli=" . sql_quote($jeton)) > 1);
346
-
347
-	return $jeton;
340
+    include_spip('inc/acces');
341
+    // s'assurer de l'unicite du jeton pour le couple (email,cookie)
342
+    do {
343
+        $jeton = creer_uniqid();
344
+        sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur));
345
+    } while (sql_countsel("spip_auteurs", "cookie_oubli=" . sql_quote($jeton)) > 1);
346
+
347
+    return $jeton;
348 348
 }
349 349
 
350 350
 /**
@@ -354,15 +354,15 @@  discard block
 block discarded – undo
354 354
  * @return array|bool
355 355
  */
356 356
 function auteur_verifier_jeton($jeton) {
357
-	// refuser un jeton corrompu
358
-	if (preg_match(',[^0-9a-f.],i', $jeton)) {
359
-		return false;
360
-	}
357
+    // refuser un jeton corrompu
358
+    if (preg_match(',[^0-9a-f.],i', $jeton)) {
359
+        return false;
360
+    }
361 361
 
362
-	// on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter
363
-	$desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=" . sql_quote($jeton, '', 'string'));
362
+    // on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter
363
+    $desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=" . sql_quote($jeton, '', 'string'));
364 364
 
365
-	return $desc;
365
+    return $desc;
366 366
 }
367 367
 
368 368
 /**
@@ -372,5 +372,5 @@  discard block
 block discarded – undo
372 372
  * @return bool
373 373
  */
374 374
 function auteur_effacer_jeton($id_auteur) {
375
-	return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur));
375
+    return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur));
376 376
 }
Please login to merge, or discard this patch.
ecrire/auth/ldap.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@
 block discarded – undo
314 314
  * @param $new_pass
315 315
  * @param $id_auteur
316 316
  * @param string $serveur
317
- * @return bool
317
+ * @return string|boolean
318 318
  *    Informe du succès ou de l'echec du changement du mot de passe
319 319
  */
320 320
 function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') {
Please login to merge, or discard this patch.
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok
@@ -25,12 +25,12 @@  discard block
 block discarded – undo
25 25
 // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login
26 26
 // ne pas ecraser une definition perso dans mes_options
27 27
 if (!isset($GLOBALS['ldap_attributes']) or !is_array($GLOBALS['ldap_attributes'])) {
28
-	$GLOBALS['ldap_attributes'] = array(
29
-		'login' => array('sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'),
30
-		'nom' => "cn",
31
-		'email' => "mail",
32
-		'bio' => "description"
33
-	);
28
+    $GLOBALS['ldap_attributes'] = array(
29
+        'login' => array('sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'),
30
+        'nom' => "cn",
31
+        'email' => "mail",
32
+        'bio' => "description"
33
+    );
34 34
 }
35 35
 
36 36
 /**
@@ -56,49 +56,49 @@  discard block
 block discarded – undo
56 56
  */
57 57
 function auth_ldap_dist($login, $pass, $serveur = '', $phpauth = false) {
58 58
 
59
-	#spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent"));
60
-
61
-	// Utilisateur connu ?
62
-	// si http auth, inutile de reauthentifier: cela
63
-	// ne marchera pas avec auth http autre que basic.
64
-	$checkpass = isset($_SERVER["REMOTE_USER"]) ? false : true;
65
-	if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) {
66
-		return array();
67
-	}
68
-	$credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass);
69
-
70
-	// Si l'utilisateur figure deja dans la base, y recuperer les infos
71
-	$r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur);
72
-
73
-	if ($r) {
74
-		return array_merge($r, $credentials_ldap);
75
-	}
76
-
77
-	// sinon importer les infos depuis LDAP, 
78
-
79
-	if ($GLOBALS['meta']["ldap_statut_import"]
80
-		and $desc = auth_ldap_retrouver($dn, array(), $serveur)
81
-	) {
82
-		// rajouter le statut indique  a l'install
83
-		$desc['statut'] = $GLOBALS['meta']["ldap_statut_import"];
84
-		$desc['login'] = $login;
85
-		$desc['source'] = 'ldap';
86
-		$desc['pass'] = '';
87
-
88
-		$r = sql_insertq('spip_auteurs', $desc, '', $serveur);
89
-	}
90
-
91
-	if ($r) {
92
-		return array_merge(
93
-			$credentials_ldap,
94
-			sql_fetsel("*", "spip_auteurs", "id_auteur=" . intval($r), '', '', '', '', $serveur)
95
-		);
96
-	}
97
-
98
-	// sinon echec
99
-	spip_log("Creation de l'auteur '$login' impossible");
100
-
101
-	return array();
59
+    #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent"));
60
+
61
+    // Utilisateur connu ?
62
+    // si http auth, inutile de reauthentifier: cela
63
+    // ne marchera pas avec auth http autre que basic.
64
+    $checkpass = isset($_SERVER["REMOTE_USER"]) ? false : true;
65
+    if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) {
66
+        return array();
67
+    }
68
+    $credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass);
69
+
70
+    // Si l'utilisateur figure deja dans la base, y recuperer les infos
71
+    $r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur);
72
+
73
+    if ($r) {
74
+        return array_merge($r, $credentials_ldap);
75
+    }
76
+
77
+    // sinon importer les infos depuis LDAP, 
78
+
79
+    if ($GLOBALS['meta']["ldap_statut_import"]
80
+        and $desc = auth_ldap_retrouver($dn, array(), $serveur)
81
+    ) {
82
+        // rajouter le statut indique  a l'install
83
+        $desc['statut'] = $GLOBALS['meta']["ldap_statut_import"];
84
+        $desc['login'] = $login;
85
+        $desc['source'] = 'ldap';
86
+        $desc['pass'] = '';
87
+
88
+        $r = sql_insertq('spip_auteurs', $desc, '', $serveur);
89
+    }
90
+
91
+    if ($r) {
92
+        return array_merge(
93
+            $credentials_ldap,
94
+            sql_fetsel("*", "spip_auteurs", "id_auteur=" . intval($r), '', '', '', '', $serveur)
95
+        );
96
+    }
97
+
98
+    // sinon echec
99
+    spip_log("Creation de l'auteur '$login' impossible");
100
+
101
+    return array();
102 102
 }
103 103
 
104 104
 /**
@@ -112,36 +112,36 @@  discard block
 block discarded – undo
112 112
  * @return array
113 113
  */
114 114
 function auth_ldap_connect($serveur = '') {
115
-	include_spip('base/connect_sql');
116
-	static $connexions_ldap = array();
117
-	if (isset($connexions_ldap[$serveur])) {
118
-		return $connexions_ldap[$serveur];
119
-	}
120
-	$connexion = spip_connect($serveur);
121
-	if (!is_array($connexion['ldap'])) {
122
-		if ($connexion['authentification']['ldap']) {
123
-			$f = _DIR_CONNECT . $connexion['authentification']['ldap'];
124
-			unset($GLOBALS['ldap_link']);
125
-			if (is_readable($f)) {
126
-				include_once($f);
127
-			};
128
-			if (isset($GLOBALS['ldap_link'])) {
129
-				$connexion['ldap'] = array(
130
-					'link' => $GLOBALS['ldap_link'],
131
-					'base' => $GLOBALS['ldap_base']
132
-				);
133
-			} else {
134
-				spip_log("connection LDAP $serveur mal definie dans $f");
135
-			}
136
-			if (isset($GLOBALS['ldap_champs'])) {
137
-				$connexion['ldap']['attributes'] = $GLOBALS['ldap_champs'];
138
-			}
139
-		} else {
140
-			spip_log("connection LDAP $serveur inconnue");
141
-		}
142
-	}
143
-
144
-	return $connexions_ldap[$serveur] = $connexion['ldap'];
115
+    include_spip('base/connect_sql');
116
+    static $connexions_ldap = array();
117
+    if (isset($connexions_ldap[$serveur])) {
118
+        return $connexions_ldap[$serveur];
119
+    }
120
+    $connexion = spip_connect($serveur);
121
+    if (!is_array($connexion['ldap'])) {
122
+        if ($connexion['authentification']['ldap']) {
123
+            $f = _DIR_CONNECT . $connexion['authentification']['ldap'];
124
+            unset($GLOBALS['ldap_link']);
125
+            if (is_readable($f)) {
126
+                include_once($f);
127
+            };
128
+            if (isset($GLOBALS['ldap_link'])) {
129
+                $connexion['ldap'] = array(
130
+                    'link' => $GLOBALS['ldap_link'],
131
+                    'base' => $GLOBALS['ldap_base']
132
+                );
133
+            } else {
134
+                spip_log("connection LDAP $serveur mal definie dans $f");
135
+            }
136
+            if (isset($GLOBALS['ldap_champs'])) {
137
+                $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs'];
138
+            }
139
+        } else {
140
+            spip_log("connection LDAP $serveur inconnue");
141
+        }
142
+    }
143
+
144
+    return $connexions_ldap[$serveur] = $connexion['ldap'];
145 145
 }
146 146
 
147 147
 /**
@@ -155,52 +155,52 @@  discard block
 block discarded – undo
155 155
  *    Le login trouvé ou chaine vide si non trouvé
156 156
  */
157 157
 function auth_ldap_search($login, $pass, $checkpass = true, $serveur = '') {
158
-	// Securite anti-injection et contre un serveur LDAP laxiste
159
-	$login_search = preg_replace("/[^-@._\s\d\w]/", "", $login);
160
-	if (!strlen($login_search) or ($checkpass and !strlen($pass))) {
161
-		return '';
162
-	}
163
-
164
-	// verifier la connexion
165
-	if (!$ldap = auth_ldap_connect($serveur)) {
166
-		return '';
167
-	}
168
-
169
-	$ldap_link = isset($ldap['link']) ? $ldap['link'] : null;
170
-	$ldap_base = isset($ldap['base']) ? $ldap['base'] : null;
171
-	$desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ;
172
-
173
-	$logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']);
174
-
175
-	// Tenter une recherche pour essayer de retrouver le DN
176
-	foreach ($logins as $att) {
177
-		$result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", array("dn"));
178
-		$info = @ldap_get_entries($ldap_link, $result);
179
-		// Ne pas accepter les resultats si plus d'une entree
180
-		// (on veut un attribut unique)
181
-
182
-		if (is_array($info) and $info['count'] == 1) {
183
-			$dn = $info[0]['dn'];
184
-			if (!$checkpass) {
185
-				return $dn;
186
-			}
187
-			if (@ldap_bind($ldap_link, $dn, $pass)) {
188
-				return $dn;
189
-			}
190
-		}
191
-	}
192
-
193
-	if ($checkpass and !isset($dn)) {
194
-		// Si echec, essayer de deviner le DN
195
-		foreach ($logins as $att) {
196
-			$dn = "$att=$login_search, $ldap_base";
197
-			if (@ldap_bind($ldap_link, $dn, $pass)) {
198
-				return "$att=$login_search, $ldap_base";
199
-			}
200
-		}
201
-	}
202
-
203
-	return '';
158
+    // Securite anti-injection et contre un serveur LDAP laxiste
159
+    $login_search = preg_replace("/[^-@._\s\d\w]/", "", $login);
160
+    if (!strlen($login_search) or ($checkpass and !strlen($pass))) {
161
+        return '';
162
+    }
163
+
164
+    // verifier la connexion
165
+    if (!$ldap = auth_ldap_connect($serveur)) {
166
+        return '';
167
+    }
168
+
169
+    $ldap_link = isset($ldap['link']) ? $ldap['link'] : null;
170
+    $ldap_base = isset($ldap['base']) ? $ldap['base'] : null;
171
+    $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ;
172
+
173
+    $logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']);
174
+
175
+    // Tenter une recherche pour essayer de retrouver le DN
176
+    foreach ($logins as $att) {
177
+        $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", array("dn"));
178
+        $info = @ldap_get_entries($ldap_link, $result);
179
+        // Ne pas accepter les resultats si plus d'une entree
180
+        // (on veut un attribut unique)
181
+
182
+        if (is_array($info) and $info['count'] == 1) {
183
+            $dn = $info[0]['dn'];
184
+            if (!$checkpass) {
185
+                return $dn;
186
+            }
187
+            if (@ldap_bind($ldap_link, $dn, $pass)) {
188
+                return $dn;
189
+            }
190
+        }
191
+    }
192
+
193
+    if ($checkpass and !isset($dn)) {
194
+        // Si echec, essayer de deviner le DN
195
+        foreach ($logins as $att) {
196
+            $dn = "$att=$login_search, $ldap_base";
197
+            if (@ldap_bind($ldap_link, $dn, $pass)) {
198
+                return "$att=$login_search, $ldap_base";
199
+            }
200
+        }
201
+    }
202
+
203
+    return '';
204 204
 }
205 205
 
206 206
 /**
@@ -212,40 +212,40 @@  discard block
 block discarded – undo
212 212
  * @return array
213 213
  */
214 214
 function auth_ldap_retrouver($dn, $desc = array(), $serveur = '') {
215
-	// Lire les infos sur l'utilisateur a partir de son DN depuis LDAP
215
+    // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP
216 216
 
217
-	if (!$ldap = spip_connect_ldap($serveur)) {
218
-		spip_log("ldap $serveur injoignable");
217
+    if (!$ldap = spip_connect_ldap($serveur)) {
218
+        spip_log("ldap $serveur injoignable");
219 219
 
220
-		return array();
221
-	}
220
+        return array();
221
+    }
222 222
 
223
-	$ldap_link = $ldap['link'];
224
-	if (!$desc) {
225
-		$desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'];
226
-		unset($desc['login']);
227
-	}
228
-	$result = @ldap_read($ldap_link, $dn, "objectClass=*", array_values($desc));
223
+    $ldap_link = $ldap['link'];
224
+    if (!$desc) {
225
+        $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'];
226
+        unset($desc['login']);
227
+    }
228
+    $result = @ldap_read($ldap_link, $dn, "objectClass=*", array_values($desc));
229 229
 
230
-	if (!$result) {
231
-		return array();
232
-	}
230
+    if (!$result) {
231
+        return array();
232
+    }
233 233
 
234
-	// Recuperer les donnees du premier (unique?) compte de l'auteur
235
-	$val = @ldap_get_entries($ldap_link, $result);
236
-	if (!is_array($val) or !is_array($val[0])) {
237
-		return array();
238
-	}
239
-	$val = $val[0];
234
+    // Recuperer les donnees du premier (unique?) compte de l'auteur
235
+    $val = @ldap_get_entries($ldap_link, $result);
236
+    if (!is_array($val) or !is_array($val[0])) {
237
+        return array();
238
+    }
239
+    $val = $val[0];
240 240
 
241
-	// Convertir depuis UTF-8 (jeu de caracteres par defaut)
242
-	include_spip('inc/charsets');
241
+    // Convertir depuis UTF-8 (jeu de caracteres par defaut)
242
+    include_spip('inc/charsets');
243 243
 
244
-	foreach ($desc as $k => $v) {
245
-		$desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8');
246
-	}
244
+    foreach ($desc as $k => $v) {
245
+        $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8');
246
+    }
247 247
 
248
-	return $desc;
248
+    return $desc;
249 249
 }
250 250
 
251 251
 
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
  * @return string
258 258
  */
259 259
 function auth_ldap_retrouver_login($login, $serveur = '') {
260
-	return auth_ldap_search($login, '', false, $serveur) ? $login : '';
260
+    return auth_ldap_search($login, '', false, $serveur) ? $login : '';
261 261
 }
262 262
 
263 263
 /**
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
  *   Message d'erreur si login non valide, chaîne vide sinon
278 278
  */
279 279
 function auth_ldap_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') {
280
-	include_spip('auth/spip');
280
+    include_spip('auth/spip');
281 281
 
282
-	return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur);
282
+    return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur);
283 283
 }
284 284
 
285 285
 /**
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
  *   ```
301 301
  */
302 302
 function auth_ldap_autoriser_modifier_pass($serveur = '') {
303
-	return true;
303
+    return true;
304 304
 }
305 305
 
306 306
 /**
@@ -318,23 +318,23 @@  discard block
 block discarded – undo
318 318
  *    Informe du succès ou de l'echec du changement du mot de passe
319 319
  */
320 320
 function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') {
321
-	if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
322
-		return false;
323
-	}
324
-	if (!$ldap = auth_ldap_connect($serveur)) {
325
-		return '';
326
-	}
327
-	$link = $ldap['link'];
328
-	include_spip("inc/session");
329
-	$dn = session_get('ldap_dn');
330
-	if ('' == $dn) {
331
-		return false;
332
-	}
333
-	if (!ldap_bind($link, $dn, session_get('ldap_password'))) {
334
-		return false;
335
-	}
336
-	$encoded_pass = "{MD5}" . base64_encode(pack("H*", md5($new_pass)));
337
-	$success = ldap_mod_replace($link, $dn, array('userPassword' => $encoded_pass));
338
-
339
-	return $success;
321
+    if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
322
+        return false;
323
+    }
324
+    if (!$ldap = auth_ldap_connect($serveur)) {
325
+        return '';
326
+    }
327
+    $link = $ldap['link'];
328
+    include_spip("inc/session");
329
+    $dn = session_get('ldap_dn');
330
+    if ('' == $dn) {
331
+        return false;
332
+    }
333
+    if (!ldap_bind($link, $dn, session_get('ldap_password'))) {
334
+        return false;
335
+    }
336
+    $encoded_pass = "{MD5}" . base64_encode(pack("H*", md5($new_pass)));
337
+    $success = ldap_mod_replace($link, $dn, array('userPassword' => $encoded_pass));
338
+
339
+    return $success;
340 340
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	$credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass);
69 69
 
70 70
 	// Si l'utilisateur figure deja dans la base, y recuperer les infos
71
-	$r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur);
71
+	$r = sql_fetsel("*", "spip_auteurs", "login=".sql_quote($login)." AND source='ldap'", '', '', '', '', $serveur);
72 72
 
73 73
 	if ($r) {
74 74
 		return array_merge($r, $credentials_ldap);
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	if ($r) {
92 92
 		return array_merge(
93 93
 			$credentials_ldap,
94
-			sql_fetsel("*", "spip_auteurs", "id_auteur=" . intval($r), '', '', '', '', $serveur)
94
+			sql_fetsel("*", "spip_auteurs", "id_auteur=".intval($r), '', '', '', '', $serveur)
95 95
 		);
96 96
 	}
97 97
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	$connexion = spip_connect($serveur);
121 121
 	if (!is_array($connexion['ldap'])) {
122 122
 		if ($connexion['authentification']['ldap']) {
123
-			$f = _DIR_CONNECT . $connexion['authentification']['ldap'];
123
+			$f = _DIR_CONNECT.$connexion['authentification']['ldap'];
124 124
 			unset($GLOBALS['ldap_link']);
125 125
 			if (is_readable($f)) {
126 126
 				include_once($f);
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 
169 169
 	$ldap_link = isset($ldap['link']) ? $ldap['link'] : null;
170 170
 	$ldap_base = isset($ldap['base']) ? $ldap['base'] : null;
171
-	$desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ;
171
+	$desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'];
172 172
 
173 173
 	$logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']);
174 174
 
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	if (!ldap_bind($link, $dn, session_get('ldap_password'))) {
334 334
 		return false;
335 335
 	}
336
-	$encoded_pass = "{MD5}" . base64_encode(pack("H*", md5($new_pass)));
336
+	$encoded_pass = "{MD5}".base64_encode(pack("H*", md5($new_pass)));
337 337
 	$success = ldap_mod_replace($link, $dn, array('userPassword' => $encoded_pass));
338 338
 
339 339
 	return $success;
Please login to merge, or discard this patch.
ecrire/balise/formulaire_.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
  * @see trouver_fond()
61 61
  * @param string $form
62 62
  *     Nom du formulaire
63
- * @return string|bool
63
+ * @return string|false
64 64
  *     - string : chemin du squelette
65 65
  *     - false : pas de squelette trouvé
66 66
  **/
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Formulaires
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 include_spip('inc/filtres');
@@ -34,24 +34,24 @@  discard block
 block discarded – undo
34 34
  *     Saisie protégée
35 35
  **/
36 36
 function protege_champ($texte) {
37
-	if (is_array($texte)) {
38
-		$texte = array_map('protege_champ', $texte);
39
-	} else {
40
-		// ne pas corrompre une valeur serialize
41
-		if ((preg_match(",^[abis]:\d+[:;],", $texte) and @unserialize($texte) != false) or is_null($texte)) {
42
-			return $texte;
43
-		}
44
-		if (is_string($texte)
45
-			and $texte
46
-			and strpbrk($texte, "&\"'<>") !== false
47
-		) {
48
-			$texte = spip_htmlspecialchars($texte, ENT_QUOTES);
49
-		} elseif (is_bool($texte)) {
50
-			$texte = ($texte ? '1' : '');
51
-		}
52
-	}
53
-
54
-	return $texte;
37
+    if (is_array($texte)) {
38
+        $texte = array_map('protege_champ', $texte);
39
+    } else {
40
+        // ne pas corrompre une valeur serialize
41
+        if ((preg_match(",^[abis]:\d+[:;],", $texte) and @unserialize($texte) != false) or is_null($texte)) {
42
+            return $texte;
43
+        }
44
+        if (is_string($texte)
45
+            and $texte
46
+            and strpbrk($texte, "&\"'<>") !== false
47
+        ) {
48
+            $texte = spip_htmlspecialchars($texte, ENT_QUOTES);
49
+        } elseif (is_bool($texte)) {
50
+            $texte = ($texte ? '1' : '');
51
+        }
52
+    }
53
+
54
+    return $texte;
55 55
 }
56 56
 
57 57
 /**
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
  *     - false : pas de squelette trouvé
66 66
  **/
67 67
 function existe_formulaire($form) {
68
-	if (substr($form, 0, 11) == "FORMULAIRE_") {
69
-		$form = strtolower(substr($form, 11));
70
-	} else {
71
-		$form = strtolower($form);
72
-	}
68
+    if (substr($form, 0, 11) == "FORMULAIRE_") {
69
+        $form = strtolower(substr($form, 11));
70
+    } else {
71
+        $form = strtolower($form);
72
+    }
73 73
 
74
-	if (!$form) {
75
-		return '';
76
-	} // on ne sait pas, le nom du formulaire n'est pas fourni ici
74
+    if (!$form) {
75
+        return '';
76
+    } // on ne sait pas, le nom du formulaire n'est pas fourni ici
77 77
 
78
-	return trouver_fond($form, 'formulaires/') ? $form : false;
78
+    return trouver_fond($form, 'formulaires/') ? $form : false;
79 79
 }
80 80
 
81 81
 
@@ -91,17 +91,17 @@  discard block
 block discarded – undo
91 91
  **/
92 92
 function balise_FORMULAIRE__dist($p) {
93 93
 
94
-	// Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide.
95
-	// mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer
96
-	if (existe_formulaire($p->nom_champ) === false) {
97
-		$p->code = "''";
98
-		$p->interdire_scripts = false;
94
+    // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide.
95
+    // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer
96
+    if (existe_formulaire($p->nom_champ) === false) {
97
+        $p->code = "''";
98
+        $p->interdire_scripts = false;
99 99
 
100
-		return $p;
101
-	}
100
+        return $p;
101
+    }
102 102
 
103
-	// sinon renvoyer un code php dynamique
104
-	return calculer_balise_dynamique($p, $p->nom_champ, array());
103
+    // sinon renvoyer un code php dynamique
104
+    return calculer_balise_dynamique($p, $p->nom_champ, array());
105 105
 }
106 106
 
107 107
 /**
@@ -114,27 +114,27 @@  discard block
 block discarded – undo
114 114
  *     - string : texte à afficher directement
115 115
  */
116 116
 function balise_FORMULAIRE__dyn($form) {
117
-	$form = existe_formulaire($form);
118
-	if (!$form) {
119
-		return '';
120
-	}
121
-
122
-	// deux moyen d'arriver ici : 
123
-	// soit #FORMULAIRE_XX reroute avec 'FORMULAIRE_XX' ajoute en premier arg
124
-	// soit #FORMULAIRE_{xx}
125
-
126
-	// recuperer les arguments passes a la balise
127
-	// on enleve le premier qui est le nom de la balise 
128
-	// deja recupere ci-dessus
129
-
130
-	$args = func_get_args();
131
-	array_shift($args);
132
-	$contexte = balise_FORMULAIRE__contexte($form, $args);
133
-	if (!is_array($contexte)) {
134
-		return $contexte;
135
-	}
136
-
137
-	return array("formulaires/$form", 3600, $contexte);
117
+    $form = existe_formulaire($form);
118
+    if (!$form) {
119
+        return '';
120
+    }
121
+
122
+    // deux moyen d'arriver ici : 
123
+    // soit #FORMULAIRE_XX reroute avec 'FORMULAIRE_XX' ajoute en premier arg
124
+    // soit #FORMULAIRE_{xx}
125
+
126
+    // recuperer les arguments passes a la balise
127
+    // on enleve le premier qui est le nom de la balise 
128
+    // deja recupere ci-dessus
129
+
130
+    $args = func_get_args();
131
+    array_shift($args);
132
+    $contexte = balise_FORMULAIRE__contexte($form, $args);
133
+    if (!is_array($contexte)) {
134
+        return $contexte;
135
+    }
136
+
137
+    return array("formulaires/$form", 3600, $contexte);
138 138
 }
139 139
 
140 140
 /**
@@ -148,120 +148,120 @@  discard block
 block discarded – undo
148 148
  *     Contexte d'environnement à envoyer au squelette
149 149
  **/
150 150
 function balise_FORMULAIRE__contexte($form, $args) {
151
-	// tester si ce formulaire vient d'etre poste (memes arguments)
152
-	// pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page
153
-	// si poste, on recupere les erreurs
154
-
155
-	$je_suis_poste = false;
156
-	if ($post_form = _request('formulaire_action')
157
-		and $post_form == $form
158
-		and $p = _request('formulaire_action_args')
159
-		and is_array($p = decoder_contexte_ajax($p, $post_form))
160
-	) {
161
-		// enlever le faux attribut de langue masque
162
-		array_shift($p);
163
-		if (formulaire__identifier($form, $args, $p)) {
164
-			$je_suis_poste = true;
165
-		}
166
-	}
167
-
168
-	$editable = true;
169
-	$erreurs = $post = array();
170
-	if ($je_suis_poste) {
171
-		$post = traiter_formulaires_dynamiques(true);
172
-		$e = "erreurs_$form";
173
-		$erreurs = isset($post[$e]) ? $post[$e] : array();
174
-		$editable = "editable_$form";
175
-		$editable = (!isset($post[$e]))
176
-			|| count($erreurs)
177
-			|| (isset($post[$editable]) && $post[$editable]);
178
-	}
179
-
180
-	$valeurs = formulaire__charger($form, $args, $je_suis_poste);
181
-
182
-	// si $valeurs n'est pas un tableau, le formulaire n'est pas applicable
183
-	// C'est plus fort qu'editable qui est gere par le squelette 
184
-	// Idealement $valeur doit etre alors un message explicatif.
185
-	if (!is_array($valeurs)) {
186
-		return is_string($valeurs) ? $valeurs : '';
187
-	}
188
-
189
-	// charger peut passer une action si le formulaire ne tourne pas sur self()
190
-	// ou une action vide si elle ne sert pas
191
-	$action = (isset($valeurs['action'])) ? $valeurs['action'] : self('&amp;', true);
192
-	// bug IEx : si action finit par / 
193
-	// IE croit que le <form ... action=../ > est autoferme
194
-	if (substr($action, -1) == '/') {
195
-		// on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un /
196
-		$action .= '#';
197
-	}
198
-
199
-	// recuperer la saisie en cours si erreurs
200
-	// seulement si c'est ce formulaire qui est poste
201
-	// ou si on le demande explicitement par le parametre _forcer_request = true
202
-	$dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request']));
203
-	foreach (array_keys($valeurs) as $champ) {
204
-		if ($champ[0] !== '_' and !in_array($champ, array('message_ok', 'message_erreur', 'editable'))) {
205
-			if ($dispo and (($v = _request($champ)) !== null)) {
206
-				$valeurs[$champ] = $v;
207
-			}
208
-			// nettoyer l'url des champs qui vont etre saisis
209
-			if ($action) {
210
-				$action = parametre_url($action, $champ, '');
211
-			}
212
-			// proteger les ' et les " dans les champs que l'on va injecter
213
-			$valeurs[$champ] = protege_champ($valeurs[$champ]);
214
-		}
215
-	}
216
-
217
-	if ($action) {
218
-		// nettoyer l'url
219
-		$action = parametre_url($action, 'formulaire_action', '');
220
-		$action = parametre_url($action, 'formulaire_action_args', '');
221
-	}
222
-
223
-	if (isset($valeurs['_action'])) {
224
-		$securiser_action = charger_fonction('securiser_action', 'inc');
225
-		$secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1);
226
-		$valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') .
227
-			"<input type='hidden' name='arg' value='" . $secu['arg'] . "' />"
228
-			. "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />";
229
-	}
230
-
231
-	// empiler la lang en tant que premier argument implicite du CVT
232
-	// pour permettre de la restaurer au moment du Verifier et du Traiter
233
-	array_unshift($args, $GLOBALS['spip_lang']);
234
-
235
-	$valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form);
236
-	$valeurs['erreurs'] = $erreurs;
237
-	$valeurs['action'] = $action;
238
-	$valeurs['form'] = $form;
239
-
240
-	if (!isset($valeurs['id'])) {
241
-		$valeurs['id'] = 'new';
242
-	}
243
-	// editable peut venir de charger() ou de traiter() sinon
244
-	if (!isset($valeurs['editable'])) {
245
-		$valeurs['editable'] = $editable;
246
-	}
247
-	// dans tous les cas, renvoyer un espace ou vide (et pas un booleen)
248
-	$valeurs['editable'] = ($valeurs['editable'] ? ' ' : '');
249
-
250
-	if ($je_suis_poste) {
251
-		$valeurs['message_erreur'] = "";
252
-		if (isset($erreurs['message_erreur'])) {
253
-			$valeurs['message_erreur'] = $erreurs['message_erreur'];
254
-		}
255
-
256
-		$valeurs['message_ok'] = "";
257
-		if (isset($post["message_ok_$form"])) {
258
-			$valeurs['message_ok'] = $post["message_ok_$form"];
259
-		} elseif (isset($erreurs['message_ok'])) {
260
-			$valeurs['message_ok'] = $erreurs["message_ok"];
261
-		}
262
-	}
263
-
264
-	return $valeurs;
151
+    // tester si ce formulaire vient d'etre poste (memes arguments)
152
+    // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page
153
+    // si poste, on recupere les erreurs
154
+
155
+    $je_suis_poste = false;
156
+    if ($post_form = _request('formulaire_action')
157
+        and $post_form == $form
158
+        and $p = _request('formulaire_action_args')
159
+        and is_array($p = decoder_contexte_ajax($p, $post_form))
160
+    ) {
161
+        // enlever le faux attribut de langue masque
162
+        array_shift($p);
163
+        if (formulaire__identifier($form, $args, $p)) {
164
+            $je_suis_poste = true;
165
+        }
166
+    }
167
+
168
+    $editable = true;
169
+    $erreurs = $post = array();
170
+    if ($je_suis_poste) {
171
+        $post = traiter_formulaires_dynamiques(true);
172
+        $e = "erreurs_$form";
173
+        $erreurs = isset($post[$e]) ? $post[$e] : array();
174
+        $editable = "editable_$form";
175
+        $editable = (!isset($post[$e]))
176
+            || count($erreurs)
177
+            || (isset($post[$editable]) && $post[$editable]);
178
+    }
179
+
180
+    $valeurs = formulaire__charger($form, $args, $je_suis_poste);
181
+
182
+    // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable
183
+    // C'est plus fort qu'editable qui est gere par le squelette 
184
+    // Idealement $valeur doit etre alors un message explicatif.
185
+    if (!is_array($valeurs)) {
186
+        return is_string($valeurs) ? $valeurs : '';
187
+    }
188
+
189
+    // charger peut passer une action si le formulaire ne tourne pas sur self()
190
+    // ou une action vide si elle ne sert pas
191
+    $action = (isset($valeurs['action'])) ? $valeurs['action'] : self('&amp;', true);
192
+    // bug IEx : si action finit par / 
193
+    // IE croit que le <form ... action=../ > est autoferme
194
+    if (substr($action, -1) == '/') {
195
+        // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un /
196
+        $action .= '#';
197
+    }
198
+
199
+    // recuperer la saisie en cours si erreurs
200
+    // seulement si c'est ce formulaire qui est poste
201
+    // ou si on le demande explicitement par le parametre _forcer_request = true
202
+    $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request']));
203
+    foreach (array_keys($valeurs) as $champ) {
204
+        if ($champ[0] !== '_' and !in_array($champ, array('message_ok', 'message_erreur', 'editable'))) {
205
+            if ($dispo and (($v = _request($champ)) !== null)) {
206
+                $valeurs[$champ] = $v;
207
+            }
208
+            // nettoyer l'url des champs qui vont etre saisis
209
+            if ($action) {
210
+                $action = parametre_url($action, $champ, '');
211
+            }
212
+            // proteger les ' et les " dans les champs que l'on va injecter
213
+            $valeurs[$champ] = protege_champ($valeurs[$champ]);
214
+        }
215
+    }
216
+
217
+    if ($action) {
218
+        // nettoyer l'url
219
+        $action = parametre_url($action, 'formulaire_action', '');
220
+        $action = parametre_url($action, 'formulaire_action_args', '');
221
+    }
222
+
223
+    if (isset($valeurs['_action'])) {
224
+        $securiser_action = charger_fonction('securiser_action', 'inc');
225
+        $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1);
226
+        $valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') .
227
+            "<input type='hidden' name='arg' value='" . $secu['arg'] . "' />"
228
+            . "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />";
229
+    }
230
+
231
+    // empiler la lang en tant que premier argument implicite du CVT
232
+    // pour permettre de la restaurer au moment du Verifier et du Traiter
233
+    array_unshift($args, $GLOBALS['spip_lang']);
234
+
235
+    $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form);
236
+    $valeurs['erreurs'] = $erreurs;
237
+    $valeurs['action'] = $action;
238
+    $valeurs['form'] = $form;
239
+
240
+    if (!isset($valeurs['id'])) {
241
+        $valeurs['id'] = 'new';
242
+    }
243
+    // editable peut venir de charger() ou de traiter() sinon
244
+    if (!isset($valeurs['editable'])) {
245
+        $valeurs['editable'] = $editable;
246
+    }
247
+    // dans tous les cas, renvoyer un espace ou vide (et pas un booleen)
248
+    $valeurs['editable'] = ($valeurs['editable'] ? ' ' : '');
249
+
250
+    if ($je_suis_poste) {
251
+        $valeurs['message_erreur'] = "";
252
+        if (isset($erreurs['message_erreur'])) {
253
+            $valeurs['message_erreur'] = $erreurs['message_erreur'];
254
+        }
255
+
256
+        $valeurs['message_ok'] = "";
257
+        if (isset($post["message_ok_$form"])) {
258
+            $valeurs['message_ok'] = $post["message_ok_$form"];
259
+        } elseif (isset($erreurs['message_ok'])) {
260
+            $valeurs['message_ok'] = $erreurs["message_ok"];
261
+        }
262
+    }
263
+
264
+    return $valeurs;
265 265
 }
266 266
 
267 267
 /**
@@ -273,51 +273,51 @@  discard block
 block discarded – undo
273 273
  * @return array
274 274
  */
275 275
 function formulaire__charger($form, $args, $poste) {
276
-	if ($charger_valeurs = charger_fonction("charger", "formulaires/$form", true)) {
277
-		$valeurs = call_user_func_array($charger_valeurs, $args);
278
-	} else {
279
-		$valeurs = array();
280
-	}
281
-
282
-	$valeurs = pipeline(
283
-		'formulaire_charger',
284
-		array(
285
-			'args' => array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste),
286
-			'data' => $valeurs
287
-		)
288
-	);
289
-
290
-	// prise en charge CVT multi etape
291
-	if (is_array($valeurs) and isset($valeurs['_etapes'])) {
292
-		include_spip('inc/cvt_multietapes');
293
-		$valeurs = cvtmulti_formulaire_charger_etapes(
294
-			array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), 
295
-			$valeurs
296
-		);
297
-	}
298
-
299
-	// si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline !
300
-	if (is_array($valeurs)) {
301
-		if (!isset($valeurs['_pipelines'])) {
302
-			$valeurs['_pipelines'] = array();
303
-		}
304
-		// l'ancien argument _pipeline devient maintenant _pipelines
305
-		// reinjectons le vieux _pipeline au debut de _pipelines
306
-		if (isset($valeurs['_pipeline'])) {
307
-			$pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline'];
308
-			$args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : array();
309
-
310
-			$pipelines = array($pipe => $args);
311
-			$valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']);
312
-		}
313
-
314
-		// et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire
315
-		// qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond
316
-		// (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes)
317
-		$valeurs['_pipelines']['formulaire_fond'] = array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste);
318
-	}
319
-
320
-	return $valeurs;
276
+    if ($charger_valeurs = charger_fonction("charger", "formulaires/$form", true)) {
277
+        $valeurs = call_user_func_array($charger_valeurs, $args);
278
+    } else {
279
+        $valeurs = array();
280
+    }
281
+
282
+    $valeurs = pipeline(
283
+        'formulaire_charger',
284
+        array(
285
+            'args' => array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste),
286
+            'data' => $valeurs
287
+        )
288
+    );
289
+
290
+    // prise en charge CVT multi etape
291
+    if (is_array($valeurs) and isset($valeurs['_etapes'])) {
292
+        include_spip('inc/cvt_multietapes');
293
+        $valeurs = cvtmulti_formulaire_charger_etapes(
294
+            array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), 
295
+            $valeurs
296
+        );
297
+    }
298
+
299
+    // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline !
300
+    if (is_array($valeurs)) {
301
+        if (!isset($valeurs['_pipelines'])) {
302
+            $valeurs['_pipelines'] = array();
303
+        }
304
+        // l'ancien argument _pipeline devient maintenant _pipelines
305
+        // reinjectons le vieux _pipeline au debut de _pipelines
306
+        if (isset($valeurs['_pipeline'])) {
307
+            $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline'];
308
+            $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : array();
309
+
310
+            $pipelines = array($pipe => $args);
311
+            $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']);
312
+        }
313
+
314
+        // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire
315
+        // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond
316
+        // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes)
317
+        $valeurs['_pipelines']['formulaire_fond'] = array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste);
318
+    }
319
+
320
+    return $valeurs;
321 321
 }
322 322
 
323 323
 /**
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
  * @return bool
337 337
  */
338 338
 function formulaire__identifier($form, $args, $p) {
339
-	if ($identifier_args = charger_fonction("identifier", "formulaires/$form", true)) {
340
-		return call_user_func_array($identifier_args, $args) === call_user_func_array($identifier_args, $p);
341
-	}
339
+    if ($identifier_args = charger_fonction("identifier", "formulaires/$form", true)) {
340
+        return call_user_func_array($identifier_args, $args) === call_user_func_array($identifier_args, $p);
341
+    }
342 342
 
343
-	return $args === $p;
343
+    return $args === $p;
344 344
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -223,9 +223,9 @@
 block discarded – undo
223 223
 	if (isset($valeurs['_action'])) {
224 224
 		$securiser_action = charger_fonction('securiser_action', 'inc');
225 225
 		$secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1);
226
-		$valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') .
227
-			"<input type='hidden' name='arg' value='" . $secu['arg'] . "' />"
228
-			. "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />";
226
+		$valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '').
227
+			"<input type='hidden' name='arg' value='".$secu['arg']."' />"
228
+			. "<input type='hidden' name='hash' value='".$secu['hash']."' />";
229 229
 	}
230 230
 
231 231
 	// empiler la lang en tant que premier argument implicite du CVT
Please login to merge, or discard this patch.
ecrire/base/connect_sql.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
  *
37 37
  * @param string $serveur Nom du connecteur
38 38
  * @param string $version Version de l'API SQL
39
- * @return bool|array
39
+ * @return string
40 40
  *     - false si la connexion a échouée,
41 41
  *     - tableau décrivant la connexion sinon
42 42
  **/
Please login to merge, or discard this patch.
Spacing   +11 added lines, -12 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19 19
 	return;
20 20
 }
21
-require_once _ROOT_RESTREINT . 'base/objets.php';
21
+require_once _ROOT_RESTREINT.'base/objets.php';
22 22
 
23 23
 
24 24
 /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		$f = (!preg_match('/^[\w\.]*$/', $serveur))
60 60
 			? '' // nom de serveur mal ecrit
61 61
 			: ($serveur ?
62
-				(_DIR_CONNECT . $serveur . '.php') // serveur externe
62
+				(_DIR_CONNECT.$serveur.'.php') // serveur externe
63 63
 				: (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok
64 64
 					: ($install ? _FILE_CONNECT_TMP // init du serveur principal
65 65
 						: ''))); // installation pas faite
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 	// chargement de la version du jeu de fonctions
103 103
 	// si pas dans le fichier par defaut
104 104
 	$type = $GLOBALS['db_ok']['type'];
105
-	$jeu = 'spip_' . $type . '_functions_' . $version;
105
+	$jeu = 'spip_'.$type.'_functions_'.$version;
106 106
 	if (!isset($GLOBALS[$jeu])) {
107
-		if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
107
+		if (!find_in_path($type.'_'.$version.'.php', 'req/', true)) {
108 108
 			spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
109 109
 
110 110
 			// ne plus reessayer
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 	$connexion = spip_connect($serveur);
166 166
 	$e = sql_errno($serveur);
167 167
 	$t = (isset($connexion['type']) ? $connexion['type'] : 'sql');
168
-	$m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
-	$f = $t . $serveur;
170
-	spip_log($m, $f . '.' . _LOG_ERREUR);
168
+	$m = "Erreur $e de $t: ".sql_error($serveur)."\nin ".sql_error_backtrace()."\n".trim($connexion['last']);
169
+	$f = $t.$serveur;
170
+	spip_log($m, $f.'.'._LOG_ERREUR);
171 171
 }
172 172
 
173 173
 /**
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	// si en cours d'installation ou si db=@test@ on ne pose rien
250 250
 	// car c'est un test de connexion
251 251
 	if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") {
252
-		$f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
252
+		$f = _DIR_TMP.$type.'.'.substr(md5($host.$port.$db), 0, 8).'.out';
253 253
 	} elseif ($db == '@test@') {
254 254
 		$db = '';
255 255
 	}
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	// En cas d'indisponibilite du serveur, eviter de le bombarder
290 290
 	if ($f) {
291 291
 		@touch($f);
292
-		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
292
+		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS);
293 293
 	}
294 294
 }
295 295
 
@@ -379,8 +379,7 @@  discard block
 block discarded – undo
379 379
  * @return string Valeur échappée.
380 380
  **/
381 381
 function _q($a) {
382
-	return (is_numeric($a)) ? strval($a) :
383
-		(!is_array($a) ? ("'" . addslashes($a) . "'")
382
+	return (is_numeric($a)) ? strval($a) : (!is_array($a) ? ("'".addslashes($a)."'")
384 383
 			: join(",", array_map('_q', $a)));
385 384
 }
386 385
 
@@ -452,7 +451,7 @@  discard block
 block discarded – undo
452 451
 				break;
453 452
 			default:
454 453
 				$replace = range(1, count($textes));
455
-				$replace = '%' . implode('$s,%', $replace) . '$s';
454
+				$replace = '%'.implode('$s,%', $replace).'$s';
456 455
 				$replace = explode(',', $replace);
457 456
 				break;
458 457
 		}
Please login to merge, or discard this patch.
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\SQL
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 require_once _ROOT_RESTREINT . 'base/objets.php';
22 22
 
@@ -42,118 +42,118 @@  discard block
 block discarded – undo
42 42
  **/
43 43
 function spip_connect($serveur = '', $version = '') {
44 44
 
45
-	$serveur = !is_string($serveur) ? '' : strtolower($serveur);
46
-	$index = $serveur ? $serveur : 0;
47
-	if (!$version) {
48
-		$version = $GLOBALS['spip_sql_version'];
49
-	}
50
-	if (isset($GLOBALS['connexions'][$index][$version])) {
51
-		return $GLOBALS['connexions'][$index];
52
-	}
53
-
54
-	include_spip('base/abstract_sql');
55
-	$install = (_request('exec') == 'install');
56
-
57
-	// Premiere connexion ?
58
-	if (!($old = isset($GLOBALS['connexions'][$index]))) {
59
-		$f = (!preg_match('/^[\w\.]*$/', $serveur))
60
-			? '' // nom de serveur mal ecrit
61
-			: ($serveur ?
62
-				(_DIR_CONNECT . $serveur . '.php') // serveur externe
63
-				: (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok
64
-					: ($install ? _FILE_CONNECT_TMP // init du serveur principal
65
-						: ''))); // installation pas faite
66
-
67
-		unset($GLOBALS['db_ok']);
68
-		unset($GLOBALS['spip_connect_version']);
69
-		if ($f) {
70
-			if (is_readable($f)) {
71
-				include($f);
72
-			} elseif ($serveur and !$install) {
73
-				// chercher une declaration de serveur dans le path
74
-				// qui pourra un jour servir a declarer des bases sqlite
75
-				// par des plugins. Et sert aussi aux boucles POUR.
76
-				find_in_path("$serveur.php", 'connect/', true);
77
-			}
78
-		}
79
-		if (!isset($GLOBALS['db_ok'])) {
80
-			// fera mieux la prochaine fois
81
-			if ($install) {
82
-				return false;
83
-			}
84
-			if ($f and is_readable($f)) {
85
-				spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
86
-			} else {
87
-				spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
88
-			}
89
-			spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS);
90
-
91
-			// ne plus reessayer si ce n'est pas l'install
92
-			return $GLOBALS['connexions'][$index] = false;
93
-		}
94
-		$GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
95
-	}
96
-	// si la connexion a deja ete tentee mais a echoue, le dire!
97
-	if (!$GLOBALS['connexions'][$index]) {
98
-		return false;
99
-	}
100
-
101
-	// la connexion a reussi ou etait deja faite.
102
-	// chargement de la version du jeu de fonctions
103
-	// si pas dans le fichier par defaut
104
-	$type = $GLOBALS['db_ok']['type'];
105
-	$jeu = 'spip_' . $type . '_functions_' . $version;
106
-	if (!isset($GLOBALS[$jeu])) {
107
-		if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
108
-			spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
109
-
110
-			// ne plus reessayer
111
-			return $GLOBALS['connexions'][$index][$version] = array();
112
-		}
113
-	}
114
-	$GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
115
-	if ($old) {
116
-		return $GLOBALS['connexions'][$index];
117
-	}
118
-
119
-	$GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0;
120
-
121
-	// initialisation de l'alphabet utilise dans les connexions SQL
122
-	// si l'installation l'a determine.
123
-	// Celui du serveur principal l'impose aux serveurs secondaires
124
-	// s'ils le connaissent
125
-
126
-	if (!$serveur) {
127
-		$charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
128
-		if (!$charset) {
129
-			unset($GLOBALS['connexions'][$index]);
130
-			spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT);
131
-
132
-			return false;
133
-		}
134
-	} else {
135
-		if ($GLOBALS['db_ok']['charset']) {
136
-			$charset = $GLOBALS['db_ok']['charset'];
137
-		}
138
-		// spip_meta n'existe pas toujours dans la base
139
-		// C'est le cas d'un dump sqlite par exemple 
140
-		elseif ($GLOBALS['connexions'][$index]['spip_connect_version']
141
-			and sql_showtable('spip_meta', true, $serveur)
142
-			and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)
143
-		) {
144
-			$charset = $r;
145
-		} else {
146
-			$charset = -1;
147
-		}
148
-	}
149
-	if ($charset != -1) {
150
-		$f = $GLOBALS[$jeu]['set_charset'];
151
-		if (function_exists($f)) {
152
-			$f($charset, $serveur);
153
-		}
154
-	}
155
-
156
-	return $GLOBALS['connexions'][$index];
45
+    $serveur = !is_string($serveur) ? '' : strtolower($serveur);
46
+    $index = $serveur ? $serveur : 0;
47
+    if (!$version) {
48
+        $version = $GLOBALS['spip_sql_version'];
49
+    }
50
+    if (isset($GLOBALS['connexions'][$index][$version])) {
51
+        return $GLOBALS['connexions'][$index];
52
+    }
53
+
54
+    include_spip('base/abstract_sql');
55
+    $install = (_request('exec') == 'install');
56
+
57
+    // Premiere connexion ?
58
+    if (!($old = isset($GLOBALS['connexions'][$index]))) {
59
+        $f = (!preg_match('/^[\w\.]*$/', $serveur))
60
+            ? '' // nom de serveur mal ecrit
61
+            : ($serveur ?
62
+                (_DIR_CONNECT . $serveur . '.php') // serveur externe
63
+                : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok
64
+                    : ($install ? _FILE_CONNECT_TMP // init du serveur principal
65
+                        : ''))); // installation pas faite
66
+
67
+        unset($GLOBALS['db_ok']);
68
+        unset($GLOBALS['spip_connect_version']);
69
+        if ($f) {
70
+            if (is_readable($f)) {
71
+                include($f);
72
+            } elseif ($serveur and !$install) {
73
+                // chercher une declaration de serveur dans le path
74
+                // qui pourra un jour servir a declarer des bases sqlite
75
+                // par des plugins. Et sert aussi aux boucles POUR.
76
+                find_in_path("$serveur.php", 'connect/', true);
77
+            }
78
+        }
79
+        if (!isset($GLOBALS['db_ok'])) {
80
+            // fera mieux la prochaine fois
81
+            if ($install) {
82
+                return false;
83
+            }
84
+            if ($f and is_readable($f)) {
85
+                spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
86
+            } else {
87
+                spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
88
+            }
89
+            spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS);
90
+
91
+            // ne plus reessayer si ce n'est pas l'install
92
+            return $GLOBALS['connexions'][$index] = false;
93
+        }
94
+        $GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
95
+    }
96
+    // si la connexion a deja ete tentee mais a echoue, le dire!
97
+    if (!$GLOBALS['connexions'][$index]) {
98
+        return false;
99
+    }
100
+
101
+    // la connexion a reussi ou etait deja faite.
102
+    // chargement de la version du jeu de fonctions
103
+    // si pas dans le fichier par defaut
104
+    $type = $GLOBALS['db_ok']['type'];
105
+    $jeu = 'spip_' . $type . '_functions_' . $version;
106
+    if (!isset($GLOBALS[$jeu])) {
107
+        if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
108
+            spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
109
+
110
+            // ne plus reessayer
111
+            return $GLOBALS['connexions'][$index][$version] = array();
112
+        }
113
+    }
114
+    $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
115
+    if ($old) {
116
+        return $GLOBALS['connexions'][$index];
117
+    }
118
+
119
+    $GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0;
120
+
121
+    // initialisation de l'alphabet utilise dans les connexions SQL
122
+    // si l'installation l'a determine.
123
+    // Celui du serveur principal l'impose aux serveurs secondaires
124
+    // s'ils le connaissent
125
+
126
+    if (!$serveur) {
127
+        $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
128
+        if (!$charset) {
129
+            unset($GLOBALS['connexions'][$index]);
130
+            spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT);
131
+
132
+            return false;
133
+        }
134
+    } else {
135
+        if ($GLOBALS['db_ok']['charset']) {
136
+            $charset = $GLOBALS['db_ok']['charset'];
137
+        }
138
+        // spip_meta n'existe pas toujours dans la base
139
+        // C'est le cas d'un dump sqlite par exemple 
140
+        elseif ($GLOBALS['connexions'][$index]['spip_connect_version']
141
+            and sql_showtable('spip_meta', true, $serveur)
142
+            and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)
143
+        ) {
144
+            $charset = $r;
145
+        } else {
146
+            $charset = -1;
147
+        }
148
+    }
149
+    if ($charset != -1) {
150
+        $f = $GLOBALS[$jeu]['set_charset'];
151
+        if (function_exists($f)) {
152
+            $f($charset, $serveur);
153
+        }
154
+    }
155
+
156
+    return $GLOBALS['connexions'][$index];
157 157
 }
158 158
 
159 159
 /**
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
  * @param string $serveur Nom du connecteur de bdd utilisé
163 163
  **/
164 164
 function spip_sql_erreur($serveur = '') {
165
-	$connexion = spip_connect($serveur);
166
-	$e = sql_errno($serveur);
167
-	$t = (isset($connexion['type']) ? $connexion['type'] : 'sql');
168
-	$m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
-	$f = $t . $serveur;
170
-	spip_log($m, $f . '.' . _LOG_ERREUR);
165
+    $connexion = spip_connect($serveur);
166
+    $e = sql_errno($serveur);
167
+    $t = (isset($connexion['type']) ? $connexion['type'] : 'sql');
168
+    $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
+    $f = $t . $serveur;
170
+    spip_log($m, $f . '.' . _LOG_ERREUR);
171 171
 }
172 172
 
173 173
 /**
@@ -189,19 +189,19 @@  discard block
 block discarded – undo
189 189
  *     - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion
190 190
  **/
191 191
 function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) {
192
-	$desc = spip_connect($serveur, $version);
193
-	if (function_exists($f = @$desc[$version][$ins])) {
194
-		return $f;
195
-	}
196
-	if ($continue) {
197
-		return $desc;
198
-	}
199
-	if ($ins) {
200
-		spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
201
-	}
202
-	include_spip('inc/minipres');
203
-	echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503));
204
-	exit;
192
+    $desc = spip_connect($serveur, $version);
193
+    if (function_exists($f = @$desc[$version][$ins])) {
194
+        return $f;
195
+    }
196
+    if ($continue) {
197
+        return $desc;
198
+    }
199
+    if ($ins) {
200
+        spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
201
+    }
202
+    include_spip('inc/minipres');
203
+    echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503));
204
+    exit;
205 205
 }
206 206
 
207 207
 /**
@@ -227,70 +227,70 @@  discard block
 block discarded – undo
227 227
  * @return array          Description de la connexion
228 228
  */
229 229
 function spip_connect_db(
230
-	$host,
231
-	$port,
232
-	$login,
233
-	$pass,
234
-	$db = '',
235
-	$type = 'mysql',
236
-	$prefixe = '',
237
-	$auth = '',
238
-	$charset = ''
230
+    $host,
231
+    $port,
232
+    $login,
233
+    $pass,
234
+    $db = '',
235
+    $type = 'mysql',
236
+    $prefixe = '',
237
+    $auth = '',
238
+    $charset = ''
239 239
 ) {
240
-	// temps avant nouvelle tentative de connexion
241
-	// suite a une connection echouee
242
-	if (!defined('_CONNECT_RETRY_DELAY')) {
243
-		define('_CONNECT_RETRY_DELAY', 30);
244
-	}
245
-
246
-	$f = "";
247
-	// un fichier de identifiant par combinaison (type,host,port,db)
248
-	// pour ne pas declarer tout indisponible d'un coup
249
-	// si en cours d'installation ou si db=@test@ on ne pose rien
250
-	// car c'est un test de connexion
251
-	if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") {
252
-		$f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
253
-	} elseif ($db == '@test@') {
254
-		$db = '';
255
-	}
256
-
257
-	if ($f
258
-		and @file_exists($f)
259
-		and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
260
-	) {
261
-		spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
262
-
263
-		return;
264
-	}
265
-
266
-	if (!$prefixe) {
267
-		$prefixe = isset($GLOBALS['table_prefix'])
268
-			? $GLOBALS['table_prefix'] : $db;
269
-	}
270
-	$h = charger_fonction($type, 'req', true);
271
-	if (!$h) {
272
-		spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
273
-
274
-		return;
275
-	}
276
-	if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
277
-
278
-		if (!is_array($auth)) {
279
-			// compatibilite version 0.7 initiale
280
-			$g['ldap'] = $auth;
281
-			$auth = array('ldap' => $auth);
282
-		}
283
-		$g['authentification'] = $auth;
284
-		$g['type'] = $type;
285
-		$g['charset'] = $charset;
286
-
287
-		return $GLOBALS['db_ok'] = $g;
288
-	}
289
-	// En cas d'indisponibilite du serveur, eviter de le bombarder
290
-	if ($f) {
291
-		@touch($f);
292
-		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
293
-	}
240
+    // temps avant nouvelle tentative de connexion
241
+    // suite a une connection echouee
242
+    if (!defined('_CONNECT_RETRY_DELAY')) {
243
+        define('_CONNECT_RETRY_DELAY', 30);
244
+    }
245
+
246
+    $f = "";
247
+    // un fichier de identifiant par combinaison (type,host,port,db)
248
+    // pour ne pas declarer tout indisponible d'un coup
249
+    // si en cours d'installation ou si db=@test@ on ne pose rien
250
+    // car c'est un test de connexion
251
+    if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") {
252
+        $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
253
+    } elseif ($db == '@test@') {
254
+        $db = '';
255
+    }
256
+
257
+    if ($f
258
+        and @file_exists($f)
259
+        and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
260
+    ) {
261
+        spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
262
+
263
+        return;
264
+    }
265
+
266
+    if (!$prefixe) {
267
+        $prefixe = isset($GLOBALS['table_prefix'])
268
+            ? $GLOBALS['table_prefix'] : $db;
269
+    }
270
+    $h = charger_fonction($type, 'req', true);
271
+    if (!$h) {
272
+        spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
273
+
274
+        return;
275
+    }
276
+    if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
277
+
278
+        if (!is_array($auth)) {
279
+            // compatibilite version 0.7 initiale
280
+            $g['ldap'] = $auth;
281
+            $auth = array('ldap' => $auth);
282
+        }
283
+        $g['authentification'] = $auth;
284
+        $g['type'] = $type;
285
+        $g['charset'] = $charset;
286
+
287
+        return $GLOBALS['db_ok'] = $g;
288
+    }
289
+    // En cas d'indisponibilite du serveur, eviter de le bombarder
290
+    if ($f) {
291
+        @touch($f);
292
+        spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
293
+    }
294 294
 }
295 295
 
296 296
 
@@ -322,31 +322,31 @@  discard block
 block discarded – undo
322 322
  *     - nom du charset sinon
323 323
  **/
324 324
 function spip_connect_main($connexion, $charset_sql_connexion = '') {
325
-	if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) {
326
-		include_spip('inc/headers');
327
-		redirige_url_ecrire('upgrade', 'reinstall=oui');
328
-	}
329
-
330
-	if (!($f = $connexion['select'])) {
331
-		return false;
332
-	}
333
-	// si le charset est fourni, l'utiliser
334
-	if ($charset_sql_connexion) {
335
-		return $charset_sql_connexion;
336
-	}
337
-	// sinon on regarde la table spip_meta
338
-	// en cas d'erreur select retourne la requette (is_string=true donc)
339
-	if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")
340
-		or is_string($r)
341
-	) {
342
-		return false;
343
-	}
344
-	if (!($f = $connexion['fetch'])) {
345
-		return false;
346
-	}
347
-	$r = $f($r);
348
-
349
-	return ($r['valeur'] ? $r['valeur'] : -1);
325
+    if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) {
326
+        include_spip('inc/headers');
327
+        redirige_url_ecrire('upgrade', 'reinstall=oui');
328
+    }
329
+
330
+    if (!($f = $connexion['select'])) {
331
+        return false;
332
+    }
333
+    // si le charset est fourni, l'utiliser
334
+    if ($charset_sql_connexion) {
335
+        return $charset_sql_connexion;
336
+    }
337
+    // sinon on regarde la table spip_meta
338
+    // en cas d'erreur select retourne la requette (is_string=true donc)
339
+    if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")
340
+        or is_string($r)
341
+    ) {
342
+        return false;
343
+    }
344
+    if (!($f = $connexion['fetch'])) {
345
+        return false;
346
+    }
347
+    $r = $f($r);
348
+
349
+    return ($r['valeur'] ? $r['valeur'] : -1);
350 350
 }
351 351
 
352 352
 /**
@@ -361,9 +361,9 @@  discard block
 block discarded – undo
361 361
  * @return array
362 362
  */
363 363
 function spip_connect_ldap($serveur = '') {
364
-	include_spip('auth/ldap');
364
+    include_spip('auth/ldap');
365 365
 
366
-	return auth_ldap_connect($serveur);
366
+    return auth_ldap_connect($serveur);
367 367
 }
368 368
 
369 369
 /**
@@ -379,9 +379,9 @@  discard block
 block discarded – undo
379 379
  * @return string Valeur échappée.
380 380
  **/
381 381
 function _q($a) {
382
-	return (is_numeric($a)) ? strval($a) :
383
-		(!is_array($a) ? ("'" . addslashes($a) . "'")
384
-			: join(",", array_map('_q', $a)));
382
+    return (is_numeric($a)) ? strval($a) :
383
+        (!is_array($a) ? ("'" . addslashes($a) . "'")
384
+            : join(",", array_map('_q', $a)));
385 385
 }
386 386
 
387 387
 
@@ -399,19 +399,19 @@  discard block
 block discarded – undo
399 399
  *     - chaîne vide si non trouvé.
400 400
  **/
401 401
 function table_jointure($x, $y) {
402
-	$trouver_table = charger_fonction('trouver_table', 'base');
403
-	$xdesc = $trouver_table(table_objet($x));
404
-	$ydesc = $trouver_table(table_objet($y));
405
-	$ix = @$xdesc['key']["PRIMARY KEY"];
406
-	$iy = @$ydesc['key']["PRIMARY KEY"];
407
-	if ($table = $ydesc['tables_jointures'][$ix]) {
408
-		return $table;
409
-	}
410
-	if ($table = $xdesc['tables_jointures'][$iy]) {
411
-		return $table;
412
-	}
413
-
414
-	return '';
402
+    $trouver_table = charger_fonction('trouver_table', 'base');
403
+    $xdesc = $trouver_table(table_objet($x));
404
+    $ydesc = $trouver_table(table_objet($y));
405
+    $ix = @$xdesc['key']["PRIMARY KEY"];
406
+    $iy = @$ydesc['key']["PRIMARY KEY"];
407
+    if ($table = $ydesc['tables_jointures'][$ix]) {
408
+        return $table;
409
+    }
410
+    if ($table = $xdesc['tables_jointures'][$iy]) {
411
+        return $table;
412
+    }
413
+
414
+    return '';
415 415
 }
416 416
 
417 417
 /**
@@ -427,41 +427,41 @@  discard block
 block discarded – undo
427 427
  * @return array
428 428
  */
429 429
 function query_echappe_textes($query) {
430
-	static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
431
-	$query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
432
-	if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) {
433
-		$textes = reset($textes); // indice 0 du match
434
-		switch (count($textes)) {
435
-			case 0:
436
-				$replace = array();
437
-				break;
438
-			case 1:
439
-				$replace = array('%1$s');
440
-				break;
441
-			case 2:
442
-				$replace = array('%1$s', '%2$s');
443
-				break;
444
-			case 3:
445
-				$replace = array('%1$s', '%2$s', '%3$s');
446
-				break;
447
-			case 4:
448
-				$replace = array('%1$s', '%2$s', '%3$s', '%4$s');
449
-				break;
450
-			case 5:
451
-				$replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s');
452
-				break;
453
-			default:
454
-				$replace = range(1, count($textes));
455
-				$replace = '%' . implode('$s,%', $replace) . '$s';
456
-				$replace = explode(',', $replace);
457
-				break;
458
-		}
459
-		$query = str_replace($textes, $replace, $query);
460
-	} else {
461
-		$textes = array();
462
-	}
463
-
464
-	return array($query, $textes);
430
+    static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
431
+    $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
432
+    if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) {
433
+        $textes = reset($textes); // indice 0 du match
434
+        switch (count($textes)) {
435
+            case 0:
436
+                $replace = array();
437
+                break;
438
+            case 1:
439
+                $replace = array('%1$s');
440
+                break;
441
+            case 2:
442
+                $replace = array('%1$s', '%2$s');
443
+                break;
444
+            case 3:
445
+                $replace = array('%1$s', '%2$s', '%3$s');
446
+                break;
447
+            case 4:
448
+                $replace = array('%1$s', '%2$s', '%3$s', '%4$s');
449
+                break;
450
+            case 5:
451
+                $replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s');
452
+                break;
453
+            default:
454
+                $replace = range(1, count($textes));
455
+                $replace = '%' . implode('$s,%', $replace) . '$s';
456
+                $replace = explode(',', $replace);
457
+                break;
458
+        }
459
+        $query = str_replace($textes, $replace, $query);
460
+    } else {
461
+        $textes = array();
462
+    }
463
+
464
+    return array($query, $textes);
465 465
 }
466 466
 
467 467
 /**
@@ -475,40 +475,40 @@  discard block
 block discarded – undo
475 475
  * @return string
476 476
  */
477 477
 function query_reinjecte_textes($query, $textes) {
478
-	static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
479
-	# debug de la substitution
480
-	#if (($c1=substr_count($query,"%"))!=($c2=count($textes))){
481
-	#	spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR);
482
-	#	spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR);
483
-	#	spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR);
484
-	#}
485
-	switch (count($textes)) {
486
-		case 0:
487
-			break;
488
-		case 1:
489
-			$query = sprintf($query, $textes[0]);
490
-			break;
491
-		case 2:
492
-			$query = sprintf($query, $textes[0], $textes[1]);
493
-			break;
494
-		case 3:
495
-			$query = sprintf($query, $textes[0], $textes[1], $textes[2]);
496
-			break;
497
-		case 4:
498
-			$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]);
499
-			break;
500
-		case 5:
501
-			$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]);
502
-			break;
503
-		default:
504
-			array_unshift($textes, $query);
505
-			$query = call_user_func_array('sprintf', $textes);
506
-			break;
507
-	}
508
-
509
-	$query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
510
-
511
-	return $query;
478
+    static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
479
+    # debug de la substitution
480
+    #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){
481
+    #	spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR);
482
+    #	spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR);
483
+    #	spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR);
484
+    #}
485
+    switch (count($textes)) {
486
+        case 0:
487
+            break;
488
+        case 1:
489
+            $query = sprintf($query, $textes[0]);
490
+            break;
491
+        case 2:
492
+            $query = sprintf($query, $textes[0], $textes[1]);
493
+            break;
494
+        case 3:
495
+            $query = sprintf($query, $textes[0], $textes[1], $textes[2]);
496
+            break;
497
+        case 4:
498
+            $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]);
499
+            break;
500
+        case 5:
501
+            $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]);
502
+            break;
503
+        default:
504
+            array_unshift($textes, $query);
505
+            $query = call_user_func_array('sprintf', $textes);
506
+            break;
507
+    }
508
+
509
+    $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
510
+
511
+    return $query;
512 512
 }
513 513
 
514 514
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
  **/
528 528
 function spip_query($query, $serveur = '') {
529 529
 
530
-	$f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
530
+    $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
531 531
 
532
-	return function_exists($f) ? $f($query, $serveur) : false;
532
+    return function_exists($f) ? $f($query, $serveur) : false;
533 533
 }
Please login to merge, or discard this patch.