This commit is contained in:
Floorb 2021-08-13 16:43:38 -04:00
parent f1742c65d9
commit e7ad8bdde1
12 changed files with 97 additions and 72 deletions

View file

@ -75,8 +75,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
</div>'; </div>';
} elseif ($action === 'captcha') { } elseif ($action === 'captcha') {
$new_captcha = [ $new_captcha = [
'enabled' => ($_POST['captcha']['enabled'] === '1'), 'enabled' => ($_POST['captcha']['enabled'] === '1'),
'multiple' => ($_POST['captcha']['multiple'] === '1') 'multiple' => ($_POST['captcha']['multiple'] === '1')
]; ];
$current_config['captcha'] = $new_captcha; $current_config['captcha'] = $new_captcha;
@ -157,67 +157,81 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
action="<?= $_SERVER['PHP_SELF']; ?>"> action="<?= $_SERVER['PHP_SELF']; ?>">
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_name">Site Name</label> <label class="col-sm-2 control-label form-label" for="site_info_name">Site
Name</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" class="form-control" name="site_info[site_name]" id="site_info_name" <input type="text" class="form-control" name="site_info[site_name]"
id="site_info_name"
placeholder="The name of your site" placeholder="The name of your site"
value="<?= pp_html_escape($current_site_info['site_name']); ?>"> value="<?= pp_html_escape($current_site_info['site_name']); ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_title">Site Title</label> <label class="col-sm-2 control-label form-label" for="site_info_title">Site
Title</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" class="form-control" name="site_info[title]" id="site_info_title" <input type="text" class="form-control" name="site_info[title]"
id="site_info_title"
placeholder="Site title tag" placeholder="Site title tag"
value="<?= pp_html_escape($current_site_info['title']); ?>"> value="<?= pp_html_escape($current_site_info['title']); ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_baseurl">Domain name</label> <label class="col-sm-2 control-label form-label" for="site_info_baseurl">Domain
name</label>
<div class="col-sm-1" style="padding:5px;"> <div class="col-sm-1" style="padding:5px;">
<span class="badge"> <span class="badge">
<?= !empty($_SERVER['HTTPS']) ? 'https://' : 'http://' ?>; <?= !empty($_SERVER['HTTPS']) ? 'https://' : 'http://' ?>;
</span> </span>
</div> </div>
<div class="col-sm-5"> <div class="col-sm-5">
<input type="text" class="form-control" name="site_info[baseurl]" id="site_info_baseurl" <input type="text" class="form-control" name="site_info[baseurl]"
id="site_info_baseurl"
placeholder="eg: ponepaste.org (no trailing slash)" placeholder="eg: ponepaste.org (no trailing slash)"
value="<?= pp_html_escape($current_site_info['baseurl']); ?>"> value="<?= pp_html_escape($current_site_info['baseurl']); ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_description">Site Description</label> <label class="col-sm-2 control-label form-label"
for="site_info_description">Site Description</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" class="form-control" name="site_info[description]" id="site_info_description" <input type="text" class="form-control" name="site_info[description]"
id="site_info_description"
placeholder="Site description" placeholder="Site description"
value="<?= pp_html_escape($current_site_info['description']); ?>"> value="<?= pp_html_escape($current_site_info['description']); ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_keywords">Site Keywords</label> <label class="col-sm-2 control-label form-label" for="site_info_keywords">Site
Keywords</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" class="form-control" name="site_info[keywords]" id="site_info_keywords" <input type="text" class="form-control" name="site_info[keywords]"
id="site_info_keywords"
placeholder="Keywords (separated by a comma)" placeholder="Keywords (separated by a comma)"
value="<?= pp_html_escape($current_site_info['keywords']); ?>"> value="<?= pp_html_escape($current_site_info['keywords']); ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_email">Admin Email</label> <label class="col-sm-2 control-label form-label" for="site_info_email">Admin
Email</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" class="form-control" name="site_info[email]" placeholder="Email" id="site_info_email" <input type="text" class="form-control" name="site_info[email]"
placeholder="Email" id="site_info_email"
value="<?= pp_html_escape($current_site_info['email']); ?>"> value="<?= pp_html_escape($current_site_info['email']); ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_additional_scripts">Additional Site <label class="col-sm-2 control-label form-label"
for="site_info_additional_scripts">Additional Site
Scripts</label> Scripts</label>
<div class="col-sm-10"> <div class="col-sm-10">
<textarea class="form-control" id="additional_scripts" id="site_info_additional_scripts" <textarea class="form-control" id="additional_scripts"
id="site_info_additional_scripts"
name="site_info[additional_scripts]" name="site_info[additional_scripts]"
rows="8"><?= pp_html_escape($current_site_info['title']); ?></textarea> rows="8"><?= pp_html_escape($current_site_info['title']); ?></textarea>
</div> </div>
@ -274,15 +288,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
action="<?= $_SERVER['PHP_SELF']; ?>"> action="<?= $_SERVER['PHP_SELF']; ?>">
<div class="checkbox checkbox-primary"> <div class="checkbox checkbox-primary">
<input <?php if ($current_captcha['enabled']) echo 'checked="true"'; ?> type="checkbox" <input <?php if ($current_captcha['enabled']) echo 'checked="true"'; ?>
name="captcha[enabked]" type="checkbox"
id="captcha_enabled"> name="captcha[enabked]"
id="captcha_enabled">
<label for="captcha_enabled">Enable Captcha</label> <label for="captcha_enabled">Enable Captcha</label>
</div> </div>
<br/> <br/>
<div class="form-group row"> <div class="form-group row">
<label for="captcha_mode" class="col-sm-1 col-form-label">Captcha Type</label> <label for="captcha_mode" class="col-sm-1 col-form-label">Captcha
Type</label>
<select id="captcha_mode" class="selectpicker" name="captcha[mode]"> <select id="captcha_mode" class="selectpicker" name="captcha[mode]">
<?php <?php
if ($current_captcha['mode'] == "Easy") { if ($current_captcha['mode'] == "Easy") {
@ -311,9 +327,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Internal Captcha Settings: Internal Captcha Settings:
</div> </div>
<div class="checkbox checkbox-primary"> <div class="checkbox checkbox-primary">
<input <?php if ($current_captcha['multiple']) echo 'checked="checked"'; ?> type="checkbox" <input <?php if ($current_captcha['multiple']) echo 'checked="checked"'; ?>
name="captcha[multiple]" type="checkbox"
id="captcha_multiple"> name="captcha[multiple]"
id="captcha_multiple">
<label for="captcha_multiple">Enable multiple backgrounds</label> <label for="captcha_multiple">Enable multiple backgrounds</label>
</div> </div>
<br/> <br/>
@ -322,7 +339,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Characters</label> Characters</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" id="captcha_allowed" name="captcha[allowed]" <input type="text" id="captcha_allowed" name="captcha[allowed]"
placeholder="Allowed Characters" value="<?php echo $current_captcha['allowed']; ?>"> placeholder="Allowed Characters"
value="<?php echo $current_captcha['allowed']; ?>">
</div> </div>
</div> </div>
@ -331,7 +349,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Colour</label> Colour</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" id="captcha_colour" name="captcha[colour]" <input type="text" id="captcha_colour" name="captcha[colour]"
placeholder="Captcha Text Colour" value="<?= $current_captcha['colour']; ?>"> placeholder="Captcha Text Colour"
value="<?= $current_captcha['colour']; ?>">
</div> </div>
</div> </div>

View file

@ -721,7 +721,7 @@
that.setSelected(clickedIndex, true); that.setSelected(clickedIndex, true);
} else { } else {
var maxOptionsArr = (typeof that.options.maxOptionsText === 'function') ? var maxOptionsArr = (typeof that.options.maxOptionsText === 'function') ?
that.options.maxOptionsText(maxOptions, maxOptionsGrp) : that.options.maxOptionsText, that.options.maxOptionsText(maxOptions, maxOptionsGrp) : that.options.maxOptionsText,
maxTxt = maxOptionsArr[0].replace('{n}', maxOptions), maxTxt = maxOptionsArr[0].replace('{n}', maxOptions),
maxTxtGrp = maxOptionsArr[1].replace('{n}', maxOptionsGrp), maxTxtGrp = maxOptionsArr[1].replace('{n}', maxOptionsGrp),
$notify = $('<div class="notify"></div>'); $notify = $('<div class="notify"></div>');

View file

@ -26,7 +26,7 @@ class DatabaseHandle {
return $stmt; return $stmt;
} }
public function querySelectOne(string $query, array $params = null) : array | null { public function querySelectOne(string $query, array $params = null) : array|null {
$stmt = $this->query($query, $params); $stmt = $this->query($query, $params);
if ($row = $stmt->fetch()) { if ($row = $stmt->fetch()) {
@ -39,6 +39,6 @@ class DatabaseHandle {
public function queryInsert(string $query, array $params = null) : int { public function queryInsert(string $query, array $params = null) : int {
$this->query($query, $params); $this->query($query, $params);
return (int) $this->conn->lastInsertId(); return (int)$this->conn->lastInsertId();
} }
} }

View file

@ -6,7 +6,7 @@ class Tag {
public string $slug; public string $slug;
public function __construct(array $row) { public function __construct(array $row) {
$this->id = (int) $row['id']; $this->id = (int)$row['id'];
$this->name = $row['name']; $this->name = $row['name'];
$this->slug = $row['slug']; $this->slug = $row['slug'];
} }
@ -22,13 +22,13 @@ class Tag {
$new_tag_id = $conn->queryInsert('INSERT INTO tags (name, slug) VALUES (?, ?)', [$name, $new_slug]); $new_tag_id = $conn->queryInsert('INSERT INTO tags (name, slug) VALUES (?, ?)', [$name, $new_slug]);
return new Tag([ return new Tag([
'id' => $new_tag_id, 'id' => $new_tag_id,
'name' => $name, 'name' => $name,
'slug' => $new_slug 'slug' => $new_slug
]); ]);
} }
public static function findBySlug(DatabaseHandle $conn, string $slug) : Tag | null { public static function findBySlug(DatabaseHandle $conn, string $slug) : Tag|null {
if ($row = $conn->querySelectOne('SELECT id, name, slug FROM tags WHERE slug = ?', [$slug])) { if ($row = $conn->querySelectOne('SELECT id, name, slug FROM tags WHERE slug = ?', [$slug])) {
return new Tag($row); return new Tag($row);
} }
@ -72,7 +72,7 @@ class Tag {
$cleanTags = []; $cleanTags = [];
foreach (explode(',', $tagInput) as $tagName) { foreach (explode(',', $tagInput) as $tagName) {
$cleanName = Tag::cleanTagName($tagName); $cleanName = Tag::cleanTagName($tagName);
if (!empty($cleanName)) { if (!empty($cleanName)) {
array_push($cleanTags, $cleanName); array_push($cleanTags, $cleanName);
@ -85,7 +85,7 @@ class Tag {
private static function encodeSlug(string $name) : string { private static function encodeSlug(string $name) : string {
/* This one's a doozy. */ /* This one's a doozy. */
$name = str_replace( $name = str_replace(
['-', '/', '\\', ':', '.', '+'], ['-', '/', '\\', ':', '.', '+'],
['-dash-', '-fwslash-', '-bwslash-', '-colon-', '-dot-', '-plus-'], ['-dash-', '-fwslash-', '-bwslash-', '-colon-', '-dot-', '-plus-'],
$name $name
); );

View file

@ -130,7 +130,7 @@ $noguests = $disableguest;
// CAPTCHA configuration // CAPTCHA configuration
$captcha_config = $site_info['captcha']; $captcha_config = $site_info['captcha'];
$captcha_enabled = (bool) $captcha_config['enabled']; $captcha_enabled = (bool)$captcha_config['enabled'];
// Prevent a potential LFI (you never know :p) // Prevent a potential LFI (you never know :p)
$lang_file = "${default_lang}.php"; $lang_file = "${default_lang}.php";

View file

@ -73,7 +73,7 @@ function sandwitch($str) {
function getevent($conn, $event_name, $count) { function getevent($conn, $event_name, $count) {
$query = $conn->prepare("SELECT id, visible, title, date, now_time, views, member, tagsys FROM pastes WHERE visible='1' AND tagsys LIKE '%?%' $query = $conn->prepare("SELECT id, visible, title, date, now_time, views, member FROM pastes WHERE visible='1' AND tagsys LIKE '%?%'
ORDER BY RAND () LIMIT 0, ?"); ORDER BY RAND () LIMIT 0, ?");
$query->execute([$event_name, $count]); $query->execute([$event_name, $count]);
return $query->fetchAll(); return $query->fetchAll();

View file

@ -27,17 +27,17 @@ require_once('includes/captcha.php');
require_once('includes/functions.php'); require_once('includes/functions.php');
require_once('includes/Tag.class.php'); require_once('includes/Tag.class.php');
function verifyCaptcha() : string | bool { function verifyCaptcha() : string|bool {
global $captcha_config; global $captcha_config;
global $lang; global $lang;
global $current_user; global $current_user;
if ($captcha_config['enabled'] && !$current_user) { if ($captcha_config['enabled'] && !$current_user) {
$scode = strtolower(htmlentities(Trim($_POST['scode']))); $scode = strtolower(htmlentities(Trim($_POST['scode'])));
$cap_code = strtolower($_SESSION['captcha']['code']); $cap_code = strtolower($_SESSION['captcha']['code']);
if ($cap_code !== $scode) { if ($cap_code !== $scode) {
return $lang['image_wrong']; // Wrong captcha. return $lang['image_wrong']; // Wrong captcha.
} }
} }
return true; return true;
@ -157,7 +157,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Edit existing paste or create new? // Edit existing paste or create new?
if ($editing) { if ($editing) {
if ($current_user && if ($current_user &&
$current_user->user_id === (int) $conn->querySelectOne('SELECT user_id FROM pastes WHERE id = ?', [$_POST['paste_id']])['user_id']) { $current_user->user_id === (int)$conn->querySelectOne('SELECT user_id FROM pastes WHERE id = ?', [$_POST['paste_id']])['user_id']) {
$paste_id = intval($_POST['paste_id']); $paste_id = intval($_POST['paste_id']);
$conn->query( $conn->query(

View file

@ -39,7 +39,7 @@ $fav_count = intval($query->fetch(PDO::FETCH_NUM)[0]);
// Get paste info // Get paste info
$row = $conn->querySelectOne( $row = $conn->querySelectOne(
'SELECT title, content, visible, code, expiry, pastes.password AS password, created_at, updated_at, encrypt, views, tagsys, users.username AS member, users.id AS user_id 'SELECT title, content, visible, code, expiry, pastes.password AS password, created_at, updated_at, encrypt, views, users.username AS member, users.id AS user_id
FROM pastes FROM pastes
INNER JOIN users ON users.id = pastes.user_id INNER JOIN users ON users.id = pastes.user_id
WHERE pastes.id = ?', [$paste_id]); WHERE pastes.id = ?', [$paste_id]);

View file

@ -721,7 +721,7 @@
that.setSelected(clickedIndex, true); that.setSelected(clickedIndex, true);
} else { } else {
var maxOptionsArr = (typeof that.options.maxOptionsText === 'function') ? var maxOptionsArr = (typeof that.options.maxOptionsText === 'function') ?
that.options.maxOptionsText(maxOptions, maxOptionsGrp) : that.options.maxOptionsText, that.options.maxOptionsText(maxOptions, maxOptionsGrp) : that.options.maxOptionsText,
maxTxt = maxOptionsArr[0].replace('{n}', maxOptions), maxTxt = maxOptionsArr[0].replace('{n}', maxOptions),
maxTxtGrp = maxOptionsArr[1].replace('{n}', maxOptionsGrp), maxTxtGrp = maxOptionsArr[1].replace('{n}', maxOptionsGrp),
$notify = $('<div class="notify"></div>'); $notify = $('<div class="notify"></div>');

View file

@ -2341,8 +2341,8 @@
} }
var distances = sortByDistanceDesc(this.getContainerDimensions(), var distances = sortByDistanceDesc(this.getContainerDimensions(),
pointer, pointer,
lastPointer), lastPointer),
i = distances.length i = distances.length
while (i--) { while (i--) {
@ -2513,8 +2513,8 @@
}, },
searchValidTarget: function (pointer, lastPointer) { searchValidTarget: function (pointer, lastPointer) {
var distances = sortByDistanceDesc(this.getItemDimensions(), var distances = sortByDistanceDesc(this.getItemDimensions(),
pointer, pointer,
lastPointer), lastPointer),
i = distances.length, i = distances.length,
rootGroup = this.rootGroup, rootGroup = this.rootGroup,
validTarget = !rootGroup.options.isValidTarget || validTarget = !rootGroup.options.isValidTarget ||

View file

@ -22,14 +22,14 @@
function setupTagsInput() { function setupTagsInput() {
const tagsInput = document.getElementById('tags-with-source'); const tagsInput = document.getElementById('tags-with-source');
new BulmaTagsInput(tagsInput, { new BulmaTagsInput(tagsInput, {
source: async function(value) { source: async function (value) {
// Value equal input value // Value equal input value
// We can then use it to request data from external API // We can then use it to request data from external API
return await fetch("/api/tags_autocomplete.php?tag=" + encodeURIComponent(value)) return await fetch("/api/tags_autocomplete.php?tag=" + encodeURIComponent(value))
.then(function(response) { .then(function (response) {
return response.json(); return response.json();
}); });
} }
}); });
} }
@ -124,7 +124,9 @@
<div class="list-widget pagination-content"> <div class="list-widget pagination-content">
<?php <?php
$res = getrandom($conn, 10); $res = getrandom($conn, 10);
foreach ($res as $index => $row) { foreach ($res
as $index => $row) {
$title = Trim($row['title']); $title = Trim($row['title']);
$titlehov = ($row['title']); $titlehov = ($row['title']);
$p_member = Trim($row['member']); $p_member = Trim($row['member']);
@ -242,8 +244,10 @@
<div class="field"> <div class="field">
<label class="label">Tags</label> <label class="label">Tags</label>
<div class="control"> <div class="control">
<input id="tags-with-source" name="tag_input" class="input" data-max-tags="10" <input id="tags-with-source" name="tag_input" class="input"
data-max-chars="40" type="text" data-item-text="name" data-item-value="name" data-max-tags="10"
data-max-chars="40" type="text" data-item-text="name"
data-item-value="name"
data-case-sensitive="false" placeholder="10 Tags Maximum" data-case-sensitive="false" placeholder="10 Tags Maximum"
value="<?php echo (isset($_POST['tag_input'])) ? $_POST['tag_input'] : ''; // Pre-populate if we come here on an error" ?>"> value="<?php echo (isset($_POST['tag_input'])) ? $_POST['tag_input'] : ''; // Pre-populate if we come here on an error" ?>">
</div> </div>
@ -391,15 +395,15 @@
<div class="column is-4"> <div class="column is-4">
<!-- CAPTCHA --> <!-- CAPTCHA -->
<?php if ($captcha_config['enabled'] && $current_user === null): ?> <?php if ($captcha_config['enabled'] && $current_user === null): ?>
<div class="is-one-quarter"> <div class="is-one-quarter">
<div class="notification"> <div class="notification">
<span class="tags are-large"><?php echo '<img src="' . $_SESSION['captcha']['image_src'] . '" alt="CAPTCHA" class="imagever">'; ?></span> <span class="tags are-large"><?php echo '<img src="' . $_SESSION['captcha']['image_src'] . '" alt="CAPTCHA" class="imagever">'; ?></span>
<input type="text" class="input" name="scode" value="" <input type="text" class="input" name="scode" value=""
placeholder="<?php echo $lang['entercode']; ?>"> placeholder="<?php echo $lang['entercode']; ?>">
<p class="is-size-6 has-text-grey-light has-text-left mt-2">and press <p class="is-size-6 has-text-grey-light has-text-left mt-2">and press
"Enter"</p> "Enter"</p>
</div>
</div> </div>
</div>
<?php endif; ?> <?php endif; ?>
} ?> } ?>
</div> </div>

View file

@ -143,7 +143,7 @@ $protocol = paste_protocol();
<table id="archive" class="table is-fullwidth is-hoverable"> <table id="archive" class="table is-fullwidth is-hoverable">
<thead> <thead>
<tr> <tr>
<td class="td-right" ><?php echo $lang['pastetitle']; ?></td> <td class="td-right"><?php echo $lang['pastetitle']; ?></td>
<td class="td-center"><?php echo $lang['pastetime']; ?></td> <td class="td-center"><?php echo $lang['pastetime']; ?></td>
<?php if ($is_current_user) { <?php if ($is_current_user) {
echo "<td class='td-center'>" . $lang['visibility'] . "</td>"; echo "<td class='td-center'>" . $lang['visibility'] . "</td>";
@ -179,7 +179,9 @@ $protocol = paste_protocol();
$p_dateui = $p_date->format("d F Y"); $p_dateui = $p_date->format("d F Y");
$p_views = Trim($row['views']); $p_views = Trim($row['views']);
$p_visible = intval($row['visible']); $p_visible = intval($row['visible']);
$tagArray = array_map(function($tag) { return $tag['name']; }, getPasteTags($conn, $p_id)); $tagArray = array_map(function ($tag) {
return $tag['name'];
}, getPasteTags($conn, $p_id));
$p_tags = implode(',', $tagArray); $p_tags = implode(',', $tagArray);
@ -262,7 +264,7 @@ $protocol = paste_protocol();
</thead> </thead>
<tbody> <tbody>
<?php <?php
foreach ($profile_favs as $index => $row) { foreach ($profile_favs as $row) {
$ftitle = Trim($row['title']); $ftitle = Trim($row['title']);
$f_id = Trim($row['paste_id']); $f_id = Trim($row['paste_id']);
$f_date = new DateTime($row['f_time']); $f_date = new DateTime($row['f_time']);