Completed
Push — master ( e997e0...cc9c6b )
by cam
01:07
created
ecrire/exec/404.php 2 patches
Indentation   +16 added lines, -16 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
 /**
@@ -25,25 +25,25 @@  discard block
 block discarded – undo
25 25
  */
26 26
 function exec_404_dist() {
27 27
 
28
-	$exec = _request('exec');
28
+    $exec = _request('exec');
29 29
 
30
-	$titre = "exec_$exec";
31
-	$navigation = '';
32
-	$extra = '';
30
+    $titre = "exec_$exec";
31
+    $navigation = '';
32
+    $extra = '';
33 33
 
34
-	include_spip('inc/presentation'); // alleger les inclusions avec un inc/presentation_mini
35
-	$commencer_page = charger_fonction('commencer_page', 'inc');
36
-	echo $commencer_page($titre);
34
+    include_spip('inc/presentation'); // alleger les inclusions avec un inc/presentation_mini
35
+    $commencer_page = charger_fonction('commencer_page', 'inc');
36
+    echo $commencer_page($titre);
37 37
 
38
-	echo debut_gauche();
39
-	echo pipeline('affiche_gauche', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']);
38
+    echo debut_gauche();
39
+    echo pipeline('affiche_gauche', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']);
40 40
 
41
-	echo creer_colonne_droite();
42
-	echo pipeline('affiche_droite', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']);
41
+    echo creer_colonne_droite();
42
+    echo pipeline('affiche_droite', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']);
43 43
 
44
-	echo debut_droite();
45
-	echo "<h1 class='grostitre'>" . _T('fichier_introuvable', ['fichier' => $exec]) . '</h1>';
46
-	echo pipeline('affiche_milieu', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']);
44
+    echo debut_droite();
45
+    echo "<h1 class='grostitre'>" . _T('fichier_introuvable', ['fichier' => $exec]) . '</h1>';
46
+    echo pipeline('affiche_milieu', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']);
47 47
 
48
-	echo fin_gauche(), fin_page();
48
+    echo fin_gauche(), fin_page();
49 49
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
 	echo pipeline('affiche_droite', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']);
43 43
 
44 44
 	echo debut_droite();
45
-	echo "<h1 class='grostitre'>" . _T('fichier_introuvable', ['fichier' => $exec]) . '</h1>';
45
+	echo "<h1 class='grostitre'>"._T('fichier_introuvable', ['fichier' => $exec]).'</h1>';
46 46
 	echo pipeline('affiche_milieu', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']);
47 47
 
48 48
 	echo fin_gauche(), fin_page();
Please login to merge, or discard this patch.
ecrire/inc/nfslock.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  **/
8 8
 
9 9
 if (!defined('_ECRIRE_INC_VERSION')) {
10
-	return;
10
+    return;
11 11
 }
12 12
 
13 13
 include_spip('inc/acces');
@@ -101,93 +101,93 @@  discard block
 block discarded – undo
101 101
  * @return int|bool Timestamp du verrou, false si erreur
102 102
  */
103 103
 function spip_nfslock($fichier, $max_age = 0) {
104
-	$tries = 0;
104
+    $tries = 0;
105 105
 
106
-	if (!$max_age) {
107
-		$max_age = _DEFAULT_LOCKTIME;
108
-	}
109
-	$lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
106
+    if (!$max_age) {
107
+        $max_age = _DEFAULT_LOCKTIME;
108
+    }
109
+    $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
110 110
 
111 111
 
112
-	/*
112
+    /*
113 113
 	 * 1. create a tmp file with a psuedo random file name. we also make
114 114
 	 *    tpath which is a buffer to store the full pathname of the tmp file.
115 115
 	 */
116 116
 
117
-	$id = creer_uniqid();
118
-	$tpath = _DIR_TMP . "slock.$id";
119
-	$tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ...
120
-	if (!$tmpfd) {  /* open failed */
121
-		@fclose($tmpfd);
122
-		spip_unlink($tpath);
117
+    $id = creer_uniqid();
118
+    $tpath = _DIR_TMP . "slock.$id";
119
+    $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ...
120
+    if (!$tmpfd) {  /* open failed */
121
+        @fclose($tmpfd);
122
+        spip_unlink($tpath);
123 123
 
124
-		return false; //NFSL_SYSF
125
-	}
124
+        return false; //NFSL_SYSF
125
+    }
126 126
 
127
-	/*
127
+    /*
128 128
 	 * 2. make fullpath, a buffer for the full pathname of the lock file.
129 129
 	 *    then start looping trying to lock it
130 130
 	 */
131 131
 
132
-	while ($tries < 10) {
133
-		/*
132
+    while ($tries < 10) {
133
+        /*
134 134
 		 * 3. link tmp file to lock file.  if it goes, we win and we clean
135 135
 		 *    up and return the st_ctime of the lock file.
136 136
 		 */
137 137
 
138
-		if (link($tpath, $lock_file) == 1) {
139
-			spip_unlink($tpath); /* got it! */
140
-			@fclose($tmpfd);
141
-			if (($our_tmp = lstat($lock_file)) == false) {  /* stat failed... shouldn't happen */
142
-				spip_unlink($lock_file);
138
+        if (link($tpath, $lock_file) == 1) {
139
+            spip_unlink($tpath); /* got it! */
140
+            @fclose($tmpfd);
141
+            if (($our_tmp = lstat($lock_file)) == false) {  /* stat failed... shouldn't happen */
142
+                spip_unlink($lock_file);
143 143
 
144
-				return false; // (NFSL_SYSF);
145
-			}
144
+                return false; // (NFSL_SYSF);
145
+            }
146 146
 
147
-			return ($our_tmp['ctime']);
148
-		}
147
+            return ($our_tmp['ctime']);
148
+        }
149 149
 
150
-		/*
150
+        /*
151 151
 		 * 4. the lock failed.  check for a stale lock file, being mindful
152 152
 		 *    of NFS and the fact the time is set from the NFS server.  we
153 153
 		 *    do a write on the tmp file to update its time to the server's
154 154
 		 *    idea of "now."
155 155
 		 */
156 156
 
157
-		$old_stat = lstat($lock_file);
158
-		if (@fputs($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) {
159
-			break;
160
-		} /* something bogus is going on */
157
+        $old_stat = lstat($lock_file);
158
+        if (@fputs($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) {
159
+            break;
160
+        } /* something bogus is going on */
161 161
 
162 162
 
163
-		if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) {
164
-			spip_unlink($lock_file); /* break the stale lock */
165
-			$tries++;
166
-			/* It is CRITICAL that we sleep after breaking
163
+        if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) {
164
+            spip_unlink($lock_file); /* break the stale lock */
165
+            $tries++;
166
+            /* It is CRITICAL that we sleep after breaking
167 167
 			 * the lock. Otherwise, we could race with
168 168
 			 * another process and unlink it's newly-
169 169
 			 * created file.
170 170
 			 */
171
-			sleep(1 + random_int(0, 4));
172
-			continue;
173
-		}
171
+            sleep(1 + random_int(0, 4));
172
+            continue;
173
+        }
174 174
 
175
-		/*
175
+        /*
176 176
 		 * 5. try again
177 177
 		 */
178 178
 
179
-		$tries++;
180
-		sleep(1 + random_int(0, 4));
181
-	}
179
+        $tries++;
180
+        sleep(1 + random_int(0, 4));
181
+    }
182 182
 
183
-	/*
183
+    /*
184 184
 	 * 6. give up, failure.
185 185
 	 */
186 186
 
187
-	spip_unlink($tpath);
188
-	@fclose($tmpfd);
187
+    spip_unlink($tpath);
188
+    @fclose($tmpfd);
189 189
 
190
-	return false; //(NFSL_LOCKED);
190
+    return false; //(NFSL_LOCKED);
191 191
 }
192 192
 
193 193
 /**
@@ -231,75 +231,75 @@  discard block
 block discarded – undo
231 231
  * return bool true si déverrouillé, false sinon
232 232
  */
233 233
 function spip_nfsunlock($fichier, $birth, $max_age = 0, $test = false) {
234
-	$id = creer_uniqid();
235
-	if (!$max_age) {
236
-		$max_age = _DEFAULT_LOCKTIME;
237
-	}
234
+    $id = creer_uniqid();
235
+    if (!$max_age) {
236
+        $max_age = _DEFAULT_LOCKTIME;
237
+    }
238 238
 
239
-	/*
239
+    /*
240 240
 	 * 1. Build a temp file and stat that to get an idea of what the server
241 241
 	 *    thinks the current time is (our_tmp.st_ctime)..
242 242
 	 */
243 243
 
244
-	$tpath = _DIR_TMP . "stime.$id";
245
-	$tmpfd = @fopen($tpath, 'w');
246
-	if (
247
-		(!$tmpfd)
248
-		or (@fputs($tmpfd, 'zz', 2) != 2)
249
-		or !($our_tmp = fstat($tmpfd))
250
-	) {
251
-		/* The open failed, or we can't write the file, or we can't stat it */
252
-		@fclose($tmpfd);
253
-		spip_unlink($tpath);
244
+    $tpath = _DIR_TMP . "stime.$id";
245
+    $tmpfd = @fopen($tpath, 'w');
246
+    if (
247
+        (!$tmpfd)
248
+        or (@fputs($tmpfd, 'zz', 2) != 2)
249
+        or !($our_tmp = fstat($tmpfd))
250
+    ) {
251
+        /* The open failed, or we can't write the file, or we can't stat it */
252
+        @fclose($tmpfd);
253
+        spip_unlink($tpath);
254 254
 
255
-		return false; //(NFSL_SYSF);
256
-	}
255
+        return false; //(NFSL_SYSF);
256
+    }
257 257
 
258
-	@fclose($tmpfd);    /* We don't need this once we have our_tmp.st_ctime. */
259
-	spip_unlink($tpath);
258
+    @fclose($tmpfd);    /* We don't need this once we have our_tmp.st_ctime. */
259
+    spip_unlink($tpath);
260 260
 
261
-	/*
261
+    /*
262 262
 	 * 2. make fullpath, a buffer for the full pathname of the lock file
263 263
 	 */
264 264
 
265
-	$lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
265
+    $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
266 266
 
267
-	/*
267
+    /*
268 268
 	 * 3. If the ctime hasn't been modified, unlink the file and return. If the
269 269
 	 *    lock has expired, sleep the usual random interval before returning.
270 270
 	 *    If we didn't sleep, there could be a race if the caller immediately
271 271
 	 *    tries to relock the file.
272 272
 	 */
273 273
 
274
-	if (
275
-		($old_stat = @lstat($lock_file))  /* stat succeeds so file is there */
276
-		&& ($old_stat['ctime'] == $birth)
277
-	) {  /* hasn't been modified since birth */
278
-		if (!$test) {
279
-			spip_unlink($lock_file);
280
-		}      /* so the lock is ours to remove */
281
-		if ($our_tmp['ctime'] >= $birth + $max_age) {  /* the lock has expired */
282
-			if (!$test) {
283
-				return false;
284
-			} //(NFSL_LOST);
285
-			sleep(1 + (random_int(0, 4)));    /* so sleep a bit */
286
-		}
287
-
288
-		return true;//(NFSL_OK);			/* success */
289
-	}
290
-
291
-	/*
274
+    if (
275
+        ($old_stat = @lstat($lock_file))  /* stat succeeds so file is there */
276
+        && ($old_stat['ctime'] == $birth)
277
+    ) {  /* hasn't been modified since birth */
278
+        if (!$test) {
279
+            spip_unlink($lock_file);
280
+        }      /* so the lock is ours to remove */
281
+        if ($our_tmp['ctime'] >= $birth + $max_age) {  /* the lock has expired */
282
+            if (!$test) {
283
+                return false;
284
+            } //(NFSL_LOST);
285
+            sleep(1 + (random_int(0, 4)));    /* so sleep a bit */
286
+        }
287
+
288
+        return true;//(NFSL_OK);			/* success */
289
+    }
290
+
291
+    /*
292 292
 	 * 4. Either ctime has been modified, or the entire lock file is missing.
293 293
 	 *    If the lock should still be ours, based on the ctime of the temp
294 294
 	 *    file, return with NFSL_STOLEN. If not, then our lock is expired and
295 295
 	 *    someone else has grabbed the file, so return NFSL_LOST.
296 296
 	 */
297 297
 
298
-	if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */
299
-		return false;
300
-	} //(NFSL_STOLEN);
298
+    if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */
299
+        return false;
300
+    } //(NFSL_STOLEN);
301 301
 
302
-	return false; //(NFSL_LOST);	/* The lock must have expired first. */
302
+    return false; //(NFSL_LOST);	/* The lock must have expired first. */
303 303
 }
304 304
 
305 305
 
@@ -323,5 +323,5 @@  discard block
 block discarded – undo
323 323
  * return bool true si déverrouillé, false sinon
324 324
  */
325 325
 function spip_nfslock_test($fichier, $birth, $max_age = 0) {
326
-	return spip_nfsunlock($fichier, $birth, $max_age, true);
326
+    return spip_nfsunlock($fichier, $birth, $max_age, true);
327 327
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	if (!$max_age) {
107 107
 		$max_age = _DEFAULT_LOCKTIME;
108 108
 	}
109
-	$lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
109
+	$lock_file = _DIR_TMP._NAME_LOCK.'-'.substr(md5($fichier), 0, 8);
110 110
 
111 111
 
112 112
 	/*
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 */
116 116
 
117 117
 	$id = creer_uniqid();
118
-	$tpath = _DIR_TMP . "slock.$id";
118
+	$tpath = _DIR_TMP."slock.$id";
119 119
 	$tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ...
120 120
 	if (!$tmpfd) {  /* open failed */
121 121
 		@fclose($tmpfd);
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 *    thinks the current time is (our_tmp.st_ctime)..
242 242
 	 */
243 243
 
244
-	$tpath = _DIR_TMP . "stime.$id";
244
+	$tpath = _DIR_TMP."stime.$id";
245 245
 	$tmpfd = @fopen($tpath, 'w');
246 246
 	if (
247 247
 		(!$tmpfd)
@@ -255,14 +255,14 @@  discard block
 block discarded – undo
255 255
 		return false; //(NFSL_SYSF);
256 256
 	}
257 257
 
258
-	@fclose($tmpfd);    /* We don't need this once we have our_tmp.st_ctime. */
258
+	@fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */
259 259
 	spip_unlink($tpath);
260 260
 
261 261
 	/*
262 262
 	 * 2. make fullpath, a buffer for the full pathname of the lock file
263 263
 	 */
264 264
 
265
-	$lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
265
+	$lock_file = _DIR_TMP._NAME_LOCK.'-'.substr(md5($fichier), 0, 8);
266 266
 
267 267
 	/*
268 268
 	 * 3. If the ctime hasn't been modified, unlink the file and return. If the
@@ -282,10 +282,10 @@  discard block
 block discarded – undo
282 282
 			if (!$test) {
283 283
 				return false;
284 284
 			} //(NFSL_LOST);
285
-			sleep(1 + (random_int(0, 4)));    /* so sleep a bit */
285
+			sleep(1 + (random_int(0, 4))); /* so sleep a bit */
286 286
 		}
287 287
 
288
-		return true;//(NFSL_OK);			/* success */
288
+		return true; //(NFSL_OK);			/* success */
289 289
 	}
290 290
 
291 291
 	/*
Please login to merge, or discard this patch.
ecrire/inc/csv.php 2 patches
Indentation   +108 added lines, -108 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
 /**
@@ -33,118 +33,118 @@  discard block
 block discarded – undo
33 33
  **/
34 34
 function analyse_csv($t) {
35 35
 
36
-	// Quel est le séparateur ?
37
-	$virg = substr_count($t, ',');
38
-	$pvirg = substr_count($t, ';');
39
-	$tab = substr_count($t, "\t");
40
-	if ($virg > $pvirg) {
41
-		$sep = ',';
42
-		$hs = '&#44;';
43
-	} else {
44
-		$sep = ';';
45
-		$hs = '&#59;';
46
-		$virg = $pvirg;
47
-	}
48
-	// un certain nombre de tab => le séparateur est tab
49
-	if ($tab > $virg / 10) {
50
-		$sep = "\t";
51
-		$hs = "\t";
52
-	}
36
+    // Quel est le séparateur ?
37
+    $virg = substr_count($t, ',');
38
+    $pvirg = substr_count($t, ';');
39
+    $tab = substr_count($t, "\t");
40
+    if ($virg > $pvirg) {
41
+        $sep = ',';
42
+        $hs = '&#44;';
43
+    } else {
44
+        $sep = ';';
45
+        $hs = '&#59;';
46
+        $virg = $pvirg;
47
+    }
48
+    // un certain nombre de tab => le séparateur est tab
49
+    if ($tab > $virg / 10) {
50
+        $sep = "\t";
51
+        $hs = "\t";
52
+    }
53 53
 
54
-	// un separateur suivi de 3 guillemets attention !
55
-	// attention au ; ou , suceptible d'etre confondu avec un separateur
56
-	// on substitue un # et on remplacera a la fin
57
-	$t = preg_replace("/([\n$sep])\"\"\"/", '\\1"&#34#', $t);
58
-	$t = str_replace('""', '&#34#', $t);
59
-	preg_match_all('/"[^"]*"/', $t, $r);
60
-	foreach ($r[0] as $cell) {
61
-		$t = str_replace(
62
-			$cell,
63
-			str_replace(
64
-				$sep,
65
-				$hs,
66
-				str_replace(
67
-					"\n",
68
-					'``**``', // échapper les saut de lignes, on les remettra après.
69
-					substr($cell, 1, -1)
70
-				)
71
-			),
72
-			$t
73
-		);
74
-	}
54
+    // un separateur suivi de 3 guillemets attention !
55
+    // attention au ; ou , suceptible d'etre confondu avec un separateur
56
+    // on substitue un # et on remplacera a la fin
57
+    $t = preg_replace("/([\n$sep])\"\"\"/", '\\1"&#34#', $t);
58
+    $t = str_replace('""', '&#34#', $t);
59
+    preg_match_all('/"[^"]*"/', $t, $r);
60
+    foreach ($r[0] as $cell) {
61
+        $t = str_replace(
62
+            $cell,
63
+            str_replace(
64
+                $sep,
65
+                $hs,
66
+                str_replace(
67
+                    "\n",
68
+                    '``**``', // échapper les saut de lignes, on les remettra après.
69
+                    substr($cell, 1, -1)
70
+                )
71
+            ),
72
+            $t
73
+        );
74
+    }
75 75
 
76
-	$t = preg_replace(
77
-		'/\r?\n/',
78
-		"\n",
79
-		preg_replace('/[\r\n]+/', "\n", $t)
80
-	);
76
+    $t = preg_replace(
77
+        '/\r?\n/',
78
+        "\n",
79
+        preg_replace('/[\r\n]+/', "\n", $t)
80
+    );
81 81
 
82
-	[$entete, $corps] = explode("\n", $t, 2);
83
-	$caption = '';
84
-	// sauter la ligne de tete formee seulement de separateurs
85
-	if (substr_count($entete, $sep) == strlen($entete)) {
86
-		[$entete, $corps] = explode("\n", $corps, 2);
87
-	}
88
-	// si une seule colonne, en faire le titre
89
-	if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) {
90
-		$caption = "\n||" . $l[1] . '|';
91
-		[$entete, $corps] = explode("\n", $corps, 2);
92
-	}
93
-	// si premiere colonne vide, le raccourci doit quand meme produire <th...
94
-	if ($entete[0] == $sep) {
95
-		$entete = ' ' . $entete;
96
-	}
82
+    [$entete, $corps] = explode("\n", $t, 2);
83
+    $caption = '';
84
+    // sauter la ligne de tete formee seulement de separateurs
85
+    if (substr_count($entete, $sep) == strlen($entete)) {
86
+        [$entete, $corps] = explode("\n", $corps, 2);
87
+    }
88
+    // si une seule colonne, en faire le titre
89
+    if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) {
90
+        $caption = "\n||" . $l[1] . '|';
91
+        [$entete, $corps] = explode("\n", $corps, 2);
92
+    }
93
+    // si premiere colonne vide, le raccourci doit quand meme produire <th...
94
+    if ($entete[0] == $sep) {
95
+        $entete = ' ' . $entete;
96
+    }
97 97
 
98
-	$lignes = explode("\n", $corps);
98
+    $lignes = explode("\n", $corps);
99 99
 
100
-	// retrait des lignes vides finales
101
-	while (
102
-		count($lignes) > 0
103
-		and preg_match("/^$sep*$/", $lignes[count($lignes) - 1])
104
-	) {
105
-		unset($lignes[count($lignes) - 1]);
106
-	}
107
-	//  calcul du  nombre de colonne a chaque ligne
108
-	$nbcols = [];
109
-	$max = $mil = substr_count($entete, $sep);
110
-	foreach ($lignes as $k => $v) {
111
-		if ($max <> ($nbcols[$k] = substr_count($v, $sep))) {
112
-			if ($max > $nbcols[$k]) {
113
-				$mil = $nbcols[$k];
114
-			} else {
115
-				$mil = $max;
116
-				$max = $nbcols[$k];
117
-			}
118
-		}
119
-	}
120
-	// Si pas le meme nombre, cadrer au nombre max
121
-	if ($mil <> $max) {
122
-		foreach ($nbcols as $k => $v) {
123
-			if ($v < $max) {
124
-				$lignes[$k] .= str_repeat($sep, $max - $v);
125
-			}
126
-		}
127
-	}
128
-	// et retirer les colonnes integralement vides
129
-	while (true) {
130
-		$nbcols = ($entete[strlen($entete) - 1] === $sep);
131
-		foreach ($lignes as $v) {
132
-			$nbcols &= ($v[strlen($v) - 1] === $sep);
133
-		}
134
-		if (!$nbcols) {
135
-			break;
136
-		}
137
-		$entete = substr($entete, 0, -1);
138
-		foreach ($lignes as $k => $v) {
139
-			$lignes[$k] = substr($v, 0, -1);
140
-		}
141
-	}
100
+    // retrait des lignes vides finales
101
+    while (
102
+        count($lignes) > 0
103
+        and preg_match("/^$sep*$/", $lignes[count($lignes) - 1])
104
+    ) {
105
+        unset($lignes[count($lignes) - 1]);
106
+    }
107
+    //  calcul du  nombre de colonne a chaque ligne
108
+    $nbcols = [];
109
+    $max = $mil = substr_count($entete, $sep);
110
+    foreach ($lignes as $k => $v) {
111
+        if ($max <> ($nbcols[$k] = substr_count($v, $sep))) {
112
+            if ($max > $nbcols[$k]) {
113
+                $mil = $nbcols[$k];
114
+            } else {
115
+                $mil = $max;
116
+                $max = $nbcols[$k];
117
+            }
118
+        }
119
+    }
120
+    // Si pas le meme nombre, cadrer au nombre max
121
+    if ($mil <> $max) {
122
+        foreach ($nbcols as $k => $v) {
123
+            if ($v < $max) {
124
+                $lignes[$k] .= str_repeat($sep, $max - $v);
125
+            }
126
+        }
127
+    }
128
+    // et retirer les colonnes integralement vides
129
+    while (true) {
130
+        $nbcols = ($entete[strlen($entete) - 1] === $sep);
131
+        foreach ($lignes as $v) {
132
+            $nbcols &= ($v[strlen($v) - 1] === $sep);
133
+        }
134
+        if (!$nbcols) {
135
+            break;
136
+        }
137
+        $entete = substr($entete, 0, -1);
138
+        foreach ($lignes as $k => $v) {
139
+            $lignes[$k] = substr($v, 0, -1);
140
+        }
141
+    }
142 142
 
143
-	foreach ($lignes as &$l) {
144
-		$l = str_replace('&#34#', '"', $l);
145
-		$l = str_replace('``**``', "\n", $l);
146
-		$l = explode($sep, $l);
147
-	}
143
+    foreach ($lignes as &$l) {
144
+        $l = str_replace('&#34#', '"', $l);
145
+        $l = str_replace('``**``', "\n", $l);
146
+        $l = explode($sep, $l);
147
+    }
148 148
 
149
-	return [explode($sep, $entete), $lignes, $caption];
149
+    return [explode($sep, $entete), $lignes, $caption];
150 150
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -87,12 +87,12 @@
 block discarded – undo
87 87
 	}
88 88
 	// si une seule colonne, en faire le titre
89 89
 	if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) {
90
-		$caption = "\n||" . $l[1] . '|';
90
+		$caption = "\n||".$l[1].'|';
91 91
 		[$entete, $corps] = explode("\n", $corps, 2);
92 92
 	}
93 93
 	// si premiere colonne vide, le raccourci doit quand meme produire <th...
94 94
 	if ($entete[0] == $sep) {
95
-		$entete = ' ' . $entete;
95
+		$entete = ' '.$entete;
96 96
 	}
97 97
 
98 98
 	$lignes = explode("\n", $corps);
Please login to merge, or discard this patch.
ecrire/inc/math.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -37,16 +37,16 @@  discard block
 block discarded – undo
37 37
 	}
38 38
 
39 39
 	// Regarder dans le repertoire local des images TeX et blocs MathML
40
-	if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
40
+	if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) {
41 41
 		@mkdir($dir_tex, _SPIP_CHMOD);
42 42
 	}
43
-	$fichier = $dir_tex . md5(trim($tex)) . $ext;
43
+	$fichier = $dir_tex.md5(trim($tex)).$ext;
44 44
 
45 45
 
46 46
 	if (!@file_exists($fichier)) {
47 47
 		// Aller chercher l'image sur le serveur
48 48
 		if ($server) {
49
-			spip_log($url = $server . '?' . rawurlencode($tex));
49
+			spip_log($url = $server.'?'.rawurlencode($tex));
50 50
 			include_spip('inc/distant');
51 51
 			recuperer_url($url, ['file' => $fichier]);
52 52
 		}
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 			return implode('', file($fichier));
62 62
 		} // TeX
63 63
 		else {
64
-			[, , , $size] = @spip_getimagesize($fichier);
64
+			[,,, $size] = @spip_getimagesize($fichier);
65 65
 			$alt = "alt=\"$tex\" title=\"$tex\"";
66 66
 
67 67
 			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 			if ($defaire_amp) {
129 129
 				$expression = str_replace('&amp;', '&', $expression);
130 130
 			}
131
-			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
131
+			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n";
132 132
 			$pos = strpos($texte_milieu, (string) $regs[0]);
133 133
 			$texte_milieu = substr($texte_milieu, 0, $pos)
134 134
 				. code_echappement($echap, $source)
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 				. substr($texte_milieu, $pos + strlen($regs[0]));
149 149
 		}
150 150
 
151
-		$texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
151
+		$texte_a_voir = $texte_debut.$texte_milieu.$texte_fin;
152 152
 	}
153 153
 
154 154
 	return $texte_a_voir;
Please login to merge, or discard this patch.
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 //
14 14
 if (!defined('_ECRIRE_INC_VERSION')) {
15
-	return;
15
+    return;
16 16
 }
17 17
 
18 18
 //
@@ -21,54 +21,54 @@  discard block
 block discarded – undo
21 21
 
22 22
 function produire_image_math($tex) {
23 23
 
24
-	switch ($GLOBALS['traiter_math']) {
25
-		// Attention: mathml desactiv'e pour l'instant
26
-		case 'mathml':
27
-			$ext = '.xhtml';
28
-			$server = $GLOBALS['mathml_server'];
29
-			break;
30
-		case 'tex':
31
-			$ext = '.png';
32
-			$server = $GLOBALS['tex_server'];
33
-			break;
34
-		default:
35
-			return $tex;
36
-	}
37
-
38
-	// Regarder dans le repertoire local des images TeX et blocs MathML
39
-	if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
40
-		@mkdir($dir_tex, _SPIP_CHMOD);
41
-	}
42
-	$fichier = $dir_tex . md5(trim($tex)) . $ext;
43
-
44
-
45
-	if (!@file_exists($fichier)) {
46
-		// Aller chercher l'image sur le serveur
47
-		if ($server) {
48
-			spip_log($url = $server . '?' . rawurlencode($tex));
49
-			include_spip('inc/distant');
50
-			recuperer_url($url, ['file' => $fichier]);
51
-		}
52
-	}
53
-
54
-
55
-	// Composer la reponse selon presence ou non de l'image
56
-	$tex = entites_html($tex);
57
-	if (@file_exists($fichier)) {
58
-		// MathML
59
-		if ($GLOBALS['traiter_math'] == 'mathml') {
60
-			return implode('', file($fichier));
61
-		} // TeX
62
-		else {
63
-			[, , , $size] = @spip_getimagesize($fichier);
64
-			$alt = "alt=\"$tex\" title=\"$tex\"";
65
-
66
-			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
67
-		}
68
-	} else // pas de fichier
69
-	{
70
-		return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
71
-	}
24
+    switch ($GLOBALS['traiter_math']) {
25
+        // Attention: mathml desactiv'e pour l'instant
26
+        case 'mathml':
27
+            $ext = '.xhtml';
28
+            $server = $GLOBALS['mathml_server'];
29
+            break;
30
+        case 'tex':
31
+            $ext = '.png';
32
+            $server = $GLOBALS['tex_server'];
33
+            break;
34
+        default:
35
+            return $tex;
36
+    }
37
+
38
+    // Regarder dans le repertoire local des images TeX et blocs MathML
39
+    if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
40
+        @mkdir($dir_tex, _SPIP_CHMOD);
41
+    }
42
+    $fichier = $dir_tex . md5(trim($tex)) . $ext;
43
+
44
+
45
+    if (!@file_exists($fichier)) {
46
+        // Aller chercher l'image sur le serveur
47
+        if ($server) {
48
+            spip_log($url = $server . '?' . rawurlencode($tex));
49
+            include_spip('inc/distant');
50
+            recuperer_url($url, ['file' => $fichier]);
51
+        }
52
+    }
53
+
54
+
55
+    // Composer la reponse selon presence ou non de l'image
56
+    $tex = entites_html($tex);
57
+    if (@file_exists($fichier)) {
58
+        // MathML
59
+        if ($GLOBALS['traiter_math'] == 'mathml') {
60
+            return implode('', file($fichier));
61
+        } // TeX
62
+        else {
63
+            [, , , $size] = @spip_getimagesize($fichier);
64
+            $alt = "alt=\"$tex\" title=\"$tex\"";
65
+
66
+            return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
67
+        }
68
+    } else // pas de fichier
69
+    {
70
+        return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
71
+    }
72 72
 }
73 73
 
74 74
 
@@ -103,52 +103,52 @@  discard block
 block discarded – undo
103 103
  */
104 104
 function traiter_math($letexte, $source = '', $defaire_amp = false) {
105 105
 
106
-	$texte_a_voir = $letexte;
107
-	while (($debut = strpos($texte_a_voir, '<math>')) !== false) {
108
-		if (!$fin = strpos($texte_a_voir, '</math>')) {
109
-			$fin = strlen($texte_a_voir);
110
-		}
111
-
112
-		$texte_debut = substr($texte_a_voir, 0, $debut);
113
-		$texte_milieu = substr(
114
-			$texte_a_voir,
115
-			$debut + strlen('<math>'),
116
-			$fin - $debut - strlen('<math>')
117
-		);
118
-		$texte_fin = substr(
119
-			$texte_a_voir,
120
-			$fin + strlen('</math>'),
121
-			strlen($texte_a_voir)
122
-		);
123
-
124
-		// Les doubles $$x^2$$ en mode 'div'
125
-		while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) {
126
-			$expression = $regs[1];
127
-			if ($defaire_amp) {
128
-				$expression = str_replace('&amp;', '&', $expression);
129
-			}
130
-			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
131
-			$pos = strpos($texte_milieu, (string) $regs[0]);
132
-			$texte_milieu = substr($texte_milieu, 0, $pos)
133
-				. code_echappement($echap, $source)
134
-				. substr($texte_milieu, $pos + strlen($regs[0]));
135
-		}
136
-
137
-		// Les simples $x^2$ en mode 'span'
138
-		while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) {
139
-			$expression = $regs[1];
140
-			if ($defaire_amp) {
141
-				$expression = str_replace('&amp;', '&', $expression);
142
-			}
143
-			$echap = produire_image_math($expression);
144
-			$pos = strpos($texte_milieu, (string) $regs[0]);
145
-			$texte_milieu = substr($texte_milieu, 0, $pos)
146
-				. code_echappement($echap, $source)
147
-				. substr($texte_milieu, $pos + strlen($regs[0]));
148
-		}
149
-
150
-		$texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
151
-	}
152
-
153
-	return $texte_a_voir;
106
+    $texte_a_voir = $letexte;
107
+    while (($debut = strpos($texte_a_voir, '<math>')) !== false) {
108
+        if (!$fin = strpos($texte_a_voir, '</math>')) {
109
+            $fin = strlen($texte_a_voir);
110
+        }
111
+
112
+        $texte_debut = substr($texte_a_voir, 0, $debut);
113
+        $texte_milieu = substr(
114
+            $texte_a_voir,
115
+            $debut + strlen('<math>'),
116
+            $fin - $debut - strlen('<math>')
117
+        );
118
+        $texte_fin = substr(
119
+            $texte_a_voir,
120
+            $fin + strlen('</math>'),
121
+            strlen($texte_a_voir)
122
+        );
123
+
124
+        // Les doubles $$x^2$$ en mode 'div'
125
+        while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) {
126
+            $expression = $regs[1];
127
+            if ($defaire_amp) {
128
+                $expression = str_replace('&amp;', '&', $expression);
129
+            }
130
+            $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
131
+            $pos = strpos($texte_milieu, (string) $regs[0]);
132
+            $texte_milieu = substr($texte_milieu, 0, $pos)
133
+                . code_echappement($echap, $source)
134
+                . substr($texte_milieu, $pos + strlen($regs[0]));
135
+        }
136
+
137
+        // Les simples $x^2$ en mode 'span'
138
+        while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) {
139
+            $expression = $regs[1];
140
+            if ($defaire_amp) {
141
+                $expression = str_replace('&amp;', '&', $expression);
142
+            }
143
+            $echap = produire_image_math($expression);
144
+            $pos = strpos($texte_milieu, (string) $regs[0]);
145
+            $texte_milieu = substr($texte_milieu, 0, $pos)
146
+                . code_echappement($echap, $source)
147
+                . substr($texte_milieu, $pos + strlen($regs[0]));
148
+        }
149
+
150
+        $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
151
+    }
152
+
153
+    return $texte_a_voir;
154 154
 }
Please login to merge, or discard this patch.
ecrire/inc/svg.php 3 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		return $fichier;
57 57
 	}
58 58
 	if (!file_exists($fichier)) {
59
-		$fichier  = supprimer_timestamp($fichier);
59
+		$fichier = supprimer_timestamp($fichier);
60 60
 		if (!file_exists($fichier)) {
61 61
 			return false;
62 62
 		}
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
171 171
 	$new_balise_svg = '<svg';
172 172
 	foreach ($attributs as $k => $v) {
173
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
173
+		$new_balise_svg .= " $k=\"".entites_html($v).'"';
174 174
 	}
175 175
 	$new_balise_svg .= '>';
176 176
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 function svg_insert_shapes($svg, $shapes, $start = true) {
190 190
 
191 191
 	if ($start === false or $start === 'end') {
192
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
192
+		$svg = str_replace('</svg>', $shapes.'</svg>', $svg);
193 193
 	}
194 194
 	else {
195 195
 		$p = stripos($svg, '<svg');
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
  */
211 211
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
212 212
 	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
213
+	$id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8);
214 214
 	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215 215
 	$g = "<g clip-path=\"url(#$id)\">";
216
-	$svg = svg_insert_shapes($svg, $clippath . $g);
216
+	$svg = svg_insert_shapes($svg, $clippath.$g);
217 217
 	$svg = svg_insert_shapes($svg, '</g>', false);
218 218
 	return $svg;
219 219
 }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	) {
233 233
 		[$balise_svg, $attributs] = $svg_infos;
234 234
 		if (!isset($attributs['viewBox'])) {
235
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
235
+			$attributs['viewBox'] = '0 0 '.$attributs['width'].' '.$attributs['height'];
236 236
 		}
237 237
 		$attributs['width'] = strval($new_width);
238 238
 		$attributs['height'] = strval($new_height);
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	else {
258 258
 		$couleur = couleur_html_to_hex($couleur);
259 259
 	}
260
-	$couleur = '#' . ltrim($couleur, '#');
260
+	$couleur = '#'.ltrim($couleur, '#');
261 261
 	return $couleur;
262 262
 }
263 263
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 function svg_couleur_to_rgb($couleur) {
270 270
 	if (strpos($couleur, 'rgb(') === 0) {
271 271
 		$c = explode(',', substr($couleur, 4));
272
-		return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
272
+		return ['red' => intval($c[0]), 'green' => intval($c[1]), 'blue' => intval($c[2])];
273 273
 	}
274 274
 	return _couleur_hex_to_dec($couleur);
275 275
 }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 			$background_color = svg_couleur_to_hexa($background_color);
475 475
 			if (isset($attributs['viewBox'])) {
476 476
 				$viewBox = explode(' ', $attributs['viewBox']);
477
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
477
+				$rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\"/>";
478 478
 			}
479 479
 			else {
480 480
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
 			$background_color = svg_couleur_to_hexa($background_color);
505 505
 			if (isset($attributs['viewBox'])) {
506 506
 				$viewBox = explode(' ', $attributs['viewBox']);
507
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
507
+				$rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>";
508 508
 			}
509 509
 			else {
510 510
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 			$g = '<g';
534 534
 			foreach ($attributs as $k => $v) {
535 535
 				if (strlen($v)) {
536
-					$g .= " $k=\"" . attribut_html($v) . '"';
536
+					$g .= " $k=\"".attribut_html($v).'"';
537 537
 				}
538 538
 			}
539 539
 			if (strlen($g) > 2) {
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
 	) {
562 562
 		if ($filter_def) {
563 563
 			[$balise_svg, ] = $svg_infos;
564
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
564
+			$filter_id = 'filter-'.substr(md5($filter_def.strlen($svg)), 0, 8);
565 565
 			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
566 566
 			$g = "<g filter=\"url(#$filter_id)\">";
567
-			$svg = svg_insert_shapes($svg, $filter . $g);
567
+			$svg = svg_insert_shapes($svg, $filter.$g);
568 568
 			$svg = svg_insert_shapes($svg, '</g>', false);
569 569
 		}
570 570
 		return $svg;
Please login to merge, or discard this patch.
Indentation   +458 added lines, -458 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  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
 if (!defined('IMG_SVG')) {
24
-	// complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
-	define('IMG_SVG', 128);
26
-	define('IMAGETYPE_SVG', 19);
24
+    // complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
+    define('IMG_SVG', 128);
26
+    define('IMAGETYPE_SVG', 19);
27 27
 }
28 28
 
29 29
 /**
@@ -39,39 +39,39 @@  discard block
 block discarded – undo
39 39
  *   false si on a pas pu charger l'image
40 40
  */
41 41
 function svg_charger($fichier, $maxlen = null) {
42
-	if (strpos($fichier, 'data:image/svg+xml') === 0) {
43
-		$image = explode(';', $fichier, 2);
44
-		$image = end($image);
45
-		if (strpos($image, 'base64,') === 0) {
46
-			$image = base64_decode(substr($image, 7));
47
-		}
48
-		if (strpos($image, '<svg') !== false) {
49
-			return $image;
50
-		}
51
-		// encodage inconnu ou autre format d'image ?
52
-		return false;
53
-	}
54
-	// c'est peut etre deja une image svg ?
55
-	if (strpos($fichier, '<svg') !== false) {
56
-		return $fichier;
57
-	}
58
-	if (!file_exists($fichier)) {
59
-		$fichier  = supprimer_timestamp($fichier);
60
-		if (!file_exists($fichier)) {
61
-			return false;
62
-		}
63
-	}
64
-	if (is_null($maxlen)) {
65
-		$image = file_get_contents($fichier);
66
-	}
67
-	else {
68
-		$image = file_get_contents($fichier, false, null, 0, $maxlen);
69
-	}
70
-	// est-ce bien une image svg ?
71
-	if (strpos($image, '<svg') !== false) {
72
-		return $image;
73
-	}
74
-	return false;
42
+    if (strpos($fichier, 'data:image/svg+xml') === 0) {
43
+        $image = explode(';', $fichier, 2);
44
+        $image = end($image);
45
+        if (strpos($image, 'base64,') === 0) {
46
+            $image = base64_decode(substr($image, 7));
47
+        }
48
+        if (strpos($image, '<svg') !== false) {
49
+            return $image;
50
+        }
51
+        // encodage inconnu ou autre format d'image ?
52
+        return false;
53
+    }
54
+    // c'est peut etre deja une image svg ?
55
+    if (strpos($fichier, '<svg') !== false) {
56
+        return $fichier;
57
+    }
58
+    if (!file_exists($fichier)) {
59
+        $fichier  = supprimer_timestamp($fichier);
60
+        if (!file_exists($fichier)) {
61
+            return false;
62
+        }
63
+    }
64
+    if (is_null($maxlen)) {
65
+        $image = file_get_contents($fichier);
66
+    }
67
+    else {
68
+        $image = file_get_contents($fichier, false, null, 0, $maxlen);
69
+    }
70
+    // est-ce bien une image svg ?
71
+    if (strpos($image, '<svg') !== false) {
72
+        return $image;
73
+    }
74
+    return false;
75 75
 }
76 76
 
77 77
 /**
@@ -80,28 +80,28 @@  discard block
 block discarded – undo
80 80
  * @return array|bool
81 81
  */
82 82
 function svg_lire_balise_svg($fichier) {
83
-	if (!$debut_fichier = svg_charger($fichier, 4096)) {
84
-		return false;
85
-	}
86
-
87
-	if (($ps = stripos($debut_fichier, '<svg')) !== false) {
88
-		$pe = stripos($debut_fichier, '>', $ps);
89
-		$balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
90
-
91
-		if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
92
-			if (!function_exists('extraire_attribut')) {
93
-				include_spip('inc/filtres');
94
-			}
95
-			$attributs = [];
96
-			foreach ($matches[1] as $att) {
97
-				$attributs[$att] = extraire_attribut($balise_svg, $att);
98
-			}
99
-
100
-			return [$balise_svg, $attributs];
101
-		}
102
-	}
103
-
104
-	return false;
83
+    if (!$debut_fichier = svg_charger($fichier, 4096)) {
84
+        return false;
85
+    }
86
+
87
+    if (($ps = stripos($debut_fichier, '<svg')) !== false) {
88
+        $pe = stripos($debut_fichier, '>', $ps);
89
+        $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
90
+
91
+        if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
92
+            if (!function_exists('extraire_attribut')) {
93
+                include_spip('inc/filtres');
94
+            }
95
+            $attributs = [];
96
+            foreach ($matches[1] as $att) {
97
+                $attributs[$att] = extraire_attribut($balise_svg, $att);
98
+            }
99
+
100
+            return [$balise_svg, $attributs];
101
+        }
102
+    }
103
+
104
+    return false;
105 105
 }
106 106
 
107 107
 /**
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
  */
112 112
 function svg_lire_attributs($img) {
113 113
 
114
-	if ($svg_infos = svg_lire_balise_svg($img)) {
115
-		[$balise_svg, $attributs] = $svg_infos;
116
-		return $attributs;
117
-	}
114
+    if ($svg_infos = svg_lire_balise_svg($img)) {
115
+        [$balise_svg, $attributs] = $svg_infos;
116
+        return $attributs;
117
+    }
118 118
 
119
-	return false;
119
+    return false;
120 120
 }
121 121
 
122 122
 /**
@@ -126,38 +126,38 @@  discard block
 block discarded – undo
126 126
  * @return bool|float|int
127 127
  */
128 128
 function svg_dimension_to_pixels($dimension, $precision = 2) {
129
-	if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
130
-		switch (strtolower($m[2])) {
131
-			case '%':
132
-				// on ne sait pas faire :(
133
-				return false;
134
-				break;
135
-			case 'em':
136
-				return round($m[1] * 16, $precision); // 16px font-size par defaut
137
-				break;
138
-			case 'ex':
139
-				return round($m[1] * 16, $precision); // 16px font-size par defaut
140
-				break;
141
-			case 'pc':
142
-				return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS
143
-				break;
144
-			case 'cm':
145
-				return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm;
146
-				break;
147
-			case 'mm':
148
-				return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm;
149
-				break;
150
-			case 'in':
151
-				return round($m[1] * 96, $precision); // 1 inch = 96px in CSS
152
-				break;
153
-			case 'px':
154
-			case 'pt':
155
-			default:
156
-				return $m[1];
157
-				break;
158
-		}
159
-	}
160
-	return false;
129
+    if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
130
+        switch (strtolower($m[2])) {
131
+            case '%':
132
+                // on ne sait pas faire :(
133
+                return false;
134
+                break;
135
+            case 'em':
136
+                return round($m[1] * 16, $precision); // 16px font-size par defaut
137
+                break;
138
+            case 'ex':
139
+                return round($m[1] * 16, $precision); // 16px font-size par defaut
140
+                break;
141
+            case 'pc':
142
+                return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS
143
+                break;
144
+            case 'cm':
145
+                return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm;
146
+                break;
147
+            case 'mm':
148
+                return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm;
149
+                break;
150
+            case 'in':
151
+                return round($m[1] * 96, $precision); // 1 inch = 96px in CSS
152
+                break;
153
+            case 'px':
154
+            case 'pt':
155
+            default:
156
+                return $m[1];
157
+                break;
158
+        }
159
+    }
160
+    return false;
161 161
 }
162 162
 
163 163
 /**
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
  * @return string
169 169
  */
170 170
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
171
-	$new_balise_svg = '<svg';
172
-	foreach ($attributs as $k => $v) {
173
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
174
-	}
175
-	$new_balise_svg .= '>';
176
-
177
-	$p = strpos($svg, $old_balise_svg);
178
-	$svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
179
-	return $svg;
171
+    $new_balise_svg = '<svg';
172
+    foreach ($attributs as $k => $v) {
173
+        $new_balise_svg .= " $k=\"" . entites_html($v) . '"';
174
+    }
175
+    $new_balise_svg .= '>';
176
+
177
+    $p = strpos($svg, $old_balise_svg);
178
+    $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
179
+    return $svg;
180 180
 }
181 181
 
182 182
 /**
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
  */
189 189
 function svg_insert_shapes($svg, $shapes, $start = true) {
190 190
 
191
-	if ($start === false or $start === 'end') {
192
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
-	}
194
-	else {
195
-		$p = stripos($svg, '<svg');
196
-		$p = strpos($svg, '>', $p);
197
-		$svg = substr_replace($svg, $shapes, $p + 1, 0);
198
-	}
199
-	return $svg;
191
+    if ($start === false or $start === 'end') {
192
+        $svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
+    }
194
+    else {
195
+        $p = stripos($svg, '<svg');
196
+        $p = strpos($svg, '>', $p);
197
+        $svg = substr_replace($svg, $shapes, $p + 1, 0);
198
+    }
199
+    return $svg;
200 200
 }
201 201
 
202 202
 /**
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
  * @return string
210 210
  */
211 211
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
212
-	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
214
-	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215
-	$g = "<g clip-path=\"url(#$id)\">";
216
-	$svg = svg_insert_shapes($svg, $clippath . $g);
217
-	$svg = svg_insert_shapes($svg, '</g>', false);
218
-	return $svg;
212
+    $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
+    $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
214
+    $clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215
+    $g = "<g clip-path=\"url(#$id)\">";
216
+    $svg = svg_insert_shapes($svg, $clippath . $g);
217
+    $svg = svg_insert_shapes($svg, '</g>', false);
218
+    return $svg;
219 219
 }
220 220
 
221 221
 /**
@@ -226,22 +226,22 @@  discard block
 block discarded – undo
226 226
  * @return bool|string
227 227
  */
228 228
 function svg_redimensionner($img, $new_width, $new_height) {
229
-	if (
230
-		$svg = svg_charger($img)
231
-		and $svg_infos = svg_lire_balise_svg($svg)
232
-	) {
233
-		[$balise_svg, $attributs] = $svg_infos;
234
-		if (!isset($attributs['viewBox'])) {
235
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
236
-		}
237
-		$attributs['width'] = strval($new_width);
238
-		$attributs['height'] = strval($new_height);
239
-
240
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
241
-		return $svg;
242
-	}
243
-
244
-	return $img;
229
+    if (
230
+        $svg = svg_charger($img)
231
+        and $svg_infos = svg_lire_balise_svg($svg)
232
+    ) {
233
+        [$balise_svg, $attributs] = $svg_infos;
234
+        if (!isset($attributs['viewBox'])) {
235
+            $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
236
+        }
237
+        $attributs['width'] = strval($new_width);
238
+        $attributs['height'] = strval($new_height);
239
+
240
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
241
+        return $svg;
242
+    }
243
+
244
+    return $img;
245 245
 }
246 246
 
247 247
 /**
@@ -250,15 +250,15 @@  discard block
 block discarded – undo
250 250
  * @return string
251 251
  */
252 252
 function svg_couleur_to_hexa($couleur) {
253
-	if (strpos($couleur, 'rgb(') === 0) {
254
-		$c = explode(',', substr($couleur, 4));
255
-		$couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
-	}
257
-	else {
258
-		$couleur = couleur_html_to_hex($couleur);
259
-	}
260
-	$couleur = '#' . ltrim($couleur, '#');
261
-	return $couleur;
253
+    if (strpos($couleur, 'rgb(') === 0) {
254
+        $c = explode(',', substr($couleur, 4));
255
+        $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
+    }
257
+    else {
258
+        $couleur = couleur_html_to_hex($couleur);
259
+    }
260
+    $couleur = '#' . ltrim($couleur, '#');
261
+    return $couleur;
262 262
 }
263 263
 
264 264
 /**
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
  * @return array
268 268
  */
269 269
 function svg_couleur_to_rgb($couleur) {
270
-	if (strpos($couleur, 'rgb(') === 0) {
271
-		$c = explode(',', substr($couleur, 4));
272
-		return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
273
-	}
274
-	return _couleur_hex_to_dec($couleur);
270
+    if (strpos($couleur, 'rgb(') === 0) {
271
+        $c = explode(',', substr($couleur, 4));
272
+        return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
273
+    }
274
+    return _couleur_hex_to_dec($couleur);
275 275
 }
276 276
 
277 277
 
@@ -281,80 +281,80 @@  discard block
 block discarded – undo
281 281
  * @return array
282 282
  */
283 283
 function svg_getimagesize_from_attr($attributs) {
284
-	$width = 350; // default width
285
-	$height = 150; // default height
286
-
287
-	$viewBox = "0 0 $width $height";
288
-	if (isset($attributs['viewBox'])) {
289
-		$viewBox = $attributs['viewBox'];
290
-		$viewBox = preg_replace(',\s+,', ' ', $viewBox);
291
-	}
292
-	// et on la convertit en px
293
-	$viewBox = explode(' ', $viewBox);
294
-	$viewBox = array_map('svg_dimension_to_pixels', $viewBox);
295
-	if (!$viewBox[2]) {
296
-		$viewBox[2] = $width;
297
-	}
298
-	if (!$viewBox[3]) {
299
-		$viewBox[3] = $height;
300
-	}
301
-
302
-	$coeff = 1;
303
-	if (
304
-		isset($attributs['width'])
305
-		and $w = svg_dimension_to_pixels($attributs['width'])
306
-	) {
307
-		$width = $w;
308
-		// si on avait pas de viewBox, la construire a partir de ce width
309
-		if (empty($attributs['viewBox'])) {
310
-			$viewBox[2] = $width;
311
-			// si pas de height valide, on suppose l'image carree
312
-			$viewBox[3] = $width;
313
-		}
314
-	}
315
-	else {
316
-		// si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
317
-		$width = $viewBox[2];
318
-		if ($width < 1) {
319
-			$coeff = max($coeff, 1000);
320
-		}
321
-		elseif ($width < 10) {
322
-			$coeff = max($coeff, 100);
323
-		}
324
-		elseif ($width < 100) {
325
-			$coeff = max($coeff, 10);
326
-		}
327
-	}
328
-	if (
329
-		isset($attributs['height'])
330
-		and $h = svg_dimension_to_pixels($attributs['height'])
331
-	) {
332
-		$height = $h;
333
-		// si on avait pas de viewBox, la construire a partir de ce height
334
-		if (empty($attributs['viewBox'])) {
335
-			$viewBox[3] = $height;
336
-		}
337
-	}
338
-	else {
339
-		$height = $viewBox[3];
340
-		if ($height < 1) {
341
-			$coeff = max($coeff, 1000);
342
-		}
343
-		elseif ($height < 10) {
344
-			$coeff = max($coeff, 100);
345
-		}
346
-		elseif ($height < 100) {
347
-			$coeff = max($coeff, 10);
348
-		}
349
-	}
350
-
351
-	// arrondir le width et height en pixel in fine
352
-	$width = round($coeff * $width);
353
-	$height = round($coeff * $height);
354
-
355
-	$viewBox = implode(' ', $viewBox);
356
-
357
-	return [$width, $height, $viewBox];
284
+    $width = 350; // default width
285
+    $height = 150; // default height
286
+
287
+    $viewBox = "0 0 $width $height";
288
+    if (isset($attributs['viewBox'])) {
289
+        $viewBox = $attributs['viewBox'];
290
+        $viewBox = preg_replace(',\s+,', ' ', $viewBox);
291
+    }
292
+    // et on la convertit en px
293
+    $viewBox = explode(' ', $viewBox);
294
+    $viewBox = array_map('svg_dimension_to_pixels', $viewBox);
295
+    if (!$viewBox[2]) {
296
+        $viewBox[2] = $width;
297
+    }
298
+    if (!$viewBox[3]) {
299
+        $viewBox[3] = $height;
300
+    }
301
+
302
+    $coeff = 1;
303
+    if (
304
+        isset($attributs['width'])
305
+        and $w = svg_dimension_to_pixels($attributs['width'])
306
+    ) {
307
+        $width = $w;
308
+        // si on avait pas de viewBox, la construire a partir de ce width
309
+        if (empty($attributs['viewBox'])) {
310
+            $viewBox[2] = $width;
311
+            // si pas de height valide, on suppose l'image carree
312
+            $viewBox[3] = $width;
313
+        }
314
+    }
315
+    else {
316
+        // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
317
+        $width = $viewBox[2];
318
+        if ($width < 1) {
319
+            $coeff = max($coeff, 1000);
320
+        }
321
+        elseif ($width < 10) {
322
+            $coeff = max($coeff, 100);
323
+        }
324
+        elseif ($width < 100) {
325
+            $coeff = max($coeff, 10);
326
+        }
327
+    }
328
+    if (
329
+        isset($attributs['height'])
330
+        and $h = svg_dimension_to_pixels($attributs['height'])
331
+    ) {
332
+        $height = $h;
333
+        // si on avait pas de viewBox, la construire a partir de ce height
334
+        if (empty($attributs['viewBox'])) {
335
+            $viewBox[3] = $height;
336
+        }
337
+    }
338
+    else {
339
+        $height = $viewBox[3];
340
+        if ($height < 1) {
341
+            $coeff = max($coeff, 1000);
342
+        }
343
+        elseif ($height < 10) {
344
+            $coeff = max($coeff, 100);
345
+        }
346
+        elseif ($height < 100) {
347
+            $coeff = max($coeff, 10);
348
+        }
349
+    }
350
+
351
+    // arrondir le width et height en pixel in fine
352
+    $width = round($coeff * $width);
353
+    $height = round($coeff * $height);
354
+
355
+    $viewBox = implode(' ', $viewBox);
356
+
357
+    return [$width, $height, $viewBox];
358 358
 }
359 359
 
360 360
 /**
@@ -370,25 +370,25 @@  discard block
 block discarded – undo
370 370
  * @return string
371 371
  */
372 372
 function svg_force_viewBox_px($img, $force_width_and_height = false) {
373
-	if (
374
-		$svg = svg_charger($img)
375
-		and $svg_infos = svg_lire_balise_svg($svg)
376
-	) {
377
-		[$balise_svg, $attributs] = $svg_infos;
373
+    if (
374
+        $svg = svg_charger($img)
375
+        and $svg_infos = svg_lire_balise_svg($svg)
376
+    ) {
377
+        [$balise_svg, $attributs] = $svg_infos;
378 378
 
379
-		[$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs);
379
+        [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs);
380 380
 
381
-		if ($force_width_and_height) {
382
-			$attributs['width'] = $width;
383
-			$attributs['height'] = $height;
384
-		}
381
+        if ($force_width_and_height) {
382
+            $attributs['width'] = $width;
383
+            $attributs['height'] = $height;
384
+        }
385 385
 
386
-		$attributs['viewBox'] = $viewBox;
386
+        $attributs['viewBox'] = $viewBox;
387 387
 
388
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
389
-		return $svg;
390
-	}
391
-	return $img;
388
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
389
+        return $svg;
390
+    }
391
+    return $img;
392 392
 }
393 393
 
394 394
 /**
@@ -397,12 +397,12 @@  discard block
 block discarded – undo
397 397
  * @return array|mixed
398 398
  */
399 399
 function svg_extract_couleurs($img) {
400
-	if ($svg = svg_charger($img)) {
401
-		if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) {
402
-			return $matches[0];
403
-		}
404
-	}
405
-	return [];
400
+    if ($svg = svg_charger($img)) {
401
+        if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) {
402
+            return $matches[0];
403
+        }
404
+    }
405
+    return [];
406 406
 }
407 407
 
408 408
 /**
@@ -413,58 +413,58 @@  discard block
 block discarded – undo
413 413
  * @return bool|string
414 414
  */
415 415
 function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') {
416
-	if (
417
-		$svg = svg_force_viewBox_px($img)
418
-		and $svg_infos = svg_lire_balise_svg($svg)
419
-	) {
420
-		[$balise_svg, $attributs] = $svg_infos;
421
-		$viewBox = explode(' ', $attributs['viewBox']);
422
-
423
-		$viewport_w = $new_width;
424
-		$viewport_h = $new_height;
425
-		$viewport_ox = $offset_width;
426
-		$viewport_oy = $offset_height;
427
-
428
-		// si on a un width/height qui rescale, il faut rescaler
429
-		if (
430
-			isset($attributs['width'])
431
-			and $w = svg_dimension_to_pixels($attributs['width'])
432
-			and isset($attributs['height'])
433
-			and $h = svg_dimension_to_pixels($attributs['height'])
434
-		) {
435
-			$xscale = $viewBox[2] / $w;
436
-			$viewport_w = round($viewport_w * $xscale, 2);
437
-			$viewport_ox = round($viewport_ox * $xscale, 2);
438
-			$yscale = $viewBox[3] / $h;
439
-			$viewport_h = round($viewport_h * $yscale, 2);
440
-			$viewport_oy = round($viewport_oy * $yscale, 2);
441
-		}
442
-
443
-		if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) {
444
-			$svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
445
-		}
446
-
447
-		// maintenant on redefinit la viewBox
448
-		$viewBox[0] += $viewport_ox;
449
-		$viewBox[1] += $viewport_oy;
450
-		$viewBox[2] = $viewport_w;
451
-		$viewBox[3] = $viewport_h;
452
-
453
-		$attributs['viewBox'] = implode(' ', $viewBox);
454
-		$attributs['width'] = strval($new_width);
455
-		$attributs['height'] = strval($new_height);
456
-
457
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
458
-
459
-		// ajouter un background
460
-		if ($background_color and $background_color !== 'transparent') {
461
-			$svg = svg_ajouter_background($svg, $background_color);
462
-		}
463
-
464
-		return $svg;
465
-	}
466
-
467
-	return $img;
416
+    if (
417
+        $svg = svg_force_viewBox_px($img)
418
+        and $svg_infos = svg_lire_balise_svg($svg)
419
+    ) {
420
+        [$balise_svg, $attributs] = $svg_infos;
421
+        $viewBox = explode(' ', $attributs['viewBox']);
422
+
423
+        $viewport_w = $new_width;
424
+        $viewport_h = $new_height;
425
+        $viewport_ox = $offset_width;
426
+        $viewport_oy = $offset_height;
427
+
428
+        // si on a un width/height qui rescale, il faut rescaler
429
+        if (
430
+            isset($attributs['width'])
431
+            and $w = svg_dimension_to_pixels($attributs['width'])
432
+            and isset($attributs['height'])
433
+            and $h = svg_dimension_to_pixels($attributs['height'])
434
+        ) {
435
+            $xscale = $viewBox[2] / $w;
436
+            $viewport_w = round($viewport_w * $xscale, 2);
437
+            $viewport_ox = round($viewport_ox * $xscale, 2);
438
+            $yscale = $viewBox[3] / $h;
439
+            $viewport_h = round($viewport_h * $yscale, 2);
440
+            $viewport_oy = round($viewport_oy * $yscale, 2);
441
+        }
442
+
443
+        if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) {
444
+            $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
445
+        }
446
+
447
+        // maintenant on redefinit la viewBox
448
+        $viewBox[0] += $viewport_ox;
449
+        $viewBox[1] += $viewport_oy;
450
+        $viewBox[2] = $viewport_w;
451
+        $viewBox[3] = $viewport_h;
452
+
453
+        $attributs['viewBox'] = implode(' ', $viewBox);
454
+        $attributs['width'] = strval($new_width);
455
+        $attributs['height'] = strval($new_height);
456
+
457
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
458
+
459
+        // ajouter un background
460
+        if ($background_color and $background_color !== 'transparent') {
461
+            $svg = svg_ajouter_background($svg, $background_color);
462
+        }
463
+
464
+        return $svg;
465
+    }
466
+
467
+    return $img;
468 468
 }
469 469
 
470 470
 /**
@@ -474,26 +474,26 @@  discard block
 block discarded – undo
474 474
  * @return bool|string
475 475
  */
476 476
 function svg_ajouter_background($img, $background_color) {
477
-	if (
478
-		$svg = svg_charger($img)
479
-		and $svg_infos = svg_lire_balise_svg($svg)
480
-	) {
481
-		if ($background_color and $background_color !== 'transparent') {
482
-			[$balise_svg, $attributs] = $svg_infos;
483
-
484
-			$background_color = svg_couleur_to_hexa($background_color);
485
-			if (isset($attributs['viewBox'])) {
486
-				$viewBox = explode(' ', $attributs['viewBox']);
487
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
488
-			}
489
-			else {
490
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
491
-			}
492
-			$svg = svg_insert_shapes($svg, $rect);
493
-		}
494
-		return $svg;
495
-	}
496
-	return $img;
477
+    if (
478
+        $svg = svg_charger($img)
479
+        and $svg_infos = svg_lire_balise_svg($svg)
480
+    ) {
481
+        if ($background_color and $background_color !== 'transparent') {
482
+            [$balise_svg, $attributs] = $svg_infos;
483
+
484
+            $background_color = svg_couleur_to_hexa($background_color);
485
+            if (isset($attributs['viewBox'])) {
486
+                $viewBox = explode(' ', $attributs['viewBox']);
487
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
488
+            }
489
+            else {
490
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
491
+            }
492
+            $svg = svg_insert_shapes($svg, $rect);
493
+        }
494
+        return $svg;
495
+    }
496
+    return $img;
497 497
 }
498 498
 
499 499
 
@@ -504,26 +504,26 @@  discard block
 block discarded – undo
504 504
  * @return bool|string
505 505
  */
506 506
 function svg_ajouter_voile($img, $background_color, $opacity) {
507
-	if (
508
-		$svg = svg_charger($img)
509
-		and $svg_infos = svg_lire_balise_svg($svg)
510
-	) {
511
-		if ($background_color and $background_color !== 'transparent') {
512
-			[$balise_svg, $attributs] = $svg_infos;
513
-
514
-			$background_color = svg_couleur_to_hexa($background_color);
515
-			if (isset($attributs['viewBox'])) {
516
-				$viewBox = explode(' ', $attributs['viewBox']);
517
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
518
-			}
519
-			else {
520
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
521
-			}
522
-			$svg = svg_insert_shapes($svg, $rect, false);
523
-		}
524
-		return $svg;
525
-	}
526
-	return $img;
507
+    if (
508
+        $svg = svg_charger($img)
509
+        and $svg_infos = svg_lire_balise_svg($svg)
510
+    ) {
511
+        if ($background_color and $background_color !== 'transparent') {
512
+            [$balise_svg, $attributs] = $svg_infos;
513
+
514
+            $background_color = svg_couleur_to_hexa($background_color);
515
+            if (isset($attributs['viewBox'])) {
516
+                $viewBox = explode(' ', $attributs['viewBox']);
517
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
518
+            }
519
+            else {
520
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
521
+            }
522
+            $svg = svg_insert_shapes($svg, $rect, false);
523
+        }
524
+        return $svg;
525
+    }
526
+    return $img;
527 527
 }
528 528
 
529 529
 
@@ -534,27 +534,27 @@  discard block
 block discarded – undo
534 534
  * @return bool|string
535 535
  */
536 536
 function svg_transformer($img, $attributs) {
537
-	if (
538
-		$svg = svg_charger($img)
539
-		and $svg_infos = svg_lire_balise_svg($svg)
540
-	) {
541
-		if ($attributs) {
542
-			[$balise_svg, ] = $svg_infos;
543
-			$g = '<g';
544
-			foreach ($attributs as $k => $v) {
545
-				if (strlen($v)) {
546
-					$g .= " $k=\"" . attribut_html($v) . '"';
547
-				}
548
-			}
549
-			if (strlen($g) > 2) {
550
-				$g .= '>';
551
-				$svg = svg_insert_shapes($svg, $g);
552
-				$svg = svg_insert_shapes($svg, '</g>', false);
553
-			}
554
-		}
555
-		return $svg;
556
-	}
557
-	return $img;
537
+    if (
538
+        $svg = svg_charger($img)
539
+        and $svg_infos = svg_lire_balise_svg($svg)
540
+    ) {
541
+        if ($attributs) {
542
+            [$balise_svg, ] = $svg_infos;
543
+            $g = '<g';
544
+            foreach ($attributs as $k => $v) {
545
+                if (strlen($v)) {
546
+                    $g .= " $k=\"" . attribut_html($v) . '"';
547
+                }
548
+            }
549
+            if (strlen($g) > 2) {
550
+                $g .= '>';
551
+                $svg = svg_insert_shapes($svg, $g);
552
+                $svg = svg_insert_shapes($svg, '</g>', false);
553
+            }
554
+        }
555
+        return $svg;
556
+    }
557
+    return $img;
558 558
 }
559 559
 
560 560
 /**
@@ -565,21 +565,21 @@  discard block
 block discarded – undo
565 565
  * @return bool|string
566 566
  */
567 567
 function svg_apply_filter($img, $filter_def) {
568
-	if (
569
-		$svg = svg_charger($img)
570
-		and $svg_infos = svg_lire_balise_svg($svg)
571
-	) {
572
-		if ($filter_def) {
573
-			[$balise_svg, ] = $svg_infos;
574
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
575
-			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
576
-			$g = "<g filter=\"url(#$filter_id)\">";
577
-			$svg = svg_insert_shapes($svg, $filter . $g);
578
-			$svg = svg_insert_shapes($svg, '</g>', false);
579
-		}
580
-		return $svg;
581
-	}
582
-	return $img;
568
+    if (
569
+        $svg = svg_charger($img)
570
+        and $svg_infos = svg_lire_balise_svg($svg)
571
+    ) {
572
+        if ($filter_def) {
573
+            [$balise_svg, ] = $svg_infos;
574
+            $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
575
+            $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
576
+            $g = "<g filter=\"url(#$filter_id)\">";
577
+            $svg = svg_insert_shapes($svg, $filter . $g);
578
+            $svg = svg_insert_shapes($svg, '</g>', false);
579
+        }
580
+        return $svg;
581
+    }
582
+    return $img;
583 583
 }
584 584
 
585 585
 /**
@@ -589,8 +589,8 @@  discard block
 block discarded – undo
589 589
  * @return string
590 590
  */
591 591
 function svg_filter_blur($img, $blur_width) {
592
-	$blur_width = intval($blur_width);
593
-	return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
592
+    $blur_width = intval($blur_width);
593
+    return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
594 594
 }
595 595
 
596 596
 /**
@@ -600,10 +600,10 @@  discard block
 block discarded – undo
600 600
  * @return bool|string
601 601
  */
602 602
 function svg_filter_grayscale($img, $intensity) {
603
-	$value = round(1.0 - $intensity, 2);
604
-	//$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
605
-	$filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
606
-	return svg_apply_filter($img, $filter);
603
+    $value = round(1.0 - $intensity, 2);
604
+    //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
605
+    $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
606
+    return svg_apply_filter($img, $filter);
607 607
 }
608 608
 
609 609
 /**
@@ -613,8 +613,8 @@  discard block
 block discarded – undo
613 613
  * @return bool|string
614 614
  */
615 615
 function svg_filter_sepia($img, $intensity) {
616
-	$filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
617
-	return svg_apply_filter($img, $filter);
616
+    $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
617
+    return svg_apply_filter($img, $filter);
618 618
 }
619 619
 
620 620
 /**
@@ -624,31 +624,31 @@  discard block
 block discarded – undo
624 624
  * @return bool|string
625 625
  */
626 626
 function svg_flip($img, $HorV) {
627
-	if (
628
-		$svg = svg_force_viewBox_px($img)
629
-		and $svg_infos = svg_lire_balise_svg($svg)
630
-	) {
631
-		[$balise_svg, $atts] = $svg_infos;
632
-		$viewBox = explode(' ', $atts['viewBox']);
633
-
634
-		if (!in_array($HorV, ['h', 'H'])) {
635
-			$transform = 'scale(-1,1)';
636
-
637
-			$x = intval($viewBox[0]) + intval($viewBox[2] / 2);
638
-			$mx = -$x;
639
-			$transform = "translate($x, 0) $transform translate($mx, 0)";
640
-		}
641
-		else {
642
-			$transform = 'scale(1,-1)';
643
-
644
-			$y = intval($viewBox[1]) + intval($viewBox[3] / 2);
645
-			$my = -$y;
646
-			$transform = "translate(0, $y) $transform translate(0, $my)";
647
-		}
648
-		$svg = svg_transformer($svg, ['transform' => $transform]);
649
-		return $svg;
650
-	}
651
-	return $img;
627
+    if (
628
+        $svg = svg_force_viewBox_px($img)
629
+        and $svg_infos = svg_lire_balise_svg($svg)
630
+    ) {
631
+        [$balise_svg, $atts] = $svg_infos;
632
+        $viewBox = explode(' ', $atts['viewBox']);
633
+
634
+        if (!in_array($HorV, ['h', 'H'])) {
635
+            $transform = 'scale(-1,1)';
636
+
637
+            $x = intval($viewBox[0]) + intval($viewBox[2] / 2);
638
+            $mx = -$x;
639
+            $transform = "translate($x, 0) $transform translate($mx, 0)";
640
+        }
641
+        else {
642
+            $transform = 'scale(1,-1)';
643
+
644
+            $y = intval($viewBox[1]) + intval($viewBox[3] / 2);
645
+            $my = -$y;
646
+            $transform = "translate(0, $y) $transform translate(0, $my)";
647
+        }
648
+        $svg = svg_transformer($svg, ['transform' => $transform]);
649
+        return $svg;
650
+    }
651
+    return $img;
652 652
 }
653 653
 
654 654
 /**
@@ -662,20 +662,20 @@  discard block
 block discarded – undo
662 662
  * @return bool|string
663 663
  */
664 664
 function svg_rotate($img, $angle, $center_x, $center_y) {
665
-	if (
666
-		$svg = svg_force_viewBox_px($img)
667
-		and $svg_infos = svg_lire_balise_svg($svg)
668
-	) {
669
-		[$balise_svg, $atts] = $svg_infos;
670
-		$viewBox = explode(' ', $atts['viewBox']);
671
-
672
-		$center_x = round($viewBox[0] + $center_x * $viewBox[2]);
673
-		$center_y = round($viewBox[1] + $center_y * $viewBox[3]);
674
-		$svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
675
-
676
-		return $svg;
677
-	}
678
-	return $img;
665
+    if (
666
+        $svg = svg_force_viewBox_px($img)
667
+        and $svg_infos = svg_lire_balise_svg($svg)
668
+    ) {
669
+        [$balise_svg, $atts] = $svg_infos;
670
+        $viewBox = explode(' ', $atts['viewBox']);
671
+
672
+        $center_x = round($viewBox[0] + $center_x * $viewBox[2]);
673
+        $center_y = round($viewBox[1] + $center_y * $viewBox[3]);
674
+        $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
675
+
676
+        return $svg;
677
+    }
678
+    return $img;
679 679
 }
680 680
 
681 681
 /**
@@ -687,41 +687,41 @@  discard block
 block discarded – undo
687 687
  * @return bool|mixed|string
688 688
  */
689 689
 function svg_filtrer_couleurs($img, $callback_filter) {
690
-	if (
691
-		$svg = svg_force_viewBox_px($img)
692
-		and $colors = svg_extract_couleurs($svg)
693
-	) {
694
-		$colors = array_unique($colors);
695
-
696
-		$short = [];
697
-		$long = [];
698
-		while (count($colors)) {
699
-			$c = array_shift($colors);
700
-			if (strlen($c) == 4) {
701
-				$short[] = $c;
702
-			}
703
-			else {
704
-				$long[] = $c;
705
-			}
706
-		}
707
-
708
-		$colors = [...$long, ...$short];
709
-		$new_colors = [];
710
-		$colors = array_flip($colors);
711
-		foreach ($colors as $c => $k) {
712
-			$colors[$c] = "@@@COLOR$$k$@@@";
713
-		}
714
-
715
-
716
-		foreach ($colors as $original => $replace) {
717
-			$new = svg_couleur_to_hexa($original);
718
-			$new_colors[$replace] = $callback_filter($new);
719
-		}
720
-
721
-		$svg = str_replace(array_keys($colors), array_values($colors), $svg);
722
-		$svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
723
-
724
-		return $svg;
725
-	}
726
-	return $img;
690
+    if (
691
+        $svg = svg_force_viewBox_px($img)
692
+        and $colors = svg_extract_couleurs($svg)
693
+    ) {
694
+        $colors = array_unique($colors);
695
+
696
+        $short = [];
697
+        $long = [];
698
+        while (count($colors)) {
699
+            $c = array_shift($colors);
700
+            if (strlen($c) == 4) {
701
+                $short[] = $c;
702
+            }
703
+            else {
704
+                $long[] = $c;
705
+            }
706
+        }
707
+
708
+        $colors = [...$long, ...$short];
709
+        $new_colors = [];
710
+        $colors = array_flip($colors);
711
+        foreach ($colors as $c => $k) {
712
+            $colors[$c] = "@@@COLOR$$k$@@@";
713
+        }
714
+
715
+
716
+        foreach ($colors as $original => $replace) {
717
+            $new = svg_couleur_to_hexa($original);
718
+            $new_colors[$replace] = $callback_filter($new);
719
+        }
720
+
721
+        $svg = str_replace(array_keys($colors), array_values($colors), $svg);
722
+        $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
723
+
724
+        return $svg;
725
+    }
726
+    return $img;
727 727
 }
Please login to merge, or discard this patch.
Braces   +13 added lines, -26 removed lines patch added patch discarded remove patch
@@ -63,8 +63,7 @@  discard block
 block discarded – undo
63 63
 	}
64 64
 	if (is_null($maxlen)) {
65 65
 		$image = file_get_contents($fichier);
66
-	}
67
-	else {
66
+	} else {
68 67
 		$image = file_get_contents($fichier, false, null, 0, $maxlen);
69 68
 	}
70 69
 	// est-ce bien une image svg ?
@@ -190,8 +189,7 @@  discard block
 block discarded – undo
190 189
 
191 190
 	if ($start === false or $start === 'end') {
192 191
 		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
-	}
194
-	else {
192
+	} else {
195 193
 		$p = stripos($svg, '<svg');
196 194
 		$p = strpos($svg, '>', $p);
197 195
 		$svg = substr_replace($svg, $shapes, $p + 1, 0);
@@ -253,8 +251,7 @@  discard block
 block discarded – undo
253 251
 	if (strpos($couleur, 'rgb(') === 0) {
254 252
 		$c = explode(',', substr($couleur, 4));
255 253
 		$couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
-	}
257
-	else {
254
+	} else {
258 255
 		$couleur = couleur_html_to_hex($couleur);
259 256
 	}
260 257
 	$couleur = '#' . ltrim($couleur, '#');
@@ -311,17 +308,14 @@  discard block
 block discarded – undo
311 308
 			// si pas de height valide, on suppose l'image carree
312 309
 			$viewBox[3] = $width;
313 310
 		}
314
-	}
315
-	else {
311
+	} else {
316 312
 		// si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
317 313
 		$width = $viewBox[2];
318 314
 		if ($width < 1) {
319 315
 			$coeff = max($coeff, 1000);
320
-		}
321
-		elseif ($width < 10) {
316
+		} elseif ($width < 10) {
322 317
 			$coeff = max($coeff, 100);
323
-		}
324
-		elseif ($width < 100) {
318
+		} elseif ($width < 100) {
325 319
 			$coeff = max($coeff, 10);
326 320
 		}
327 321
 	}
@@ -334,16 +328,13 @@  discard block
 block discarded – undo
334 328
 		if (empty($attributs['viewBox'])) {
335 329
 			$viewBox[3] = $height;
336 330
 		}
337
-	}
338
-	else {
331
+	} else {
339 332
 		$height = $viewBox[3];
340 333
 		if ($height < 1) {
341 334
 			$coeff = max($coeff, 1000);
342
-		}
343
-		elseif ($height < 10) {
335
+		} elseif ($height < 10) {
344 336
 			$coeff = max($coeff, 100);
345
-		}
346
-		elseif ($height < 100) {
337
+		} elseif ($height < 100) {
347 338
 			$coeff = max($coeff, 10);
348 339
 		}
349 340
 	}
@@ -485,8 +476,7 @@  discard block
 block discarded – undo
485 476
 			if (isset($attributs['viewBox'])) {
486 477
 				$viewBox = explode(' ', $attributs['viewBox']);
487 478
 				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
488
-			}
489
-			else {
479
+			} else {
490 480
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
491 481
 			}
492 482
 			$svg = svg_insert_shapes($svg, $rect);
@@ -515,8 +505,7 @@  discard block
 block discarded – undo
515 505
 			if (isset($attributs['viewBox'])) {
516 506
 				$viewBox = explode(' ', $attributs['viewBox']);
517 507
 				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
518
-			}
519
-			else {
508
+			} else {
520 509
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
521 510
 			}
522 511
 			$svg = svg_insert_shapes($svg, $rect, false);
@@ -637,8 +626,7 @@  discard block
 block discarded – undo
637 626
 			$x = intval($viewBox[0]) + intval($viewBox[2] / 2);
638 627
 			$mx = -$x;
639 628
 			$transform = "translate($x, 0) $transform translate($mx, 0)";
640
-		}
641
-		else {
629
+		} else {
642 630
 			$transform = 'scale(1,-1)';
643 631
 
644 632
 			$y = intval($viewBox[1]) + intval($viewBox[3] / 2);
@@ -699,8 +687,7 @@  discard block
 block discarded – undo
699 687
 			$c = array_shift($colors);
700 688
 			if (strlen($c) == 4) {
701 689
 				$short[] = $c;
702
-			}
703
-			else {
690
+			} else {
704 691
 				$long[] = $c;
705 692
 			}
706 693
 		}
Please login to merge, or discard this patch.
ecrire/inc/rechercher.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
101 101
 		// c'est une preg
102 102
 		$recherche_trans = translitteration($recherche);
103
-		$preg = $recherche_trans . $options['preg_flags'];
103
+		$preg = $recherche_trans.$options['preg_flags'];
104 104
 		$is_preg = true;
105 105
 	} else {
106 106
 		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 			}
121 121
 		}
122 122
 
123
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
123
+		if (preg_match(',\s+,'.$u, $recherche_mod)) {
124 124
 			$is_preg = true;
125 125
 
126 126
 			$recherche_inter = '|';
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 			foreach ($recherche_mots as $mot) {
131 131
 				if (strlen($mot) >= $min_long) {
132 132
 					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
133
-					$recherche_inter .= preg_quote($mot) . ' ';
133
+					$recherche_inter .= preg_quote($mot).' ';
134 134
 					$petits_mots = false;
135 135
 				}
136 136
 			}
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
 
139 139
 			// mais on cherche quand même l'expression complète, même si elle
140 140
 			// comporte des mots de moins de quatre lettres
141
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
141
+			$recherche = trim(preg_replace(',\s+,'.$u, '|', $recherche_inter), '|');
142 142
 			if (!$recherche or $petits_mots) {
143 143
 				$recherche = preg_quote($recherche_org);
144 144
 			}
145 145
 			$recherche_trans = translitteration($recherche);
146 146
 		}
147 147
 
148
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
148
+		$preg = '/'.str_replace('/', '\\/', $recherche_trans).'/'.$options['preg_flags'];
149 149
 	}
150 150
 
151 151
 	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 		}
186 186
 		$q = sql_quote(
187 187
 			'%'
188
-			. preg_replace(',\s+,' . $u, '%', $q)
188
+			. preg_replace(',\s+,'.$u, '%', $q)
189 189
 			. '%'
190 190
 		);
191 191
 
192
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
192
+		$preg = '/'.preg_replace(',\s+,'.$u, '.+', trim($recherche_mod)).'/'.$options['preg_flags'];
193 193
 	} else {
194 194
 		$methode = 'REGEXP';
195 195
 		$q = sql_quote(trim($recherche, '/'));
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	foreach ($tables as $table => $champs) {
312 312
 		# lock via memoization, si dispo
313 313
 		if (function_exists('cache_lock')) {
314
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
314
+			cache_lock($lock = _RECHERCHE_LOCK_KEY.' '.$table.' '.$recherche);
315 315
 		}
316 316
 
317 317
 		spip_timer('rech');
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 
327 327
 
328 328
 		spip_log(
329
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
329
+			"recherche $table ($recherche) : ".(is_countable($results[$table]) ? count($results[$table]) : 0).' resultats '.spip_timer('rech'),
330 330
 			'recherche'
331 331
 		);
332 332
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 
362 362
 	$results = recherche_en_base($recherche, $tables, $options);
363 363
 
364
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
364
+	$preg = '/'.str_replace('/', '\\/', $recherche).'/'.$options['preg_flags'];
365 365
 
366 366
 	foreach ($results as $table => $r) {
367 367
 		$_id_table = id_table_objet($table);
Please login to merge, or discard this patch.
Indentation   +317 added lines, -317 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
 defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext');
@@ -35,198 +35,198 @@  discard block
 block discarded – undo
35 35
  * @return array Couples (type d'objet => Couples (champ => score))
36 36
  */
37 37
 function liste_des_champs() {
38
-	static $liste = null;
39
-	if (is_null($liste)) {
40
-		$liste = [];
41
-		// recuperer les tables_objets_sql declarees
42
-		include_spip('base/objets');
43
-		$tables_objets = lister_tables_objets_sql();
44
-		foreach ($tables_objets as $t => $infos) {
45
-			if ($infos['rechercher_champs']) {
46
-				$liste[$infos['type']] = $infos['rechercher_champs'];
47
-			}
48
-		}
49
-		// puis passer dans le pipeline
50
-		$liste = pipeline('rechercher_liste_des_champs', $liste);
51
-	}
52
-
53
-	return $liste;
38
+    static $liste = null;
39
+    if (is_null($liste)) {
40
+        $liste = [];
41
+        // recuperer les tables_objets_sql declarees
42
+        include_spip('base/objets');
43
+        $tables_objets = lister_tables_objets_sql();
44
+        foreach ($tables_objets as $t => $infos) {
45
+            if ($infos['rechercher_champs']) {
46
+                $liste[$infos['type']] = $infos['rechercher_champs'];
47
+            }
48
+        }
49
+        // puis passer dans le pipeline
50
+        $liste = pipeline('rechercher_liste_des_champs', $liste);
51
+    }
52
+
53
+    return $liste;
54 54
 }
55 55
 
56 56
 
57 57
 // Recherche des auteurs et mots-cles associes
58 58
 // en ne regardant que le titre ou le nom
59 59
 function liste_des_jointures() {
60
-	static $liste = null;
61
-	if (is_null($liste)) {
62
-		$liste = [];
63
-		// recuperer les tables_objets_sql declarees
64
-		include_spip('base/objets');
65
-		$tables_objets = lister_tables_objets_sql();
66
-		foreach ($tables_objets as $t => $infos) {
67
-			if ($infos['rechercher_jointures']) {
68
-				$liste[$infos['type']] = $infos['rechercher_jointures'];
69
-			}
70
-		}
71
-		// puis passer dans le pipeline
72
-		$liste = pipeline('rechercher_liste_des_jointures', $liste);
73
-	}
74
-
75
-	return $liste;
60
+    static $liste = null;
61
+    if (is_null($liste)) {
62
+        $liste = [];
63
+        // recuperer les tables_objets_sql declarees
64
+        include_spip('base/objets');
65
+        $tables_objets = lister_tables_objets_sql();
66
+        foreach ($tables_objets as $t => $infos) {
67
+            if ($infos['rechercher_jointures']) {
68
+                $liste[$infos['type']] = $infos['rechercher_jointures'];
69
+            }
70
+        }
71
+        // puis passer dans le pipeline
72
+        $liste = pipeline('rechercher_liste_des_jointures', $liste);
73
+    }
74
+
75
+    return $liste;
76 76
 }
77 77
 
78 78
 function expression_recherche($recherche, $options) {
79
-	// ne calculer qu'une seule fois l'expression par hit
80
-	// (meme si utilisee dans plusieurs boucles)
81
-	static $expression = [];
82
-	$key = serialize([$recherche, $options['preg_flags']]);
83
-	if (isset($expression[$key])) {
84
-		return $expression[$key];
85
-	}
86
-
87
-	$u = $GLOBALS['meta']['pcre_u'];
88
-	if ($u and !str_contains($options['preg_flags'], (string) $u)) {
89
-		$options['preg_flags'] .= $u;
90
-	}
91
-	include_spip('inc/charsets');
92
-	$recherche = trim($recherche);
93
-
94
-	// retirer les + de +truc et les * de truc*
95
-	$recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
96
-	$recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
97
-
98
-	$is_preg = false;
99
-	if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
100
-		// c'est une preg
101
-		$recherche_trans = translitteration($recherche);
102
-		$preg = $recherche_trans . $options['preg_flags'];
103
-		$is_preg = true;
104
-	} else {
105
-		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
106
-		// sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
107
-		// 'une', 'des' ...)
108
-
109
-		// attention : plusieurs mots entre guillemets sont a rechercher tels quels
110
-		$recherche_trans = $recherche_mod = $recherche_org = $recherche;
111
-
112
-		// les expressions entre " " sont un mot a chercher tel quel
113
-		// -> on remplace les espaces par un \x1 et on enleve les guillemets
114
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
115
-			foreach ($matches as $match) {
116
-				$word = preg_replace(',\s+,Uims', "\x1", $match);
117
-				$word = trim($word, '"');
118
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
119
-			}
120
-		}
121
-
122
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
123
-			$is_preg = true;
124
-
125
-			$recherche_inter = '|';
126
-			$recherche_mots = explode(' ', $recherche_mod);
127
-			$min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
128
-			$petits_mots = true;
129
-			foreach ($recherche_mots as $mot) {
130
-				if (strlen($mot) >= $min_long) {
131
-					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
132
-					$recherche_inter .= preg_quote($mot) . ' ';
133
-					$petits_mots = false;
134
-				}
135
-			}
136
-			$recherche_inter = str_replace("\x1", '\s', $recherche_inter);
137
-
138
-			// mais on cherche quand même l'expression complète, même si elle
139
-			// comporte des mots de moins de quatre lettres
140
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
141
-			if (!$recherche or $petits_mots) {
142
-				$recherche = preg_quote($recherche_org);
143
-			}
144
-			$recherche_trans = translitteration($recherche);
145
-		}
146
-
147
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
148
-	}
149
-
150
-	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
151
-	// ou si l'expression reguliere est invalide
152
-	if (
153
-		!$is_preg
154
-		or (@preg_match($preg, '') === false)
155
-	) {
156
-		$methode = 'LIKE';
157
-		$u = $GLOBALS['meta']['pcre_u'];
158
-
159
-		// echapper les % et _
160
-		$q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
161
-
162
-		// eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
163
-		$recherche = preg_quote($recherche, '/');
164
-		$recherche_trans = translitteration($recherche);
165
-		$recherche_mod = $recherche_trans;
166
-
167
-		// les expressions entre " " sont un mot a chercher tel quel
168
-		// -> on remplace les espaces par un _ et on enleve les guillemets
169
-		// corriger le like dans le $q
170
-		if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
171
-			foreach ($matches as $match) {
172
-				$word = preg_replace(',\s+,Uims', '_', $match);
173
-				$word = trim($word, '"');
174
-				$q = str_replace($match, $word, $q);
175
-			}
176
-		}
177
-		// corriger la regexp
178
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
179
-			foreach ($matches as $match) {
180
-				$word = preg_replace(',\s+,Uims', '[\s]', $match);
181
-				$word = trim($word, '"');
182
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
183
-			}
184
-		}
185
-		$q = sql_quote(
186
-			'%'
187
-			. preg_replace(',\s+,' . $u, '%', $q)
188
-			. '%'
189
-		);
190
-
191
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
192
-	} else {
193
-		$methode = 'REGEXP';
194
-		$q = sql_quote(trim($recherche, '/'));
195
-	}
196
-
197
-	// tous les caracteres transliterables de $q sont remplaces par un joker
198
-	// permet de matcher en SQL meme si on est sensible aux accents (SQLite)
199
-	$q_t = $q;
200
-	for ($i = 0; $i < spip_strlen($q); $i++) {
201
-		$char = spip_substr($q, $i, 1);
202
-		if (
203
-			!is_ascii($char)
204
-			and $char_t = translitteration($char)
205
-			and $char_t !== $char
206
-		) {
207
-			// on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
208
-			// mais c'est un pis aller cf #4354
209
-			$q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
210
-		}
211
-	}
212
-
213
-	$q = $q_t;
214
-
215
-	// fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
216
-	// les plus frequents qui peuvent etre accentues
217
-	// (oui c'est tres dicustable...)
218
-	if (
219
-		isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
220
-		and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0
221
-	) {
222
-		$q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
223
-		// si il reste au moins un char significatif...
224
-		if (preg_match(",[^'%_.],", $q_t)) {
225
-			$q = $q_t;
226
-		}
227
-	}
228
-
229
-	return $expression[$key] = [$methode, $q, $preg];
79
+    // ne calculer qu'une seule fois l'expression par hit
80
+    // (meme si utilisee dans plusieurs boucles)
81
+    static $expression = [];
82
+    $key = serialize([$recherche, $options['preg_flags']]);
83
+    if (isset($expression[$key])) {
84
+        return $expression[$key];
85
+    }
86
+
87
+    $u = $GLOBALS['meta']['pcre_u'];
88
+    if ($u and !str_contains($options['preg_flags'], (string) $u)) {
89
+        $options['preg_flags'] .= $u;
90
+    }
91
+    include_spip('inc/charsets');
92
+    $recherche = trim($recherche);
93
+
94
+    // retirer les + de +truc et les * de truc*
95
+    $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
96
+    $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
97
+
98
+    $is_preg = false;
99
+    if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
100
+        // c'est une preg
101
+        $recherche_trans = translitteration($recherche);
102
+        $preg = $recherche_trans . $options['preg_flags'];
103
+        $is_preg = true;
104
+    } else {
105
+        // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
106
+        // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
107
+        // 'une', 'des' ...)
108
+
109
+        // attention : plusieurs mots entre guillemets sont a rechercher tels quels
110
+        $recherche_trans = $recherche_mod = $recherche_org = $recherche;
111
+
112
+        // les expressions entre " " sont un mot a chercher tel quel
113
+        // -> on remplace les espaces par un \x1 et on enleve les guillemets
114
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
115
+            foreach ($matches as $match) {
116
+                $word = preg_replace(',\s+,Uims', "\x1", $match);
117
+                $word = trim($word, '"');
118
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
119
+            }
120
+        }
121
+
122
+        if (preg_match(',\s+,' . $u, $recherche_mod)) {
123
+            $is_preg = true;
124
+
125
+            $recherche_inter = '|';
126
+            $recherche_mots = explode(' ', $recherche_mod);
127
+            $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
128
+            $petits_mots = true;
129
+            foreach ($recherche_mots as $mot) {
130
+                if (strlen($mot) >= $min_long) {
131
+                    // echapper les caracteres de regexp qui sont eventuellement dans la recherche
132
+                    $recherche_inter .= preg_quote($mot) . ' ';
133
+                    $petits_mots = false;
134
+                }
135
+            }
136
+            $recherche_inter = str_replace("\x1", '\s', $recherche_inter);
137
+
138
+            // mais on cherche quand même l'expression complète, même si elle
139
+            // comporte des mots de moins de quatre lettres
140
+            $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
141
+            if (!$recherche or $petits_mots) {
142
+                $recherche = preg_quote($recherche_org);
143
+            }
144
+            $recherche_trans = translitteration($recherche);
145
+        }
146
+
147
+        $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
148
+    }
149
+
150
+    // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
151
+    // ou si l'expression reguliere est invalide
152
+    if (
153
+        !$is_preg
154
+        or (@preg_match($preg, '') === false)
155
+    ) {
156
+        $methode = 'LIKE';
157
+        $u = $GLOBALS['meta']['pcre_u'];
158
+
159
+        // echapper les % et _
160
+        $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
161
+
162
+        // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
163
+        $recherche = preg_quote($recherche, '/');
164
+        $recherche_trans = translitteration($recherche);
165
+        $recherche_mod = $recherche_trans;
166
+
167
+        // les expressions entre " " sont un mot a chercher tel quel
168
+        // -> on remplace les espaces par un _ et on enleve les guillemets
169
+        // corriger le like dans le $q
170
+        if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
171
+            foreach ($matches as $match) {
172
+                $word = preg_replace(',\s+,Uims', '_', $match);
173
+                $word = trim($word, '"');
174
+                $q = str_replace($match, $word, $q);
175
+            }
176
+        }
177
+        // corriger la regexp
178
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
179
+            foreach ($matches as $match) {
180
+                $word = preg_replace(',\s+,Uims', '[\s]', $match);
181
+                $word = trim($word, '"');
182
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
183
+            }
184
+        }
185
+        $q = sql_quote(
186
+            '%'
187
+            . preg_replace(',\s+,' . $u, '%', $q)
188
+            . '%'
189
+        );
190
+
191
+        $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
192
+    } else {
193
+        $methode = 'REGEXP';
194
+        $q = sql_quote(trim($recherche, '/'));
195
+    }
196
+
197
+    // tous les caracteres transliterables de $q sont remplaces par un joker
198
+    // permet de matcher en SQL meme si on est sensible aux accents (SQLite)
199
+    $q_t = $q;
200
+    for ($i = 0; $i < spip_strlen($q); $i++) {
201
+        $char = spip_substr($q, $i, 1);
202
+        if (
203
+            !is_ascii($char)
204
+            and $char_t = translitteration($char)
205
+            and $char_t !== $char
206
+        ) {
207
+            // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
208
+            // mais c'est un pis aller cf #4354
209
+            $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
210
+        }
211
+    }
212
+
213
+    $q = $q_t;
214
+
215
+    // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
216
+    // les plus frequents qui peuvent etre accentues
217
+    // (oui c'est tres dicustable...)
218
+    if (
219
+        isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
220
+        and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0
221
+    ) {
222
+        $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
223
+        // si il reste au moins un char significatif...
224
+        if (preg_match(",[^'%_.],", $q_t)) {
225
+            $q = $q_t;
226
+        }
227
+    }
228
+
229
+    return $expression[$key] = [$methode, $q, $preg];
230 230
 }
231 231
 
232 232
 
@@ -253,142 +253,142 @@  discard block
 block discarded – undo
253 253
  * @return array
254 254
  */
255 255
 function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') {
256
-	include_spip('base/abstract_sql');
257
-
258
-	if (!is_array($tables)) {
259
-		$liste = liste_des_champs();
260
-
261
-		if (
262
-			is_string($tables)
263
-			and $tables != ''
264
-		) {
265
-			$toutes = [];
266
-			foreach (explode(',', $tables) as $t) {
267
-				$t = trim($t);
268
-				if (isset($liste[$t])) {
269
-					$toutes[$t] = $liste[$t];
270
-				}
271
-			}
272
-			$tables = $toutes;
273
-			unset($toutes);
274
-		} else {
275
-			$tables = $liste;
276
-		}
277
-	}
278
-
279
-	if (!strlen($recherche) or !count($tables)) {
280
-		return [];
281
-	}
282
-
283
-	include_spip('inc/autoriser');
284
-
285
-	// options par defaut
286
-	$options = array_merge(
287
-		[
288
-		'preg_flags' => 'UimsS',
289
-		'toutvoir' => false,
290
-		'champs' => false,
291
-		'score' => false,
292
-		'matches' => false,
293
-		'jointures' => false,
294
-		'serveur' => $serveur
295
-		],
296
-		$options
297
-	);
298
-
299
-	$results = [];
300
-
301
-	// Utiliser l'iterateur (DATA:recherche)
302
-	// pour recuperer les couples (id_objet, score)
303
-	// Le resultat est au format {
304
-	//      id1 = { 'score' => x, attrs => { } },
305
-	//      id2 = { 'score' => x, attrs => { } },
306
-	// }
307
-
308
-	include_spip('inc/recherche_to_array');
309
-
310
-	foreach ($tables as $table => $champs) {
311
-		# lock via memoization, si dispo
312
-		if (function_exists('cache_lock')) {
313
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
314
-		}
315
-
316
-		spip_timer('rech');
317
-
318
-		# TODO : ici plutot charger un iterateur via l'API iterateurs
319
-		$to_array = charger_fonction('recherche_to_array', 'inc');
320
-		$results[$table] = $to_array(
321
-			$recherche,
322
-			array_merge($options, ['table' => $table, 'champs' => $champs])
323
-		);
324
-		##var_dump($results[$table]);
325
-
326
-
327
-		spip_log(
328
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
329
-			'recherche'
330
-		);
331
-
332
-		if (isset($lock)) {
333
-			cache_unlock($lock);
334
-		}
335
-	}
336
-
337
-	return $results;
256
+    include_spip('base/abstract_sql');
257
+
258
+    if (!is_array($tables)) {
259
+        $liste = liste_des_champs();
260
+
261
+        if (
262
+            is_string($tables)
263
+            and $tables != ''
264
+        ) {
265
+            $toutes = [];
266
+            foreach (explode(',', $tables) as $t) {
267
+                $t = trim($t);
268
+                if (isset($liste[$t])) {
269
+                    $toutes[$t] = $liste[$t];
270
+                }
271
+            }
272
+            $tables = $toutes;
273
+            unset($toutes);
274
+        } else {
275
+            $tables = $liste;
276
+        }
277
+    }
278
+
279
+    if (!strlen($recherche) or !count($tables)) {
280
+        return [];
281
+    }
282
+
283
+    include_spip('inc/autoriser');
284
+
285
+    // options par defaut
286
+    $options = array_merge(
287
+        [
288
+        'preg_flags' => 'UimsS',
289
+        'toutvoir' => false,
290
+        'champs' => false,
291
+        'score' => false,
292
+        'matches' => false,
293
+        'jointures' => false,
294
+        'serveur' => $serveur
295
+        ],
296
+        $options
297
+    );
298
+
299
+    $results = [];
300
+
301
+    // Utiliser l'iterateur (DATA:recherche)
302
+    // pour recuperer les couples (id_objet, score)
303
+    // Le resultat est au format {
304
+    //      id1 = { 'score' => x, attrs => { } },
305
+    //      id2 = { 'score' => x, attrs => { } },
306
+    // }
307
+
308
+    include_spip('inc/recherche_to_array');
309
+
310
+    foreach ($tables as $table => $champs) {
311
+        # lock via memoization, si dispo
312
+        if (function_exists('cache_lock')) {
313
+            cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
314
+        }
315
+
316
+        spip_timer('rech');
317
+
318
+        # TODO : ici plutot charger un iterateur via l'API iterateurs
319
+        $to_array = charger_fonction('recherche_to_array', 'inc');
320
+        $results[$table] = $to_array(
321
+            $recherche,
322
+            array_merge($options, ['table' => $table, 'champs' => $champs])
323
+        );
324
+        ##var_dump($results[$table]);
325
+
326
+
327
+        spip_log(
328
+            "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
329
+            'recherche'
330
+        );
331
+
332
+        if (isset($lock)) {
333
+            cache_unlock($lock);
334
+        }
335
+    }
336
+
337
+    return $results;
338 338
 }
339 339
 
340 340
 
341 341
 // Effectue une recherche sur toutes les tables de la base de donnees
342 342
 function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) {
343
-	include_spip('inc/modifier');
344
-
345
-	// options par defaut
346
-	$options = array_merge(
347
-		[
348
-		'preg_flags' => 'UimsS',
349
-		'toutmodifier' => false
350
-		],
351
-		$options
352
-	);
353
-	$options['champs'] = true;
354
-
355
-
356
-	if (!is_array($tables)) {
357
-		$tables = liste_des_champs();
358
-	}
359
-
360
-	$results = recherche_en_base($recherche, $tables, $options);
361
-
362
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
363
-
364
-	foreach ($results as $table => $r) {
365
-		$_id_table = id_table_objet($table);
366
-		foreach ($r as $id => $x) {
367
-			if (
368
-				$options['toutmodifier']
369
-				or autoriser('modifier', $table, $id)
370
-			) {
371
-				$modifs = [];
372
-				foreach ($x['champs'] as $key => $val) {
373
-					if ($key == $_id_table) {
374
-						continue;
375
-					}
376
-					$repl = preg_replace($preg, $remplace, $val);
377
-					if ($repl <> $val) {
378
-						$modifs[$key] = $repl;
379
-					}
380
-				}
381
-				if ($modifs) {
382
-					objet_modifier_champs(
383
-						$table,
384
-						$id,
385
-						[
386
-							'champs' => array_keys($modifs),
387
-						],
388
-						$modifs
389
-					);
390
-				}
391
-			}
392
-		}
393
-	}
343
+    include_spip('inc/modifier');
344
+
345
+    // options par defaut
346
+    $options = array_merge(
347
+        [
348
+        'preg_flags' => 'UimsS',
349
+        'toutmodifier' => false
350
+        ],
351
+        $options
352
+    );
353
+    $options['champs'] = true;
354
+
355
+
356
+    if (!is_array($tables)) {
357
+        $tables = liste_des_champs();
358
+    }
359
+
360
+    $results = recherche_en_base($recherche, $tables, $options);
361
+
362
+    $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
363
+
364
+    foreach ($results as $table => $r) {
365
+        $_id_table = id_table_objet($table);
366
+        foreach ($r as $id => $x) {
367
+            if (
368
+                $options['toutmodifier']
369
+                or autoriser('modifier', $table, $id)
370
+            ) {
371
+                $modifs = [];
372
+                foreach ($x['champs'] as $key => $val) {
373
+                    if ($key == $_id_table) {
374
+                        continue;
375
+                    }
376
+                    $repl = preg_replace($preg, $remplace, $val);
377
+                    if ($repl <> $val) {
378
+                        $modifs[$key] = $repl;
379
+                    }
380
+                }
381
+                if ($modifs) {
382
+                    objet_modifier_champs(
383
+                        $table,
384
+                        $id,
385
+                        [
386
+                            'champs' => array_keys($modifs),
387
+                        ],
388
+                        $modifs
389
+                    );
390
+                }
391
+            }
392
+        }
393
+    }
394 394
 }
Please login to merge, or discard this patch.
ecrire/inc/invalideur.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	$n = 0;
46 46
 	$time = $GLOBALS['meta']['cache_mark'] ?? 0;
47 47
 	for ($i = 0; $i < 256; $i++) {
48
-		$dir = _DIR_CACHE . sprintf('%02s', dechex($i));
48
+		$dir = _DIR_CACHE.sprintf('%02s', dechex($i));
49 49
 		if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
50 50
 			while (($f = readdir($d)) !== false) {
51 51
 				if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) {
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 
103 103
 	// stocker la date_modif_$objet (ne sert a rien pour le moment)
104 104
 	if (isset($objet)) {
105
-		ecrire_meta('derniere_modif_' . $objet, time());
105
+		ecrire_meta('derniere_modif_'.$objet, time());
106 106
 	}
107 107
 
108 108
 	// si $derniere_modif_invalide est un array('article', 'rubrique')
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 
146 146
 	// sur certains sites on veut absolument garder certains caches référencés dans un CDN
147 147
 	// on peut donc inhiber la purge de ces répertoires pour eviter tout probleme
148
-	if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) {
148
+	if (file_exists(rtrim($dir, '/').'/inhib_purger_repertoire.txt')) {
149 149
 		return 0;
150 150
 	}
151 151
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 		)
209 209
 	) {
210 210
 		// supprimer le fichier (de facon propre)
211
-		supprimer_fichier(_DIR_CACHE . $cache);
211
+		supprimer_fichier(_DIR_CACHE.$cache);
212 212
 	} else {
213 213
 		spip_log("Nom de fichier cache incorrect : $cache");
214 214
 	}
Please login to merge, or discard this patch.
Indentation   +138 added lines, -138 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
 include_spip('base/serial');
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  * en droit de l'éliminer
28 28
  */
29 29
 if (!defined('_AGE_CACHE_ATIME')) {
30
-	define('_AGE_CACHE_ATIME', 3600);
30
+    define('_AGE_CACHE_ATIME', 3600);
31 31
 }
32 32
 
33 33
 
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
  * @return int Taille approximative en octets
41 41
  **/
42 42
 function taille_du_cache() {
43
-	# check dirs until we reach > 500 files
44
-	$t = 0;
45
-	$n = 0;
46
-	$time = $GLOBALS['meta']['cache_mark'] ?? 0;
47
-	for ($i = 0; $i < 256; $i++) {
48
-		$dir = _DIR_CACHE . sprintf('%02s', dechex($i));
49
-		if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
50
-			while (($f = readdir($d)) !== false) {
51
-				if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) {
52
-					$n++;
53
-					if ($a['mtime'] >= $time) {
54
-						if ($a['blocks'] > 0) {
55
-							$t += 512 * $a['blocks'];
56
-						} else {
57
-							$t += $a['size'];
58
-						}
59
-					}
60
-				}
61
-			}
62
-		}
63
-		if ($n > 500) {
64
-			return intval(256 * $t / (1 + $i));
65
-		}
66
-	}
67
-	return $t;
43
+    # check dirs until we reach > 500 files
44
+    $t = 0;
45
+    $n = 0;
46
+    $time = $GLOBALS['meta']['cache_mark'] ?? 0;
47
+    for ($i = 0; $i < 256; $i++) {
48
+        $dir = _DIR_CACHE . sprintf('%02s', dechex($i));
49
+        if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
50
+            while (($f = readdir($d)) !== false) {
51
+                if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) {
52
+                    $n++;
53
+                    if ($a['mtime'] >= $time) {
54
+                        if ($a['blocks'] > 0) {
55
+                            $t += 512 * $a['blocks'];
56
+                        } else {
57
+                            $t += $a['size'];
58
+                        }
59
+                    }
60
+                }
61
+            }
62
+        }
63
+        if ($n > 500) {
64
+            return intval(256 * $t / (1 + $i));
65
+        }
66
+    }
67
+    return $t;
68 68
 }
69 69
 
70 70
 
@@ -91,30 +91,30 @@  discard block
 block discarded – undo
91 91
  *     Inutilisé
92 92
  **/
93 93
 function inc_suivre_invalideur_dist($cond, $modif = true) {
94
-	if (!$modif) {
95
-		return;
96
-	}
97
-
98
-	// determiner l'objet modifie : forum, article, etc
99
-	if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) {
100
-		$objet = objet_type($r[1]);
101
-	}
102
-
103
-	// stocker la date_modif_$objet (ne sert a rien pour le moment)
104
-	if (isset($objet)) {
105
-		ecrire_meta('derniere_modif_' . $objet, time());
106
-	}
107
-
108
-	// si $derniere_modif_invalide est un array('article', 'rubrique')
109
-	// n'affecter la meta que si un de ces objets est modifie
110
-	if (is_array($GLOBALS['derniere_modif_invalide'])) {
111
-		if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) {
112
-			ecrire_meta('derniere_modif', time());
113
-		}
114
-	} // sinon, cas standard, toujours affecter la meta
115
-	else {
116
-		ecrire_meta('derniere_modif', time());
117
-	}
94
+    if (!$modif) {
95
+        return;
96
+    }
97
+
98
+    // determiner l'objet modifie : forum, article, etc
99
+    if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) {
100
+        $objet = objet_type($r[1]);
101
+    }
102
+
103
+    // stocker la date_modif_$objet (ne sert a rien pour le moment)
104
+    if (isset($objet)) {
105
+        ecrire_meta('derniere_modif_' . $objet, time());
106
+    }
107
+
108
+    // si $derniere_modif_invalide est un array('article', 'rubrique')
109
+    // n'affecter la meta que si un de ces objets est modifie
110
+    if (is_array($GLOBALS['derniere_modif_invalide'])) {
111
+        if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) {
112
+            ecrire_meta('derniere_modif', time());
113
+        }
114
+    } // sinon, cas standard, toujours affecter la meta
115
+    else {
116
+        ecrire_meta('derniere_modif', time());
117
+    }
118 118
 }
119 119
 
120 120
 
@@ -139,57 +139,57 @@  discard block
 block discarded – undo
139 139
  *     Nombre de fichiers supprimés
140 140
  **/
141 141
 function purger_repertoire($dir, $options = []) {
142
-	if (!is_dir($dir) or !is_readable($dir)) {
143
-		return 0;
144
-	}
145
-
146
-	// sur certains sites on veut absolument garder certains caches référencés dans un CDN
147
-	// on peut donc inhiber la purge de ces répertoires pour eviter tout probleme
148
-	if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) {
149
-		return 0;
150
-	}
151
-
152
-	$handle = opendir($dir);
153
-	if (!$handle) {
154
-		return 0;
155
-	}
156
-
157
-	$total = 0;
158
-
159
-	while (($fichier = @readdir($handle)) !== false) {
160
-		// Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG
161
-		if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') {
162
-			continue;
163
-		}
164
-		$chemin = "$dir/$fichier";
165
-		if (is_file($chemin)) {
166
-			if (
167
-				(!isset($options['atime']) or (@fileatime($chemin) < $options['atime']))
168
-				and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime']))
169
-			) {
170
-				supprimer_fichier($chemin);
171
-				$total++;
172
-			}
173
-		} else {
174
-			if (is_dir($chemin)) {
175
-				$opts = $options;
176
-				if (isset($options['limit'])) {
177
-					$opts['limit'] = $options['limit'] - $total;
178
-				}
179
-				$total += purger_repertoire($chemin, $opts);
180
-				if (isset($options['subdir']) && $options['subdir']) {
181
-					spip_unlink($chemin);
182
-				}
183
-			}
184
-		}
185
-
186
-		if (isset($options['limit']) and $total >= $options['limit']) {
187
-			break;
188
-		}
189
-	}
190
-	closedir($handle);
191
-
192
-	return $total;
142
+    if (!is_dir($dir) or !is_readable($dir)) {
143
+        return 0;
144
+    }
145
+
146
+    // sur certains sites on veut absolument garder certains caches référencés dans un CDN
147
+    // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme
148
+    if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) {
149
+        return 0;
150
+    }
151
+
152
+    $handle = opendir($dir);
153
+    if (!$handle) {
154
+        return 0;
155
+    }
156
+
157
+    $total = 0;
158
+
159
+    while (($fichier = @readdir($handle)) !== false) {
160
+        // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG
161
+        if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') {
162
+            continue;
163
+        }
164
+        $chemin = "$dir/$fichier";
165
+        if (is_file($chemin)) {
166
+            if (
167
+                (!isset($options['atime']) or (@fileatime($chemin) < $options['atime']))
168
+                and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime']))
169
+            ) {
170
+                supprimer_fichier($chemin);
171
+                $total++;
172
+            }
173
+        } else {
174
+            if (is_dir($chemin)) {
175
+                $opts = $options;
176
+                if (isset($options['limit'])) {
177
+                    $opts['limit'] = $options['limit'] - $total;
178
+                }
179
+                $total += purger_repertoire($chemin, $opts);
180
+                if (isset($options['subdir']) && $options['subdir']) {
181
+                    spip_unlink($chemin);
182
+                }
183
+            }
184
+        }
185
+
186
+        if (isset($options['limit']) and $total >= $options['limit']) {
187
+            break;
188
+        }
189
+    }
190
+    closedir($handle);
191
+
192
+    return $total;
193 193
 }
194 194
 
195 195
 
@@ -200,26 +200,26 @@  discard block
 block discarded – undo
200 200
 // Securite : est sur que c'est un cache
201 201
 function retire_cache($cache) {
202 202
 
203
-	if (
204
-		preg_match(
205
-			',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i',
206
-			$cache
207
-		)
208
-	) {
209
-		// supprimer le fichier (de facon propre)
210
-		supprimer_fichier(_DIR_CACHE . $cache);
211
-	} else {
212
-		spip_log("Nom de fichier cache incorrect : $cache");
213
-	}
203
+    if (
204
+        preg_match(
205
+            ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i',
206
+            $cache
207
+        )
208
+    ) {
209
+        // supprimer le fichier (de facon propre)
210
+        supprimer_fichier(_DIR_CACHE . $cache);
211
+    } else {
212
+        spip_log("Nom de fichier cache incorrect : $cache");
213
+    }
214 214
 }
215 215
 
216 216
 // Supprimer les caches marques "x"
217 217
 // A priori dans cette version la fonction ne sera pas appelee, car
218 218
 // la meta est toujours false ; mais evitons un bug si elle est appellee
219 219
 function inc_retire_caches_dist($chemin = '') {
220
-	if (isset($GLOBALS['meta']['invalider_caches'])) {
221
-		effacer_meta('invalider_caches');
222
-	} # concurrence
220
+    if (isset($GLOBALS['meta']['invalider_caches'])) {
221
+        effacer_meta('invalider_caches');
222
+    } # concurrence
223 223
 }
224 224
 
225 225
 #######################################################################
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 ##
231 231
 
232 232
 function retire_caches($chemin = '') {
233
-	if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) {
234
-		return $retire_caches($chemin);
235
-	}
233
+    if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) {
234
+        return $retire_caches($chemin);
235
+    }
236 236
 }
237 237
 
238 238
 
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 // (note: si absente, n'est pas appellee)
241 241
 
242 242
 function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) {
243
-	if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) {
244
-		return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle);
245
-	}
246
-	return $corps;
243
+    if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) {
244
+        return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle);
245
+    }
246
+    return $corps;
247 247
 }
248 248
 
249 249
 
@@ -252,41 +252,41 @@  discard block
 block discarded – undo
252 252
 // invoquee quand on vide tout le cache en bloc (action/purger)
253 253
 //
254 254
 function supprime_invalideurs() {
255
-	if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) {
256
-		return $supprime_invalideurs();
257
-	}
255
+    if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) {
256
+        return $supprime_invalideurs();
257
+    }
258 258
 }
259 259
 
260 260
 
261 261
 // Calcul des pages : noter dans la base les liens d'invalidation
262 262
 function maj_invalideurs($fichier, &$page) {
263
-	if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) {
264
-		return $maj_invalideurs($fichier, $page);
265
-	}
263
+    if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) {
264
+        return $maj_invalideurs($fichier, $page);
265
+    }
266 266
 }
267 267
 
268 268
 
269 269
 // les invalideurs sont de la forme "objet/id_objet"
270 270
 function insere_invalideur($inval, $fichier) {
271
-	if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) {
272
-		return $insere_invalideur($inval, $fichier);
273
-	}
271
+    if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) {
272
+        return $insere_invalideur($inval, $fichier);
273
+    }
274 274
 }
275 275
 
276 276
 //
277 277
 // Marquer les fichiers caches invalides comme etant a supprimer
278 278
 //
279 279
 function applique_invalideur($depart) {
280
-	if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) {
281
-		return $applique_invalideur($depart);
282
-	}
280
+    if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) {
281
+        return $applique_invalideur($depart);
282
+    }
283 283
 }
284 284
 
285 285
 //
286 286
 // Invalider les caches liés à telle condition
287 287
 //
288 288
 function suivre_invalideur($cond, $modif = true) {
289
-	if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) {
290
-		return $suivre_invalideur($cond, $modif);
291
-	}
289
+    if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) {
290
+        return $suivre_invalideur($cond, $modif);
291
+    }
292 292
 }
Please login to merge, or discard this patch.
ecrire/inc/plonger.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	$res = sql_select(
36 36
 		'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant',
37 37
 		'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)',
38
-		'rub1.id_parent = ' . sql_quote($id_rubrique) . '
39
-			AND rub1.id_rubrique!=' . sql_quote($exclu) . '
40
-			AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')',
38
+		'rub1.id_parent = '.sql_quote($id_rubrique).'
39
+			AND rub1.id_rubrique!=' . sql_quote($exclu).'
40
+			AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu).')',
41 41
 		'',
42 42
 		'0+rub1.titre,rub1.titre'
43 43
 	);
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 				if ($row['langue_choisie'] != 'oui') {
51 51
 					$t .= ' <small title="'
52 52
 						. traduire_nom_langue($row['lang'])
53
-						. '">[' . $row['lang'] . ']</small>';
53
+						. '">['.$row['lang'].']</small>';
54 54
 				}
55 55
 				$ordre[$row['id_rubrique']] = $t;
56 56
 			}
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 	}
59 59
 	$next = $list[$col] ?? 0;
60 60
 	if ($ordre) {
61
-		$rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1));
61
+		$rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=".($col + 1));
62 62
 		$info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id=");
63
-		$args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event";
63
+		$args = "'$idom',this,$col,'".$GLOBALS['spip_lang_left']."','$info',event";
64 64
 
65 65
 		foreach ($ordre as $id => $titrebrut) {
66 66
 			$titre = supprimer_numero($titrebrut);
67 67
 
68
-			$classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur');
68
+			$classe1 = 'petit-item '.($id_rubrique ? 'petite-rubrique' : 'petit-secteur');
69 69
 			if (isset($rub[$id]['enfants'])) {
70 70
 				$classe2 = " class='rub-ouverte'";
71 71
 				$url = "\nhref='$rec&amp;id=$id'";
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 				$url = "\nhref='javascript:void(0)'";
75 75
 			}
76 76
 
77
-			$js_func = $do . '_selection_titre';
77
+			$js_func = $do.'_selection_titre';
78 78
 			$click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn "
79 79
 				. (!is_array($list) ? ' false'
80 80
 					: "aff_selection_provisoire($id,$args)")
@@ -101,17 +101,17 @@  discard block
 block discarded – undo
101 101
 		}
102 102
 	}
103 103
 
104
-	$idom2 = $idom . '_col_' . ($col + 1);
104
+	$idom2 = $idom.'_col_'.($col + 1);
105 105
 	$left = ($col * 250);
106 106
 
107 107
 	return http_img_pack(
108 108
 		'loader.svg',
109 109
 		'',
110
-		"class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': '
110
+		"class='loader' style='visibility: hidden; position: absolute; ".$GLOBALS['spip_lang_left'].': '
111 111
 		. ($left - 30)
112 112
 		. "px; top: 2px; z-index: 2;' id='img_$idom2'"
113 113
 	)
114
-	. "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': '
114
+	. "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; ".$GLOBALS['spip_lang_left'].': '
115 115
 	. ($left - 250)
116 116
 	. "px;'>"
117 117
 	. $ret
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -11,112 +11,112 @@
 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/texte');
18 18
 
19 19
 function inc_plonger_dist($id_rubrique, $idom = '', $list = [], $col = 1, $exclu = 0, $do = 'aff') {
20 20
 
21
-	if ($list) {
22
-		$id_rubrique = $list[$col - 1];
23
-	}
21
+    if ($list) {
22
+        $id_rubrique = $list[$col - 1];
23
+    }
24 24
 
25
-	$ret = '';
25
+    $ret = '';
26 26
 
27
-	# recherche les filles et petites-filles de la rubrique donnee
28
-	# en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on
29
-	# deplace une rubrique, on peut la deplacer partout a partir de la
30
-	# racine... sauf vers elle-meme ou sa propre branche)
31
-	$ordre = [];
32
-	$rub = [];
27
+    # recherche les filles et petites-filles de la rubrique donnee
28
+    # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on
29
+    # deplace une rubrique, on peut la deplacer partout a partir de la
30
+    # racine... sauf vers elle-meme ou sa propre branche)
31
+    $ordre = [];
32
+    $rub = [];
33 33
 
34
-	$res = sql_select(
35
-		'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant',
36
-		'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)',
37
-		'rub1.id_parent = ' . sql_quote($id_rubrique) . '
34
+    $res = sql_select(
35
+        'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant',
36
+        'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)',
37
+        'rub1.id_parent = ' . sql_quote($id_rubrique) . '
38 38
 			AND rub1.id_rubrique!=' . sql_quote($exclu) . '
39 39
 			AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')',
40
-		'',
41
-		'0+rub1.titre,rub1.titre'
42
-	);
40
+        '',
41
+        '0+rub1.titre,rub1.titre'
42
+    );
43 43
 
44
-	while ($row = sql_fetch($res)) {
45
-		if (autoriser('voir', 'rubrique', $row['id_rubrique'])) {
46
-			$rub[$row['id_rubrique']]['enfants'] = $row['id_enfant'];
47
-			if ($row['id_parent'] == $id_rubrique) {
48
-				$t = trim(typo(supprimer_numero($row['titre'])));
49
-				if ($row['langue_choisie'] != 'oui') {
50
-					$t .= ' <small title="'
51
-						. traduire_nom_langue($row['lang'])
52
-						. '">[' . $row['lang'] . ']</small>';
53
-				}
54
-				$ordre[$row['id_rubrique']] = $t;
55
-			}
56
-		}
57
-	}
58
-	$next = $list[$col] ?? 0;
59
-	if ($ordre) {
60
-		$rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1));
61
-		$info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id=");
62
-		$args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event";
44
+    while ($row = sql_fetch($res)) {
45
+        if (autoriser('voir', 'rubrique', $row['id_rubrique'])) {
46
+            $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant'];
47
+            if ($row['id_parent'] == $id_rubrique) {
48
+                $t = trim(typo(supprimer_numero($row['titre'])));
49
+                if ($row['langue_choisie'] != 'oui') {
50
+                    $t .= ' <small title="'
51
+                        . traduire_nom_langue($row['lang'])
52
+                        . '">[' . $row['lang'] . ']</small>';
53
+                }
54
+                $ordre[$row['id_rubrique']] = $t;
55
+            }
56
+        }
57
+    }
58
+    $next = $list[$col] ?? 0;
59
+    if ($ordre) {
60
+        $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1));
61
+        $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id=");
62
+        $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event";
63 63
 
64
-		foreach ($ordre as $id => $titrebrut) {
65
-			$titre = supprimer_numero($titrebrut);
64
+        foreach ($ordre as $id => $titrebrut) {
65
+            $titre = supprimer_numero($titrebrut);
66 66
 
67
-			$classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur');
68
-			if (isset($rub[$id]['enfants'])) {
69
-				$classe2 = " class='rub-ouverte'";
70
-				$url = "\nhref='$rec&amp;id=$id'";
71
-			} else {
72
-				$classe2 = $url = '';
73
-				$url = "\nhref='javascript:void(0)'";
74
-			}
67
+            $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur');
68
+            if (isset($rub[$id]['enfants'])) {
69
+                $classe2 = " class='rub-ouverte'";
70
+                $url = "\nhref='$rec&amp;id=$id'";
71
+            } else {
72
+                $classe2 = $url = '';
73
+                $url = "\nhref='javascript:void(0)'";
74
+            }
75 75
 
76
-			$js_func = $do . '_selection_titre';
77
-			$click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn "
78
-				. (!is_array($list) ? ' false'
79
-					: "aff_selection_provisoire($id,$args)")
76
+            $js_func = $do . '_selection_titre';
77
+            $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn "
78
+                . (!is_array($list) ? ' false'
79
+                    : "aff_selection_provisoire($id,$args)")
80 80
 # ce lien provoque la selection (directe) de la rubrique cliquee
81 81
 # et l'affichage de son titre dans le bandeau
82
-				. "\"\nondblclick=\""
83
-				. "$js_func(this."
84
-				. 'firstChild.nodeValue,'
85
-				. $id
86
-				. ",'selection_rubrique','id_parent');"
87
-				. "\nreturn aff_selection_provisoire($id,$args);"
88
-				. '"';
82
+                . "\"\nondblclick=\""
83
+                . "$js_func(this."
84
+                . 'firstChild.nodeValue,'
85
+                . $id
86
+                . ",'selection_rubrique','id_parent');"
87
+                . "\nreturn aff_selection_provisoire($id,$args);"
88
+                . '"';
89 89
 
90
-			$ret .= "<div class='"
91
-				. (($id == $next) ? 'item on' : 'item')
92
-				. "'><div class='"
93
-				. $classe1
94
-				. "'><div$classe2><a"
95
-				. $url
96
-				. $click
97
-				. '>'
98
-				. $titre
99
-				. '</a></div></div></div>';
100
-		}
101
-	}
90
+            $ret .= "<div class='"
91
+                . (($id == $next) ? 'item on' : 'item')
92
+                . "'><div class='"
93
+                . $classe1
94
+                . "'><div$classe2><a"
95
+                . $url
96
+                . $click
97
+                . '>'
98
+                . $titre
99
+                . '</a></div></div></div>';
100
+        }
101
+    }
102 102
 
103
-	$idom2 = $idom . '_col_' . ($col + 1);
104
-	$left = ($col * 250);
103
+    $idom2 = $idom . '_col_' . ($col + 1);
104
+    $left = ($col * 250);
105 105
 
106
-	return http_img_pack(
107
-		'loader.svg',
108
-		'',
109
-		"class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': '
110
-		. ($left - 30)
111
-		. "px; top: 2px; z-index: 2;' id='img_$idom2'"
112
-	)
113
-	. "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': '
114
-	. ($left - 250)
115
-	. "px;'>"
116
-	. $ret
117
-	. "\n</div>\n<div id='$idom2'>"
118
-	. ($next
119
-		? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu)
120
-		: '')
121
-	. "\n</div>";
106
+    return http_img_pack(
107
+        'loader.svg',
108
+        '',
109
+        "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': '
110
+        . ($left - 30)
111
+        . "px; top: 2px; z-index: 2;' id='img_$idom2'"
112
+    )
113
+    . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': '
114
+    . ($left - 250)
115
+    . "px;'>"
116
+    . $ret
117
+    . "\n</div>\n<div id='$idom2'>"
118
+    . ($next
119
+        ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu)
120
+        : '')
121
+    . "\n</div>";
122 122
 }
Please login to merge, or discard this patch.
ecrire/inc/texte.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
 	foreach (['script', 'iframe'] as $tag) {
106 106
 		if (
107 107
 			stripos($t, (string) "<$tag") !== false
108
-			and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
108
+			and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER)
109 109
 		) {
110 110
 			foreach ($r as $regs) {
111 111
 				$t = str_replace(
112 112
 					$regs[0],
113
-					"<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
113
+					"<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>',
114 114
 					$t
115 115
 				);
116 116
 			}
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 	}
164 164
 
165 165
 	// echapper les tags asp/php
166
-	$t = str_replace('<' . '%', '&lt;%', $arg);
166
+	$t = str_replace('<'.'%', '&lt;%', $arg);
167 167
 
168 168
 	// echapper le php
169
-	$t = str_replace('<' . '?', '&lt;?', $t);
169
+	$t = str_replace('<'.'?', '&lt;?', $t);
170 170
 
171 171
 	// echapper le < script language=php >
172 172
 	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
@@ -188,10 +188,10 @@  discard block
 block discarded – undo
188 188
 
189 189
 	// Reinserer les echappements des modeles
190 190
 	if (defined('_PROTEGE_JS_MODELES')) {
191
-		$t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES);
191
+		$t = echappe_retour($t, 'javascript'._PROTEGE_JS_MODELES);
192 192
 	}
193 193
 	if (defined('_PROTEGE_PHP_MODELES')) {
194
-		$t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES);
194
+		$t = echappe_retour($t, 'php'._PROTEGE_PHP_MODELES);
195 195
 	}
196 196
 
197 197
 	return $dejavu[$mode_filtre][$arg] = $t;
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 define('_TYPO_PROTEGER', "!':;?~%-");
290 290
 define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8");
291 291
 
292
-define('_TYPO_BALISE', ',</?[a-z!][^<>]*[' . preg_quote(_TYPO_PROTEGER) . '][^<>]*>,imsS');
292
+define('_TYPO_BALISE', ',</?[a-z!][^<>]*['.preg_quote(_TYPO_PROTEGER).'][^<>]*>,imsS');
293 293
 
294 294
 /**
295 295
  * Corrige la typographie
Please login to merge, or discard this patch.
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/texte_mini');
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
  * @return array Tablea ('','')
34 34
  */
35 35
 function definir_raccourcis_alineas() {
36
-	return ['', ''];
36
+    return ['', ''];
37 37
 }
38 38
 
39 39
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
  * @return string
47 47
  */
48 48
 function traiter_tableau($bloc) {
49
-	return $bloc;
49
+    return $bloc;
50 50
 }
51 51
 
52 52
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
  * @return string
61 61
  */
62 62
 function traiter_listes($texte) {
63
-	return $texte;
63
+    return $texte;
64 64
 }
65 65
 
66 66
 /**
@@ -76,16 +76,16 @@  discard block
 block discarded – undo
76 76
  */
77 77
 function traiter_raccourcis($letexte) {
78 78
 
79
-	// Appeler les fonctions de pre_traitement
80
-	$letexte = pipeline('pre_propre', $letexte);
79
+    // Appeler les fonctions de pre_traitement
80
+    $letexte = pipeline('pre_propre', $letexte);
81 81
 
82
-	// APPELER ICI UN PIPELINE traiter_raccourcis ?
83
-	// $letexte = pipeline('traiter_raccourcis', $letexte);
82
+    // APPELER ICI UN PIPELINE traiter_raccourcis ?
83
+    // $letexte = pipeline('traiter_raccourcis', $letexte);
84 84
 
85
-	// Appeler les fonctions de post-traitement
86
-	$letexte = pipeline('post_propre', $letexte);
85
+    // Appeler les fonctions de post-traitement
86
+    $letexte = pipeline('post_propre', $letexte);
87 87
 
88
-	return $letexte;
88
+    return $letexte;
89 89
 }
90 90
 
91 91
 /*************************************************************************************************************************
@@ -101,22 +101,22 @@  discard block
 block discarded – undo
101 101
  * @return string
102 102
  */
103 103
 function echappe_js($t, $class = ' class = "echappe-js"') {
104
-	foreach (['script', 'iframe'] as $tag) {
105
-		if (
106
-			stripos($t, (string) "<$tag") !== false
107
-			and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
108
-		) {
109
-			foreach ($r as $regs) {
110
-				$t = str_replace(
111
-					$regs[0],
112
-					"<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
113
-					$t
114
-				);
115
-			}
116
-		}
117
-	}
118
-
119
-	return $t;
104
+    foreach (['script', 'iframe'] as $tag) {
105
+        if (
106
+            stripos($t, (string) "<$tag") !== false
107
+            and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
108
+        ) {
109
+            foreach ($r as $regs) {
110
+                $t = str_replace(
111
+                    $regs[0],
112
+                    "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
113
+                    $t
114
+                );
115
+            }
116
+        }
117
+    }
118
+
119
+    return $t;
120 120
 }
121 121
 
122 122
 
@@ -145,55 +145,55 @@  discard block
 block discarded – undo
145 145
  *     Code protégé
146 146
  **/
147 147
 function interdire_scripts($arg, $mode_filtre = null) {
148
-	// on memorise le resultat sur les arguments non triviaux
149
-	static $dejavu = [];
150
-
151
-	// Attention, si ce n'est pas une chaine, laisser intact
152
-	if (!$arg or !is_string($arg) or !strstr($arg, '<')) {
153
-		return $arg;
154
-	}
155
-
156
-	if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) {
157
-		$mode_filtre = $GLOBALS['filtrer_javascript'];
158
-	}
159
-
160
-	if (isset($dejavu[$mode_filtre][$arg])) {
161
-		return $dejavu[$mode_filtre][$arg];
162
-	}
163
-
164
-	// echapper les tags asp/php
165
-	$t = str_replace('<' . '%', '&lt;%', $arg);
166
-
167
-	// echapper le php
168
-	$t = str_replace('<' . '?', '&lt;?', $t);
169
-
170
-	// echapper le < script language=php >
171
-	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
172
-
173
-	// Pour le js, trois modes : parano (-1), prive (0), ok (1)
174
-	switch ($mode_filtre) {
175
-		case 0:
176
-			if (!_DIR_RESTREINT) {
177
-				$t = echappe_js($t);
178
-			}
179
-			break;
180
-		case -1:
181
-			$t = echappe_js($t);
182
-			break;
183
-	}
184
-
185
-	// pas de <base href /> svp !
186
-	$t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
187
-
188
-	// Reinserer les echappements des modeles
189
-	if (defined('_PROTEGE_JS_MODELES')) {
190
-		$t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES);
191
-	}
192
-	if (defined('_PROTEGE_PHP_MODELES')) {
193
-		$t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES);
194
-	}
195
-
196
-	return $dejavu[$mode_filtre][$arg] = $t;
148
+    // on memorise le resultat sur les arguments non triviaux
149
+    static $dejavu = [];
150
+
151
+    // Attention, si ce n'est pas une chaine, laisser intact
152
+    if (!$arg or !is_string($arg) or !strstr($arg, '<')) {
153
+        return $arg;
154
+    }
155
+
156
+    if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) {
157
+        $mode_filtre = $GLOBALS['filtrer_javascript'];
158
+    }
159
+
160
+    if (isset($dejavu[$mode_filtre][$arg])) {
161
+        return $dejavu[$mode_filtre][$arg];
162
+    }
163
+
164
+    // echapper les tags asp/php
165
+    $t = str_replace('<' . '%', '&lt;%', $arg);
166
+
167
+    // echapper le php
168
+    $t = str_replace('<' . '?', '&lt;?', $t);
169
+
170
+    // echapper le < script language=php >
171
+    $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
172
+
173
+    // Pour le js, trois modes : parano (-1), prive (0), ok (1)
174
+    switch ($mode_filtre) {
175
+        case 0:
176
+            if (!_DIR_RESTREINT) {
177
+                $t = echappe_js($t);
178
+            }
179
+            break;
180
+        case -1:
181
+            $t = echappe_js($t);
182
+            break;
183
+    }
184
+
185
+    // pas de <base href /> svp !
186
+    $t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
187
+
188
+    // Reinserer les echappements des modeles
189
+    if (defined('_PROTEGE_JS_MODELES')) {
190
+        $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES);
191
+    }
192
+    if (defined('_PROTEGE_PHP_MODELES')) {
193
+        $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES);
194
+    }
195
+
196
+    return $dejavu[$mode_filtre][$arg] = $t;
197 197
 }
198 198
 
199 199
 
@@ -222,66 +222,66 @@  discard block
 block discarded – undo
222 222
  *     texte transformé
223 223
  **/
224 224
 function typo($letexte, $echapper = true, $connect = null, $env = []) {
225
-	// Plus vite !
226
-	if (!$letexte) {
227
-		return $letexte;
228
-	}
229
-
230
-	// les appels directs a cette fonction depuis le php de l'espace
231
-	// prive etant historiquement ecrit sans argment $connect
232
-	// on utilise la presence de celui-ci pour distinguer les cas
233
-	// ou il faut passer interdire_script explicitement
234
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
235
-	// ne seront pas perturbes
236
-	$interdire_script = false;
237
-	if (is_null($connect)) {
238
-		$connect = '';
239
-		$interdire_script = true;
240
-		$env['espace_prive'] = test_espace_prive();
241
-	}
242
-
243
-	// Echapper les codes <html> etc
244
-	if ($echapper) {
245
-		$letexte = echappe_html($letexte, 'TYPO');
246
-	}
247
-
248
-	//
249
-	// Installer les modeles, notamment images et documents ;
250
-	//
251
-	// NOTE : propre() ne passe pas par ici mais directement par corriger_typo
252
-	// cf. inc/lien
253
-
254
-	$letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env);
255
-	if ($letexte != $mem) {
256
-		$echapper = true;
257
-	}
258
-	unset($mem);
259
-
260
-	$letexte = corriger_typo($letexte);
261
-	$letexte = echapper_faux_tags($letexte);
262
-
263
-	// reintegrer les echappements
264
-	if ($echapper) {
265
-		$letexte = echappe_retour($letexte, 'TYPO');
266
-	}
267
-
268
-	// Dans les appels directs hors squelette, securiser ici aussi
269
-	if ($interdire_script) {
270
-		$letexte = interdire_scripts($letexte);
271
-	}
272
-
273
-	// Dans l'espace prive on se mefie de tout contenu dangereux
274
-	// https://core.spip.net/issues/3371
275
-	// et aussi dans l'espace public si la globale filtrer_javascript = -1
276
-	// https://core.spip.net/issues/4166
277
-	if (
278
-		$GLOBALS['filtrer_javascript'] == -1
279
-		or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
280
-	) {
281
-		$letexte = echapper_html_suspect($letexte, [], $connect, $env);
282
-	}
283
-
284
-	return $letexte;
225
+    // Plus vite !
226
+    if (!$letexte) {
227
+        return $letexte;
228
+    }
229
+
230
+    // les appels directs a cette fonction depuis le php de l'espace
231
+    // prive etant historiquement ecrit sans argment $connect
232
+    // on utilise la presence de celui-ci pour distinguer les cas
233
+    // ou il faut passer interdire_script explicitement
234
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
235
+    // ne seront pas perturbes
236
+    $interdire_script = false;
237
+    if (is_null($connect)) {
238
+        $connect = '';
239
+        $interdire_script = true;
240
+        $env['espace_prive'] = test_espace_prive();
241
+    }
242
+
243
+    // Echapper les codes <html> etc
244
+    if ($echapper) {
245
+        $letexte = echappe_html($letexte, 'TYPO');
246
+    }
247
+
248
+    //
249
+    // Installer les modeles, notamment images et documents ;
250
+    //
251
+    // NOTE : propre() ne passe pas par ici mais directement par corriger_typo
252
+    // cf. inc/lien
253
+
254
+    $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env);
255
+    if ($letexte != $mem) {
256
+        $echapper = true;
257
+    }
258
+    unset($mem);
259
+
260
+    $letexte = corriger_typo($letexte);
261
+    $letexte = echapper_faux_tags($letexte);
262
+
263
+    // reintegrer les echappements
264
+    if ($echapper) {
265
+        $letexte = echappe_retour($letexte, 'TYPO');
266
+    }
267
+
268
+    // Dans les appels directs hors squelette, securiser ici aussi
269
+    if ($interdire_script) {
270
+        $letexte = interdire_scripts($letexte);
271
+    }
272
+
273
+    // Dans l'espace prive on se mefie de tout contenu dangereux
274
+    // https://core.spip.net/issues/3371
275
+    // et aussi dans l'espace public si la globale filtrer_javascript = -1
276
+    // https://core.spip.net/issues/4166
277
+    if (
278
+        $GLOBALS['filtrer_javascript'] == -1
279
+        or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
280
+    ) {
281
+        $letexte = echapper_html_suspect($letexte, [], $connect, $env);
282
+    }
283
+
284
+    return $letexte;
285 285
 }
286 286
 
287 287
 // Correcteur typographique
@@ -306,57 +306,57 @@  discard block
 block discarded – undo
306 306
  */
307 307
 function corriger_typo($letexte, $lang = '') {
308 308
 
309
-	// Plus vite !
310
-	if (!$letexte) {
311
-		return $letexte;
312
-	}
313
-
314
-	$letexte = pipeline('pre_typo', $letexte);
315
-
316
-	// Caracteres de controle "illegaux"
317
-	$letexte = corriger_caracteres($letexte);
318
-
319
-	// Proteger les caracteres typographiques a l'interieur des tags html
320
-	if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
321
-		foreach ($regs as $reg) {
322
-			$insert = $reg[0];
323
-			// hack: on transforme les caracteres a proteger en les remplacant
324
-			// par des caracteres "illegaux". (cf corriger_caracteres())
325
-			$insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
326
-			$letexte = str_replace($reg[0], $insert, $letexte);
327
-		}
328
-	}
329
-
330
-	// trouver les blocs idiomes et les traiter à part
331
-	$letexte = extraire_idiome($ei = $letexte, $lang, true);
332
-	$ei = ($ei !== $letexte);
333
-
334
-	// trouver les blocs multi et les traiter a part
335
-	$letexte = extraire_multi($em = $letexte, $lang, true);
336
-	$em = ($em !== $letexte);
337
-
338
-	// Charger & appliquer les fonctions de typographie
339
-	$typographie = charger_fonction(lang_typo($lang), 'typographie');
340
-	$letexte = $typographie($letexte);
341
-
342
-	// Les citations en une autre langue, s'il y a lieu
343
-	if ($em) {
344
-		$letexte = echappe_retour($letexte, 'multi');
345
-	}
346
-	if ($ei) {
347
-		$letexte = echappe_retour($letexte, 'idiome');
348
-	}
349
-
350
-	// Retablir les caracteres proteges
351
-	$letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
352
-
353
-	// pipeline
354
-	$letexte = pipeline('post_typo', $letexte);
355
-
356
-	# un message pour abs_url - on est passe en mode texte
357
-	$GLOBALS['mode_abs_url'] = 'texte';
358
-
359
-	return $letexte;
309
+    // Plus vite !
310
+    if (!$letexte) {
311
+        return $letexte;
312
+    }
313
+
314
+    $letexte = pipeline('pre_typo', $letexte);
315
+
316
+    // Caracteres de controle "illegaux"
317
+    $letexte = corriger_caracteres($letexte);
318
+
319
+    // Proteger les caracteres typographiques a l'interieur des tags html
320
+    if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
321
+        foreach ($regs as $reg) {
322
+            $insert = $reg[0];
323
+            // hack: on transforme les caracteres a proteger en les remplacant
324
+            // par des caracteres "illegaux". (cf corriger_caracteres())
325
+            $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
326
+            $letexte = str_replace($reg[0], $insert, $letexte);
327
+        }
328
+    }
329
+
330
+    // trouver les blocs idiomes et les traiter à part
331
+    $letexte = extraire_idiome($ei = $letexte, $lang, true);
332
+    $ei = ($ei !== $letexte);
333
+
334
+    // trouver les blocs multi et les traiter a part
335
+    $letexte = extraire_multi($em = $letexte, $lang, true);
336
+    $em = ($em !== $letexte);
337
+
338
+    // Charger & appliquer les fonctions de typographie
339
+    $typographie = charger_fonction(lang_typo($lang), 'typographie');
340
+    $letexte = $typographie($letexte);
341
+
342
+    // Les citations en une autre langue, s'il y a lieu
343
+    if ($em) {
344
+        $letexte = echappe_retour($letexte, 'multi');
345
+    }
346
+    if ($ei) {
347
+        $letexte = echappe_retour($letexte, 'idiome');
348
+    }
349
+
350
+    // Retablir les caracteres proteges
351
+    $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
352
+
353
+    // pipeline
354
+    $letexte = pipeline('post_typo', $letexte);
355
+
356
+    # un message pour abs_url - on est passe en mode texte
357
+    $GLOBALS['mode_abs_url'] = 'texte';
358
+
359
+    return $letexte;
360 360
 }
361 361
 
362 362
 
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
  * @return string
373 373
  */
374 374
 function paragrapher($letexte, $forcer = true) {
375
-	return $letexte;
375
+    return $letexte;
376 376
 }
377 377
 
378 378
 /**
@@ -384,11 +384,11 @@  discard block
 block discarded – undo
384 384
  * @return string texte
385 385
  **/
386 386
 function traiter_retours_chariots($letexte) {
387
-	$letexte = preg_replace(",\r\n?,S", "\n", $letexte);
388
-	$letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte);
389
-	$letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte);
387
+    $letexte = preg_replace(",\r\n?,S", "\n", $letexte);
388
+    $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte);
389
+    $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte);
390 390
 
391
-	return $letexte;
391
+    return $letexte;
392 392
 }
393 393
 
394 394
 
@@ -414,41 +414,41 @@  discard block
 block discarded – undo
414 414
  *     texte transformé
415 415
  **/
416 416
 function propre($t, $connect = null, $env = []) {
417
-	// les appels directs a cette fonction depuis le php de l'espace
418
-	// prive etant historiquement ecrits sans argment $connect
419
-	// on utilise la presence de celui-ci pour distinguer les cas
420
-	// ou il faut passer interdire_script explicitement
421
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
422
-	// ne seront pas perturbes
423
-	// FIXME: Trouver une solution pour avoir un type (string) unique sur $connect.
424
-	$interdire_script = false;
425
-	if (is_null($connect)) {
426
-		$connect = '';
427
-		$interdire_script = true;
428
-		$env['espace_prive'] = true;
429
-	}
430
-
431
-	if (!$t) {
432
-		return strval($t);
433
-	}
434
-
435
-	// Dans l'espace prive on se mefie de tout contenu dangereux
436
-	// avant echappement des balises <html>
437
-	// https://core.spip.net/issues/3371
438
-	// et aussi dans l'espace public si la globale filtrer_javascript = -1
439
-	// https://core.spip.net/issues/4166
440
-	if (
441
-		$interdire_script
442
-		or $GLOBALS['filtrer_javascript'] == -1
443
-		or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0)
444
-		or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)
445
-	) {
446
-		$t = echapper_html_suspect($t, ['strict' => false], $connect, $env);
447
-	}
448
-	$t = echappe_html($t);
449
-	$t = expanser_liens($t, $connect ?? '', $env);
450
-	$t = traiter_raccourcis($t);
451
-	$t = echappe_retour_modeles($t, $interdire_script);
452
-
453
-	return $t;
417
+    // les appels directs a cette fonction depuis le php de l'espace
418
+    // prive etant historiquement ecrits sans argment $connect
419
+    // on utilise la presence de celui-ci pour distinguer les cas
420
+    // ou il faut passer interdire_script explicitement
421
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
422
+    // ne seront pas perturbes
423
+    // FIXME: Trouver une solution pour avoir un type (string) unique sur $connect.
424
+    $interdire_script = false;
425
+    if (is_null($connect)) {
426
+        $connect = '';
427
+        $interdire_script = true;
428
+        $env['espace_prive'] = true;
429
+    }
430
+
431
+    if (!$t) {
432
+        return strval($t);
433
+    }
434
+
435
+    // Dans l'espace prive on se mefie de tout contenu dangereux
436
+    // avant echappement des balises <html>
437
+    // https://core.spip.net/issues/3371
438
+    // et aussi dans l'espace public si la globale filtrer_javascript = -1
439
+    // https://core.spip.net/issues/4166
440
+    if (
441
+        $interdire_script
442
+        or $GLOBALS['filtrer_javascript'] == -1
443
+        or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0)
444
+        or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)
445
+    ) {
446
+        $t = echapper_html_suspect($t, ['strict' => false], $connect, $env);
447
+    }
448
+    $t = echappe_html($t);
449
+    $t = expanser_liens($t, $connect ?? '', $env);
450
+    $t = traiter_raccourcis($t);
451
+    $t = echappe_retour_modeles($t, $interdire_script);
452
+
453
+    return $t;
454 454
 }
Please login to merge, or discard this patch.