Completed
Push — master ( a15233...457c22 )
by cam
01:25
created
ecrire/genie/mise_a_jour.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -26,15 +26,15 @@  discard block
 block discarded – undo
26 26
  * @return int
27 27
  */
28 28
 function genie_mise_a_jour_dist($t) {
29
-	include_spip('inc/meta');
30
-	$maj = info_maj($GLOBALS['spip_version_branche']);
31
-	ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche'] . "|$maj") : '', 'non');
29
+    include_spip('inc/meta');
30
+    $maj = info_maj($GLOBALS['spip_version_branche']);
31
+    ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche'] . "|$maj") : '', 'non');
32 32
 
33
-	mise_a_jour_ecran_securite();
33
+    mise_a_jour_ecran_securite();
34 34
 
35
-	spip_log('Verification version SPIP : ' . ($maj ?: 'version a jour'), 'verifie_maj');
35
+    spip_log('Verification version SPIP : ' . ($maj ?: 'version a jour'), 'verifie_maj');
36 36
 
37
-	return 1;
37
+    return 1;
38 38
 }
39 39
 
40 40
 // TODO : fournir une URL sur spip.net pour maitriser la diffusion d'une nouvelle version de l'ecran via l'update auto
@@ -51,46 +51,46 @@  discard block
 block discarded – undo
51 51
  * ou de ne repondre une 304 que si le md5 est bon
52 52
  */
53 53
 function mise_a_jour_ecran_securite() {
54
-	// TODO : url https avec verification du certificat
55
-	return;
56
-
57
-	// si l'ecran n'est pas deja present ou pas updatable, sortir
58
-	if (
59
-		!_URL_ECRAN_SECURITE
60
-		or !file_exists($filename = _DIR_ETC . 'ecran_securite.php')
61
-		or !is_writable($filename)
62
-		or !$last_modified = filemtime($filename)
63
-		or !$md5 = md5_file($filename)
64
-	) {
65
-		return false;
66
-	}
67
-
68
-	include_spip('inc/distant');
69
-	$tmp_file = _DIR_TMP . 'ecran_securite.php';
70
-	$url = parametre_url(_URL_ECRAN_SECURITE, 'md5', $md5);
71
-	$url = parametre_url($url, 'vspip', $GLOBALS['spip_version_branche']);
72
-	$res = recuperer_url($url, [
73
-		'if_modified_since' => $last_modified,
74
-		'file' => $tmp_file
75
-	]);
76
-
77
-	// si il y a une version plus recente que l'on a recu correctement
78
-	if (
79
-		$res['status'] == 200
80
-		and $res['length']
81
-		and $tmp_file = $res['file']
82
-	) {
83
-		if ($md5 !== md5_file($tmp_file)) {
84
-			// on essaye de l'inclure pour verifier que ca ne fait pas erreur fatale
85
-			include_once $tmp_file;
86
-			// ok, on le copie a la place de l'ecran existant
87
-			// en backupant l'ecran avant, au cas ou
88
-			@copy($filename, $filename . '-bck-' . date('Y-m-d-His', $last_modified));
89
-			@rename($tmp_file, $filename);
90
-		} else {
91
-			@unlink($tmp_file);
92
-		}
93
-	}
54
+    // TODO : url https avec verification du certificat
55
+    return;
56
+
57
+    // si l'ecran n'est pas deja present ou pas updatable, sortir
58
+    if (
59
+        !_URL_ECRAN_SECURITE
60
+        or !file_exists($filename = _DIR_ETC . 'ecran_securite.php')
61
+        or !is_writable($filename)
62
+        or !$last_modified = filemtime($filename)
63
+        or !$md5 = md5_file($filename)
64
+    ) {
65
+        return false;
66
+    }
67
+
68
+    include_spip('inc/distant');
69
+    $tmp_file = _DIR_TMP . 'ecran_securite.php';
70
+    $url = parametre_url(_URL_ECRAN_SECURITE, 'md5', $md5);
71
+    $url = parametre_url($url, 'vspip', $GLOBALS['spip_version_branche']);
72
+    $res = recuperer_url($url, [
73
+        'if_modified_since' => $last_modified,
74
+        'file' => $tmp_file
75
+    ]);
76
+
77
+    // si il y a une version plus recente que l'on a recu correctement
78
+    if (
79
+        $res['status'] == 200
80
+        and $res['length']
81
+        and $tmp_file = $res['file']
82
+    ) {
83
+        if ($md5 !== md5_file($tmp_file)) {
84
+            // on essaye de l'inclure pour verifier que ca ne fait pas erreur fatale
85
+            include_once $tmp_file;
86
+            // ok, on le copie a la place de l'ecran existant
87
+            // en backupant l'ecran avant, au cas ou
88
+            @copy($filename, $filename . '-bck-' . date('Y-m-d-His', $last_modified));
89
+            @rename($tmp_file, $filename);
90
+        } else {
91
+            @unlink($tmp_file);
92
+        }
93
+    }
94 94
 }
95 95
 
96 96
 /**
@@ -106,28 +106,28 @@  discard block
 block discarded – undo
106 106
  * @return string
107 107
  */
108 108
 function info_maj(string $version): string {
109
-	include_spip('inc/plugin');
110
-
111
-	// API V1
112
-	$contenu = info_maj_cache();
113
-	if (!$contenu) {
114
-		return '';
115
-	}
116
-
117
-	$maj = info_maj_versions($version, array_keys($contenu['versions'] ?? []));
118
-	if (!$maj['mineure'] and !$maj['majeure']) {
119
-		return '';
120
-	}
121
-
122
-	$message = [];
123
-	if ($maj['mineure']) {
124
-		$message[] = _T('nouvelle_version_spip', ['version' => $maj['mineure']]);
125
-	}
126
-	if ($maj['majeure']) {
127
-		$message[] = _T('nouvelle_version_spip_majeure', ['version' => $maj['majeure']]);
128
-	}
129
-
130
-	return '<a class="info_maj_spip" href="https://www.spip.net/fr_update" title="' . $maj['mineure'] . '">' . implode(' | ', $message) . '</a>';
109
+    include_spip('inc/plugin');
110
+
111
+    // API V1
112
+    $contenu = info_maj_cache();
113
+    if (!$contenu) {
114
+        return '';
115
+    }
116
+
117
+    $maj = info_maj_versions($version, array_keys($contenu['versions'] ?? []));
118
+    if (!$maj['mineure'] and !$maj['majeure']) {
119
+        return '';
120
+    }
121
+
122
+    $message = [];
123
+    if ($maj['mineure']) {
124
+        $message[] = _T('nouvelle_version_spip', ['version' => $maj['mineure']]);
125
+    }
126
+    if ($maj['majeure']) {
127
+        $message[] = _T('nouvelle_version_spip_majeure', ['version' => $maj['majeure']]);
128
+    }
129
+
130
+    return '<a class="info_maj_spip" href="https://www.spip.net/fr_update" title="' . $maj['mineure'] . '">' . implode(' | ', $message) . '</a>';
131 131
 }
132 132
 
133 133
 /**
@@ -142,34 +142,34 @@  discard block
 block discarded – undo
142 142
  * @return array|null Contenu du fichier de cache de l'info de maj de SPIP.
143 143
  */
144 144
 function info_maj_cache(): ?array {
145
-	$contenu = '';
146
-	$options = [];
147
-	$nom = _DIR_CACHE . _VERSIONS_LISTE;
148
-	if (file_exists($nom)) {
149
-		$contenu = file_get_contents($nom);
150
-		$options['if_modified_since'] = filemtime($nom);
151
-	}
152
-	include_spip('inc/distant');
153
-	$res = recuperer_url_cache(_VERSIONS_SERVEUR, $options);
154
-
155
-	// Si rien de neuf (ou inaccessible), garder l'ancienne
156
-	if ($res and $res['page']) {
157
-		$contenu = $res['page'];
158
-		ecrire_fichier($nom, $contenu);
159
-	}
160
-
161
-	if (!$contenu) {
162
-		return null;
163
-	}
164
-
165
-	try {
166
-		$json = json_decode($contenu, true, 512, JSON_THROW_ON_ERROR);
167
-	} catch (JsonException $e) {
168
-		spip_log('Failed to parse Json data : ' . $e->getMessage(), 'verifie_maj');
169
-		return null;
170
-	}
171
-
172
-	return $json;
145
+    $contenu = '';
146
+    $options = [];
147
+    $nom = _DIR_CACHE . _VERSIONS_LISTE;
148
+    if (file_exists($nom)) {
149
+        $contenu = file_get_contents($nom);
150
+        $options['if_modified_since'] = filemtime($nom);
151
+    }
152
+    include_spip('inc/distant');
153
+    $res = recuperer_url_cache(_VERSIONS_SERVEUR, $options);
154
+
155
+    // Si rien de neuf (ou inaccessible), garder l'ancienne
156
+    if ($res and $res['page']) {
157
+        $contenu = $res['page'];
158
+        ecrire_fichier($nom, $contenu);
159
+    }
160
+
161
+    if (!$contenu) {
162
+        return null;
163
+    }
164
+
165
+    try {
166
+        $json = json_decode($contenu, true, 512, JSON_THROW_ON_ERROR);
167
+    } catch (JsonException $e) {
168
+        spip_log('Failed to parse Json data : ' . $e->getMessage(), 'verifie_maj');
169
+        return null;
170
+    }
171
+
172
+    return $json;
173 173
 }
174 174
 
175 175
 /**
@@ -184,40 +184,40 @@  discard block
 block discarded – undo
184 184
  * @return array<string, string> Version mineure supérieure, version majeure supérieure
185 185
  */
186 186
 function info_maj_versions(string $version, array $versions): array {
187
-	$maj = ['mineure' => '', 'majeure' => ''];
188
-	if (!$version) {
189
-		return $maj;
190
-	}
191
-
192
-	// pas de version dev
193
-	$versions = array_diff($versions, ['dev']);
194
-
195
-	// branche en cours d'utilisation
196
-	$branche = implode('.', array_slice(explode('.', $version, 3), 0, 2));
197
-
198
-	foreach ($versions as $v) {
199
-		[$maj2, $min2, $rev2] = explode('.', $v);
200
-		$branche_maj = $maj2 . '.' . $min2;
201
-		$version_maj = $maj2 . '.' . $min2 . '.' . $rev2;
202
-		$is_version_stable = is_numeric($rev2);
203
-		// d'abord les mises à jour de la même branche (version mineure)
204
-		if (
205
-			spip_version_compare($version, $version_maj, '<')
206
-			and spip_version_compare($maj['mineure'], $version_maj, '<')
207
-			and spip_version_compare($branche, $branche_maj, '=')
208
-		) {
209
-			$maj['mineure'] = $version_maj;
210
-		}
211
-		// puis les mises à jours majeures
212
-		if (
213
-			$is_version_stable
214
-			and spip_version_compare($version, $version_maj, '<')
215
-			and spip_version_compare($maj['majeure'], $version_maj, '<')
216
-			and spip_version_compare($branche, $branche_maj, '<')
217
-		) {
218
-			$maj['majeure'] = $version_maj;
219
-		}
220
-	}
221
-
222
-	return $maj;
187
+    $maj = ['mineure' => '', 'majeure' => ''];
188
+    if (!$version) {
189
+        return $maj;
190
+    }
191
+
192
+    // pas de version dev
193
+    $versions = array_diff($versions, ['dev']);
194
+
195
+    // branche en cours d'utilisation
196
+    $branche = implode('.', array_slice(explode('.', $version, 3), 0, 2));
197
+
198
+    foreach ($versions as $v) {
199
+        [$maj2, $min2, $rev2] = explode('.', $v);
200
+        $branche_maj = $maj2 . '.' . $min2;
201
+        $version_maj = $maj2 . '.' . $min2 . '.' . $rev2;
202
+        $is_version_stable = is_numeric($rev2);
203
+        // d'abord les mises à jour de la même branche (version mineure)
204
+        if (
205
+            spip_version_compare($version, $version_maj, '<')
206
+            and spip_version_compare($maj['mineure'], $version_maj, '<')
207
+            and spip_version_compare($branche, $branche_maj, '=')
208
+        ) {
209
+            $maj['mineure'] = $version_maj;
210
+        }
211
+        // puis les mises à jours majeures
212
+        if (
213
+            $is_version_stable
214
+            and spip_version_compare($version, $version_maj, '<')
215
+            and spip_version_compare($maj['majeure'], $version_maj, '<')
216
+            and spip_version_compare($branche, $branche_maj, '<')
217
+        ) {
218
+            $maj['majeure'] = $version_maj;
219
+        }
220
+    }
221
+
222
+    return $maj;
223 223
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
 function genie_mise_a_jour_dist($t) {
29 29
 	include_spip('inc/meta');
30 30
 	$maj = info_maj($GLOBALS['spip_version_branche']);
31
-	ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche'] . "|$maj") : '', 'non');
31
+	ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche']."|$maj") : '', 'non');
32 32
 
33 33
 	mise_a_jour_ecran_securite();
34 34
 
35
-	spip_log('Verification version SPIP : ' . ($maj ?: 'version a jour'), 'verifie_maj');
35
+	spip_log('Verification version SPIP : '.($maj ?: 'version a jour'), 'verifie_maj');
36 36
 
37 37
 	return 1;
38 38
 }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	// si l'ecran n'est pas deja present ou pas updatable, sortir
58 58
 	if (
59 59
 		!_URL_ECRAN_SECURITE
60
-		or !file_exists($filename = _DIR_ETC . 'ecran_securite.php')
60
+		or !file_exists($filename = _DIR_ETC.'ecran_securite.php')
61 61
 		or !is_writable($filename)
62 62
 		or !$last_modified = filemtime($filename)
63 63
 		or !$md5 = md5_file($filename)
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	}
67 67
 
68 68
 	include_spip('inc/distant');
69
-	$tmp_file = _DIR_TMP . 'ecran_securite.php';
69
+	$tmp_file = _DIR_TMP.'ecran_securite.php';
70 70
 	$url = parametre_url(_URL_ECRAN_SECURITE, 'md5', $md5);
71 71
 	$url = parametre_url($url, 'vspip', $GLOBALS['spip_version_branche']);
72 72
 	$res = recuperer_url($url, [
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 			include_once $tmp_file;
86 86
 			// ok, on le copie a la place de l'ecran existant
87 87
 			// en backupant l'ecran avant, au cas ou
88
-			@copy($filename, $filename . '-bck-' . date('Y-m-d-His', $last_modified));
88
+			@copy($filename, $filename.'-bck-'.date('Y-m-d-His', $last_modified));
89 89
 			@rename($tmp_file, $filename);
90 90
 		} else {
91 91
 			@unlink($tmp_file);
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		$message[] = _T('nouvelle_version_spip_majeure', ['version' => $maj['majeure']]);
128 128
 	}
129 129
 
130
-	return '<a class="info_maj_spip" href="https://www.spip.net/fr_update" title="' . $maj['mineure'] . '">' . implode(' | ', $message) . '</a>';
130
+	return '<a class="info_maj_spip" href="https://www.spip.net/fr_update" title="'.$maj['mineure'].'">'.implode(' | ', $message).'</a>';
131 131
 }
132 132
 
133 133
 /**
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 function info_maj_cache(): ?array {
145 145
 	$contenu = '';
146 146
 	$options = [];
147
-	$nom = _DIR_CACHE . _VERSIONS_LISTE;
147
+	$nom = _DIR_CACHE._VERSIONS_LISTE;
148 148
 	if (file_exists($nom)) {
149 149
 		$contenu = file_get_contents($nom);
150 150
 		$options['if_modified_since'] = filemtime($nom);
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	try {
166 166
 		$json = json_decode($contenu, true, 512, JSON_THROW_ON_ERROR);
167 167
 	} catch (JsonException $e) {
168
-		spip_log('Failed to parse Json data : ' . $e->getMessage(), 'verifie_maj');
168
+		spip_log('Failed to parse Json data : '.$e->getMessage(), 'verifie_maj');
169 169
 		return null;
170 170
 	}
171 171
 
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 
198 198
 	foreach ($versions as $v) {
199 199
 		[$maj2, $min2, $rev2] = explode('.', $v);
200
-		$branche_maj = $maj2 . '.' . $min2;
201
-		$version_maj = $maj2 . '.' . $min2 . '.' . $rev2;
200
+		$branche_maj = $maj2.'.'.$min2;
201
+		$version_maj = $maj2.'.'.$min2.'.'.$rev2;
202 202
 		$is_version_stable = is_numeric($rev2);
203 203
 		// d'abord les mises à jour de la même branche (version mineure)
204 204
 		if (
Please login to merge, or discard this patch.