diff options
author | cflip <36554078+cflip@users.noreply.github.com> | 2021-04-07 16:24:54 -0600 |
---|---|---|
committer | cflip <36554078+cflip@users.noreply.github.com> | 2021-04-07 16:24:54 -0600 |
commit | 3b0349188c83b24cb8ff7dfe76796dabc3916e83 (patch) | |
tree | c8c3cf77ace1c03cea281baf3e924fe1c4dc6748 | |
parent | 700449b8d903b9707b2751784dc54b4450a655df (diff) |
Styling and formatting for posts
-rw-r--r-- | model/Post.php | 35 | ||||
-rw-r--r-- | search.php | 2 | ||||
-rw-r--r-- | styles/style.css | 23 | ||||
-rw-r--r-- | 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 '<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>'; } } @@ -47,7 +47,7 @@ foreach ($posts as $post) { echo '<h4>From ' . $post->thread->subject . '</h4>'; - $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)) { <!DOCTYPE html> <html> <head> - <title><?php echo $current->subject; ?> - cflip.net forum</title> + <title><?= $current->subject; ?> - cflip.net forum</title> <link rel="stylesheet" href="styles/style.css"> </head> <body> <?php include_once 'templates/header.php';?> - <h1><?php echo $current->subject; ?></h1> - created by <b><?php echo $current->author->name; ?></b> - in <b><?php echo $current->category->name; ?></b> - <abbr title="<?php echo date('M d, Y g:ia', strtotime($current->date_created));?>">3 days ago</abbr> + <h1><?= $current->subject; ?></h1> + created by <b><?= $current->author->name; ?></b> + in <b><?= $current->category->name; ?></b> + <abbr title="<?= date('M d, Y g:ia', strtotime($current->date_created));?>">3 days ago</abbr> <hr> <?php $posts = $current->get_posts($dbc); foreach ($posts as $post) { - $post->display_content(); + $post->display_content($dbc); } ?> <hr> |