From 8e33ed362cbdabdb74912587c7cadc6fef0723a3 Mon Sep 17 00:00:00 2001 From: ruan <2369127-ruany@users.noreply.gitlab.com> Date: Wed, 21 Oct 2020 15:44:38 +0200 Subject: [PATCH] Minor performance improvements / cleanup --- check.php | 2 +- error/access-denied.php | 2 +- history.php | 4 ++-- inc/page.php | 17 +++++++---------- inc/test/php/PageTest.php | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/check.php b/check.php index 3bde456..911ef20 100644 --- a/check.php +++ b/check.php @@ -38,7 +38,7 @@ class Check { redirect($page->link("info.php?id=$name&type=$type")); return; } - $name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8'); + $name = htmlspecialchars($name, ENT_QUOTES); $this->println(str_replace("{name}", $name, $page->t("error.name.unseen"))); return; } diff --git a/error/access-denied.php b/error/access-denied.php index 1e06ef0..57ab778 100644 --- a/error/access-denied.php +++ b/error/access-denied.php @@ -25,7 +25,7 @@ if ($error !== false) { // sanitize user input - $error = htmlspecialchars($error, ENT_QUOTES, "UTF-8"); + $error = htmlspecialchars($error, ENT_QUOTES); echo $error; } diff --git a/history.php b/history.php index c4ea1e7..522da1a 100644 --- a/history.php +++ b/history.php @@ -29,7 +29,7 @@ class History { if ($st->execute()) { while ($row = $st->fetch(PDO::FETCH_ASSOC)) { $row['__table__'] = $type; - array_push($array, $row); + $array[] = $row; } } $st->closeCursor(); @@ -173,7 +173,7 @@ try { foreach ($all as $row) { $i++; if ($i > $limit) break; - array_push($trim, $row); + $trim[] = $row; } $all = $trim; } diff --git a/inc/page.php b/inc/page.php index 38dcbfc..5ba1681 100644 --- a/inc/page.php +++ b/inc/page.php @@ -214,8 +214,8 @@ class Page { $bitColumns = array("active", "ipban"); if ($table === $this->settings->table['warnings']) { - array_push($columns, "warned"); - array_push($bitColumns, "warned"); + $columns[] = "warned"; + $bitColumns[] = "warned"; } if ($table !== $this->settings->table['kicks']) { @@ -228,7 +228,7 @@ class Page { if ($phpIsBroken === true) { foreach ($bitColumns as $column) { unset($columns[$column]); - array_push($columns, "CAST($column AS UNSIGNED) AS $column"); + $columns[] = "CAST($column AS UNSIGNED) AS $column"; } } return implode(",", $columns); @@ -249,7 +249,7 @@ class Page { } $uuid = $this->uuid_undashify($uuid); - $src = str_replace('{name}', $name, str_replace('{uuid}', $uuid, $avatar_source)); + $src = str_replace(array('{uuid}', '{name}'), array($uuid, $name), $avatar_source); if (in_array($name, $this->settings->console_aliases) || $name === $this->settings->console_name) { $src = $this->resource($this->settings->console_image); $name = $this->settings->console_name; @@ -324,7 +324,7 @@ class Page { if (strstr($text, "\xa7") || strstr($text, "&")) { $text = preg_replace("/(?i)(\x{00a7}|&)[0-9A-FK-OR]/u", "", $text); } - $text = htmlspecialchars($text, ENT_QUOTES, "UTF-8"); + $text = htmlspecialchars($text, ENT_QUOTES); if (strstr($text, "\n")) { $text = preg_replace("/\n/", "
", $text); } @@ -493,7 +493,7 @@ class Page { } else { $header = $this->t("table.$header"); } - array_push($headers_translated, $header); + $headers_translated[] = $header; } $this->table_print_headers($headers_translated); $this->table_headers_printed = true; @@ -663,10 +663,7 @@ class Page { public function where_append($where) { if ($where !== "") { return "$where AND "; - } else { - return "WHERE "; } + return "WHERE "; } - - } diff --git a/inc/test/php/PageTest.php b/inc/test/php/PageTest.php index e531349..e032383 100644 --- a/inc/test/php/PageTest.php +++ b/inc/test/php/PageTest.php @@ -20,7 +20,7 @@ final class PageTest extends TestCase { public function testHistoryPagerHTML(): void { $page = new Page("test", false); foreach (explode("\n", file_get_contents("./inc/test/php/test_setup.sql")) as $query) { - if (strlen($query) > 0) { + if ($query !== '') { $page->conn->query($query); } }