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 $guarded = [];
|
||||
protected $casts = [
|
||||
'visible' => 'integer',
|
||||
'encrypt' => 'boolean'
|
||||
];
|
||||
|
||||
public function user() {
|
||||
return $this->belongsTo(User::class);
|
||||
|
|
24
index.php
24
index.php
|
@ -81,6 +81,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
|
||||
$error = validatePasteFields();
|
||||
|
||||
|
||||
if ($error !== null) {
|
||||
goto OutPut;
|
||||
}
|
||||
|
@ -92,6 +93,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
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']);
|
||||
|
||||
$paste_title = trim($_POST['title']);
|
||||
|
@ -126,9 +137,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
// Edit existing paste or create new?
|
||||
if ($editing) {
|
||||
$paste = Paste::find($_POST['paste_id']);
|
||||
if ($current_user &&
|
||||
$current_user->id === $paste->user_id) {
|
||||
$paste_id = $paste->id;
|
||||
if (can('edit', $paste)) {
|
||||
$paste->update([
|
||||
'title' => $paste_title,
|
||||
'content' => $paste_content,
|
||||
|
@ -139,7 +148,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
'ip' => $ip
|
||||
]);
|
||||
|
||||
$paste->replaceTags(Tag::parseTagInput($tag_input));
|
||||
$paste->replaceTags($tags);
|
||||
$redis->del('ajax_pastes'); /* Expire from Redis so the edited paste shows up */
|
||||
} else {
|
||||
$error = 'You must be logged in to do that.';
|
||||
|
@ -161,13 +170,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
$paste->user()->associate($paste_owner);
|
||||
$paste->save();
|
||||
|
||||
$paste->replaceTags(Tag::parseTagInput($tag_input));
|
||||
$paste->replaceTags($tags);
|
||||
|
||||
$paste_id = $new_paste->id;
|
||||
|
||||
if ($p_visible == '0') {
|
||||
if ($paste_visibility == Paste::VISIBILITY_PUBLIC) {
|
||||
addToSitemap($paste, $priority, $changefreq);
|
||||
}
|
||||
|
||||
$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'])) {
|
||||
$error = 'All fields must be filled out.';
|
||||
} elseif (strlen($username) > 25) {
|
||||
$error = 'Username too long.'; // "Username already taken.";
|
||||
$error = 'Username too long.';
|
||||
} elseif (!preg_match('/^[A-Za-z0-9._\\-]+$/', $username)) {
|
||||
$error = 'Username is invalid - please use A-Za-z0-9, periods, hyphens, and underscores only.';
|
||||
} else {
|
||||
|
|
28
paste.php
28
paste.php
|
@ -35,14 +35,12 @@ function getUserRecommended(User $user) {
|
|||
return $query->fetchAll();*/
|
||||
}
|
||||
|
||||
$paste_id = intval(trim($_REQUEST['id']));
|
||||
|
||||
updatePageViews();
|
||||
|
||||
// This is used in the theme files.
|
||||
$totalpastes = Paste::count();
|
||||
|
||||
$paste = Paste::with('user')->find($paste_id);
|
||||
$paste = Paste::with('user')->find((int) trim($_REQUEST['id']));
|
||||
$is_private = false;
|
||||
$error = null;
|
||||
|
||||
|
@ -73,12 +71,10 @@ $using_highlighter = $paste_code !== 'pastedown';
|
|||
$fav_count = $paste->favouriters()->count();
|
||||
|
||||
$p_content = $paste->content;
|
||||
$p_visible = $paste->visible;
|
||||
$p_password = $paste->password;
|
||||
$p_encrypt = (bool) $paste->encrypt;
|
||||
$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)) {
|
||||
$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) {
|
||||
$p_download = "download/$paste_id";
|
||||
$p_raw = "raw/$paste_id";
|
||||
$p_embed = "embed/$paste_id";
|
||||
$p_download = "download/$paste->id";
|
||||
$p_raw = "raw/$paste->id";
|
||||
$p_embed = "embed/$paste->id";
|
||||
} else {
|
||||
$p_download = "paste.php?download&id=$paste_id";
|
||||
$p_raw = "paste.php?raw&id=$paste_id";
|
||||
$p_embed = "paste.php?embed&id=$paste_id";
|
||||
$p_download = "paste.php?download&id=$paste->id";
|
||||
$p_raw = "paste.php?raw&id=$paste->id";
|
||||
$p_embed = "paste.php?embed&id=$paste->id";
|
||||
}
|
||||
|
||||
/* Expiry */
|
||||
|
@ -150,7 +146,7 @@ if (isset($_POST['fave']) && $current_user) {
|
|||
$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);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
if (isset($_GET['embed'])) {
|
||||
embedView($paste_id, $paste_title, $p_content, $title);
|
||||
embedView($paste->id, $paste->title, $p_content, $title);
|
||||
exit();
|
||||
}
|
||||
|
||||
// View counter
|
||||
if (!isRequesterLikelyBot() && @$_SESSION['not_unique'] !== $paste_id) {
|
||||
$_SESSION['not_unique'] = $paste_id;
|
||||
if (!isRequesterLikelyBot() && @$_SESSION['not_unique'] !== $paste->id) {
|
||||
$_SESSION['not_unique'] = $paste->id;
|
||||
$paste->views += 1;
|
||||
$paste->save();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ require_once('includes/passwords.php');
|
|||
use PonePaste\Models\Paste;
|
||||
|
||||
if ($current_user === null) {
|
||||
header("Location: ./login.php");
|
||||
header("Location: /login");
|
||||
die();
|
||||
}
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ $flashes = getFlashes();
|
|||
</form>
|
||||
</section>
|
||||
<footer class="modal-card-foot">
|
||||
<a href="../login.php?forgotpassw">Forgot Password?</a>
|
||||
<a href="/forgot">Forgot Password?</a>
|
||||
</footer>
|
||||
</div>
|
||||
<div id="regid" class="content-tab" style="display:none">
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<form method="post">
|
||||
<div class="field has-addons">
|
||||
<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="password" class="input" name="mypass"
|
||||
placeholder="Password" />
|
||||
|
|
|
@ -165,9 +165,9 @@
|
|||
<div class="columns">
|
||||
<div class="column">
|
||||
<h1 class="title is-4">Where to?</h1>
|
||||
<a href="login.php?login">Login</a><br/>
|
||||
<a href="login.php?registeraccount">Register</a> <br/>
|
||||
<a href="login.php?forgotpassw">Forgot Password</a><br/>
|
||||
<a href="/login">Login</a><br/>
|
||||
<a href="/register">Register</a> <br/>
|
||||
<a href="/forgot">Forgot Password</a><br/>
|
||||
</div>
|
||||
<div class="column">
|
||||
</div>
|
||||
|
|
|
@ -83,7 +83,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
|
|||
</div>
|
||||
</div>
|
||||
<!--<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 style="text-align: center;">
|
||||
<div id="reportbutton" class="column">
|
||||
|
@ -171,7 +171,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
|
|||
} else {
|
||||
echo 'paste.php?embed&id=';
|
||||
}
|
||||
echo $paste_id . '"></script>'; ?>' readonly />
|
||||
echo $paste->id . '"></script>'; ?>' readonly />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -326,7 +326,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
|
|||
$visibility_codes[] = '2';
|
||||
}
|
||||
|
||||
echo optionsForSelect($visibility_names, $visibility_codes, $p_visible);
|
||||
echo optionsForSelect($visibility_names, $visibility_codes, $paste->visible);
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue