From 24efe49bc2b545e3a3e46d7d6f2bd1166163e52b Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Sat, 5 Jun 2021 11:18:10 -0600 Subject: Move object related functions into their classes. Some of the pages are still broken from this commit, but I plan to either rewrite or ignore them. --- includes/functions_post.php | 159 -------------------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 includes/functions_post.php (limited to 'includes/functions_post.php') diff --git a/includes/functions_post.php b/includes/functions_post.php deleted file mode 100644 index 97fc622..0000000 --- a/includes/functions_post.php +++ /dev/null @@ -1,159 +0,0 @@ -query($sql); - - $posts = array(); - - foreach ($result as $row) { - $post = new Post(); - $post->get_from_database($row['post_id']); - array_push($posts, $post); - } - - return $posts; -} - -function create_post($post_content, $post_thread, $post_category) -{ - // User must be signed in - if (!Session::get()->is_signed_in()) { - trigger_error('You must be signed in to create a post'); - return; - } - - $user = Session::get()->get_current_user(); - - // Insert the post into the database - $sql = "INSERT INTO posts(post_content, post_date_created, post_thread, post_author) VALUES (?, CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), ?, ?);"; - Database::get()->query($sql, "sii", $post_content, $post_thread, $user->id); - - // Increment the category's post count - $sql = "UPDATE categories SET `cat_post_count` = `cat_post_count` + '1' WHERE cat_id = ?;"; - Database::get()->query($sql, "i", $post_category); - - // Set the last post date of the parent thread - $sql = "UPDATE threads SET thread_date_lastpost = CONVERT_TZ(NOW(), 'SYSTEM', '+00:00') WHERE thread_id = ?;"; - Database::get()->query($sql, "i", $post_thread); -} - -function create_quote(int $id): string -{ - $sql = "SELECT post_content, post_author, post_thread, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_id = ?;"; - $result = Database::get()->query($sql, "i", $id); - - $reply = $result[0]; - - if (empty($reply)) { - return '
This post has been deleted'; - } - - return '
Quote from ' . $reply['user_name'] . ''; -} - -function format_post_content(string $post_content) -{ - $post_content = preg_replace_callback('/>#\d+/', function ($matches) { - $result = ""; - foreach ($matches as $match) { - $id = (int) filter_var($match, FILTER_SANITIZE_NUMBER_INT); - $result .= create_quote($id); - } - return $result; - }, $post_content); - - $result = $post_content; - - // Replace newline characters with HTML
' . $reply['post_content'] . '