Antichrist Message Board - Source Excerpt 07
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
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.topic.reply_heading', 'Reply to this topic' ) ); ?></h2>
<input type="hidden" name="action" value="acnmb_create_reply" />
<input type="hidden" name="topic_id" value="<?php echo absint( $post->ID ); ?>" />
<input type="hidden" name="redirect_to" value="<?php echo esc_url( get_permalink( $post ) ); ?>" />
<?php wp_nonce_field( 'acnmb_create_reply_' . $post->ID, 'acnmb_nonce' ); ?>
<label for="acnmb-reply-content"><?php echo esc_html( acnmb_t( 'acnmb.topic.reply_label', 'Reply' ) ); ?></label>
<textarea id="acnmb-reply-content" name="reply_content" rows="7" required></textarea>
<button type="submit"><?php echo esc_html( acnmb_t( 'acnmb.topic.publish_reply', 'Publish reply' ) ); ?></button>
</form>
<?php
return ob_get_clean();
}
/**
* Handle topic form submission.
*/
function acnmb_handle_create_topic() {
if ( ! is_user_logged_in() || ! isset( $_POST['acnmb_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['acnmb_nonce'] ) ), 'acnmb_create_topic' ) ) {
wp_safe_redirect( add_query_arg( 'acnmb_status', 'login_required', acnmb_submission_redirect() ) );
exit;
}
$result = acnmb_insert_topic(
array(
'title' => isset( $_POST['topic_title'] ) ? wp_unslash( $_POST['topic_title'] ) : '',
'content' => isset( $_POST['topic_content'] ) ? wp_unslash( $_POST['topic_content'] ) : '',
'category' => isset( $_POST['topic_category'] ) ? absint( $_POST['topic_category'] ) : 0,
),
get_current_user_id()
);
if ( is_wp_error( $result ) ) {
wp_safe_redirect( add_query_arg( 'acnmb_status', $result->get_error_code(), acnmb_submission_redirect() ) );
exit;
}
wp_safe_redirect( get_permalink( $result ) );
exit;
}
/**
* Handle reply form submission.
*/
function acnmb_handle_create_reply() {
$topic_id = isset( $_POST['topic_id'] ) ? absint( $_POST['topic_id'] ) : 0;
if ( ! is_user_logged_in() || ! $topic_id || ! isset( $_POST['acnmb_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['acnmb_nonce'] ) ), 'acnmb_create_reply_' . $topic_id ) ) {
wp_safe_redirect( add_query_arg( 'acnmb_status', 'login_required', acnmb_submission_redirect() ) );
exit;
}
$result = acnmb_insert_reply(
$topic_id,
isset( $_POST['reply_content'] ) ? wp_unslash( $_POST['reply_content'] ) : '',
get_current_user_id()
);
if ( is_wp_error( $result ) ) {
wp_safe_redirect( add_query_arg( 'acnmb_status', $result->get_error_code(), acnmb_submission_redirect() ) );
exit;
}
wp_safe_redirect( add_query_arg( 'acnmb_status', 'reply_created', get_permalink( $topic_id ) ) . '#reply-' . absint( $result ) );
exit;
}
/**
* Insert a topic programmatically.
*
* @param array $data Topic data.
* @param int $user_id User ID.
* @return int|WP_Error
*/
function acnmb_insert_topic( array $data, $user_id ) {
$user_id = absint( $user_id );
if ( ! $user_id || ! get_userdata( $user_id ) ) {
return new WP_Error( 'login_required', acnmb_t( 'acnmb.error.login_required', 'Log in before posting.' ) );
}
if ( acnmb_is_rate_limited( 'topic', $user_id ) ) {
return new WP_Error( 'rate_limited', acnmb_t( 'acnmb.error.rate_limited', 'Please wait a moment before posting again.' ) );
}
$locale = isset( $data['locale'] ) ? acnmb_normalize_locale_tag( $data['locale'] ) : acnmb_current_locale_tag();
$title = isset( $data['title'] ) ? sanitize_text_field( $data['title'] ) : '';
$content = isset( $data['content'] ) ? wp_kses_post( $data['content'] ) : '';
$category = isset( $data['category'] ) ? $data['category'] : '';
if ( strlen( $title ) < 4 ) {
return new WP_Error( 'title_required', acnmb_t( 'acnmb.error.title_required', 'Add a clearer title.' ) );
}
if ( strlen( wp_strip_all_tags( $content ) ) < 8 ) {
return new WP_Error( 'message_required', acnmb_t( 'acnmb.error.message_required', 'Add a message before posting.' ) );
}
$term = acnmb_resolve_category_term( $category, $locale );
if ( ! $term instanceof WP_Term || is_wp_error( $term ) ) {
return new WP_Error( 'category_required', acnmb_t( 'acnmb.error.category_required', 'Choose a board category.' ) );
}
$post_id = wp_insert_post(
wp_slash(
array(
'post_type' => ACNMB_TOPIC_POST_TYPE,
'post_status' => 'publish',
'post_title' => $title,
'post_content' => $content,
'post_author' => $user_id,
'comment_status' => 'open',
)
),
true
);
if ( is_wp_error( $post_id ) ) {
return $post_id;
}
wp_set_object_terms( $post_id, array( (int) $term->term_id ), ACNMB_CATEGORY_TAXONOMY );
update_post_meta( $post_id, '_acnmb_locale', $locale );
update_post_meta( $post_id, '_acnmb_category_base_slug', acnmb_term_base_slug( $term ) );
update_post_meta( $post_id, '_acnmb_pinned', 0 );
update_post_meta( $post_id, '_acnmb_locked', 0 );
acnmb_set_rate_limit( 'topic', $user_id );
return (int) $post_id;
}
/**
* Insert a reply programmatically.
*
* @param int $topic_id Topic ID.
* @param string $content Reply content.
* @param int $user_id User ID.
* @return int|WP_Error
*/
function acnmb_insert_reply( $topic_id, $content, $user_id ) {
$user_id = absint( $user_id );
$topic_id = absint( $topic_id );
$topic = get_post( $topic_id );
if ( ! $user_id || ! get_userdata( $user_id ) ) {
return new WP_Error( 'login_required', acnmb_t( 'acnmb.error.login_required', 'Log in before posting.' ) );
}
if ( ! $topic instanceof WP_Post || ACNMB_TOPIC_POST_TYPE !== $topic->post_type || 'publish' !== $topic->post_status ) {
return new WP_Error( 'topic_not_found', acnmb_t( 'acnmb.error.topic_not_found', 'Topic not found.' ) );
}
$topic_locale = acnmb_topic_locale( $topic_id );
$current_locale = acnmb_current_locale_tag();
if ( $topic_locale !== $current_locale ) {
return new WP_Error( 'locale_mismatch', acnmb_t( 'acnmb.error.locale_mismatch', 'This topic belongs to another language board.' ) );
}
if ( get_post_meta( $topic_id, '_acnmb_locked', true ) ) {
return new WP_Error( 'topic_locked', acnmb_t( 'acnmb.error.topic_locked', 'This topic is locked.' ) );
}
if ( acnmb_is_rate_limited( 'reply', $user_id ) ) {
return new WP_Error( 'rate_limited', acnmb_t( 'acnmb.error.rate_limited', 'Please wait a moment before posting again.' ) );
}
$content = wp_kses_post( $content );
if ( strlen( wp_strip_all_tags( $content ) ) < 3 ) {
return new WP_Error( 'message_required', acnmb_t( 'acnmb.error.reply_required', 'Add a reply before posting.' ) );
}
$user = get_userdata( $user_id );
$id = wp_insert_comment(
wp_slash(
array(
'comment_post_ID' => $topic_id,
'comment_author' => $user->display_name,
'comment_author_email' => $user->user_email,
'comment_content' => $content,
'user_id' => $user_id,
'comment_type' => 'acn_board_reply',
'comment_approved' => 1,
)
)
);
if ( ! $id ) {
return new WP_Error( 'reply_failed', acnmb_t( 'acnmb.error.reply_failed', 'Reply could not be saved.' ) );
}
update_comment_meta( $id, '_acnmb_locale', $topic_locale );
wp_update_post(
array(
'ID' => $topic_id,
'post_modified' => current_time( 'mysql' ),
'post_modified_gmt' => current_time( 'mysql', 1 ),
)
);
acnmb_set_rate_limit( 'reply', $user_id );
return (int) $id;
}
/**
* Rate-limit front-end posting.
*
* @param string $action Action name.
* @param int $user_id User ID.
* @return bool
*/
function acnmb_is_rate_limited( $action, $user_id ) {
if ( defined( 'ACNMB_DISABLE_RATE_LIMITS' ) && ACNMB_DISABLE_RATE_LIMITS ) {
return false;
}
return (bool) get_transient( 'acnmb_' . sanitize_key( $action ) . '_' . absint( $user_id ) );
}
/**
* Set rate limit.
*
* @param string $action Action.
* @param int $user_id User ID.
*/
function acnmb_set_rate_limit( $action, $user_id ) {
if ( defined( 'ACNMB_DISABLE_RATE_LIMITS' ) && ACNMB_DISABLE_RATE_LIMITS ) {
return;
}
set_transient( 'acnmb_' . sanitize_key( $action ) . '_' . absint( $user_id ), 1, 30 );
}
/**
* Return approved board replies.
*
* @param int $topic_id Topic ID.
* @return array
*/
function acnmb_get_replies( $topic_id ) {
$locale = acnmb_topic_locale( $topic_id );
$meta_query = array(
array(
'key' => '_acnmb_locale',
'value' => $locale,
),
);
if ( 'en-US' === $locale ) {
$meta_query = array(
'relation' => 'OR',
array(
'key' => '_acnmb_locale',
'value' => 'en-US',
),
array(
'key' => '_acnmb_locale',
'compare' => 'NOT EXISTS',
),
);
}
return get_comments(
array(
'post_id' => absint( $topic_id ),
'status' => 'approve',
'type' => 'acn_board_reply',
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'meta_query' => $meta_query,
)
);
}