query($sql, "i", $id);
if (empty($result)) {
return false;
}
$this->id = $id;
$this->content = $result[0]['post_content'];
$this->date_created = $result[0]['post_date_created'];
$this->date_edited = $result[0]['post_date_edited'];
$this->thread = new Thread();
$this->thread->get_from_database($result[0]['post_thread']);
$this->author = new User();
$this->author->get_by_id($result[0]['post_author']);
return true;
}
function display_content($dbc)
{
echo '
';
$post_content = $this->content;
$thread_id = $this->id;
$post_content = preg_replace_callback('/>#\d+/', function ($matches) use ($thread_id, $dbc) {
return create_quote($dbc, $thread_id, $matches);
}, $post_content);
// Replace newline characters with HTML
tags
$post_content = nl2br($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",
'
', $post_content);
// Replace Image URLs with embedded images.
$post_content = preg_replace('@\b(http(s)?://)([^\s]*?(?:\.[a-z\d?=/_-]+)+(?:\.jpg|\.png|\.gif))(?![^<]*?(?:\w+>|/?>))@i', '
', $post_content);
// Replace other URLs with links.
$post_content = preg_replace('@\b(http(s)?://)([^\s]*?(?:\.[a-z\d?=/_-]+)+)(?![^<]*?(?:\w+>|/?>))@i', '$0', $post_content);
echo '' . $post_content . '';
}
}