From 3b0349188c83b24cb8ff7dfe76796dabc3916e83 Mon Sep 17 00:00:00 2001
From: cflip <36554078+cflip@users.noreply.github.com>
Date: Wed, 7 Apr 2021 16:24:54 -0600
Subject: Styling and formatting for posts
---
model/Post.php | 35 +++++++++++++++++++++++++++++------
search.php | 2 +-
styles/style.css | 23 ++++++++++++++++++++++-
viewthread.php | 12 ++++++------
4 files changed, 58 insertions(+), 14 deletions(-)
diff --git a/model/Post.php b/model/Post.php
index ef2fe4f..02c9dec 100644
--- a/model/Post.php
+++ b/model/Post.php
@@ -2,6 +2,28 @@
include_once 'Thread.php';
+function add_quote($dbc, $thread_id, $matches) {
+ foreach ($matches as $match) {
+ $id = (int) filter_var($match, FILTER_SANITIZE_NUMBER_INT);
+ $sql = "SELECT post_content, post_author, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_id = " . $id;
+ $result = mysqli_query($dbc, $sql);
+
+ if (!$result) {
+ return '
';
+ }
+
+ $reply = mysqli_fetch_assoc($result);
+
+ if (empty($reply)) {
+ return 'Invalid quote! ';
+ }
+
+ $id = $id + 1;
+
+ return 'Quote from ' . $reply['user_name'] . ' ' . $reply['post_content'] . ' ';
+ }
+}
+
class Post {
public $id;
public $content;
@@ -36,14 +58,15 @@ class Post {
mysqli_free_result($result);
}
- function display_content() {
- echo '';
+ function display_content($dbc) {
+ echo '';
$post_content = $this->content;
+ $thread_id = $this->id;
- // $post_content = preg_replace_callback('/>#\d+/', function($matches) use($thread_id, $dbc) {
- // return add_quote($dbc, $thread_id, $matches);
- // }, $post_content);
+ $post_content = preg_replace_callback('/>#\d+/', function($matches) use($thread_id, $dbc) {
+ return add_quote($dbc, $thread_id, $matches);
+ }, $post_content);
// Replace YouTube URLs with embedded YouTube videos.
$post_content = preg_replace(
@@ -54,7 +77,7 @@ class Post {
// Replace other URLs with links.
$post_content = preg_replace('@\b(http(s)?://)([^\s]*?(?:\.[a-z\d?=/_-]+)+)(?![^<]*?(?:\w+>|/?>))@i', '$0 ', $post_content);
- echo '' . $post_content . '
';
+ echo '' . $post_content . ' ';
}
}
diff --git a/search.php b/search.php
index 1357d55..00555df 100644
--- a/search.php
+++ b/search.php
@@ -47,7 +47,7 @@
foreach ($posts as $post) {
echo 'From ' . $post->thread->subject . ' ';
- $post->display_content();
+ $post->display_content($dbc);
}
break;
case 'user':
diff --git a/styles/style.css b/styles/style.css
index b2a56af..c4e0b2c 100644
--- a/styles/style.css
+++ b/styles/style.css
@@ -39,12 +39,24 @@ td {
}
.info {
- margin: 1px 1px 1px 6px;
color: #666;
}
.post-content {
overflow: auto;
+ background-color: #eee;
+ padding: 12px 4px 12px 4px;
+ display: block;
+}
+
+.youtube-embed {
+ width: 480px;
+ height: 270px;
+ border: none;
+}
+
+.image-embed {
+ width: 480px;
}
textarea {
@@ -54,3 +66,12 @@ textarea {
overflow: scroll;
resize: none;
}
+
+blockquote {
+ border-color: #b6dcd5;
+ background-color: #E9F5F2;
+ padding: 12px;
+ border: 1px solid #79a;
+ overflow: hidden;
+ border-radius: 5px;
+}
diff --git a/viewthread.php b/viewthread.php
index c8ae99e..64750a5 100644
--- a/viewthread.php
+++ b/viewthread.php
@@ -22,21 +22,21 @@ if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
- subject; ?> - cflip.net forum
+ = $current->subject; ?> - cflip.net forum
- subject; ?>
- created by author->name; ?>
- in category->name; ?>
- 3 days ago
+ = $current->subject; ?>
+ created by = $current->author->name; ?>
+ in = $current->category->name; ?>
+ 3 days ago
get_posts($dbc);
foreach ($posts as $post) {
- $post->display_content();
+ $post->display_content($dbc);
}
?>
--
cgit v1.2.3