diff --git a/check.php b/check.php
index 771d6a7..3bde456 100644
--- a/check.php
+++ b/check.php
@@ -35,7 +35,7 @@ class Check {
if (!isset($uuid)) {
if (filter_var($name, FILTER_VALIDATE_FLOAT)) {
echo "
";
- redirect("info.php?id=$name&type=$type");
+ redirect($page->link("info.php?id=$name&type=$type"));
return;
}
$name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
@@ -50,7 +50,7 @@ class Check {
}
echo "
";
- redirect($href);
+ redirect($page->link($href));
/*
$table = $page->settings->table['bans'];
diff --git a/history.php b/history.php
index 877a96f..f641889 100644
--- a/history.php
+++ b/history.php
@@ -1,6 +1,5 @@
t("error.missing-args"));
+$args = $page->args;
-$staffhistory = (isset($_GET['staffhistory']) && $_GET['staffhistory'] === "1");
+count($args) > 0 && is_string($args[0]) or die($page->t("error.missing-args"));
-$uuid = $page->uuid_dashify($_GET['uuid']);
+//$staffhistory = (count($args) >= 2 && $args[1] === "1");
+$staffhistory=false;
+
+$arg0 = $args[0];
+if (strstr($arg0, ":issued")) {
+ $staffhistory=true;
+ $arg0 = substr($arg0, 0, -strlen(":issued"));
+}
+$uuid = $page->uuid_dashify($arg0);
$name = $page->get_name($uuid);
$name !== null or die(str_replace("{name}", $name, $page->t("error.name.unseen")));
@@ -99,7 +106,7 @@ if (isset($_GET['from'])) {
if ($info['type'] !== null) {
$from_title = $info['title'];
$from = Page::lc_first($from_title);
- $from_href = $info['page'];
+ $from_href = $page->link($info['page']);
}
}
@@ -197,7 +204,7 @@ try {
$player_name = $page->get_name($row['uuid']);
$label_type = $page->type;
- $label_name = Info::create($row, $player_name, $page, $label_type)->name(); //ucfirst($label_type);
+ $label_name = $page->t("generic." . $label_type);
$label = "$label_name";
$page->print_table_rows($row, array(
@@ -217,12 +224,18 @@ try {
// print pager
if ($page->settings->show_pager) {
$page->name = "history";
- $args = "&uuid=$uuid";
- if ($from !== null) {
- $args .= "&from=$from";
- }
+ $target = null;
+
if ($staffhistory) {
- $args .= "&staffhistory=1";
+// $args .= "&staffhistory=1";
+// $args .= ":issued";
+ $uuid .= ":issued";
+ }
+ $args = "?uuid=$uuid";
+
+ if ($page->settings->simple_urls) {
+ $target = $page->name . "/$uuid";
+ $args = "";
}
$prevargs = $args;
@@ -233,7 +246,13 @@ try {
$prevargs .= "&after=$after";
}
- $page->print_pager($total, $args, $prevargs);
+ if ($from !== null) {
+ $args .= "&from=$from";
+ $prevargs .= "&from=$from";
+ }
+
+
+ $page->print_pager($total, $args, $prevargs, $target, false);
}
} else {
echo $page->t("history.error.uuid.no-result") . "
";
diff --git a/inc/footer.php b/inc/footer.php
index 186a570..9c303f2 100644
--- a/inc/footer.php
+++ b/inc/footer.php
@@ -1,3 +1,3 @@
-
-
+
+
"; ?>
diff --git a/inc/header.php b/inc/header.php
index d28f364..f179cb0 100644
--- a/inc/header.php
+++ b/inc/header.php
@@ -34,10 +34,15 @@ function __construct($page) {
function navbar($links) {
echo '
';
+ $request = $this->page->get_requested_page();
foreach ($links as $page => $title) {
$li = "li";
$class = "nav-item";
- if ((substr($_SERVER['SCRIPT_NAME'], -strlen($page))) === $page) {
+ if ($this->page->settings->simple_urls) {
+ if ("$request.php" === $page) {
+ $class .= " active navbar-active";
+ }
+ } else if ((substr($_SERVER['SCRIPT_NAME'], -strlen($page))) === $page) {
$class .= " active navbar-active";
}
$li .= " class=\"$class\"";
@@ -47,6 +52,7 @@ function navbar($links) {
$title .= $this->count[$page];
$title .= "";
}
+ $page = $this->page->link($page);
echo "<$li>$title";
}
echo '
';
@@ -62,11 +68,11 @@ $settings = $this->page->settings;
-
+
-
-
-
+
+
+
+
';
}
- function print_pager($total = -1, $args = "", $prevargs = "") {
+ function print_pager($total = -1, $args = "", $prevargs = "", $page = null, $simple=true) {
if (!$this->settings->show_pager) return;
$table = $this->table;
- $page = $this->name . ".php";
+ if ($page === null) {
+ $page = $this->name . ".php";
+ }
if ($total === -1) {
$where = $this->where_append($this->name === "kicks" ? "" : $this->settings->active_query);
@@ -548,13 +582,21 @@ class Page {
$next_class = "litebans-" . ($next_active ? "pager-active" : "pager-inactive");
$pager_prev = "";
- if ($prev_active) {
- $pager_prev = "$pager_prev";
+ $pager_next = "";
+
+ if ($simple) {
+ $pager_prev_href = $this->link("$page{$prevargs}&page={$prev}");
+ $pager_next_href = $this->link("$page{$args}&page={$next}");
+ } else {
+ $pager_prev_href = $this->link("$page") . "{$prevargs}&page={$prev}";
+ $pager_next_href = $this->link("$page") . "{$args}&page={$next}";
}
- $pager_next = "";
+ if ($prev_active) {
+ $pager_prev = "$pager_prev";
+ }
if ($next_active) {
- $pager_next = "$pager_next";
+ $pager_next = "$pager_next";
}
$pager_count = '';
echo "$pager_prev $pager_next $pager_count";
@@ -570,8 +612,24 @@ class Page {
include_once './inc/footer.php';
}
- function autoversion($file) {
- return "$file?" . filemtime($file);
+ function link($url) {
+ if ($this->settings->simple_urls && $this->is_index) {
+ $url = preg_replace("/\.php/", "", $url, 1);
+ $url = preg_replace("/\?[a-z]+=/", "/", $url);
+ $url = preg_replace("/&[a-z]+=/", "/", $url);
+ $url = $this->index_base_path . $url . "/";
+ }
+ return $url;
+ }
+
+ function resource($file) {
+ if (!file_exists($file)) return $file;
+
+ $mtime = filemtime($file);
+ if ($this->settings->simple_urls && $this->is_index) {
+ $file = $this->index_base_path . $file;
+ }
+ return "$file?" . $mtime;
}
function table_begin() {
diff --git a/inc/settings.php b/inc/settings.php
index 9abebd9..a5f8626 100644
--- a/inc/settings.php
+++ b/inc/settings.php
@@ -98,6 +98,13 @@ final class Settings {
// Enable error pages.
$this->error_pages = true;
+ // Enable simple URLs?
+ // This will convert URLs like "example.com/punishments/bans.php" to "example.com/punishments/bans/"
+ // It will also simplify URL parameters: "example.com/punishments/info.php?type=mute&id=94" -> "example.com/punishments/info/mute/94/"
+ // Your web server must be configured correctly to allow this to work, otherwise you will get a 404 error.
+ // Web server configuration: https://gitlab.com/ruany/litebans-php/-/wikis/Simple-URLs
+ $this->simple_urls = false;
+
$this->date_month_translations = null;
// If your system locale doesn't automatically translate month names, you can set them manually here.
diff --git a/index.php b/index.php
index 98f3f95..de837ae 100644
--- a/index.php
+++ b/index.php
@@ -2,6 +2,18 @@
require_once './inc/page.php';
$page = new Page("index");
+
+if ($page->settings->simple_urls && count($_GET) !== 0) {
+ $target = $page->get_requested_page();
+ if ($target !== "index" && strlen($target) <= 16 && preg_match("/^[a-z]+$/", $target)) {
+ $local_script = "./${target}.php";
+ if (file_exists($local_script)) {
+ include_once $local_script;
+ return;
+ }
+ }
+}
+
$page->print_title();
?>
diff --git a/info.php b/info.php
index 2db113a..44496e7 100644
--- a/info.php
+++ b/info.php
@@ -41,13 +41,14 @@ abstract class Info {
function history_link($name, $uuid, $args = "") {
$uuid = $this->page->uuid_undashify($uuid);
- return "$name";
+ $href = $this->page->link("history.php?uuid=$uuid$args");
+ return "$name";
}
function moderator_avatar() {
$row = $this->row;
$banner_name = $this->page->get_banner_name($row);
- return $this->page->get_avatar($banner_name, $row['banned_by_uuid'], true, $this->history_link($banner_name, $row['banned_by_uuid'], "&staffhistory=1"), $name_left = false);
+ return $this->page->get_avatar($banner_name, $row['banned_by_uuid'], true, $this->history_link($banner_name, $row['banned_by_uuid'], ":issued"), $name_left = false);
}
function basic_info() {
@@ -78,15 +79,19 @@ class KickInfo extends Info {
}
// check if info.php is requested, otherwise it's included
-if ((substr($_SERVER['SCRIPT_NAME'], -strlen("info.php"))) !== "info.php") {
- return;
-}
+//if ((substr($_SERVER['SCRIPT_NAME'], -strlen("info.php"))) !== "info.php" && ((substr($_SERVER['SCRIPT_NAME'], -strlen("index.php"))) !== "index.php")) {
+// return;
+//}
-isset($_GET['type'], $_GET['id']) && is_string($_GET['type']) && is_string($_GET['id']) or die($page->t("error.missing-args"));
+$page = new Page("info");
+$args = $page->args;
-$type = $_GET['type'];
-$id = $_GET['id'];
-$page = new Page($type);
+count($args) >= 2 && is_string($args[0]) && is_string($args[1]) or die($page->t("error.missing-args"));
+
+$type = $args[0];
+$id = $args[1];
+
+$page->set_info($page->type_info($type));
($page->type !== null) or die("Unknown page type requested");
diff --git a/lang/README.md b/lang/README.md
old mode 100644
new mode 100755
diff --git a/lang/cs_CZ.utf8.php b/lang/cs_CZ.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/da_DK.utf8.php b/lang/da_DK.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/de_DE.utf8.php b/lang/de_DE.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/en_US.utf8.php b/lang/en_US.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/es_ES.utf8.php b/lang/es_ES.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/fr_FR.utf8.php b/lang/fr_FR.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/it_IT.utf8.php b/lang/it_IT.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/ja_JP.utf8.php b/lang/ja_JP.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/nl_NL.utf8.php b/lang/nl_NL.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/pl_PL.utf8.php b/lang/pl_PL.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/ru_RU.utf8.php b/lang/ru_RU.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/zh_CN.utf8.php b/lang/zh_CN.utf8.php
old mode 100644
new mode 100755
diff --git a/lang/zh_HK.utf8.php b/lang/zh_HK.utf8.php
old mode 100644
new mode 100755