Skip to content

Commit d113fd6

Browse files
V1.2.4
1 parent 00ff2f2 commit d113fd6

File tree

10 files changed

+97
-36
lines changed

10 files changed

+97
-36
lines changed

admin/styles.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ ul,ol{
101101
list-style-position:inside
102102
}
103103
img{
104-
max-width:100%
104+
max-width:100%;
105+
height: auto;
105106
}
106107
table{
107108
width:100%;
@@ -208,11 +209,12 @@ button[type=submit].floating, [type=submit].button.floating {
208209
width: 58px;
209210
height: 58px;
210211
text-align: center;
211-
box-shadow: 0 0 30px 10px rgba(0,0,0,0.15);
212+
box-shadow: 2px 2px 3px #999;
212213
padding: 0;
213214
font-size: 25px;
214215
line-height: 25px;
215216
z-index: 998;
217+
border: none;
216218
}
217219

218220
/* UTIL */

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
## V1.2.4
8+
9+
### Changed
10+
11+
- Updates are now displayed in every admin pages
12+
- ConfigManager plugin is using cache to check only once a day a new update
13+
14+
### Fixed
15+
16+
- Files _after and _beforeChangeFiles couldnt get called
17+
- V1.2.3 Issue with blog config changes
18+
719
## V1.2.3
820

921
### Changed

common/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @package 299Ko https://github.com/299Ko/299ko
1212
*/
13-
define('VERSION', '1.2.3');
13+
define('VERSION', '1.2.4');
1414
define('COMMON', ROOT . 'common/');
1515
define('DATA', ROOT . 'data/');
1616
define('UPLOAD', ROOT . 'data/upload/');

common/util.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ public static function writeJsonFile($file, $data) {
120120
## Retourne un tableau provenant d'un fichier au format json
121121

122122
public static function readJsonFile($file, $assoc = true) {
123+
if (!file_exists($file)) {
124+
return false;
125+
}
123126
return json_decode(@file_get_contents($file), $assoc);
124127
}
125128

plugin/configmanager/admin.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616
$error = false;
1717
$passwordError = false;
1818

19-
$updaterManager = new UpdaterManager();
20-
if ($updaterManager) {
21-
$nextVersion = $updaterManager->getNextVersion();
22-
} else {
23-
$nextVersion = false;
24-
}
25-
26-
2719
switch ($action) {
2820
case 'update':
21+
$updaterManager = new UpdaterManager();
22+
if ($updaterManager) {
23+
$nextVersion = $updaterManager->getNextVersion();
24+
} else {
25+
$nextVersion = false;
26+
}
2927
if ($nextVersion && $administrator->isAuthorized()) {
3028
$updaterManager->update();
3129
show::msg("La version $nextVersion a été installée. Consultez le fichier logs.txt pour en savoir plus.", 'success');
32-
header('location:index.php?p=configmanager');
33-
die();
30+
unlink($file = DATA_PLUGIN . 'configmanager/cache.json');
31+
header('location:index.php?p=configmanager');
32+
die();
3433
}
3534
break;
3635
case 'del_install':

plugin/configmanager/configmanager.php

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,67 @@ function configmanagerInstall() {
2626
function configManagerDisplayInstallFile() {
2727
if (file_exists(ROOT . 'install.php')) {
2828
echo "<div class='msg warning'>
29-
<p>Le fichier install.php est toujours présent. Pour plus de sécurité, il est conseillé de le supprimer.<br/>
30-
Si l'installation de 299ko s'est déroulée correctement, cliquez sur le bouton ci-dessous pour le supprimer</p>
31-
<div style='text-align:center'><a class='button' href='index.php?p=configmanager&action=del_install&token=" . administrator::getToken() . "'>Supprimer le fichier install</a></div>"
32-
. "<a href='#' class='msg-button-close'><i class='fa-solid fa-xmark'></i></a></div>";
29+
<p>Le fichier install.php est toujours présent. Pour plus de sécurité, il est conseillé de le supprimer.<br/>
30+
Si l'installation de 299ko s'est déroulée correctement, cliquez sur le bouton ci-dessous pour le supprimer</p>
31+
<div style='text-align:center'><a class='button' href='index.php?p=configmanager&action=del_install&token=" . administrator::getToken() . "'>Supprimer le fichier install</a></div>"
32+
. "<a href='#' class='msg-button-close'><i class='fa-solid fa-xmark'></i></a></div>";
3333
}
3434
}
35+
36+
function configManagerCheckNewVersion() {
37+
$cachedInfos = util::readJsonFile(DATA_PLUGIN . 'configmanager/cache.json');
38+
if ($cachedInfos !== false) {
39+
// Cached infos
40+
$lastVersion = $cachedInfos['lastVersion'];
41+
if ($lastVersion === VERSION) {
42+
// No local update, check if cache is fresh
43+
$lastCheckUpdate = (int) $cachedInfos['lastCheckUpdate'];
44+
if ($lastCheckUpdate + 86400 < time()) {
45+
// Expired cache, try to retrieve new version
46+
$nextVersion = configmanagerGetNewVersion();
47+
} else {
48+
// Cache ok, actual version is the lastest
49+
$nextVersion = false;
50+
}
51+
} else {
52+
// Newer version exist in cache
53+
$nextVersion = $lastVersion;
54+
}
55+
} else {
56+
// No cache
57+
$nextVersion = configmanagerGetNewVersion();
58+
}
59+
if ($nextVersion) {
60+
configmanagerDisplayNewVersion($nextVersion);
61+
}
62+
}
63+
64+
function configmanagerDisplayNewVersion($nextVersion) {
65+
show::msg("<p>Une nouvelle version est disponible.<br/>
66+
Cliquez ci-dessous pour mettre à jour votre site en version " . $nextVersion . "</p>
67+
<p>N'oubliez pas de faire une sauvegarde de votre site avant d'effectuer cette mise à jour.</p>
68+
<p>Vous pouvez consulter le <a href='https://github.com/299Ko/299ko/blob/master/changelog.md'
69+
target='_blank'>changelog des versions de 299Ko ici</a>.</p>
70+
<div style='text-align:center'><a class='button alert' href='index.php?p=configmanager&action=update&token=" . administrator::getToken() . "'>Mettre à jour le site</a></div>");
71+
}
72+
73+
function configmanagerGetNewVersion() {
74+
$updaterManager = new UpdaterManager();
75+
if ($updaterManager) {
76+
$nextVersion = $updaterManager->getNextVersion();
77+
} else {
78+
$nextVersion = false;
79+
}
80+
$file = DATA_PLUGIN . 'configmanager/cache.json';
81+
$cachedInfos = util::readJsonFile($file);
82+
if ($cachedInfos === false) {
83+
$cachedInfos = [];
84+
}
85+
$cachedInfos['lastVersion'] = $updaterManager->lastVersion;
86+
$cachedInfos['lastCheckUpdate'] = time();
87+
util::writeJsonFile($file, $cachedInfos);
88+
if ($nextVersion) {
89+
logg('Nouvelle version trouvée : ' . $nextVersion, 'INFO');
90+
}
91+
return $nextVersion;
92+
}

plugin/configmanager/lib/UpdaterManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ protected function getRemoteFileContent($remoteFileUrl, $severity = 'INFO') {
259259
}
260260

261261
protected function runBeforeChangeFiles($nextVersion) {
262-
$remoteFile = $this->getRemoteFile('_beforeChangeFiles.php', $nextVersion);
262+
$remoteFile = self::REMOTE . 'versions/main/core/' . $nextVersion .'/_beforeChangeFiles.php';
263263
$content = $this->getRemoteFileContent($remoteFile);
264264
if ($content === false) {
265265
// No script to run before change files
@@ -275,7 +275,7 @@ protected function runBeforeChangeFiles($nextVersion) {
275275
}
276276

277277
protected function runAfterChangeFiles($nextVersion) {
278-
$remoteFile = $this->getRemoteFile('_afterChangeFiles.php', $nextVersion);
278+
$remoteFile = self::REMOTE . 'versions/main/core/' . $nextVersion .'/_afterChangeFiles.php';
279279
$content = $this->getRemoteFileContent($remoteFile);
280280
if ($content === false) {
281281
// No script to run before change files
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"afterAdminTitle" : "configManagerDisplayInstallFile"
2+
"afterAdminTitle" : "configManagerDisplayInstallFile",
3+
"adminBeforeRunPlugin" : "configManagerCheckNewVersion"
34
}

plugin/configmanager/template/admin.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
<?php
22
defined('ROOT') OR exit('No direct script access allowed');
33
include_once(ROOT . 'admin/header.php');
4-
5-
if ($nextVersion) {
6-
?>
7-
<div class="msg info">
8-
<p>Une nouvelle version est disponible.<br/>
9-
Cliquez ci-dessous pour mettre à jour votre site en version <?php echo $nextVersion; ?></p>
10-
<p>N'oubliez pas de faire une sauvegarde de votre site avant d'effectuer cette miseà jour.</p>
11-
<p>Vous pouvez consulter le <a href="https://github.com/299Ko/299ko/blob/master/changelog.md"
12-
target="_blank">changelog des versions de 299Ko ici</a>.</p>
13-
<div style='text-align:center'><a class='button alert' href='index.php?p=configmanager&action=update&token=<?php echo administrator::getToken(); ?>'>
14-
Mettre à jour le site</a></div>
15-
<a href='#' class='msg-button-close'><i class='fa-solid fa-xmark'></i></a>
16-
</div>
17-
<?php
18-
}
194
?>
205

216
<form id="configForm" method="post" action="index.php?p=configmanager&action=save" autocomplete="off">

theme/default/styles.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ hr{
130130
}
131131

132132
img{
133-
max-width:100%
133+
max-width:100%;
134+
height: auto;
134135
}
135136

136137
table{

0 commit comments

Comments
 (0)