summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/functions_display.php110
1 files changed, 0 insertions, 110 deletions
diff --git a/includes/functions_display.php b/includes/functions_display.php
deleted file mode 100644
index 47ba188..0000000
--- a/includes/functions_display.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-
-function display_navbar($dbc) {
-
-}
-
-function display_categories($dbc, $sql_result) {
- $sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name FROM threads JOIN users ON thread_author = user_id WHERE thread_cat = ? ORDER BY thread_id DESC LIMIT 1";
- $stmt = mysqli_stmt_init($dbc);
-
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- die('Could not create thread due to internal error: ' . mysqli_error($dbc));
- }
-
- while ($row = mysqli_fetch_assoc($sql_result)) {
- mysqli_stmt_bind_param($stmt, "i", $row['cat_id']);
- mysqli_stmt_execute($stmt);
-
- $thread_res = mysqli_stmt_get_result($stmt);
- $thread = mysqli_fetch_assoc($thread_res);
-
- echo '<tr><td class="left">';
- echo '<h4><a href="category.php?id=' . $row['cat_id'] . '">' . $row['cat_name'] . '</a></h4>';
- echo $row['cat_description'];
- if ($thread) {
- echo '</td><td class="right">' . $thread['thread_subject'] . '<br>';
- echo '<small>by <b><a href="user.php?id=' . $thread['user_id'] . '">' . $thread['user_name'] . '</a></b></small></td></tr>';
- } else {
- $no_threads_msg = 'There are no threads in this category yet.';
- echo '</td><td class="right"><small>'. $no_threads_msg .'</small></td>';
- }
- }
-
- mysqli_stmt_close($stmt);
- mysqli_free_result($thread_res);
-}
-
-function display_threads($dbc, $sql_result, $show_category = false) {
- $sql = "SELECT post_id, post_date, user_id, user_name FROM posts JOIN users ON post_author = user_id WHERE post_thread = ? ORDER BY post_id DESC LIMIT 1";
- $stmt = mysqli_stmt_init($dbc);
-
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- die('Could not create thread due to internal error: ' . mysqli_error($dbc));
- }
-
- while ($row = mysqli_fetch_assoc($sql_result)) {
- mysqli_stmt_bind_param($stmt, "i", $row['thread_id']);
- mysqli_stmt_execute($stmt);
-
- $thread_res = mysqli_stmt_get_result($stmt);
- $thread = mysqli_fetch_assoc($thread_res);
-
- echo '<tr><td class="left">';
- echo '<h4><a href="thread.php?id=' . $row['thread_id'] . '">' . $row['thread_subject'] . '</a></h4>';
- echo '<small>by <b><a href="user.php?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a></b> ';
- if ($show_category) {
- echo 'in <b><a href="category.php?id=' . $row['cat_id'] . '">' . $row['cat_name'] . '</a></b> ';
- }
- echo 'on ' . date('M d, Y', strtotime($row['thread_date'])) . '</small>';
- echo '</td><td class="right">by <b><a href="user.php?id=' . $thread['user_id'] . '">' . $thread['user_name'] . '</a></b><br>';
- echo '<small>' . date('m/d/Y g:ia', strtotime($thread['post_date'])) . '</small></td></tr>';
- }
-
- mysqli_stmt_close($stmt);
-}
-
-function add_quote($dbc, $thread_id, $matches) {
- foreach ($matches as $match) {
- $id = (int) filter_var($match, FILTER_SANITIZE_NUMBER_INT) - 1;
- $sql = "SELECT post_content, post_author, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_thread = " . $thread_id . " LIMIT 1 OFFSET " . $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>';
- }
-}
-
-function display_posts($dbc, $thread_id, $sql_result) {
- while ($row = mysqli_fetch_assoc($sql_result)) {
- echo '#' . $row['post_id'] . ' Posted by <a href="user.php?id='. $row['user_id'] .'">' . $row['user_name'] . '</a> on ' . date('m/d/Y g:ia', strtotime($row['post_date'])) . '<br>';
-
- $post_content = $row['post_content'];
-
- $post_content = preg_replace_callback('/>#\d+/', function($matches) use($thread_id, $dbc) {
- return create_quote($dbc, $thread_id, $matches);
- }, $post_content);
-
- // Replace YouTube URLs with embedded YouTube videos.
- $post_content = preg_replace(
- "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
- '<br><iframe class="youtube-embed" src="//www.youtube.com/embed/$2" allowfullscreen></iframe>', $post_content);
- // Replace Image URLs with embedded images.
- $post_content = preg_replace('@\b(http(s)?://)([^\s]*?(?:\.[a-z\d?=/_-]+)+(?:\.jpg|\.png|\.gif))(?![^<]*?(?:</\w+>|/?>))@i', '<img class="image-embed" src="http$2://$3" alt="http$2://$3" />', $post_content);
- // 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 $post_content;
- }
-} \ No newline at end of file