mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
Various fixes of errors.
This commit is contained in:
parent
f1e3166eec
commit
49a7afb694
9 changed files with 49 additions and 41 deletions
|
@ -12,6 +12,10 @@ class Paste extends Model {
|
||||||
protected $table = 'pastes';
|
protected $table = 'pastes';
|
||||||
|
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
protected $casts = [
|
||||||
|
'visible' => 'integer',
|
||||||
|
'encrypt' => 'boolean'
|
||||||
|
];
|
||||||
|
|
||||||
public function user() {
|
public function user() {
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
|
|
38
index.php
38
index.php
|
@ -81,6 +81,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
|
||||||
$error = validatePasteFields();
|
$error = validatePasteFields();
|
||||||
|
|
||||||
|
|
||||||
if ($error !== null) {
|
if ($error !== null) {
|
||||||
goto OutPut;
|
goto OutPut;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +93,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
goto OutPut;
|
goto OutPut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tags = Tag::parseTagInput($tag_input);
|
||||||
|
|
||||||
|
if (count($tags) < 1) {
|
||||||
|
$error = 'You must specify at least 1 tag.';
|
||||||
|
goto OutPut;
|
||||||
|
} elseif (count($tags) > 32) {
|
||||||
|
$error = 'You must specify at most 32 tags.';
|
||||||
|
goto OutPut;
|
||||||
|
}
|
||||||
|
|
||||||
$editing = isset($_POST['edit']);
|
$editing = isset($_POST['edit']);
|
||||||
|
|
||||||
$paste_title = trim($_POST['title']);
|
$paste_title = trim($_POST['title']);
|
||||||
|
@ -126,20 +137,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
// Edit existing paste or create new?
|
// Edit existing paste or create new?
|
||||||
if ($editing) {
|
if ($editing) {
|
||||||
$paste = Paste::find($_POST['paste_id']);
|
$paste = Paste::find($_POST['paste_id']);
|
||||||
if ($current_user &&
|
if (can('edit', $paste)) {
|
||||||
$current_user->id === $paste->user_id) {
|
|
||||||
$paste_id = $paste->id;
|
|
||||||
$paste->update([
|
$paste->update([
|
||||||
'title' => $paste_title,
|
'title' => $paste_title,
|
||||||
'content' => $paste_content,
|
'content' => $paste_content,
|
||||||
'visible' => $paste_visibility,
|
'visible' => $paste_visibility,
|
||||||
'code' => $paste_code,
|
'code' => $paste_code,
|
||||||
'expiry' => $expires,
|
'expiry' => $expires,
|
||||||
'password' => $paste_password,
|
'password' => $paste_password,
|
||||||
'ip' => $ip
|
'ip' => $ip
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$paste->replaceTags(Tag::parseTagInput($tag_input));
|
$paste->replaceTags($tags);
|
||||||
$redis->del('ajax_pastes'); /* Expire from Redis so the edited paste shows up */
|
$redis->del('ajax_pastes'); /* Expire from Redis so the edited paste shows up */
|
||||||
} else {
|
} else {
|
||||||
$error = 'You must be logged in to do that.';
|
$error = 'You must be logged in to do that.';
|
||||||
|
@ -161,13 +170,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$paste->user()->associate($paste_owner);
|
$paste->user()->associate($paste_owner);
|
||||||
$paste->save();
|
$paste->save();
|
||||||
|
|
||||||
$paste->replaceTags(Tag::parseTagInput($tag_input));
|
$paste->replaceTags($tags);
|
||||||
|
|
||||||
$paste_id = $new_paste->id;
|
if ($paste_visibility == Paste::VISIBILITY_PUBLIC) {
|
||||||
|
|
||||||
if ($p_visible == '0') {
|
|
||||||
addToSitemap($paste, $priority, $changefreq);
|
addToSitemap($paste, $priority, $changefreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
$redis->del('ajax_pastes'); /* Expire from Redis so the new paste shows up */
|
$redis->del('ajax_pastes'); /* Expire from Redis so the new paste shows up */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ if (isset($_POST['forgot'])) {
|
||||||
if (empty($_POST['password']) || empty($_POST['username'])) {
|
if (empty($_POST['password']) || empty($_POST['username'])) {
|
||||||
$error = 'All fields must be filled out.';
|
$error = 'All fields must be filled out.';
|
||||||
} elseif (strlen($username) > 25) {
|
} elseif (strlen($username) > 25) {
|
||||||
$error = 'Username too long.'; // "Username already taken.";
|
$error = 'Username too long.';
|
||||||
} elseif (!preg_match('/^[A-Za-z0-9._\\-]+$/', $username)) {
|
} elseif (!preg_match('/^[A-Za-z0-9._\\-]+$/', $username)) {
|
||||||
$error = 'Username is invalid - please use A-Za-z0-9, periods, hyphens, and underscores only.';
|
$error = 'Username is invalid - please use A-Za-z0-9, periods, hyphens, and underscores only.';
|
||||||
} else {
|
} else {
|
||||||
|
|
28
paste.php
28
paste.php
|
@ -35,14 +35,12 @@ function getUserRecommended(User $user) {
|
||||||
return $query->fetchAll();*/
|
return $query->fetchAll();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
$paste_id = intval(trim($_REQUEST['id']));
|
|
||||||
|
|
||||||
updatePageViews();
|
updatePageViews();
|
||||||
|
|
||||||
// This is used in the theme files.
|
// This is used in the theme files.
|
||||||
$totalpastes = Paste::count();
|
$totalpastes = Paste::count();
|
||||||
|
|
||||||
$paste = Paste::with('user')->find($paste_id);
|
$paste = Paste::with('user')->find((int) trim($_REQUEST['id']));
|
||||||
$is_private = false;
|
$is_private = false;
|
||||||
$error = null;
|
$error = null;
|
||||||
|
|
||||||
|
@ -73,12 +71,10 @@ $using_highlighter = $paste_code !== 'pastedown';
|
||||||
$fav_count = $paste->favouriters()->count();
|
$fav_count = $paste->favouriters()->count();
|
||||||
|
|
||||||
$p_content = $paste->content;
|
$p_content = $paste->content;
|
||||||
$p_visible = $paste->visible;
|
|
||||||
$p_password = $paste->password;
|
$p_password = $paste->password;
|
||||||
$p_encrypt = (bool) $paste->encrypt;
|
|
||||||
$paste_is_favourited = $current_user !== null && $current_user->favourites->where('id', $paste->id)->count() === 1;
|
$paste_is_favourited = $current_user !== null && $current_user->favourites->where('id', $paste->id)->count() === 1;
|
||||||
|
|
||||||
$is_private = $p_visible === '2';
|
$is_private = $paste->visible === Paste::VISIBILITY_PRIVATE;
|
||||||
|
|
||||||
if (!can('view', $paste)) {
|
if (!can('view', $paste)) {
|
||||||
$error = 'This is a private paste. If you created this paste, please log in to view it.';
|
$error = 'This is a private paste. If you created this paste, please log in to view it.';
|
||||||
|
@ -118,13 +114,13 @@ if ($password_required && !in_array($paste->id, $password_ok_pastes)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PP_MOD_REWRITE) {
|
if (PP_MOD_REWRITE) {
|
||||||
$p_download = "download/$paste_id";
|
$p_download = "download/$paste->id";
|
||||||
$p_raw = "raw/$paste_id";
|
$p_raw = "raw/$paste->id";
|
||||||
$p_embed = "embed/$paste_id";
|
$p_embed = "embed/$paste->id";
|
||||||
} else {
|
} else {
|
||||||
$p_download = "paste.php?download&id=$paste_id";
|
$p_download = "paste.php?download&id=$paste->id";
|
||||||
$p_raw = "paste.php?raw&id=$paste_id";
|
$p_raw = "paste.php?raw&id=$paste->id";
|
||||||
$p_embed = "paste.php?embed&id=$paste_id";
|
$p_embed = "paste.php?embed&id=$paste->id";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Expiry */
|
/* Expiry */
|
||||||
|
@ -150,7 +146,7 @@ if (isset($_POST['fave']) && $current_user) {
|
||||||
$paste_is_favourited = !$paste_is_favourited;
|
$paste_is_favourited = !$paste_is_favourited;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($p_encrypt == 1) {
|
if ($paste->encrypt) {
|
||||||
$p_content = openssl_decrypt($p_content, PP_ENCRYPTION_ALGO, PP_ENCRYPTION_KEY);
|
$p_content = openssl_decrypt($p_content, PP_ENCRYPTION_ALGO, PP_ENCRYPTION_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,13 +198,13 @@ if ($paste_code === "pastedown") {
|
||||||
|
|
||||||
// Embed view after highlighting is applied so that $p_code is syntax highlighted as it should be.
|
// Embed view after highlighting is applied so that $p_code is syntax highlighted as it should be.
|
||||||
if (isset($_GET['embed'])) {
|
if (isset($_GET['embed'])) {
|
||||||
embedView($paste_id, $paste_title, $p_content, $title);
|
embedView($paste->id, $paste->title, $p_content, $title);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// View counter
|
// View counter
|
||||||
if (!isRequesterLikelyBot() && @$_SESSION['not_unique'] !== $paste_id) {
|
if (!isRequesterLikelyBot() && @$_SESSION['not_unique'] !== $paste->id) {
|
||||||
$_SESSION['not_unique'] = $paste_id;
|
$_SESSION['not_unique'] = $paste->id;
|
||||||
$paste->views += 1;
|
$paste->views += 1;
|
||||||
$paste->save();
|
$paste->save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ require_once('includes/passwords.php');
|
||||||
use PonePaste\Models\Paste;
|
use PonePaste\Models\Paste;
|
||||||
|
|
||||||
if ($current_user === null) {
|
if ($current_user === null) {
|
||||||
header("Location: ./login.php");
|
header("Location: /login");
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ $flashes = getFlashes();
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
<footer class="modal-card-foot">
|
<footer class="modal-card-foot">
|
||||||
<a href="../login.php?forgotpassw">Forgot Password?</a>
|
<a href="/forgot">Forgot Password?</a>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
<div id="regid" class="content-tab" style="display:none">
|
<div id="regid" class="content-tab" style="display:none">
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input type="hidden" name="id" value="<?= $paste_id; ?>" />
|
<input type="hidden" name="id" value="<?= $paste->id; ?>" />
|
||||||
<input type="hidden" name="csrf_token" value="<?= $csrf_token ?>" />
|
<input type="hidden" name="csrf_token" value="<?= $csrf_token ?>" />
|
||||||
<input type="password" class="input" name="mypass"
|
<input type="password" class="input" name="mypass"
|
||||||
placeholder="Password" />
|
placeholder="Password" />
|
||||||
|
|
|
@ -165,9 +165,9 @@
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<h1 class="title is-4">Where to?</h1>
|
<h1 class="title is-4">Where to?</h1>
|
||||||
<a href="login.php?login">Login</a><br/>
|
<a href="/login">Login</a><br/>
|
||||||
<a href="login.php?registeraccount">Register</a> <br/>
|
<a href="/register">Register</a> <br/>
|
||||||
<a href="login.php?forgotpassw">Forgot Password</a><br/>
|
<a href="/forgot">Forgot Password</a><br/>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -83,7 +83,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--<div class="column">
|
<!--<div class="column">
|
||||||
<input type="hidden" name="reppasteid" value="<?php echo($paste_id); ?>">
|
<input type="hidden" name="reppasteid" value="<?php echo($paste->id); ?>">
|
||||||
<div>
|
<div>
|
||||||
<div style="text-align: center;">
|
<div style="text-align: center;">
|
||||||
<div id="reportbutton" class="column">
|
<div id="reportbutton" class="column">
|
||||||
|
@ -171,7 +171,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
|
||||||
} else {
|
} else {
|
||||||
echo 'paste.php?embed&id=';
|
echo 'paste.php?embed&id=';
|
||||||
}
|
}
|
||||||
echo $paste_id . '"></script>'; ?>' readonly />
|
echo $paste->id . '"></script>'; ?>' readonly />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -326,7 +326,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
|
||||||
$visibility_codes[] = '2';
|
$visibility_codes[] = '2';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo optionsForSelect($visibility_names, $visibility_codes, $p_visible);
|
echo optionsForSelect($visibility_names, $visibility_codes, $paste->visible);
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue