summaryrefslogtreecommitdiff
path: root/model/Post.php
diff options
context:
space:
mode:
authorcflip <36554078+cflip@users.noreply.github.com>2021-04-07 16:24:54 -0600
committercflip <36554078+cflip@users.noreply.github.com>2021-04-07 16:24:54 -0600
commit3b0349188c83b24cb8ff7dfe76796dabc3916e83 (patch)
treec8c3cf77ace1c03cea281baf3e924fe1c4dc6748 /model/Post.php
parent700449b8d903b9707b2751784dc54b4450a655df (diff)
Styling and formatting for posts
Diffstat (limited to 'model/Post.php')
-rw-r--r--model/Post.php35
1 files changed, 29 insertions, 6 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 '<blockquote></blockquote>';
+ }
+
+ $reply = mysqli_fetch_assoc($result);
+
+ if (empty($reply)) {
+ return '<blockquote>Invalid quote!</blockquote>';
+ }
+
+ $id = $id + 1;
+
+ return '<blockquote><a href="#' . $id .'">Quote from ' . $reply['user_name'] . '</a><br>' . $reply['post_content'] . '</blockquote>';
+ }
+}
+
class Post {
public $id;
public $content;
@@ -36,14 +58,15 @@ class Post {
mysqli_free_result($result);
}
- function display_content() {
- echo '<div class="header">#' . $this->id . ' Posted by <a href="viewuser.php?id='. $this->author->id.'">' . $this->author->name . '</a> on ' . date('m/d/Y g:ia', strtotime($this->date)) . '<br></div>';
+ function display_content($dbc) {
+ echo '<div class="header"><b>#' . $this->id . '</b> Posted by <a href="viewuser.php?id='. $this->author->id.'">' . $this->author->name . '</a> on ' . date('m/d/Y g:ia', strtotime($this->date)) . '<br></div>';
$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', '<a href="http$2://$3">$0</a>', $post_content);
- echo '<p class="post-content">' . $post_content . '</p>';
+ echo '<span class="post-content">' . $post_content . '</span>';
}
}