Antichrist Message Board - Source Excerpt 02
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
$settings = (array) get_option( $option_prefix . '_settings', array() );
$settings = array_merge(
$settings,
array(
'enabled' => true,
'default_locale' => 'en-US',
'url_casing_strategy' => 'lowercase',
'trailing_slash_strategy' => 'always',
'redirect_bare_urls' => false,
'content_link_rewriting' => true,
)
);
update_option( $option_prefix . '_settings', $settings, false );
$settings_class = acnmb_locale_settings_class();
if ( '' !== $settings_class && method_exists( $settings_class, 'reset_cache' ) ) {
$settings_class::reset_cache();
}
}
/**
* Normalize a locale tag to one of the board-supported locales.
*
* @param string $locale Locale tag.
* @return string
*/
function acnmb_normalize_locale_tag( $locale ) {
$normalized = str_replace( '_', '-', trim( (string) $locale ) );
foreach ( acnmb_required_locale_tags() as $tag ) {
if ( strtolower( $normalized ) === strtolower( (string) $tag ) ) {
return (string) $tag;
}
}
if ( 0 === strpos( strtolower( $normalized ), 'es' ) ) {
return 'es-US';
}
if ( 0 === strpos( strtolower( $normalized ), 'fr' ) ) {
return 'fr-FR';
}
if ( 0 === strpos( strtolower( $normalized ), 'zh' ) ) {
return 'zh-CN';
}
return 'en-US';
}
/**
* Return the active public locale for board queries and submissions.
*
* @return string
*/
function acnmb_current_locale_tag() {
$forced = apply_filters( 'acnmb_current_locale', '' );
if ( is_string( $forced ) && '' !== trim( $forced ) ) {
return acnmb_normalize_locale_tag( $forced );
}
if ( function_exists( 'acn_cs_current_locale_tag' ) ) {
return acnmb_normalize_locale_tag( acn_cs_current_locale_tag() );
}
foreach (
array(
array( '\UAIXLocaleRouter\Router', '\UAIXLocaleRouter\LocaleRepository' ),
array( '\Ns12LocaleRouter\Router', '\Ns12LocaleRouter\LocaleRepository' ),
) as $classes
) {
list( $router_class, $locale_repository ) = $classes;
if ( ! class_exists( $router_class ) || ! class_exists( $locale_repository ) || ! method_exists( $router_class, 'get_current_url_tag' ) ) {
continue;
}
$url_tag = $router_class::get_current_url_tag();
if ( '' === $url_tag ) {
continue;
}
foreach ( $locale_repository::get_enabled_locales() as $locale ) {
$record_url_tag = isset( $locale['urlTag'] ) ? strtolower( trim( (string) $locale['urlTag'], '/' ) ) : '';
if ( $record_url_tag === strtolower( trim( (string) $url_tag, '/' ) ) && ! empty( $locale['tag'] ) ) {
return acnmb_normalize_locale_tag( (string) $locale['tag'] );
}
}
}
if ( function_exists( 'determine_locale' ) ) {
return acnmb_normalize_locale_tag( determine_locale() );
}
return 'en-US';
}
/**
* Return the translation array key for a locale.
*
* @param string $locale Locale tag.
* @return string
*/
function acnmb_translation_language_key( $locale ) {
$locale = strtolower( (string) $locale );
if ( 0 === strpos( $locale, 'es' ) ) {
return 'es';
}
if ( 0 === strpos( $locale, 'fr' ) ) {
return 'fr';
}
if ( 0 === strpos( $locale, 'zh' ) ) {
return 'zh';
}
return 'en';
}
/**
* Return the URL tag used by the locale router.
*
* @param string $locale Locale tag.
* @return string
*/
function acnmb_locale_url_tag( $locale ) {
$locale = acnmb_normalize_locale_tag( $locale );
if ( 'es-US' === $locale ) {
return 'es-us';
}
if ( 'fr-FR' === $locale ) {
return 'fr-fr';
}
if ( 'zh-CN' === $locale ) {
return 'zh-cn';
}
return 'en-us';
}
/**
* Resolve a translation pair for a locale.
*
* @param array $pair Translation pair.
* @param string $locale Locale tag.
* @return string
*/
function acnmb_translation_value_for_locale( $pair, $locale ) {
$language_key = acnmb_translation_language_key( $locale );
if ( isset( $pair[ $language_key ] ) && '' !== trim( (string) $pair[ $language_key ] ) ) {
return (string) $pair[ $language_key ];
}
return isset( $pair['en'] ) ? (string) $pair['en'] : '';
}
/**
* Register topic post type and hierarchical board category taxonomy.
*/
function acnmb_register_content_types() {
register_post_type(
ACNMB_TOPIC_POST_TYPE,
array(
'labels' => array(
'name' => acnmb_t( 'acnmb.admin.topics', 'Message Board Topics' ),
'singular_name' => acnmb_t( 'acnmb.admin.topic', 'Message Board Topic' ),
'add_new_item' => acnmb_t( 'acnmb.admin.add_topic', 'Add New Topic' ),
'edit_item' => acnmb_t( 'acnmb.admin.edit_topic', 'Edit Topic' ),
'new_item' => acnmb_t( 'acnmb.admin.new_topic', 'New Topic' ),
'view_item' => acnmb_t( 'acnmb.admin.view_topic', 'View Topic' ),
'search_items' => acnmb_t( 'acnmb.admin.search_topics', 'Search Topics' ),
'not_found' => acnmb_t( 'acnmb.admin.no_topics', 'No topics found' ),
'menu_name' => acnmb_t( 'acnmb.admin.menu', 'Message Board' ),
'not_found_in_trash' => acnmb_t( 'acnmb.admin.no_topics_trash', 'No topics found in Trash' ),
),
'public' => true,
'has_archive' => false,
'show_in_rest' => true,
'menu_icon' => 'dashicons-format-chat',
'rewrite' => array(
'slug' => 'message-board/topic',
'with_front' => false,
),
'supports' => array( 'title', 'editor', 'author', 'excerpt', 'comments', 'revisions' ),
)
);
register_taxonomy(
ACNMB_CATEGORY_TAXONOMY,
ACNMB_TOPIC_POST_TYPE,
array(
'labels' => array(
'name' => acnmb_t( 'acnmb.admin.categories', 'Board Categories' ),
'singular_name' => acnmb_t( 'acnmb.admin.category', 'Board Category' ),
'search_items' => acnmb_t( 'acnmb.admin.search_categories', 'Search Board Categories' ),
'all_items' => acnmb_t( 'acnmb.admin.all_categories', 'All Board Categories' ),
'parent_item' => acnmb_t( 'acnmb.admin.parent_category', 'Parent Board Category' ),
'edit_item' => acnmb_t( 'acnmb.admin.edit_category', 'Edit Board Category' ),
'update_item' => acnmb_t( 'acnmb.admin.update_category', 'Update Board Category' ),
'add_new_item' => acnmb_t( 'acnmb.admin.add_category', 'Add Board Category' ),
'new_item_name' => acnmb_t( 'acnmb.admin.new_category', 'New Board Category' ),
'menu_name' => acnmb_t( 'acnmb.admin.categories_menu', 'Board Categories' ),
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_rest' => true,
'rewrite' => array(
'slug' => 'message-board/category',
'with_front' => false,
'hierarchical' => true,
),
)
);
}
/**
* Activation callback.
*/
function acnmb_activate() {
acnmb_register_content_types();
acnmb_configure_locale_router();
acnmb_run_setup_tasks();
flush_rewrite_rules();
update_option( 'acnmb_version', ACNMB_VERSION, false );
}
/**
* Deactivation callback.
*/
function acnmb_deactivate() {
flush_rewrite_rules();
}
/**
* Run versioned setup tasks.
*/
function acnmb_maybe_upgrade() {
if ( get_option( 'acnmb_version' ) === ACNMB_VERSION && ! get_option( 'acnmb_setup_errors' ) ) {
return;
}
acnmb_run_setup_tasks();
flush_rewrite_rules( false );
update_option( 'acnmb_version', ACNMB_VERSION, false );
}
/**
* Run setup tasks without allowing a recoverable setup problem to white-screen the site.
*/
function acnmb_run_setup_tasks() {
$errors = array();
foreach ( array( 'acnmb_seed_defaults', 'acnmb_write_ns12_dictionaries' ) as $callback ) {
try {
call_user_func( $callback );
} catch ( Throwable $throwable ) {
$errors[] = $callback . ': ' . $throwable->getMessage();
}
}
if ( empty( $errors ) ) {
delete_option( 'acnmb_setup_errors' );
return;
}
update_option( 'acnmb_setup_errors', $errors, false );
if ( function_exists( 'error_log' ) ) {
error_log( 'Antichrist.net Message Board setup warning: ' . implode( ' | ', $errors ) );
}
}
/**
* Seed the board page, default category hierarchy, and menu links.
*/
function acnmb_seed_defaults() {
acnmb_seed_categories();
acnmb_backfill_topic_locales();
acnmb_seed_board_page();
acnmb_seed_menu_links();
}
/**
* Seed default board categories.
*/
function acnmb_seed_categories() {
$created = array();
foreach ( acnmb_required_locale_tags() as $locale ) {
$created[ $locale ] = array();
foreach ( acnmb_category_records() as $base_slug => $record ) {
$localized = acnmb_category_record_for_locale( $base_slug, $locale );
$parent = 0;
if ( ! empty( $record['parent'] ) ) {
if ( isset( $created[ $locale ][ $record['parent'] ] ) ) {
$parent = (int) $created[ $locale ][ $record['parent'] ];
} else {
$parent_term = acnmb_category_term_for_base_slug( $record['parent'], $locale );
if ( $parent_term instanceof WP_Term ) {
$parent = (int) $parent_term->term_id;
}
}
}