Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tltneon committed Jun 27, 2024
1 parent 0cbe3cb commit 9f15943
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
19 changes: 3 additions & 16 deletions install.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?php
namespace tltneon\LGSL;
//------------------------------------------------------------------------------------------------------------+
header("Content-Type:text/html; charset=utf-8");
//------------------------------------------------------------------------------------------------------------+

header("Content-Type:text/html; charset=utf-8");
require('src/lgsl_class.php');


$db_type = empty($_POST["db_type"]) ? "mysql" : $_POST["db_type"];
$db_server = empty($_POST["server"]) ? "localhost" : $_POST["server"];
Expand Down Expand Up @@ -165,7 +161,6 @@
$conf = json_decode($_POST['_config'], true);
if (empty($lgsl_database)) {
file_put_contents('install.php', 666);
//chmod('install.php', 666);
chmod('src/lgsl_config.php', 666);
function type($var) {
if (gettype($var) == "Array") return $var;
Expand Down Expand Up @@ -315,15 +310,7 @@ function type($var) {
<div>
<?php
//------------------------------------------------------------------------------------------------------------+
$loc = array_reduce(["AD","AE","AF","AG","AI","AL","AM","AN","AO","AR","AS","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BM","BN",
"BO","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CS","CU","CV","CX","CY","CZ",
"DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","EU","FI","FJ","FK","FM","FO","FR","GA","GB","GD","GE","GF","GH","GI",
"GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IN","IO","IQ","IR","IS","IT","JM",
"JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD",
"ME","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO",
"NP","NR","NU","NZ","OFF","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA",
"SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","ST","SV","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TL","TM",
"TN","TO","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","ZA","ZM","ZW"],
$loc = array_reduce(LGSL::locationsCodes(),
function($a, $b) {
return "{$a}<option value='{$b}'>{$b}</option>";
});
Expand All @@ -347,7 +334,7 @@ function check($name, $bool, $hint = '') {
$output .= check('FSOCKOPEN', function_exists("fsockopen") && fsockopen("udp://127.0.0.1", 13, $errno, $errstr, 3), 'mainly used for querying');
$output .= check('CURL', LGSL::isEnabled("curl"), 'optional: for some games');
$output .= check('BZ2', function_exists("bzdecompress"), 'optional: for some games');
$output .= check('GD', function_exists("gd"), 'optional: for charts & userbars');
$output .= check('GD', LGSL::isEnabled("gd"), 'optional: for charts & userbars');
}

$output .= "
Expand Down
4 changes: 2 additions & 2 deletions src/lgsl_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ function lgsl_help_info() {
["href" => "http://php.net/curl", "name" => "CURL", "test" => LGSL::isEnabled("curl"), "desc" => "crl"],
["href" => "http://php.net/mbstring", "name" => "MBSTRING", "test" => function_exists("mb_convert_encoding"), "desc" => "mbs"],
["href" => "http://php.net/bzip2", "name" => "BZIP2", "test" => function_exists("bzdecompress"), "desc" => "bz2"],
["href" => "http://php.net/gd2", "name" => "GD", "test" => extension_loaded("gd"), "desc" => "gd2"],
["href" => "http://php.net/gd", "name" => "GD", "test" => LGSL::isEnabled("gd"), "desc" => "gd2"],
["href" => "http://php.net/zlib", "name" => "ZLIB", "test" => function_exists("gzuncompress"), "desc" => "zli"],
];
$output = "";
foreach ($funcs as $func) {
$output .= "
<tr>
<td> <a href='{$func['href']}'>{$func['name']}</a> </td>
<td> <a href='{$func['href']}' target='_blank'>{$func['name']}</a> </td>
<td> {$lgsl_config['text']['enb']}: ".($func['test'] ? $lgsl_config['text']['yes'] : $lgsl_config['text']['nno'])." </td>
<td> ( {$lgsl_config['text'][$func['desc']]} ) </td>
</tr>
Expand Down
15 changes: 12 additions & 3 deletions src/lgsl_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ static function buildLink($url, $params) {
static public function isEnabled($func) {
switch ($func) {
case "curl": return function_exists('curl_init') && function_exists('curl_setopt') && function_exists('curl_exec');
case "gd": return extension_loaded('gd');
}
}
static public function locationCoords($code) {
$a = array_search($code, [
static public function locationsCodes($sort = true) {
$arr = [
"AD","AE","AF","AG","AI","AL","AM","AN","AO","AR","AS","AT","AU","VG",
"AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BM","VI",
"BN","BO","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","VN",
Expand All @@ -209,7 +210,15 @@ static public function locationCoords($code) {
"PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","",
"SH","SI","SJ","SK","SL","SM","SN","SO","SR","ST","SV","SY","SZ","",
"TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","",
"TV","TW","TZ","UA","UG","UK","UM","US","UY","UZ","VA","VC","VE"]);
"TV","TW","TZ","UA","UG","UK","UM","US","UY","UZ","VA","VC","VE"];
if ($sort) {
sort($arr);
return array_filter($arr, fn($value) => !is_null($value) && $value !== '');
}
return $arr;
}
static public function locationCoords($code) {
$a = array_search($code, self::locationsCodes(false));
return [$a % 14 * 16, floor($a / 14) * 11];
}
static public function normalizeString($string) {
Expand Down
2 changes: 1 addition & 1 deletion src/lgsl_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<div>";

if ($lgsl_config['image_mod']) {
if (extension_loaded('gd')) {
if (LGSL::isEnabled("gd")) {
for ($i = 1; $i < 4; $i++) {
$output .= "
<div style='overflow-x: auto;'><img src='userbar.php?{$g}&t={$i}' alt='{$server->getName()}'/></div>
Expand Down
2 changes: 1 addition & 1 deletion src/other/loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<script>
document.addEventListener("DOMContentLoaded", reloadLocale);
function reloadLocale() {
let lang =
let lang = !document.cookie ? "english" :
document.cookie
.split(';')
.map(v => v.split('='))
Expand Down
1 change: 1 addition & 0 deletions src/styles/darken_style.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ div[id^="servername"] { margin:auto; text-align:center; font-weight:bold; paddin
.status_icon_pen { width: 14px; height: 14px; background-color: gray; display: inline-block; border: 1px solid black; }
.status_icon_nrs { background-image: url(../other/icon_no_response.gif) !important; }
.status_icon_onp { background-image: url(../other/icon_online_password.gif) !important; }
.status_icon_err { width: 14px; height: 14px; background-color: rgb(126, 124, 0); display: inline-block; border: 1px solid black; }
img.game_icon { width: 16px;border-radius: 2px; }

#server_list_table { margin:auto; width:90%; border-radius: 12px; margin-top:30px; }
Expand Down

0 comments on commit 9f15943

Please sign in to comment.