Skip to content
wiki.fftac.org

Antichrist Message Board - Source Excerpt 01

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

<?php
/**
 * Plugin Name: Antichrist.net Message Board
 * Description: Publicly readable, login-to-post message board with hierarchical categories for Antichrist.net.
 * Version: 3.28.0
 * Author: Antichrist.net
 * License: GPL-2.0-or-later
 * Text Domain: antichrist-message-board
 *
 * @package AntichristMessageBoard
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

define( 'ACNMB_VERSION', '3.28.0' );
define( 'ACNMB_PLUGIN_FILE', __FILE__ );
define( 'ACNMB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ACNMB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'ACNMB_TOPIC_POST_TYPE', 'acn_board_topic' );
define( 'ACNMB_CATEGORY_TAXONOMY', 'acn_board_category' );

add_action( 'plugins_loaded', 'acnmb_load_textdomain' );
add_action( 'init', 'acnmb_register_content_types', 5 );
add_action( 'init', 'acnmb_configure_locale_router', 16 );
add_action( 'init', 'acnmb_maybe_upgrade', 35 );
add_action( 'wp_enqueue_scripts', 'acnmb_enqueue_assets' );
add_action( 'admin_post_acnmb_create_topic', 'acnmb_handle_create_topic' );
add_action( 'admin_post_acnmb_create_reply', 'acnmb_handle_create_reply' );
add_action( 'add_meta_boxes', 'acnmb_add_topic_meta_box' );
add_action( 'save_post_' . ACNMB_TOPIC_POST_TYPE, 'acnmb_save_topic_meta', 10, 2 );
add_filter( 'the_content', 'acnmb_render_topic_content', 20 );
add_filter( 'manage_' . ACNMB_TOPIC_POST_TYPE . '_posts_columns', 'acnmb_topic_admin_columns' );
add_action( 'manage_' . ACNMB_TOPIC_POST_TYPE . '_posts_custom_column', 'acnmb_render_topic_admin_column', 10, 2 );
add_shortcode( 'acn_message_board', 'acnmb_render_board_shortcode' );
add_filter( 'uaixlr_locale_dictionary', 'acnmb_merge_runtime_dictionary_strings', 11, 2 );
add_filter( 'ns12lr_locale_dictionary', 'acnmb_merge_runtime_dictionary_strings', 11, 2 );

register_activation_hook( __FILE__, 'acnmb_activate' );
register_deactivation_hook( __FILE__, 'acnmb_deactivate' );

/**
 * Load gettext translations.
 */
function acnmb_load_textdomain() {
	load_plugin_textdomain( 'antichrist-message-board', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}

/**
 * Translate a message-board string through the locale router when available.
 *
 * @param string $key Translation key.
 * @param string $fallback English fallback.
 * @return string
 */
function acnmb_t( $key, $fallback ) {
	$strings = acnmb_translation_strings();
	if ( isset( $strings[ $key ] ) ) {
		$value = acnmb_translation_value_for_locale( $strings[ $key ], acnmb_current_locale_tag() );
		if ( '' !== trim( $value ) ) {
			return $value;
		}
	}

	if ( function_exists( 'uaixlr_t' ) ) {
		return uaixlr_t( $key, $fallback );
	}

	if ( function_exists( 'ns12lr_t' ) ) {
		return ns12lr_t( $key, $fallback );
	}

	return __( $fallback, 'antichrist-message-board' );
}

/**
 * Translate and interpolate a string.
 *
 * @param string $key Translation key.
 * @param array  $replacements Placeholder replacements.
 * @param string $fallback English fallback.
 * @return string
 */
function acnmb_tf( $key, array $replacements, $fallback ) {
	$strings = acnmb_translation_strings();
	if ( isset( $strings[ $key ] ) ) {
		$value = acnmb_translation_value_for_locale( $strings[ $key ], acnmb_current_locale_tag() );
		if ( '' !== trim( $value ) ) {
			foreach ( $replacements as $name => $replacement ) {
				$value = str_replace( '{' . $name . '}', (string) $replacement, $value );
			}
			return $value;
		}
	}

	if ( function_exists( 'uaixlr_t_format' ) ) {
		return uaixlr_t_format( $key, $replacements, $fallback );
	}

	if ( function_exists( 'ns12lr_t_format' ) ) {
		return ns12lr_t_format( $key, $replacements, $fallback );
	}

	$value = __( $fallback, 'antichrist-message-board' );
	foreach ( $replacements as $name => $replacement ) {
		$value = str_replace( '{' . $name . '}', (string) $replacement, $value );
	}
	return $value;
}

/**
 * Return locale tags that must have isolated board content.
 *
 * @return array
 */
function acnmb_required_locale_tags() {
	if ( function_exists( 'acn_cs_required_locale_tags' ) ) {
		return acn_cs_required_locale_tags();
	}

	return array( 'en-US', 'es-US', 'fr-FR', 'zh-CN' );
}

/**
 * Return the active locale repository class.
 *
 * @return string
 */
function acnmb_locale_repository_class() {
	if ( class_exists( '\UAIXLocaleRouter\LocaleRepository' ) ) {
		return '\UAIXLocaleRouter\LocaleRepository';
	}

	if ( class_exists( '\Ns12LocaleRouter\LocaleRepository' ) ) {
		return '\Ns12LocaleRouter\LocaleRepository';
	}

	return '';
}

/**
 * Return the active locale-router settings class.
 *
 * @return string
 */
function acnmb_locale_settings_class() {
	if ( class_exists( '\UAIXLocaleRouter\Settings' ) ) {
		return '\UAIXLocaleRouter\Settings';
	}

	if ( class_exists( '\Ns12LocaleRouter\Settings' ) ) {
		return '\Ns12LocaleRouter\Settings';
	}

	return '';
}

/**
 * Default locale-router record for a board-supported locale.
 *
 * @param string $tag Locale tag.
 * @return array
 */
function acnmb_required_locale_record( $tag ) {
	if ( 'es-US' === $tag ) {
		return array(
			'tag'        => 'es-US',
			'urlTag'     => 'es-us',
			'language'   => 'Spanish',
			'nativeName' => 'Espanol (Estados Unidos)',
			'region'     => 'US',
			'script'     => 'Latn',
			'isRtl'      => false,
			'enabled'    => true,
			'isDefault'  => false,
			'fallback'   => 'en-US',
		);
	}

	if ( 'fr-FR' === $tag ) {
		return array(
			'tag'        => 'fr-FR',
			'urlTag'     => 'fr-fr',
			'language'   => 'French',
			'nativeName' => 'Francais (France)',
			'region'     => 'FR',
			'script'     => 'Latn',
			'isRtl'      => false,
			'enabled'    => true,
			'isDefault'  => false,
			'fallback'   => 'en-US',
		);
	}

	if ( 'zh-CN' === $tag ) {
		return array(
			'tag'        => 'zh-CN',
			'urlTag'     => 'zh-cn',
			'language'   => 'Chinese',
			'nativeName' => 'Chinese (China)',
			'region'     => 'CN',
			'script'     => 'Hans',
			'isRtl'      => false,
			'enabled'    => true,
			'isDefault'  => false,
			'fallback'   => 'en-US',
		);
	}

	return array(
		'tag'        => 'en-US',
		'urlTag'     => 'en-us',
		'language'   => 'English',
		'nativeName' => 'English (United States)',
		'region'     => 'US',
		'script'     => 'Latn',
		'isRtl'      => false,
		'enabled'    => true,
		'isDefault'  => true,
		'fallback'   => 'en-US',
	);
}

/**
 * Detect stale locale-router settings when the board is installed without the content system.
 *
 * @param string $locale_repository Locale repository class.
 * @return bool
 */
function acnmb_locale_router_needs_config( $locale_repository ) {
	$required = acnmb_required_locale_tags();
	$enabled  = array();
	$default  = '';

	foreach ( $locale_repository::get_supported_locales() as $locale ) {
		if ( ! is_array( $locale ) || empty( $locale['tag'] ) ) {
			continue;
		}

		$tag = (string) $locale['tag'];
		if ( ! empty( $locale['enabled'] ) ) {
			$enabled[] = $tag;
		}

		if ( ! empty( $locale['isDefault'] ) ) {
			$default = $tag;
		}

		if ( in_array( $tag, $required, true ) ) {
			$expected = acnmb_required_locale_record( $tag );
			foreach ( array( 'enabled', 'isDefault', 'urlTag', 'fallback' ) as $key ) {
				if ( ! array_key_exists( $key, $locale ) || $locale[ $key ] !== $expected[ $key ] ) {
					return true;
				}
			}
		}
	}

	sort( $enabled );
	sort( $required );

	return $enabled !== $required || 'en-US' !== $default;
}

/**
 * Pin the locale router to real board locales if the site content system is absent.
 */
function acnmb_configure_locale_router() {
	if ( function_exists( 'acn_cs_configure_locale_router' ) ) {
		return;
	}

	$locale_repository = acnmb_locale_repository_class();
	if ( '' === $locale_repository || ! acnmb_locale_router_needs_config( $locale_repository ) ) {
		return;
	}

	$allowed = acnmb_required_locale_tags();
	$locales = $locale_repository::get_supported_locales();
	$known   = array();

	foreach ( $locales as $locale ) {
		if ( is_array( $locale ) && ! empty( $locale['tag'] ) ) {
			$known[ (string) $locale['tag'] ] = true;
		}
	}

	foreach ( $allowed as $tag ) {
		if ( empty( $known[ $tag ] ) ) {
			$locales[] = acnmb_required_locale_record( $tag );
		}
	}

	foreach ( $locales as &$locale ) {
		$tag = isset( $locale['tag'] ) ? (string) $locale['tag'] : '';

		$locale['enabled']   = in_array( $tag, $allowed, true );
		$locale['isDefault'] = 'en-US' === $tag;

		if ( in_array( $tag, $allowed, true ) ) {
			$locale = array_merge( $locale, acnmb_required_locale_record( $tag ) );
		}
	}
	unset( $locale );

	$locale_repository::save_supported_locales( $locales );

	$option_prefix = class_exists( '\UAIXLocaleRouter\LocaleRepository' ) ? 'uaixlr' : 'ns12lr';
	update_option( $option_prefix . '_default_locale', 'en-US', false );