From c1ed98a5bdf0b6095538af23e38e2fc10e2bcec3 Mon Sep 17 00:00:00 2001
From: Floorb <132411956+Neetpone@users.noreply.github.com>
Date: Fri, 22 Oct 2021 21:43:35 -0400
Subject: [PATCH] Some work, mainly committing so my next commit can be a
little smaller.
---
includes/Models/Paste.php | 4 +
includes/common.php | 8 +-
includes/functions.php | 11 ++-
theme/bulma/user_profile.php | 137 +++++++++++++----------------------
user.php | 26 ++-----
5 files changed, 74 insertions(+), 112 deletions(-)
diff --git a/includes/Models/Paste.php b/includes/Models/Paste.php
index 30a32aa..42f826e 100644
--- a/includes/Models/Paste.php
+++ b/includes/Models/Paste.php
@@ -6,6 +6,10 @@ use Illuminate\Database\Eloquent\Model;
use Watson\Validating\ValidatingTrait;
class Paste extends Model {
+ public const VISIBILITY_PUBLIC = 0;
+ public const VISIBILITY_UNLISTED = 1;
+ public const VISIBILITY_PRIVATE = 2;
+
protected $table = 'pastes';
protected $guarded = [];
diff --git a/includes/common.php b/includes/common.php
index 4151e8b..6abe9cc 100644
--- a/includes/common.php
+++ b/includes/common.php
@@ -31,12 +31,12 @@ function urlForPaste(Paste $paste) : string {
return "/paste.php?id={$paste->id}";
}
-function urlForMember(User $member_name) : string {
+function urlForMember(User $user) : string {
if (PP_MOD_REWRITE) {
- return '/user/' . urlencode($member_name);
+ return '/user/' . urlencode($user->username);
}
- return '/user.php?name=' . urlencode($member_name);
+ return '/user.php?name=' . urlencode($user->username);
}
function optionsForSelect(array $displays, array $values, string $currentSelection = null) : string {
@@ -190,10 +190,8 @@ $title = Trim($row['title']);
$baseurl = Trim($row['baseurl']);
$site_name = Trim($row['site_name']);
$email = Trim($row['email']);
-$ga = Trim($row['google_analytics']);
$additional_scripts = Trim($row['additional_scripts']);
-
// Setup theme
$default_theme = 'bulma';
diff --git a/includes/functions.php b/includes/functions.php
index 9a9a351..75746ab 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -57,14 +57,23 @@ function tagsToHtml(array | Collection $tags) : string {
return $output;
}
-function tagsToHtmlUser(string | array $tags, $profile_username) : string {
+function tagsToHtmlUser(string | array | Collection $tags, $profile_username) : string {
$output = "";
+
+ if (is_a($tags, Collection::class)) {
+ $tags = $tags->toArray();
+ }
+
if (is_array($tags)) {
$tagsSplit = array_map(function($tag) { return $tag['name']; }, $tags);
} else {
$tagsSplit = explode(",", $tags);
}
+ if (count($tagsSplit) === 0) {
+ return 'No tags';
+ }
+
foreach ($tagsSplit as $tag) {
if (stripos($tag, 'nsfw') !== false) {
$tag = strtoupper($tag);
diff --git a/theme/bulma/user_profile.php b/theme/bulma/user_profile.php
index 0e56b9b..c12c429 100644
--- a/theme/bulma/user_profile.php
+++ b/theme/bulma/user_profile.php
@@ -119,7 +119,7 @@
}
?>
- username === $profile_username): ?>
+
Some of your statistics:
Total pastes: = $profile_total_pastes ?> —
@@ -138,7 +138,7 @@
- ' . ($title) . ' - | -- ' . $p_dateui . ' - | -- ' . $p_views . ' - | -'; - if (strlen($p_tags) > 0) { - echo tagsToHtmlUser($p_tags,$profile_username); - } else { - echo ' No tags'; - } - - - echo ' | -||
- = $title ?> - | -- = $p_dateui ?> - | -- = $p_visible ?> - | -- = $p_views ?> - | -- = strtoupper($p_code) ?> - | -- - - | -= $escaped_title ?> | += $p_date->format('d F Y') ?> | += $p_visible; ?> | += $paste->views ?> | += tagsToHtmlUser($paste->tags, $profile_username); ?> | + + + +
Date Favourited | Status | Tags | - Delete"; - //} ?>|||
= $escaped_title ?> | += $p_date->format('d F Y') ?> | += $p_visible; ?> | += $paste->views ?> | += tagsToHtmlUser($paste->tags, $profile_username); ?> | + +|
Title | +Date Favourited | +Status | +Tags | +'; if (strlen($f_tags) > 0) { - echo tagsToHtmlUser($f_tags,$profile_username); + echo tagsToHtmlUser($f_tags,$profile_username); } else { echo ' No tags'; } - echo ' | - '; + echo ''; } } ?> diff --git a/user.php b/user.php index 2134866..b991298 100644 --- a/user.php +++ b/user.php @@ -1,12 +1,10 @@ favourites->count(); - $total_yfav = $profile_info->favourites->count(); // Badges @@ -39,30 +36,19 @@ $profile_badge = match ($profile_info['badge']) { default => '', }; -$query = $conn->prepare('SELECT COUNT(*) FROM pastes WHERE user_id = ?'); -$query->execute([$profile_info['id']]); -$profile_total_pastes = intval($query->fetch(PDO::FETCH_NUM)[0]); +$profile_total_pastes = $profile_info->pastes->count(); +$profile_total_public = $profile_info->pastes->where('visible', 0)->count(); +$profile_total_unlisted = $profile_info->pastes->where('visible', 1)->count(); +$profile_total_private = $profile_info->pastes->where('visible', 2)->count(); -$query = $conn->prepare('SELECT COUNT(*) FROM pastes WHERE user_id = ? AND visible = 0'); -$query->execute([$profile_info['id']]); -$profile_total_public = intval($query->fetch(PDO::FETCH_NUM)[0]); - -$query = $conn->prepare('SELECT COUNT(*) FROM pastes WHERE user_id = ? AND visible = 1'); -$query->execute([$profile_info['id']]); -$profile_total_unlisted = intval($query->fetch(PDO::FETCH_NUM)[0]); - -$query = $conn->prepare('SELECT COUNT(*) FROM pastes WHERE user_id = ? AND visible = 2'); -$query->execute([$profile_info['id']]); -$profile_total_private = intval($query->fetch(PDO::FETCH_NUM)[0]); - $query = $conn->prepare('SELECT SUM(views) FROM pastes WHERE user_id = ?'); $query->execute([$profile_info['id']]); $profile_total_paste_views = intval($query->fetch(PDO::FETCH_NUM)[0]); $profile_join_date = $profile_info['date']; -$profile_pastes = getUserPastes($conn, $profile_info['id']); +$profile_pastes = $profile_info->pastes; $profile_favs = $profile_info->favourites; $is_current_user = ($current_user !== null) && ($profile_info->id == $current_user->id);