Completed
Push — master ( 5b53e6...916bf1 )
by cam
01:08
created
ecrire/exec/admin_plugin.php 1 patch
Indentation   +203 added lines, -203 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('inc/config');
@@ -37,26 +37,26 @@  discard block
 block discarded – undo
37 37
  */
38 38
 function exec_admin_plugin_dist($retour = '') {
39 39
 
40
-	if (!autoriser('configurer', '_plugins')) {
41
-		include_spip('inc/minipres');
42
-		echo minipres();
43
-	} else {
44
-		// on fait la verif du path avant tout,
45
-		// et l'installation des qu'on est dans la colonne principale
46
-		// si jamais la liste des plugins actifs change, il faut faire un refresh du hit
47
-		// pour etre sur que les bons fichiers seront charges lors de l'install
48
-		$new = actualise_plugins_actifs();
49
-		if ($new and _request('actualise') < 2) {
50
-			include_spip('inc/headers');
51
-			if (isset($GLOBALS['fichier_php_compile_recent'])) {
52
-				// attendre eventuellement l'invalidation du cache opcode
53
-				spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']);
54
-			}
55
-			redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&'));
56
-		} else {
57
-			admin_plug_args(_request('voir'), _request('erreur'), _request('format'));
58
-		}
59
-	}
40
+    if (!autoriser('configurer', '_plugins')) {
41
+        include_spip('inc/minipres');
42
+        echo minipres();
43
+    } else {
44
+        // on fait la verif du path avant tout,
45
+        // et l'installation des qu'on est dans la colonne principale
46
+        // si jamais la liste des plugins actifs change, il faut faire un refresh du hit
47
+        // pour etre sur que les bons fichiers seront charges lors de l'install
48
+        $new = actualise_plugins_actifs();
49
+        if ($new and _request('actualise') < 2) {
50
+            include_spip('inc/headers');
51
+            if (isset($GLOBALS['fichier_php_compile_recent'])) {
52
+                // attendre eventuellement l'invalidation du cache opcode
53
+                spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']);
54
+            }
55
+            redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&'));
56
+        } else {
57
+            admin_plug_args(_request('voir'), _request('erreur'), _request('format'));
58
+        }
59
+    }
60 60
 }
61 61
 
62 62
 /**
@@ -81,132 +81,132 @@  discard block
 block discarded – undo
81 81
  *     Format d'affichage (liste ou arborescence)
82 82
  **/
83 83
 function admin_plug_args($quoi, $erreur, $format) {
84
-	$lpf = null;
85
-	$lcpas = null;
86
-	$lcpaffichesup = null;
87
-	if (!$quoi) {
88
-		$quoi = 'actifs';
89
-	}
90
-	// empecher l'affichage des erreurs dans le bandeau, on le donne ensuite
91
-	// format brut par plugin
92
-	$GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false);
93
-	// format resume mis en forme
94
-	$erreur_activation = plugin_donne_erreurs();
95
-	$commencer_page = charger_fonction('commencer_page', 'inc');
96
-	echo $commencer_page(_T('icone_admin_plugin'), 'configuration', 'plugin');
97
-
98
-	echo debut_gauche();
99
-	echo recuperer_fond('prive/squelettes/navigation/configurer', ['exec' => 'admin_plugin']);
100
-
101
-	echo pipeline(
102
-		'affiche_gauche',
103
-		[
104
-			'args' => ['exec' => 'admin_plugin'],
105
-			'data' => afficher_librairies()
106
-		]
107
-	);
108
-
109
-	echo debut_droite();
110
-	echo gros_titre(_T('icone_admin_plugin'), '');
111
-
112
-	// Barre d'onglets de premier niveau
113
-	echo barre_onglets('plugins', 'plugins_actifs');
114
-	// Barre d'onglets de second niveau
115
-	$onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin';
116
-	echo debut_onglet('onglets_simple second');
117
-	echo onglet(_T('plugins_tous_liste'), generer_url_ecrire('admin_plugin', 'voir=tous'), 'admin_plugin', $onglet2);
118
-	echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire('admin_plugin'), 'plugins_actifs', $onglet2);
119
-	echo fin_onglet();
120
-
121
-	// message d'erreur au retour d'une operation
122
-	if ($erreur) {
123
-		echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>';
124
-	}
125
-	if ($erreur_activation) {
126
-		echo "<div class='error'>$erreur_activation</div>";
127
-	}
128
-
129
-	// la mise a jour de cette meta a ete faite par ecrire_plugin_actifs
130
-	$actifs = (array) unserialize($GLOBALS['meta']['plugin']);
131
-	$lcpa = $actifs + (array) unserialize($GLOBALS['meta']['plugin_attente']);
132
-
133
-	// Les affichages se basent sur le repertoire, pas sur le nom
134
-	$actifs = liste_chemin_plugin($actifs, '');
135
-	if (defined('_DIR_PLUGINS_SUPPL')) {
136
-		$lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL);
137
-	}
138
-	$lcpa = liste_chemin_plugin($lcpa);
139
-
140
-	// on installe les plugins maintenant,
141
-	// cela permet aux scripts d'install de faire des affichages (moches...)
142
-	plugin_installes_meta();
143
-
144
-	echo "<div class='liste-plugins formulaire_spip'>";
145
-	echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins');
146
-
147
-	if ($quoi !== 'actifs') {
148
-		$lpf = liste_plugin_files();
149
-		if ($lpf) {
150
-			echo '<p>' . _T('texte_presente_plugin') . '</p>';
151
-		} else {
152
-			if (!@is_dir(_DIR_PLUGINS)) {
153
-				echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)])
154
-					. ' &mdash; ' . _T('plugin_info_automatique_creer') . '</p>';
155
-			}
156
-		}
157
-		$lcpaffiche = $lpf;
158
-		if (defined('_DIR_PLUGINS_SUPPL')) {
159
-			$lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL);
160
-		}
161
-	} else {
162
-		// la liste
163
-		// $quoi=='actifs'
164
-		$lcpaffiche = $lcpa;
165
-		if (defined('_DIR_PLUGINS_SUPPL')) {
166
-			$lcpaffichesup = $lcpas;
167
-		}
168
-	}
169
-
170
-	if ($quoi == 'actifs' or $lpf) {
171
-		$nb = is_countable($lcpa) ? count($lcpa) : 0;
172
-		if (defined('_DIR_PLUGINS_SUPPL')) {
173
-			$nb += is_countable($lcpas) ? count($lcpas) : 0;
174
-		}
175
-		echo '<h3>' . sinon(
176
-			singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'),
177
-			_T('plugins_actif_aucun')
178
-		) . '</h3>';
179
-	}
180
-
181
-	if (empty($format)) {
182
-		$format = 'liste';
183
-	} elseif (!in_array($format, ['liste', 'repertoires'])) {
184
-		$format = 'repertoires';
185
-	}
186
-
187
-	$afficher = charger_fonction("afficher_$format", 'plugins');
188
-	$corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs);
189
-	if (defined('_DIR_PLUGINS_SUPPL')) {
190
-		$corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL);
191
-	}
192
-
193
-	if ($corps) {
194
-		$corps .= "\n<div class='boutons' style='display:none;'>"
195
-			. "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer')
196
-			. "' />"
197
-			. '</div>';
198
-	}
199
-
200
-	echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps);
201
-
202
-	echo fin_cadre_trait_couleur();
203
-
204
-	if ($quoi == 'actifs') {
205
-		echo affiche_les_plugins_verrouilles($actifs);
206
-	}
207
-	echo '</div>';
208
-
209
-	echo http_script("
84
+    $lpf = null;
85
+    $lcpas = null;
86
+    $lcpaffichesup = null;
87
+    if (!$quoi) {
88
+        $quoi = 'actifs';
89
+    }
90
+    // empecher l'affichage des erreurs dans le bandeau, on le donne ensuite
91
+    // format brut par plugin
92
+    $GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false);
93
+    // format resume mis en forme
94
+    $erreur_activation = plugin_donne_erreurs();
95
+    $commencer_page = charger_fonction('commencer_page', 'inc');
96
+    echo $commencer_page(_T('icone_admin_plugin'), 'configuration', 'plugin');
97
+
98
+    echo debut_gauche();
99
+    echo recuperer_fond('prive/squelettes/navigation/configurer', ['exec' => 'admin_plugin']);
100
+
101
+    echo pipeline(
102
+        'affiche_gauche',
103
+        [
104
+            'args' => ['exec' => 'admin_plugin'],
105
+            'data' => afficher_librairies()
106
+        ]
107
+    );
108
+
109
+    echo debut_droite();
110
+    echo gros_titre(_T('icone_admin_plugin'), '');
111
+
112
+    // Barre d'onglets de premier niveau
113
+    echo barre_onglets('plugins', 'plugins_actifs');
114
+    // Barre d'onglets de second niveau
115
+    $onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin';
116
+    echo debut_onglet('onglets_simple second');
117
+    echo onglet(_T('plugins_tous_liste'), generer_url_ecrire('admin_plugin', 'voir=tous'), 'admin_plugin', $onglet2);
118
+    echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire('admin_plugin'), 'plugins_actifs', $onglet2);
119
+    echo fin_onglet();
120
+
121
+    // message d'erreur au retour d'une operation
122
+    if ($erreur) {
123
+        echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>';
124
+    }
125
+    if ($erreur_activation) {
126
+        echo "<div class='error'>$erreur_activation</div>";
127
+    }
128
+
129
+    // la mise a jour de cette meta a ete faite par ecrire_plugin_actifs
130
+    $actifs = (array) unserialize($GLOBALS['meta']['plugin']);
131
+    $lcpa = $actifs + (array) unserialize($GLOBALS['meta']['plugin_attente']);
132
+
133
+    // Les affichages se basent sur le repertoire, pas sur le nom
134
+    $actifs = liste_chemin_plugin($actifs, '');
135
+    if (defined('_DIR_PLUGINS_SUPPL')) {
136
+        $lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL);
137
+    }
138
+    $lcpa = liste_chemin_plugin($lcpa);
139
+
140
+    // on installe les plugins maintenant,
141
+    // cela permet aux scripts d'install de faire des affichages (moches...)
142
+    plugin_installes_meta();
143
+
144
+    echo "<div class='liste-plugins formulaire_spip'>";
145
+    echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins');
146
+
147
+    if ($quoi !== 'actifs') {
148
+        $lpf = liste_plugin_files();
149
+        if ($lpf) {
150
+            echo '<p>' . _T('texte_presente_plugin') . '</p>';
151
+        } else {
152
+            if (!@is_dir(_DIR_PLUGINS)) {
153
+                echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)])
154
+                    . ' &mdash; ' . _T('plugin_info_automatique_creer') . '</p>';
155
+            }
156
+        }
157
+        $lcpaffiche = $lpf;
158
+        if (defined('_DIR_PLUGINS_SUPPL')) {
159
+            $lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL);
160
+        }
161
+    } else {
162
+        // la liste
163
+        // $quoi=='actifs'
164
+        $lcpaffiche = $lcpa;
165
+        if (defined('_DIR_PLUGINS_SUPPL')) {
166
+            $lcpaffichesup = $lcpas;
167
+        }
168
+    }
169
+
170
+    if ($quoi == 'actifs' or $lpf) {
171
+        $nb = is_countable($lcpa) ? count($lcpa) : 0;
172
+        if (defined('_DIR_PLUGINS_SUPPL')) {
173
+            $nb += is_countable($lcpas) ? count($lcpas) : 0;
174
+        }
175
+        echo '<h3>' . sinon(
176
+            singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'),
177
+            _T('plugins_actif_aucun')
178
+        ) . '</h3>';
179
+    }
180
+
181
+    if (empty($format)) {
182
+        $format = 'liste';
183
+    } elseif (!in_array($format, ['liste', 'repertoires'])) {
184
+        $format = 'repertoires';
185
+    }
186
+
187
+    $afficher = charger_fonction("afficher_$format", 'plugins');
188
+    $corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs);
189
+    if (defined('_DIR_PLUGINS_SUPPL')) {
190
+        $corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL);
191
+    }
192
+
193
+    if ($corps) {
194
+        $corps .= "\n<div class='boutons' style='display:none;'>"
195
+            . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer')
196
+            . "' />"
197
+            . '</div>';
198
+    }
199
+
200
+    echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps);
201
+
202
+    echo fin_cadre_trait_couleur();
203
+
204
+    if ($quoi == 'actifs') {
205
+        echo affiche_les_plugins_verrouilles($actifs);
206
+    }
207
+    echo '</div>';
208
+
209
+    echo http_script("
210 210
 	jQuery(function(){
211 211
 		jQuery('.plugins li.item a[rel=info]').click(function(){
212 212
 			var li = jQuery(this).parents('li').eq(0);
@@ -232,15 +232,15 @@  discard block
 block discarded – undo
232 232
 	});
233 233
 	");
234 234
 
235
-	echo pipeline(
236
-		'affiche_milieu',
237
-		[
238
-			'args' => ['exec' => 'admin_plugin'],
239
-			'data' => ''
240
-		]
241
-	);
235
+    echo pipeline(
236
+        'affiche_milieu',
237
+        [
238
+            'args' => ['exec' => 'admin_plugin'],
239
+            'data' => ''
240
+        ]
241
+    );
242 242
 
243
-	echo fin_gauche(), fin_page();
243
+    echo fin_gauche(), fin_page();
244 244
 }
245 245
 
246 246
 /**
@@ -254,23 +254,23 @@  discard block
 block discarded – undo
254 254
  *     Code HTML
255 255
  **/
256 256
 function affiche_les_plugins_verrouilles($actifs) {
257
-	if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) {
258
-		return '';
259
-	}
260
-
261
-	$afficher = charger_fonction('afficher_liste', 'plugins');
262
-	$liste = $afficher(self(), $liste, [], $actifs, _DIR_PLUGINS_DIST);
263
-
264
-	return
265
-		"<div id='plugins_dist'>"
266
-		. debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist')
267
-		. '<p>'
268
-		. _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)])
269
-		. '<br />' . _T('plugin_info_plugins_dist_2')
270
-		. '</p>'
271
-		. $liste
272
-		. fin_cadre_trait_couleur()
273
-		. "</div>\n";
257
+    if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) {
258
+        return '';
259
+    }
260
+
261
+    $afficher = charger_fonction('afficher_liste', 'plugins');
262
+    $liste = $afficher(self(), $liste, [], $actifs, _DIR_PLUGINS_DIST);
263
+
264
+    return
265
+        "<div id='plugins_dist'>"
266
+        . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist')
267
+        . '<p>'
268
+        . _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)])
269
+        . '<br />' . _T('plugin_info_plugins_dist_2')
270
+        . '</p>'
271
+        . $liste
272
+        . fin_cadre_trait_couleur()
273
+        . "</div>\n";
274 274
 }
275 275
 
276 276
 /**
@@ -282,19 +282,19 @@  discard block
 block discarded – undo
282 282
  */
283 283
 function afficher_librairies() {
284 284
 
285
-	if (!$libs = liste_librairies()) {
286
-		return '';
287
-	}
288
-	ksort($libs);
289
-	$res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees'));
290
-	$res .= '<dl>';
291
-	foreach ($libs as $lib => $rep) {
292
-		$res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n";
293
-	}
294
-	$res .= '</dl>';
295
-	$res .= fin_cadre_enfonce();
296
-
297
-	return $res;
285
+    if (!$libs = liste_librairies()) {
286
+        return '';
287
+    }
288
+    ksort($libs);
289
+    $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees'));
290
+    $res .= '<dl>';
291
+    foreach ($libs as $lib => $rep) {
292
+        $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n";
293
+    }
294
+    $res .= '</dl>';
295
+    $res .= fin_cadre_enfonce();
296
+
297
+    return $res;
298 298
 }
299 299
 
300 300
 
@@ -305,22 +305,22 @@  discard block
 block discarded – undo
305 305
  *     Tableau (nom de la lib => repertoire , ...)
306 306
  */
307 307
 function liste_librairies() {
308
-	$libs = [];
309
-	foreach (array_reverse(creer_chemin()) as $d) {
310
-		if (
311
-			is_dir($dir = $d . 'lib/')
312
-			and $t = opendir($dir)
313
-		) {
314
-			while (($f = readdir($t)) !== false) {
315
-				if (
316
-					$f[0] != '.'
317
-					and is_dir("$dir/$f")
318
-				) {
319
-					$libs[$f] = $dir;
320
-				}
321
-			}
322
-		}
323
-	}
324
-
325
-	return $libs;
308
+    $libs = [];
309
+    foreach (array_reverse(creer_chemin()) as $d) {
310
+        if (
311
+            is_dir($dir = $d . 'lib/')
312
+            and $t = opendir($dir)
313
+        ) {
314
+            while (($f = readdir($t)) !== false) {
315
+                if (
316
+                    $f[0] != '.'
317
+                    and is_dir("$dir/$f")
318
+                ) {
319
+                    $libs[$f] = $dir;
320
+                }
321
+            }
322
+        }
323
+    }
324
+
325
+    return $libs;
326 326
 }
Please login to merge, or discard this patch.
ecrire/inc/log.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -11,109 +11,109 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) {
18
-	static $test_repertoire = [];
19
-	static $compteur = [];
20
-	static $debugverb = ''; // pour ne pas le recalculer au reappel
21
-
22
-	if (is_null($logname) or !is_string($logname)) {
23
-		$logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip';
24
-	}
25
-	if (!isset($compteur[$logname])) {
26
-		$compteur[$logname] = 0;
27
-	}
28
-	if (
29
-		$logname != 'maj'
30
-		and defined('_MAX_LOG')
31
-		and (
32
-			$compteur[$logname]++ > _MAX_LOG
33
-			or !$GLOBALS['nombre_de_logs']
34
-			or !$GLOBALS['taille_des_logs']
35
-		)
36
-	) {
37
-		return;
38
-	}
39
-
40
-	// si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies
41
-	$logfile =
42
-		($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES))
43
-		. $logname
44
-		. ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log'));
45
-
46
-	if (!isset($test_repertoire[$d = dirname($logfile)])) {
47
-		$test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
48
-		$test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire(
49
-			$d,
50
-			'',
51
-			false,
52
-			true
53
-		) : false));
54
-	}
55
-
56
-	// Si le repertoire défini n'existe pas, poser dans tmp/
57
-	if (!$test_repertoire[$d]) {
58
-		$logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
59
-	}
60
-
61
-	$rotate = 0;
62
-	$pid = '(pid ' . @getmypid() . ')';
63
-
64
-	// accepter spip_log( Array )
65
-	if (!is_string($message)) {
66
-		$message = var_export($message, true);
67
-	}
68
-
69
-	if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) {
70
-		$debug = debug_backtrace();
71
-		$l = $debug[1]['line'];
72
-		$fi = $debug[1]['file'];
73
-		if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) {
74
-			$fi = substr($fi, strlen(_ROOT_RACINE));
75
-		}
76
-		$fu = $debug[2]['function'] ?? '';
77
-		$debugverb = "$fi:L$l:$fu" . '():';
78
-	}
79
-
80
-	$m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' '
81
-		//distinguer les logs prives et publics dans les grep
82
-		. $debugverb
83
-		. (test_espace_prive() ? ':Pri:' : ':Pub:')
84
-		. preg_replace("/\n*$/", "\n", $message);
85
-
86
-
87
-	if (
88
-		@is_readable($logfile)
89
-		and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
90
-	) {
91
-		$rotate = $GLOBALS['nombre_de_logs'];
92
-		$m .= "[-- rotate --]\n";
93
-	}
94
-
95
-	$f = @fopen($logfile, 'ab');
96
-	if ($f) {
97
-		fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '&lt;', $m));
98
-		fclose($f);
99
-	}
100
-
101
-	if (
102
-		$rotate-- > 0
103
-		and function_exists('spip_unlink')
104
-	) {
105
-		spip_unlink($logfile . '.' . $rotate);
106
-		while ($rotate--) {
107
-			@rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
108
-		}
109
-	}
110
-
111
-	// Dupliquer les erreurs specifiques dans le log general
112
-	if (
113
-		defined('_FILE_LOG')
114
-		and ($logname !== _FILE_LOG)
115
-	) {
116
-		inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message);
117
-	}
118
-	$debugverb = '';
18
+    static $test_repertoire = [];
19
+    static $compteur = [];
20
+    static $debugverb = ''; // pour ne pas le recalculer au reappel
21
+
22
+    if (is_null($logname) or !is_string($logname)) {
23
+        $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip';
24
+    }
25
+    if (!isset($compteur[$logname])) {
26
+        $compteur[$logname] = 0;
27
+    }
28
+    if (
29
+        $logname != 'maj'
30
+        and defined('_MAX_LOG')
31
+        and (
32
+            $compteur[$logname]++ > _MAX_LOG
33
+            or !$GLOBALS['nombre_de_logs']
34
+            or !$GLOBALS['taille_des_logs']
35
+        )
36
+    ) {
37
+        return;
38
+    }
39
+
40
+    // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies
41
+    $logfile =
42
+        ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES))
43
+        . $logname
44
+        . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log'));
45
+
46
+    if (!isset($test_repertoire[$d = dirname($logfile)])) {
47
+        $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
48
+        $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire(
49
+            $d,
50
+            '',
51
+            false,
52
+            true
53
+        ) : false));
54
+    }
55
+
56
+    // Si le repertoire défini n'existe pas, poser dans tmp/
57
+    if (!$test_repertoire[$d]) {
58
+        $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
59
+    }
60
+
61
+    $rotate = 0;
62
+    $pid = '(pid ' . @getmypid() . ')';
63
+
64
+    // accepter spip_log( Array )
65
+    if (!is_string($message)) {
66
+        $message = var_export($message, true);
67
+    }
68
+
69
+    if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) {
70
+        $debug = debug_backtrace();
71
+        $l = $debug[1]['line'];
72
+        $fi = $debug[1]['file'];
73
+        if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) {
74
+            $fi = substr($fi, strlen(_ROOT_RACINE));
75
+        }
76
+        $fu = $debug[2]['function'] ?? '';
77
+        $debugverb = "$fi:L$l:$fu" . '():';
78
+    }
79
+
80
+    $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' '
81
+        //distinguer les logs prives et publics dans les grep
82
+        . $debugverb
83
+        . (test_espace_prive() ? ':Pri:' : ':Pub:')
84
+        . preg_replace("/\n*$/", "\n", $message);
85
+
86
+
87
+    if (
88
+        @is_readable($logfile)
89
+        and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
90
+    ) {
91
+        $rotate = $GLOBALS['nombre_de_logs'];
92
+        $m .= "[-- rotate --]\n";
93
+    }
94
+
95
+    $f = @fopen($logfile, 'ab');
96
+    if ($f) {
97
+        fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '&lt;', $m));
98
+        fclose($f);
99
+    }
100
+
101
+    if (
102
+        $rotate-- > 0
103
+        and function_exists('spip_unlink')
104
+    ) {
105
+        spip_unlink($logfile . '.' . $rotate);
106
+        while ($rotate--) {
107
+            @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
108
+        }
109
+    }
110
+
111
+    // Dupliquer les erreurs specifiques dans le log general
112
+    if (
113
+        defined('_FILE_LOG')
114
+        and ($logname !== _FILE_LOG)
115
+    ) {
116
+        inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message);
117
+    }
118
+    $debugverb = '';
119 119
 }
Please login to merge, or discard this patch.
ecrire/install/etape_ldap2.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -11,89 +11,89 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 function install_etape_ldap2_dist() {
18
-	echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"');
19
-
20
-	$adresse_ldap = _request('adresse_ldap');
21
-
22
-	$port_ldap = _request('port_ldap');
23
-
24
-	$tls_ldap = _request('tls_ldap');
25
-
26
-	$protocole_ldap = _request('protocole_ldap');
27
-
28
-	$login_ldap = _request('login_ldap');
29
-
30
-	$pass_ldap = _request('pass_ldap');
31
-
32
-	$port_ldap = intval($port_ldap);
33
-
34
-	$tls = false;
35
-
36
-	if ($tls_ldap == 'oui') {
37
-		if ($port_ldap == 636) {
38
-			$adresse_ldap = "ldaps://$adresse_ldap";
39
-		} else {
40
-			$tls = true;
41
-		}
42
-	}
43
-	else {
44
-		$tls_ldap == 'non';
45
-	}
46
-
47
-	// Verifions que l'adresse demandee est valide
48
-	$adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: '';
49
-
50
-	$ldap_link = ldap_connect($adresse_ldap, $port_ldap);
51
-	$erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')';
52
-
53
-	if ($ldap_link) {
54
-		if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) {
55
-			$protocole_ldap = 2;
56
-			ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap);
57
-		}
58
-		if ($tls === true) {
59
-			if (!ldap_start_tls($ldap_link)) {
60
-				$erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link)
61
-					. ' ' . spip_htmlspecialchars($adresse_ldap)
62
-					. ', ' . spip_htmlspecialchars($port_ldap) . ')';
63
-				$ldap_link = false;
64
-			}
65
-		}
66
-		if ($ldap_link) {
67
-			$ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap);
68
-			$erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link)
69
-				. "', '" . spip_htmlspecialchars($login_ldap)
70
-				. "', '" . spip_htmlspecialchars($pass_ldap)
71
-				. "'): " . spip_htmlspecialchars($adresse_ldap)
72
-				. ', ' . spip_htmlspecialchars($port_ldap);
73
-		}
74
-	}
75
-
76
-	if ($ldap_link) {
77
-		echo info_etape(
78
-			_T('titre_connexion_ldap'),
79
-			info_progression_etape(2, 'etape_ldap', 'install/')
80
-		),  _T('info_connexion_ldap_ok');
81
-		echo generer_form_ecrire('install', (
82
-			"\n<input type='hidden' name='etape' value='ldap3' />"
83
-			. "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />'
84
-			. "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />'
85
-			. "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />'
86
-			. "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />'
87
-			. "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />'
88
-			. "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />'
89
-			. bouton_suivant()));
90
-	} else {
91
-		echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true),
92
-			"<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>',
93
-			'<p>' . _T('avis_connexion_ldap_echec_2') .
94
-			"<br />\n" . _T('avis_connexion_ldap_echec_3') .
95
-			'<br /><br />' . $erreur . '<b> ?</b></p></div>';
96
-	}
97
-
98
-	echo install_fin_html();
18
+    echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"');
19
+
20
+    $adresse_ldap = _request('adresse_ldap');
21
+
22
+    $port_ldap = _request('port_ldap');
23
+
24
+    $tls_ldap = _request('tls_ldap');
25
+
26
+    $protocole_ldap = _request('protocole_ldap');
27
+
28
+    $login_ldap = _request('login_ldap');
29
+
30
+    $pass_ldap = _request('pass_ldap');
31
+
32
+    $port_ldap = intval($port_ldap);
33
+
34
+    $tls = false;
35
+
36
+    if ($tls_ldap == 'oui') {
37
+        if ($port_ldap == 636) {
38
+            $adresse_ldap = "ldaps://$adresse_ldap";
39
+        } else {
40
+            $tls = true;
41
+        }
42
+    }
43
+    else {
44
+        $tls_ldap == 'non';
45
+    }
46
+
47
+    // Verifions que l'adresse demandee est valide
48
+    $adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: '';
49
+
50
+    $ldap_link = ldap_connect($adresse_ldap, $port_ldap);
51
+    $erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')';
52
+
53
+    if ($ldap_link) {
54
+        if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) {
55
+            $protocole_ldap = 2;
56
+            ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap);
57
+        }
58
+        if ($tls === true) {
59
+            if (!ldap_start_tls($ldap_link)) {
60
+                $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link)
61
+                    . ' ' . spip_htmlspecialchars($adresse_ldap)
62
+                    . ', ' . spip_htmlspecialchars($port_ldap) . ')';
63
+                $ldap_link = false;
64
+            }
65
+        }
66
+        if ($ldap_link) {
67
+            $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap);
68
+            $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link)
69
+                . "', '" . spip_htmlspecialchars($login_ldap)
70
+                . "', '" . spip_htmlspecialchars($pass_ldap)
71
+                . "'): " . spip_htmlspecialchars($adresse_ldap)
72
+                . ', ' . spip_htmlspecialchars($port_ldap);
73
+        }
74
+    }
75
+
76
+    if ($ldap_link) {
77
+        echo info_etape(
78
+            _T('titre_connexion_ldap'),
79
+            info_progression_etape(2, 'etape_ldap', 'install/')
80
+        ),  _T('info_connexion_ldap_ok');
81
+        echo generer_form_ecrire('install', (
82
+            "\n<input type='hidden' name='etape' value='ldap3' />"
83
+            . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />'
84
+            . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />'
85
+            . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />'
86
+            . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />'
87
+            . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />'
88
+            . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />'
89
+            . bouton_suivant()));
90
+    } else {
91
+        echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true),
92
+            "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>',
93
+            '<p>' . _T('avis_connexion_ldap_echec_2') .
94
+            "<br />\n" . _T('avis_connexion_ldap_echec_3') .
95
+            '<br /><br />' . $erreur . '<b> ?</b></p></div>';
96
+    }
97
+
98
+    echo install_fin_html();
99 99
 }
Please login to merge, or discard this patch.
ecrire/install/etape_3.php 1 patch
Indentation   +346 added lines, -346 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/headers');
@@ -19,199 +19,199 @@  discard block
 block discarded – undo
19 19
 
20 20
 function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db) {
21 21
 
22
-	// Prefix des tables :
23
-	// S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer
24
-	// a partir de ce qui est envoye a l'installation
25
-	if (!defined('_INSTALL_TABLE_PREFIX')) {
26
-		$table_prefix = ($GLOBALS['table_prefix'] != 'spip')
27
-			? $GLOBALS['table_prefix']
28
-			: preparer_prefixe_tables(_request('tprefix'));
29
-		// S'il est vide on remet spip
30
-		if (!$table_prefix) {
31
-			$table_prefix = 'spip';
32
-		}
33
-	} else {
34
-		$table_prefix = _INSTALL_TABLE_PREFIX;
35
-	}
36
-
37
-	if (preg_match(',(.*):(.*),', $adresse_db, $r)) {
38
-		[, $adresse_db, $port] = $r;
39
-	} else {
40
-		$port = '';
41
-	}
42
-
43
-	$GLOBALS['connexions'][$server_db]
44
-		= spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db);
45
-
46
-	$GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']]
47
-		= $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']];
48
-
49
-	$fquery = sql_serveur('query', $server_db);
50
-	if ($choix_db == 'new_spip') {
51
-		$re = ',^[a-z_][a-z_0-9-]*$,i';
52
-		if (preg_match($re, $sel_db)) {
53
-			$ok = sql_create_base($sel_db, $server_db);
54
-			if (!$ok) {
55
-				$re = "Impossible de creer la base $re";
56
-				spip_log($re);
57
-				return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->";
58
-			}
59
-		} else {
60
-			$re = "Le nom de la base doit correspondre a $re";
61
-			spip_log($re);
62
-
63
-			return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->";
64
-		}
65
-	}
66
-
67
-	// on rejoue la connexion apres avoir teste si il faut lui indiquer
68
-	// un sql_mode
69
-	install_mode_appel($server_db, false);
70
-	$GLOBALS['connexions'][$server_db]
71
-		= spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db);
72
-
73
-	$GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']]
74
-		= $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']];
75
-
76
-	// Completer le tableau decrivant la connexion
77
-
78
-	$GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix;
79
-	$GLOBALS['connexions'][$server_db]['db'] = $sel_db;
80
-
81
-	$old = sql_showbase($table_prefix . '_meta', $server_db);
82
-	if ($old) {
83
-		$old = sql_fetch($old, $server_db);
84
-	}
85
-	if (!$old) {
86
-		// Si possible, demander au serveur d'envoyer les textes
87
-		// dans le codage std de SPIP,
88
-		$charset = sql_get_charset(_DEFAULT_CHARSET, $server_db);
89
-
90
-		if ($charset) {
91
-			sql_set_charset($charset['charset'], $server_db);
92
-			$GLOBALS['meta']['charset_sql_base'] =
93
-				$charset['charset'];
94
-			$GLOBALS['meta']['charset_collation_sql_base'] =
95
-				$charset['collation'];
96
-			$GLOBALS['meta']['charset_sql_connexion'] =
97
-				$charset['charset'];
98
-			$charsetbase = $charset['charset'];
99
-		} else {
100
-			spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL');
101
-			$charsetbase = 'standard';
102
-		}
103
-		spip_log("Creation des tables. Codage $charsetbase");
104
-		creer_base($server_db); // AT LAST
105
-		// memoriser avec quel charset on l'a creee
106
-
107
-		if ($charset) {
108
-			$t = [
109
-				'nom' => 'charset_sql_base',
110
-				'valeur' => $charset['charset'],
111
-				'impt' => 'non'
112
-			];
113
-			@sql_insertq('spip_meta', $t, [], $server_db);
114
-			$t['nom'] = 'charset_collation_sql_base';
115
-			$t['valeur'] = $charset['collation'];
116
-			@sql_insertq('spip_meta', $t, [], $server_db);
117
-			$t['nom'] = 'charset_sql_connexion';
118
-			$t['valeur'] = $charset['charset'];
119
-			@sql_insertq('spip_meta', $t, [], $server_db);
120
-		}
121
-		$t = [
122
-			'nom' => 'version_installee',
123
-			'valeur' => $GLOBALS['spip_version_base'],
124
-			'impt' => 'non'
125
-		];
126
-		@sql_insertq('spip_meta', $t, [], $server_db);
127
-		$t['nom'] = 'nouvelle_install';
128
-		$t['valeur'] = 1;
129
-		@sql_insertq('spip_meta', $t, [], $server_db);
130
-		// positionner la langue par defaut du site si un cookie de lang a ete mis
131
-		if (isset($_COOKIE['spip_lang_ecrire'])) {
132
-			@sql_insertq(
133
-				'spip_meta',
134
-				['nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']],
135
-				[],
136
-				$server_db
137
-			);
138
-		}
139
-	} else {
140
-		// pour recreer les tables disparues au besoin
141
-		spip_log('Table des Meta deja la. Verification des autres.');
142
-		creer_base($server_db);
143
-		$fupdateq = sql_serveur('updateq', $server_db);
144
-
145
-		$r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db);
146
-
147
-		if ($r) {
148
-			$r = sql_fetch($r, $server_db);
149
-		}
150
-		$version_installee = !$r ? 0 : (double)$r['valeur'];
151
-		if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) {
152
-			$fupdateq(
153
-				'spip_meta',
154
-				['valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'],
155
-				"nom='version_installee'",
156
-				'',
157
-				$server_db
158
-			);
159
-			spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']);
160
-		}
161
-		// eliminer la derniere operation d'admin mal terminee
162
-		// notamment la mise a jour
163
-		@$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR  nom='admin'", $server_db);
164
-	}
165
-
166
-	// recuperer le charset de la connexion dans les meta
167
-	$charset = '';
168
-	$r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db);
169
-	if ($r) {
170
-		$r = sql_fetch($r, $server_db);
171
-	}
172
-	if ($r) {
173
-		$charset = $r['valeur'];
174
-	}
175
-
176
-	$ligne_rappel = install_mode_appel($server_db);
177
-
178
-	$result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db);
179
-	if (!$result_ok) {
180
-		return "<!--\nvielle = $old rappel= $ligne_rappel\n-->";
181
-	}
182
-
183
-	if ($chmod_db) {
184
-		install_fichier_connexion(
185
-			_FILE_CHMOD_TMP,
186
-			"if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n"
187
-		);
188
-	}
189
-
190
-	// si ce fichier existe a cette etape c'est qu'il provient
191
-	// d'une installation qui ne l'a pas cree correctement.
192
-	// Le supprimer pour que _FILE_CONNECT_TMP prime.
193
-
194
-	if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) {
195
-		spip_unlink(_FILE_CONNECT);
196
-	}
197
-
198
-	install_fichier_connexion(
199
-		_FILE_CONNECT_TMP,
200
-		$ligne_rappel
201
-		. install_connexion(
202
-			$adresse_db,
203
-			$port,
204
-			$login_db,
205
-			$pass_db,
206
-			$sel_db,
207
-			$server_db,
208
-			$table_prefix,
209
-			'',
210
-			$charset
211
-		)
212
-	);
213
-
214
-	return '';
22
+    // Prefix des tables :
23
+    // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer
24
+    // a partir de ce qui est envoye a l'installation
25
+    if (!defined('_INSTALL_TABLE_PREFIX')) {
26
+        $table_prefix = ($GLOBALS['table_prefix'] != 'spip')
27
+            ? $GLOBALS['table_prefix']
28
+            : preparer_prefixe_tables(_request('tprefix'));
29
+        // S'il est vide on remet spip
30
+        if (!$table_prefix) {
31
+            $table_prefix = 'spip';
32
+        }
33
+    } else {
34
+        $table_prefix = _INSTALL_TABLE_PREFIX;
35
+    }
36
+
37
+    if (preg_match(',(.*):(.*),', $adresse_db, $r)) {
38
+        [, $adresse_db, $port] = $r;
39
+    } else {
40
+        $port = '';
41
+    }
42
+
43
+    $GLOBALS['connexions'][$server_db]
44
+        = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db);
45
+
46
+    $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']]
47
+        = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']];
48
+
49
+    $fquery = sql_serveur('query', $server_db);
50
+    if ($choix_db == 'new_spip') {
51
+        $re = ',^[a-z_][a-z_0-9-]*$,i';
52
+        if (preg_match($re, $sel_db)) {
53
+            $ok = sql_create_base($sel_db, $server_db);
54
+            if (!$ok) {
55
+                $re = "Impossible de creer la base $re";
56
+                spip_log($re);
57
+                return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->";
58
+            }
59
+        } else {
60
+            $re = "Le nom de la base doit correspondre a $re";
61
+            spip_log($re);
62
+
63
+            return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->";
64
+        }
65
+    }
66
+
67
+    // on rejoue la connexion apres avoir teste si il faut lui indiquer
68
+    // un sql_mode
69
+    install_mode_appel($server_db, false);
70
+    $GLOBALS['connexions'][$server_db]
71
+        = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db);
72
+
73
+    $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']]
74
+        = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']];
75
+
76
+    // Completer le tableau decrivant la connexion
77
+
78
+    $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix;
79
+    $GLOBALS['connexions'][$server_db]['db'] = $sel_db;
80
+
81
+    $old = sql_showbase($table_prefix . '_meta', $server_db);
82
+    if ($old) {
83
+        $old = sql_fetch($old, $server_db);
84
+    }
85
+    if (!$old) {
86
+        // Si possible, demander au serveur d'envoyer les textes
87
+        // dans le codage std de SPIP,
88
+        $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db);
89
+
90
+        if ($charset) {
91
+            sql_set_charset($charset['charset'], $server_db);
92
+            $GLOBALS['meta']['charset_sql_base'] =
93
+                $charset['charset'];
94
+            $GLOBALS['meta']['charset_collation_sql_base'] =
95
+                $charset['collation'];
96
+            $GLOBALS['meta']['charset_sql_connexion'] =
97
+                $charset['charset'];
98
+            $charsetbase = $charset['charset'];
99
+        } else {
100
+            spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL');
101
+            $charsetbase = 'standard';
102
+        }
103
+        spip_log("Creation des tables. Codage $charsetbase");
104
+        creer_base($server_db); // AT LAST
105
+        // memoriser avec quel charset on l'a creee
106
+
107
+        if ($charset) {
108
+            $t = [
109
+                'nom' => 'charset_sql_base',
110
+                'valeur' => $charset['charset'],
111
+                'impt' => 'non'
112
+            ];
113
+            @sql_insertq('spip_meta', $t, [], $server_db);
114
+            $t['nom'] = 'charset_collation_sql_base';
115
+            $t['valeur'] = $charset['collation'];
116
+            @sql_insertq('spip_meta', $t, [], $server_db);
117
+            $t['nom'] = 'charset_sql_connexion';
118
+            $t['valeur'] = $charset['charset'];
119
+            @sql_insertq('spip_meta', $t, [], $server_db);
120
+        }
121
+        $t = [
122
+            'nom' => 'version_installee',
123
+            'valeur' => $GLOBALS['spip_version_base'],
124
+            'impt' => 'non'
125
+        ];
126
+        @sql_insertq('spip_meta', $t, [], $server_db);
127
+        $t['nom'] = 'nouvelle_install';
128
+        $t['valeur'] = 1;
129
+        @sql_insertq('spip_meta', $t, [], $server_db);
130
+        // positionner la langue par defaut du site si un cookie de lang a ete mis
131
+        if (isset($_COOKIE['spip_lang_ecrire'])) {
132
+            @sql_insertq(
133
+                'spip_meta',
134
+                ['nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']],
135
+                [],
136
+                $server_db
137
+            );
138
+        }
139
+    } else {
140
+        // pour recreer les tables disparues au besoin
141
+        spip_log('Table des Meta deja la. Verification des autres.');
142
+        creer_base($server_db);
143
+        $fupdateq = sql_serveur('updateq', $server_db);
144
+
145
+        $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db);
146
+
147
+        if ($r) {
148
+            $r = sql_fetch($r, $server_db);
149
+        }
150
+        $version_installee = !$r ? 0 : (double)$r['valeur'];
151
+        if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) {
152
+            $fupdateq(
153
+                'spip_meta',
154
+                ['valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'],
155
+                "nom='version_installee'",
156
+                '',
157
+                $server_db
158
+            );
159
+            spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']);
160
+        }
161
+        // eliminer la derniere operation d'admin mal terminee
162
+        // notamment la mise a jour
163
+        @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR  nom='admin'", $server_db);
164
+    }
165
+
166
+    // recuperer le charset de la connexion dans les meta
167
+    $charset = '';
168
+    $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db);
169
+    if ($r) {
170
+        $r = sql_fetch($r, $server_db);
171
+    }
172
+    if ($r) {
173
+        $charset = $r['valeur'];
174
+    }
175
+
176
+    $ligne_rappel = install_mode_appel($server_db);
177
+
178
+    $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db);
179
+    if (!$result_ok) {
180
+        return "<!--\nvielle = $old rappel= $ligne_rappel\n-->";
181
+    }
182
+
183
+    if ($chmod_db) {
184
+        install_fichier_connexion(
185
+            _FILE_CHMOD_TMP,
186
+            "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n"
187
+        );
188
+    }
189
+
190
+    // si ce fichier existe a cette etape c'est qu'il provient
191
+    // d'une installation qui ne l'a pas cree correctement.
192
+    // Le supprimer pour que _FILE_CONNECT_TMP prime.
193
+
194
+    if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) {
195
+        spip_unlink(_FILE_CONNECT);
196
+    }
197
+
198
+    install_fichier_connexion(
199
+        _FILE_CONNECT_TMP,
200
+        $ligne_rappel
201
+        . install_connexion(
202
+            $adresse_db,
203
+            $port,
204
+            $login_db,
205
+            $pass_db,
206
+            $sel_db,
207
+            $server_db,
208
+            $table_prefix,
209
+            '',
210
+            $charset
211
+        )
212
+    );
213
+
214
+    return '';
215 215
 }
216 216
 
217 217
 /**
@@ -226,166 +226,166 @@  discard block
 block discarded – undo
226 226
  * @return string Le préfixe corrigé
227 227
  */
228 228
 function preparer_prefixe_tables($prefixe) {
229
-	return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe))));
229
+    return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe))));
230 230
 }
231 231
 
232 232
 function install_propose_ldap() {
233
-	return generer_form_ecrire('install', (
234
-	fieldset(
235
-		_T('info_authentification_externe'),
236
-		[
237
-			'etape' => [
238
-				'label' => _T('texte_annuaire_ldap_1'),
239
-				'valeur' => 'ldap1',
240
-				'hidden' => true
241
-			]
242
-		],
243
-		bouton_suivant(_T('bouton_acces_ldap'))
244
-	)));
233
+    return generer_form_ecrire('install', (
234
+    fieldset(
235
+        _T('info_authentification_externe'),
236
+        [
237
+            'etape' => [
238
+                'label' => _T('texte_annuaire_ldap_1'),
239
+                'valeur' => 'ldap1',
240
+                'hidden' => true
241
+            ]
242
+        ],
243
+        bouton_suivant(_T('bouton_acces_ldap'))
244
+    )));
245 245
 }
246 246
 
247 247
 
248 248
 function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) {
249
-	return info_progression_etape(3, 'etape_', 'install/') .
250
-	info_etape(
251
-		_T('info_informations_personnelles'),
252
-		'<b>' . _T('texte_informations_personnelles_1') . '</b>' .
253
-		aider('install5', true) .
254
-		'<p>' .
255
-		($auteur_obligatoire ?
256
-			''
257
-			:
258
-			_T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides')
259
-		)
260
-	)
261
-	. generer_form_ecrire('install', (
262
-		"\n<input type='hidden' name='etape' value='3b' />"
263
-		. $hidden
264
-		. fieldset(
265
-			_T('info_identification_publique'),
266
-			[
267
-				'nom' => [
268
-					'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n",
269
-					'valeur' => $nom,
270
-					'required' => $auteur_obligatoire,
271
-				],
272
-				'email' => [
273
-					'label' => '<b>' . _T('entree_adresse_email') . "</b>\n",
274
-					'valeur' => $email,
275
-				]
276
-			]
277
-		)
278
-
279
-		. fieldset(
280
-			_T('entree_identifiants_connexion'),
281
-			[
282
-				'login' => [
283
-					'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T(
284
-						'info_login_trop_court_car_pluriel',
285
-						['nb' => _LOGIN_TROP_COURT]
286
-					) . "\n",
287
-					'valeur' => $login,
288
-					'required' => $auteur_obligatoire,
289
-				],
290
-				'pass' => [
291
-					'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T(
292
-						'info_passe_trop_court_car_pluriel',
293
-						['nb' => _PASS_LONGUEUR_MINI]
294
-					) . "\n",
295
-					'valeur' => $pass,
296
-					'required' => $auteur_obligatoire,
297
-				],
298
-				'pass_verif' => [
299
-					'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n",
300
-					'valeur' => $pass,
301
-					'required' => $auteur_obligatoire,
302
-				]
303
-			]
304
-		)
305
-		. bouton_suivant()));
249
+    return info_progression_etape(3, 'etape_', 'install/') .
250
+    info_etape(
251
+        _T('info_informations_personnelles'),
252
+        '<b>' . _T('texte_informations_personnelles_1') . '</b>' .
253
+        aider('install5', true) .
254
+        '<p>' .
255
+        ($auteur_obligatoire ?
256
+            ''
257
+            :
258
+            _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides')
259
+        )
260
+    )
261
+    . generer_form_ecrire('install', (
262
+        "\n<input type='hidden' name='etape' value='3b' />"
263
+        . $hidden
264
+        . fieldset(
265
+            _T('info_identification_publique'),
266
+            [
267
+                'nom' => [
268
+                    'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n",
269
+                    'valeur' => $nom,
270
+                    'required' => $auteur_obligatoire,
271
+                ],
272
+                'email' => [
273
+                    'label' => '<b>' . _T('entree_adresse_email') . "</b>\n",
274
+                    'valeur' => $email,
275
+                ]
276
+            ]
277
+        )
278
+
279
+        . fieldset(
280
+            _T('entree_identifiants_connexion'),
281
+            [
282
+                'login' => [
283
+                    'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T(
284
+                        'info_login_trop_court_car_pluriel',
285
+                        ['nb' => _LOGIN_TROP_COURT]
286
+                    ) . "\n",
287
+                    'valeur' => $login,
288
+                    'required' => $auteur_obligatoire,
289
+                ],
290
+                'pass' => [
291
+                    'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T(
292
+                        'info_passe_trop_court_car_pluriel',
293
+                        ['nb' => _PASS_LONGUEUR_MINI]
294
+                    ) . "\n",
295
+                    'valeur' => $pass,
296
+                    'required' => $auteur_obligatoire,
297
+                ],
298
+                'pass_verif' => [
299
+                    'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n",
300
+                    'valeur' => $pass,
301
+                    'required' => $auteur_obligatoire,
302
+                ]
303
+            ]
304
+        )
305
+        . bouton_suivant()));
306 306
 }
307 307
 
308 308
 function install_etape_3_dist() {
309
-	$ldap_present = _request('ldap_present');
310
-
311
-	if (!$ldap_present) {
312
-		$adresse_db = defined('_INSTALL_HOST_DB')
313
-			? _INSTALL_HOST_DB
314
-			: _request('adresse_db');
315
-
316
-		$login_db = defined('_INSTALL_USER_DB')
317
-			? _INSTALL_USER_DB
318
-			: _request('login_db');
319
-
320
-		$pass_db = defined('_INSTALL_PASS_DB')
321
-			? _INSTALL_PASS_DB
322
-			: _request('pass_db');
323
-
324
-		$server_db = defined('_INSTALL_SERVER_DB')
325
-			? _INSTALL_SERVER_DB
326
-			: _request('server_db');
327
-
328
-		$chmod_db = defined('_SPIP_CHMOD')
329
-			? _SPIP_CHMOD
330
-			: _request('chmod');
331
-
332
-		$choix_db = defined('_INSTALL_NAME_DB')
333
-			? _INSTALL_NAME_DB
334
-			: _request('choix_db');
335
-
336
-		$sel_db = ($choix_db == 'new_spip')
337
-			? _request('table_new') : $choix_db;
338
-
339
-		$res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db);
340
-
341
-		if ($res) {
342
-			$res = info_progression_etape(2, 'etape_', 'install/', true)
343
-				. "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>'
344
-				. $res
345
-				. '<p>' . _T('texte_operation_echec') . '</p>'
346
-				. '</div>';
347
-		}
348
-	} else {
349
-		$res = '';
350
-		[$adresse_db, $login_db, $pass_db, $sel_db, $server_db] = analyse_fichier_connection(_FILE_CONNECT_TMP);
351
-		$GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db);
352
-	}
353
-
354
-	if (!$res) {
355
-		if (file_exists(_FILE_CONNECT_TMP)) {
356
-			include(_FILE_CONNECT_TMP);
357
-		} else {
358
-			redirige_url_ecrire('install');
359
-		}
360
-
361
-		if (file_exists(_FILE_CHMOD_TMP)) {
362
-			include(_FILE_CHMOD_TMP);
363
-		} else {
364
-			redirige_url_ecrire('install');
365
-		}
366
-
367
-		$hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db)
368
-			. (defined('_INSTALL_NAME_DB') ? ''
369
-				: "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />');
370
-
371
-		$auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db));
372
-
373
-		$res = "<div class='success'><b>"
374
-			. _T('info_base_installee')
375
-			. '</b></div>'
376
-			. install_premier_auteur(
377
-				_request('email'),
378
-				_request('login'),
379
-				_request('nom'),
380
-				_request('pass'),
381
-				$hidden,
382
-				$auteur_obligatoire
383
-			)
384
-			. (($ldap_present or !function_exists('ldap_connect'))
385
-				? '' : install_propose_ldap());
386
-	}
387
-
388
-	echo install_debut_html();
389
-	echo $res;
390
-	echo install_fin_html();
309
+    $ldap_present = _request('ldap_present');
310
+
311
+    if (!$ldap_present) {
312
+        $adresse_db = defined('_INSTALL_HOST_DB')
313
+            ? _INSTALL_HOST_DB
314
+            : _request('adresse_db');
315
+
316
+        $login_db = defined('_INSTALL_USER_DB')
317
+            ? _INSTALL_USER_DB
318
+            : _request('login_db');
319
+
320
+        $pass_db = defined('_INSTALL_PASS_DB')
321
+            ? _INSTALL_PASS_DB
322
+            : _request('pass_db');
323
+
324
+        $server_db = defined('_INSTALL_SERVER_DB')
325
+            ? _INSTALL_SERVER_DB
326
+            : _request('server_db');
327
+
328
+        $chmod_db = defined('_SPIP_CHMOD')
329
+            ? _SPIP_CHMOD
330
+            : _request('chmod');
331
+
332
+        $choix_db = defined('_INSTALL_NAME_DB')
333
+            ? _INSTALL_NAME_DB
334
+            : _request('choix_db');
335
+
336
+        $sel_db = ($choix_db == 'new_spip')
337
+            ? _request('table_new') : $choix_db;
338
+
339
+        $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db);
340
+
341
+        if ($res) {
342
+            $res = info_progression_etape(2, 'etape_', 'install/', true)
343
+                . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>'
344
+                . $res
345
+                . '<p>' . _T('texte_operation_echec') . '</p>'
346
+                . '</div>';
347
+        }
348
+    } else {
349
+        $res = '';
350
+        [$adresse_db, $login_db, $pass_db, $sel_db, $server_db] = analyse_fichier_connection(_FILE_CONNECT_TMP);
351
+        $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db);
352
+    }
353
+
354
+    if (!$res) {
355
+        if (file_exists(_FILE_CONNECT_TMP)) {
356
+            include(_FILE_CONNECT_TMP);
357
+        } else {
358
+            redirige_url_ecrire('install');
359
+        }
360
+
361
+        if (file_exists(_FILE_CHMOD_TMP)) {
362
+            include(_FILE_CHMOD_TMP);
363
+        } else {
364
+            redirige_url_ecrire('install');
365
+        }
366
+
367
+        $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db)
368
+            . (defined('_INSTALL_NAME_DB') ? ''
369
+                : "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />');
370
+
371
+        $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db));
372
+
373
+        $res = "<div class='success'><b>"
374
+            . _T('info_base_installee')
375
+            . '</b></div>'
376
+            . install_premier_auteur(
377
+                _request('email'),
378
+                _request('login'),
379
+                _request('nom'),
380
+                _request('pass'),
381
+                $hidden,
382
+                $auteur_obligatoire
383
+            )
384
+            . (($ldap_present or !function_exists('ldap_connect'))
385
+                ? '' : install_propose_ldap());
386
+    }
387
+
388
+    echo install_debut_html();
389
+    echo $res;
390
+    echo install_fin_html();
391 391
 }
Please login to merge, or discard this patch.
ecrire/urls/page.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 defined('URLS_PAGE_EXEMPLE') || define('URLS_PAGE_EXEMPLE', 'spip.php?article12');
@@ -37,23 +37,23 @@  discard block
 block discarded – undo
37 37
  */
38 38
 function urls_page_generer_url_objet_dist(int $id, string $objet, string $args = '', string $ancre = ''): string {
39 39
 
40
-	if ($generer_url_externe = charger_fonction_url($objet, 'defaut')) {
41
-		$url = $generer_url_externe($id, $args, $ancre);
42
-		// une url === null indique "je ne traite pas cette url, appliquez le calcul standard"
43
-		// une url vide est une url vide, ne rien faire de plus
44
-		if (!is_null($url)) {
45
-			return $url;
46
-		}
47
-	}
40
+    if ($generer_url_externe = charger_fonction_url($objet, 'defaut')) {
41
+        $url = $generer_url_externe($id, $args, $ancre);
42
+        // une url === null indique "je ne traite pas cette url, appliquez le calcul standard"
43
+        // une url vide est une url vide, ne rien faire de plus
44
+        if (!is_null($url)) {
45
+            return $url;
46
+        }
47
+    }
48 48
 
49
-	$url = \_debut_urls_page . $objet . \_separateur_urls_page
50
-		. $id . \_terminaison_urls_page;
49
+    $url = \_debut_urls_page . $objet . \_separateur_urls_page
50
+        . $id . \_terminaison_urls_page;
51 51
 
52
-	if ($args) {
53
-		$args = strpos($url, '?') ? "&$args" : "?$args";
54
-	}
52
+    if ($args) {
53
+        $args = strpos($url, '?') ? "&$args" : "?$args";
54
+    }
55 55
 
56
-	return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
56
+    return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
57 57
 }
58 58
 
59 59
 /**
@@ -69,27 +69,27 @@  discard block
 block discarded – undo
69 69
  */
70 70
 function urls_page_decoder_url_dist(string $url, string $entite, array $contexte = []): array {
71 71
 
72
-	// traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23
73
-	if ($GLOBALS['profondeur_url'] > 0 and $entite == 'sommaire') {
74
-		return [[], '404'];
75
-	}
72
+    // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23
73
+    if ($GLOBALS['profondeur_url'] > 0 and $entite == 'sommaire') {
74
+        return [[], '404'];
75
+    }
76 76
 
77
-	include_spip('inc/urls');
78
-	$r = nettoyer_url_page($url, $contexte);
79
-	if ($r) {
80
-		array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici
81
-		return $r;
82
-	}
77
+    include_spip('inc/urls');
78
+    $r = nettoyer_url_page($url, $contexte);
79
+    if ($r) {
80
+        array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici
81
+        return $r;
82
+    }
83 83
 
84
-	/*
84
+    /*
85 85
 	 * Le bloc qui suit sert a faciliter les transitions depuis
86 86
 	 * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html'
87 87
 	 * Il est inutile de le recopier si vous personnalisez vos URLs
88 88
 	 * et votre .htaccess
89 89
 	 */
90
-	// Si on est revenu en mode html, mais c'est une ancienne url_propre
91
-	// on ne redirige pas, on assume le nouveau contexte (si possible)
92
-	$url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? '';
93
-	return urls_transition_retrouver_anciennes_url_propres($url_propre, $entite, $contexte);
94
-	/* Fin du bloc compatibilite url-propres */
90
+    // Si on est revenu en mode html, mais c'est une ancienne url_propre
91
+    // on ne redirige pas, on assume le nouveau contexte (si possible)
92
+    $url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? '';
93
+    return urls_transition_retrouver_anciennes_url_propres($url_propre, $entite, $contexte);
94
+    /* Fin du bloc compatibilite url-propres */
95 95
 }
Please login to merge, or discard this patch.
ecrire/inc/svg.php 1 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.
ecrire/inc/envoyer_mail.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Mail
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function nettoyer_titre_email($titre) {
35
-	return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
35
+    return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
36 36
 }
37 37
 
38 38
 /**
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function nettoyer_caracteres_mail($t) {
50 50
 
51
-	$t = filtrer_entites($t);
51
+    $t = filtrer_entites($t);
52 52
 
53
-	if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
-		$t = str_replace(
55
-			['&#8217;', '&#8220;', '&#8221;'],
56
-			["'", '"', '"'],
57
-			$t
58
-		);
59
-	}
53
+    if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
+        $t = str_replace(
55
+            ['&#8217;', '&#8220;', '&#8221;'],
56
+            ["'", '"', '"'],
57
+            $t
58
+        );
59
+    }
60 60
 
61
-	$t = str_replace(
62
-		['&mdash;', '&endash;'],
63
-		['--', '-'],
64
-		$t
65
-	);
61
+    $t = str_replace(
62
+        ['&mdash;', '&endash;'],
63
+        ['--', '-'],
64
+        $t
65
+    );
66 66
 
67
-	return $t;
67
+    return $t;
68 68
 }
69 69
 
70 70
 /**
@@ -97,87 +97,87 @@  discard block
 block discarded – undo
97 97
  */
98 98
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') {
99 99
 
100
-	if (!email_valide($destinataire)) {
101
-		return false;
102
-	}
103
-	if ($destinataire == _T('info_mail_fournisseur')) {
104
-		return false;
105
-	} // tres fort
106
-
107
-	// Fournir si possible un Message-Id: conforme au RFC1036,
108
-	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
-
110
-	$email_envoi = $GLOBALS['meta']['email_envoi'];
111
-	if (!email_valide($email_envoi)) {
112
-		spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
-		$email_envoi = $destinataire;
114
-	}
115
-
116
-	$parts = '';
117
-	if (is_array($corps)) {
118
-		$texte = $corps['texte'];
119
-		$from = ($corps['from'] ?? $from);
120
-		$headers = ($corps['headers'] ?? $headers);
121
-		if (is_array($headers)) {
122
-			$headers = implode("\n", $headers);
123
-		}
124
-		if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) {
125
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
-		}
127
-	} else {
128
-		$texte = $corps;
129
-	}
130
-
131
-	if (!$from) {
132
-		$from = $email_envoi;
133
-	}
134
-
135
-	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
-	}
139
-
140
-	// nettoyer les &eacute; &#8217, &emdash; etc...
141
-	// les 'cliquer ici' etc sont a eviter;  voir:
142
-	// http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
-	$texte = nettoyer_caracteres_mail($texte);
144
-	$sujet = nettoyer_caracteres_mail($sujet);
145
-
146
-	// encoder le sujet si possible selon la RFC
147
-	if (init_mb_string()) {
148
-		# un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
-		# est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
-		$charset = $GLOBALS['meta']['charset'];
151
-		mb_internal_encoding($charset);
152
-		$sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
-		mb_internal_encoding('utf-8');
154
-	}
155
-
156
-	$headers = $headers ?? '';
157
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
158
-		$texte = wordwrap($texte);
159
-	}
160
-
161
-	[$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
162
-
163
-	if (_OS_SERVEUR == 'windows') {
164
-		$texte = preg_replace("@\r*\n@", "\r\n", $texte);
165
-		$headers = preg_replace("@\r*\n@", "\r\n", $headers);
166
-		$sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
167
-	}
168
-
169
-	spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
170
-	// mode TEST : forcer l'email
171
-	if (defined('_TEST_EMAIL_DEST')) {
172
-		if (!_TEST_EMAIL_DEST) {
173
-			return false;
174
-		} else {
175
-			$texte = "Dest : $destinataire\r\n" . $texte;
176
-			$destinataire = _TEST_EMAIL_DEST;
177
-		}
178
-	}
179
-
180
-	return @mail($destinataire, $sujet, $texte, $headers);
100
+    if (!email_valide($destinataire)) {
101
+        return false;
102
+    }
103
+    if ($destinataire == _T('info_mail_fournisseur')) {
104
+        return false;
105
+    } // tres fort
106
+
107
+    // Fournir si possible un Message-Id: conforme au RFC1036,
108
+    // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
+
110
+    $email_envoi = $GLOBALS['meta']['email_envoi'];
111
+    if (!email_valide($email_envoi)) {
112
+        spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
+        $email_envoi = $destinataire;
114
+    }
115
+
116
+    $parts = '';
117
+    if (is_array($corps)) {
118
+        $texte = $corps['texte'];
119
+        $from = ($corps['from'] ?? $from);
120
+        $headers = ($corps['headers'] ?? $headers);
121
+        if (is_array($headers)) {
122
+            $headers = implode("\n", $headers);
123
+        }
124
+        if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) {
125
+            $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
+        }
127
+    } else {
128
+        $texte = $corps;
129
+    }
130
+
131
+    if (!$from) {
132
+        $from = $email_envoi;
133
+    }
134
+
135
+    // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
+    if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
+        $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
+    }
139
+
140
+    // nettoyer les &eacute; &#8217, &emdash; etc...
141
+    // les 'cliquer ici' etc sont a eviter;  voir:
142
+    // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
+    $texte = nettoyer_caracteres_mail($texte);
144
+    $sujet = nettoyer_caracteres_mail($sujet);
145
+
146
+    // encoder le sujet si possible selon la RFC
147
+    if (init_mb_string()) {
148
+        # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
+        # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
+        $charset = $GLOBALS['meta']['charset'];
151
+        mb_internal_encoding($charset);
152
+        $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
+        mb_internal_encoding('utf-8');
154
+    }
155
+
156
+    $headers = $headers ?? '';
157
+    if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
158
+        $texte = wordwrap($texte);
159
+    }
160
+
161
+    [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
162
+
163
+    if (_OS_SERVEUR == 'windows') {
164
+        $texte = preg_replace("@\r*\n@", "\r\n", $texte);
165
+        $headers = preg_replace("@\r*\n@", "\r\n", $headers);
166
+        $sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
167
+    }
168
+
169
+    spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
170
+    // mode TEST : forcer l'email
171
+    if (defined('_TEST_EMAIL_DEST')) {
172
+        if (!_TEST_EMAIL_DEST) {
173
+            return false;
174
+        } else {
175
+            $texte = "Dest : $destinataire\r\n" . $texte;
176
+            $destinataire = _TEST_EMAIL_DEST;
177
+        }
178
+    }
179
+
180
+    return @mail($destinataire, $sujet, $texte, $headers);
181 181
 }
182 182
 
183 183
 /**
@@ -191,58 +191,58 @@  discard block
 block discarded – undo
191 191
  * @return array
192 192
  */
193 193
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
194
-	$charset = $GLOBALS['meta']['charset'];
195
-
196
-	// Ajouter le Content-Type et consort s'il n'y est pas deja
197
-	if (strpos($headers, 'Content-Type: ') === false) {
198
-		$type =
199
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
200
-			"Content-Transfer-Encoding: 8bit\n";
201
-	} else {
202
-		$type = '';
203
-	}
204
-
205
-	// calculer un identifiant unique
206
-	// Marie Toto <[email protected]> => @toto.com
207
-	if (preg_match('/@[^\s>]+/', $from, $domain)) {
208
-		$domain = $domain[0];
209
-	}
210
-	else {
211
-		$domain = '@unknown-' . md5($from) . '.org';
212
-	}
213
-	$uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
214
-
215
-	// Si multi-part, s'en servir comme borne ...
216
-	if ($parts) {
217
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
218
-		foreach ($parts as $part) {
219
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
220
-			$e = join("\n", $part[0]);
221
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
222
-		}
223
-		$texte .= "\n\n--$uniq--\n";
224
-		// Si boundary n'est pas entre guillemets,
225
-		// elle est comprise mais le charset est ignoree !
226
-		$type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
227
-	}
228
-
229
-	// .. et s'en servir pour plaire a SpamAssassin
230
-
231
-	$mid = 'Message-Id: <' . $uniq . '>';
232
-
233
-	// indispensable pour les sites qui collent d'office From: serveur-http
234
-	// sauf si deja mis par l'envoyeur
235
-	$rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
236
-
237
-	// Nettoyer les en-tetes envoyees
238
-	// Ajouter le \n final
239
-	if (strlen($headers = trim($headers))) {
240
-		$headers .= "\n";
241
-	}
242
-
243
-	// Et mentionner l'indeboulonable nomenclature ratee
244
-
245
-	$headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
246
-
247
-	return [$headers, $texte];
194
+    $charset = $GLOBALS['meta']['charset'];
195
+
196
+    // Ajouter le Content-Type et consort s'il n'y est pas deja
197
+    if (strpos($headers, 'Content-Type: ') === false) {
198
+        $type =
199
+            "Content-Type: text/plain;charset=\"$charset\";\n" .
200
+            "Content-Transfer-Encoding: 8bit\n";
201
+    } else {
202
+        $type = '';
203
+    }
204
+
205
+    // calculer un identifiant unique
206
+    // Marie Toto <[email protected]> => @toto.com
207
+    if (preg_match('/@[^\s>]+/', $from, $domain)) {
208
+        $domain = $domain[0];
209
+    }
210
+    else {
211
+        $domain = '@unknown-' . md5($from) . '.org';
212
+    }
213
+    $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
214
+
215
+    // Si multi-part, s'en servir comme borne ...
216
+    if ($parts) {
217
+        $texte = "--$uniq\n$type\n" . $texte . "\n";
218
+        foreach ($parts as $part) {
219
+            $n = strlen($part[1]) . ($part[0] ? "\n" : '');
220
+            $e = join("\n", $part[0]);
221
+            $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
222
+        }
223
+        $texte .= "\n\n--$uniq--\n";
224
+        // Si boundary n'est pas entre guillemets,
225
+        // elle est comprise mais le charset est ignoree !
226
+        $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
227
+    }
228
+
229
+    // .. et s'en servir pour plaire a SpamAssassin
230
+
231
+    $mid = 'Message-Id: <' . $uniq . '>';
232
+
233
+    // indispensable pour les sites qui collent d'office From: serveur-http
234
+    // sauf si deja mis par l'envoyeur
235
+    $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
236
+
237
+    // Nettoyer les en-tetes envoyees
238
+    // Ajouter le \n final
239
+    if (strlen($headers = trim($headers))) {
240
+        $headers .= "\n";
241
+    }
242
+
243
+    // Et mentionner l'indeboulonable nomenclature ratee
244
+
245
+    $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
246
+
247
+    return [$headers, $texte];
248 248
 }
Please login to merge, or discard this patch.
ecrire/src/Chiffrer/Chiffrement.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -19,78 +19,78 @@
 block discarded – undo
19 19
  * @link https://www.php.net/manual/fr/book.sodium.php
20 20
  */
21 21
 class Chiffrement {
22
-	/** Chiffre un message en utilisant une clé ou un mot de passe */
23
-	public static function chiffrer(
24
-		string $message,
25
-		#[\SensitiveParameter]
26
-		string $key
27
-	): ?string {
28
-		// create a random salt for key derivation
29
-		$salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES);
30
-		$key = self::deriveKeyFromPassword($key, $salt);
31
-		$nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
32
-		$padded_message = sodium_pad($message, 16);
33
-		$encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key);
34
-		$encoded = base64_encode($salt . $nonce . $encrypted);
35
-		sodium_memzero($key);
36
-		sodium_memzero($nonce);
37
-		sodium_memzero($salt);
38
-		#spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG);
39
-		return $encoded;
40
-	}
22
+    /** Chiffre un message en utilisant une clé ou un mot de passe */
23
+    public static function chiffrer(
24
+        string $message,
25
+        #[\SensitiveParameter]
26
+        string $key
27
+    ): ?string {
28
+        // create a random salt for key derivation
29
+        $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES);
30
+        $key = self::deriveKeyFromPassword($key, $salt);
31
+        $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
32
+        $padded_message = sodium_pad($message, 16);
33
+        $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key);
34
+        $encoded = base64_encode($salt . $nonce . $encrypted);
35
+        sodium_memzero($key);
36
+        sodium_memzero($nonce);
37
+        sodium_memzero($salt);
38
+        #spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG);
39
+        return $encoded;
40
+    }
41 41
 
42
-	/** Déchiffre un message en utilisant une clé ou un mot de passe */
43
-	public static function dechiffrer(
44
-		string $encoded,
45
-		#[\SensitiveParameter]
46
-		string $key
47
-	): ?string {
48
-		$decoded = base64_decode($encoded);
49
-		$salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES);
50
-		$nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
51
-		$encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
52
-		$key = self::deriveKeyFromPassword($key, $salt);
53
-		$padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key);
54
-		sodium_memzero($key);
55
-		sodium_memzero($nonce);
56
-		sodium_memzero($salt);
57
-		if ($padded_message === false) {
58
-			spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG);
59
-			return null;
60
-		}
61
-		$message = sodium_unpad($padded_message, 16);
62
-		#spip_log("dechiffrer($encoded)=$message", 'chiffrer' . _LOG_DEBUG);
63
-		return $message;
64
-	}
42
+    /** Déchiffre un message en utilisant une clé ou un mot de passe */
43
+    public static function dechiffrer(
44
+        string $encoded,
45
+        #[\SensitiveParameter]
46
+        string $key
47
+    ): ?string {
48
+        $decoded = base64_decode($encoded);
49
+        $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES);
50
+        $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
51
+        $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
52
+        $key = self::deriveKeyFromPassword($key, $salt);
53
+        $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key);
54
+        sodium_memzero($key);
55
+        sodium_memzero($nonce);
56
+        sodium_memzero($salt);
57
+        if ($padded_message === false) {
58
+            spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG);
59
+            return null;
60
+        }
61
+        $message = sodium_unpad($padded_message, 16);
62
+        #spip_log("dechiffrer($encoded)=$message", 'chiffrer' . _LOG_DEBUG);
63
+        return $message;
64
+    }
65 65
 
66
-	/** Génère une clé de la taille attendue pour le chiffrement */
67
-	public static function keygen(): string {
68
-		return sodium_crypto_secretbox_keygen();
69
-	}
66
+    /** Génère une clé de la taille attendue pour le chiffrement */
67
+    public static function keygen(): string {
68
+        return sodium_crypto_secretbox_keygen();
69
+    }
70 70
 
71
-	/**
72
-	 * Retourne une clé de la taille attendue pour le chiffrement
73
-	 *
74
-	 * Notamment si on utilise un mot de passe comme clé, il faut le hacher
75
-	 * pour servir de clé à la taille correspondante.
76
-	 */
77
-	private static function deriveKeyFromPassword(
78
-		#[\SensitiveParameter]
79
-		string $password,
80
-		string $salt
81
-	): string {
82
-		if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
83
-			return $password;
84
-		}
85
-		$key = sodium_crypto_pwhash(
86
-			\SODIUM_CRYPTO_SECRETBOX_KEYBYTES,
87
-			$password,
88
-			$salt,
89
-			\SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
90
-			\SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
91
-		);
92
-		sodium_memzero($password);
71
+    /**
72
+     * Retourne une clé de la taille attendue pour le chiffrement
73
+     *
74
+     * Notamment si on utilise un mot de passe comme clé, il faut le hacher
75
+     * pour servir de clé à la taille correspondante.
76
+     */
77
+    private static function deriveKeyFromPassword(
78
+        #[\SensitiveParameter]
79
+        string $password,
80
+        string $salt
81
+    ): string {
82
+        if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
83
+            return $password;
84
+        }
85
+        $key = sodium_crypto_pwhash(
86
+            \SODIUM_CRYPTO_SECRETBOX_KEYBYTES,
87
+            $password,
88
+            $salt,
89
+            \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
90
+            \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
91
+        );
92
+        sodium_memzero($password);
93 93
 
94
-		return $key;
95
-	}
94
+        return $key;
95
+    }
96 96
 }
Please login to merge, or discard this patch.
ecrire/src/Chiffrer/Cles.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -14,48 +14,48 @@
 block discarded – undo
14 14
 
15 15
 /** Conteneur de clés (chiffrement, authentification) */
16 16
 class Cles implements \Countable /* , ContainerInterface */ {
17
-	private array $keys;
18
-	public function __construct(array $keys) {
19
-		$this->keys = $keys;
20
-	}
21
-
22
-	public function has(string $name): bool {
23
-		return array_key_exists($name, $this->keys);
24
-	}
25
-
26
-	public function get(string $name): ?string {
27
-		return $this->keys[$name] ?? null;
28
-	}
29
-
30
-	public function generate(string $name): string {
31
-		$key = Chiffrement::keygen();
32
-		$this->keys[$name] = $key;
33
-		spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE);
34
-		return $key;
35
-	}
36
-
37
-	public function set(
38
-		string $name,
39
-		#[\SensitiveParameter]
40
-		string $key
41
-	): void {
42
-		$this->keys[$name] = $key;
43
-	}
44
-
45
-	public function delete(string $name): bool {
46
-		if (isset($this->keys[$name])) {
47
-			unset($this->keys[$name]);
48
-			return true;
49
-		};
50
-		return false;
51
-	}
52
-
53
-	public function count(): int {
54
-		return count($this->keys);
55
-	}
56
-
57
-	public function toJson(): string {
58
-		$json = array_map('base64_encode', $this->keys);
59
-		return \json_encode($json);
60
-	}
17
+    private array $keys;
18
+    public function __construct(array $keys) {
19
+        $this->keys = $keys;
20
+    }
21
+
22
+    public function has(string $name): bool {
23
+        return array_key_exists($name, $this->keys);
24
+    }
25
+
26
+    public function get(string $name): ?string {
27
+        return $this->keys[$name] ?? null;
28
+    }
29
+
30
+    public function generate(string $name): string {
31
+        $key = Chiffrement::keygen();
32
+        $this->keys[$name] = $key;
33
+        spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE);
34
+        return $key;
35
+    }
36
+
37
+    public function set(
38
+        string $name,
39
+        #[\SensitiveParameter]
40
+        string $key
41
+    ): void {
42
+        $this->keys[$name] = $key;
43
+    }
44
+
45
+    public function delete(string $name): bool {
46
+        if (isset($this->keys[$name])) {
47
+            unset($this->keys[$name]);
48
+            return true;
49
+        };
50
+        return false;
51
+    }
52
+
53
+    public function count(): int {
54
+        return count($this->keys);
55
+    }
56
+
57
+    public function toJson(): string {
58
+        $json = array_map('base64_encode', $this->keys);
59
+        return \json_encode($json);
60
+    }
61 61
 }
Please login to merge, or discard this patch.