Completed
Pull Request — master (#39)
by
unknown
07:42
created
ecrire/xml/sax.php 3 patches
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -102,6 +102,9 @@  discard block
 block discarded – undo
102 102
 		: xml_entites_html($data);
103 103
 }
104 104
 
105
+/**
106
+ * @param IndenteurXML $phraseur
107
+ */
105 108
 function xml_piElement($phraseur, $target, $data) {
106 109
 	$depth = $phraseur->depth;
107 110
 
@@ -118,6 +121,9 @@  discard block
 block discarded – undo
118 121
 
119 122
 
120 123
 // http://code.spip.net/@xml_defautElement
124
+/**
125
+ * @param IndenteurXML $phraseur
126
+ */
121 127
 function xml_defaultElement($phraseur, $data) {
122 128
 	$depth = $phraseur->depth;
123 129
 
@@ -149,6 +155,9 @@  discard block
 block discarded – undo
149 155
 }
150 156
 
151 157
 // http://code.spip.net/@coordonnees_erreur
158
+/**
159
+ * @param string $msg
160
+ */
152 161
 function coordonnees_erreur($phraseur, $msg) {
153 162
 	$entete_length = substr_count($phraseur->entete, "\n");
154 163
 	$phraseur->err[] = array(
Please login to merge, or discard this patch.
Indentation   +246 added lines, -246 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
 include_spip('inc/charsets');
@@ -24,218 +24,218 @@  discard block
 block discarded – undo
24 24
  * @return string
25 25
  */
26 26
 function xml_entites_html($texte) {
27
-	if (!is_string($texte) or !$texte
28
-		or strpbrk($texte, "&\"'<>") == false
29
-	) {
30
-		return $texte;
31
-	}
32
-
33
-	if (!function_exists('spip_htmlspecialchars')) {
34
-		include_spip("inc/filtres_mini");
35
-	}
36
-	$texte = spip_htmlspecialchars($texte, ENT_QUOTES);
37
-
38
-	return $texte;
27
+    if (!is_string($texte) or !$texte
28
+        or strpbrk($texte, "&\"'<>") == false
29
+    ) {
30
+        return $texte;
31
+    }
32
+
33
+    if (!function_exists('spip_htmlspecialchars')) {
34
+        include_spip("inc/filtres_mini");
35
+    }
36
+    $texte = spip_htmlspecialchars($texte, ENT_QUOTES);
37
+
38
+    return $texte;
39 39
 }
40 40
 
41 41
 // http://code.spip.net/@xml_debutElement
42 42
 function xml_debutElement($phraseur, $name, $attrs) {
43
-	$depth = $phraseur->depth;
44
-
45
-	$t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' ';
46
-	// espace initial signifie: deja integree au resultat
47
-	if ($t[0] != ' ') {
48
-		$phraseur->res .= '<' . $t . '>';
49
-		$phraseur->ouvrant[$depth] = ' ' . $t;
50
-	}
51
-	$t = $phraseur->contenu[$depth];
52
-	// n'indenter que s'il y a un separateur avant
53
-	$phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t);
54
-	$phraseur->contenu[$depth] = "";
55
-	$att = '';
56
-	$sep = ' ';
57
-	foreach ($attrs as $k => $v) {
58
-		$delim = strpos($v, "'") === false ? "'" : '"';
59
-		$val = xml_entites_html($v);
60
-		$att .= $sep . $k . "=" . $delim
61
-			. ($delim !== '"' ? str_replace('&quot;', '"', $val) : $val)
62
-			. $delim;
63
-		$sep = "\n $depth";
64
-	}
65
-	$phraseur->depth .= '  ';
66
-	$phraseur->contenu[$phraseur->depth] = "";
67
-	$phraseur->ouvrant[$phraseur->depth] = $name . $att;
68
-	$phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
43
+    $depth = $phraseur->depth;
44
+
45
+    $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' ';
46
+    // espace initial signifie: deja integree au resultat
47
+    if ($t[0] != ' ') {
48
+        $phraseur->res .= '<' . $t . '>';
49
+        $phraseur->ouvrant[$depth] = ' ' . $t;
50
+    }
51
+    $t = $phraseur->contenu[$depth];
52
+    // n'indenter que s'il y a un separateur avant
53
+    $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t);
54
+    $phraseur->contenu[$depth] = "";
55
+    $att = '';
56
+    $sep = ' ';
57
+    foreach ($attrs as $k => $v) {
58
+        $delim = strpos($v, "'") === false ? "'" : '"';
59
+        $val = xml_entites_html($v);
60
+        $att .= $sep . $k . "=" . $delim
61
+            . ($delim !== '"' ? str_replace('&quot;', '"', $val) : $val)
62
+            . $delim;
63
+        $sep = "\n $depth";
64
+    }
65
+    $phraseur->depth .= '  ';
66
+    $phraseur->contenu[$phraseur->depth] = "";
67
+    $phraseur->ouvrant[$phraseur->depth] = $name . $att;
68
+    $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
69 69
 }
70 70
 
71 71
 // http://code.spip.net/@xml_finElement
72 72
 function xml_finElement($phraseur, $name, $fusion_bal = false) {
73
-	$ouv = $phraseur->ouvrant[$phraseur->depth];
74
-
75
-	if ($ouv[0] != ' ') {
76
-		$phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv;
77
-	} else {
78
-		$ouv = "";
79
-	}
80
-	$t = $phraseur->contenu[$phraseur->depth];
81
-	$phraseur->depth = substr($phraseur->depth, 2);
82
-	$t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t);
83
-
84
-	// fusion <balise></balise> en <balise />.
85
-	// ATTENTION,  certains clients http croient que fusion ==> pas d'atttributs
86
-	// en particulier pour les balises Script et A.
87
-	// en presence d'attributs ne le faire que si la DTD est dispo et d'accord
88
-	// (param fusion_bal)
89
-
90
-	if ($t || (($ouv != $name) and !$fusion_bal)) {
91
-		$phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">";
92
-	} else {
93
-		$phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">"));
94
-	}
73
+    $ouv = $phraseur->ouvrant[$phraseur->depth];
74
+
75
+    if ($ouv[0] != ' ') {
76
+        $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv;
77
+    } else {
78
+        $ouv = "";
79
+    }
80
+    $t = $phraseur->contenu[$phraseur->depth];
81
+    $phraseur->depth = substr($phraseur->depth, 2);
82
+    $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t);
83
+
84
+    // fusion <balise></balise> en <balise />.
85
+    // ATTENTION,  certains clients http croient que fusion ==> pas d'atttributs
86
+    // en particulier pour les balises Script et A.
87
+    // en presence d'attributs ne le faire que si la DTD est dispo et d'accord
88
+    // (param fusion_bal)
89
+
90
+    if ($t || (($ouv != $name) and !$fusion_bal)) {
91
+        $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">";
92
+    } else {
93
+        $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">"));
94
+    }
95 95
 }
96 96
 
97 97
 // http://code.spip.net/@xml_textElement
98 98
 function xml_textElement($phraseur, $data) {
99
-	$depth = $phraseur->depth;
100
-	$phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth])
101
-		? $data
102
-		: xml_entites_html($data);
99
+    $depth = $phraseur->depth;
100
+    $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth])
101
+        ? $data
102
+        : xml_entites_html($data);
103 103
 }
104 104
 
105 105
 function xml_piElement($phraseur, $target, $data) {
106
-	$depth = $phraseur->depth;
107
-
108
-	if (strtolower($target) != "php") {
109
-		$phraseur->contenu[$depth] .= $data;
110
-	} else {
111
-		ob_start();
112
-		eval($data);
113
-		$data = ob_get_contents();
114
-		ob_end_clean();
115
-		$phraseur->contenu[$depth] .= $data;
116
-	}
106
+    $depth = $phraseur->depth;
107
+
108
+    if (strtolower($target) != "php") {
109
+        $phraseur->contenu[$depth] .= $data;
110
+    } else {
111
+        ob_start();
112
+        eval($data);
113
+        $data = ob_get_contents();
114
+        ob_end_clean();
115
+        $phraseur->contenu[$depth] .= $data;
116
+    }
117 117
 }
118 118
 
119 119
 
120 120
 // http://code.spip.net/@xml_defautElement
121 121
 function xml_defaultElement($phraseur, $data) {
122
-	$depth = $phraseur->depth;
122
+    $depth = $phraseur->depth;
123 123
 
124
-	if (!isset($phraseur->contenu[$depth])) {
125
-		$phraseur->contenu[$depth] = '';
126
-	}
127
-	$phraseur->contenu[$depth] .= $data;
124
+    if (!isset($phraseur->contenu[$depth])) {
125
+        $phraseur->contenu[$depth] = '';
126
+    }
127
+    $phraseur->contenu[$depth] .= $data;
128 128
 }
129 129
 
130 130
 // http://code.spip.net/@xml_parsestring
131 131
 function xml_parsestring($phraseur, $data) {
132
-	$phraseur->contenu[$phraseur->depth] = '';
133
-
134
-	if (!xml_parse($phraseur->sax, $data, true)) {
135
-		coordonnees_erreur($phraseur,
136
-			xml_error_string(xml_get_error_code($phraseur->sax))
137
-			. "<br />\n" .
138
-			(!$phraseur->depth ? '' :
139
-				('(' .
140
-					_T('erreur_balise_non_fermee') .
141
-					" <tt>" .
142
-					$phraseur->ouvrant[$phraseur->depth] .
143
-					"</tt> " .
144
-					_T('ligne') .
145
-					" " .
146
-					$phraseur->reperes[$phraseur->depth] .
147
-					") <br />\n")));
148
-	}
132
+    $phraseur->contenu[$phraseur->depth] = '';
133
+
134
+    if (!xml_parse($phraseur->sax, $data, true)) {
135
+        coordonnees_erreur($phraseur,
136
+            xml_error_string(xml_get_error_code($phraseur->sax))
137
+            . "<br />\n" .
138
+            (!$phraseur->depth ? '' :
139
+                ('(' .
140
+                    _T('erreur_balise_non_fermee') .
141
+                    " <tt>" .
142
+                    $phraseur->ouvrant[$phraseur->depth] .
143
+                    "</tt> " .
144
+                    _T('ligne') .
145
+                    " " .
146
+                    $phraseur->reperes[$phraseur->depth] .
147
+                    ") <br />\n")));
148
+    }
149 149
 }
150 150
 
151 151
 // http://code.spip.net/@coordonnees_erreur
152 152
 function coordonnees_erreur($phraseur, $msg) {
153
-	$entete_length = substr_count($phraseur->entete, "\n");
154
-	$phraseur->err[] = array(
155
-		$msg,
156
-		xml_get_current_line_number($phraseur->sax) + $entete_length,
157
-		xml_get_current_column_number($phraseur->sax)
158
-	);
153
+    $entete_length = substr_count($phraseur->entete, "\n");
154
+    $phraseur->err[] = array(
155
+        $msg,
156
+        xml_get_current_line_number($phraseur->sax) + $entete_length,
157
+        xml_get_current_column_number($phraseur->sax)
158
+    );
159 159
 }
160 160
 
161 161
 // http://code.spip.net/@xml_sax_dist
162 162
 function xml_sax_dist($page, $apply = false, $phraseur = null, $doctype = '', $charset = null) {
163
-	if (is_null($charset)) {
164
-		$charset = $GLOBALS['meta']['charset'];
165
-	}
166
-	if ($apply) {
167
-		ob_start();
168
-		if (is_array($apply)) {
169
-			$r = call_user_func_array($page, $apply);
170
-		} else {
171
-			$r = $page();
172
-		}
173
-		$page = ob_get_contents();
174
-		ob_end_clean();
175
-		// fonction sans aucun "echo", ca doit etre le resultat
176
-		if (!$page) {
177
-			$page = $r;
178
-		}
179
-	}
180
-
181
-	if (!$page) {
182
-		return '';
183
-	}
184
-	// charger la DTD et transcoder les entites,
185
-	// et escamoter le doctype que sax mange en php5 mais pas en  php4
186
-	if (!$doctype) {
187
-		if (!$r = analyser_doctype($page)) {
188
-			$page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
189
-				. preg_replace(_REGEXP_DOCTYPE, '', $page);
190
-			$r = analyser_doctype($page);
191
-		}
192
-		list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null);
193
-		$page = substr($page, strlen($entete));
194
-	} else {
195
-		$avail = 'SYSTEM';
196
-		$grammaire = $doctype;
197
-		$rotlvl = basename($grammaire);
198
-	}
199
-
200
-	include_spip('xml/analyser_dtd');
201
-	$dtc = charger_dtd($grammaire, $avail, $rotlvl);
202
-	$page = sax_bug($page, $dtc, $charset);
203
-
204
-	// compatibilite Tidy espace public
205
-	if (!$phraseur) {
206
-		$indenter_xml = charger_fonction('indenter', 'xml');
207
-
208
-		return $indenter_xml($page, $apply);
209
-	}
210
-
211
-	$xml_parser = xml_parser_create($charset);
212
-
213
-	xml_set_element_handler($xml_parser,
214
-		array($phraseur, "debutElement"),
215
-		array($phraseur, "finElement"));
216
-
217
-	xml_set_character_data_handler($xml_parser,
218
-		array($phraseur, "textElement"));
219
-
220
-	xml_set_processing_instruction_handler($xml_parser,
221
-		array($phraseur, 'piElement'));
222
-
223
-	xml_set_default_handler($xml_parser,
224
-		array($phraseur, "defaultElement"));
225
-
226
-	xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
227
-
228
-	$phraseur->sax = $xml_parser;
229
-	if (isset($entete)) {
230
-		$phraseur->entete = $entete;
231
-	}
232
-	$phraseur->page = $page;
233
-	$phraseur->dtc = $dtc;
234
-	$phraseur->phraserTout($xml_parser, $page);
235
-	xml_parser_free($xml_parser);
236
-	$phraseur->sax = '';
237
-
238
-	return $phraseur;
163
+    if (is_null($charset)) {
164
+        $charset = $GLOBALS['meta']['charset'];
165
+    }
166
+    if ($apply) {
167
+        ob_start();
168
+        if (is_array($apply)) {
169
+            $r = call_user_func_array($page, $apply);
170
+        } else {
171
+            $r = $page();
172
+        }
173
+        $page = ob_get_contents();
174
+        ob_end_clean();
175
+        // fonction sans aucun "echo", ca doit etre le resultat
176
+        if (!$page) {
177
+            $page = $r;
178
+        }
179
+    }
180
+
181
+    if (!$page) {
182
+        return '';
183
+    }
184
+    // charger la DTD et transcoder les entites,
185
+    // et escamoter le doctype que sax mange en php5 mais pas en  php4
186
+    if (!$doctype) {
187
+        if (!$r = analyser_doctype($page)) {
188
+            $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
189
+                . preg_replace(_REGEXP_DOCTYPE, '', $page);
190
+            $r = analyser_doctype($page);
191
+        }
192
+        list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null);
193
+        $page = substr($page, strlen($entete));
194
+    } else {
195
+        $avail = 'SYSTEM';
196
+        $grammaire = $doctype;
197
+        $rotlvl = basename($grammaire);
198
+    }
199
+
200
+    include_spip('xml/analyser_dtd');
201
+    $dtc = charger_dtd($grammaire, $avail, $rotlvl);
202
+    $page = sax_bug($page, $dtc, $charset);
203
+
204
+    // compatibilite Tidy espace public
205
+    if (!$phraseur) {
206
+        $indenter_xml = charger_fonction('indenter', 'xml');
207
+
208
+        return $indenter_xml($page, $apply);
209
+    }
210
+
211
+    $xml_parser = xml_parser_create($charset);
212
+
213
+    xml_set_element_handler($xml_parser,
214
+        array($phraseur, "debutElement"),
215
+        array($phraseur, "finElement"));
216
+
217
+    xml_set_character_data_handler($xml_parser,
218
+        array($phraseur, "textElement"));
219
+
220
+    xml_set_processing_instruction_handler($xml_parser,
221
+        array($phraseur, 'piElement'));
222
+
223
+    xml_set_default_handler($xml_parser,
224
+        array($phraseur, "defaultElement"));
225
+
226
+    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
227
+
228
+    $phraseur->sax = $xml_parser;
229
+    if (isset($entete)) {
230
+        $phraseur->entete = $entete;
231
+    }
232
+    $phraseur->page = $page;
233
+    $phraseur->dtc = $dtc;
234
+    $phraseur->phraserTout($xml_parser, $page);
235
+    xml_parser_free($xml_parser);
236
+    $phraseur->sax = '';
237
+
238
+    return $phraseur;
239 239
 }
240 240
 
241 241
 // SAX ne dit pas si une Entite est dans un attribut ou non.
@@ -247,24 +247,24 @@  discard block
 block discarded – undo
247 247
 
248 248
 // http://code.spip.net/@sax_bug
249 249
 function sax_bug($data, $dtc, $charset = null) {
250
-	if (is_null($charset)) {
251
-		$charset = $GLOBALS['meta']['charset'];
252
-	}
253
-
254
-	if ($dtc) {
255
-		$trans = array();
256
-
257
-		foreach ($dtc->entites as $k => $v) {
258
-			if (!strpos(" amp lt gt quot ", $k)) {
259
-				$trans["&$k;"] = $v;
260
-			}
261
-		}
262
-		$data = strtr($data, $trans);
263
-	} else {
264
-		$data = html2unicode($data, true);
265
-	}
266
-
267
-	return unicode2charset($data, $charset);
250
+    if (is_null($charset)) {
251
+        $charset = $GLOBALS['meta']['charset'];
252
+    }
253
+
254
+    if ($dtc) {
255
+        $trans = array();
256
+
257
+        foreach ($dtc->entites as $k => $v) {
258
+            if (!strpos(" amp lt gt quot ", $k)) {
259
+                $trans["&$k;"] = $v;
260
+            }
261
+        }
262
+        $data = strtr($data, $trans);
263
+    } else {
264
+        $data = html2unicode($data, true);
265
+    }
266
+
267
+    return unicode2charset($data, $charset);
268 268
 }
269 269
 
270 270
 // Retirer < ? xml... ? > et autre PI, ainsi que les commentaires en debut
@@ -275,52 +275,52 @@  discard block
 block discarded – undo
275 275
 // mais un XML Schema que SPIP ne fait pas encore lire.
276 276
 // http://code.spip.net/@analyser_doctype
277 277
 function analyser_doctype($data) {
278
-	if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) {
279
-		if (preg_match(_REGEXP_XML, $data, $page)) {
280
-			list(, $entete, $topelement) = $page;
281
-			if ($topelement == 'rss') {
282
-				return array(
283
-					$entete,
284
-					'PUBLIC',
285
-					_DOCTYPE_RSS,
286
-					'rss-0.91.dtd'
287
-				);
288
-			} else {
289
-				$dtd = $topelement . '.dtd';
290
-				$f = find_in_path($dtd);
291
-				if (file_exists($f)) {
292
-					return array($entete, 'SYSTEM', $f, $dtd);
293
-				}
294
-			}
295
-		}
296
-		spip_log("Dtd pas vu pour " . substr($data, 0, 100));
297
-
298
-		return array();
299
-	}
300
-	list($entete, , $topelement, $avail, $suite) = $page;
301
-
302
-	if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) {
303
-		if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) {
304
-			return array();
305
-		}
306
-	}
307
-	list(, $rotlvl, $suite) = $r;
308
-
309
-	if (!$suite) {
310
-		if ($avail != 'SYSTEM') {
311
-			return array();
312
-		}
313
-		$grammaire = $rotlvl;
314
-		$rotlvl = '';
315
-	} else {
316
-		if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) {
317
-			if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) {
318
-				return array();
319
-			}
320
-		}
321
-
322
-		$grammaire = $r[1];
323
-	}
324
-
325
-	return array($entete, $avail, $grammaire, $rotlvl);
278
+    if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) {
279
+        if (preg_match(_REGEXP_XML, $data, $page)) {
280
+            list(, $entete, $topelement) = $page;
281
+            if ($topelement == 'rss') {
282
+                return array(
283
+                    $entete,
284
+                    'PUBLIC',
285
+                    _DOCTYPE_RSS,
286
+                    'rss-0.91.dtd'
287
+                );
288
+            } else {
289
+                $dtd = $topelement . '.dtd';
290
+                $f = find_in_path($dtd);
291
+                if (file_exists($f)) {
292
+                    return array($entete, 'SYSTEM', $f, $dtd);
293
+                }
294
+            }
295
+        }
296
+        spip_log("Dtd pas vu pour " . substr($data, 0, 100));
297
+
298
+        return array();
299
+    }
300
+    list($entete, , $topelement, $avail, $suite) = $page;
301
+
302
+    if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) {
303
+        if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) {
304
+            return array();
305
+        }
306
+    }
307
+    list(, $rotlvl, $suite) = $r;
308
+
309
+    if (!$suite) {
310
+        if ($avail != 'SYSTEM') {
311
+            return array();
312
+        }
313
+        $grammaire = $rotlvl;
314
+        $rotlvl = '';
315
+    } else {
316
+        if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) {
317
+            if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) {
318
+                return array();
319
+            }
320
+        }
321
+
322
+        $grammaire = $r[1];
323
+    }
324
+
325
+    return array($entete, $avail, $grammaire, $rotlvl);
326 326
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -22 removed lines patch added patch discarded remove patch
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
 	$t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' ';
46 46
 	// espace initial signifie: deja integree au resultat
47 47
 	if ($t[0] != ' ') {
48
-		$phraseur->res .= '<' . $t . '>';
49
-		$phraseur->ouvrant[$depth] = ' ' . $t;
48
+		$phraseur->res .= '<'.$t.'>';
49
+		$phraseur->ouvrant[$depth] = ' '.$t;
50 50
 	}
51 51
 	$t = $phraseur->contenu[$depth];
52 52
 	// n'indenter que s'il y a un separateur avant
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 	foreach ($attrs as $k => $v) {
58 58
 		$delim = strpos($v, "'") === false ? "'" : '"';
59 59
 		$val = xml_entites_html($v);
60
-		$att .= $sep . $k . "=" . $delim
60
+		$att .= $sep.$k."=".$delim
61 61
 			. ($delim !== '"' ? str_replace('&quot;', '"', $val) : $val)
62 62
 			. $delim;
63 63
 		$sep = "\n $depth";
64 64
 	}
65 65
 	$phraseur->depth .= '  ';
66 66
 	$phraseur->contenu[$phraseur->depth] = "";
67
-	$phraseur->ouvrant[$phraseur->depth] = $name . $att;
67
+	$phraseur->ouvrant[$phraseur->depth] = $name.$att;
68 68
 	$phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
69 69
 }
70 70
 
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
 	$ouv = $phraseur->ouvrant[$phraseur->depth];
74 74
 
75 75
 	if ($ouv[0] != ' ') {
76
-		$phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv;
76
+		$phraseur->ouvrant[$phraseur->depth] = ' '.$ouv;
77 77
 	} else {
78 78
 		$ouv = "";
79 79
 	}
80 80
 	$t = $phraseur->contenu[$phraseur->depth];
81 81
 	$phraseur->depth = substr($phraseur->depth, 2);
82
-	$t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t);
82
+	$t = preg_replace("/[\n\t ]+$/", "\n".$phraseur->depth, $t);
83 83
 
84 84
 	// fusion <balise></balise> en <balise />.
85 85
 	// ATTENTION,  certains clients http croient que fusion ==> pas d'atttributs
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 	// (param fusion_bal)
89 89
 
90 90
 	if ($t || (($ouv != $name) and !$fusion_bal)) {
91
-		$phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">";
91
+		$phraseur->res .= ($ouv ? ('<'.$ouv.'>') : '').$t."</".$name.">";
92 92
 	} else {
93
-		$phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">"));
93
+		$phraseur->res .= ($ouv ? ('<'.$ouv.' />') : ("</".$name.">"));
94 94
 	}
95 95
 }
96 96
 
@@ -134,16 +134,15 @@  discard block
 block discarded – undo
134 134
 	if (!xml_parse($phraseur->sax, $data, true)) {
135 135
 		coordonnees_erreur($phraseur,
136 136
 			xml_error_string(xml_get_error_code($phraseur->sax))
137
-			. "<br />\n" .
138
-			(!$phraseur->depth ? '' :
139
-				('(' .
140
-					_T('erreur_balise_non_fermee') .
141
-					" <tt>" .
142
-					$phraseur->ouvrant[$phraseur->depth] .
143
-					"</tt> " .
144
-					_T('ligne') .
145
-					" " .
146
-					$phraseur->reperes[$phraseur->depth] .
137
+			. "<br />\n".
138
+			(!$phraseur->depth ? '' : ('('.
139
+					_T('erreur_balise_non_fermee').
140
+					" <tt>".
141
+					$phraseur->ouvrant[$phraseur->depth].
142
+					"</tt> ".
143
+					_T('ligne').
144
+					" ".
145
+					$phraseur->reperes[$phraseur->depth].
147 146
 					") <br />\n")));
148 147
 	}
149 148
 }
@@ -185,7 +184,7 @@  discard block
 block discarded – undo
185 184
 	// et escamoter le doctype que sax mange en php5 mais pas en  php4
186 185
 	if (!$doctype) {
187 186
 		if (!$r = analyser_doctype($page)) {
188
-			$page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
187
+			$page = _MESSAGE_DOCTYPE._DOCTYPE_ECRIRE
189 188
 				. preg_replace(_REGEXP_DOCTYPE, '', $page);
190 189
 			$r = analyser_doctype($page);
191 190
 		}
@@ -286,18 +285,18 @@  discard block
 block discarded – undo
286 285
 					'rss-0.91.dtd'
287 286
 				);
288 287
 			} else {
289
-				$dtd = $topelement . '.dtd';
288
+				$dtd = $topelement.'.dtd';
290 289
 				$f = find_in_path($dtd);
291 290
 				if (file_exists($f)) {
292 291
 					return array($entete, 'SYSTEM', $f, $dtd);
293 292
 				}
294 293
 			}
295 294
 		}
296
-		spip_log("Dtd pas vu pour " . substr($data, 0, 100));
295
+		spip_log("Dtd pas vu pour ".substr($data, 0, 100));
297 296
 
298 297
 		return array();
299 298
 	}
300
-	list($entete, , $topelement, $avail, $suite) = $page;
299
+	list($entete,, $topelement, $avail, $suite) = $page;
301 300
 
302 301
 	if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) {
303 302
 		if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) {
Please login to merge, or discard this patch.
ecrire/inc/securiser_action.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -304,6 +304,7 @@
 block discarded – undo
304 304
  * @param string $url Url à autoriser en prévisu
305 305
  * @param int|null id_auteur qui génère le token de prévisu. Null utilisera auteur courant.
306 306
  * @param string $alea Nom de l’alea à utiliser
307
+ * @param integer $id_auteur
307 308
  * @return string Token, de la forme "{id}*{hash}"
308 309
  */
309 310
 function calculer_token_previsu($url, $id_auteur = null, $alea = 'alea_ephemere') {
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
 /**
@@ -50,19 +50,19 @@  discard block
 block discarded – undo
50 50
  * @return array|string
51 51
  */
52 52
 function inc_securiser_action_dist($action = '', $arg = '', $redirect = "", $mode = false, $att = '', $public = false) {
53
-	if ($action) {
54
-		return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public);
55
-	} else {
56
-		$arg = _request('arg');
57
-		$hash = _request('hash');
58
-		$action = _request('action') ? _request('action') : _request('formulaire_action');
59
-		if ($a = verifier_action_auteur("$action-$arg", $hash)) {
60
-			return $arg;
61
-		}
62
-		include_spip('inc/minipres');
63
-		echo minipres();
64
-		exit;
65
-	}
53
+    if ($action) {
54
+        return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public);
55
+    } else {
56
+        $arg = _request('arg');
57
+        $hash = _request('hash');
58
+        $action = _request('action') ? _request('action') : _request('formulaire_action');
59
+        if ($a = verifier_action_auteur("$action-$arg", $hash)) {
60
+            return $arg;
61
+        }
62
+        include_spip('inc/minipres');
63
+        echo minipres();
64
+        exit;
65
+    }
66 66
 }
67 67
 
68 68
 /**
@@ -94,30 +94,30 @@  discard block
 block discarded – undo
94 94
  */
95 95
 function securiser_action_auteur($action, $arg, $redirect = "", $mode = false, $att = '', $public = false) {
96 96
 
97
-	// mode URL ou array
98
-	if (!is_string($mode)) {
99
-		$hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null);
100
-
101
-		$r = rawurlencode($redirect);
102
-		if ($mode === -1) {
103
-			return array('action' => $action, 'arg' => $arg, 'hash' => $hash);
104
-		} else {
105
-			return generer_url_action($action, "arg=" . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
106
-				$mode, $public);
107
-		}
108
-	}
109
-
110
-	// mode formulaire
111
-	$hash = calculer_action_auteur("$action-$arg");
112
-	$att .= " style='margin: 0px; border: 0px'";
113
-	if ($redirect) {
114
-		$redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
115
-	}
116
-	$mode .= $redirect . "
97
+    // mode URL ou array
98
+    if (!is_string($mode)) {
99
+        $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null);
100
+
101
+        $r = rawurlencode($redirect);
102
+        if ($mode === -1) {
103
+            return array('action' => $action, 'arg' => $arg, 'hash' => $hash);
104
+        } else {
105
+            return generer_url_action($action, "arg=" . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
106
+                $mode, $public);
107
+        }
108
+    }
109
+
110
+    // mode formulaire
111
+    $hash = calculer_action_auteur("$action-$arg");
112
+    $att .= " style='margin: 0px; border: 0px'";
113
+    if ($redirect) {
114
+        $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
115
+    }
116
+    $mode .= $redirect . "
117 117
 <input name='hash' type='hidden' value='$hash' />
118 118
 <input name='arg' type='hidden' value='$arg' />";
119 119
 
120
-	return generer_form_action($action, $mode, $att, $public);
120
+    return generer_form_action($action, $mode, $att, $public);
121 121
 }
122 122
 
123 123
 /**
@@ -127,47 +127,47 @@  discard block
 block discarded – undo
127 127
  * @return array
128 128
  */
129 129
 function caracteriser_auteur($id_auteur = null) {
130
-	static $caracterisation = array();
131
-
132
-	if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) {
133
-		// si l'auteur courant n'est pas connu alors qu'il peut demander une action
134
-		// c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie.
135
-		// S'il n'avait pas le droit de realiser cette action, le hash sera faux.
136
-		if (isset($_COOKIE['spip_session'])
137
-			and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r))
138
-		) {
139
-			return array($r[1], '');
140
-			// Necessaire aux forums anonymes.
141
-			// Pour le reste, ca echouera.
142
-		} else {
143
-			return array('0', '');
144
-		}
145
-	}
146
-	// Eviter l'acces SQL si le pass est connu de PHP
147
-	if (is_null($id_auteur)) {
148
-		$id_auteur = isset($GLOBALS['visiteur_session']['id_auteur']) ? $GLOBALS['visiteur_session']['id_auteur'] : 0;
149
-		if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) {
150
-			return $caracterisation[$id_auteur] = array($id_auteur, $GLOBALS['visiteur_session']['pass']);
151
-		}
152
-	}
153
-
154
-	if (isset($caracterisation[$id_auteur])) {
155
-		return $caracterisation[$id_auteur];
156
-	}
157
-
158
-	if ($id_auteur) {
159
-		include_spip('base/abstract_sql');
160
-		$t = sql_fetsel("id_auteur, pass", "spip_auteurs", "id_auteur=$id_auteur");
161
-		if ($t) {
162
-			return $caracterisation[$id_auteur] = array($t['id_auteur'], $t['pass']);
163
-		}
164
-		include_spip('inc/minipres');
165
-		echo minipres();
166
-		exit;
167
-	} // Visiteur anonyme, pour ls forums par exemple
168
-	else {
169
-		return array('0', '');
170
-	}
130
+    static $caracterisation = array();
131
+
132
+    if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) {
133
+        // si l'auteur courant n'est pas connu alors qu'il peut demander une action
134
+        // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie.
135
+        // S'il n'avait pas le droit de realiser cette action, le hash sera faux.
136
+        if (isset($_COOKIE['spip_session'])
137
+            and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r))
138
+        ) {
139
+            return array($r[1], '');
140
+            // Necessaire aux forums anonymes.
141
+            // Pour le reste, ca echouera.
142
+        } else {
143
+            return array('0', '');
144
+        }
145
+    }
146
+    // Eviter l'acces SQL si le pass est connu de PHP
147
+    if (is_null($id_auteur)) {
148
+        $id_auteur = isset($GLOBALS['visiteur_session']['id_auteur']) ? $GLOBALS['visiteur_session']['id_auteur'] : 0;
149
+        if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) {
150
+            return $caracterisation[$id_auteur] = array($id_auteur, $GLOBALS['visiteur_session']['pass']);
151
+        }
152
+    }
153
+
154
+    if (isset($caracterisation[$id_auteur])) {
155
+        return $caracterisation[$id_auteur];
156
+    }
157
+
158
+    if ($id_auteur) {
159
+        include_spip('base/abstract_sql');
160
+        $t = sql_fetsel("id_auteur, pass", "spip_auteurs", "id_auteur=$id_auteur");
161
+        if ($t) {
162
+            return $caracterisation[$id_auteur] = array($t['id_auteur'], $t['pass']);
163
+        }
164
+        include_spip('inc/minipres');
165
+        echo minipres();
166
+        exit;
167
+    } // Visiteur anonyme, pour ls forums par exemple
168
+    else {
169
+        return array('0', '');
170
+    }
171 171
 }
172 172
 
173 173
 /**
@@ -182,26 +182,26 @@  discard block
 block discarded – undo
182 182
  * @return string
183 183
  */
184 184
 function _action_auteur($action, $id_auteur, $pass, $alea) {
185
-	static $sha = array();
186
-	if (!isset($sha[$id_auteur . $pass . $alea])) {
187
-		if (!isset($GLOBALS['meta'][$alea]) and _request('exec') !== 'install') {
188
-			include_spip('inc/acces');
189
-			charger_aleas();
190
-			if (empty($GLOBALS['meta'][$alea])) {
191
-				include_spip('inc/minipres');
192
-				echo minipres();
193
-				spip_log("$alea indisponible");
194
-				exit;
195
-			}
196
-		}
197
-		include_spip('auth/sha256.inc');
198
-		$sha[$id_auteur . $pass . $alea] = _nano_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]);
199
-	}
200
-	if (function_exists('sha1')) {
201
-		return sha1($action . $sha[$id_auteur . $pass . $alea]);
202
-	} else {
203
-		return md5($action . $sha[$id_auteur . $pass . $alea]);
204
-	}
185
+    static $sha = array();
186
+    if (!isset($sha[$id_auteur . $pass . $alea])) {
187
+        if (!isset($GLOBALS['meta'][$alea]) and _request('exec') !== 'install') {
188
+            include_spip('inc/acces');
189
+            charger_aleas();
190
+            if (empty($GLOBALS['meta'][$alea])) {
191
+                include_spip('inc/minipres');
192
+                echo minipres();
193
+                spip_log("$alea indisponible");
194
+                exit;
195
+            }
196
+        }
197
+        include_spip('auth/sha256.inc');
198
+        $sha[$id_auteur . $pass . $alea] = _nano_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]);
199
+    }
200
+    if (function_exists('sha1')) {
201
+        return sha1($action . $sha[$id_auteur . $pass . $alea]);
202
+    } else {
203
+        return md5($action . $sha[$id_auteur . $pass . $alea]);
204
+    }
205 205
 }
206 206
 
207 207
 /**
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
  * @return string
213 213
  */
214 214
 function calculer_action_auteur($action, $id_auteur = null) {
215
-	list($id_auteur, $pass) = caracteriser_auteur($id_auteur);
215
+    list($id_auteur, $pass) = caracteriser_auteur($id_auteur);
216 216
 
217
-	return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere');
217
+    return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere');
218 218
 }
219 219
 
220 220
 
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
  * @return bool
228 228
  */
229 229
 function verifier_action_auteur($action, $hash) {
230
-	list($id_auteur, $pass) = caracteriser_auteur();
231
-	if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) {
232
-		return true;
233
-	}
234
-	if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')) {
235
-		return true;
236
-	}
237
-
238
-	return false;
230
+    list($id_auteur, $pass) = caracteriser_auteur();
231
+    if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) {
232
+        return true;
233
+    }
234
+    if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')) {
235
+        return true;
236
+    }
237
+
238
+    return false;
239 239
 }
240 240
 
241 241
 //
@@ -251,21 +251,21 @@  discard block
 block discarded – undo
251 251
  * @return string
252 252
  */
253 253
 function secret_du_site() {
254
-	if (!isset($GLOBALS['meta']['secret_du_site'])) {
255
-		include_spip('base/abstract_sql');
256
-		$GLOBALS['meta']['secret_du_site'] = sql_getfetsel('valeur', 'spip_meta', "nom='secret_du_site'");
257
-	}
258
-	if (!isset($GLOBALS['meta']['secret_du_site'])
259
-		or (strlen($GLOBALS['meta']['secret_du_site']) < 64)
260
-	) {
261
-		include_spip('inc/acces');
262
-		include_spip('auth/sha256.inc');
263
-		ecrire_meta('secret_du_site',
264
-			_nano_sha256($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SERVER_SIGNATURE"] . creer_uniqid()), 'non');
265
-		lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas
266
-	}
267
-
268
-	return $GLOBALS['meta']['secret_du_site'];
254
+    if (!isset($GLOBALS['meta']['secret_du_site'])) {
255
+        include_spip('base/abstract_sql');
256
+        $GLOBALS['meta']['secret_du_site'] = sql_getfetsel('valeur', 'spip_meta', "nom='secret_du_site'");
257
+    }
258
+    if (!isset($GLOBALS['meta']['secret_du_site'])
259
+        or (strlen($GLOBALS['meta']['secret_du_site']) < 64)
260
+    ) {
261
+        include_spip('inc/acces');
262
+        include_spip('auth/sha256.inc');
263
+        ecrire_meta('secret_du_site',
264
+            _nano_sha256($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SERVER_SIGNATURE"] . creer_uniqid()), 'non');
265
+        lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas
266
+    }
267
+
268
+    return $GLOBALS['meta']['secret_du_site'];
269 269
 }
270 270
 
271 271
 /**
@@ -275,11 +275,11 @@  discard block
 block discarded – undo
275 275
  * @return string
276 276
  */
277 277
 function calculer_cle_action($action) {
278
-	if (function_exists('sha1')) {
279
-		return sha1($action . secret_du_site());
280
-	} else {
281
-		return md5($action . secret_du_site());
282
-	}
278
+    if (function_exists('sha1')) {
279
+        return sha1($action . secret_du_site());
280
+    } else {
281
+        return md5($action . secret_du_site());
282
+    }
283 283
 }
284 284
 
285 285
 /**
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
  * @return bool
291 291
  */
292 292
 function verifier_cle_action($action, $cle) {
293
-	return ($cle == calculer_cle_action($action));
293
+    return ($cle == calculer_cle_action($action));
294 294
 }
295 295
 
296 296
 
@@ -307,19 +307,19 @@  discard block
 block discarded – undo
307 307
  * @return string Token, de la forme "{id}*{hash}"
308 308
  */
309 309
 function calculer_token_previsu($url, $id_auteur = null, $alea = 'alea_ephemere') {
310
-	if (is_null($id_auteur)) {
311
-		if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
312
-			$id_auteur = $GLOBALS['visiteur_session']['id_auteur'];
313
-		}
314
-	}
315
-	if (!$id_auteur = intval($id_auteur)) {
316
-		return "";
317
-	}
318
-	// On nettoie l’URL de tous les var_.
319
-	$url = nettoyer_uri_var($url);
320
-
321
-	$token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea);
322
-	return "$id_auteur-$token";
310
+    if (is_null($id_auteur)) {
311
+        if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
312
+            $id_auteur = $GLOBALS['visiteur_session']['id_auteur'];
313
+        }
314
+    }
315
+    if (!$id_auteur = intval($id_auteur)) {
316
+        return "";
317
+    }
318
+    // On nettoie l’URL de tous les var_.
319
+    $url = nettoyer_uri_var($url);
320
+
321
+    $token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea);
322
+    return "$id_auteur-$token";
323 323
 }
324 324
 
325 325
 
@@ -337,31 +337,31 @@  discard block
 block discarded – undo
337 337
  *     + Tableau (id auteur, type d’objet, id_objet) sinon.
338 338
  */
339 339
 function verifier_token_previsu($token) {
340
-	// retrouver auteur / hash
341
-	$e = explode('-', $token, 2);
342
-	if (count($e) == 2 and is_numeric(reset($e))) {
343
-		$id_auteur = intval(reset($e));
344
-	} else {
345
-		return false;
346
-	}
347
-
348
-	// calculer le type et id de l’url actuelle
349
-	include_spip('inc/urls');
350
-	include_spip('inc/filtres_mini');
351
-	$url = url_absolue(self());
352
-
353
-	// verifier le token
354
-	$_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere');
355
-	if (!$_token or $token !== $_token) {
356
-		$_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien');
357
-		if (!$_token or $token !== $_token) {
358
-			return false;
359
-		}
360
-	}
361
-
362
-	return array(
363
-		'id_auteur' => $id_auteur,
364
-	);
340
+    // retrouver auteur / hash
341
+    $e = explode('-', $token, 2);
342
+    if (count($e) == 2 and is_numeric(reset($e))) {
343
+        $id_auteur = intval(reset($e));
344
+    } else {
345
+        return false;
346
+    }
347
+
348
+    // calculer le type et id de l’url actuelle
349
+    include_spip('inc/urls');
350
+    include_spip('inc/filtres_mini');
351
+    $url = url_absolue(self());
352
+
353
+    // verifier le token
354
+    $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere');
355
+    if (!$_token or $token !== $_token) {
356
+        $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien');
357
+        if (!$_token or $token !== $_token) {
358
+            return false;
359
+        }
360
+    }
361
+
362
+    return array(
363
+        'id_auteur' => $id_auteur,
364
+    );
365 365
 }
366 366
 
367 367
 /**
@@ -370,13 +370,13 @@  discard block
 block discarded – undo
370 370
  * @return bool|array
371 371
  */
372 372
 function decrire_token_previsu() {
373
-	static $desc = null;
374
-	if (is_null($desc)) {
375
-		if ($token = _request('var_previewtoken')) {
376
-			$desc = verifier_token_previsu($token);
377
-		} else {
378
-			$desc = false;
379
-		}
380
-	}
381
-	return $desc;
373
+    static $desc = null;
374
+    if (is_null($desc)) {
375
+        if ($token = _request('var_previewtoken')) {
376
+            $desc = verifier_token_previsu($token);
377
+        } else {
378
+            $desc = false;
379
+        }
380
+    }
381
+    return $desc;
382 382
 }
383 383
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		if ($mode === -1) {
103 103
 			return array('action' => $action, 'arg' => $arg, 'hash' => $hash);
104 104
 		} else {
105
-			return generer_url_action($action, "arg=" . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
105
+			return generer_url_action($action, "arg=".rawurlencode($arg)."&hash=$hash".(!$r ? '' : "&redirect=$r"),
106 106
 				$mode, $public);
107 107
 		}
108 108
 	}
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 	$hash = calculer_action_auteur("$action-$arg");
112 112
 	$att .= " style='margin: 0px; border: 0px'";
113 113
 	if ($redirect) {
114
-		$redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
114
+		$redirect = "\n\t\t<input name='redirect' type='hidden' value='".str_replace("'", '&#39;', $redirect)."' />";
115 115
 	}
116
-	$mode .= $redirect . "
116
+	$mode .= $redirect."
117 117
 <input name='hash' type='hidden' value='$hash' />
118 118
 <input name='arg' type='hidden' value='$arg' />";
119 119
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
  */
184 184
 function _action_auteur($action, $id_auteur, $pass, $alea) {
185 185
 	static $sha = array();
186
-	if (!isset($sha[$id_auteur . $pass . $alea])) {
186
+	if (!isset($sha[$id_auteur.$pass.$alea])) {
187 187
 		if (!isset($GLOBALS['meta'][$alea]) and _request('exec') !== 'install') {
188 188
 			include_spip('inc/acces');
189 189
 			charger_aleas();
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
 			}
196 196
 		}
197 197
 		include_spip('auth/sha256.inc');
198
-		$sha[$id_auteur . $pass . $alea] = _nano_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]);
198
+		$sha[$id_auteur.$pass.$alea] = _nano_sha256($id_auteur.$pass.@$GLOBALS['meta'][$alea]);
199 199
 	}
200 200
 	if (function_exists('sha1')) {
201
-		return sha1($action . $sha[$id_auteur . $pass . $alea]);
201
+		return sha1($action.$sha[$id_auteur.$pass.$alea]);
202 202
 	} else {
203
-		return md5($action . $sha[$id_auteur . $pass . $alea]);
203
+		return md5($action.$sha[$id_auteur.$pass.$alea]);
204 204
 	}
205 205
 }
206 206
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 		include_spip('inc/acces');
262 262
 		include_spip('auth/sha256.inc');
263 263
 		ecrire_meta('secret_du_site',
264
-			_nano_sha256($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SERVER_SIGNATURE"] . creer_uniqid()), 'non');
264
+			_nano_sha256($_SERVER["DOCUMENT_ROOT"].$_SERVER["SERVER_SIGNATURE"].creer_uniqid()), 'non');
265 265
 		lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas
266 266
 	}
267 267
 
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
  */
277 277
 function calculer_cle_action($action) {
278 278
 	if (function_exists('sha1')) {
279
-		return sha1($action . secret_du_site());
279
+		return sha1($action.secret_du_site());
280 280
 	} else {
281
-		return md5($action . secret_du_site());
281
+		return md5($action.secret_du_site());
282 282
 	}
283 283
 }
284 284
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 	// On nettoie l’URL de tous les var_.
319 319
 	$url = nettoyer_uri_var($url);
320 320
 
321
-	$token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea);
321
+	$token = _action_auteur('previsualiser-'.$url, $id_auteur, null, $alea);
322 322
 	return "$id_auteur-$token";
323 323
 }
324 324
 
Please login to merge, or discard this patch.
ecrire/public/quete.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 /**
29 29
  * Retourne l'URL de redirection d'un article virtuel, seulement si il est publié
30 30
  *
31
- * @param $id_article
32
- * @param $connect
33
- * @return array|bool|null
31
+ * @param integer $id_article
32
+ * @param string $connect
33
+ * @return string
34 34
  */
35 35
 function quete_virtuel($id_article, $connect) {
36 36
 	return sql_getfetsel(
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
  * @uses quete_parent_lang()
123 123
  *
124 124
  * @param int $id_article
125
- * @param $serveur
125
+ * @param string $serveur
126 126
  * @return int
127 127
  */
128 128
 function quete_rubrique($id_article, $serveur) {
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
  *
294 294
  * @param int $id_document
295 295
  * @param string $serveur
296
- * @return array|bool|null
296
+ * @return string
297 297
  */
298 298
 function quete_fichier($id_document, $serveur = '') {
299 299
 	return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
Please login to merge, or discard this patch.
Indentation   +387 added lines, -387 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 
@@ -33,16 +33,16 @@  discard block
 block discarded – undo
33 33
  * @return array|bool|null
34 34
  */
35 35
 function quete_virtuel($id_article, $connect) {
36
-	return sql_getfetsel(
37
-		'virtuel',
38
-		'spip_articles',
39
-		array('id_article=' . intval($id_article), "statut='publie'"),
40
-		'',
41
-		'',
42
-		'',
43
-		'',
44
-		$connect
45
-	);
36
+    return sql_getfetsel(
37
+        'virtuel',
38
+        'spip_articles',
39
+        array('id_article=' . intval($id_article), "statut='publie'"),
40
+        '',
41
+        '',
42
+        '',
43
+        '',
44
+        $connect
45
+    );
46 46
 }
47 47
 
48 48
 /**
@@ -57,38 +57,38 @@  discard block
 block discarded – undo
57 57
  * @return array
58 58
  */
59 59
 function quete_parent_lang($table, $id, $connect = '') {
60
-	static $cache_quete = array();
61
-
62
-	if (!isset($cache_quete[$connect][$table][$id])) {
63
-		if (!isset($cache_quete[$connect][$table]['_select'])) {
64
-			$trouver_table = charger_fonction('trouver_table', 'base');
65
-			if (!$desc = $trouver_table($table,
66
-					$connect) or !isset($desc['field']['id_rubrique'])
67
-			) {
68
-				// pas de parent rubrique, on passe
69
-				$cache_quete[$connect][$table]['_select'] = false;
70
-			} else {
71
-				$select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
72
-				$select .= isset($desc['field']['lang']) ? ', lang' : '';
73
-				$cache_quete[$connect][$table]['_select'] = $select;
74
-				$cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
75
-			}
76
-		}
77
-		if ($cache_quete[$connect][$table]['_select']) {
78
-			$cache_quete[$connect][$table][$id] = sql_fetsel(
79
-				$cache_quete[$connect][$table]['_select'],
80
-				$table,
81
-				$cache_quete[$connect][$table]['_id'] . '=' . intval($id),
82
-				'',
83
-				'',
84
-				'',
85
-				'',
86
-				$connect
87
-			);
88
-		}
89
-	}
90
-
91
-	return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null;
60
+    static $cache_quete = array();
61
+
62
+    if (!isset($cache_quete[$connect][$table][$id])) {
63
+        if (!isset($cache_quete[$connect][$table]['_select'])) {
64
+            $trouver_table = charger_fonction('trouver_table', 'base');
65
+            if (!$desc = $trouver_table($table,
66
+                    $connect) or !isset($desc['field']['id_rubrique'])
67
+            ) {
68
+                // pas de parent rubrique, on passe
69
+                $cache_quete[$connect][$table]['_select'] = false;
70
+            } else {
71
+                $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
72
+                $select .= isset($desc['field']['lang']) ? ', lang' : '';
73
+                $cache_quete[$connect][$table]['_select'] = $select;
74
+                $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
75
+            }
76
+        }
77
+        if ($cache_quete[$connect][$table]['_select']) {
78
+            $cache_quete[$connect][$table][$id] = sql_fetsel(
79
+                $cache_quete[$connect][$table]['_select'],
80
+                $table,
81
+                $cache_quete[$connect][$table]['_id'] . '=' . intval($id),
82
+                '',
83
+                '',
84
+                '',
85
+                '',
86
+                $connect
87
+            );
88
+        }
89
+    }
90
+
91
+    return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null;
92 92
 }
93 93
 
94 94
 
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
  * @return int
106 106
  */
107 107
 function quete_parent($id_rubrique, $connect = '') {
108
-	if (!$id_rubrique = intval($id_rubrique)) {
109
-		return 0;
110
-	}
111
-	$id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
108
+    if (!$id_rubrique = intval($id_rubrique)) {
109
+        return 0;
110
+    }
111
+    $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
112 112
 
113
-	return $id_parent['id_parent'];
113
+    return $id_parent['id_parent'];
114 114
 }
115 115
 
116 116
 /**
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
  * @return int
127 127
  */
128 128
 function quete_rubrique($id_article, $serveur) {
129
-	$id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
129
+    $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
130 130
 
131
-	return $id_parent['id_rubrique'];
131
+    return $id_parent['id_rubrique'];
132 132
 }
133 133
 
134 134
 
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
  * @return int
143 143
  */
144 144
 function quete_profondeur($id, $connect = '') {
145
-	$n = 0;
146
-	while ($id) {
147
-		$n++;
148
-		$id = quete_parent($id, $connect);
149
-	}
145
+    $n = 0;
146
+    while ($id) {
147
+        $n++;
148
+        $id = quete_parent($id, $connect);
149
+    }
150 150
 
151
-	return $n;
151
+    return $n;
152 152
 }
153 153
 
154 154
 
@@ -164,15 +164,15 @@  discard block
 block discarded – undo
164 164
  *     Morceau de la requête SQL testant la date
165 165
  */
166 166
 function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) {
167
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
168
-		return '1=1';
169
-	}
170
-
171
-	return
172
-		(isset($GLOBALS['meta']['date_prochain_postdate'])
173
-			and $GLOBALS['meta']['date_prochain_postdate'] > time())
174
-			? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
175
-			: '1=1';
167
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
168
+        return '1=1';
169
+    }
170
+
171
+    return
172
+        (isset($GLOBALS['meta']['date_prochain_postdate'])
173
+            and $GLOBALS['meta']['date_prochain_postdate'] > time())
174
+            ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
175
+            : '1=1';
176 176
 }
177 177
 
178 178
 
@@ -192,100 +192,100 @@  discard block
 block discarded – undo
192 192
  * @return array|string
193 193
  */
194 194
 function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) {
195
-	static $cond = array();
196
-	$key = func_get_args();
197
-	$key = implode('-', $key);
198
-	if (isset($cond[$key])) {
199
-		return $cond[$key];
200
-	}
201
-
202
-	$liste_statuts = $publie;
203
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
204
-		$liste_statuts = $previsu;
205
-	}
206
-	$not = false;
207
-	if (strncmp($liste_statuts, '!', 1) == 0) {
208
-		$not = true;
209
-		$liste_statuts = substr($liste_statuts, 1);
210
-	}
211
-	// '' => ne rien afficher, '!'=> ne rien filtrer
212
-	if (!strlen($liste_statuts)) {
213
-		return $cond[$key] = ($not ? '1=1' : '0=1');
214
-	}
215
-
216
-	$liste_statuts = explode(',', $liste_statuts);
217
-	$where = array();
218
-	foreach ($liste_statuts as $k => $v) {
219
-		// filtrage /auteur pour limiter les objets d'un statut (prepa en general)
220
-		// a ceux de l'auteur identifie
221
-		if (strpos($v, '/') !== false) {
222
-			$v = explode('/', $v);
223
-			$filtre = end($v);
224
-			$v = reset($v);
225
-			$v = preg_replace(',\W,', '', $v);
226
-			if ($filtre == 'auteur'
227
-				and (strpos($mstatut, '.') !== false)
228
-				and $objet = explode('.', $mstatut)
229
-				and $id_table = reset($objet)
230
-				and $objet = objet_type($id_table)
231
-			) {
232
-				$w = "$mstatut<>" . sql_quote($v);
233
-
234
-				// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
235
-				// sinon l’auteur en session
236
-				include_spip('inc/securiser_action');
237
-				if ($desc = decrire_token_previsu()) {
238
-					$id_auteur = $desc['id_auteur'];
239
-				} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
240
-					$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
241
-				} else {
242
-					$id_auteur = null;
243
-				}
244
-
245
-				// dans ce cas (admin en general), pas de filtrage sur ce statut
246
-				if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
247
-					// si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
248
-					if (!$id_auteur) {
249
-						$where[] = $w;
250
-					} else {
251
-						$primary = id_table_objet($objet);
252
-						$where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
253
-								'ssss.id_objet',
254
-								'spip_auteurs_liens AS ssss',
255
-								'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
256
-								'',
257
-								'',
258
-								'',
259
-								'',
260
-								$serveur
261
-							) . '))';
262
-					}
263
-				}
264
-			} // ignorer ce statut si on ne sait pas comment le filtrer
265
-			else {
266
-				$v = '';
267
-			}
268
-		}
269
-		// securite
270
-		$liste_statuts[$k] = preg_replace(',\W,', '', $v);
271
-	}
272
-	$liste_statuts = array_filter($liste_statuts);
273
-	if (count($liste_statuts) == 1) {
274
-		$where[] = array('=', $mstatut, sql_quote(reset($liste_statuts), $serveur));
275
-	} else {
276
-		$where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
277
-	}
278
-
279
-	while (count($where) > 1) {
280
-		$and = array('AND', array_pop($where), array_pop($where));
281
-		$where[] = $and;
282
-	}
283
-	$cond[$key] = reset($where);
284
-	if ($not) {
285
-		$cond[$key] = array('NOT', $cond[$key]);
286
-	}
287
-
288
-	return $cond[$key];
195
+    static $cond = array();
196
+    $key = func_get_args();
197
+    $key = implode('-', $key);
198
+    if (isset($cond[$key])) {
199
+        return $cond[$key];
200
+    }
201
+
202
+    $liste_statuts = $publie;
203
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
204
+        $liste_statuts = $previsu;
205
+    }
206
+    $not = false;
207
+    if (strncmp($liste_statuts, '!', 1) == 0) {
208
+        $not = true;
209
+        $liste_statuts = substr($liste_statuts, 1);
210
+    }
211
+    // '' => ne rien afficher, '!'=> ne rien filtrer
212
+    if (!strlen($liste_statuts)) {
213
+        return $cond[$key] = ($not ? '1=1' : '0=1');
214
+    }
215
+
216
+    $liste_statuts = explode(',', $liste_statuts);
217
+    $where = array();
218
+    foreach ($liste_statuts as $k => $v) {
219
+        // filtrage /auteur pour limiter les objets d'un statut (prepa en general)
220
+        // a ceux de l'auteur identifie
221
+        if (strpos($v, '/') !== false) {
222
+            $v = explode('/', $v);
223
+            $filtre = end($v);
224
+            $v = reset($v);
225
+            $v = preg_replace(',\W,', '', $v);
226
+            if ($filtre == 'auteur'
227
+                and (strpos($mstatut, '.') !== false)
228
+                and $objet = explode('.', $mstatut)
229
+                and $id_table = reset($objet)
230
+                and $objet = objet_type($id_table)
231
+            ) {
232
+                $w = "$mstatut<>" . sql_quote($v);
233
+
234
+                // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
235
+                // sinon l’auteur en session
236
+                include_spip('inc/securiser_action');
237
+                if ($desc = decrire_token_previsu()) {
238
+                    $id_auteur = $desc['id_auteur'];
239
+                } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
240
+                    $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
241
+                } else {
242
+                    $id_auteur = null;
243
+                }
244
+
245
+                // dans ce cas (admin en general), pas de filtrage sur ce statut
246
+                if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
247
+                    // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
248
+                    if (!$id_auteur) {
249
+                        $where[] = $w;
250
+                    } else {
251
+                        $primary = id_table_objet($objet);
252
+                        $where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
253
+                                'ssss.id_objet',
254
+                                'spip_auteurs_liens AS ssss',
255
+                                'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
256
+                                '',
257
+                                '',
258
+                                '',
259
+                                '',
260
+                                $serveur
261
+                            ) . '))';
262
+                    }
263
+                }
264
+            } // ignorer ce statut si on ne sait pas comment le filtrer
265
+            else {
266
+                $v = '';
267
+            }
268
+        }
269
+        // securite
270
+        $liste_statuts[$k] = preg_replace(',\W,', '', $v);
271
+    }
272
+    $liste_statuts = array_filter($liste_statuts);
273
+    if (count($liste_statuts) == 1) {
274
+        $where[] = array('=', $mstatut, sql_quote(reset($liste_statuts), $serveur));
275
+    } else {
276
+        $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
277
+    }
278
+
279
+    while (count($where) > 1) {
280
+        $and = array('AND', array_pop($where), array_pop($where));
281
+        $where[] = $and;
282
+    }
283
+    $cond[$key] = reset($where);
284
+    if ($not) {
285
+        $cond[$key] = array('NOT', $cond[$key]);
286
+    }
287
+
288
+    return $cond[$key];
289 289
 }
290 290
 
291 291
 /**
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
  * @return array|bool|null
297 297
  */
298 298
 function quete_fichier($id_document, $serveur = '') {
299
-	return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
299
+    return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
300 300
 }
301 301
 
302 302
 /**
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
  * @return array|bool
308 308
  */
309 309
 function quete_document($id_document, $serveur = '') {
310
-	return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
310
+    return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
311 311
 }
312 312
 
313 313
 /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  * @return array|bool|null
319 319
  */
320 320
 function quete_meta($nom, $serveur) {
321
-	return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
321
+    return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
322 322
 }
323 323
 
324 324
 /**
@@ -344,64 +344,64 @@  discard block
 block discarded – undo
344 344
  *     Retourne soit un tableau, soit le chemin du fichier.
345 345
  */
346 346
 function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) {
347
-	include_spip('base/objets');
348
-	$nom = strtolower($onoff);
349
-
350
-	while (1) {
351
-		$objet = objet_type($cle_objet);
352
-
353
-		$on = quete_logo_objet($id, $objet, $nom);
354
-
355
-		if ($on) {
356
-			if ($flag) {
357
-				return basename($on['chemin']);
358
-			} else {
359
-				$taille = @getimagesize($on['chemin']);
360
-
361
-				// Si on a déjà demandé un survol directement ($onoff = off)
362
-				// ou qu'on a demandé uniquement le normal ($onoff = on)
363
-				// alors on ne cherche pas du tout le survol ici
364
-				if ($onoff != 'ON') {
365
-					$off = '';
366
-				} else {
367
-					// Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
368
-					$off = quete_logo_objet($id, $objet, 'off');
369
-				}
370
-
371
-				// on retourne une url du type IMG/artonXX?timestamp
372
-				// qui permet de distinguer le changement de logo
373
-				// et placer un expire sur le dossier IMG/
374
-				$res = array(
375
-					$on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
376
-					($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
377
-					(!$taille ? '' : (' ' . $taille[3]))
378
-				);
379
-				$res['src'] = $res[0];
380
-				$res['logo_on'] = $res[0];
381
-				$res['logo_off'] = $res[1];
382
-				$res['width'] = ($taille ? $taille[0] : '');
383
-				$res['height'] = ($taille ? $taille[1] : '');
384
-
385
-				return $res;
386
-			}
387
-		} else {
388
-			if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
389
-				return '';
390
-			} else {
391
-				if ($id_rubrique) {
392
-					$cle_objet = 'id_rubrique';
393
-					$id = $id_rubrique;
394
-					$id_rubrique = 0;
395
-				} else {
396
-					if ($id and $cle_objet == 'id_rubrique') {
397
-						$id = quete_parent($id);
398
-					} else {
399
-						return '';
400
-					}
401
-				}
402
-			}
403
-		}
404
-	}
347
+    include_spip('base/objets');
348
+    $nom = strtolower($onoff);
349
+
350
+    while (1) {
351
+        $objet = objet_type($cle_objet);
352
+
353
+        $on = quete_logo_objet($id, $objet, $nom);
354
+
355
+        if ($on) {
356
+            if ($flag) {
357
+                return basename($on['chemin']);
358
+            } else {
359
+                $taille = @getimagesize($on['chemin']);
360
+
361
+                // Si on a déjà demandé un survol directement ($onoff = off)
362
+                // ou qu'on a demandé uniquement le normal ($onoff = on)
363
+                // alors on ne cherche pas du tout le survol ici
364
+                if ($onoff != 'ON') {
365
+                    $off = '';
366
+                } else {
367
+                    // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
368
+                    $off = quete_logo_objet($id, $objet, 'off');
369
+                }
370
+
371
+                // on retourne une url du type IMG/artonXX?timestamp
372
+                // qui permet de distinguer le changement de logo
373
+                // et placer un expire sur le dossier IMG/
374
+                $res = array(
375
+                    $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
376
+                    ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
377
+                    (!$taille ? '' : (' ' . $taille[3]))
378
+                );
379
+                $res['src'] = $res[0];
380
+                $res['logo_on'] = $res[0];
381
+                $res['logo_off'] = $res[1];
382
+                $res['width'] = ($taille ? $taille[0] : '');
383
+                $res['height'] = ($taille ? $taille[1] : '');
384
+
385
+                return $res;
386
+            }
387
+        } else {
388
+            if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
389
+                return '';
390
+            } else {
391
+                if ($id_rubrique) {
392
+                    $cle_objet = 'id_rubrique';
393
+                    $id = $id_rubrique;
394
+                    $id_rubrique = 0;
395
+                } else {
396
+                    if ($id and $cle_objet == 'id_rubrique') {
397
+                        $id = quete_parent($id);
398
+                    } else {
399
+                        return '';
400
+                    }
401
+                }
402
+            }
403
+        }
404
+    }
405 405
 }
406 406
 
407 407
 /**
@@ -415,37 +415,37 @@  discard block
 block discarded – undo
415 415
  * 		"on" ou "off" suivant le logo normal ou survol
416 416
  **/
417 417
 function quete_logo_objet($id_objet, $objet, $mode) {
418
-	static $chercher_logo;
419
-	if (is_null($chercher_logo)) {
420
-		$chercher_logo = charger_fonction('chercher_logo', 'inc');
421
-	}
422
-	$cle_objet = id_table_objet($objet);
423
-
424
-	// On cherche pas la méthode classique
425
-	$infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
426
-	// Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
427
-	if (!empty($infos_logo)) {
428
-		$infos_logo = array(
429
-			'chemin' => $infos_logo[0],
430
-			'timestamp' => $infos_logo[4],
431
-		);
432
-	}
433
-
434
-	// On passe cette recherche de logo dans un pipeline
435
-	$infos_logo = pipeline(
436
-		'quete_logo_objet',
437
-		array(
438
-			'args' => array(
439
-				'id_objet' => $id_objet,
440
-				'objet' => $objet,
441
-				'cle_objet' => $cle_objet,
442
-				'mode' => $mode,
443
-			),
444
-			'data' => $infos_logo,
445
-		)
446
-	);
447
-
448
-	return $infos_logo;
418
+    static $chercher_logo;
419
+    if (is_null($chercher_logo)) {
420
+        $chercher_logo = charger_fonction('chercher_logo', 'inc');
421
+    }
422
+    $cle_objet = id_table_objet($objet);
423
+
424
+    // On cherche pas la méthode classique
425
+    $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
426
+    // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
427
+    if (!empty($infos_logo)) {
428
+        $infos_logo = array(
429
+            'chemin' => $infos_logo[0],
430
+            'timestamp' => $infos_logo[4],
431
+        );
432
+    }
433
+
434
+    // On passe cette recherche de logo dans un pipeline
435
+    $infos_logo = pipeline(
436
+        'quete_logo_objet',
437
+        array(
438
+            'args' => array(
439
+                'id_objet' => $id_objet,
440
+                'objet' => $objet,
441
+                'cle_objet' => $cle_objet,
442
+                'mode' => $mode,
443
+            ),
444
+            'data' => $infos_logo,
445
+        )
446
+    );
447
+
448
+    return $infos_logo;
449 449
 }
450 450
 
451 451
 /**
@@ -458,24 +458,24 @@  discard block
 block discarded – undo
458 458
  * @return bool|string
459 459
  */
460 460
 function quete_logo_file($row, $connect = null) {
461
-	include_spip('inc/documents');
462
-	$logo = vignette_logo_document($row, $connect);
463
-	if (!$logo) {
464
-		$logo = image_du_document($row, $connect);
465
-	}
466
-	if (!$logo) {
467
-		$f = charger_fonction('vignette', 'inc');
468
-		$logo = $f($row['extension'], false);
469
-	}
470
-	// si c'est une vignette type doc, la renvoyer direct
471
-	if (strcmp($logo, _DIR_PLUGINS) == 0
472
-		or strcmp($logo, _DIR_PLUGINS_DIST) == 0
473
-		or strcmp($logo, _DIR_RACINE . 'prive/') == 0
474
-	) {
475
-		return $logo;
476
-	}
477
-
478
-	return get_spip_doc($logo);
461
+    include_spip('inc/documents');
462
+    $logo = vignette_logo_document($row, $connect);
463
+    if (!$logo) {
464
+        $logo = image_du_document($row, $connect);
465
+    }
466
+    if (!$logo) {
467
+        $f = charger_fonction('vignette', 'inc');
468
+        $logo = $f($row['extension'], false);
469
+    }
470
+    // si c'est une vignette type doc, la renvoyer direct
471
+    if (strcmp($logo, _DIR_PLUGINS) == 0
472
+        or strcmp($logo, _DIR_PLUGINS_DIST) == 0
473
+        or strcmp($logo, _DIR_RACINE . 'prive/') == 0
474
+    ) {
475
+        return $logo;
476
+    }
477
+
478
+    return get_spip_doc($logo);
479 479
 }
480 480
 
481 481
 /**
@@ -503,20 +503,20 @@  discard block
 block discarded – undo
503 503
  */
504 504
 function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect = null) {
505 505
 
506
-	include_spip('inc/documents');
507
-	$logo = '';
508
-	if (!in_array($mode_logo, array('icone', 'apercu'))) {
509
-		$logo = vignette_logo_document($row, $connect);
510
-	}
511
-	// si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
512
-	if ($mode_logo == 'vignette' and !$logo) {
513
-		return '';
514
-	}
515
-	if ($mode_logo == 'icone') {
516
-		$row['fichier'] = '';
517
-	}
518
-
519
-	return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
506
+    include_spip('inc/documents');
507
+    $logo = '';
508
+    if (!in_array($mode_logo, array('icone', 'apercu'))) {
509
+        $logo = vignette_logo_document($row, $connect);
510
+    }
511
+    // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
512
+    if ($mode_logo == 'vignette' and !$logo) {
513
+        return '';
514
+    }
515
+    if ($mode_logo == 'icone') {
516
+        $row['fichier'] = '';
517
+    }
518
+
519
+    return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
520 520
 }
521 521
 
522 522
 /**
@@ -530,14 +530,14 @@  discard block
 block discarded – undo
530 530
  * @return string|false
531 531
  */
532 532
 function document_spip_externe($fichier, $connect) {
533
-	if ($connect) {
534
-		$site = quete_meta('adresse_site', $connect);
535
-		if ($site) {
536
-			$dir = quete_meta('dir_img', $connect);
537
-			return "$site/$dir$fichier";
538
-		}
539
-	}
540
-	return false;
533
+    if ($connect) {
534
+        $site = quete_meta('adresse_site', $connect);
535
+        if ($site) {
536
+            $dir = quete_meta('dir_img', $connect);
537
+            return "$site/$dir$fichier";
538
+        }
539
+    }
540
+    return false;
541 541
 }
542 542
 
543 543
 /**
@@ -550,23 +550,23 @@  discard block
 block discarded – undo
550 550
  * @return string
551 551
  */
552 552
 function vignette_logo_document($row, $connect = '') {
553
-	if (!$row['id_vignette']) {
554
-		return '';
555
-	}
556
-	$fichier = quete_fichier($row['id_vignette'], $connect);
557
-	if ($url = document_spip_externe($fichier, $connect)) {
558
-		return $url;
559
-	}
560
-
561
-	$f = get_spip_doc($fichier);
562
-	if ($f and @file_exists($f)) {
563
-		return $f;
564
-	}
565
-	if ($row['mode'] !== 'vignette') {
566
-		return '';
567
-	}
568
-
569
-	return generer_url_entite($row['id_document'], 'document', '', '', $connect);
553
+    if (!$row['id_vignette']) {
554
+        return '';
555
+    }
556
+    $fichier = quete_fichier($row['id_vignette'], $connect);
557
+    if ($url = document_spip_externe($fichier, $connect)) {
558
+        return $url;
559
+    }
560
+
561
+    $f = get_spip_doc($fichier);
562
+    if ($f and @file_exists($f)) {
563
+        return $f;
564
+    }
565
+    if ($row['mode'] !== 'vignette') {
566
+        return '';
567
+    }
568
+
569
+    return generer_url_entite($row['id_document'], 'document', '', '', $connect);
570 570
 }
571 571
 
572 572
 /**
@@ -582,68 +582,68 @@  discard block
 block discarded – undo
582 582
  * @return bool|string
583 583
  */
584 584
 function calcul_exposer($id, $prim, $reference, $parent, $type, $connect = '') {
585
-	static $exposer = array();
586
-
587
-	// Que faut-il exposer ? Tous les elements de $reference
588
-	// ainsi que leur hierarchie ; on ne fait donc ce calcul
589
-	// qu'une fois (par squelette) et on conserve le resultat
590
-	// en static.
591
-	if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
592
-		$principal = isset($reference[$type]) ? $reference[$type] :
593
-			// cas de la pagination indecte @xx qui positionne la page avec l'id xx
594
-			// et donne la reference dynamique @type=xx dans le contexte
595
-			(isset($reference["@$type"]) ? $reference["@$type"] : '');
596
-		// le parent fournit en argument est le parent de $id, pas celui de $principal
597
-		// il n'est donc pas utile
598
-		$parent = 0;
599
-		if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
600
-			$enfants = array('id_rubrique' => array('id_article'), 'id_groupe' => array('id_mot'));
601
-			if (isset($enfants[$type])) {
602
-				foreach ($enfants[$type] as $t) {
603
-					if (isset($reference[$t])
604
-						// cas de la reference donnee dynamiquement par la pagination
605
-						or isset($reference["@$t"])
606
-					) {
607
-						$type = $t;
608
-						$principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"];
609
-						continue;
610
-					}
611
-				}
612
-			}
613
-		}
614
-		$exposer[$m][$type] = array();
615
-		if ($principal) {
616
-			$principaux = is_array($principal) ? $principal : array($principal);
617
-			foreach ($principaux as $principal) {
618
-				$exposer[$m][$type][$principal] = true;
619
-				if ($type == 'id_mot') {
620
-					if (!$parent) {
621
-						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
622
-					}
623
-					if ($parent) {
624
-						$exposer[$m]['id_groupe'][$parent] = true;
625
-					}
626
-				} else {
627
-					if ($type != 'id_groupe') {
628
-						if (!$parent) {
629
-							if ($type == 'id_rubrique') {
630
-								$parent = $principal;
631
-							}
632
-							if ($type == 'id_article') {
633
-								$parent = quete_rubrique($principal, $connect);
634
-							}
635
-						}
636
-						do {
637
-							$exposer[$m]['id_rubrique'][$parent] = true;
638
-						} while ($parent = quete_parent($parent, $connect));
639
-					}
640
-				}
641
-			}
642
-		}
643
-	}
644
-
645
-	// And the winner is...
646
-	return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
585
+    static $exposer = array();
586
+
587
+    // Que faut-il exposer ? Tous les elements de $reference
588
+    // ainsi que leur hierarchie ; on ne fait donc ce calcul
589
+    // qu'une fois (par squelette) et on conserve le resultat
590
+    // en static.
591
+    if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
592
+        $principal = isset($reference[$type]) ? $reference[$type] :
593
+            // cas de la pagination indecte @xx qui positionne la page avec l'id xx
594
+            // et donne la reference dynamique @type=xx dans le contexte
595
+            (isset($reference["@$type"]) ? $reference["@$type"] : '');
596
+        // le parent fournit en argument est le parent de $id, pas celui de $principal
597
+        // il n'est donc pas utile
598
+        $parent = 0;
599
+        if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
600
+            $enfants = array('id_rubrique' => array('id_article'), 'id_groupe' => array('id_mot'));
601
+            if (isset($enfants[$type])) {
602
+                foreach ($enfants[$type] as $t) {
603
+                    if (isset($reference[$t])
604
+                        // cas de la reference donnee dynamiquement par la pagination
605
+                        or isset($reference["@$t"])
606
+                    ) {
607
+                        $type = $t;
608
+                        $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"];
609
+                        continue;
610
+                    }
611
+                }
612
+            }
613
+        }
614
+        $exposer[$m][$type] = array();
615
+        if ($principal) {
616
+            $principaux = is_array($principal) ? $principal : array($principal);
617
+            foreach ($principaux as $principal) {
618
+                $exposer[$m][$type][$principal] = true;
619
+                if ($type == 'id_mot') {
620
+                    if (!$parent) {
621
+                        $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
622
+                    }
623
+                    if ($parent) {
624
+                        $exposer[$m]['id_groupe'][$parent] = true;
625
+                    }
626
+                } else {
627
+                    if ($type != 'id_groupe') {
628
+                        if (!$parent) {
629
+                            if ($type == 'id_rubrique') {
630
+                                $parent = $principal;
631
+                            }
632
+                            if ($type == 'id_article') {
633
+                                $parent = quete_rubrique($principal, $connect);
634
+                            }
635
+                        }
636
+                        do {
637
+                            $exposer[$m]['id_rubrique'][$parent] = true;
638
+                        } while ($parent = quete_parent($parent, $connect));
639
+                    }
640
+                }
641
+            }
642
+        }
643
+    }
644
+
645
+    // And the winner is...
646
+    return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
647 647
 }
648 648
 
649 649
 /**
@@ -658,21 +658,21 @@  discard block
 block discarded – undo
658 658
  * @return int
659 659
  */
660 660
 function quete_debut_pagination($primary, $valeur, $pas, $iter) {
661
-	// on ne devrait pas arriver ici si la cle primaire est inexistante
662
-	// ou composee, mais verifions
663
-	if (!$primary or preg_match('/[,\s]/', $primary)) {
664
-		return 0;
665
-	}
666
-
667
-	$pos = 0;
668
-	while ($row = $iter->fetch() and $row[$primary] != $valeur) {
669
-		$pos++;
670
-	}
671
-	// si on a pas trouve
672
-	if ($row[$primary] != $valeur) {
673
-		return 0;
674
-	}
675
-
676
-	// sinon, calculer le bon numero de page
677
-	return floor($pos / $pas) * $pas;
661
+    // on ne devrait pas arriver ici si la cle primaire est inexistante
662
+    // ou composee, mais verifions
663
+    if (!$primary or preg_match('/[,\s]/', $primary)) {
664
+        return 0;
665
+    }
666
+
667
+    $pos = 0;
668
+    while ($row = $iter->fetch() and $row[$primary] != $valeur) {
669
+        $pos++;
670
+    }
671
+    // si on a pas trouve
672
+    if ($row[$primary] != $valeur) {
673
+        return 0;
674
+    }
675
+
676
+    // sinon, calculer le bon numero de page
677
+    return floor($pos / $pas) * $pas;
678 678
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -18 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	return sql_getfetsel(
37 37
 		'virtuel',
38 38
 		'spip_articles',
39
-		array('id_article=' . intval($id_article), "statut='publie'"),
39
+		array('id_article='.intval($id_article), "statut='publie'"),
40 40
 		'',
41 41
 		'',
42 42
 		'',
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 			$cache_quete[$connect][$table][$id] = sql_fetsel(
79 79
 				$cache_quete[$connect][$table]['_select'],
80 80
 				$table,
81
-				$cache_quete[$connect][$table]['_id'] . '=' . intval($id),
81
+				$cache_quete[$connect][$table]['_id'].'='.intval($id),
82 82
 				'',
83 83
 				'',
84 84
 				'',
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	return
172 172
 		(isset($GLOBALS['meta']['date_prochain_postdate'])
173 173
 			and $GLOBALS['meta']['date_prochain_postdate'] > time())
174
-			? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
174
+			? "$champ_date<".sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
175 175
 			: '1=1';
176 176
 }
177 177
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 				and $id_table = reset($objet)
230 230
 				and $objet = objet_type($id_table)
231 231
 			) {
232
-				$w = "$mstatut<>" . sql_quote($v);
232
+				$w = "$mstatut<>".sql_quote($v);
233 233
 
234 234
 				// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
235 235
 				// sinon l’auteur en session
@@ -243,22 +243,22 @@  discard block
 block discarded – undo
243 243
 				}
244 244
 
245 245
 				// dans ce cas (admin en general), pas de filtrage sur ce statut
246
-				if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
246
+				if (!autoriser('previsualiser'.$v, $objet, '', $id_auteur)) {
247 247
 					// si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
248 248
 					if (!$id_auteur) {
249 249
 						$where[] = $w;
250 250
 					} else {
251 251
 						$primary = id_table_objet($objet);
252
-						$where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
252
+						$where[] = "($w OR $id_table.$primary IN (".sql_get_select(
253 253
 								'ssss.id_objet',
254 254
 								'spip_auteurs_liens AS ssss',
255
-								'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
255
+								'ssss.objet='.sql_quote($objet).' AND ssss.id_auteur='.intval($id_auteur),
256 256
 								'',
257 257
 								'',
258 258
 								'',
259 259
 								'',
260 260
 								$serveur
261
-							) . '))';
261
+							).'))';
262 262
 					}
263 263
 				}
264 264
 			} // ignorer ce statut si on ne sait pas comment le filtrer
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
  * @return array|bool|null
297 297
  */
298 298
 function quete_fichier($id_document, $serveur = '') {
299
-	return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
299
+	return sql_getfetsel('fichier', 'spip_documents', ('id_document='.intval($id_document)), '', array(), '', '', $serveur);
300 300
 }
301 301
 
302 302
 /**
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
  * @return array|bool
308 308
  */
309 309
 function quete_document($id_document, $serveur = '') {
310
-	return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
310
+	return sql_fetsel('*', 'spip_documents', ('id_document='.intval($id_document)), '', array(), '', '', $serveur);
311 311
 }
312 312
 
313 313
 /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  * @return array|bool|null
319 319
  */
320 320
 function quete_meta($nom, $serveur) {
321
-	return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
321
+	return sql_getfetsel('valeur', 'spip_meta', 'nom='.sql_quote($nom), '', '', '', '', $serveur);
322 322
 }
323 323
 
324 324
 /**
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
 				// qui permet de distinguer le changement de logo
373 373
 				// et placer un expire sur le dossier IMG/
374 374
 				$res = array(
375
-					$on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
376
-					($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
377
-					(!$taille ? '' : (' ' . $taille[3]))
375
+					$on['chemin'].($on['timestamp'] ? "?{$on['timestamp']}" : ''),
376
+					($off ? $off['chemin'].($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
377
+					(!$taille ? '' : (' '.$taille[3]))
378 378
 				);
379 379
 				$res['src'] = $res[0];
380 380
 				$res['logo_on'] = $res[0];
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 	// si c'est une vignette type doc, la renvoyer direct
471 471
 	if (strcmp($logo, _DIR_PLUGINS) == 0
472 472
 		or strcmp($logo, _DIR_PLUGINS_DIST) == 0
473
-		or strcmp($logo, _DIR_RACINE . 'prive/') == 0
473
+		or strcmp($logo, _DIR_RACINE.'prive/') == 0
474 474
 	) {
475 475
 		return $logo;
476 476
 	}
@@ -589,8 +589,7 @@  discard block
 block discarded – undo
589 589
 	// qu'une fois (par squelette) et on conserve le resultat
590 590
 	// en static.
591 591
 	if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
592
-		$principal = isset($reference[$type]) ? $reference[$type] :
593
-			// cas de la pagination indecte @xx qui positionne la page avec l'id xx
592
+		$principal = isset($reference[$type]) ? $reference[$type] : // cas de la pagination indecte @xx qui positionne la page avec l'id xx
594 593
 			// et donne la reference dynamique @type=xx dans le contexte
595 594
 			(isset($reference["@$type"]) ? $reference["@$type"] : '');
596 595
 		// le parent fournit en argument est le parent de $id, pas celui de $principal
@@ -618,7 +617,7 @@  discard block
 block discarded – undo
618 617
 				$exposer[$m][$type][$principal] = true;
619 618
 				if ($type == 'id_mot') {
620 619
 					if (!$parent) {
621
-						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
620
+						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot='.intval($principal), '', '', '', '', $connect);
622 621
 					}
623 622
 					if ($parent) {
624 623
 						$exposer[$m]['id_groupe'][$parent] = true;
Please login to merge, or discard this patch.
ecrire/inc/lien.php 3 patches
Doc Comments   +13 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,6 +42,9 @@  discard block
 block discarded – undo
42 42
 define('_RACCOURCI_LIEN', "/\[([^][]*?([[]\w*[]][^][]*)*)->(>?)([^]]*)\]/msS");
43 43
 
44 44
 // http://code.spip.net/@expanser_liens
45
+/**
46
+ * @return string
47
+ */
45 48
 function expanser_liens($t, $connect = '', $env = array()) {
46 49
 
47 50
 	$t = pipeline('pre_liens', $t);
@@ -56,6 +59,9 @@  discard block
 block discarded – undo
56 59
 // Meme analyse mais pour eliminer les liens
57 60
 // et ne laisser que leur titre, a expliciter si ce n'est fait
58 61
 // http://code.spip.net/@nettoyer_raccourcis_typo
62
+/**
63
+ * @param string $texte
64
+ */
59 65
 function nettoyer_raccourcis_typo($texte, $connect = '') {
60 66
 	return $texte;
61 67
 }
@@ -96,6 +102,9 @@  discard block
 block discarded – undo
96 102
 // 'url':   seulement U  (i.e. generer_url_RACCOURCI)
97 103
 
98 104
 // http://code.spip.net/@calculer_url
105
+/**
106
+ * @return string
107
+ */
99 108
 function calculer_url($ref, $texte = '', $pour = 'url', $connect = '', $echappe_typo = true) {
100 109
 	$r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo);
101 110
 
@@ -256,7 +265,7 @@  discard block
 block discarded – undo
256 265
  * @param int $id Identifiant de l'objet
257 266
  * @param string $type Type d'objet
258 267
  * @param string|null $connect Connecteur SQL utilisé
259
- * @return array {
268
+ * @return string {
260 269
  * @var string $titre Titre si présent, sinon ''
261 270
  * @var string $lang Langue si présente, sinon ''
262 271
  * }
@@ -302,6 +311,9 @@  discard block
 block discarded – undo
302 311
 define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS');
303 312
 
304 313
 // http://code.spip.net/@traiter_modeles
314
+/**
315
+ * @return string
316
+ */
305 317
 function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '', $liens = null, $env = array()) {
306 318
 	// preserver la compatibilite : true = recherche des documents
307 319
 	if ($doublons === true) {
Please login to merge, or discard this patch.
Indentation   +273 added lines, -273 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
 include_spip('base/abstract_sql');
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
 //
24 24
 
25 25
 function inc_lien_dist(
26
-	$lien,
27
-	$texte = '',
28
-	$class = '',
29
-	$title = '',
30
-	$hlang = '',
31
-	$rel = '',
32
-	$connect = '',
33
-	$env = array()
26
+    $lien,
27
+    $texte = '',
28
+    $class = '',
29
+    $title = '',
30
+    $hlang = '',
31
+    $rel = '',
32
+    $connect = '',
33
+    $env = array()
34 34
 ) {
35
-	return $lien;
35
+    return $lien;
36 36
 }
37 37
 
38 38
 // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip
@@ -44,30 +44,30 @@  discard block
 block discarded – undo
44 44
 // http://code.spip.net/@expanser_liens
45 45
 function expanser_liens($t, $connect = '', $env = array()) {
46 46
 
47
-	$t = pipeline('pre_liens', $t);
47
+    $t = pipeline('pre_liens', $t);
48 48
 
49
-	// on passe a traiter_modeles la liste des liens reperes pour lui permettre
50
-	// de remettre le texte d'origine dans les parametres du modele
51
-	$t = traiter_modeles($t, false, false, $connect);
49
+    // on passe a traiter_modeles la liste des liens reperes pour lui permettre
50
+    // de remettre le texte d'origine dans les parametres du modele
51
+    $t = traiter_modeles($t, false, false, $connect);
52 52
 
53
-	return $t;
53
+    return $t;
54 54
 }
55 55
 
56 56
 // Meme analyse mais pour eliminer les liens
57 57
 // et ne laisser que leur titre, a expliciter si ce n'est fait
58 58
 // http://code.spip.net/@nettoyer_raccourcis_typo
59 59
 function nettoyer_raccourcis_typo($texte, $connect = '') {
60
-	return $texte;
60
+    return $texte;
61 61
 }
62 62
 
63 63
 // Repere dans la partie texte d'un raccourci [texte->...]
64 64
 // la langue et la bulle eventuelles
65 65
 // http://code.spip.net/@traiter_raccourci_lien_atts
66 66
 function traiter_raccourci_lien_atts($texte) {
67
-	$bulle = '';
68
-	$hlang = '';
67
+    $bulle = '';
68
+    $hlang = '';
69 69
 
70
-	return array(trim($texte), $bulle, $hlang);
70
+    return array(trim($texte), $bulle, $hlang);
71 71
 }
72 72
 
73 73
 define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/');
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
  * @return string
84 84
  */
85 85
 function virtuel_redirige($virtuel, $url = false) {
86
-	return $virtuel;
86
+    return $virtuel;
87 87
 }
88 88
 
89 89
 // Cherche un lien du type [->raccourci 123]
@@ -97,114 +97,114 @@  discard block
 block discarded – undo
97 97
 
98 98
 // http://code.spip.net/@calculer_url
99 99
 function calculer_url($ref, $texte = '', $pour = 'url', $connect = '', $echappe_typo = true) {
100
-	$r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo);
100
+    $r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo);
101 101
 
102
-	return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
102
+    return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
103 103
 }
104 104
 
105 105
 define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS');
106 106
 
107 107
 // http://code.spip.net/@traiter_lien_explicite
108 108
 function traiter_lien_explicite($ref, $texte = '', $pour = 'url', $connect = '', $echappe_typo = true) {
109
-	if (preg_match(_EXTRAIRE_LIEN, $ref)) {
110
-		return ($pour != 'tout') ? '' : array('', '', '', '');
111
-	}
112
-
113
-	$lien = entites_html(trim($ref));
114
-
115
-	// Liens explicites
116
-	if (!$texte) {
117
-		$texte = str_replace('"', '', $lien);
118
-		// evite l'affichage de trops longues urls.
119
-		$lien_court = charger_fonction('lien_court', 'inc');
120
-		$texte = $lien_court($texte);
121
-		if ($echappe_typo) {
122
-			$texte = "<html>" . quote_amp($texte) . "</html>";
123
-		}
124
-	}
125
-
126
-	// petites corrections d'URL
127
-	if (preg_match('/^www\.[^@]+$/S', $lien)) {
128
-		$lien = "http://" . $lien;
129
-	} else {
130
-		if (strpos($lien, "@") && email_valide($lien)) {
131
-			if (!$texte) {
132
-				$texte = $lien;
133
-			}
134
-			$lien = "mailto:" . $lien;
135
-		}
136
-	}
137
-
138
-	if ($pour == 'url') {
139
-		return $lien;
140
-	}
141
-
142
-	if ($pour == 'titre') {
143
-		return $texte;
144
-	}
145
-
146
-	return array('url' => $lien, 'titre' => $texte);
109
+    if (preg_match(_EXTRAIRE_LIEN, $ref)) {
110
+        return ($pour != 'tout') ? '' : array('', '', '', '');
111
+    }
112
+
113
+    $lien = entites_html(trim($ref));
114
+
115
+    // Liens explicites
116
+    if (!$texte) {
117
+        $texte = str_replace('"', '', $lien);
118
+        // evite l'affichage de trops longues urls.
119
+        $lien_court = charger_fonction('lien_court', 'inc');
120
+        $texte = $lien_court($texte);
121
+        if ($echappe_typo) {
122
+            $texte = "<html>" . quote_amp($texte) . "</html>";
123
+        }
124
+    }
125
+
126
+    // petites corrections d'URL
127
+    if (preg_match('/^www\.[^@]+$/S', $lien)) {
128
+        $lien = "http://" . $lien;
129
+    } else {
130
+        if (strpos($lien, "@") && email_valide($lien)) {
131
+            if (!$texte) {
132
+                $texte = $lien;
133
+            }
134
+            $lien = "mailto:" . $lien;
135
+        }
136
+    }
137
+
138
+    if ($pour == 'url') {
139
+        return $lien;
140
+    }
141
+
142
+    if ($pour == 'titre') {
143
+        return $texte;
144
+    }
145
+
146
+    return array('url' => $lien, 'titre' => $texte);
147 147
 }
148 148
 
149 149
 function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, $connect = '') {
150
-	if (function_exists($f = 'glossaire_' . $ancre)) {
151
-		$url = $f($texte, $id);
152
-	} else {
153
-		$url = glossaire_std($texte);
154
-	}
150
+    if (function_exists($f = 'glossaire_' . $ancre)) {
151
+        $url = $f($texte, $id);
152
+    } else {
153
+        $url = glossaire_std($texte);
154
+    }
155 155
 
156
-	return $url;
156
+    return $url;
157 157
 }
158 158
 
159 159
 // http://code.spip.net/@traiter_lien_implicite
160 160
 function traiter_lien_implicite($ref, $texte = '', $pour = 'url', $connect = '') {
161
-	if (!($match = typer_raccourci($ref))) {
162
-		return false;
163
-	}
164
-	@list($type, , $id, , $args, , $ancre) = $match;
165
-	// attention dans le cas des sites le lien doit pointer non pas sur
166
-	// la page locale du site, mais directement sur le site lui-meme
167
-	if ($f = charger_fonction("implicite_$type", "liens", true)) {
168
-		$url = $f($texte, $id, $type, $args, $ancre, $connect);
169
-	}
170
-	if (!$url) {
171
-		$url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null);
172
-	}
173
-	if (!$url) {
174
-		return false;
175
-	}
176
-	if (is_array($url)) {
177
-		@list($type, $id) = $url;
178
-		$url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null);
179
-	}
180
-	if ($pour === 'url') {
181
-		return $url;
182
-	}
183
-	$r = traiter_raccourci_titre($id, $type, $connect);
184
-	if ($r) {
185
-		$r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in';
186
-	}
187
-	if ($texte = trim($texte)) {
188
-		$r['titre'] = $texte;
189
-	}
190
-	if (!@$r['titre']) {
191
-		$r['titre'] = _T($type) . " $id";
192
-	}
193
-	if ($pour == 'titre') {
194
-		return $r['titre'];
195
-	}
196
-	$r['url'] = $url;
197
-
198
-	// dans le cas d'un lien vers un doc, ajouter le type='mime/type'
199
-	if ($type == 'document'
200
-		and $mime = sql_getfetsel('mime_type', 'spip_types_documents',
201
-			"extension IN (" . sql_get_select("extension", "spip_documents", "id_document=" . sql_quote($id)) . ")",
202
-			'', '', '', '', $connect)
203
-	) {
204
-		$r['mime'] = $mime;
205
-	}
206
-
207
-	return $r;
161
+    if (!($match = typer_raccourci($ref))) {
162
+        return false;
163
+    }
164
+    @list($type, , $id, , $args, , $ancre) = $match;
165
+    // attention dans le cas des sites le lien doit pointer non pas sur
166
+    // la page locale du site, mais directement sur le site lui-meme
167
+    if ($f = charger_fonction("implicite_$type", "liens", true)) {
168
+        $url = $f($texte, $id, $type, $args, $ancre, $connect);
169
+    }
170
+    if (!$url) {
171
+        $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null);
172
+    }
173
+    if (!$url) {
174
+        return false;
175
+    }
176
+    if (is_array($url)) {
177
+        @list($type, $id) = $url;
178
+        $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null);
179
+    }
180
+    if ($pour === 'url') {
181
+        return $url;
182
+    }
183
+    $r = traiter_raccourci_titre($id, $type, $connect);
184
+    if ($r) {
185
+        $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in';
186
+    }
187
+    if ($texte = trim($texte)) {
188
+        $r['titre'] = $texte;
189
+    }
190
+    if (!@$r['titre']) {
191
+        $r['titre'] = _T($type) . " $id";
192
+    }
193
+    if ($pour == 'titre') {
194
+        return $r['titre'];
195
+    }
196
+    $r['url'] = $url;
197
+
198
+    // dans le cas d'un lien vers un doc, ajouter le type='mime/type'
199
+    if ($type == 'document'
200
+        and $mime = sql_getfetsel('mime_type', 'spip_types_documents',
201
+            "extension IN (" . sql_get_select("extension", "spip_documents", "id_document=" . sql_quote($id)) . ")",
202
+            '', '', '', '', $connect)
203
+    ) {
204
+        $r['mime'] = $mime;
205
+    }
206
+
207
+    return $r;
208 208
 }
209 209
 
210 210
 // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes
@@ -213,41 +213,41 @@  discard block
 block discarded – undo
213 213
 
214 214
 // http://code.spip.net/@typer_raccourci
215 215
 function typer_raccourci($lien) {
216
-	if (!preg_match(_RACCOURCI_URL, $lien, $match)) {
217
-		return array();
218
-	}
219
-	$f = $match[1];
220
-	// valeur par defaut et alias historiques
221
-	if (!$f) {
222
-		$f = 'article';
223
-	} else {
224
-		if ($f == 'art') {
225
-			$f = 'article';
226
-		} else {
227
-			if ($f == 'br') {
228
-				$f = 'breve';
229
-			} else {
230
-				if ($f == 'rub') {
231
-					$f = 'rubrique';
232
-				} else {
233
-					if ($f == 'aut') {
234
-						$f = 'auteur';
235
-					} else {
236
-						if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') {
237
-							$f = 'document';
238
-						} else {
239
-							if (preg_match('/^br..?ve$/S', $f)) {
240
-								$f = 'breve';
241
-							}
242
-						}
243
-					}
244
-				}
245
-			}
246
-		}
247
-	} # accents :(
248
-	$match[0] = $f;
249
-
250
-	return $match;
216
+    if (!preg_match(_RACCOURCI_URL, $lien, $match)) {
217
+        return array();
218
+    }
219
+    $f = $match[1];
220
+    // valeur par defaut et alias historiques
221
+    if (!$f) {
222
+        $f = 'article';
223
+    } else {
224
+        if ($f == 'art') {
225
+            $f = 'article';
226
+        } else {
227
+            if ($f == 'br') {
228
+                $f = 'breve';
229
+            } else {
230
+                if ($f == 'rub') {
231
+                    $f = 'rubrique';
232
+                } else {
233
+                    if ($f == 'aut') {
234
+                        $f = 'auteur';
235
+                    } else {
236
+                        if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') {
237
+                            $f = 'document';
238
+                        } else {
239
+                            if (preg_match('/^br..?ve$/S', $f)) {
240
+                                $f = 'breve';
241
+                            }
242
+                        }
243
+                    }
244
+                }
245
+            }
246
+        }
247
+    } # accents :(
248
+    $match[0] = $f;
249
+
250
+    return $match;
251 251
 }
252 252
 
253 253
 /**
@@ -262,25 +262,25 @@  discard block
 block discarded – undo
262 262
  * }
263 263
  **/
264 264
 function traiter_raccourci_titre($id, $type, $connect = null) {
265
-	$trouver_table = charger_fonction('trouver_table', 'base');
266
-	$desc = $trouver_table(table_objet($type));
267
-	if (!($desc and $s = $desc['titre'])) {
268
-		return array();
269
-	}
270
-	$_id = $desc['key']['PRIMARY KEY'];
271
-	$r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
272
-	if (!$r) {
273
-		return array();
274
-	}
275
-	$r['titre'] = supprimer_numero($r['titre']);
276
-	if (!$r['titre'] and !empty($r['surnom'])) {
277
-		$r['titre'] = $r['surnom'];
278
-	}
279
-	if (!isset($r['lang'])) {
280
-		$r['lang'] = '';
281
-	}
282
-
283
-	return $r;
265
+    $trouver_table = charger_fonction('trouver_table', 'base');
266
+    $desc = $trouver_table(table_objet($type));
267
+    if (!($desc and $s = $desc['titre'])) {
268
+        return array();
269
+    }
270
+    $_id = $desc['key']['PRIMARY KEY'];
271
+    $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
272
+    if (!$r) {
273
+        return array();
274
+    }
275
+    $r['titre'] = supprimer_numero($r['titre']);
276
+    if (!$r['titre'] and !empty($r['surnom'])) {
277
+        $r['titre'] = $r['surnom'];
278
+    }
279
+    if (!isset($r['lang'])) {
280
+        $r['lang'] = '';
281
+    }
282
+
283
+    return $r;
284 284
 }
285 285
 
286 286
 // traite les modeles (dans la fonction typo), en remplacant
@@ -292,115 +292,115 @@  discard block
 block discarded – undo
292 292
 // http://code.spip.net/@traiter_modeles
293 293
 
294 294
 define('_RACCOURCI_MODELE',
295
-	'(<([a-z_-]{3,})' # <modele
296
-	. '\s*([0-9]*)\s*' # id
297
-	. '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
298
-	. '\s*/?' . '>)' # fin du modele >
299
-	. '\s*(<\/a>)?' # eventuel </a>
295
+    '(<([a-z_-]{3,})' # <modele
296
+    . '\s*([0-9]*)\s*' # id
297
+    . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
298
+    . '\s*/?' . '>)' # fin du modele >
299
+    . '\s*(<\/a>)?' # eventuel </a>
300 300
 );
301 301
 
302 302
 define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS');
303 303
 
304 304
 // http://code.spip.net/@traiter_modeles
305 305
 function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '', $liens = null, $env = array()) {
306
-	// preserver la compatibilite : true = recherche des documents
307
-	if ($doublons === true) {
308
-		$doublons = array('documents' => array('doc', 'emb', 'img'));
309
-	}
310
-	// detecter les modeles (rapide)
311
-	if (strpos($texte, "<") !== false and
312
-		preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)
313
-	) {
314
-		include_spip('public/assembler');
315
-		$wrap_embed_html = charger_fonction("wrap_embed_html", "inc", true);
316
-		foreach ($matches as $match) {
317
-			// Recuperer l'appel complet (y compris un eventuel lien)
318
-
319
-			$a = strpos($texte, $match[0]);
320
-			preg_match(_RACCOURCI_MODELE_DEBUT,
321
-				substr($texte, $a), $regs);
322
-			$regs[] = ""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
323
-			list(, $mod, $type, $id, $params, $fin) = $regs;
324
-			if ($fin and
325
-				preg_match('/<a\s[^<>]*>\s*$/i',
326
-					substr($texte, 0, $a), $r)
327
-			) {
328
-				$lien = array(
329
-					'href' => extraire_attribut($r[0], 'href'),
330
-					'class' => extraire_attribut($r[0], 'class'),
331
-					'mime' => extraire_attribut($r[0], 'type'),
332
-					'title' => extraire_attribut($r[0], 'title'),
333
-					'hreflang' => extraire_attribut($r[0], 'hreflang')
334
-				);
335
-				$n = strlen($r[0]);
336
-				$a -= $n;
337
-				$cherche = $n + strlen($regs[0]);
338
-			} else {
339
-				$lien = false;
340
-				$cherche = strlen($mod);
341
-			}
342
-
343
-			// calculer le modele
344
-			# hack indexation
345
-			if ($doublons) {
346
-				$texte .= preg_replace(',[|][^|=]*,s', ' ', $params);
347
-			} # version normale
348
-			else {
349
-				// si un tableau de liens a ete passe, reinjecter le contenu d'origine
350
-				// dans les parametres, plutot que les liens echappes
351
-				if (!is_null($liens)) {
352
-					$params = str_replace($liens[0], $liens[1], $params);
353
-				}
354
-				$modele = inclure_modele($type, $id, $params, $lien, $connect, $env);
355
-				// en cas d'echec, 
356
-				// si l'objet demande a une url, 
357
-				// creer un petit encadre vers elle
358
-				if ($modele === false) {
359
-					if (!$lien) {
360
-						$lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
361
-					}
362
-					if ($lien) {
363
-						$modele = '<a href="'
364
-							. $lien['url']
365
-							. '" class="spip_modele'
366
-							. '">'
367
-							. sinon($lien['titre'], _T('ecrire:info_sans_titre'))
368
-							. "</a>";
369
-					} else {
370
-						$modele = "";
371
-						if (test_espace_prive()) {
372
-							$modele = entites_html(substr($texte, $a, $cherche));
373
-							if (!is_null($liens)) {
374
-								$modele = "<pre>" . str_replace($liens[0], $liens[1], $modele) . "</pre>";
375
-							}
376
-						}
377
-					}
378
-				}
379
-				// le remplacer dans le texte
380
-				if ($modele !== false) {
381
-					$modele = protege_js_modeles($modele);
382
-					if ($wrap_embed_html) {
383
-						$modele = $wrap_embed_html($mod, $modele);
384
-					}
385
-					$rempl = code_echappement($modele, $echap);
386
-					$texte = substr($texte, 0, $a)
387
-						. $rempl
388
-						. substr($texte, $a + $cherche);
389
-				}
390
-			}
391
-
392
-			// hack pour tout l'espace prive
393
-			if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) {
394
-				foreach ($doublons ? $doublons : array('documents' => array('doc', 'emb', 'img')) as $quoi => $modeles) {
395
-					if (in_array($type, $modeles)) {
396
-						$GLOBALS["doublons_{$quoi}_inclus"][] = $id;
397
-					}
398
-				}
399
-			}
400
-		}
401
-	}
402
-
403
-	return $texte;
306
+    // preserver la compatibilite : true = recherche des documents
307
+    if ($doublons === true) {
308
+        $doublons = array('documents' => array('doc', 'emb', 'img'));
309
+    }
310
+    // detecter les modeles (rapide)
311
+    if (strpos($texte, "<") !== false and
312
+        preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)
313
+    ) {
314
+        include_spip('public/assembler');
315
+        $wrap_embed_html = charger_fonction("wrap_embed_html", "inc", true);
316
+        foreach ($matches as $match) {
317
+            // Recuperer l'appel complet (y compris un eventuel lien)
318
+
319
+            $a = strpos($texte, $match[0]);
320
+            preg_match(_RACCOURCI_MODELE_DEBUT,
321
+                substr($texte, $a), $regs);
322
+            $regs[] = ""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
323
+            list(, $mod, $type, $id, $params, $fin) = $regs;
324
+            if ($fin and
325
+                preg_match('/<a\s[^<>]*>\s*$/i',
326
+                    substr($texte, 0, $a), $r)
327
+            ) {
328
+                $lien = array(
329
+                    'href' => extraire_attribut($r[0], 'href'),
330
+                    'class' => extraire_attribut($r[0], 'class'),
331
+                    'mime' => extraire_attribut($r[0], 'type'),
332
+                    'title' => extraire_attribut($r[0], 'title'),
333
+                    'hreflang' => extraire_attribut($r[0], 'hreflang')
334
+                );
335
+                $n = strlen($r[0]);
336
+                $a -= $n;
337
+                $cherche = $n + strlen($regs[0]);
338
+            } else {
339
+                $lien = false;
340
+                $cherche = strlen($mod);
341
+            }
342
+
343
+            // calculer le modele
344
+            # hack indexation
345
+            if ($doublons) {
346
+                $texte .= preg_replace(',[|][^|=]*,s', ' ', $params);
347
+            } # version normale
348
+            else {
349
+                // si un tableau de liens a ete passe, reinjecter le contenu d'origine
350
+                // dans les parametres, plutot que les liens echappes
351
+                if (!is_null($liens)) {
352
+                    $params = str_replace($liens[0], $liens[1], $params);
353
+                }
354
+                $modele = inclure_modele($type, $id, $params, $lien, $connect, $env);
355
+                // en cas d'echec, 
356
+                // si l'objet demande a une url, 
357
+                // creer un petit encadre vers elle
358
+                if ($modele === false) {
359
+                    if (!$lien) {
360
+                        $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
361
+                    }
362
+                    if ($lien) {
363
+                        $modele = '<a href="'
364
+                            . $lien['url']
365
+                            . '" class="spip_modele'
366
+                            . '">'
367
+                            . sinon($lien['titre'], _T('ecrire:info_sans_titre'))
368
+                            . "</a>";
369
+                    } else {
370
+                        $modele = "";
371
+                        if (test_espace_prive()) {
372
+                            $modele = entites_html(substr($texte, $a, $cherche));
373
+                            if (!is_null($liens)) {
374
+                                $modele = "<pre>" . str_replace($liens[0], $liens[1], $modele) . "</pre>";
375
+                            }
376
+                        }
377
+                    }
378
+                }
379
+                // le remplacer dans le texte
380
+                if ($modele !== false) {
381
+                    $modele = protege_js_modeles($modele);
382
+                    if ($wrap_embed_html) {
383
+                        $modele = $wrap_embed_html($mod, $modele);
384
+                    }
385
+                    $rempl = code_echappement($modele, $echap);
386
+                    $texte = substr($texte, 0, $a)
387
+                        . $rempl
388
+                        . substr($texte, $a + $cherche);
389
+                }
390
+            }
391
+
392
+            // hack pour tout l'espace prive
393
+            if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) {
394
+                foreach ($doublons ? $doublons : array('documents' => array('doc', 'emb', 'img')) as $quoi => $modeles) {
395
+                    if (in_array($type, $modeles)) {
396
+                        $GLOBALS["doublons_{$quoi}_inclus"][] = $id;
397
+                    }
398
+                }
399
+            }
400
+        }
401
+    }
402
+
403
+    return $texte;
404 404
 }
405 405
 
406 406
 //
@@ -408,15 +408,15 @@  discard block
 block discarded – undo
408 408
 //
409 409
 // http://code.spip.net/@traiter_raccourci_ancre
410 410
 function traiter_raccourci_ancre($letexte) {
411
-	return $letexte;
411
+    return $letexte;
412 412
 }
413 413
 
414 414
 // http://code.spip.net/@traiter_raccourci_glossaire
415 415
 function traiter_raccourci_glossaire($texte) {
416
-	return $texte;
416
+    return $texte;
417 417
 }
418 418
 
419 419
 // http://code.spip.net/@glossaire_std
420 420
 function glossaire_std($terme) {
421
-	return $terme;
421
+    return $terme;
422 422
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
103 103
 }
104 104
 
105
-define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS');
105
+define('_EXTRAIRE_LIEN', ',^\s*(?:'._PROTOCOLES_STD.'):?/?/?\s*$,iS');
106 106
 
107 107
 // http://code.spip.net/@traiter_lien_explicite
108 108
 function traiter_lien_explicite($ref, $texte = '', $pour = 'url', $connect = '', $echappe_typo = true) {
@@ -119,19 +119,19 @@  discard block
 block discarded – undo
119 119
 		$lien_court = charger_fonction('lien_court', 'inc');
120 120
 		$texte = $lien_court($texte);
121 121
 		if ($echappe_typo) {
122
-			$texte = "<html>" . quote_amp($texte) . "</html>";
122
+			$texte = "<html>".quote_amp($texte)."</html>";
123 123
 		}
124 124
 	}
125 125
 
126 126
 	// petites corrections d'URL
127 127
 	if (preg_match('/^www\.[^@]+$/S', $lien)) {
128
-		$lien = "http://" . $lien;
128
+		$lien = "http://".$lien;
129 129
 	} else {
130 130
 		if (strpos($lien, "@") && email_valide($lien)) {
131 131
 			if (!$texte) {
132 132
 				$texte = $lien;
133 133
 			}
134
-			$lien = "mailto:" . $lien;
134
+			$lien = "mailto:".$lien;
135 135
 		}
136 136
 	}
137 137
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 }
148 148
 
149 149
 function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, $connect = '') {
150
-	if (function_exists($f = 'glossaire_' . $ancre)) {
150
+	if (function_exists($f = 'glossaire_'.$ancre)) {
151 151
 		$url = $f($texte, $id);
152 152
 	} else {
153 153
 		$url = glossaire_std($texte);
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	if (!($match = typer_raccourci($ref))) {
162 162
 		return false;
163 163
 	}
164
-	@list($type, , $id, , $args, , $ancre) = $match;
164
+	@list($type,, $id,, $args,, $ancre) = $match;
165 165
 	// attention dans le cas des sites le lien doit pointer non pas sur
166 166
 	// la page locale du site, mais directement sur le site lui-meme
167 167
 	if ($f = charger_fonction("implicite_$type", "liens", true)) {
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 		$r['titre'] = $texte;
189 189
 	}
190 190
 	if (!@$r['titre']) {
191
-		$r['titre'] = _T($type) . " $id";
191
+		$r['titre'] = _T($type)." $id";
192 192
 	}
193 193
 	if ($pour == 'titre') {
194 194
 		return $r['titre'];
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	// dans le cas d'un lien vers un doc, ajouter le type='mime/type'
199 199
 	if ($type == 'document'
200 200
 		and $mime = sql_getfetsel('mime_type', 'spip_types_documents',
201
-			"extension IN (" . sql_get_select("extension", "spip_documents", "id_document=" . sql_quote($id)) . ")",
201
+			"extension IN (".sql_get_select("extension", "spip_documents", "id_document=".sql_quote($id)).")",
202 202
 			'', '', '', '', $connect)
203 203
 	) {
204 204
 		$r['mime'] = $mime;
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
 	'(<([a-z_-]{3,})' # <modele
296 296
 	. '\s*([0-9]*)\s*' # id
297 297
 	. '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
298
-	. '\s*/?' . '>)' # fin du modele >
298
+	. '\s*/?'.'>)' # fin du modele >
299 299
 	. '\s*(<\/a>)?' # eventuel </a>
300 300
 );
301 301
 
302
-define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS');
302
+define('_RACCOURCI_MODELE_DEBUT', '@^'._RACCOURCI_MODELE.'@isS');
303 303
 
304 304
 // http://code.spip.net/@traiter_modeles
305 305
 function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '', $liens = null, $env = array()) {
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 						if (test_espace_prive()) {
372 372
 							$modele = entites_html(substr($texte, $a, $cherche));
373 373
 							if (!is_null($liens)) {
374
-								$modele = "<pre>" . str_replace($liens[0], $liens[1], $modele) . "</pre>";
374
+								$modele = "<pre>".str_replace($liens[0], $liens[1], $modele)."</pre>";
375 375
 							}
376 376
 						}
377 377
 					}
Please login to merge, or discard this patch.
index.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,3 +1,3 @@
 block discarded – undo
1 1
 <?php
2
-	# appel SPIP
3
-	include('spip.php');
2
+    # appel SPIP
3
+    include('spip.php');
Please login to merge, or discard this patch.
prive/objets/liste/objets-trad_fonctions.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,24 +11,24 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 function lister_traductions($id_trad, $objet) {
18
-	$table_objet_sql = table_objet_sql($objet);
19
-	$primary = id_table_objet($objet);
18
+    $table_objet_sql = table_objet_sql($objet);
19
+    $primary = id_table_objet($objet);
20 20
 
21
-	$select = "$primary as id,lang";
22
-	$where = 'id_trad=' . intval($id_trad);
23
-	$trouver_table = charger_fonction('trouver_table','base');
24
-	$desc = $trouver_table($table_objet_sql);
25
-	if (isset($desc['field']['statut'])) {
26
-		$select .= ',statut';
27
-		$where .= ' AND statut!='.sql_quote('poubelle');
28
-	}
21
+    $select = "$primary as id,lang";
22
+    $where = 'id_trad=' . intval($id_trad);
23
+    $trouver_table = charger_fonction('trouver_table','base');
24
+    $desc = $trouver_table($table_objet_sql);
25
+    if (isset($desc['field']['statut'])) {
26
+        $select .= ',statut';
27
+        $where .= ' AND statut!='.sql_quote('poubelle');
28
+    }
29 29
 
30
-	$rows = sql_allfetsel($select, $table_objet_sql, $where);
31
-	lang_select();
30
+    $rows = sql_allfetsel($select, $table_objet_sql, $where);
31
+    lang_select();
32 32
 
33
-	return $rows;
33
+    return $rows;
34 34
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
 	$primary = id_table_objet($objet);
20 20
 
21 21
 	$select = "$primary as id,lang";
22
-	$where = 'id_trad=' . intval($id_trad);
23
-	$trouver_table = charger_fonction('trouver_table','base');
22
+	$where = 'id_trad='.intval($id_trad);
23
+	$trouver_table = charger_fonction('trouver_table', 'base');
24 24
 	$desc = $trouver_table($table_objet_sql);
25 25
 	if (isset($desc['field']['statut'])) {
26 26
 		$select .= ',statut';
Please login to merge, or discard this patch.
prive/objets/liste/auteurs_lies_fonctions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('prive/objets/liste/auteurs_fonctions');
Please login to merge, or discard this patch.
prive/objets/liste/objets-en-edition_fonctions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/drapeau_edition');
Please login to merge, or discard this patch.
prive/objets/liste/auteurs_fonctions.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Fonctions
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -29,29 +29,29 @@  discard block
 block discarded – undo
29 29
  * @param <type> $left
30 30
  */
31 31
 function critere_compteur_articles_filtres_dist($idb, &$boucles, $crit, $left = false) {
32
-	$boucle = &$boucles[$idb];
32
+    $boucle = &$boucles[$idb];
33 33
 
34
-	$_statut = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent);
34
+    $_statut = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent);
35 35
 
36
-	$not = '';
37
-	if ($crit->not) {
38
-		$not = ", 'NOT'";
39
-	}
40
-	$boucle->from['LAA'] = 'spip_auteurs_liens';
41
-	$boucle->from_type['LAA'] = 'left';
42
-	$boucle->join['LAA'] = array("'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''");
36
+    $not = '';
37
+    if ($crit->not) {
38
+        $not = ", 'NOT'";
39
+    }
40
+    $boucle->from['LAA'] = 'spip_auteurs_liens';
41
+    $boucle->from_type['LAA'] = 'left';
42
+    $boucle->join['LAA'] = array("'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''");
43 43
 
44
-	$boucle->from['articles'] = 'spip_articles';
45
-	$boucle->from_type['articles'] = 'left';
46
-	$boucle->join['articles'] = array(
47
-		"'LAA'",
48
-		"'id_article'",
49
-		"'id_objet'",
50
-		"'(articles.statut IS NULL OR '.sql_in('articles.statut',_q($_statut)$not).')'"
51
-	);
44
+    $boucle->from['articles'] = 'spip_articles';
45
+    $boucle->from_type['articles'] = 'left';
46
+    $boucle->join['articles'] = array(
47
+        "'LAA'",
48
+        "'id_article'",
49
+        "'id_objet'",
50
+        "'(articles.statut IS NULL OR '.sql_in('articles.statut',_q($_statut)$not).')'"
51
+    );
52 52
 
53
-	$boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles';
54
-	$boucle->group[] = 'auteurs.id_auteur';
53
+    $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles';
54
+    $boucle->group[] = 'auteurs.id_auteur';
55 55
 }
56 56
 
57 57
 /**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
  *     Pile complétée par le code à générer
70 70
  */
71 71
 function balise_COMPTEUR_ARTICLES_dist($p) {
72
-	return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres');
72
+    return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres');
73 73
 }
74 74
 
75 75
 
@@ -85,42 +85,42 @@  discard block
 block discarded – undo
85 85
  * @return <type>
86 86
  */
87 87
 function afficher_initiale($url, $initiale, $compteur, $debut, $pas) {
88
-	static $memo = null;
89
-	static $res = array();
90
-	$out = '';
91
-	if (!$memo
92
-		or (!$initiale and !$url)
93
-		or ($initiale !== $memo['initiale'])
94
-	) {
95
-		$newcompt = intval(floor(($compteur - 1) / $pas) * $pas);
96
-		// si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien
97
-		if (!$initiale and !$url and !$memo['compteur']) {
98
-			$memo = null;
99
-		}
100
-		if ($memo) {
101
-			$on = (($memo['compteur'] <= $debut)
102
-				and (
103
-					$newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur'])
104
-				));
105
-			$res[] = lien_ou_expose($memo['url'], $memo['initiale'], $on, 'lien_pagination');
106
-		}
107
-		if ($initiale) {
108
-			$memo = array(
109
-				'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0,
110
-				'initiale' => $initiale,
111
-				'url' => parametre_url($url, 'i', $initiale),
112
-				'compteur' => $newcompt
113
-			);
114
-		}
115
-	}
116
-	if (!$initiale and !$url) {
117
-		if (count($res) > 1) {
118
-			$out = implode(' ', $res);
119
-		}
120
-		$memo = $res = null;
121
-	}
88
+    static $memo = null;
89
+    static $res = array();
90
+    $out = '';
91
+    if (!$memo
92
+        or (!$initiale and !$url)
93
+        or ($initiale !== $memo['initiale'])
94
+    ) {
95
+        $newcompt = intval(floor(($compteur - 1) / $pas) * $pas);
96
+        // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien
97
+        if (!$initiale and !$url and !$memo['compteur']) {
98
+            $memo = null;
99
+        }
100
+        if ($memo) {
101
+            $on = (($memo['compteur'] <= $debut)
102
+                and (
103
+                    $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur'])
104
+                ));
105
+            $res[] = lien_ou_expose($memo['url'], $memo['initiale'], $on, 'lien_pagination');
106
+        }
107
+        if ($initiale) {
108
+            $memo = array(
109
+                'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0,
110
+                'initiale' => $initiale,
111
+                'url' => parametre_url($url, 'i', $initiale),
112
+                'compteur' => $newcompt
113
+            );
114
+        }
115
+    }
116
+    if (!$initiale and !$url) {
117
+        if (count($res) > 1) {
118
+            $out = implode(' ', $res);
119
+        }
120
+        $memo = $res = null;
121
+    }
122 122
 
123
-	return $out;
123
+    return $out;
124 124
 }
125 125
 
126 126
 /**
@@ -139,23 +139,23 @@  discard block
 block discarded – undo
139 139
  * @return string
140 140
  */
141 141
 function auteur_lien_messagerie($id_auteur, $en_ligne, $statut, $imessage, $email = '') {
142
-	static $time = null;
143
-	if (!in_array($statut, array('0minirezo', '1comite'))) {
144
-		return '';
145
-	}
142
+    static $time = null;
143
+    if (!in_array($statut, array('0minirezo', '1comite'))) {
144
+        return '';
145
+    }
146 146
 
147
-	if (is_null($time)) {
148
-		$time = time();
149
-	}
150
-	$parti = (($time - strtotime($en_ligne)) > 15 * 60);
147
+    if (is_null($time)) {
148
+        $time = time();
149
+    }
150
+    $parti = (($time - strtotime($en_ligne)) > 15 * 60);
151 151
 
152
-	if ($imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ?
153
-		and $GLOBALS['meta']['messagerie_agenda'] != 'non'
154
-	) {
155
-		return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self());
156
-	} elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) {
157
-		return 'mailto:' . $email;
158
-	} else {
159
-		return '';
160
-	}
152
+    if ($imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ?
153
+        and $GLOBALS['meta']['messagerie_agenda'] != 'non'
154
+    ) {
155
+        return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self());
156
+    } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) {
157
+        return 'mailto:' . $email;
158
+    } else {
159
+        return '';
160
+    }
161 161
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -154,7 +154,7 @@
 block discarded – undo
154 154
 	) {
155 155
 		return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self());
156 156
 	} elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) {
157
-		return 'mailto:' . $email;
157
+		return 'mailto:'.$email;
158 158
 	} else {
159 159
 		return '';
160 160
 	}
Please login to merge, or discard this patch.