diff --git a/Minecraft-Modern-Theme/inc/changelog-admin.php b/Minecraft-Modern-Theme/inc/changelog-admin.php new file mode 100644 index 0000000..87e47bf --- /dev/null +++ b/Minecraft-Modern-Theme/inc/changelog-admin.php @@ -0,0 +1,410 @@ +). + * + * @return string Gueltiges Datum oder leerer String. + */ +function mm_changelog_parse_date( $value ) { + $value = trim( (string) $value ); + if ( ! preg_match( '/^(\d{4})-(\d{2})-(\d{2})$/', $value, $m ) ) { + return ''; + } + return checkdate( (int) $m[2], (int) $m[3], (int) $m[1] ) ? $value : ''; +} + +/** + * Macht aus einem Datum die beiden Zeitwerte, die WordPress speichert. + * Uhrzeit 12:00, damit der Eintrag in jeder Zeitzone am selben Tag bleibt. + * + * @return array{0:string,1:string} Lokale Zeit und GMT. + */ +function mm_changelog_post_dates( $date ) { + $local = $date . ' 12:00:00'; + return array( $local, get_gmt_from_date( $local ) ); +} + +/** + * Datumsfeld in der Details-Box (wird von mm_changelog_meta_box_html aufgerufen). + */ +function mm_changelog_date_field( $post ) { + $is_new = 'auto-draft' === $post->post_status; + $value = $is_new ? '' : get_the_date( 'Y-m-d', $post ); + ?> +
+ + + +
+ wp_date( 'Y-m-d' ) ) { + return $data; + } + // Unveraendertes Datum: die bisherige Uhrzeit behalten. + if ( substr( (string) $data['post_date'], 0, 10 ) === $date ) { + return $data; + } + + list( $data['post_date'], $data['post_date_gmt'] ) = mm_changelog_post_dates( $date ); + return $data; +} +add_filter( 'wp_insert_post_data', 'mm_changelog_apply_date', 10, 2 ); + +// ── Spalten in der Uebersicht ──────────────────────────────────────────────── + +function mm_changelog_columns( $columns ) { + $new = array(); + foreach ( $columns as $key => $label ) { + $new[ $key ] = $label; + if ( 'title' === $key ) { + $new['mm_cl_type'] = __( 'Art', 'minecraft-modern-theme' ); + $new['mm_cl_version'] = __( 'Version', 'minecraft-modern-theme' ); + } + } + return $new; +} +add_filter( 'manage_mm_changelog_posts_columns', 'mm_changelog_columns' ); + +function mm_changelog_column_content( $column, $post_id ) { + if ( 'mm_cl_type' === $column ) { + $types = mm_changelog_types(); + $type = get_post_meta( $post_id, '_mm_changelog_type', true ); + $info = $types[ $type ] ?? $types['update']; + echo '' . esc_html( $info['label'] ) . ''; + } elseif ( 'mm_cl_version' === $column ) { + echo esc_html( get_post_meta( $post_id, '_mm_changelog_version', true ) ); + } +} +add_action( 'manage_mm_changelog_posts_custom_column', 'mm_changelog_column_content', 10, 2 ); + +// ── Seite "Nachtragen" ─────────────────────────────────────────────────────── + +function mm_changelog_backfill_menu() { + if ( ! mm_changelog_enabled() ) { + return; + } + add_submenu_page( + 'edit.php?post_type=mm_changelog', + __( 'Changelog nachtragen', 'minecraft-modern-theme' ), + __( 'Nachtragen', 'minecraft-modern-theme' ), + 'publish_posts', + 'mm-changelog-backfill', + 'mm_changelog_backfill_page' + ); +} +add_action( 'admin_menu', 'mm_changelog_backfill_menu' ); + +/** + * Legt die Eintraege aus dem Nachtragen-Formular an. + */ +function mm_changelog_backfill_handle() { + if ( ! current_user_can( 'publish_posts' ) ) { + wp_die( esc_html__( 'Keine Berechtigung.', 'minecraft-modern-theme' ), 403 ); + } + check_admin_referer( 'mm_changelog_backfill' ); + + $rows = isset( $_POST['rows'] ) && is_array( $_POST['rows'] ) ? wp_unslash( $_POST['rows'] ) : array(); + $types = mm_changelog_types(); + $today = wp_date( 'Y-m-d' ); + $created = 0; + $skipped = 0; + + foreach ( array_slice( $rows, 0, 100 ) as $row ) { + $title = sanitize_text_field( $row['title'] ?? '' ); + $date = mm_changelog_parse_date( $row['date'] ?? '' ); + $text = wp_kses_post( $row['text'] ?? '' ); + + // Komplett leere Zeilen stillschweigend uebergehen. + if ( '' === $title && '' === trim( $text ) && '' === trim( (string) ( $row['date'] ?? '' ) ) ) { + continue; + } + // Ohne Titel oder mit ungueltigem/zukuenftigem Datum nicht anlegen. + if ( '' === $title || '' === $date || $date > $today ) { + $skipped++; + continue; + } + + $type = sanitize_key( $row['type'] ?? 'update' ); + if ( ! array_key_exists( $type, $types ) ) { + $type = 'update'; + } + list( $local, $gmt ) = mm_changelog_post_dates( $date ); + + $post_id = wp_insert_post( array( + 'post_type' => 'mm_changelog', + 'post_status' => 'publish', + 'post_title' => $title, + 'post_content' => $text, + 'post_date' => $local, + 'post_date_gmt' => $gmt, + ), true ); + + if ( is_wp_error( $post_id ) ) { + $skipped++; + continue; + } + update_post_meta( $post_id, '_mm_changelog_type', $type ); + update_post_meta( $post_id, '_mm_changelog_version', mb_substr( sanitize_text_field( $row['version'] ?? '' ), 0, 30 ) ); + $created++; + } + + wp_safe_redirect( add_query_arg( + array( + 'post_type' => 'mm_changelog', + 'page' => 'mm-changelog-backfill', + 'mm_created' => $created, + 'mm_skipped' => $skipped, + ), + admin_url( 'edit.php' ) + ) ); + exit; +} +add_action( 'admin_post_mm_changelog_backfill', 'mm_changelog_backfill_handle' ); + +/** + * Gibt eine Formularzeile aus. $index "__i__" ist die Vorlage fuer neue Zeilen. + */ +function mm_changelog_backfill_row( $index ) { + $name = 'rows[' . $index . ']'; + ?> ++ +
+ + + + + ++ +
+
+ TT.MM.JJJJ | Art | Version | Titel | Beschreibung
+
+
+ + +
+' . esc_html__( 'Discord-Karte: Bitte im Customizer unter „Discord-Karte“ Server-ID oder Einladungslink eintragen.', 'minecraft-modern-theme' ) . '
'; + } + return ''; + } + + $name = $data ? $data['name'] : __( 'Unser Discord', 'minecraft-modern-theme' ); + + ob_start(); + ?> ++ + +
+ +' . esc_html__( 'Vote-Liste: Bitte im Customizer unter „Vote-Seiten“ mindestens eine Seite eintragen.', 'minecraft-modern-theme' ) . '
'; + } + return ''; + } + $text = get_theme_mod( 'mm_vote_text', '' ); + + ob_start(); + ?> ++ + +
+ sanitize_text_field( $new_instance['title'] ?? '' ) ); + } +} + +class MM_Discord_Widget extends MM_Render_Widget { + public function __construct() { + parent::__construct( 'mm_discord', __( 'Discord-Karte', 'minecraft-modern-theme' ), array( + 'description' => __( 'Servername, Online-Zahl und Beitritts-Button.', 'minecraft-modern-theme' ), + ) ); + } + protected function render() { + return mm_discord_render(); + } + protected function default_title() { + return __( 'Discord', 'minecraft-modern-theme' ); + } +} + +class MM_Vote_Widget extends MM_Render_Widget { + public function __construct() { + parent::__construct( 'mm_vote', __( 'Vote-Seiten', 'minecraft-modern-theme' ), array( + 'description' => __( 'Liste der Serverlisten zum Abstimmen.', 'minecraft-modern-theme' ), + ) ); + } + protected function render() { + return mm_vote_render(); + } + protected function default_title() { + return __( 'Für uns voten', 'minecraft-modern-theme' ); + } +} + +function mm_community_register_widgets() { + register_widget( 'MM_Server_Status_Widget' ); + register_widget( 'MM_Discord_Widget' ); + register_widget( 'MM_Vote_Widget' ); +} +add_action( 'widgets_init', 'mm_community_register_widgets' ); diff --git a/Minecraft-Modern-Theme/inc/content-types.php b/Minecraft-Modern-Theme/inc/content-types.php new file mode 100644 index 0000000..4c23253 --- /dev/null +++ b/Minecraft-Modern-Theme/inc/content-types.php @@ -0,0 +1,518 @@ +add_section( 'mm_modules_section', array( + 'title' => __( 'Module', 'minecraft-modern-theme' ), + 'description' => __( 'Zusätzliche Inhaltstypen ein- und ausschalten. Nach dem Einschalten erscheint ein neuer Menüpunkt im Backend.', 'minecraft-modern-theme' ), + 'priority' => 66, + ) ); + + $wp_customize->add_setting( 'mm_rules_enabled', array( + 'default' => false, + 'sanitize_callback' => 'wp_validate_boolean', + ) ); + $wp_customize->add_control( 'mm_rules_enabled', array( + 'label' => __( 'Regelwerk aktivieren', 'minecraft-modern-theme' ), + 'description' => __( 'Regeln nach Kategorien mit Inhaltsverzeichnis unter /regelwerk. Die Reihenfolge legst du im Backend unter Regelwerk → Reihenfolge fest. Nicht nötig, wenn bereits ein Regel-Plugin im Einsatz ist.', 'minecraft-modern-theme' ), + 'section' => 'mm_modules_section', + 'type' => 'checkbox', + ) ); + + $wp_customize->add_setting( 'mm_rules_intro', array( + 'default' => '', + 'sanitize_callback' => 'sanitize_textarea_field', + ) ); + $wp_customize->add_control( 'mm_rules_intro', array( + 'label' => __( 'Einleitung über dem Regelwerk', 'minecraft-modern-theme' ), + 'section' => 'mm_modules_section', + 'type' => 'textarea', + ) ); + + $wp_customize->add_setting( 'mm_rules_source', array( + 'default' => 'auto', + 'sanitize_callback' => 'mm_rules_sanitize_source', + ) ); + $wp_customize->add_control( 'mm_rules_source', array( + 'label' => __( 'Quelle der Regeln', 'minecraft-modern-theme' ), + 'description' => __( 'Das Theme kann die Regeln direkt aus dem Plugin „Multi Rules“ übernehmen. Dann pflegst du sie nur noch dort.', 'minecraft-modern-theme' ), + 'section' => 'mm_modules_section', + 'type' => 'select', + 'choices' => array( + 'auto' => __( 'Automatisch (Plugin, falls vorhanden – sonst Theme)', 'minecraft-modern-theme' ), + 'plugin' => __( 'Plugin „Multi Rules“', 'minecraft-modern-theme' ), + 'theme' => __( 'Theme (Backend → Regelwerk)', 'minecraft-modern-theme' ), + ), + ) ); + + $wp_customize->add_setting( 'mm_rules_layout', array( + 'default' => 'tabs', + 'sanitize_callback' => 'mm_rules_sanitize_layout', + ) ); + $wp_customize->add_control( 'mm_rules_layout', array( + 'label' => __( 'Darstellung des Regelwerks', 'minecraft-modern-theme' ), + 'section' => 'mm_modules_section', + 'type' => 'select', + 'choices' => array( + 'tabs' => __( 'Eine Kategorie zur Zeit, Regeln zum Aufklappen', 'minecraft-modern-theme' ), + 'list' => __( 'Alles untereinander', 'minecraft-modern-theme' ), + ), + ) ); + + $wp_customize->add_setting( 'mm_changelog_enabled', array( + 'default' => false, + 'sanitize_callback' => 'wp_validate_boolean', + ) ); + $wp_customize->add_control( 'mm_changelog_enabled', array( + 'label' => __( 'Changelog aktivieren', 'minecraft-modern-theme' ), + 'description' => __( 'Server-Updates als Zeitleiste unter /changelog. Ältere Ereignisse lassen sich im Backend unter Changelog → Nachtragen mit eigenem Datum eintragen.', 'minecraft-modern-theme' ), + 'section' => 'mm_modules_section', + 'type' => 'checkbox', + ) ); +} +add_action( 'customize_register', 'mm_content_types_customizer' ); + +function mm_register_content_types() { + if ( mm_rules_enabled() ) { + register_post_type( 'mm_rule', array( + 'labels' => array( + 'name' => __( 'Regelwerk', 'minecraft-modern-theme' ), + 'singular_name' => __( 'Regel', 'minecraft-modern-theme' ), + 'add_new' => __( 'Neue Regel', 'minecraft-modern-theme' ), + 'add_new_item' => __( 'Neue Regel hinzufügen', 'minecraft-modern-theme' ), + 'edit_item' => __( 'Regel bearbeiten', 'minecraft-modern-theme' ), + 'all_items' => __( 'Regeln', 'minecraft-modern-theme' ), + 'search_items' => __( 'Regeln durchsuchen', 'minecraft-modern-theme' ), + 'not_found' => __( 'Keine Regeln gefunden', 'minecraft-modern-theme' ), + ), + 'public' => true, + 'has_archive' => 'regelwerk', + 'rewrite' => array( 'slug' => 'regelwerk', 'with_front' => false ), + 'menu_icon' => 'dashicons-shield', + // "page-attributes" liefert das Feld "Reihenfolge" für die Sortierung. + 'supports' => array( 'title', 'editor', 'page-attributes', 'revisions' ), + 'show_in_rest' => true, + ) ); + register_taxonomy( 'mm_rule_category', 'mm_rule', array( + 'labels' => array( + 'name' => __( 'Regel-Kategorien', 'minecraft-modern-theme' ), + 'singular_name' => __( 'Regel-Kategorie', 'minecraft-modern-theme' ), + ), + 'hierarchical' => true, + 'show_admin_column' => true, + 'show_in_rest' => true, + 'rewrite' => array( 'slug' => 'regelwerk-kategorie', 'with_front' => false ), + ) ); + } + + if ( mm_changelog_enabled() ) { + register_post_type( 'mm_changelog', array( + 'labels' => array( + 'name' => __( 'Changelog', 'minecraft-modern-theme' ), + 'singular_name' => __( 'Changelog-Eintrag', 'minecraft-modern-theme' ), + 'add_new' => __( 'Neuer Eintrag', 'minecraft-modern-theme' ), + 'add_new_item' => __( 'Neuen Eintrag hinzufügen', 'minecraft-modern-theme' ), + 'edit_item' => __( 'Eintrag bearbeiten', 'minecraft-modern-theme' ), + 'all_items' => __( 'Changelog', 'minecraft-modern-theme' ), + 'not_found' => __( 'Keine Einträge gefunden', 'minecraft-modern-theme' ), + ), + 'public' => true, + 'has_archive' => 'changelog', + 'rewrite' => array( 'slug' => 'changelog', 'with_front' => false ), + 'menu_icon' => 'dashicons-update', + 'supports' => array( 'title', 'editor', 'revisions' ), + 'show_in_rest' => true, + ) ); + } +} +add_action( 'init', 'mm_register_content_types' ); + +/** + * Nach dem Ein-/Ausschalten eines Moduls muessen die Permalinks neu + * aufgebaut werden, sonst liefern /regelwerk und /changelog einen 404. + * Das Flag wird beim Speichern gesetzt und beim naechsten Seitenaufruf + * NACH der Registrierung der Inhaltstypen abgearbeitet. + */ +function mm_content_types_schedule_flush() { + update_option( 'mm_flush_rewrite_rules', 1, false ); +} +add_action( 'customize_save_after', 'mm_content_types_schedule_flush' ); +add_action( 'after_switch_theme', 'mm_content_types_schedule_flush' ); + +function mm_content_types_maybe_flush() { + if ( get_option( 'mm_flush_rewrite_rules' ) ) { + delete_option( 'mm_flush_rewrite_rules' ); + flush_rewrite_rules( false ); + } +} +add_action( 'init', 'mm_content_types_maybe_flush', 99 ); + + +// ============================================================================= +// REGELWERK +// ============================================================================= + +function mm_rules_sanitize_layout( $value ) { + return 'list' === $value ? 'list' : 'tabs'; +} + +function mm_rules_sanitize_source( $value ) { + return in_array( $value, array( 'auto', 'plugin', 'theme' ), true ) ? $value : 'auto'; +} + +/** + * Liest die Kategorien ("Tabs") aus dem Plugin "Multi Rules". + * + * Das Plugin speichert alles in der Option "mrp_settings": + * tabs[] => array( 'title' => …, 'rules' => array( array( 'rule_title' => …, 'rule_content' => … ) ) ). + * + * @return array[] Leeres Array, wenn das Plugin keine Regeln hat. + */ +function mm_rules_plugin_tabs() { + $options = get_option( 'mrp_settings' ); + $tabs = isset( $options['tabs'] ) && is_array( $options['tabs'] ) ? $options['tabs'] : array(); + return (array) apply_filters( 'mm_rules_plugin_tabs', $tabs ); +} + +/** + * True, wenn das Regelwerk aus dem Plugin statt aus dem Theme kommt. + */ +function mm_rules_uses_plugin() { + $source = get_theme_mod( 'mm_rules_source', 'auto' ); + if ( 'theme' === $source ) { + return false; + } + // "plugin" ohne Plugin-Daten: lieber die Theme-Regeln zeigen als eine leere Seite. + return ! empty( mm_rules_plugin_tabs() ); +} + +/** + * Baut aus den Plugin-Daten dieselbe Struktur, die mm_rules_get_groups() liefert. + */ +function mm_rules_groups_from_plugin() { + $groups = array(); + $used = array(); + + foreach ( mm_rules_plugin_tabs() as $index => $tab ) { + $rules = array(); + foreach ( (array) ( $tab['rules'] ?? array() ) as $rule ) { + $title = trim( (string) ( $rule['rule_title'] ?? '' ) ); + $content = (string) ( $rule['rule_content'] ?? '' ); + if ( '' === $title && '' === trim( wp_strip_all_tags( $content ) ) ) { + continue; + } + // Gleiche Form wie ein Beitrag, damit das Template nicht unterscheiden muss. + // wp_kses_post(): Inhalte aus einer Plugin-Option nie ungefiltert ausgeben. + $rules[] = (object) array( + 'post_title' => $title, + 'post_content' => wp_kses_post( $content ), + ); + } + if ( empty( $rules ) ) { + continue; + } + + $name = trim( (string) ( $tab['title'] ?? '' ) ); + if ( '' === $name ) { + $name = __( 'Allgemein', 'minecraft-modern-theme' ); + } + // Anker müssen eindeutig sein, auch bei zwei gleichnamigen Kategorien. + $slug = sanitize_title( $name ); + if ( '' === $slug || isset( $used[ $slug ] ) ) { + $slug = ( '' === $slug ? 'kategorie' : $slug ) . '-' . ( $index + 1 ); + } + $used[ $slug ] = true; + + $groups[] = array( + 'id' => 'regeln-' . $slug, + 'term_id' => 0, + 'name' => $name, + 'description' => '', + 'rules' => $rules, + ); + } + return $groups; +} + +/** + * Skript für Kategorie-Umschaltung und aufklappbare Regeln. + */ +function mm_rules_assets() { + if ( mm_rules_enabled() && is_post_type_archive( 'mm_rule' ) && 'list' !== get_theme_mod( 'mm_rules_layout', 'tabs' ) ) { + wp_enqueue_script( 'mm-rules', get_template_directory_uri() . '/js/rules.js', array(), filemtime( get_template_directory() . '/js/rules.js' ), true ); + } +} +add_action( 'wp_enqueue_scripts', 'mm_rules_assets' ); + +/** + * Liefert das Regelwerk gruppiert nach Kategorien. + * + * Die Reihenfolge von Kategorien und Regeln wird im Backend unter + * "Regelwerk → Reihenfolge" festgelegt (siehe inc/rules-order.php). + * + * @param bool $for_admin True: auch Entwürfe und geplante Regeln liefern (Sortier-Seite). + * @return array[] Liste aus array( 'id' => Anker, 'term_id' => …, 'name' => …, 'description' => …, 'rules' => WP_Post[] ). + */ +function mm_rules_get_groups( $for_admin = false ) { + // Die Sortier-Seite im Backend arbeitet immer mit den Theme-Regeln. + if ( ! $for_admin && mm_rules_uses_plugin() ) { + return mm_rules_groups_from_plugin(); + } + + $groups = array(); + $query = array( + 'post_type' => 'mm_rule', + 'post_status' => $for_admin ? array( 'publish', 'draft', 'pending', 'future', 'private' ) : 'publish', + 'posts_per_page' => 500, + 'orderby' => array( 'menu_order' => 'ASC', 'title' => 'ASC' ), + 'no_found_rows' => true, + ); + + $terms = get_terms( array( + 'taxonomy' => 'mm_rule_category', + // Im Backend zählen auch Kategorien, die bisher nur Entwürfe enthalten. + 'hide_empty' => ! $for_admin, + 'orderby' => 'name', + ) ); + if ( is_wp_error( $terms ) ) { + $terms = array(); + } + $terms = mm_rules_sort_terms( $terms ); + + foreach ( $terms as $term ) { + $rules = get_posts( $query + array( + 'tax_query' => array( array( + 'taxonomy' => 'mm_rule_category', + 'terms' => $term->term_id, + 'include_children' => false, + ) ), + ) ); + if ( $rules ) { + $groups[] = array( + 'id' => 'regeln-' . $term->slug, + 'term_id' => (int) $term->term_id, + 'name' => $term->name, + 'description' => $term->description, + 'rules' => $rules, + ); + } + } + + // Regeln ohne Kategorie. + $uncategorized = get_posts( $query + array( + 'tax_query' => array( array( + 'taxonomy' => 'mm_rule_category', + 'operator' => 'NOT EXISTS', + ) ), + ) ); + if ( $uncategorized ) { + array_unshift( $groups, array( + 'id' => 'regeln-allgemein', + 'term_id' => 0, + 'name' => __( 'Allgemein', 'minecraft-modern-theme' ), + 'description' => '', + 'rules' => $uncategorized, + ) ); + } + + return $groups; +} + +/** + * Datum der letzten Aenderung am Regelwerk (fuer "Stand: …"). + */ +function mm_rules_last_modified() { + // Das Plugin speichert kein Änderungsdatum. + if ( mm_rules_uses_plugin() ) { + return ''; + } + $latest = get_posts( array( + 'post_type' => 'mm_rule', + 'posts_per_page' => 1, + 'orderby' => 'modified', + 'order' => 'DESC', + 'no_found_rows' => true, + ) ); + return $latest ? get_the_modified_date( '', $latest[0] ) : ''; +} + + +// ============================================================================= +// CHANGELOG +// ============================================================================= + +/** + * Arten von Changelog-Eintraegen: Schluessel => Beschriftung, Icon, Farbe. + */ +function mm_changelog_types() { + return array( + 'update' => array( 'label' => __( 'Update', 'minecraft-modern-theme' ), 'icon' => 'fas fa-arrow-up', 'color' => '#00d4ff' ), + 'feature' => array( 'label' => __( 'Neu', 'minecraft-modern-theme' ), 'icon' => 'fas fa-star', 'color' => '#46b450' ), + 'fix' => array( 'label' => __( 'Fehlerbehebung', 'minecraft-modern-theme' ), 'icon' => 'fas fa-wrench', 'color' => '#f0ad4e' ), + 'event' => array( 'label' => __( 'Event', 'minecraft-modern-theme' ), 'icon' => 'fas fa-calendar', 'color' => '#aa00ff' ), + ); +} + +function mm_changelog_meta_box() { + add_meta_box( 'mm_changelog_details', __( 'Details', 'minecraft-modern-theme' ), 'mm_changelog_meta_box_html', 'mm_changelog', 'side', 'high' ); +} +add_action( 'add_meta_boxes', 'mm_changelog_meta_box' ); + +function mm_changelog_meta_box_html( $post ) { + wp_nonce_field( 'mm_changelog_save', 'mm_changelog_nonce' ); + $version = get_post_meta( $post->ID, '_mm_changelog_version', true ); + $type = get_post_meta( $post->ID, '_mm_changelog_type', true ) ?: 'update'; + mm_changelog_date_field( $post ); + ?> ++ + +
++ + +
+ is_main_query() && $query->is_post_type_archive( 'mm_changelog' ) ) { + $query->set( 'posts_per_page', 15 ); + } +} +add_action( 'pre_get_posts', 'mm_changelog_archive_query' ); + +/** + * Rendert einen Eintrag der Zeitleiste. Erwartet, dass der globale Post gesetzt ist. + * + * @param bool $excerpt True: nur gekuerzter Text (Startseite, Shortcode). + */ +function mm_changelog_render_entry( $excerpt = false ) { + $types = mm_changelog_types(); + $type = get_post_meta( get_the_ID(), '_mm_changelog_type', true ); + $info = $types[ $type ] ?? $types['update']; + $version = get_post_meta( get_the_ID(), '_mm_changelog_version', true ); + ?> +| + | + |
|---|---|
| + | + + + | +
| + | + |
| + | + |
' . esc_html__( 'Aktuell sind keine Events geplant.', 'minecraft-modern-theme' ) . '
'; +} +add_shortcode( 'mm_events', 'mm_events_shortcode' ); diff --git a/Minecraft-Modern-Theme/inc/frontpage-sections.php b/Minecraft-Modern-Theme/inc/frontpage-sections.php new file mode 100644 index 0000000..8d93e59 --- /dev/null +++ b/Minecraft-Modern-Theme/inc/frontpage-sections.php @@ -0,0 +1,296 @@ +add_panel( 'mm_home_panel', array( + 'title' => __( 'Startseiten-Sektionen', 'minecraft-modern-theme' ), + 'description' => __( 'Zusätzliche Blöcke zwischen Hero/Slider und Seiteninhalt.', 'minecraft-modern-theme' ), + 'priority' => 21, + ) ); + + // ── Server-Status ── + $wp_customize->add_section( 'mm_home_status_section', array( + 'title' => __( 'Server-Status-Leiste', 'minecraft-modern-theme' ), + 'panel' => 'mm_home_panel', + ) ); + $wp_customize->add_setting( 'mm_home_status', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) ); + $wp_customize->add_control( 'mm_home_status', array( + 'label' => __( 'Server-Status unter dem Hero anzeigen', 'minecraft-modern-theme' ), + 'description' => __( 'Die Server-Adresse wird unter „Server-Status“ eingetragen.', 'minecraft-modern-theme' ), + 'section' => 'mm_home_status_section', + 'type' => 'checkbox', + ) ); + + // ── Features ── + $wp_customize->add_section( 'mm_home_features_section', array( + 'title' => __( 'Feature-Kacheln', 'minecraft-modern-theme' ), + 'panel' => 'mm_home_panel', + ) ); + $wp_customize->add_setting( 'mm_home_features', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) ); + $wp_customize->add_control( 'mm_home_features', array( + 'label' => __( 'Feature-Kacheln anzeigen', 'minecraft-modern-theme' ), + 'section' => 'mm_home_features_section', + 'type' => 'checkbox', + ) ); + $wp_customize->add_setting( 'mm_home_features_title', array( 'default' => __( 'Das erwartet dich', 'minecraft-modern-theme' ), 'sanitize_callback' => 'sanitize_text_field' ) ); + $wp_customize->add_control( 'mm_home_features_title', array( + 'label' => __( 'Überschrift', 'minecraft-modern-theme' ), + 'section' => 'mm_home_features_section', + 'type' => 'text', + ) ); + for ( $i = 1; $i <= MM_HOME_FEATURE_COUNT; $i++ ) { + $wp_customize->add_setting( "mm_home_feature_{$i}_icon", array( 'default' => '', 'sanitize_callback' => 'mm_sanitize_icon_class' ) ); + $wp_customize->add_control( "mm_home_feature_{$i}_icon", array( + /* translators: %d: tile number */ + 'label' => sprintf( __( 'Kachel %d – Icon', 'minecraft-modern-theme' ), $i ), + 'description' => 1 === $i ? __( 'Font-Awesome-Klasse, z. B. „fas fa-shield-alt“.', 'minecraft-modern-theme' ) : '', + 'section' => 'mm_home_features_section', + 'type' => 'text', + ) ); + $wp_customize->add_setting( "mm_home_feature_{$i}_title", array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ) ); + $wp_customize->add_control( "mm_home_feature_{$i}_title", array( + /* translators: %d: tile number */ + 'label' => sprintf( __( 'Kachel %d – Titel', 'minecraft-modern-theme' ), $i ), + 'section' => 'mm_home_features_section', + 'type' => 'text', + ) ); + $wp_customize->add_setting( "mm_home_feature_{$i}_text", array( 'default' => '', 'sanitize_callback' => 'sanitize_textarea_field' ) ); + $wp_customize->add_control( "mm_home_feature_{$i}_text", array( + /* translators: %d: tile number */ + 'label' => sprintf( __( 'Kachel %d – Text', 'minecraft-modern-theme' ), $i ), + 'section' => 'mm_home_features_section', + 'type' => 'textarea', + ) ); + $wp_customize->add_setting( "mm_home_feature_{$i}_url", array( 'default' => '', 'sanitize_callback' => 'esc_url_raw' ) ); + $wp_customize->add_control( "mm_home_feature_{$i}_url", array( + /* translators: %d: tile number */ + 'label' => sprintf( __( 'Kachel %d – Link (optional)', 'minecraft-modern-theme' ), $i ), + 'section' => 'mm_home_features_section', + 'type' => 'url', + ) ); + } + + // ── Changelog ── + $wp_customize->add_section( 'mm_home_changelog_section', array( + 'title' => __( 'Neueste Updates', 'minecraft-modern-theme' ), + 'panel' => 'mm_home_panel', + ) ); + $wp_customize->add_setting( 'mm_home_changelog', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) ); + $wp_customize->add_control( 'mm_home_changelog', array( + 'label' => __( 'Neueste Changelog-Einträge anzeigen', 'minecraft-modern-theme' ), + 'description' => __( 'Benötigt das Modul „Changelog“ (Customizer → Module).', 'minecraft-modern-theme' ), + 'section' => 'mm_home_changelog_section', + 'type' => 'checkbox', + ) ); + $wp_customize->add_setting( 'mm_home_changelog_count', array( 'default' => 3, 'sanitize_callback' => 'absint' ) ); + $wp_customize->add_control( 'mm_home_changelog_count', array( + 'label' => __( 'Anzahl Einträge', 'minecraft-modern-theme' ), + 'section' => 'mm_home_changelog_section', + 'type' => 'number', + 'input_attrs' => array( 'min' => 1, 'max' => 10 ), + ) ); + + // ── Team ── + $wp_customize->add_section( 'mm_home_team_section', array( + 'title' => __( 'Team-Vorschau', 'minecraft-modern-theme' ), + 'panel' => 'mm_home_panel', + ) ); + $wp_customize->add_setting( 'mm_home_team', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) ); + $wp_customize->add_control( 'mm_home_team', array( + 'label' => __( 'Team-Vorschau anzeigen', 'minecraft-modern-theme' ), + 'section' => 'mm_home_team_section', + 'type' => 'checkbox', + ) ); + $wp_customize->add_setting( 'mm_home_team_count', array( 'default' => 4, 'sanitize_callback' => 'absint' ) ); + $wp_customize->add_control( 'mm_home_team_count', array( + 'label' => __( 'Anzahl Teammitglieder', 'minecraft-modern-theme' ), + 'section' => 'mm_home_team_section', + 'type' => 'number', + 'input_attrs' => array( 'min' => 1, 'max' => 12 ), + ) ); + + // ── Community ── + $wp_customize->add_section( 'mm_home_community_section', array( + 'title' => __( 'Community (Discord & Voten)', 'minecraft-modern-theme' ), + 'panel' => 'mm_home_panel', + ) ); + $wp_customize->add_setting( 'mm_home_discord', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) ); + $wp_customize->add_control( 'mm_home_discord', array( + 'label' => __( 'Discord-Karte anzeigen', 'minecraft-modern-theme' ), + 'section' => 'mm_home_community_section', + 'type' => 'checkbox', + ) ); + $wp_customize->add_setting( 'mm_home_vote', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) ); + $wp_customize->add_control( 'mm_home_vote', array( + 'label' => __( 'Vote-Seiten anzeigen', 'minecraft-modern-theme' ), + 'section' => 'mm_home_community_section', + 'type' => 'checkbox', + ) ); +} +add_action( 'customize_register', 'mm_home_sections_customizer' ); + +/** + * Oeffnet eine Sektion mit optionaler Ueberschrift. + */ +function mm_home_section_open( $slug, $title = '', $link_url = '', $link_text = '' ) { + echo '' . nl2br( esc_html( $tile['text'] ) ) . '
'; + } + echo '' . $tag . '>'; // phpcs:ignore WordPress.Security.EscapeOutput + } + echo '