summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCflip <36554078+cflip@users.noreply.github.com>2021-01-28 10:59:12 -0700
committerCflip <36554078+cflip@users.noreply.github.com>2021-01-28 10:59:12 -0700
commite5c06f81e065aad0c711ca3baf578b3c0a4fd8d8 (patch)
tree340bb78cbcaa0347a00371e46b6bf36780ae0902
parentedc0e3a052540933d5becb918cf71dc8352ca667 (diff)
embed links and images/videos
-rw-r--r--styles/style.css9
-rw-r--r--thread.php14
2 files changed, 20 insertions, 3 deletions
diff --git a/styles/style.css b/styles/style.css
index b3f39a6..f83a9b6 100644
--- a/styles/style.css
+++ b/styles/style.css
@@ -125,6 +125,15 @@ th a:hover {
padding: 12px;
}
+.youtube-embed {
+ width: 480px;
+ height: 270px;
+}
+
+.image-embed {
+ width: 480px;
+}
+
h1, h4 {
margin-top: 2px;
margin-bottom: 10px;
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 '<blockquote><a href="#' . $id .'">Quote from ' . $reply['user_name'] . '</a><br>' . $reply['post_content'] . '</blockquote>';
+ return '<blockquote><a href="#' . $id + 1 .'">Quote from ' . $reply['user_name'] . '</a><br>' . $reply['post_content'] . '</blockquote>';
}
}
@@ -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",
+ '<br><iframe class="youtube-embed" src="//www.youtube.com/embed/$2" allowfullscreen></iframe>', $post_content);
+
+ $post_content = preg_replace('/(https?:\/\/[^ ]+?(?:\.jpg|\.png|\.gif))/', '<img class="image-embed" src="$1" alt="$1" />', $post_content);
+
+ $post_content = preg_replace('@\b(http(s)?://)?([^\s]*?(?:\.[a-z\d?=/_-]+)+)(?![^<]*?(?:</\w+>|/?>))@i', '<a href="http$2://$3">$0</a>', $post_content);
+
echo '<td class="post-content">' . $post_content . '</td></tr>';
$post_index++;