From 82dd10314406bacc73357b30f8548cff5b617828 Mon Sep 17 00:00:00 2001
From: Floorb <132411956+Neetpone@users.noreply.github.com>
Date: Sat, 26 Mar 2022 23:57:28 -0400
Subject: [PATCH] Code cleanup
---
api/tags_autocomplete.php | 2 +-
archive.php | 2 +-
discover.php | 13 ----------
includes/DatabaseHandle.class.php | 38 -----------------------------
includes/Models/Tag.php | 2 +-
includes/NonRetardedSSP.class.php | 37 ----------------------------
includes/ViewBag.class.php | 34 --------------------------
includes/captcha.php | 5 ++--
includes/common.php | 2 +-
includes/functions.php | 3 ++-
theme/bulma/js/paste.js | 40 +++++++++++++++----------------
theme/bulma/view.php | 4 ++--
user.php | 2 +-
13 files changed, 32 insertions(+), 152 deletions(-)
delete mode 100644 includes/DatabaseHandle.class.php
delete mode 100644 includes/NonRetardedSSP.class.php
delete mode 100644 includes/ViewBag.class.php
diff --git a/api/tags_autocomplete.php b/api/tags_autocomplete.php
index 88c7863..3e9fb74 100644
--- a/api/tags_autocomplete.php
+++ b/api/tags_autocomplete.php
@@ -23,6 +23,6 @@ $results = Tag::select('name')
->fetchAll()
->toArray();
-array_push($tags, ['name' => $tag_name]);
+$tags[] = ['name' => $tag_name];
echo json_encode($tags);
diff --git a/archive.php b/archive.php
index ca5c90b..bbb2496 100644
--- a/archive.php
+++ b/archive.php
@@ -15,5 +15,5 @@ updatePageViews();
// Theme
$page_template = 'archive';
$page_title = 'Pastes Archive';
-array_push($script_bundles, 'archive');
+$script_bundles[] = 'archive';
require_once('theme/' . $default_theme . '/common.php');
diff --git a/discover.php b/discover.php
index 48aa975..b86576f 100644
--- a/discover.php
+++ b/discover.php
@@ -5,19 +5,6 @@ require_once('includes/functions.php');
use PonePaste\Models\Paste;
-function transformPasteRow(Paste $row) : array {
- return [
- 'id' => $row['id'],
- 'title' => $row['title'],
- 'member' => $row['member'],
- 'time' => $row['created_at'],
- 'time_update' => $row['updated_at'],
- 'friendly_update_time' => friendlyDateDifference(new DateTime($row['updated_at']), new DateTime()),
- 'friendly_time' => friendlyDateDifference(new DateTime($row['created_at']), new DateTime()),
- 'tags' => $row->tags
- ];
-}
-
$popular_pastes = Paste::getMostViewed();//->map('transformPasteRow');
$monthly_popular_pastes = Paste::getMonthPopular();//->map('transformPasteRow');
$recent_pastes = Paste::getRecent();//->map('transformPasteRow');
diff --git a/includes/DatabaseHandle.class.php b/includes/DatabaseHandle.class.php
deleted file mode 100644
index 1a5974b..0000000
--- a/includes/DatabaseHandle.class.php
+++ /dev/null
@@ -1,38 +0,0 @@
-conn = new PDO($conString, $username, $password, [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false
- ]);
- }
-
- public function prepare(string $query) : PDOStatement {
- return $this->conn->prepare($query);
- }
-
- public function query(string $query, array $params = null) : PDOStatement {
- if (empty($params)) {
- return $this->conn->query($query);
- }
-
- $stmt = $this->conn->prepare($query);
- $stmt->execute($params);
-
- return $stmt;
- }
-
- public function querySelectOne(string $query, array $params = null, int $fetchMode = PDO::FETCH_ASSOC) : array|null {
- $stmt = $this->query($query, $params);
-
- if ($row = $stmt->fetch($fetchMode)) {
- return $row;
- }
-
- return null;
- }
-}
diff --git a/includes/Models/Tag.php b/includes/Models/Tag.php
index 7d70f0b..89f87a9 100644
--- a/includes/Models/Tag.php
+++ b/includes/Models/Tag.php
@@ -47,7 +47,7 @@ class Tag extends Model {
$cleanName = Tag::cleanTagName($tagName);
if (!empty($cleanName)) {
- array_push($cleanTags, $cleanName);
+ $cleanTags[] = $cleanName;
}
}
diff --git a/includes/NonRetardedSSP.class.php b/includes/NonRetardedSSP.class.php
deleted file mode 100644
index 3f2e407..0000000
--- a/includes/NonRetardedSSP.class.php
+++ /dev/null
@@ -1,37 +0,0 @@
-count();
-
- /* build query */
- $params = [];
-
- if ($length != 0) {
- $builder = $builder->limit($length);
-
- if ($start != 0) {
- $builder = $builder->offset($start);
- }
- }
-
- /* fire it off */
- $data = $builder->get();
-
- return [
- 'draw' => $draw,
- 'recordsTotal' => $recordsTotal,
- 'recordsFiltered' => ($recordsTotal - count($data)),
- 'data' => $data
- ];
- }
-}
diff --git a/includes/ViewBag.class.php b/includes/ViewBag.class.php
deleted file mode 100644
index e4f4d6e..0000000
--- a/includes/ViewBag.class.php
+++ /dev/null
@@ -1,34 +0,0 @@
-", "", $site_data);
diff --git a/theme/bulma/js/paste.js b/theme/bulma/js/paste.js
index 30eeef0..a98cc23 100644
--- a/theme/bulma/js/paste.js
+++ b/theme/bulma/js/paste.js
@@ -28,15 +28,15 @@ function replaceSelection(e, t) {
var n = e.selectionStart;
var r = e.selectionEnd;
e.value = e.value.substring(0, n) + t + e.value.substring(r);
- if (n != r) {
+ if (n !== r) {
setSelectionRange(e, n, n + t.length);
} else {
setSelectionRange(e, n + t.length, n + t.length);
}
} else if (document.selection) {
var i = document.selection.createRange();
- if (i.parentElement() == e) {
- var s = i.text == "";
+ if (i.parentElement() === e) {
+ var s = i.text === "";
i.text = t;
if (!s) {
i.moveStart("character", -t.length);
@@ -47,13 +47,14 @@ function replaceSelection(e, t) {
}
function catchTab(e, t) {
+ let c;
if (navigator.userAgent.match("Gecko")) {
c = t.which;
} else {
c = t.keyCode;
}
- if (c == 9) {
- var n = e.scrollTop;
+ if (c === 9) {
+ const n = e.scrollTop;
replaceSelection(e, String.fromCharCode(9));
stopEvent(t);
e.scrollTop = n;
@@ -77,8 +78,7 @@ var js = {
return this.getLines(e).length;
},
getLines: function (e) {
- var t = e.split("\n");
- return t;
+ return e.split("\n");
},
},
textElement: {
@@ -97,7 +97,7 @@ var js = {
}
t.start = i;
t.end = i + n.text.replace(/\r/g, "").length;
- } else if (e.selectionStart || e.selectionStart == 0) {
+ } else if (e.selectionStart || e.selectionStart === 0) {
t.start = e.selectionStart;
t.end = e.selectionEnd;
}
@@ -118,32 +118,32 @@ var js = {
};
function highlight(e) {
- var t = js.textElement.caretPosition(e);
+ const t = js.textElement.caretPosition(e);
if (!t.start && !t.end) return;
- var n = js.text.getLines(js.textElement.value(e));
- var r = 0,
+ const n = js.text.getLines(js.textElement.value(e));
+ let r = 0,
i = 0;
- var s = "";
- var o = false;
- var u = 0;
- for (var a in n) {
+ let s = "";
+ let o = false;
+ let u = 0;
+ for (const a in n) {
i = r + n[a].length;
if (t.start >= r && t.start <= i) o = true;
if (o) {
- var f = n[a].substr(0, 11) == "!highlight!";
+ const f = n[a].substr(0, 11) === "!highlight!";
if (!u) {
if (f) u = 1;
else u = 2;
}
- if (u == 1 && f) n[a] = n[a].substr(11, n[a].length - 11);
- else if (u == 2 && !f) s += "!highlight!";
+ if (u === 1 && f) n[a] = n[a].substr(11, n[a].length - 11);
+ else if (u === 2 && !f) s += "!highlight!";
}
s = s + n[a] + "\n";
if (t.end >= r && t.end <= i) o = false;
r = i + 1;
}
e.value = s.substring(0, s.length - 1);
- var l = t.start + (u == 1 ? -11 : 11);
+ const l = t.start + (u === 1 ? -11 : 11);
js.textElement.setCaretPosition(e, {
start: l,
end: l,
@@ -152,7 +152,7 @@ function highlight(e) {
function togglev() {
if (
- document.getElementsByTagName("ol")[0].style.listStyle.substr(0, 4) ==
+ document.getElementsByTagName("ol")[0].style.listStyle.substr(0, 4) ===
"none"
) {
document.getElementsByTagName("ol")[0].style.listStyle = "decimal";
diff --git a/theme/bulma/view.php b/theme/bulma/view.php
index 09bcb4d..ad88166 100644
--- a/theme/bulma/view.php
+++ b/theme/bulma/view.php
@@ -1,7 +1,7 @@