Completed
Push — master ( 68a7da...1066bb )
by cam
01:22
created
ecrire/genie/mise_a_jour.php 1 patch
Indentation   +104 added lines, -104 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,53 +106,53 @@  discard block
 block discarded – undo
106 106
  * @return string
107 107
  */
108 108
 function info_maj($version) {
109
-	include_spip('inc/plugin');
110
-
111
-	$nom = _DIR_CACHE . _VERSIONS_LISTE;
112
-	$contenu = !file_exists($nom) ? '' : file_get_contents($nom);
113
-	$contenu = info_maj_cache($nom, $contenu);
114
-	try {
115
-		$contenu = json_decode($contenu, true, 512, JSON_THROW_ON_ERROR);
116
-	} catch (JsonException $e) {
117
-		spip_log('Failed to parse Json data : ' . $e->getMessage(), 'verifie_maj');
118
-		return '';
119
-	}
120
-
121
-	$liste = $liste_majeure = '';
122
-
123
-	// branche en cours d'utilisation
124
-	$branche = implode('.', array_slice(explode('.', $version, 3), 0, 2));
125
-
126
-	foreach ($contenu['versions'] as $v => $path) {
127
-		$v = explode('.', $v);
128
-		[$maj2, $min2, $rev2] = $v;
129
-		$branche_maj = $maj2 . '.' . $min2;
130
-		$version_maj = $maj2 . '.' . $min2 . '.' . $rev2;
131
-		// d'abord les mises à jour de la même branche
132
-		if (
133
-			(spip_version_compare($version, $version_maj, '<'))
134
-			and (spip_version_compare($liste, $version_maj, '<'))
135
-			and spip_version_compare($branche, $branche_maj, '=')
136
-		) {
137
-			$liste = $version_maj;
138
-		}
139
-		// puis les mises à jours majeures
140
-		if (
141
-			(spip_version_compare($version, $version_maj, '<'))
142
-			and (spip_version_compare($liste, $version_maj, '<'))
143
-			and spip_version_compare($branche, $branche_maj, '<')
144
-		) {
145
-			$liste_majeure = $version_maj;
146
-		}
147
-	}
148
-	if (!$liste and !$liste_majeure) {
149
-		return '';
150
-	}
151
-
152
-	$message = $liste ? _T('nouvelle_version_spip', ['version' => $liste]) . ($liste_majeure ? ' | ' : '') : '';
153
-	$message .= $liste_majeure ? _T('nouvelle_version_spip_majeure', ['version' => $liste_majeure]) : '';
154
-
155
-	return "<a class='info_maj_spip' href='https://www.spip.net/fr_update' title='$liste'>" . $message . '</a>';
109
+    include_spip('inc/plugin');
110
+
111
+    $nom = _DIR_CACHE . _VERSIONS_LISTE;
112
+    $contenu = !file_exists($nom) ? '' : file_get_contents($nom);
113
+    $contenu = info_maj_cache($nom, $contenu);
114
+    try {
115
+        $contenu = json_decode($contenu, true, 512, JSON_THROW_ON_ERROR);
116
+    } catch (JsonException $e) {
117
+        spip_log('Failed to parse Json data : ' . $e->getMessage(), 'verifie_maj');
118
+        return '';
119
+    }
120
+
121
+    $liste = $liste_majeure = '';
122
+
123
+    // branche en cours d'utilisation
124
+    $branche = implode('.', array_slice(explode('.', $version, 3), 0, 2));
125
+
126
+    foreach ($contenu['versions'] as $v => $path) {
127
+        $v = explode('.', $v);
128
+        [$maj2, $min2, $rev2] = $v;
129
+        $branche_maj = $maj2 . '.' . $min2;
130
+        $version_maj = $maj2 . '.' . $min2 . '.' . $rev2;
131
+        // d'abord les mises à jour de la même branche
132
+        if (
133
+            (spip_version_compare($version, $version_maj, '<'))
134
+            and (spip_version_compare($liste, $version_maj, '<'))
135
+            and spip_version_compare($branche, $branche_maj, '=')
136
+        ) {
137
+            $liste = $version_maj;
138
+        }
139
+        // puis les mises à jours majeures
140
+        if (
141
+            (spip_version_compare($version, $version_maj, '<'))
142
+            and (spip_version_compare($liste, $version_maj, '<'))
143
+            and spip_version_compare($branche, $branche_maj, '<')
144
+        ) {
145
+            $liste_majeure = $version_maj;
146
+        }
147
+    }
148
+    if (!$liste and !$liste_majeure) {
149
+        return '';
150
+    }
151
+
152
+    $message = $liste ? _T('nouvelle_version_spip', ['version' => $liste]) . ($liste_majeure ? ' | ' : '') : '';
153
+    $message .= $liste_majeure ? _T('nouvelle_version_spip_majeure', ['version' => $liste_majeure]) : '';
154
+
155
+    return "<a class='info_maj_spip' href='https://www.spip.net/fr_update' title='$liste'>" . $message . '</a>';
156 156
 }
157 157
 
158 158
 /**
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
  *     Contenu du fichier de cache de l'info de maj de SPIP.
173 173
  */
174 174
 function info_maj_cache($nom, $contenu = '') {
175
-	$a = file_exists($nom) ? filemtime($nom) : '';
176
-	include_spip('inc/distant');
177
-	$res = recuperer_url_cache(_VERSIONS_SERVEUR, ['if_modified_since' => $a]);
178
-	// Si rien de neuf (ou inaccessible), garder l'ancienne
179
-	if ($res) {
180
-		$contenu = $res['page'] ?: $contenu;
181
-	}
182
-	ecrire_fichier($nom, $contenu);
183
-
184
-	return $contenu;
175
+    $a = file_exists($nom) ? filemtime($nom) : '';
176
+    include_spip('inc/distant');
177
+    $res = recuperer_url_cache(_VERSIONS_SERVEUR, ['if_modified_since' => $a]);
178
+    // Si rien de neuf (ou inaccessible), garder l'ancienne
179
+    if ($res) {
180
+        $contenu = $res['page'] ?: $contenu;
181
+    }
182
+    ecrire_fichier($nom, $contenu);
183
+
184
+    return $contenu;
185 185
 }
Please login to merge, or discard this patch.