Skip to content

Commit 0cb72c5

Browse files
committed
feat: modify the update system
Update system now uses the new alert system. I think it looks nicer.
1 parent 5e97c24 commit 0cb72c5

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

index.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
require_once("utils/params.php");
2828
require_once("utils/update_checker.php");
2929

30-
Update::getCurrentVersion();
30+
Update::getCurrentVersion();
3131

3232
$config = Config::getConfig();
3333
$parser = ParamParser::getParser();
@@ -70,6 +70,7 @@
7070
?>
7171

7272
<script src="js/jquery-3.2.1.min.js"></script>
73+
<script src="js/bootstrap.min.js"></script>
7374

7475
<!-- Change the key below -->
7576
<script type="text/javascript" src="https://maps.google.com/maps/api/js"></script>
@@ -141,7 +142,6 @@
141142

142143
</head>
143144
<body>
144-
145145
<nav class="navbar navbar-default-invert navbar-static-top" style="margin: 0;">
146146
<!-- At some point, I'll add more stuff here. For the time being, it'll just be the site logo -->
147147
<div class="container-fluid">
@@ -207,21 +207,19 @@
207207

208208
<p style="color: black; text-align: center;">This was originaly created by <a href="https://github.com/TGRHavoc">Havoc</a></p>
209209

210-
<?php
211-
if (!Update::latestVersion()){
212-
// If not the latest version, tell them
213-
?>
214-
<p style="color: red; text-align: center; font-weight: 700;">An update is available, please download it <a href="https://github.com/TGRHavoc/live_map-interface">HERE</a></p>
215-
<?php
216-
}
217-
?>
210+
<div id="alert-holder" class="position: absolute; width: 80%; z-index: 1">
211+
</div>
218212

219213
</div>
220214
</div>
221215

222216
<?php
223217
Minifier::printLastJs($config->debug);
224218
$parser->printJsForParams();
219+
220+
if(!Update::latestVersion()){
221+
echo Update::alertJs();
222+
}
225223
?>
226224

227225
</body>

utils/update_checker.php

+22
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ class Update{
44

55
private static $version = "2.1.3";
66
private static $url = "https://raw.githubusercontent.com/TGRHavoc/live_map-interface/master/version.json";
7+
private static $downloadUrl = "http://github.com/TGRHavoc/live_map-interface";
8+
private static $latestVer = "";
79

810
public static function latestVersion(){
911
$data = file_get_contents(self::$url);
1012
$data = json_decode($data);
1113

14+
self::$latestVer = $data->interface;
15+
1216
return $data->interface == self::$version;
1317
}
1418

@@ -19,6 +23,24 @@ public static function getCurrentVersion(){
1923
self::$version = $ver->interface;
2024
}
2125

26+
public static function alertJs(){
27+
$arr = array(
28+
sprintf("An update is available (%s -> %s)", self::$version, self::$latestVer),
29+
sprintf("Please download it <a href=\'%s\'>HERE</a>", self::$downloadUrl),
30+
);
31+
32+
// Dynamically create a array string for the above array
33+
$jsArrayString = "[";
34+
foreach ($arr as $key => $value) {
35+
$jsArrayString .= "'%s'" . ($key == count($arr)-1 ? "" : ",");
36+
}
37+
$jsArrayString .= "]";
38+
39+
$jsArrayString = vsprintf($jsArrayString, $arr);
40+
41+
return "<script> createAlert('danger', 'Update available', " . $jsArrayString . "); </script>";
42+
43+
}
2244
}
2345

2446
?>

0 commit comments

Comments
 (0)