From e5c06f81e065aad0c711ca3baf578b3c0a4fd8d8 Mon Sep 17 00:00:00 2001 From: Cflip <36554078+cflip@users.noreply.github.com> Date: Thu, 28 Jan 2021 10:59:12 -0700 Subject: embed links and images/videos --- thread.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'thread.php') diff --git a/thread.php b/thread.php index 0ba4906..7eb0e88 100644 --- a/thread.php +++ b/thread.php @@ -5,8 +5,8 @@ include_once 'includes/db_inc.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_thread = " . $thread_id . " LIMIT 1 OFFSET " . $id - 1; + $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) { @@ -15,7 +15,7 @@ function add_quote($dbc, $thread_id, $matches) { $reply = mysqli_fetch_assoc($result); - return '
Quote from ' . $reply['user_name'] . '
' . $reply['post_content'] . '
'; + return '
Quote from ' . $reply['user_name'] . '
' . $reply['post_content'] . '
'; } } @@ -64,6 +64,14 @@ if (mysqli_num_rows($result) == 0) { return add_quote($dbc, $thread_id, $matches); }, $post_content); + $post_content = preg_replace( + "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", + '
', $post_content); + + $post_content = preg_replace('/(https?:\/\/[^ ]+?(?:\.jpg|\.png|\.gif))/', '$1', $post_content); + + $post_content = preg_replace('@\b(http(s)?://)?([^\s]*?(?:\.[a-z\d?=/_-]+)+)(?![^<]*?(?:|/?>))@i', '$0', $post_content); + echo '' . $post_content . ''; $post_index++; -- cgit v1.2.3