mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
Code cleanup
This commit is contained in:
parent
02715158d3
commit
82dd103144
13 changed files with 32 additions and 152 deletions
|
@ -23,6 +23,6 @@ $results = Tag::select('name')
|
||||||
->fetchAll()
|
->fetchAll()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
array_push($tags, ['name' => $tag_name]);
|
$tags[] = ['name' => $tag_name];
|
||||||
|
|
||||||
echo json_encode($tags);
|
echo json_encode($tags);
|
||||||
|
|
|
@ -15,5 +15,5 @@ updatePageViews();
|
||||||
// Theme
|
// Theme
|
||||||
$page_template = 'archive';
|
$page_template = 'archive';
|
||||||
$page_title = 'Pastes Archive';
|
$page_title = 'Pastes Archive';
|
||||||
array_push($script_bundles, 'archive');
|
$script_bundles[] = 'archive';
|
||||||
require_once('theme/' . $default_theme . '/common.php');
|
require_once('theme/' . $default_theme . '/common.php');
|
||||||
|
|
13
discover.php
13
discover.php
|
@ -5,19 +5,6 @@ require_once('includes/functions.php');
|
||||||
|
|
||||||
use PonePaste\Models\Paste;
|
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');
|
$popular_pastes = Paste::getMostViewed();//->map('transformPasteRow');
|
||||||
$monthly_popular_pastes = Paste::getMonthPopular();//->map('transformPasteRow');
|
$monthly_popular_pastes = Paste::getMonthPopular();//->map('transformPasteRow');
|
||||||
$recent_pastes = Paste::getRecent();//->map('transformPasteRow');
|
$recent_pastes = Paste::getRecent();//->map('transformPasteRow');
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class DatabaseHandle {
|
|
||||||
private PDO $conn;
|
|
||||||
|
|
||||||
public function __construct(string $conString, string $username, string $password) {
|
|
||||||
$this->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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -47,7 +47,7 @@ class Tag extends Model {
|
||||||
$cleanName = Tag::cleanTagName($tagName);
|
$cleanName = Tag::cleanTagName($tagName);
|
||||||
|
|
||||||
if (!empty($cleanName)) {
|
if (!empty($cleanName)) {
|
||||||
array_push($cleanTags, $cleanName);
|
$cleanTags[] = $cleanName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
|
|
||||||
class NonRetardedSSP {
|
|
||||||
public static function run(array $request, Builder $builder) {
|
|
||||||
/* Some of these parameters might not be passed; zero is an OK default */
|
|
||||||
$draw = (int) @$request['draw'];
|
|
||||||
$start = (int) @$request['start'];
|
|
||||||
$length = (int) @$request['length'];
|
|
||||||
|
|
||||||
|
|
||||||
/* figure out total records */
|
|
||||||
$recordsTotal = $builder->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
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class ViewBag {
|
|
||||||
private static array $global = [];
|
|
||||||
private static array $local = [];
|
|
||||||
|
|
||||||
public static function putGlobal(string $key, string $value) : void {
|
|
||||||
ViewBag::$global[$key] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function put(string $key, string $value) : void {
|
|
||||||
ViewBag::$local[$key] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getGlobal(string $key, bool $escape = true) : string {
|
|
||||||
$value = ViewBag::$global[$key];
|
|
||||||
|
|
||||||
if ($escape) {
|
|
||||||
$value = pp_html_escape($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function get(string $key, bool $escape = true) : string {
|
|
||||||
$value = ViewBag::$local[$key];
|
|
||||||
|
|
||||||
if ($escape) {
|
|
||||||
$value = pp_html_escape($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -147,8 +147,9 @@ if (isset($_GET['_CAPTCHA'])) {
|
||||||
$font = $captcha_config['fonts'][rand(0, count($captcha_config['fonts']) - 1)];
|
$font = $captcha_config['fonts'][rand(0, count($captcha_config['fonts']) - 1)];
|
||||||
|
|
||||||
// Verify font file exists
|
// Verify font file exists
|
||||||
if (!file_exists($font))
|
if (!file_exists($font)) {
|
||||||
throw new Exception('Font file not found: ' . $font);
|
die('Font file not found.');
|
||||||
|
}
|
||||||
|
|
||||||
// Set the font size
|
// Set the font size
|
||||||
$font_size = rand($captcha_config['min_font_size'], $captcha_config['max_font_size']);
|
$font_size = rand($captcha_config['min_font_size'], $captcha_config['max_font_size']);
|
||||||
|
|
|
@ -88,7 +88,7 @@ function flash(string $level, string $message) {
|
||||||
throw new Exception('Invalid flash level ' . $level);
|
throw new Exception('Invalid flash level ' . $level);
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($_SESSION['flashes'][$level], $message);
|
$_SESSION['flashes'][$level][] = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use PonePaste\Models\Paste;
|
||||||
|
|
||||||
function tagsToHtml(array | Collection $tags) : string {
|
function tagsToHtml(array | Collection $tags) : string {
|
||||||
$output = "";
|
$output = "";
|
||||||
|
@ -215,7 +216,7 @@ function embedView($paste_id, $p_title, $content, $title) {
|
||||||
return $stats;
|
return $stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToSitemap(\PonePaste\Models\Paste $paste, $priority, $changefreq) {
|
function addToSitemap(Paste $paste, $priority, $changefreq) {
|
||||||
$c_date = date('Y-m-d');
|
$c_date = date('Y-m-d');
|
||||||
$site_data = file_get_contents("sitemap.xml");
|
$site_data = file_get_contents("sitemap.xml");
|
||||||
$site_data = str_replace("</urlset>", "", $site_data);
|
$site_data = str_replace("</urlset>", "", $site_data);
|
||||||
|
|
|
@ -28,15 +28,15 @@ function replaceSelection(e, t) {
|
||||||
var n = e.selectionStart;
|
var n = e.selectionStart;
|
||||||
var r = e.selectionEnd;
|
var r = e.selectionEnd;
|
||||||
e.value = e.value.substring(0, n) + t + e.value.substring(r);
|
e.value = e.value.substring(0, n) + t + e.value.substring(r);
|
||||||
if (n != r) {
|
if (n !== r) {
|
||||||
setSelectionRange(e, n, n + t.length);
|
setSelectionRange(e, n, n + t.length);
|
||||||
} else {
|
} else {
|
||||||
setSelectionRange(e, n + t.length, n + t.length);
|
setSelectionRange(e, n + t.length, n + t.length);
|
||||||
}
|
}
|
||||||
} else if (document.selection) {
|
} else if (document.selection) {
|
||||||
var i = document.selection.createRange();
|
var i = document.selection.createRange();
|
||||||
if (i.parentElement() == e) {
|
if (i.parentElement() === e) {
|
||||||
var s = i.text == "";
|
var s = i.text === "";
|
||||||
i.text = t;
|
i.text = t;
|
||||||
if (!s) {
|
if (!s) {
|
||||||
i.moveStart("character", -t.length);
|
i.moveStart("character", -t.length);
|
||||||
|
@ -47,13 +47,14 @@ function replaceSelection(e, t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function catchTab(e, t) {
|
function catchTab(e, t) {
|
||||||
|
let c;
|
||||||
if (navigator.userAgent.match("Gecko")) {
|
if (navigator.userAgent.match("Gecko")) {
|
||||||
c = t.which;
|
c = t.which;
|
||||||
} else {
|
} else {
|
||||||
c = t.keyCode;
|
c = t.keyCode;
|
||||||
}
|
}
|
||||||
if (c == 9) {
|
if (c === 9) {
|
||||||
var n = e.scrollTop;
|
const n = e.scrollTop;
|
||||||
replaceSelection(e, String.fromCharCode(9));
|
replaceSelection(e, String.fromCharCode(9));
|
||||||
stopEvent(t);
|
stopEvent(t);
|
||||||
e.scrollTop = n;
|
e.scrollTop = n;
|
||||||
|
@ -77,8 +78,7 @@ var js = {
|
||||||
return this.getLines(e).length;
|
return this.getLines(e).length;
|
||||||
},
|
},
|
||||||
getLines: function (e) {
|
getLines: function (e) {
|
||||||
var t = e.split("\n");
|
return e.split("\n");
|
||||||
return t;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
textElement: {
|
textElement: {
|
||||||
|
@ -97,7 +97,7 @@ var js = {
|
||||||
}
|
}
|
||||||
t.start = i;
|
t.start = i;
|
||||||
t.end = i + n.text.replace(/\r/g, "").length;
|
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.start = e.selectionStart;
|
||||||
t.end = e.selectionEnd;
|
t.end = e.selectionEnd;
|
||||||
}
|
}
|
||||||
|
@ -118,32 +118,32 @@ var js = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function highlight(e) {
|
function highlight(e) {
|
||||||
var t = js.textElement.caretPosition(e);
|
const t = js.textElement.caretPosition(e);
|
||||||
if (!t.start && !t.end) return;
|
if (!t.start && !t.end) return;
|
||||||
var n = js.text.getLines(js.textElement.value(e));
|
const n = js.text.getLines(js.textElement.value(e));
|
||||||
var r = 0,
|
let r = 0,
|
||||||
i = 0;
|
i = 0;
|
||||||
var s = "";
|
let s = "";
|
||||||
var o = false;
|
let o = false;
|
||||||
var u = 0;
|
let u = 0;
|
||||||
for (var a in n) {
|
for (const a in n) {
|
||||||
i = r + n[a].length;
|
i = r + n[a].length;
|
||||||
if (t.start >= r && t.start <= i) o = true;
|
if (t.start >= r && t.start <= i) o = true;
|
||||||
if (o) {
|
if (o) {
|
||||||
var f = n[a].substr(0, 11) == "!highlight!";
|
const f = n[a].substr(0, 11) === "!highlight!";
|
||||||
if (!u) {
|
if (!u) {
|
||||||
if (f) u = 1;
|
if (f) u = 1;
|
||||||
else u = 2;
|
else u = 2;
|
||||||
}
|
}
|
||||||
if (u == 1 && f) n[a] = n[a].substr(11, n[a].length - 11);
|
if (u === 1 && f) n[a] = n[a].substr(11, n[a].length - 11);
|
||||||
else if (u == 2 && !f) s += "!highlight!";
|
else if (u === 2 && !f) s += "!highlight!";
|
||||||
}
|
}
|
||||||
s = s + n[a] + "\n";
|
s = s + n[a] + "\n";
|
||||||
if (t.end >= r && t.end <= i) o = false;
|
if (t.end >= r && t.end <= i) o = false;
|
||||||
r = i + 1;
|
r = i + 1;
|
||||||
}
|
}
|
||||||
e.value = s.substring(0, s.length - 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, {
|
js.textElement.setCaretPosition(e, {
|
||||||
start: l,
|
start: l,
|
||||||
end: l,
|
end: l,
|
||||||
|
@ -152,7 +152,7 @@ function highlight(e) {
|
||||||
|
|
||||||
function togglev() {
|
function togglev() {
|
||||||
if (
|
if (
|
||||||
document.getElementsByTagName("ol")[0].style.listStyle.substr(0, 4) ==
|
document.getElementsByTagName("ol")[0].style.listStyle.substr(0, 4) ===
|
||||||
"none"
|
"none"
|
||||||
) {
|
) {
|
||||||
document.getElementsByTagName("ol")[0].style.listStyle = "decimal";
|
document.getElementsByTagName("ol")[0].style.listStyle = "decimal";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<link rel="stylesheet" href="theme/bulma/css/bulma-tagsinput.min.css"/>
|
<link rel="stylesheet" href="theme/bulma/css/bulma-tagsinput.min.css"/>
|
||||||
<script>
|
<script>
|
||||||
function openreport() {
|
function openreport() {
|
||||||
var x = document.getElementById("panel");
|
const x = document.getElementById("panel");
|
||||||
if (x.style.display === "none") {
|
if (x.style.display === "none") {
|
||||||
x.style.display = "block";
|
x.style.display = "block";
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function closereport() {
|
function closereport() {
|
||||||
var x = document.getElementById("panel");
|
const x = document.getElementById("panel");
|
||||||
if (x.style.display === "none") {
|
if (x.style.display === "none") {
|
||||||
x.style.display = "block";
|
x.style.display = "block";
|
||||||
} else {
|
} else {
|
||||||
|
|
2
user.php
2
user.php
|
@ -67,5 +67,5 @@ updatePageViews();
|
||||||
$csrf_token = setupCsrfToken();
|
$csrf_token = setupCsrfToken();
|
||||||
$page_title = 'Profile of ' . $profile_username;
|
$page_title = 'Profile of ' . $profile_username;
|
||||||
$page_template = 'user_profile';
|
$page_template = 'user_profile';
|
||||||
array_push($script_bundles, 'user_profile');
|
$script_bundles[] = 'user_profile';
|
||||||
require_once('theme/' . $default_theme . '/common.php');
|
require_once('theme/' . $default_theme . '/common.php');
|
||||||
|
|
Loading…
Add table
Reference in a new issue