Antichrist Message Board - Source Excerpt 06
Back to Antichrist Message Board
Summary
This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/antichrist-message-board/antichrist-message-board.php so readers can inspect the evidence without opening the full source file.
**Source path:** Antichrist.net/wp-content/plugins/antichrist-message-board/antichrist-message-board.php
/**
* Render one topic card.
*
* @param WP_Post $post Topic post.
* @return string
*/
function acnmb_topic_card( WP_Post $post ) {
$reply_count = acnmb_reply_count( $post->ID );
$is_pinned = (bool) get_post_meta( $post->ID, '_acnmb_pinned', true );
$is_locked = (bool) get_post_meta( $post->ID, '_acnmb_locked', true );
$author = get_userdata( (int) $post->post_author );
$author_name = $author ? $author->display_name : acnmb_t( 'acnmb.board.unknown_author', 'Unknown member' );
$terms = get_the_terms( $post, ACNMB_CATEGORY_TAXONOMY );
$term_text = $terms && ! is_wp_error( $terms ) ? implode( ', ', wp_list_pluck( $terms, 'name' ) ) : acnmb_t( 'acnmb.board.uncategorized', 'Uncategorized' );
$excerpt = has_excerpt( $post ) ? get_the_excerpt( $post ) : wp_trim_words( wp_strip_all_tags( $post->post_content ), 28 );
$html = '<article class="acnmb-topic-card">';
$html .= '<div class="acnmb-topic-flags">';
if ( $is_pinned ) {
$html .= '<span>' . esc_html( acnmb_t( 'acnmb.board.pinned', 'Pinned' ) ) . '</span>';
}
if ( $is_locked ) {
$html .= '<span>' . esc_html( acnmb_t( 'acnmb.board.locked', 'Locked' ) ) . '</span>';
}
$html .= '</div>';
$html .= '<h2><a href="' . esc_url( get_permalink( $post ) ) . '">' . esc_html( get_the_title( $post ) ) . '</a></h2>';
$html .= '<p>' . esc_html( $excerpt ) . '</p>';
$html .= '<div class="acnmb-topic-meta">';
$html .= '<span>' . esc_html( $term_text ) . '</span>';
$html .= '<span>' . esc_html( acnmb_tf( 'acnmb.board.started_by', array( 'name' => $author_name ), 'Started by {name}' ) ) . '</span>';
$html .= '<span>' . esc_html( acnmb_tf( 'acnmb.board.reply_count', array( 'count' => $reply_count ), '{count} replies' ) ) . '</span>';
$html .= '</div>';
$html .= '</article>';
return $html;
}
/**
* Render pagination for board results.
*
* @param WP_Query $query Query object.
* @param string $selected_slug Selected category.
* @param string $search Search string.
* @param int $paged Page number.
* @return string
*/
function acnmb_render_pagination( WP_Query $query, $selected_slug, $search, $paged ) {
if ( $query->max_num_pages < 2 ) {
return '';
}
$html = '<nav class="acnmb-pagination" aria-label="' . esc_attr( acnmb_t( 'acnmb.board.pagination', 'Message board pages' ) ) . '">';
for ( $i = 1; $i <= (int) $query->max_num_pages; $i++ ) {
$args = array( 'board_page' => $i );
if ( $selected_slug ) {
$args['board_category'] = $selected_slug;
}
if ( $search ) {
$args['board_search'] = $search;
}
$class = (int) $paged === $i ? ' class="is-active"' : '';
$html .= '<a' . $class . ' href="' . esc_url( add_query_arg( $args, acnmb_board_url() ) ) . '">' . absint( $i ) . '</a>';
}
$html .= '</nav>';
return $html;
}
/**
* Render new-topic form or login prompt.
*
* @param WP_Term|null $selected_term Selected category.
* @return string
*/
function acnmb_render_topic_form( $selected_term = null ) {
if ( ! is_user_logged_in() ) {
$login_url = wp_login_url( acnmb_current_url() );
return '<div class="acnmb-form-panel"><h2>' . esc_html( acnmb_t( 'acnmb.board.login_title', 'Log in to post' ) ) . '</h2><p>' . esc_html( acnmb_t( 'acnmb.board.login_copy', 'The board is publicly readable, but posting requires a member account.' ) ) . '</p><a class="button" href="' . esc_url( $login_url ) . '">' . esc_html( acnmb_t( 'acnmb.board.login_button', 'Log in' ) ) . '</a></div>';
}
ob_start();
?>
<form class="acnmb-form-panel" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
<h2><?php echo esc_html( acnmb_t( 'acnmb.form.new_topic', 'Start a topic' ) ); ?></h2>
<input type="hidden" name="action" value="acnmb_create_topic" />
<input type="hidden" name="redirect_to" value="<?php echo esc_url( acnmb_current_url() ); ?>" />
<?php wp_nonce_field( 'acnmb_create_topic', 'acnmb_nonce' ); ?>
<label for="acnmb-topic-title"><?php echo esc_html( acnmb_t( 'acnmb.form.title', 'Title' ) ); ?></label>
<input id="acnmb-topic-title" type="text" name="topic_title" maxlength="160" required />
<label for="acnmb-topic-category"><?php echo esc_html( acnmb_t( 'acnmb.form.category', 'Category' ) ); ?></label>
<select id="acnmb-topic-category" name="topic_category" required>
<option value=""><?php echo esc_html( acnmb_t( 'acnmb.form.choose_category', 'Choose a category' ) ); ?></option>
<?php echo acnmb_render_category_select_options( $selected_term ); ?>
</select>
<label for="acnmb-topic-content"><?php echo esc_html( acnmb_t( 'acnmb.form.message', 'Message' ) ); ?></label>
<textarea id="acnmb-topic-content" name="topic_content" rows="8" required></textarea>
<button type="submit"><?php echo esc_html( acnmb_t( 'acnmb.form.publish_topic', 'Publish topic' ) ); ?></button>
</form>
<?php
return ob_get_clean();
}
/**
* Append full board topic view to single-topic pages.
*
* @param string $content Existing content.
* @return string
*/
function acnmb_render_topic_content( $content ) {
if ( is_admin() || ! is_singular( ACNMB_TOPIC_POST_TYPE ) || ! in_the_loop() || ! is_main_query() ) {
return $content;
}
$post = get_post();
if ( ! $post instanceof WP_Post ) {
return $content;
}
return acnmb_render_single_topic( $post, $content );
}
/**
* Render a single topic with replies.
*
* @param WP_Post $post Topic.
* @param string $content Topic content.
* @return string
*/
function acnmb_render_single_topic( WP_Post $post, $content ) {
$is_locked = (bool) get_post_meta( $post->ID, '_acnmb_locked', true );
$replies = acnmb_get_replies( $post->ID );
$locale = acnmb_current_locale_tag();
if ( acnmb_topic_locale( $post->ID ) !== $locale ) {
return '<div class="acnmb-empty"><h2>' . esc_html( acnmb_t( 'acnmb.topic.locale_mismatch_title', 'Topic unavailable' ) ) . '</h2><p>' . esc_html( acnmb_t( 'acnmb.topic.locale_mismatch_copy', 'This discussion belongs to another language board.' ) ) . '</p><p><a href="' . esc_url( acnmb_board_url() ) . '">' . esc_html( acnmb_t( 'acnmb.topic.back', 'Back to board' ) ) . '</a></p></div>';
}
ob_start();
?>
<article class="acnmb-single-topic">
<div class="acnmb-back-link"><a href="<?php echo esc_url( acnmb_board_url() ); ?>"><?php echo esc_html( acnmb_t( 'acnmb.topic.back', 'Back to board' ) ); ?></a></div>
<div class="acnmb-topic-body">
<?php echo wp_kses_post( $content ); ?>
</div>
<section class="acnmb-replies" aria-labelledby="acnmb-replies-title">
<h2 id="acnmb-replies-title"><?php echo esc_html( acnmb_tf( 'acnmb.topic.replies_title', array( 'count' => count( $replies ) ), 'Replies ({count})' ) ); ?></h2>
<?php if ( empty( $replies ) ) : ?>
<p><?php echo esc_html( acnmb_t( 'acnmb.topic.no_replies', 'No replies yet.' ) ); ?></p>
<?php else : ?>
<ol class="acnmb-reply-list">
<?php foreach ( $replies as $reply ) : ?>
<li id="reply-<?php echo absint( $reply->comment_ID ); ?>">
<div class="acnmb-reply-meta">
<strong><?php echo esc_html( get_comment_author( $reply ) ); ?></strong>
<span><?php echo esc_html( get_comment_date( '', $reply ) ); ?></span>
</div>
<div class="acnmb-reply-content"><?php echo wp_kses_post( wpautop( $reply->comment_content ) ); ?></div>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
</section>
<?php echo acnmb_render_reply_form( $post, $is_locked ); ?>
</article>
<?php
return ob_get_clean();
}
/**
* Render reply form or login/locked notice.
*
* @param WP_Post $post Topic.
* @param bool $is_locked Locked flag.
* @return string
*/
function acnmb_render_reply_form( WP_Post $post, $is_locked ) {
if ( $is_locked ) {
return '<div class="acnmb-form-panel"><h2>' . esc_html( acnmb_t( 'acnmb.topic.locked_title', 'Topic locked' ) ) . '</h2><p>' . esc_html( acnmb_t( 'acnmb.topic.locked_copy', 'Replies are closed for this topic.' ) ) . '</p></div>';
}
if ( ! is_user_logged_in() ) {
return '<div class="acnmb-form-panel"><h2>' . esc_html( acnmb_t( 'acnmb.topic.login_title', 'Log in to reply' ) ) . '</h2><p>' . esc_html( acnmb_t( 'acnmb.topic.login_copy', 'Anyone can read this discussion, but replies require a member account.' ) ) . '</p><a class="button" href="' . esc_url( wp_login_url( get_permalink( $post ) ) ) . '">' . esc_html( acnmb_t( 'acnmb.board.login_button', 'Log in' ) ) . '</a></div>';
}