More Eloquent conversions

This commit is contained in:
Floorb 2021-11-01 16:56:17 -04:00
parent c1ed98a5bd
commit ab632347b6
20 changed files with 145 additions and 257 deletions

View file

@ -1,8 +1,9 @@
<?php <?php
define('IN_PONEPASTE', 1); define('IN_PONEPASTE', 1);
require_once(__DIR__ . '/../includes/common.php'); require_once(__DIR__ . '/../includes/common.php');
use PonePaste\Models\Tag;
/* get rid of unintended wildcards in a parameter to LIKE queries; not a security issue, just unexpected behaviour. */ /* get rid of unintended wildcards in a parameter to LIKE queries; not a security issue, just unexpected behaviour. */
function escapeLikeQuery(string $query) : string { function escapeLikeQuery(string $query) : string {
return str_replace(['\\', '_', '%'], ['\\\\', '\\_', '\\%'], $query); return str_replace(['\\', '_', '%'], ['\\\\', '\\_', '\\%'], $query);

View file

@ -2,10 +2,13 @@
define('IN_PONEPASTE', 1); define('IN_PONEPASTE', 1);
require_once('includes/common.php'); require_once('includes/common.php');
use PonePaste\Models\Paste;
$date = date('jS F Y'); $date = date('jS F Y');
// Temp count for untagged pastes // Temp count for untagged pastes
$total_untagged = intval($conn->query("SELECT COUNT(*) from pastes WHERE tagsys IS NULL")->fetch(PDO::FETCH_NUM)[0]); $total_untagged = Paste::doesntHave('tags')->count();
updatePageViews($conn); updatePageViews($conn);

View file

@ -0,0 +1,8 @@
<?php
namespace PonePaste\Models;
use Illuminate\Database\Eloquent\Model;
class IPBan extends Model {
protected $table = 'ban_user';
}

View file

@ -0,0 +1,8 @@
<?php
namespace PonePaste\Models;
use Illuminate\Database\Eloquent\Model;
class PageView extends Model {
protected $table = 'page_view';
}

View file

@ -3,7 +3,6 @@ namespace PonePaste\Models;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Watson\Validating\ValidatingTrait;
class Paste extends Model { class Paste extends Model {
public const VISIBILITY_PUBLIC = 0; public const VISIBILITY_PUBLIC = 0;

View file

@ -5,6 +5,9 @@ use Illuminate\Database\Eloquent\Model;
class User extends Model { class User extends Model {
protected $table = 'users'; protected $table = 'users';
protected $fillable = [
'username', 'password', 'recovery_code_hash', 'date'
];
public function session() { public function session() {
return $this->hasOne(UserSession::class); return $this->hasOne(UserSession::class);

View file

@ -8,9 +8,9 @@ require_once(__DIR__ . '/functions.php');
require_once(__DIR__ . '/DatabaseHandle.class.php'); require_once(__DIR__ . '/DatabaseHandle.class.php');
use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use PonePaste\Helpers\SessionHelper; use PonePaste\Helpers\SessionHelper;
use PonePaste\Models\IPBan;
use PonePaste\Models\PageView;
use PonePaste\Models\Paste; use PonePaste\Models\Paste;
use PonePaste\Models\User; use PonePaste\Models\User;
@ -102,22 +102,6 @@ function getSiteInfo() : array {
return require(__DIR__ . '/../config/site.php'); return require(__DIR__ . '/../config/site.php');
} }
function getSiteAds(DatabaseHandle $conn) : array|bool {
return $conn->query('SELECT text_ads, ads_1, ads_2 FROM ads LIMIT 1')->fetch();
}
function getSiteTotalPastes(DatabaseHandle $conn) : int {
return intval($conn->query('SELECT COUNT(*) FROM pastes')->fetch(PDO::FETCH_NUM)[0]);
}
function getSiteTotalviews(DatabaseHandle $conn) : int {
return intval($conn->query('SELECT tpage FROM page_view ORDER BY id DESC LIMIT 1')->fetch(PDO::FETCH_NUM)[0]);
}
function getSiteTotal_unique_views(DatabaseHandle $conn) : int {
return intval($conn->query('SELECT tvisit FROM page_view ORDER BY id DESC LIMIT 1')->fetch(PDO::FETCH_NUM)[0]);
}
/** /**
* Specialization of `htmlentities()` that avoids double escaping and uses UTF-8. * Specialization of `htmlentities()` that avoids double escaping and uses UTF-8.
* *
@ -186,11 +170,11 @@ $capsule->bootEloquent();
$site_info = getSiteInfo(); $site_info = getSiteInfo();
$global_site_info = $site_info['site_info']; $global_site_info = $site_info['site_info'];
$row = $site_info['site_info']; $row = $site_info['site_info'];
$title = Trim($row['title']); $title = trim($row['title']);
$baseurl = Trim($row['baseurl']); $baseurl = trim($row['baseurl']);
$site_name = Trim($row['site_name']); $site_name = trim($row['site_name']);
$email = Trim($row['email']); $email = trim($row['email']);
$additional_scripts = Trim($row['additional_scripts']); $additional_scripts = trim($row['additional_scripts']);
// Setup theme // Setup theme
$default_theme = 'bulma'; $default_theme = 'bulma';
@ -212,14 +196,13 @@ $captcha_enabled = (bool) $captcha_config['enabled'];
// Check if IP is banned // Check if IP is banned
$ip = $_SERVER['REMOTE_ADDR']; $ip = $_SERVER['REMOTE_ADDR'];
if ($conn->query('SELECT 1 FROM ban_user WHERE ip = ?', [$ip])->fetch()) { if (IPBan::where('ip', $ip)->first()) {
die('You have been banned.'); die('You have been banned.');
} }
$site_ads = getSiteAds($conn); $total_pastes = Paste::count();
$total_pastes = getSiteTotalPastes($conn); $total_page_views = PageView::select('tpage')->orderBy('id', 'desc')->first()->tpage;
$total_page_views = getSiteTotalviews($conn); $total_unique_views = PageView::select('tvisit')->orderBy('id', 'desc')->first()->tvisit;
$total_unique_views = getSiteTotal_unique_views($conn);
$current_user = SessionHelper::currentUser(); $current_user = SessionHelper::currentUser();

View file

@ -1,34 +1,6 @@
<?php <?php
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
function getPasteTags(DatabaseHandle $conn, int $paste_id) : array {
return $conn->query(
'SELECT name, slug FROM tags
INNER JOIN paste_taggings ON paste_taggings.tag_id = tags.id
WHERE paste_taggings.paste_id = ?',
[$paste_id])->fetchAll();
}
function getUserFavs(DatabaseHandle $conn, int $user_id) : array {
$query = $conn->prepare(
"SELECT pins.f_time, pastes.id, pins.paste_id, pastes.title, pastes.created_at, pastes.updated_at
FROM pins
INNER JOIN pastes ON pastes.id = pins.paste_id
WHERE pins.user_id = ?");
$query->execute([$user_id]);
return $query->fetchAll();
}
function checkFavorite($user, $paste_id) : string {
if ($user->favourites->where('paste_id', $paste_id)->first()) {
return "<a href='#' id='favorite' class='icon tool-icon' data-fid='" . $paste_id . "'><i class='fas fa-star fa-lg has-text-grey' title='Favourite'></i></a>";
} else {
return "<a href='#' id='favorite' class='icon tool-icon' data-fid='" . $paste_id . "'><i class='far fa-star fa-lg has-text-grey' title='Favourite'></i></a>";
}
}
function getreports($conn, $count = 10) { function getreports($conn, $count = 10) {
$query = $conn->prepare('SELECT * FROM user_reports LIMIT ?'); $query = $conn->prepare('SELECT * FROM user_reports LIMIT ?');
$query->execute([$count]); $query->execute([$count]);
@ -162,21 +134,6 @@ function getRecentadmin($conn, $count = 5) {
return $query->fetchAll(); return $query->fetchAll();
} }
function getUserPastes(DatabaseHandle $conn, int $user_id) : array {
return $conn->query(
"SELECT id, title, visible, code, created_at, views FROM pastes
WHERE user_id = ?
ORDER by pastes.id DESC", [$user_id])->fetchAll();
}
function getTotalPastes(DatabaseHandle $conn, int $user_id) : int {
$query = $conn->prepare("SELECT COUNT(*) AS total_pastes
FROM pastes INNER JOIN users ON users.id = pastes.user_id
WHERE users.id = ?");
$query->execute([$user_id]);
return intval($query->fetch(PDO::FETCH_NUM)[0]);
}
function friendlyDateDifference(DateTime $lesser, DateTime $greater) : string { function friendlyDateDifference(DateTime $lesser, DateTime $greater) : string {
$delta = $greater->diff($lesser, true); $delta = $greater->diff($lesser, true);

View file

@ -4,6 +4,10 @@ require_once('includes/common.php');
require_once('includes/functions.php'); require_once('includes/functions.php');
require_once('includes/passwords.php'); require_once('includes/passwords.php');
use PonePaste\Helpers\SessionHelper;
use PonePaste\Models\User;
use PonePaste\Models\UserSession;
// Current Date & User IP // Current Date & User IP
$date = date('jS F Y'); $date = date('jS F Y');
$ip = $_SERVER['REMOTE_ADDR']; $ip = $_SERVER['REMOTE_ADDR'];
@ -22,22 +26,24 @@ if (isset($_POST['forgot'])) {
$username = trim($_POST['username']); $username = trim($_POST['username']);
$recovery_code = trim($_POST['recovery_code']); $recovery_code = trim($_POST['recovery_code']);
$query = $conn->query("SELECT id, recovery_code_hash FROM users WHERE username = ?", [$username]); $user = User::select('id', 'recovery_code_hash')
$row = $query->fetch(); ->where('username', $username);
/* see justification below for error-suppression operator */
if ($row && pp_password_verify($_POST['recovery_code'], $row['recovery_code_hash'])) { if (pp_password_verify($_POST['recovery_code'], @$user->recovery_code_hash)) {
$new_password = pp_random_password(); $new_password = pp_random_password();
$new_password_hash = pp_password_hash($new_password); $new_password_hash = pp_password_hash($new_password);
$recovery_code = pp_random_token(); $recovery_code = pp_random_token();
$new_recovery_code_hash = pp_password_hash($recovery_code); $new_recovery_code_hash = pp_password_hash($recovery_code);
$conn->prepare('UPDATE users SET password = ?, recovery_code_hash = ? WHERE id = ?') $user->password = $new_password_hash;
->execute([$new_password_hash, $new_recovery_code_hash, $row['id']]); $user->recovery_code_hash = $new_recovery_code_hash;
$user->save();
$success = 'Your password has been changed. A new recovery code has also been generated. Please note the recovery code and then sign in with the new password.'; $success = 'Your password has been changed. A new recovery code has also been generated. Please note the recovery code and then sign in with the new password.';
} else { } else {
$error = 'Incorrect username or password.'; $error = 'Incorrect username or recovery code.';
} }
} else { } else {
$error = 'All fields must be filled out.'; $error = 'All fields must be filled out.';
@ -46,38 +52,40 @@ if (isset($_POST['forgot'])) {
if (!empty($_POST['username']) && !empty($_POST['password'])) { if (!empty($_POST['username']) && !empty($_POST['password'])) {
$remember_me = (bool) $_POST['remember_me']; $remember_me = (bool) $_POST['remember_me'];
$username = trim($_POST['username']); $username = trim($_POST['username']);
$row = $conn->query("SELECT id, password, banned FROM users WHERE username = ?", [$username]) $user = User::select('id', 'password', 'banned')
->fetch(); ->where('username', $username)
->first();
$needs_rehash = false; $needs_rehash = false;
/* This is designed to be a constant time lookup, hence the warning suppression operator so that /* This is designed to be a constant time lookup, hence the warning suppression operator so that
* we always call pp_password_verify, even if row is null. * we always call pp_password_verify, even if the user is null.
*/ */
if (pp_password_verify($_POST['password'], @$row['password'], $needs_rehash)) { if (pp_password_verify($_POST['password'], @$user->password, $needs_rehash)) {
$user_id = $row['id'];
if ($needs_rehash) { if ($needs_rehash) {
$new_password_hash = pp_password_hash($_POST['password']); $user->password = pp_password_hash($_POST['password']);
$user->save();
$conn->query('UPDATE users SET password = ? WHERE id = ?',
[$new_password_hash, $user_id]);
} }
if ($row['banned']) { if ($user->banned) {
// User is banned // User is banned
$error = 'You are banned.'; $error = 'You are banned.';
} else { } else {
// Login successful // Login successful
$_SESSION['user_id'] = (string) $user_id; $_SESSION['user_id'] = (string) $user->id;
if ($remember_me) { if ($remember_me) {
$remember_token = pp_random_token(); $remember_token = pp_random_token();
$expire_at = (new DateTime())->add(new DateInterval('P1Y')); $expire_at = (new DateTime())->add(new DateInterval('P1Y'));
$conn->query('INSERT INTO user_sessions (user_id, token, expire_at) VALUES (?, ?, FROM_UNIXTIME(?))', [$user_id, $remember_token, $expire_at->format('U')]); $session = new UserSession([
'user_id' => $user->id,
'token' => $remember_token,
'expire_at' => $expire_at
]);
$session->save();
setcookie(User::REMEMBER_TOKEN_COOKIE, $remember_token, [ setcookie(SessionHelper::REMEMBER_TOKEN_COOKIE, $remember_token, [
'expires' => (int) $expire_at->format('U'), 'expires' => (int) $expire_at->format('U'),
'secure' => !empty($_SERVER['HTTPS']), /* Local dev environment is non-HTTPS */ 'secure' => !empty($_SERVER['HTTPS']), /* Local dev environment is non-HTTPS */
'httponly' => true, 'httponly' => true,
@ -96,7 +104,7 @@ if (isset($_POST['forgot'])) {
$error = 'All fields must be filled out.'; $error = 'All fields must be filled out.';
} }
} elseif (isset($_POST['signup'])) { // Registration process } elseif (isset($_POST['signup'])) { // Registration process
$username = htmlentities(trim($_POST['username'], ENT_QUOTES)); $username = trim($_POST['username']);
$password = pp_password_hash($_POST['password']); $password = pp_password_hash($_POST['password']);
if (empty($_POST['password']) || empty($_POST['username'])) { if (empty($_POST['password']) || empty($_POST['username'])) {
@ -106,15 +114,20 @@ if (isset($_POST['forgot'])) {
} 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 {
if ($conn->querySelectOne('SELECT 1 FROM users WHERE username = ?', [$username])) { if (User::where('username', $username)->first()) {
$error = 'That username has already been taken.'; $error = 'That username has already been taken.';
} else { } else {
/* this is displayed to the user in the template, hence the variable rather than inlining */
$recovery_code = pp_random_token(); $recovery_code = pp_random_token();
$recovery_code_hash = pp_password_hash($recovery_code);
$conn->query( $user = new User([
"INSERT INTO users (username, password, recovery_code_hash, picture, date, ip, badge) VALUES (?, ?, ?, 'NONE', ?, ?, '0')", 'username' => $username,
[$username, $password, $recovery_code_hash, $date, $ip] 'password' => $password,
); 'recovery_code_hash' => pp_password_hash($recovery_code),
'date' => $date,
'ip' => $ip
]);
$user->save();
$success = 'Your account was successfully registered.'; $success = 'Your account was successfully registered.';
} }

View file

@ -21,7 +21,7 @@ $paste_id = intval(trim($_REQUEST['id']));
updatePageViews($conn); updatePageViews($conn);
// This is used in the theme files. // This is used in the theme files.
$totalpastes = getSiteTotalPastes($conn); $totalpastes = Paste::count();
// Get paste favorite count // Get paste favorite count
$fav_count = $conn->querySelectOne('SELECT COUNT(*) FROM user_favourites WHERE paste_id = ?', [$paste_id], PDO::FETCH_NUM)[0]; $fav_count = $conn->querySelectOne('SELECT COUNT(*) FROM user_favourites WHERE paste_id = ?', [$paste_id], PDO::FETCH_NUM)[0];
@ -46,8 +46,6 @@ if (!$paste) {
goto Not_Valid_Paste; goto Not_Valid_Paste;
} }
//var_dump($paste);
$paste_owner_id = $paste->user->id; $paste_owner_id = $paste->user->id;
$paste_title = $paste->title; $paste_title = $paste->title;
$paste_code = $paste->code; $paste_code = $paste->code;
@ -69,6 +67,7 @@ $p_visible = $paste->visible;
$p_expiry = $paste->expiry; $p_expiry = $paste->expiry;
$p_password = $paste->password; $p_password = $paste->password;
$p_encrypt = (bool) $paste->encrypt; $p_encrypt = (bool) $paste->encrypt;
$paste_is_favourited = $current_user !== null && $current_user->favourites->where('paste_id', $paste->id)->count() === 1;
$is_private = $p_visible === '2'; $is_private = $p_visible === '2';
@ -110,6 +109,15 @@ if (!empty($p_expiry) && $p_expiry !== 'SELF') {
} }
} }
/* handle favouriting */
if (isset($_POST['fave'])) {
if ($paste_is_favourited) {
$current_user->favourites()->detach($paste->id);
} else {
$current_user->favourites()->attach($paste->id);
}
}
if ($p_encrypt == 1) { if ($p_encrypt == 1) {
$p_content = openssl_decrypt($p_content, PP_ENCRYPTION_ALGO, PP_ENCRYPTION_KEY); $p_content = openssl_decrypt($p_content, PP_ENCRYPTION_ALGO, PP_ENCRYPTION_KEY);
} }
@ -133,7 +141,7 @@ if (isset($_POST['delete'])) {
if (!$current_user || ($paste_owner_id !== $current_user->user_id)) { if (!$current_user || ($paste_owner_id !== $current_user->user_id)) {
flashError('You must be logged in and own this paste to delete it.'); flashError('You must be logged in and own this paste to delete it.');
} else { } else {
$conn->query('DELETE FROM pastes WHERE id = ?', [$paste_id]); $paste->delete();
flashSuccess('Paste deleted.'); flashSuccess('Paste deleted.');
header('Location: ' . urlForMember($current_user->username)); header('Location: ' . urlForMember($current_user->username));
die(); die();
@ -195,7 +203,8 @@ if ($password_required && $password_valid) {
// View counter // View counter
if (@$_SESSION['not_unique'] !== $paste_id) { if (@$_SESSION['not_unique'] !== $paste_id) {
$_SESSION['not_unique'] = $paste_id; $_SESSION['not_unique'] = $paste_id;
$conn->query("UPDATE pastes SET views = (views + 1) where id = ?", [$paste_id]); $paste->views += 1;
$paste->save();
} }
$page_template = 'view'; $page_template = 'view';

View file

@ -4,6 +4,8 @@ require_once('includes/common.php');
require_once('includes/functions.php'); require_once('includes/functions.php');
require_once('includes/passwords.php'); require_once('includes/passwords.php');
use PonePaste\Models\Paste;
// Check if already logged in // Check if already logged in
if ($current_user === null) { if ($current_user === null) {
header("Location: ./login.php"); header("Location: ./login.php");
@ -11,14 +13,11 @@ if ($current_user === null) {
} }
$user_username = $current_user->username; $user_username = $current_user->username;
$query = $conn->query('SELECT * FROM users WHERE id = ?', [$current_user->user_id]);
$row = $query->fetch(); $row = $query->fetch();
$user_id = $row['id']; $user_id = $current_user->id;
$user_platform = Trim($row['platform']); $user_date = $current_user->date;
$user_date = $row['date']; $user_ip = $current_user->ip;
$user_ip = $row['ip']; $user_password = $current_user->password;
$user_password = $row['password'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['cpassword'])) { if (isset($_POST['cpassword'])) {
@ -41,7 +40,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
updatePageViews($conn); updatePageViews($conn);
$total_user_pastes = getTotalPastes($conn, $current_user->user_id); $total_user_pastes = Paste::where('user_id', $current_user->user_id)->count();
// Theme // Theme
$page_template = 'profile'; $page_template = 'profile';

View file

@ -69,13 +69,6 @@
</table> </table>
<div class="paginator"></div> <div class="paginator"></div>
<?php
if (isset($site_ads)) {
echo $site_ads['ads_2'];
}
?>
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>

View file

@ -161,14 +161,25 @@ input:checked + .slider:before {
} }
} }
img [alt="www.000webhost.com"] {
display: none;
}
.td-center { .td-center {
text-align: center !important; text-align: center !important;
} }
.green .hljs-comment { .green .hljs-comment {
color: #789922; color: #789922;
}
button.button--no-style {
background: none;
color: inherit;
border: none;
padding: 0;
font: inherit;
cursor: pointer;
outline: inherit;
display: inline;
}
.form--inline {
display: inline;
} }

View file

@ -68,11 +68,11 @@
<div class="media"> <div class="media">
<div class="media-content" style="overflow: hidden"> <div class="media-content" style="overflow: hidden">
<p class="title is-5"> <p class="title is-5">
<a href="<?= urlForPaste($paste['id']) ?>" <a href="<?= urlForPaste($paste) ?>"
title="<?= $paste['title'] ?>"> <?= $paste['title'] ?> </a> title="<?= pp_html_escape($paste->title) ?>"> <?= pp_html_escape($paste->title) ?> </a>
</p> </p>
<p class="subtitle is-6"> <p class="subtitle is-6">
<a href="<?= urlForMember($paste['member']) ?>"><?= $paste['member'] ?></a> <a href="<?= urlForMember($paste->user) ?>"><?= pp_html_escape($paste->user->username) ?></a>
<br> <br>
<time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time> <time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time>
</p> </p>
@ -107,11 +107,11 @@
<div class="media"> <div class="media">
<div class="media-content" style="overflow: hidden"> <div class="media-content" style="overflow: hidden">
<p class="title is-5"> <p class="title is-5">
<a href="<?= urlForPaste($paste['id']) ?>" <a href="<?= urlForPaste($paste) ?>"
title="<?= $paste['title'] ?>"> <?= $paste['title'] ?> </a> title="<?= pp_html_escape($paste->title) ?>"> <?= pp_html_escape($paste->title) ?> </a>
</p> </p>
<p class="subtitle is-6"> <p class="subtitle is-6">
<a href="<?= urlForMember($paste['member']) ?>"><?= $paste['member'] ?></a> <a href="<?= urlForMember($paste->user) ?>"><?= pp_html_escape($paste->user->username) ?></a>
<br> <br>
<time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time> <time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time>
</p> </p>
@ -146,11 +146,11 @@
<div class="media"> <div class="media">
<div class="media-content" style="overflow: hidden"> <div class="media-content" style="overflow: hidden">
<p class="title is-5"> <p class="title is-5">
<a href="<?= urlForPaste($paste['id']) ?>" <a href="<?= urlForPaste($paste) ?>"
title="<?= $paste['title'] ?>"> <?= $paste['title'] ?> </a> title="<?= pp_html_escape($paste->title) ?>"> <?= pp_html_escape($paste->title) ?> </a>
</p> </p>
<p class="subtitle is-6"> <p class="subtitle is-6">
<a href="<?= urlForMember($paste['member']) ?>"><?= $paste['member'] ?></a> <a href="<?= urlForMember($paste->user) ?>"><?= pp_html_escape($paste->user->username) ?></a>
<br> <br>
<time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_update_time'] ?></time> <time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_update_time'] ?></time>
</p> </p>
@ -185,11 +185,11 @@
<div class="media"> <div class="media">
<div class="media-content" style="overflow: hidden"> <div class="media-content" style="overflow: hidden">
<p class="title is-5"> <p class="title is-5">
<a href="<?= urlForPaste($paste['id']) ?>" <a href="<?= urlForPaste($paste) ?>"
title="<?= $paste['title'] ?>"> <?= $paste['title'] ?> </a> title="<?= pp_html_escape($paste->title) ?>"> <?= pp_html_escape($paste->title) ?> </a>
</p> </p>
<p class="subtitle is-6"> <p class="subtitle is-6">
<a href="<?= urlForMember($paste['member']) ?>"><?= $paste['member'] ?></a> <a href="<?= urlForMember($paste->user) ?>"><?= pp_html_escape($paste->user->username) ?></a>
<br> <br>
<time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time> <time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time>
</p> </p>

View file

@ -133,7 +133,7 @@
<!-- Submitted Pastes --> <!-- Submitted Pastes -->
<div class="col-md-9 col-lg-10"> <div class="col-md-9 col-lg-10">
<div class="panel panel-default"> <div class="panel panel-default">
<h1 class="title is-4">Submited Entries <h1 class="title is-4">Submitted Entries
<h1> <h1>
<div class="panel-body"> <div class="panel-body">
<div class="list-widget pagination-content"> <div class="list-widget pagination-content">
@ -164,18 +164,7 @@
'</header>'; '</header>';
?> ?>
<?php } <?php } ?>
// Display a message if the pastebin is empty
$query = "SELECT count(*) as count FROM pastes";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$totalpastes = $row['count'];
}
if ($totalpastes == '0') {
echo "None submitted";
} ?>
</p>
</div> </div>
</div> </div>
<div class="notification is-warning"> <div class="notification is-warning">
@ -201,10 +190,4 @@
<!-- End Panel --> <!-- End Panel -->
<?php } <?php } ?>
if (!$site_is_private) {
return;
} elseif (isset($site_ads)) {
echo $site_ads['ads_2'];
}// Remove sidebar if site is private
?>

View file

@ -64,11 +64,6 @@
<div class="column"> <div class="column">
</div> </div>
<div class="column"> <div class="column">
<?php
if (isset($site_ads) && $current_user === null) {
echo $site_ads['ads_2'];
}
?>
</div> </div>
</div> </div>
</form> </form>
@ -121,11 +116,6 @@
<div class="column"> <div class="column">
</div> </div>
<div class="column"> <div class="column">
<?php
if (isset($site_ads) && $current_user === null) {
echo $site_ads['ads_2'];
}
?>
</div> </div>
</div> </div>
<div class="field"> <div class="field">
@ -169,11 +159,6 @@
<div class="column"> <div class="column">
</div> </div>
<div class="column"> <div class="column">
<?php
if (isset($site_ads) && $current_user === null) {
echo $site_ads['ads_2'];
}
?>
</div> </div>
</div> </div>
</form> </form>
@ -188,11 +173,6 @@
<div class="column"> <div class="column">
</div> </div>
<div class="column"> <div class="column">
<?php
if (isset($site_ads) && $current_user === null) {
echo $site_ads['ads_2'];
}
?>
</div> </div>
</div> </div>
<?php } ?> <?php } ?>

View file

@ -302,13 +302,6 @@
</nav> </nav>
</div> </div>
<div class="column is-3"> <div class="column is-3">
<!-- $text_ads -->
<?php
// don't display ads for logged in users.
if (!empty($site_ads) && $current_user === null) {
echo $site_ads['text_ads'];
}
?>
</div> </div>
<div class="column is-4"> <div class="column is-4">
<!-- CAPTCHA --> <!-- CAPTCHA -->

View file

@ -10,10 +10,6 @@
} else { } else {
echo '<p class="help is-danger subtitle is-6">Not Found</p>'; echo '<p class="help is-danger subtitle is-6">Not Found</p>';
} }
if (isset($site_ads)) {
echo $site_ads['ads_2'];
}
?> ?>
</div> </div>
</div> </div>

View file

@ -209,16 +209,22 @@
<?php foreach ($profile_favs as $paste): ?> <?php foreach ($profile_favs as $paste): ?>
<?php <?php
$escaped_title = pp_html_escape(truncate($paste->title, 20, 50)); $escaped_title = pp_html_escape(truncate($paste->title, 20, 50));
$p_date = new DateTime($paste->created_at); $f_date = new DateTime($paste->pivot->f_time);
$update_date = new DateTime($paste->updated_at);
$delta = $update_date->diff(new DateTime(), true);
?> ?>
<?php if ($is_current_user || $row['visible'] == Paste::VISIBILITY_PUBLIC): ?> <?php if ($is_current_user || $row['visible'] == Paste::VISIBILITY_PUBLIC): ?>
<tr> <tr>
<td><a href="<?= urlForPaste($paste) ?>" title="<?= $escaped_title ?>"><?= $escaped_title ?></a></td> <td><a href="<?= urlForPaste($paste) ?>" title="<?= $escaped_title ?>"><?= $escaped_title ?></a></td>
<td data-sort="<?= $p_date->format('U') ?>" class="td-center"><?= $p_date->format('d F Y') ?></td> <td data-sort="<?= $p_date->format('U') ?>" class="td-center"><?= $p_date->format('d F Y') ?></td>
<td class="td-center"><?= $p_visible; ?></td> <td class="td-center">
<td class="td-center"><?= $paste->views ?></td> <?php if ($delta->days <= 2): ?>
<i class='far fa-check-square fa-lg' aria-hidden='true'></i>
<?php else: ?>
<i class='far fa-minus-square fa-lg' aria-hidden='true'></i>
<?php endif; ?>
</td>
<td class="td-left"><?= tagsToHtmlUser($paste->tags, $profile_username); ?></td> <td class="td-left"><?= tagsToHtmlUser($paste->tags, $profile_username); ?></td>
<!-- Delete button here? -->
</tr> </tr>
<?php endif; ?> <?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
@ -231,62 +237,9 @@
<td class="td-center">Tags</td> <td class="td-center">Tags</td>
</tr> </tr>
</tfoot> </tfoot>
<?php } ?>
<tbody>
<?php
foreach ($profile_favs as $row) {
$ftitle = Trim($row['title']);
$f_id = Trim($row['paste_id']);
$f_date = new DateTime($row['f_time']);
$f_dateui = $f_date->format("d F Y");
$Recent_update = new DateTime($row['updated_at']);
$Recent_update_u = date_format($Recent_update, 'U');
$tagArray2 = array_map(function ($tag) {
return $tag['name'];
}, getPasteTags($conn, $f_id));
$f_tags = implode(',', $tagArray2);
//$p_link = ($mod_rewrite == '1') ? "$f_id" : "paste.php?favdel=$fu_id";
//$f_delete_link = ($mod_rewrite == '1') ? "user.php?favdel&user=$profile_username&fid=$f_id" : "user.php?favdel&user=$profile_username&fid=$f_id";
$title = truncate($title, 20, 50);
$current_time = time();
$past = strtotime('-2 day', $current_time);
if ($past <= $Recent_update_u && $Recent_update_u <= $current_time) {
$updatenote = "<i class='far fa-check-square fa-lg' aria-hidden='true'></i>";
} else {
$updatenote = "<i class='far fa-minus-square fa-lg' aria-hidden='true'></i>";
}
echo '<tr>
<td>
<a href="' . $protocol . $baseurl . '/' . $f_id . '" title="' . $ftitle . '">' . ($ftitle) . '</a>
</td>
<td data-sort="' . date_format($f_date, 'U') . '" class="td-center">
<span>' . $f_dateui . '</span>
</td>
<td data-sort="' . $Recent_update_u . '" class="td-center">
<span>' . $updatenote . '</span>
</td>
<td class="td-left">';
if (strlen($f_tags) > 0) {
echo tagsToHtmlUser($f_tags,$profile_username);
} else {
echo ' <span class="tag is-warning">No tags</span>';
}
echo '</td></tr>';
}
}
?>
</tbody>
</table> </table>
</div> </div>
<?php
if (isset($site_ads)) {
echo $site_ads['ads_2'];
}
?>
</div> </div>
</div> </div>
</div> </div>

View file

@ -175,11 +175,12 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
<div class="column is-4 has-text-right"> <div class="column is-4 has-text-right">
<div class=""> <div class="">
<div class="panel-tools"> <div class="panel-tools">
<?php <?php if ($current_user !== null): ?>
if ($current_user !== null) { <form action="" method="POST" class="form--inline">
echo checkFavorite($current_user, $paste->id); <input type="hidden" name="fave" value="1" />
} <button type="submit" class="icon tool-icon button--no-style"><i class="fas fa-star fa-lg <?= $paste_is_favourited ? '' : 'has-text-grey' ?>" title="Favourite"></i></button>
?> </form>
<?php endif; ?>
<a class="icon tool-icon flip" onclick="openreport()"><i <a class="icon tool-icon flip" onclick="openreport()"><i
class="far fa-flag fa-lg has-text-grey" title="Report Paste"></i></a> class="far fa-flag fa-lg has-text-grey" title="Report Paste"></i></a>
<?php if ($paste['code'] != "pastedown") { ?> <?php if ($paste['code'] != "pastedown") { ?>
@ -442,11 +443,6 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
</div> </div>
<br/> <br/>
</nav> </nav>
<?php
if (isset($site_ads)) {
echo $site_ads['ads_2'];
}
?>
</form> </form>
<?php } ?> <?php } ?>