Skip to main content
The Post model represents an individual post/message in a topic. It extends DataModel and provides properties and methods for managing post content, permissions, and user interactions.

Location

app/Models/Post/Post.php

Properties

id
int
Unique post identifier
topic_id
int
ID of the parent topic
poster_id
int
ID of the user who created the post
poster
string
Username of the poster (stored for guests)
poster_email
string
Email of the poster (for guests)
poster_ip
string
IP address of the poster
message
string
Raw post content (BBCode or markdown)
posted
int
Timestamp when post was created
edited
int
Timestamp of last edit (0 if never edited)
editor_id
int
ID of user who last edited the post
edit_post
int
Edit flag/counter
hide_smilies
int
Whether to hide smilies (0=show, 1=hide)

Computed Properties

parent
Topic|null
Parent topic object. Returns null if topic is invalid or moved.
user
User
User object for the post author. Returns guest user if poster_id < 1.
Direct URL to this post

Permission Properties

canReport
bool
Returns true if current user can report this post
canDelete
bool
Returns true if current user can delete this post
canEdit
bool
Returns true if current user can edit this post
canQuote
bool
Returns true if current user can quote this post (same as canReply on parent topic)
useReaction
bool
Returns true if current user can react to this post
URL to report this post
URL to delete this post
URL to edit this post
URL to edit author and date (admin/moderator only)
URL to reply with quote
URL to view IP/host information (admin only)
URL to mark/unmark post as solution

Methods

html()

Returns the parsed HTML content of the post.
public function html(): string
Returns: HTML-formatted, censored post content Example:
$post = $container->posts->load(123);
echo $post->html();

reactionData()

Generates reaction form data for this post.
public function reactionData(bool $allow = true): ?array
allow
bool
Whether to allow reactions
Returns: Array of reaction data or null Example:
$post = $container->posts->load(123);
$reactions = $post->reactionData();

if ($reactions) {
    // Display reaction options
    foreach ($reactions['available'] as $reaction) {
        echo "<button>{$reaction['emoji']}</button>";
    }
}

Usage Example

// Load a post
$post = $container->posts->load(456);

// Display post content
echo "<div class='post' id='p{$post->id}'>";

// Display author info
$author = $post->user;
echo "<div class='author'>";
if (!$author->isGuest && $author->avatar) {
    echo "<img src=\"{$author->avatar}\" alt='Avatar'>";
}
echo "<strong>{$author->username}</strong><br>";
echo $author->title();
echo "</div>";

// Display post message
echo "<div class='message'>";
echo $post->html();
echo "</div>";

// Display post metadata
echo "<div class='meta'>";
echo "Posted: " . date('Y-m-d H:i:s', $post->posted);

if ($post->edited > 0) {
    echo " (Edited: " . date('Y-m-d H:i:s', $post->edited) . ")";
}
echo "</div>";

// Display action buttons
echo "<div class='actions'>";

if ($post->canEdit) {
    echo "<a href=\"{$post->linkEdit}\">Edit</a> ";
}

if ($post->canDelete) {
    echo "<a href=\"{$post->linkDelete}\">Delete</a> ";
}

if ($post->canQuote) {
    echo "<a href=\"{$post->linkQuote}\">Quote</a> ";
}

if ($post->canReport) {
    echo "<a href=\"{$post->linkReport}\">Report</a> ";
}

// Admin/moderator actions
if ($container->user->isAdmMod) {
    echo "<a href=\"{$post->linkGetHost}\">IP: {$post->poster_ip}</a> ";
    echo "<a href=\"{$post->linkAnD}\">Edit Author/Date</a> ";
}

echo "</div>";

// Display reactions if enabled
if ($post->useReaction) {
    $reactions = $post->reactionData();
    if ($reactions) {
        echo "<div class='reactions'>";
        // Render reaction interface
        echo "</div>";
    }
}

echo "</div>";

Post Editing Example

// Load post and check edit permission
$post = $container->posts->load(456);

if (!$post->canEdit) {
    throw new Exception('You cannot edit this post');
}

// Update post content
$post->message = 'Updated post content with [b]BBCode[/b]';
$post->edited = time();
$post->editor_id = $container->user->id;

// Save changes
$container->posts->update($post);

// Update topic table of contents if needed
if ($post->parent->poster_id === $post->poster_id) {
    // Parse the message to extract headings
    $container->Parser->parseMessage($post->message);
    $post->parent->addPostToToc($post);
    $container->topics->update($post->parent);
}

Permission Checking Example

$post = $container->posts->load(456);
$currentUser = $container->user;

// Check various permissions
if ($post->canEdit) {
    echo "You can edit this post\n";
}

if ($post->canDelete) {
    echo "You can delete this post\n";
}

if ($currentUser->isAdmin) {
    // Admins can always edit/delete
    echo "Admin can see IP: {$post->poster_ip}\n";
}

if ($currentUser->isModerator($post)) {
    // Moderators have special permissions
    echo "You moderate this post's forum\n";
}

// Check if user is the author
if ($post->poster_id === $currentUser->id) {
    echo "You are the author of this post\n";
    
    // Check edit time limits
    $editInterval = $currentUser->g_deledit_interval;
    if ($editInterval > 0 && time() - $post->posted > $editInterval) {
        echo "Edit time limit expired\n";
    }
}