Upload via GUI (205 Dateien)
This commit is contained in:
@@ -0,0 +1,410 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Changelog im Backend: Datum frei setzen und Eintraege nachtragen.
|
||||||
|
*
|
||||||
|
* - Feld "Datum des Eintrags" in der Details-Box jedes Eintrags. Es setzt
|
||||||
|
* das Veroeffentlichungsdatum, nach dem die Zeitleiste sortiert wird.
|
||||||
|
* - Seite "Changelog → Nachtragen": mehrere Eintraege auf einmal anlegen,
|
||||||
|
* jeder mit eigenem Datum.
|
||||||
|
* - Spalten "Art" und "Version" in der Uebersicht.
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prueft ein Datum im Format JJJJ-MM-TT (so liefert es <input type="date">).
|
||||||
|
*
|
||||||
|
* @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 );
|
||||||
|
?>
|
||||||
|
<p>
|
||||||
|
<label for="mm_changelog_date"><strong><?php esc_html_e( 'Datum des Eintrags', 'minecraft-modern-theme' ); ?></strong></label>
|
||||||
|
<input type="date" class="widefat" id="mm_changelog_date" name="mm_changelog_date"
|
||||||
|
value="<?php echo esc_attr( $value ); ?>" max="<?php echo esc_attr( wp_date( 'Y-m-d' ) ); ?>">
|
||||||
|
<span class="description"><?php esc_html_e( 'Leer = heute. Zum Nachtragen einfach ein früheres Datum wählen.', 'minecraft-modern-theme' ); ?></span>
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uebernimmt das Datum aus dem Feld als Veroeffentlichungsdatum.
|
||||||
|
*
|
||||||
|
* Laeuft als Filter direkt beim Speichern – so wird das Datum in einem
|
||||||
|
* Schritt gesetzt, ohne den Beitrag ein zweites Mal zu speichern.
|
||||||
|
*/
|
||||||
|
function mm_changelog_apply_date( $data, $postarr ) {
|
||||||
|
if ( 'mm_changelog' !== $data['post_type'] || ! isset( $_POST['mm_changelog_date'], $_POST['mm_changelog_nonce'] ) ) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['mm_changelog_nonce'] ) ), 'mm_changelog_save' ) ) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
// Nur fuer den Beitrag, dessen Formular gerade abgeschickt wurde (nicht fuer Revisionen o. Ae.).
|
||||||
|
if ( empty( $postarr['ID'] ) || (int) ( $_POST['post_ID'] ?? 0 ) !== (int) $postarr['ID'] ) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$date = mm_changelog_parse_date( wp_unslash( $_POST['mm_changelog_date'] ) );
|
||||||
|
// Datum in der Zukunft: WordPress plant solche Beitraege selbst ein, das bleibt unangetastet.
|
||||||
|
if ( '' === $date || $date > 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 '<span style="color:' . esc_attr( $info['color'] ) . ';font-weight:600;">' . esc_html( $info['label'] ) . '</span>';
|
||||||
|
} 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 . ']';
|
||||||
|
?>
|
||||||
|
<tr class="mm-cl-row">
|
||||||
|
<td><input type="date" name="<?php echo esc_attr( $name ); ?>[date]" max="<?php echo esc_attr( wp_date( 'Y-m-d' ) ); ?>"></td>
|
||||||
|
<td>
|
||||||
|
<select name="<?php echo esc_attr( $name ); ?>[type]">
|
||||||
|
<?php foreach ( mm_changelog_types() as $key => $info ) : ?>
|
||||||
|
<option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $info['label'] ); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td><input type="text" name="<?php echo esc_attr( $name ); ?>[version]" maxlength="30" size="8" placeholder="1.4.2"></td>
|
||||||
|
<td><input type="text" class="widefat" name="<?php echo esc_attr( $name ); ?>[title]" placeholder="<?php esc_attr_e( 'z. B. SkyBlock-Server eröffnet', 'minecraft-modern-theme' ); ?>"></td>
|
||||||
|
<td><textarea class="widefat" rows="2" name="<?php echo esc_attr( $name ); ?>[text]" placeholder="<?php esc_attr_e( 'Beschreibung (optional)', 'minecraft-modern-theme' ); ?>"></textarea></td>
|
||||||
|
<td><button type="button" class="button-link mm-cl-remove" aria-label="<?php esc_attr_e( 'Zeile entfernen', 'minecraft-modern-theme' ); ?>"><span class="dashicons dashicons-no-alt"></span></button></td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_changelog_backfill_page() {
|
||||||
|
if ( ! current_user_can( 'publish_posts' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$initial_rows = 5;
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php esc_html_e( 'Changelog nachtragen', 'minecraft-modern-theme' ); ?></h1>
|
||||||
|
<p class="description" style="max-width:820px;">
|
||||||
|
<?php esc_html_e( 'Mehrere Einträge auf einmal anlegen, jeder mit eigenem Datum. Die Zeitleiste auf der Website sortiert automatisch nach Datum – die Reihenfolge hier ist egal. Zeilen ohne Titel oder Datum werden nicht angelegt.', 'minecraft-modern-theme' ); ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<?php if ( isset( $_GET['mm_created'] ) ) : ?>
|
||||||
|
<div class="notice notice-success is-dismissible"><p>
|
||||||
|
<?php
|
||||||
|
/* translators: %d: number of created entries */
|
||||||
|
printf( esc_html( _n( '%d Eintrag angelegt.', '%d Einträge angelegt.', absint( $_GET['mm_created'] ), 'minecraft-modern-theme' ) ), absint( $_GET['mm_created'] ) );
|
||||||
|
?>
|
||||||
|
<a href="<?php echo esc_url( get_post_type_archive_link( 'mm_changelog' ) ); ?>" target="_blank"><?php esc_html_e( 'Changelog ansehen', 'minecraft-modern-theme' ); ?></a>
|
||||||
|
</p></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ( ! empty( $_GET['mm_skipped'] ) ) : ?>
|
||||||
|
<div class="notice notice-warning is-dismissible"><p>
|
||||||
|
<?php
|
||||||
|
/* translators: %d: number of skipped rows */
|
||||||
|
printf( esc_html( _n( '%d Zeile übersprungen (Titel oder gültiges Datum fehlte, oder das Datum lag in der Zukunft).', '%d Zeilen übersprungen (Titel oder gültiges Datum fehlte, oder das Datum lag in der Zukunft).', absint( $_GET['mm_skipped'] ), 'minecraft-modern-theme' ) ), absint( $_GET['mm_skipped'] ) );
|
||||||
|
?>
|
||||||
|
</p></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<details class="mm-cl-paste" style="max-width:980px;margin:16px 0;">
|
||||||
|
<summary style="cursor:pointer;font-weight:600;"><?php esc_html_e( 'Liste einfügen (viele Einträge auf einmal)', 'minecraft-modern-theme' ); ?></summary>
|
||||||
|
<p class="description">
|
||||||
|
<?php esc_html_e( 'Eine Zeile pro Eintrag, Felder mit | getrennt:', 'minecraft-modern-theme' ); ?>
|
||||||
|
<code>TT.MM.JJJJ | Art | Version | Titel | Beschreibung</code><br>
|
||||||
|
<?php esc_html_e( 'Art: Update, Neu, Fehlerbehebung oder Event. Version und Beschreibung dürfen leer bleiben. Die Zeilen landen zuerst unten in der Tabelle, wo du sie noch prüfen und ändern kannst – angelegt wird erst mit „Einträge anlegen“.', 'minecraft-modern-theme' ); ?>
|
||||||
|
</p>
|
||||||
|
<textarea id="mm-cl-paste-text" class="widefat code" rows="8" placeholder="14.05.2026 | Neu | | SkyBlock-Server eröffnet | Ab sofort könnt ihr eure eigene Insel aufbauen."></textarea>
|
||||||
|
<p>
|
||||||
|
<button type="button" class="button" id="mm-cl-paste-apply"><?php esc_html_e( 'In die Tabelle übernehmen', 'minecraft-modern-theme' ); ?></button>
|
||||||
|
<span id="mm-cl-paste-status" role="status" aria-live="polite" style="margin-left:10px;"></span>
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
|
||||||
|
<input type="hidden" name="action" value="mm_changelog_backfill">
|
||||||
|
<?php wp_nonce_field( 'mm_changelog_backfill' ); ?>
|
||||||
|
|
||||||
|
<table class="widefat striped" style="margin-top:16px;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="width:150px;"><?php esc_html_e( 'Datum', 'minecraft-modern-theme' ); ?></th>
|
||||||
|
<th style="width:150px;"><?php esc_html_e( 'Art', 'minecraft-modern-theme' ); ?></th>
|
||||||
|
<th style="width:100px;"><?php esc_html_e( 'Version', 'minecraft-modern-theme' ); ?></th>
|
||||||
|
<th style="width:28%;"><?php esc_html_e( 'Titel', 'minecraft-modern-theme' ); ?></th>
|
||||||
|
<th><?php esc_html_e( 'Beschreibung', 'minecraft-modern-theme' ); ?></th>
|
||||||
|
<th style="width:30px;"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="mm-cl-rows">
|
||||||
|
<?php
|
||||||
|
for ( $i = 0; $i < $initial_rows; $i++ ) {
|
||||||
|
mm_changelog_backfill_row( $i );
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<button type="button" class="button" id="mm-cl-add"><?php esc_html_e( '+ Zeile hinzufügen', 'minecraft-modern-theme' ); ?></button>
|
||||||
|
<button type="submit" class="button button-primary"><?php esc_html_e( 'Einträge anlegen', 'minecraft-modern-theme' ); ?></button>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<template id="mm-cl-template"><?php mm_changelog_backfill_row( '__i__' ); ?></template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
var body = document.getElementById('mm-cl-rows');
|
||||||
|
var template = document.getElementById('mm-cl-template');
|
||||||
|
var next = <?php echo (int) $initial_rows; ?>;
|
||||||
|
if (!body || !template) return;
|
||||||
|
|
||||||
|
// Vorlage kopieren und den Platzhalter im Feldnamen durch eine neue Nummer ersetzen.
|
||||||
|
function addRow() {
|
||||||
|
var row = template.content.firstElementChild.cloneNode(true);
|
||||||
|
row.querySelectorAll('[name]').forEach(function (field) {
|
||||||
|
field.name = field.name.replace('__i__', next);
|
||||||
|
});
|
||||||
|
next++;
|
||||||
|
body.appendChild(row);
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
function field(row, key) {
|
||||||
|
return row.querySelector('[name$="[' + key + ']"]');
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEmpty(row) {
|
||||||
|
return !field(row, 'date').value && !field(row, 'title').value.trim() && !field(row, 'text').value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('mm-cl-add').addEventListener('click', function () {
|
||||||
|
var first = addRow().querySelector('input');
|
||||||
|
if (first) first.focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Liste einfügen ──
|
||||||
|
var TYPES = <?php
|
||||||
|
// Beschriftung und Schluessel jeder Art, klein geschrieben, zum Erkennen im eingefuegten Text.
|
||||||
|
$mm_type_map = array();
|
||||||
|
foreach ( mm_changelog_types() as $mm_key => $mm_info ) {
|
||||||
|
$mm_type_map[ mb_strtolower( $mm_info['label'] ) ] = $mm_key;
|
||||||
|
$mm_type_map[ $mm_key ] = $mm_key;
|
||||||
|
}
|
||||||
|
echo wp_json_encode( $mm_type_map );
|
||||||
|
?>;
|
||||||
|
var MSG = <?php echo wp_json_encode( array(
|
||||||
|
/* translators: 1: rows added, 2: rows not understood */
|
||||||
|
'done' => __( '%1$s Zeilen übernommen, %2$s nicht erkannt (Datum oder Titel fehlt).', 'minecraft-modern-theme' ),
|
||||||
|
) ); ?>;
|
||||||
|
|
||||||
|
// "14.05.2026", "14.5.26" oder "2026-05-14" → "2026-05-14"; sonst ''.
|
||||||
|
function toIsoDate(text) {
|
||||||
|
var y, mo, d;
|
||||||
|
var m = text.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
||||||
|
if (m) {
|
||||||
|
y = +m[1]; mo = +m[2]; d = +m[3];
|
||||||
|
} else {
|
||||||
|
m = text.match(/^(\d{1,2})\.(\d{1,2})\.(\d{2}|\d{4})$/);
|
||||||
|
if (!m) return '';
|
||||||
|
y = m[3].length === 2 ? 2000 + (+m[3]) : +m[3]; mo = +m[2]; d = +m[1];
|
||||||
|
}
|
||||||
|
// Kalenderprüfung: den 31.02. gibt es nicht – Date würde ihn stillschweigend in den März schieben.
|
||||||
|
var check = new Date(y, mo - 1, d);
|
||||||
|
if (check.getFullYear() !== y || check.getMonth() !== mo - 1 || check.getDate() !== d) return '';
|
||||||
|
return y + '-' + ('0' + mo).slice(-2) + '-' + ('0' + d).slice(-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('mm-cl-paste-apply').addEventListener('click', function () {
|
||||||
|
var area = document.getElementById('mm-cl-paste-text');
|
||||||
|
var added = 0, failed = [];
|
||||||
|
|
||||||
|
area.value.split(/\r?\n/).forEach(function (line) {
|
||||||
|
if (!line.trim()) return;
|
||||||
|
var parts = line.split('|').map(function (p) { return p.trim(); });
|
||||||
|
var date = toIsoDate(parts[0] || '');
|
||||||
|
var title = parts[3] || '';
|
||||||
|
if (!date || !title) {
|
||||||
|
failed.push(line);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Zuerst leere Zeilen der Tabelle nutzen, dann neue anhängen.
|
||||||
|
var row = Array.prototype.filter.call(body.querySelectorAll('.mm-cl-row'), isEmpty)[0] || addRow();
|
||||||
|
field(row, 'date').value = date;
|
||||||
|
field(row, 'type').value = TYPES[(parts[1] || '').toLowerCase()] || 'update';
|
||||||
|
field(row, 'version').value = parts[2] || '';
|
||||||
|
field(row, 'title').value = title;
|
||||||
|
// Falls die Beschreibung selbst ein | enthält, den Rest wieder zusammensetzen.
|
||||||
|
field(row, 'text').value = parts.slice(4).join(' | ');
|
||||||
|
added++;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Nicht erkannte Zeilen bleiben zum Korrigieren im Feld stehen.
|
||||||
|
area.value = failed.join('\n');
|
||||||
|
document.getElementById('mm-cl-paste-status').textContent =
|
||||||
|
MSG.done.replace('%1$s', added).replace('%2$s', failed.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
body.addEventListener('click', function (e) {
|
||||||
|
var button = e.target.closest('.mm-cl-remove');
|
||||||
|
if (!button) return;
|
||||||
|
var row = button.closest('.mm-cl-row');
|
||||||
|
// Letzte Zeile nicht entfernen, nur leeren.
|
||||||
|
if (body.querySelectorAll('.mm-cl-row').length > 1) {
|
||||||
|
row.remove();
|
||||||
|
} else {
|
||||||
|
row.querySelectorAll('input, textarea').forEach(function (f) { f.value = ''; });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Changelog: Filter nach Art und RSS-Feed.
|
||||||
|
*
|
||||||
|
* - /changelog/?art=feature zeigt nur Einträge der Art "Neu" (auch mit Seitenzahlen).
|
||||||
|
* - Der Feed unter /changelog/feed/ wird in jeder Seite als Abo-Link angeboten
|
||||||
|
* und bekommt Art und Version im Titel, z. B. "[Update] Lobby 2.0 (v2.0)".
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gewählte Art aus der Adresse ("art"), oder '' für alle.
|
||||||
|
* Nur bekannte Schlüssel werden akzeptiert.
|
||||||
|
*/
|
||||||
|
function mm_changelog_current_type() {
|
||||||
|
if ( ! function_exists( 'mm_changelog_types' ) || ! isset( $_GET['art'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$art = sanitize_key( wp_unslash( $_GET['art'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
|
||||||
|
return array_key_exists( $art, mm_changelog_types() ) ? $art : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Filtert die Hauptabfrage des Changelog-Archivs. */
|
||||||
|
function mm_changelog_filter_query( $query ) {
|
||||||
|
if ( is_admin() || ! $query->is_main_query() || ! $query->is_post_type_archive( 'mm_changelog' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$art = mm_changelog_current_type();
|
||||||
|
if ( $art ) {
|
||||||
|
$query->set( 'meta_query', array(
|
||||||
|
array(
|
||||||
|
'key' => '_mm_changelog_type',
|
||||||
|
'value' => $art,
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'pre_get_posts', 'mm_changelog_filter_query' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arten, zu denen es veröffentlichte Einträge gibt (Schlüssel => Anzahl).
|
||||||
|
* Kurz zwischengespeichert; beim Speichern eines Eintrags wird der Wert verworfen.
|
||||||
|
*/
|
||||||
|
function mm_changelog_type_counts() {
|
||||||
|
$counts = get_transient( 'mm_changelog_type_counts' );
|
||||||
|
if ( is_array( $counts ) ) {
|
||||||
|
return $counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
global $wpdb;
|
||||||
|
$rows = $wpdb->get_results( $wpdb->prepare(
|
||||||
|
"SELECT pm.meta_value AS art, COUNT(*) AS n
|
||||||
|
FROM {$wpdb->postmeta} pm
|
||||||
|
INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id
|
||||||
|
WHERE pm.meta_key = %s AND p.post_type = %s AND p.post_status = %s
|
||||||
|
GROUP BY pm.meta_value",
|
||||||
|
'_mm_changelog_type',
|
||||||
|
'mm_changelog',
|
||||||
|
'publish'
|
||||||
|
) );
|
||||||
|
|
||||||
|
$counts = array();
|
||||||
|
foreach ( (array) $rows as $row ) {
|
||||||
|
$counts[ $row->art ] = (int) $row->n;
|
||||||
|
}
|
||||||
|
set_transient( 'mm_changelog_type_counts', $counts, 10 * MINUTE_IN_SECONDS );
|
||||||
|
return $counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_changelog_flush_type_counts() {
|
||||||
|
delete_transient( 'mm_changelog_type_counts' );
|
||||||
|
}
|
||||||
|
add_action( 'save_post_mm_changelog', 'mm_changelog_flush_type_counts' );
|
||||||
|
add_action( 'deleted_post', 'mm_changelog_flush_type_counts' );
|
||||||
|
add_action( 'trashed_post', 'mm_changelog_flush_type_counts' );
|
||||||
|
|
||||||
|
/** Filterleiste über der Zeitleiste. */
|
||||||
|
function mm_changelog_render_filter() {
|
||||||
|
$counts = mm_changelog_type_counts();
|
||||||
|
if ( count( $counts ) < 2 ) {
|
||||||
|
return; // Bei nur einer Art gibt es nichts zu filtern.
|
||||||
|
}
|
||||||
|
|
||||||
|
$base = get_post_type_archive_link( 'mm_changelog' );
|
||||||
|
$current = mm_changelog_current_type();
|
||||||
|
$total = array_sum( $counts );
|
||||||
|
|
||||||
|
echo '<nav class="mm-changelog-filter" aria-label="' . esc_attr__( 'Changelog filtern', 'minecraft-modern-theme' ) . '">';
|
||||||
|
printf(
|
||||||
|
'<a class="mm-changelog-filter__item%s" href="%s"%s>%s <span class="mm-changelog-filter__n">%d</span></a>',
|
||||||
|
$current ? '' : ' is-active',
|
||||||
|
esc_url( $base ),
|
||||||
|
$current ? '' : ' aria-current="page"',
|
||||||
|
esc_html__( 'Alle', 'minecraft-modern-theme' ),
|
||||||
|
(int) $total
|
||||||
|
);
|
||||||
|
foreach ( mm_changelog_types() as $key => $info ) {
|
||||||
|
if ( empty( $counts[ $key ] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
printf(
|
||||||
|
'<a class="mm-changelog-filter__item%s" href="%s"%s style="--mm-cl-color: %s;"><i class="%s" aria-hidden="true"></i> %s <span class="mm-changelog-filter__n">%d</span></a>',
|
||||||
|
$current === $key ? ' is-active' : '',
|
||||||
|
esc_url( add_query_arg( 'art', $key, $base ) ),
|
||||||
|
$current === $key ? ' aria-current="page"' : '',
|
||||||
|
esc_attr( $info['color'] ),
|
||||||
|
esc_attr( $info['icon'] ),
|
||||||
|
esc_html( $info['label'] ),
|
||||||
|
(int) $counts[ $key ]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
echo '</nav>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gefilterte Ansichten nicht in Suchmaschinen aufnehmen (doppelte Inhalte). */
|
||||||
|
function mm_changelog_filter_robots( $robots ) {
|
||||||
|
if ( is_post_type_archive( 'mm_changelog' ) && mm_changelog_current_type() ) {
|
||||||
|
$robots['noindex'] = true;
|
||||||
|
$robots['follow'] = true;
|
||||||
|
unset( $robots['index'] );
|
||||||
|
}
|
||||||
|
return $robots;
|
||||||
|
}
|
||||||
|
add_filter( 'wp_robots', 'mm_changelog_filter_robots' );
|
||||||
|
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// RSS-Feed
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
/** Feed-Link im <head> aller Seiten, damit Feed-Reader ihn automatisch finden. */
|
||||||
|
function mm_changelog_feed_discovery() {
|
||||||
|
if ( ! function_exists( 'mm_changelog_enabled' ) || ! mm_changelog_enabled() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$url = get_post_type_archive_feed_link( 'mm_changelog' );
|
||||||
|
if ( $url ) {
|
||||||
|
printf(
|
||||||
|
'<link rel="alternate" type="application/rss+xml" title="%s" href="%s">' . "\n",
|
||||||
|
esc_attr( get_bloginfo( 'name' ) . ' – ' . __( 'Changelog', 'minecraft-modern-theme' ) ),
|
||||||
|
esc_url( $url )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'wp_head', 'mm_changelog_feed_discovery', 3 );
|
||||||
|
|
||||||
|
/** Titel im Feed: "[Art] Titel (vVersion)". */
|
||||||
|
function mm_changelog_feed_title( $title ) {
|
||||||
|
$post = get_post();
|
||||||
|
if ( ! $post || 'mm_changelog' !== $post->post_type ) {
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
$types = mm_changelog_types();
|
||||||
|
$type = get_post_meta( $post->ID, '_mm_changelog_type', true );
|
||||||
|
$version = get_post_meta( $post->ID, '_mm_changelog_version', true );
|
||||||
|
|
||||||
|
$prefix = isset( $types[ $type ] ) ? '[' . $types[ $type ]['label'] . '] ' : '';
|
||||||
|
$suffix = $version ? ' (v' . ltrim( $version, 'vV' ) . ')' : '';
|
||||||
|
return $prefix . $title . $suffix;
|
||||||
|
}
|
||||||
|
add_filter( 'the_title_rss', 'mm_changelog_feed_title' );
|
||||||
@@ -0,0 +1,304 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Community-Bausteine: Discord-Karte und Vote-Seiten-Liste.
|
||||||
|
*
|
||||||
|
* Discord: Die Daten kommen serverseitig aus der oeffentlichen Widget-API des
|
||||||
|
* Discord-Servers und werden 5 Minuten zwischengespeichert. Der Browser des
|
||||||
|
* Besuchers baut dabei KEINE Verbindung zu Discord auf (kein iframe, keine
|
||||||
|
* Avatare von Discord-Servern) – es ist daher keine Einwilligung noetig.
|
||||||
|
*
|
||||||
|
* Ausgabe ueber Startseiten-Sektionen, Widgets oder die Shortcodes
|
||||||
|
* [mm_discord] und [mm_vote].
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_community_customizer( $wp_customize ) {
|
||||||
|
// ── Discord ──
|
||||||
|
$wp_customize->add_section( 'mm_discord_section', array(
|
||||||
|
'title' => __( 'Discord-Karte', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Zeigt Servername, Online-Zahl und Beitritts-Button. Dafür muss in Discord unter Servereinstellungen → Widget das „Server-Widget“ aktiviert sein. Einbinden per Startseiten-Sektion, Widget oder Shortcode [mm_discord].', 'minecraft-modern-theme' ),
|
||||||
|
'priority' => 23,
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_discord_guild_id', array(
|
||||||
|
'default' => '',
|
||||||
|
'sanitize_callback' => 'mm_community_sanitize_snowflake',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_discord_guild_id', array(
|
||||||
|
'label' => __( 'Discord Server-ID', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Die Zahl aus Servereinstellungen → Widget → „Server-ID“.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_discord_section',
|
||||||
|
'type' => 'text',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_discord_invite', array(
|
||||||
|
'default' => '',
|
||||||
|
'sanitize_callback' => 'esc_url_raw',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_discord_invite', array(
|
||||||
|
'label' => __( 'Einladungslink', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Leer = Discord-Link aus „Social Media Links“ bzw. der Link aus dem Discord-Widget.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_discord_section',
|
||||||
|
'type' => 'url',
|
||||||
|
) );
|
||||||
|
|
||||||
|
// ── Vote-Seiten ──
|
||||||
|
$wp_customize->add_section( 'mm_vote_section', array(
|
||||||
|
'title' => __( 'Vote-Seiten', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Liste der Serverlisten, auf denen Spieler abstimmen können. Einbinden per Startseiten-Sektion, Widget oder Shortcode [mm_vote].', 'minecraft-modern-theme' ),
|
||||||
|
'priority' => 24,
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_vote_sites', array(
|
||||||
|
'default' => '',
|
||||||
|
'sanitize_callback' => 'sanitize_textarea_field',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_vote_sites', array(
|
||||||
|
'label' => __( 'Vote-Seiten', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Eine Seite pro Zeile im Format: Name | https://link-zur-vote-seite', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_vote_section',
|
||||||
|
'type' => 'textarea',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_vote_text', array(
|
||||||
|
'default' => '',
|
||||||
|
'sanitize_callback' => 'sanitize_text_field',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_vote_text', array(
|
||||||
|
'label' => __( 'Hinweistext (optional)', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'z. B. „Für jeden Vote bekommst du einen Vote-Key.“', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_vote_section',
|
||||||
|
'type' => 'text',
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
add_action( 'customize_register', 'mm_community_customizer' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discord-IDs ("Snowflakes") sind reine Zahlen mit 17–20 Stellen.
|
||||||
|
*/
|
||||||
|
function mm_community_sanitize_snowflake( $value ) {
|
||||||
|
$value = preg_replace( '/\D/', '', (string) $value );
|
||||||
|
return preg_match( '/^\d{17,20}$/', $value ) ? $value : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liefert Name, Online-Zahl und Einladungslink des Discord-Servers.
|
||||||
|
*
|
||||||
|
* @return array|null null, wenn keine ID gesetzt ist oder Discord nicht antwortet.
|
||||||
|
*/
|
||||||
|
function mm_discord_get_data() {
|
||||||
|
$guild_id = get_theme_mod( 'mm_discord_guild_id', '' );
|
||||||
|
if ( empty( $guild_id ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = 'mm_discord_widget_' . $guild_id;
|
||||||
|
$cached = get_transient( $key );
|
||||||
|
if ( false !== $cached ) {
|
||||||
|
return is_array( $cached ) ? $cached : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = 0; // 0 = Fehlschlag merken, damit nicht jeder Seitenaufruf erneut anfragt.
|
||||||
|
$response = wp_remote_get( 'https://discord.com/api/guilds/' . $guild_id . '/widget.json', array( 'timeout' => 4 ) );
|
||||||
|
if ( ! is_wp_error( $response ) && 200 === wp_remote_retrieve_response_code( $response ) ) {
|
||||||
|
$json = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||||
|
if ( is_array( $json ) && isset( $json['name'] ) ) {
|
||||||
|
$data = array(
|
||||||
|
'name' => sanitize_text_field( $json['name'] ),
|
||||||
|
'online' => (int) ( $json['presence_count'] ?? 0 ),
|
||||||
|
'invite' => esc_url_raw( $json['instant_invite'] ?? '' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set_transient( $key, $data, 5 * MINUTE_IN_SECONDS );
|
||||||
|
return is_array( $data ) ? $data : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rendert die Discord-Karte.
|
||||||
|
*/
|
||||||
|
function mm_discord_render() {
|
||||||
|
$data = mm_discord_get_data();
|
||||||
|
$invite = get_theme_mod( 'mm_discord_invite', '' );
|
||||||
|
if ( empty( $invite ) ) {
|
||||||
|
$invite = get_theme_mod( 'social_discord', '' );
|
||||||
|
}
|
||||||
|
if ( empty( $invite ) && $data ) {
|
||||||
|
$invite = $data['invite'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ohne Daten und ohne Link gibt es nichts Sinnvolles anzuzeigen.
|
||||||
|
if ( ! $data && empty( $invite ) ) {
|
||||||
|
if ( current_user_can( 'edit_theme_options' ) ) {
|
||||||
|
return '<p class="mm-server-status-hint">' . esc_html__( 'Discord-Karte: Bitte im Customizer unter „Discord-Karte“ Server-ID oder Einladungslink eintragen.', 'minecraft-modern-theme' ) . '</p>';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = $data ? $data['name'] : __( 'Unser Discord', 'minecraft-modern-theme' );
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
?>
|
||||||
|
<div class="mm-discord-card">
|
||||||
|
<div class="mm-discord-card__icon" aria-hidden="true"><i class="fab fa-discord"></i></div>
|
||||||
|
<div class="mm-discord-card__body">
|
||||||
|
<p class="mm-discord-card__name"><?php echo esc_html( $name ); ?></p>
|
||||||
|
<?php if ( $data ) : ?>
|
||||||
|
<p class="mm-discord-card__online">
|
||||||
|
<span class="mm-discord-card__dot" aria-hidden="true"></span>
|
||||||
|
<?php
|
||||||
|
/* translators: %s: number of members online */
|
||||||
|
echo esc_html( sprintf( _n( '%s Mitglied online', '%s Mitglieder online', $data['online'], 'minecraft-modern-theme' ), number_format_i18n( $data['online'] ) ) );
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php if ( $invite ) : ?>
|
||||||
|
<a class="mm-discord-card__join" href="<?php echo esc_url( $invite ); ?>" target="_blank" rel="noopener noreferrer">
|
||||||
|
<?php esc_html_e( 'Beitreten', 'minecraft-modern-theme' ); ?>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
return ob_get_clean();
|
||||||
|
}
|
||||||
|
add_shortcode( 'mm_discord', 'mm_discord_render' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liest die Vote-Seiten aus dem Customizer.
|
||||||
|
*
|
||||||
|
* @return array[] Liste aus array( 'name' => …, 'url' => … ).
|
||||||
|
*/
|
||||||
|
function mm_vote_get_sites() {
|
||||||
|
$sites = array();
|
||||||
|
foreach ( preg_split( '/\r\n|\r|\n/', (string) get_theme_mod( 'mm_vote_sites', '' ) ) as $line ) {
|
||||||
|
if ( false === strpos( $line, '|' ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
list( $name, $url ) = array_map( 'trim', explode( '|', $line, 2 ) );
|
||||||
|
$url = esc_url_raw( $url, array( 'http', 'https' ) );
|
||||||
|
if ( '' !== $name && '' !== $url ) {
|
||||||
|
$sites[] = array( 'name' => $name, 'url' => $url );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $sites;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rendert die Vote-Liste.
|
||||||
|
*/
|
||||||
|
function mm_vote_render() {
|
||||||
|
$sites = mm_vote_get_sites();
|
||||||
|
if ( empty( $sites ) ) {
|
||||||
|
if ( current_user_can( 'edit_theme_options' ) ) {
|
||||||
|
return '<p class="mm-server-status-hint">' . esc_html__( 'Vote-Liste: Bitte im Customizer unter „Vote-Seiten“ mindestens eine Seite eintragen.', 'minecraft-modern-theme' ) . '</p>';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$text = get_theme_mod( 'mm_vote_text', '' );
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
?>
|
||||||
|
<div class="mm-vote">
|
||||||
|
<?php if ( $text ) : ?>
|
||||||
|
<p class="mm-vote__text"><?php echo esc_html( $text ); ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<ol class="mm-vote__list">
|
||||||
|
<?php foreach ( $sites as $site ) : ?>
|
||||||
|
<li>
|
||||||
|
<a class="mm-vote__link" href="<?php echo esc_url( $site['url'] ); ?>" target="_blank" rel="noopener noreferrer nofollow">
|
||||||
|
<span class="mm-vote__name"><?php echo esc_html( $site['name'] ); ?></span>
|
||||||
|
<span class="mm-vote__cta"><?php esc_html_e( 'Voten', 'minecraft-modern-theme' ); ?> <i class="fas fa-external-link-alt" aria-hidden="true"></i></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
return ob_get_clean();
|
||||||
|
}
|
||||||
|
add_shortcode( 'mm_vote', 'mm_vote_render' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Einfaches Widget, das die Ausgabe einer Render-Funktion anzeigt.
|
||||||
|
* Basis fuer das Discord- und das Vote-Widget.
|
||||||
|
*/
|
||||||
|
abstract class MM_Render_Widget extends WP_Widget {
|
||||||
|
|
||||||
|
/** @return string HTML des Bausteins. */
|
||||||
|
abstract protected function render();
|
||||||
|
|
||||||
|
/** @return string Vorgabe fuer den Widget-Titel. */
|
||||||
|
abstract protected function default_title();
|
||||||
|
|
||||||
|
public function widget( $args, $instance ) {
|
||||||
|
$html = $this->render();
|
||||||
|
if ( '' === $html ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput
|
||||||
|
$title = apply_filters( 'widget_title', $instance['title'] ?? '' );
|
||||||
|
if ( $title ) {
|
||||||
|
echo $args['before_title'] . esc_html( $title ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput
|
||||||
|
}
|
||||||
|
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput -- in der Render-Funktion escaped.
|
||||||
|
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form( $instance ) {
|
||||||
|
$title = $instance['title'] ?? $this->default_title();
|
||||||
|
?>
|
||||||
|
<p>
|
||||||
|
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Titel:', 'minecraft-modern-theme' ); ?></label>
|
||||||
|
<input class="widefat" type="text" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
|
||||||
|
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $title ); ?>">
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update( $new_instance, $old_instance ) {
|
||||||
|
return array( 'title' => 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' );
|
||||||
@@ -0,0 +1,518 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Optionale Inhaltstypen: Regelwerk und Changelog.
|
||||||
|
*
|
||||||
|
* Beide Module sind standardmaessig AUS und werden im Customizer unter
|
||||||
|
* "Module" eingeschaltet. So entsteht kein Konflikt mit Plugins, die
|
||||||
|
* dieselbe Aufgabe bereits uebernehmen (z. B. ein Regel-Plugin).
|
||||||
|
*
|
||||||
|
* - Regelwerk: /regelwerk – Regeln nach Kategorien, mit Inhaltsverzeichnis
|
||||||
|
* und Ankerlinks (§-Nummern).
|
||||||
|
* - Changelog: /changelog – Zeitleiste mit Version und Art der Aenderung,
|
||||||
|
* ausserdem Shortcode [mm_changelog count="5"].
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_rules_enabled() {
|
||||||
|
return (bool) get_theme_mod( 'mm_rules_enabled', false );
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_changelog_enabled() {
|
||||||
|
return (bool) get_theme_mod( 'mm_changelog_enabled', false );
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_content_types_customizer( $wp_customize ) {
|
||||||
|
$wp_customize->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 );
|
||||||
|
?>
|
||||||
|
<p>
|
||||||
|
<label for="mm_changelog_version"><strong><?php esc_html_e( 'Version (optional)', 'minecraft-modern-theme' ); ?></strong></label>
|
||||||
|
<input type="text" class="widefat" id="mm_changelog_version" name="mm_changelog_version"
|
||||||
|
value="<?php echo esc_attr( $version ); ?>" placeholder="z. B. 1.4.2" maxlength="30">
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="mm_changelog_type"><strong><?php esc_html_e( 'Art', 'minecraft-modern-theme' ); ?></strong></label>
|
||||||
|
<select class="widefat" id="mm_changelog_type" name="mm_changelog_type">
|
||||||
|
<?php foreach ( mm_changelog_types() as $key => $info ) : ?>
|
||||||
|
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $type, $key ); ?>><?php echo esc_html( $info['label'] ); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_changelog_save_meta( $post_id ) {
|
||||||
|
if ( ! isset( $_POST['mm_changelog_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['mm_changelog_nonce'] ) ), 'mm_changelog_save' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = isset( $_POST['mm_changelog_version'] ) ? mb_substr( sanitize_text_field( wp_unslash( $_POST['mm_changelog_version'] ) ), 0, 30 ) : '';
|
||||||
|
update_post_meta( $post_id, '_mm_changelog_version', $version );
|
||||||
|
|
||||||
|
$type = isset( $_POST['mm_changelog_type'] ) ? sanitize_key( wp_unslash( $_POST['mm_changelog_type'] ) ) : 'update';
|
||||||
|
if ( ! array_key_exists( $type, mm_changelog_types() ) ) {
|
||||||
|
$type = 'update';
|
||||||
|
}
|
||||||
|
update_post_meta( $post_id, '_mm_changelog_type', $type );
|
||||||
|
}
|
||||||
|
add_action( 'save_post_mm_changelog', 'mm_changelog_save_meta' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 15 Eintraege pro Seite im Changelog-Archiv.
|
||||||
|
*/
|
||||||
|
function mm_changelog_archive_query( $query ) {
|
||||||
|
if ( ! is_admin() && $query->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 );
|
||||||
|
?>
|
||||||
|
<li class="mm-changelog__entry" id="changelog-<?php the_ID(); ?>">
|
||||||
|
<span class="mm-changelog__marker" style="--mm-cl-color: <?php echo esc_attr( $info['color'] ); ?>;" aria-hidden="true">
|
||||||
|
<i class="<?php echo esc_attr( $info['icon'] ); ?>"></i>
|
||||||
|
</span>
|
||||||
|
<article class="mm-changelog__card">
|
||||||
|
<header class="mm-changelog__head">
|
||||||
|
<span class="mm-changelog__type" style="--mm-cl-color: <?php echo esc_attr( $info['color'] ); ?>;"><?php echo esc_html( $info['label'] ); ?></span>
|
||||||
|
<?php if ( $version ) : ?>
|
||||||
|
<span class="mm-changelog__version">v<?php echo esc_html( ltrim( $version, 'vV' ) ); ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
<time class="mm-changelog__date" datetime="<?php echo esc_attr( get_the_date( 'c' ) ); ?>"><?php echo esc_html( get_the_date() ); ?></time>
|
||||||
|
</header>
|
||||||
|
<h3 class="mm-changelog__title">
|
||||||
|
<?php if ( $excerpt ) : ?>
|
||||||
|
<a href="<?php echo esc_url( get_post_type_archive_link( 'mm_changelog' ) . '#changelog-' . get_the_ID() ); ?>"><?php the_title(); ?></a>
|
||||||
|
<?php else : ?>
|
||||||
|
<?php the_title(); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</h3>
|
||||||
|
<div class="mm-changelog__content">
|
||||||
|
<?php
|
||||||
|
if ( $excerpt ) {
|
||||||
|
echo '<p>' . esc_html( wp_trim_words( wp_strip_all_tags( strip_shortcodes( get_the_content() ) ), 30 ) ) . '</p>';
|
||||||
|
} else {
|
||||||
|
the_content();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</li>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rendert die neuesten Changelog-Eintraege (Startseite, Shortcode).
|
||||||
|
*/
|
||||||
|
function mm_changelog_render_latest( $count = 5 ) {
|
||||||
|
if ( ! mm_changelog_enabled() ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
wp_enqueue_style( 'mm-community' );
|
||||||
|
|
||||||
|
$query = new WP_Query( array(
|
||||||
|
'post_type' => 'mm_changelog',
|
||||||
|
'posts_per_page' => max( 1, min( 20, (int) $count ) ),
|
||||||
|
'no_found_rows' => true,
|
||||||
|
) );
|
||||||
|
if ( ! $query->have_posts() ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
echo '<ol class="mm-changelog mm-changelog--compact">';
|
||||||
|
while ( $query->have_posts() ) {
|
||||||
|
$query->the_post();
|
||||||
|
mm_changelog_render_entry( true );
|
||||||
|
}
|
||||||
|
echo '</ol>';
|
||||||
|
wp_reset_postdata();
|
||||||
|
return ob_get_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_changelog_shortcode( $atts ) {
|
||||||
|
$atts = shortcode_atts( array( 'count' => 5 ), $atts, 'mm_changelog' );
|
||||||
|
return mm_changelog_render_latest( $atts['count'] );
|
||||||
|
}
|
||||||
|
add_shortcode( 'mm_changelog', 'mm_changelog_shortcode' );
|
||||||
@@ -365,6 +365,9 @@ function minecraft_modern_customize_register( $wp_customize ) {
|
|||||||
$wp_customize->add_setting( 'faq_enabled', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
|
$wp_customize->add_setting( 'faq_enabled', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
|
||||||
$wp_customize->add_control( 'faq_enabled', array( 'label' => __('FAQ System aktivieren', 'minecraft-modern-theme'), 'section' => 'faq_settings', 'type' => 'checkbox' ) );
|
$wp_customize->add_control( 'faq_enabled', array( 'label' => __('FAQ System aktivieren', 'minecraft-modern-theme'), 'section' => 'faq_settings', 'type' => 'checkbox' ) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'faq_show_title', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) );
|
||||||
|
$wp_customize->add_control( 'faq_show_title', array( 'label' => __('Überschrift auf der FAQ-Seite anzeigen', 'minecraft-modern-theme'), 'section' => 'faq_settings', 'type' => 'checkbox' ) );
|
||||||
|
|
||||||
$wp_customize->add_section( 'team_settings', array( 'title' => __('Team Einstellungen', 'minecraft-modern-theme'), 'priority' => 65 ) );
|
$wp_customize->add_section( 'team_settings', array( 'title' => __('Team Einstellungen', 'minecraft-modern-theme'), 'priority' => 65 ) );
|
||||||
$wp_customize->add_setting( 'team_enabled', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
|
$wp_customize->add_setting( 'team_enabled', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
|
||||||
$wp_customize->add_control( 'team_enabled', array( 'label' => __('Team Showcase aktivieren', 'minecraft-modern-theme'), 'section' => 'team_settings', 'type' => 'checkbox' ) );
|
$wp_customize->add_control( 'team_enabled', array( 'label' => __('Team Showcase aktivieren', 'minecraft-modern-theme'), 'section' => 'team_settings', 'type' => 'checkbox' ) );
|
||||||
|
|||||||
@@ -0,0 +1,365 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Event-Kalender: Turniere, Aktionen, Wartungsfenster und Feiertags-Events.
|
||||||
|
*
|
||||||
|
* Das Modul ist standardmäßig AUS und wird im Customizer unter "Module"
|
||||||
|
* eingeschaltet. Es bringt
|
||||||
|
* - den Inhaltstyp "Events" (Backend-Menü, Seite /events),
|
||||||
|
* - Start, optionales Ende, Ort/Server und Link pro Event,
|
||||||
|
* - Shortcode [mm_events count="3"] und eine Startseiten-Sektion.
|
||||||
|
*
|
||||||
|
* Auf /events stehen kommende Events (das nächste zuerst) und darunter eine
|
||||||
|
* kurze Liste vergangener Events. Ein Event gilt als vorbei, sobald sein Ende
|
||||||
|
* erreicht ist - ohne Endzeit drei Stunden nach dem Start.
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wie lange ein Event ohne Endzeit als "läuft gerade" gilt. */
|
||||||
|
define( 'MM_EVENT_DEFAULT_DURATION', 3 * HOUR_IN_SECONDS );
|
||||||
|
|
||||||
|
function mm_events_enabled() {
|
||||||
|
return (bool) get_theme_mod( 'mm_events_enabled', false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// 1. Customizer und Inhaltstyp
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
function mm_events_customizer( $wp_customize ) {
|
||||||
|
$wp_customize->add_setting( 'mm_events_enabled', array(
|
||||||
|
'default' => false,
|
||||||
|
'sanitize_callback' => 'wp_validate_boolean',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_events_enabled', array(
|
||||||
|
'label' => __( 'Event-Kalender aktivieren', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Turniere, Aktionen und Wartungen mit Datum unter /events. Im Backend erscheint der Menüpunkt „Events“.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_modules_section',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
) );
|
||||||
|
|
||||||
|
// Startseiten-Sektion
|
||||||
|
$wp_customize->add_section( 'mm_home_events_section', array(
|
||||||
|
'title' => __( 'Nächste Events', 'minecraft-modern-theme' ),
|
||||||
|
'panel' => 'mm_home_panel',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_setting( 'mm_home_events', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) );
|
||||||
|
$wp_customize->add_control( 'mm_home_events', array(
|
||||||
|
'label' => __( 'Kommende Events anzeigen', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Benötigt das Modul „Event-Kalender“ (Customizer → Module). Ohne kommende Events bleibt der Block unsichtbar.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_home_events_section',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_setting( 'mm_home_events_count', array( 'default' => 3, 'sanitize_callback' => 'absint' ) );
|
||||||
|
$wp_customize->add_control( 'mm_home_events_count', array(
|
||||||
|
'label' => __( 'Anzahl Events', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_home_events_section',
|
||||||
|
'type' => 'number',
|
||||||
|
'input_attrs' => array( 'min' => 1, 'max' => 10 ),
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
// Priorität 11: Section "mm_modules_section" und Panel "mm_home_panel" müssen schon existieren.
|
||||||
|
add_action( 'customize_register', 'mm_events_customizer', 11 );
|
||||||
|
|
||||||
|
function mm_events_register() {
|
||||||
|
if ( ! mm_events_enabled() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
register_post_type( 'mm_event', array(
|
||||||
|
'labels' => array(
|
||||||
|
'name' => __( 'Events', 'minecraft-modern-theme' ),
|
||||||
|
'singular_name' => __( 'Event', 'minecraft-modern-theme' ),
|
||||||
|
'add_new' => __( 'Neues Event', 'minecraft-modern-theme' ),
|
||||||
|
'add_new_item' => __( 'Neues Event hinzufügen', 'minecraft-modern-theme' ),
|
||||||
|
'edit_item' => __( 'Event bearbeiten', 'minecraft-modern-theme' ),
|
||||||
|
'all_items' => __( 'Events', 'minecraft-modern-theme' ),
|
||||||
|
'not_found' => __( 'Keine Events gefunden', 'minecraft-modern-theme' ),
|
||||||
|
),
|
||||||
|
'public' => true,
|
||||||
|
'has_archive' => 'events',
|
||||||
|
'rewrite' => array( 'slug' => 'events', 'with_front' => false ),
|
||||||
|
'menu_icon' => 'dashicons-calendar-alt',
|
||||||
|
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
|
||||||
|
'show_in_rest' => true,
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
add_action( 'init', 'mm_events_register' );
|
||||||
|
// Hinweis: Das Neuaufbauen der Permalinks nach dem Ein-/Ausschalten übernimmt
|
||||||
|
// mm_content_types_schedule_flush() in content-types.php (hängt an customize_save_after).
|
||||||
|
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// 2. Datumshilfen
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
/** Wandelt "2026-12-05T18:00" (Ortszeit der Seite) in einen Zeitstempel; 0 bei ungültiger Eingabe. */
|
||||||
|
function mm_event_parse( $value ) {
|
||||||
|
$value = trim( (string) $value );
|
||||||
|
$dt = DateTime::createFromFormat( 'Y-m-d\TH:i', $value, wp_timezone() );
|
||||||
|
$err = DateTime::getLastErrors();
|
||||||
|
if ( ! $dt || ( $err && ( $err['warning_count'] || $err['error_count'] ) ) ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return $dt->getTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{start:int,end:int,until:int} Zeitstempel; end=0 wenn keine Endzeit gesetzt. */
|
||||||
|
function mm_event_times( $post_id ) {
|
||||||
|
$start = mm_event_parse( get_post_meta( $post_id, '_mm_event_start', true ) );
|
||||||
|
$end = mm_event_parse( get_post_meta( $post_id, '_mm_event_end', true ) );
|
||||||
|
if ( $end && $end <= $start ) {
|
||||||
|
$end = 0;
|
||||||
|
}
|
||||||
|
return array(
|
||||||
|
'start' => $start,
|
||||||
|
'end' => $end,
|
||||||
|
'until' => $end ? $end : $start + MM_EVENT_DEFAULT_DURATION,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// 3. Eingabemaske im Backend
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
function mm_event_add_meta_box() {
|
||||||
|
add_meta_box( 'mm_event_details', __( 'Zeit und Ort', 'minecraft-modern-theme' ), 'mm_event_meta_box', 'mm_event', 'normal', 'high' );
|
||||||
|
}
|
||||||
|
add_action( 'add_meta_boxes', 'mm_event_add_meta_box' );
|
||||||
|
|
||||||
|
function mm_event_meta_box( $post ) {
|
||||||
|
wp_nonce_field( 'mm_event_save', 'mm_event_nonce' );
|
||||||
|
$start = get_post_meta( $post->ID, '_mm_event_start', true );
|
||||||
|
$end = get_post_meta( $post->ID, '_mm_event_end', true );
|
||||||
|
$where = get_post_meta( $post->ID, '_mm_event_where', true );
|
||||||
|
$url = get_post_meta( $post->ID, '_mm_event_url', true );
|
||||||
|
?>
|
||||||
|
<table class="form-table" role="presentation">
|
||||||
|
<tr>
|
||||||
|
<th><label for="mm_event_start"><?php esc_html_e( 'Beginn', 'minecraft-modern-theme' ); ?></label></th>
|
||||||
|
<td><input type="datetime-local" id="mm_event_start" name="mm_event_start" value="<?php echo esc_attr( $start ); ?>" required></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><label for="mm_event_end"><?php esc_html_e( 'Ende (optional)', 'minecraft-modern-theme' ); ?></label></th>
|
||||||
|
<td>
|
||||||
|
<input type="datetime-local" id="mm_event_end" name="mm_event_end" value="<?php echo esc_attr( $end ); ?>">
|
||||||
|
<p class="description"><?php esc_html_e( 'Ohne Ende gilt das Event drei Stunden nach dem Beginn als vorbei.', 'minecraft-modern-theme' ); ?></p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><label for="mm_event_where"><?php esc_html_e( 'Ort / Server', 'minecraft-modern-theme' ); ?></label></th>
|
||||||
|
<td><input type="text" id="mm_event_where" name="mm_event_where" class="regular-text" value="<?php echo esc_attr( $where ); ?>" placeholder="<?php esc_attr_e( 'z. B. Minigames-Server', 'minecraft-modern-theme' ); ?>"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><label for="mm_event_url"><?php esc_html_e( 'Link (optional)', 'minecraft-modern-theme' ); ?></label></th>
|
||||||
|
<td><input type="url" id="mm_event_url" name="mm_event_url" class="regular-text" value="<?php echo esc_attr( $url ); ?>" placeholder="https://"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_event_save( $post_id ) {
|
||||||
|
if ( ! isset( $_POST['mm_event_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['mm_event_nonce'] ) ), 'mm_event_save' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! current_user_can( 'edit_post', $post_id ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Beginn und Ende: nur gültige Werte speichern.
|
||||||
|
foreach ( array( 'start', 'end' ) as $f ) {
|
||||||
|
$raw = isset( $_POST[ 'mm_event_' . $f ] ) ? sanitize_text_field( wp_unslash( $_POST[ 'mm_event_' . $f ] ) ) : '';
|
||||||
|
if ( mm_event_parse( $raw ) ) {
|
||||||
|
update_post_meta( $post_id, '_mm_event_' . $f, $raw );
|
||||||
|
} else {
|
||||||
|
delete_post_meta( $post_id, '_mm_event_' . $f );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$where = isset( $_POST['mm_event_where'] ) ? sanitize_text_field( wp_unslash( $_POST['mm_event_where'] ) ) : '';
|
||||||
|
$url = isset( $_POST['mm_event_url'] ) ? esc_url_raw( wp_unslash( $_POST['mm_event_url'] ), array( 'http', 'https' ) ) : '';
|
||||||
|
update_post_meta( $post_id, '_mm_event_where', $where );
|
||||||
|
update_post_meta( $post_id, '_mm_event_url', $url );
|
||||||
|
|
||||||
|
// Sortier-/Filterwert: Zeitpunkt, ab dem das Event vorbei ist.
|
||||||
|
$t = mm_event_times( $post_id );
|
||||||
|
if ( $t['start'] ) {
|
||||||
|
update_post_meta( $post_id, '_mm_event_until', $t['until'] );
|
||||||
|
} else {
|
||||||
|
delete_post_meta( $post_id, '_mm_event_until' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'save_post_mm_event', 'mm_event_save' );
|
||||||
|
|
||||||
|
/** Spalten in der Backend-Liste. */
|
||||||
|
function mm_event_columns( $cols ) {
|
||||||
|
$out = array();
|
||||||
|
foreach ( $cols as $k => $v ) {
|
||||||
|
$out[ $k ] = $v;
|
||||||
|
if ( 'title' === $k ) {
|
||||||
|
$out['mm_start'] = __( 'Beginn', 'minecraft-modern-theme' );
|
||||||
|
$out['mm_where'] = __( 'Ort / Server', 'minecraft-modern-theme' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset( $out['date'] );
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
add_filter( 'manage_mm_event_posts_columns', 'mm_event_columns' );
|
||||||
|
|
||||||
|
function mm_event_column_content( $col, $post_id ) {
|
||||||
|
if ( 'mm_start' === $col ) {
|
||||||
|
$t = mm_event_times( $post_id );
|
||||||
|
echo $t['start'] ? esc_html( wp_date( 'd.m.Y, H:i', $t['start'] ) . ' Uhr' ) : '<em>' . esc_html__( 'Kein Datum', 'minecraft-modern-theme' ) . '</em>';
|
||||||
|
} elseif ( 'mm_where' === $col ) {
|
||||||
|
echo esc_html( get_post_meta( $post_id, '_mm_event_where', true ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'manage_mm_event_posts_custom_column', 'mm_event_column_content', 10, 2 );
|
||||||
|
|
||||||
|
function mm_event_sortable( $cols ) {
|
||||||
|
$cols['mm_start'] = 'mm_start';
|
||||||
|
return $cols;
|
||||||
|
}
|
||||||
|
add_filter( 'manage_edit-mm_event_sortable_columns', 'mm_event_sortable' );
|
||||||
|
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// 4. Abfragen
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kommende bzw. vergangene Events.
|
||||||
|
*
|
||||||
|
* @param bool $upcoming true = noch nicht vorbei (nächstes zuerst), false = vorbei (jüngstes zuerst).
|
||||||
|
* @param int $limit Anzahl; -1 = alle.
|
||||||
|
*/
|
||||||
|
function mm_events_query( $upcoming = true, $limit = -1 ) {
|
||||||
|
return new WP_Query( array(
|
||||||
|
'post_type' => 'mm_event',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'posts_per_page' => $limit,
|
||||||
|
'no_found_rows' => true,
|
||||||
|
'meta_key' => '_mm_event_until',
|
||||||
|
'orderby' => 'meta_value_num',
|
||||||
|
'order' => $upcoming ? 'ASC' : 'DESC',
|
||||||
|
'meta_query' => array(
|
||||||
|
array(
|
||||||
|
'key' => '_mm_event_until',
|
||||||
|
'value' => time(),
|
||||||
|
'compare' => $upcoming ? '>=' : '<',
|
||||||
|
'type' => 'NUMERIC',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sortierung nach Beginn in der Backend-Liste; im Backend sonst neueste zuerst. */
|
||||||
|
function mm_event_admin_order( $query ) {
|
||||||
|
if ( ! is_admin() || ! $query->is_main_query() || 'mm_event' !== $query->get( 'post_type' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( ! $query->get( 'orderby' ) || 'mm_start' === $query->get( 'orderby' ) ) {
|
||||||
|
$query->set( 'meta_key', '_mm_event_until' );
|
||||||
|
$query->set( 'orderby', 'meta_value_num' );
|
||||||
|
if ( ! isset( $_GET['order'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||||
|
$query->set( 'order', 'DESC' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'pre_get_posts', 'mm_event_admin_order' );
|
||||||
|
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// 5. Ausgabe
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eine Event-Karte. Muss innerhalb einer Schleife / mit gesetztem $post aufgerufen werden.
|
||||||
|
*
|
||||||
|
* @param int $post_id Event.
|
||||||
|
* @param bool $past true = vergangenes Event (ausgegraut).
|
||||||
|
* @return string HTML (escaped)
|
||||||
|
*/
|
||||||
|
function mm_event_render_card( $post_id, $past = false ) {
|
||||||
|
$t = mm_event_times( $post_id );
|
||||||
|
$now = time();
|
||||||
|
$live = ! $past && $t['start'] && $t['start'] <= $now && $now < $t['until'];
|
||||||
|
$where = get_post_meta( $post_id, '_mm_event_where', true );
|
||||||
|
$url = get_post_meta( $post_id, '_mm_event_url', true );
|
||||||
|
$text = has_excerpt( $post_id ) ? get_the_excerpt( $post_id ) : wp_trim_words( wp_strip_all_tags( strip_shortcodes( get_post_field( 'post_content', $post_id ) ) ), 28 );
|
||||||
|
|
||||||
|
// Zeitangabe: "Sa., 05.12.2026, 18:00 Uhr" bzw. mit Ende am selben Tag "… – 20:00 Uhr".
|
||||||
|
$when = '';
|
||||||
|
if ( $t['start'] ) {
|
||||||
|
$when = wp_date( 'D, d.m.Y, H:i', $t['start'] ) . ' Uhr';
|
||||||
|
if ( $t['end'] ) {
|
||||||
|
$same = wp_date( 'Ymd', $t['start'] ) === wp_date( 'Ymd', $t['end'] );
|
||||||
|
$when .= ' – ' . ( $same ? wp_date( 'H:i', $t['end'] ) : wp_date( 'd.m.Y, H:i', $t['end'] ) ) . ' Uhr';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$classes = 'mm-event' . ( $past ? ' mm-event--past' : '' ) . ( $live ? ' mm-event--live' : '' );
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
?>
|
||||||
|
<article class="<?php echo esc_attr( $classes ); ?>">
|
||||||
|
<?php if ( $t['start'] ) : ?>
|
||||||
|
<time class="mm-event__date" datetime="<?php echo esc_attr( wp_date( 'c', $t['start'] ) ); ?>">
|
||||||
|
<span class="mm-event__day"><?php echo esc_html( wp_date( 'd', $t['start'] ) ); ?></span>
|
||||||
|
<span class="mm-event__month"><?php echo esc_html( wp_date( 'M', $t['start'] ) ); ?></span>
|
||||||
|
</time>
|
||||||
|
<?php endif; ?>
|
||||||
|
<div class="mm-event__body">
|
||||||
|
<h3 class="mm-event__title">
|
||||||
|
<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>"><?php echo esc_html( get_the_title( $post_id ) ); ?></a>
|
||||||
|
<?php if ( $live ) : ?>
|
||||||
|
<span class="mm-event__badge"><?php esc_html_e( 'Läuft gerade', 'minecraft-modern-theme' ); ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</h3>
|
||||||
|
<p class="mm-event__meta">
|
||||||
|
<?php if ( $when ) : ?>
|
||||||
|
<span><i class="far fa-clock" aria-hidden="true"></i> <?php echo esc_html( $when ); ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ( $where ) : ?>
|
||||||
|
<span><i class="fas fa-map-marker-alt" aria-hidden="true"></i> <?php echo esc_html( $where ); ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</p>
|
||||||
|
<?php if ( $text ) : ?>
|
||||||
|
<p class="mm-event__text"><?php echo esc_html( $text ); ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ( $url && ! $past ) : ?>
|
||||||
|
<a class="mm-event__link" href="<?php echo esc_url( $url ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Mehr erfahren', 'minecraft-modern-theme' ); ?> <i class="fas fa-arrow-right" aria-hidden="true"></i></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
<?php
|
||||||
|
return ob_get_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Liste kommender Events als HTML; leer, wenn es keine gibt. */
|
||||||
|
function mm_events_render_upcoming( $count = 3 ) {
|
||||||
|
if ( ! post_type_exists( 'mm_event' ) ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$q = mm_events_query( true, max( 1, min( 20, (int) $count ) ) );
|
||||||
|
if ( ! $q->have_posts() ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$out = '<div class="mm-events">';
|
||||||
|
foreach ( $q->posts as $p ) {
|
||||||
|
$out .= mm_event_render_card( $p->ID );
|
||||||
|
}
|
||||||
|
return $out . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_events_shortcode( $atts ) {
|
||||||
|
$a = shortcode_atts( array( 'count' => 3 ), $atts, 'mm_events' );
|
||||||
|
$html = mm_events_render_upcoming( $a['count'] );
|
||||||
|
return $html ? $html : '<p class="mm-events-empty">' . esc_html__( 'Aktuell sind keine Events geplant.', 'minecraft-modern-theme' ) . '</p>';
|
||||||
|
}
|
||||||
|
add_shortcode( 'mm_events', 'mm_events_shortcode' );
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Startseiten-Sektionen: im Customizer ein- und ausschaltbare Bloecke
|
||||||
|
* zwischen Hero/Slider und dem Seiteninhalt.
|
||||||
|
*
|
||||||
|
* Alle Sektionen sind standardmaessig AUS – ein Theme-Update veraendert die
|
||||||
|
* bestehende Startseite also nicht von selbst.
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Anzahl der Feature-Kacheln. */
|
||||||
|
define( 'MM_HOME_FEATURE_COUNT', 4 );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Laesst nur Font-Awesome-Klassen zu (z. B. "fas fa-shield-alt").
|
||||||
|
*/
|
||||||
|
function mm_sanitize_icon_class( $value ) {
|
||||||
|
return trim( preg_replace( '/[^a-z0-9\- ]/', '', strtolower( (string) $value ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_home_sections_customizer( $wp_customize ) {
|
||||||
|
$wp_customize->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 '<section class="mm-home-section mm-home-section--' . esc_attr( $slug ) . '"><div class="container">';
|
||||||
|
if ( $title ) {
|
||||||
|
echo '<header class="mm-home-section__head"><h2 class="mm-home-section__title">' . esc_html( $title ) . '</h2>';
|
||||||
|
if ( $link_url && $link_text ) {
|
||||||
|
echo '<a class="mm-home-section__more" href="' . esc_url( $link_url ) . '">' . esc_html( $link_text ) . ' <i class="fas fa-arrow-right" aria-hidden="true"></i></a>';
|
||||||
|
}
|
||||||
|
echo '</header>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_home_section_close() {
|
||||||
|
echo '</div></section>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt alle eingeschalteten Sektionen aus. Aufruf in front-page.php.
|
||||||
|
*/
|
||||||
|
function mm_home_sections_render() {
|
||||||
|
|
||||||
|
// ── Server-Status ──
|
||||||
|
if ( get_theme_mod( 'mm_home_status', false ) ) {
|
||||||
|
$html = mm_server_status_render( array( 'layout' => 'bar' ) );
|
||||||
|
if ( $html ) {
|
||||||
|
mm_home_section_open( 'status' );
|
||||||
|
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput -- in mm_server_status_render() escaped.
|
||||||
|
mm_home_section_close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Features ──
|
||||||
|
if ( get_theme_mod( 'mm_home_features', false ) ) {
|
||||||
|
$tiles = array();
|
||||||
|
for ( $i = 1; $i <= MM_HOME_FEATURE_COUNT; $i++ ) {
|
||||||
|
$title = get_theme_mod( "mm_home_feature_{$i}_title", '' );
|
||||||
|
if ( '' === $title ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$tiles[] = array(
|
||||||
|
'icon' => get_theme_mod( "mm_home_feature_{$i}_icon", '' ),
|
||||||
|
'title' => $title,
|
||||||
|
'text' => get_theme_mod( "mm_home_feature_{$i}_text", '' ),
|
||||||
|
'url' => get_theme_mod( "mm_home_feature_{$i}_url", '' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( $tiles ) {
|
||||||
|
mm_home_section_open( 'features', get_theme_mod( 'mm_home_features_title', __( 'Das erwartet dich', 'minecraft-modern-theme' ) ) );
|
||||||
|
echo '<div class="mm-features mm-features--' . count( $tiles ) . '">';
|
||||||
|
foreach ( $tiles as $tile ) {
|
||||||
|
$tag = $tile['url'] ? 'a' : 'div';
|
||||||
|
echo '<' . $tag . ' class="mm-feature"' . ( $tile['url'] ? ' href="' . esc_url( $tile['url'] ) . '"' : '' ) . '>'; // phpcs:ignore WordPress.Security.EscapeOutput -- $tag ist fest "a" oder "div".
|
||||||
|
if ( $tile['icon'] ) {
|
||||||
|
echo '<span class="mm-feature__icon" aria-hidden="true"><i class="' . esc_attr( $tile['icon'] ) . '"></i></span>';
|
||||||
|
}
|
||||||
|
echo '<h3 class="mm-feature__title">' . esc_html( $tile['title'] ) . '</h3>';
|
||||||
|
if ( $tile['text'] ) {
|
||||||
|
echo '<p class="mm-feature__text">' . nl2br( esc_html( $tile['text'] ) ) . '</p>';
|
||||||
|
}
|
||||||
|
echo '</' . $tag . '>'; // phpcs:ignore WordPress.Security.EscapeOutput
|
||||||
|
}
|
||||||
|
echo '</div>';
|
||||||
|
mm_home_section_close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Events ──
|
||||||
|
if ( get_theme_mod( 'mm_home_events', false ) && function_exists( 'mm_events_render_upcoming' ) ) {
|
||||||
|
$html = mm_events_render_upcoming( get_theme_mod( 'mm_home_events_count', 3 ) );
|
||||||
|
if ( $html ) {
|
||||||
|
mm_home_section_open( 'events', __( 'Nächste Events', 'minecraft-modern-theme' ), get_post_type_archive_link( 'mm_event' ), __( 'Alle Events', 'minecraft-modern-theme' ) );
|
||||||
|
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput -- in mm_event_render_card() escaped.
|
||||||
|
mm_home_section_close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Changelog ──
|
||||||
|
if ( get_theme_mod( 'mm_home_changelog', false ) && mm_changelog_enabled() ) {
|
||||||
|
$html = mm_changelog_render_latest( get_theme_mod( 'mm_home_changelog_count', 3 ) );
|
||||||
|
if ( $html ) {
|
||||||
|
mm_home_section_open( 'changelog', __( 'Neueste Updates', 'minecraft-modern-theme' ), get_post_type_archive_link( 'mm_changelog' ), __( 'Alle Updates', 'minecraft-modern-theme' ) );
|
||||||
|
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput -- in mm_changelog_render_entry() escaped.
|
||||||
|
mm_home_section_close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Team ──
|
||||||
|
if ( get_theme_mod( 'mm_home_team', false ) && post_type_exists( 'team_member' ) ) {
|
||||||
|
$team = new WP_Query( array(
|
||||||
|
'post_type' => 'team_member',
|
||||||
|
'posts_per_page' => max( 1, min( 12, (int) get_theme_mod( 'mm_home_team_count', 4 ) ) ),
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'order' => 'ASC',
|
||||||
|
'no_found_rows' => true,
|
||||||
|
) );
|
||||||
|
if ( $team->have_posts() ) {
|
||||||
|
mm_home_section_open( 'team', __( 'Unser Team', 'minecraft-modern-theme' ), get_post_type_archive_link( 'team_member' ), __( 'Ganzes Team', 'minecraft-modern-theme' ) );
|
||||||
|
echo '<div class="mm-home-team">';
|
||||||
|
while ( $team->have_posts() ) {
|
||||||
|
$team->the_post();
|
||||||
|
$uuid = get_post_meta( get_the_ID(), '_team_member_uuid', true );
|
||||||
|
$avatar = $uuid ? mm_proxy_url( 'bust', $uuid ) : '';
|
||||||
|
if ( ! $avatar ) {
|
||||||
|
$avatar = get_the_post_thumbnail_url( get_the_ID(), 'thumbnail' );
|
||||||
|
}
|
||||||
|
$ranks = array_filter( array_map( 'trim', explode( ',', (string) get_post_meta( get_the_ID(), '_team_member_rank', true ) ) ) );
|
||||||
|
echo '<div class="mm-home-team__member">';
|
||||||
|
if ( $avatar ) {
|
||||||
|
echo '<img class="mm-home-team__avatar" src="' . esc_url( $avatar ) . '" alt="" width="96" height="96" loading="lazy" decoding="async">';
|
||||||
|
} else {
|
||||||
|
echo '<span class="mm-home-team__avatar mm-home-team__avatar--placeholder" aria-hidden="true">' . esc_html( mb_strtoupper( mb_substr( get_the_title(), 0, 1 ) ) ) . '</span>';
|
||||||
|
}
|
||||||
|
echo '<span class="mm-home-team__name">' . esc_html( get_the_title() ) . '</span>';
|
||||||
|
if ( $ranks ) {
|
||||||
|
echo '<span class="mm-home-team__rank">' . esc_html( reset( $ranks ) ) . '</span>';
|
||||||
|
}
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
echo '</div>';
|
||||||
|
wp_reset_postdata();
|
||||||
|
mm_home_section_close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Community ──
|
||||||
|
$discord = get_theme_mod( 'mm_home_discord', false ) ? mm_discord_render() : '';
|
||||||
|
$vote = get_theme_mod( 'mm_home_vote', false ) ? mm_vote_render() : '';
|
||||||
|
if ( $discord || $vote ) {
|
||||||
|
mm_home_section_open( 'community', __( 'Community', 'minecraft-modern-theme' ) );
|
||||||
|
echo '<div class="mm-home-community' . ( $discord && $vote ? ' mm-home-community--two' : '' ) . '">';
|
||||||
|
if ( $discord ) {
|
||||||
|
echo '<div class="mm-home-community__col">' . $discord . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput -- in mm_discord_render() escaped.
|
||||||
|
}
|
||||||
|
if ( $vote ) {
|
||||||
|
echo '<div class="mm-home-community__col"><h3 class="mm-home-community__title">' . esc_html__( 'Für uns voten', 'minecraft-modern-theme' ) . '</h3>' . $vote . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput -- in mm_vote_render() escaped.
|
||||||
|
}
|
||||||
|
echo '</div>';
|
||||||
|
mm_home_section_close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,6 +49,52 @@ function set_static_front_page_automatically() {
|
|||||||
add_action( 'after_switch_theme', 'set_static_front_page_automatically' );
|
add_action( 'after_switch_theme', 'set_static_front_page_automatically' );
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt das <img> für einen Slide aus.
|
||||||
|
*
|
||||||
|
* Liegt das Bild in der Mediathek, liefert WordPress srcset und sizes;
|
||||||
|
* andernfalls (externe URL) wird ein einfaches <img> erzeugt.
|
||||||
|
*
|
||||||
|
* @param string $url Bild-URL aus dem Customizer.
|
||||||
|
* @param string $alt Alternativtext (Slide-Titel).
|
||||||
|
* @param bool $is_first Erstes Bild: sofort und mit hoher Priorität laden.
|
||||||
|
* @return string Escaptes HTML.
|
||||||
|
*/
|
||||||
|
function mm_slider_image( $url, $alt = '', $is_first = false ) {
|
||||||
|
$attr = array(
|
||||||
|
'class' => 'slider-bg',
|
||||||
|
'alt' => (string) $alt,
|
||||||
|
'sizes' => '100vw',
|
||||||
|
'loading' => $is_first ? 'eager' : 'lazy',
|
||||||
|
'decoding' => $is_first ? 'sync' : 'async',
|
||||||
|
'fetchpriority' => $is_first ? 'high' : 'low',
|
||||||
|
);
|
||||||
|
|
||||||
|
// attachment_url_to_postid() durchsucht die komplette Meta-Tabelle und ist
|
||||||
|
// auf grossen Seiten langsam – das Ergebnis deshalb eine Woche merken
|
||||||
|
// (0 = kein Mediathek-Bild). Der Schluessel haengt an der URL, ein neues
|
||||||
|
// Bild im Customizer wird also sofort neu nachgeschlagen.
|
||||||
|
$cache_key = 'mm_slide_id_' . md5( $url );
|
||||||
|
$attachment_id = get_transient( $cache_key );
|
||||||
|
if ( false === $attachment_id ) {
|
||||||
|
$attachment_id = (int) attachment_url_to_postid( $url );
|
||||||
|
set_transient( $cache_key, $attachment_id, WEEK_IN_SECONDS );
|
||||||
|
}
|
||||||
|
$attachment_id = (int) $attachment_id;
|
||||||
|
if ( $attachment_id ) {
|
||||||
|
$html = wp_get_attachment_image( $attachment_id, 'full', false, $attr );
|
||||||
|
if ( $html ) {
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$html = '<img src="' . esc_url( $url ) . '"';
|
||||||
|
foreach ( $attr as $name => $value ) {
|
||||||
|
$html .= ' ' . $name . '="' . esc_attr( $value ) . '"';
|
||||||
|
}
|
||||||
|
return $html . '>';
|
||||||
|
}
|
||||||
|
|
||||||
function add_home_body_class( $classes ) {
|
function add_home_body_class( $classes ) {
|
||||||
if ( is_front_page() && ! get_theme_mod( 'show_home_title', true ) ) {
|
if ( is_front_page() && ! get_theme_mod( 'show_home_title', true ) ) {
|
||||||
$classes[] = 'home-title-hidden';
|
$classes[] = 'home-title-hidden';
|
||||||
|
|||||||
@@ -48,8 +48,9 @@ function mm_nav( $extra_class = '' ) {
|
|||||||
// Im Sidebar-Layout sitzt die Navigation im <aside> Panel –
|
// Im Sidebar-Layout sitzt die Navigation im <aside> Panel –
|
||||||
// der Hamburger wird dort nicht gebraucht und verursacht JS-Konflikte.
|
// der Hamburger wird dort nicht gebraucht und verursacht JS-Konflikte.
|
||||||
if ( $menu_style !== 'sidebar' ) : ?>
|
if ( $menu_style !== 'sidebar' ) : ?>
|
||||||
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
|
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"
|
||||||
<i class="fas fa-bars"></i>
|
aria-label="<?php esc_attr_e( 'Menü öffnen', 'minecraft-modern-theme' ); ?>">
|
||||||
|
<i class="fas fa-bars" aria-hidden="true"></i>
|
||||||
</button>
|
</button>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php wp_nav_menu( array(
|
<?php wp_nav_menu( array(
|
||||||
@@ -78,7 +79,7 @@ function mm_icons() {
|
|||||||
<div class="header-info">
|
<div class="header-info">
|
||||||
<div class="header-search">
|
<div class="header-search">
|
||||||
<button class="header-search-toggle" aria-label="<?php esc_attr_e('Suche öffnen', 'minecraft-modern-theme'); ?>" aria-expanded="false">
|
<button class="header-search-toggle" aria-label="<?php esc_attr_e('Suche öffnen', 'minecraft-modern-theme'); ?>" aria-expanded="false">
|
||||||
<i class="fas fa-search"></i>
|
<i class="fas fa-search" aria-hidden="true"></i>
|
||||||
</button>
|
</button>
|
||||||
<div class="header-search-dropdown" aria-hidden="true">
|
<div class="header-search-dropdown" aria-hidden="true">
|
||||||
<?php get_search_form(); ?>
|
<?php get_search_form(); ?>
|
||||||
@@ -87,7 +88,7 @@ function mm_icons() {
|
|||||||
<div class="social-links">
|
<div class="social-links">
|
||||||
<?php foreach ( $social_icons as $key => $class ) :
|
<?php foreach ( $social_icons as $key => $class ) :
|
||||||
$url = get_theme_mod( 'social_' . $key );
|
$url = get_theme_mod( 'social_' . $key );
|
||||||
if ( $url ) echo '<a href="' . esc_url($url) . '" target="_blank" rel="noopener noreferrer" aria-label="' . esc_attr($key) . '"><i class="' . esc_attr($class) . '"></i></a>';
|
if ( $url ) echo '<a href="' . esc_url($url) . '" target="_blank" rel="noopener noreferrer" aria-label="' . esc_attr( ucfirst( $key ) ) . '"><i class="' . esc_attr($class) . '" aria-hidden="true"></i></a>';
|
||||||
endforeach; ?>
|
endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ function add_minecraft_avatar_slider_to_login() {
|
|||||||
$uuid = get_theme_mod( 'login_avatar_uuid_' . $i );
|
$uuid = get_theme_mod( 'login_avatar_uuid_' . $i );
|
||||||
if ( ! empty( $uuid ) ) {
|
if ( ! empty( $uuid ) ) {
|
||||||
$has_avatars = true;
|
$has_avatars = true;
|
||||||
$avatar_url = 'https://visage.surgeplay.com/full/' . $uuid . '.png';
|
$avatar_url = mm_proxy_url( 'full', $uuid );
|
||||||
// FIX: Klasse wird hier gesetzt, JS überschreibt sie trotzdem (kompatibel)
|
// FIX: Klasse wird hier gesetzt, JS überschreibt sie trotzdem (kompatibel)
|
||||||
$active_class = ( $i === 1 ) ? 'avatar-slide avatar-slide-active' : 'avatar-slide';
|
$active_class = ( $i === 1 ) ? 'avatar-slide avatar-slide-active' : 'avatar-slide';
|
||||||
$avatar_html .= '<img class="' . esc_attr( $active_class ) . '" src="' . esc_url( $avatar_url ) . '" alt="Minecraft Avatar ' . $i . '">';
|
$avatar_html .= '<img class="' . esc_attr( $active_class ) . '" src="' . esc_url( $avatar_url ) . '" alt="Minecraft Avatar ' . $i . '">';
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Regelwerk und Changelog im Menü-Editor auswählbar machen.
|
||||||
|
*
|
||||||
|
* WordPress bietet für Archivseiten eigener Inhaltstypen keine Auswahlbox an.
|
||||||
|
* Dieses Modul ergänzt unter Design → Menüs die Box "Regeln & Changelog"
|
||||||
|
* mit Häkchen. Die Einträge sind vom Typ "post_type_archive": Die Adresse wird
|
||||||
|
* bei jedem Aufruf aus dem aktuellen Slug erzeugt und der Menüpunkt
|
||||||
|
* bekommt automatisch die Klasse für die aktive Seite.
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Archivseiten, die in der Box angeboten werden (Inhaltstyp => Beschriftung).
|
||||||
|
* Nur Typen, die registriert sind und ein Archiv haben, und nur solche,
|
||||||
|
* die im Customizer nicht abgeschaltet wurden.
|
||||||
|
*/
|
||||||
|
function mm_nav_archives_list() {
|
||||||
|
$wanted = array(
|
||||||
|
'mm_rule' => __( 'Regeln', 'minecraft-modern-theme' ),
|
||||||
|
'mm_changelog' => __( 'Changelog', 'minecraft-modern-theme' ),
|
||||||
|
'mm_event' => __( 'Events', 'minecraft-modern-theme' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$out = array();
|
||||||
|
foreach ( $wanted as $post_type => $label ) {
|
||||||
|
$url = get_post_type_archive_link( $post_type );
|
||||||
|
if ( $url ) {
|
||||||
|
$out[ $post_type ] = array( 'label' => $label, 'url' => $url );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Box im Menü-Editor registrieren. */
|
||||||
|
function mm_nav_archives_register_box() {
|
||||||
|
add_meta_box(
|
||||||
|
'mm-nav-archives',
|
||||||
|
__( 'Regeln & Changelog', 'minecraft-modern-theme' ),
|
||||||
|
'mm_nav_archives_box',
|
||||||
|
'nav-menus',
|
||||||
|
'side',
|
||||||
|
'default'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action( 'admin_head-nav-menus.php', 'mm_nav_archives_register_box' );
|
||||||
|
|
||||||
|
/** Inhalt der Box: Häkchenliste im Stil der Seiten-Box. */
|
||||||
|
function mm_nav_archives_box() {
|
||||||
|
$archives = mm_nav_archives_list();
|
||||||
|
|
||||||
|
if ( empty( $archives ) || ! class_exists( 'Walker_Nav_Menu_Checklist' ) ) {
|
||||||
|
echo '<p>' . esc_html__( 'Keine Archivseiten verfügbar. Prüfe unter Design → Customizer → Module, ob Regelwerk und Changelog aktiviert sind.', 'minecraft-modern-theme' ) . '</p>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = array();
|
||||||
|
$i = 0;
|
||||||
|
foreach ( $archives as $post_type => $a ) {
|
||||||
|
$i--;
|
||||||
|
$items[] = (object) array(
|
||||||
|
'ID' => $i,
|
||||||
|
'db_id' => 0,
|
||||||
|
'object_id' => $i,
|
||||||
|
'object' => $post_type,
|
||||||
|
'menu_item_parent' => 0,
|
||||||
|
'type' => 'post_type_archive',
|
||||||
|
'type_label' => __( 'Archiv', 'minecraft-modern-theme' ),
|
||||||
|
'title' => $a['label'],
|
||||||
|
'url' => $a['url'],
|
||||||
|
'target' => '',
|
||||||
|
'attr_title' => '',
|
||||||
|
'description' => '',
|
||||||
|
'classes' => array(),
|
||||||
|
'xfn' => '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div id="posttype-mm-archives" class="posttypediv">
|
||||||
|
<div id="tabs-panel-mm-archives" class="tabs-panel tabs-panel-active" role="region" aria-label="<?php esc_attr_e( 'Regeln & Changelog', 'minecraft-modern-theme' ); ?>" tabindex="0">
|
||||||
|
<ul id="mm-archives-checklist" class="categorychecklist form-no-clear">
|
||||||
|
<?php
|
||||||
|
echo walk_nav_menu_tree( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Kern-Walker escaped selbst.
|
||||||
|
$items,
|
||||||
|
0,
|
||||||
|
(object) array( 'walker' => new Walker_Nav_Menu_Checklist() )
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<p class="button-controls wp-clearfix" data-items-type="posttype-mm-archives">
|
||||||
|
<span class="list-controls hide-if-no-js">
|
||||||
|
<input type="checkbox" id="mm-archives-select-all" class="select-all">
|
||||||
|
<label for="mm-archives-select-all"><?php esc_html_e( 'Alle auswählen', 'minecraft-modern-theme' ); ?></label>
|
||||||
|
</span>
|
||||||
|
<span class="add-to-menu">
|
||||||
|
<input type="submit" class="button submit-add-to-menu right"
|
||||||
|
value="<?php esc_attr_e( 'Zum Menü hinzufügen', 'minecraft-modern-theme' ); ?>"
|
||||||
|
name="add-post-type-menu-item" id="submit-posttype-mm-archives">
|
||||||
|
<span class="spinner"></span>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Datenschutz: Bilder von Drittanbietern lokal zwischenspeichern.
|
||||||
|
*
|
||||||
|
* Skin-Köpfe (mc-heads.net, visage.surgeplay.com, minotar.net) und
|
||||||
|
* YouTube-Vorschaubilder (img.youtube.com) wurden bisher direkt im Browser
|
||||||
|
* des Besuchers geladen. Dabei wäre dessen IP-Adresse ohne Einwilligung an
|
||||||
|
* diese Dienste übertragen worden. Jetzt holt der Server das Bild einmal ab,
|
||||||
|
* legt es unter wp-content/uploads/mm-proxy/ ab und liefert es von der
|
||||||
|
* eigenen Domain aus. Die Besucher sprechen nie mehr mit dem Drittanbieter.
|
||||||
|
*
|
||||||
|
* Ablauf: mm_proxy_url() gibt die Adresse der gespeicherten Datei zurück,
|
||||||
|
* wenn sie schon existiert. Sonst zeigt sie auf den Endpunkt
|
||||||
|
* admin-ajax.php?action=mm_proxy, der das Bild holt, speichert und ausliefert.
|
||||||
|
*
|
||||||
|
* Außerdem: Gravatar (WordPress-Standard für Autoren- und Kommentarbilder)
|
||||||
|
* wird abgeschaltet, solange es im Customizer nicht ausdrücklich erlaubt ist.
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wie lange eine gespeicherte Datei als frisch gilt. */
|
||||||
|
define( 'MM_PROXY_TTL', 7 * DAY_IN_SECONDS );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erlaubte Quellen. Nur diese Vorlagen werden jemals abgerufen.
|
||||||
|
*
|
||||||
|
* id: Muster für die Kennung (Spielername, UUID oder Video-ID)
|
||||||
|
* size: true, wenn die Vorlage eine Pixelgröße enthält
|
||||||
|
*/
|
||||||
|
function mm_proxy_kinds() {
|
||||||
|
$player = '/^(?:[A-Za-z0-9_]{1,16}|[0-9a-fA-F]{32}|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/';
|
||||||
|
return array(
|
||||||
|
'head' => array( 'url' => 'https://mc-heads.net/avatar/{id}/{size}', 'id' => $player, 'size' => true ),
|
||||||
|
'body' => array( 'url' => 'https://mc-heads.net/body/{id}/{size}', 'id' => $player, 'size' => true ),
|
||||||
|
'minotar' => array( 'url' => 'https://minotar.net/avatar/{id}/{size}', 'id' => $player, 'size' => true ),
|
||||||
|
'bust' => array( 'url' => 'https://visage.surgeplay.com/bust/{id}.png', 'id' => $player, 'size' => false ),
|
||||||
|
'full' => array( 'url' => 'https://visage.surgeplay.com/full/{id}.png', 'id' => $player, 'size' => false ),
|
||||||
|
'vhead' => array( 'url' => 'https://visage.surgeplay.com/head/{size}/{id}', 'id' => $player, 'size' => true ),
|
||||||
|
'ytthumb' => array( 'url' => 'https://img.youtube.com/vi/{id}/maxresdefault.jpg', 'id' => '/^[A-Za-z0-9_-]{11}$/', 'size' => false ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ordner für die gespeicherten Bilder. */
|
||||||
|
function mm_proxy_dir() {
|
||||||
|
$up = wp_upload_dir( null, false );
|
||||||
|
return array(
|
||||||
|
'path' => trailingslashit( $up['basedir'] ) . 'mm-proxy/',
|
||||||
|
'url' => trailingslashit( $up['baseurl'] ) . 'mm-proxy/',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pixelgröße auf einen sinnvollen Bereich begrenzen. */
|
||||||
|
function mm_proxy_size( $size ) {
|
||||||
|
$size = (int) $size;
|
||||||
|
return max( 8, min( 512, $size ?: 64 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Dateiname im Cache oder '' bei ungültiger Eingabe. */
|
||||||
|
function mm_proxy_filename( $kind, $id, $size ) {
|
||||||
|
$kinds = mm_proxy_kinds();
|
||||||
|
if ( ! isset( $kinds[ $kind ] ) || ! preg_match( $kinds[ $kind ]['id'], (string) $id ) ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
// Spielernamen sind nicht groß-/kleinschreibungsabhängig, YouTube-IDs schon.
|
||||||
|
$id = $kind === 'ytthumb' ? (string) $id : strtolower( str_replace( '-', '', (string) $id ) );
|
||||||
|
$name = $kind . '-' . $id;
|
||||||
|
if ( $kinds[ $kind ]['size'] ) {
|
||||||
|
$name .= '-' . mm_proxy_size( $size );
|
||||||
|
}
|
||||||
|
// Namen enthalten nur [a-z0-9_-] - so ist ein Ausbruch aus dem Ordner ausgeschlossen.
|
||||||
|
return preg_replace( '/[^a-z0-9_-]/', '', $name ) . '.img';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adresse des Bildes auf der eigenen Domain.
|
||||||
|
*
|
||||||
|
* @param string $kind Quelle, siehe mm_proxy_kinds().
|
||||||
|
* @param string $id Spielername, UUID oder YouTube-ID.
|
||||||
|
* @param int $size Pixelgröße (nur bei Quellen mit Größe).
|
||||||
|
* @return string Leer, wenn die Eingabe ungültig ist.
|
||||||
|
*/
|
||||||
|
function mm_proxy_url( $kind, $id, $size = 64 ) {
|
||||||
|
$id = trim( (string) $id );
|
||||||
|
$file = mm_proxy_filename( $kind, $id, $size );
|
||||||
|
if ( $file === '' ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$dir = mm_proxy_dir();
|
||||||
|
$path = $dir['path'] . $file;
|
||||||
|
// Frische Datei vorhanden: direkt ausliefern, ohne PHP.
|
||||||
|
if ( is_file( $path ) && ( time() - filemtime( $path ) ) < MM_PROXY_TTL ) {
|
||||||
|
return $dir['url'] . $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
return add_query_arg(
|
||||||
|
array( 'action' => 'mm_proxy', 'k' => $kind, 'i' => $id, 's' => mm_proxy_size( $size ) ),
|
||||||
|
admin_url( 'admin-ajax.php' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Basisadresse des Endpunkts für Skripte, die Namen erst im Browser zusammensetzen. */
|
||||||
|
function mm_proxy_endpoint() {
|
||||||
|
return admin_url( 'admin-ajax.php?action=mm_proxy' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bild holen, speichern, ausliefern. */
|
||||||
|
function mm_proxy_serve() {
|
||||||
|
$kind = isset( $_GET['k'] ) ? sanitize_key( wp_unslash( $_GET['k'] ) ) : '';
|
||||||
|
$id = isset( $_GET['i'] ) ? sanitize_text_field( wp_unslash( $_GET['i'] ) ) : '';
|
||||||
|
$size = isset( $_GET['s'] ) ? (int) $_GET['s'] : 64;
|
||||||
|
|
||||||
|
$file = mm_proxy_filename( $kind, $id, $size );
|
||||||
|
$kinds = mm_proxy_kinds();
|
||||||
|
if ( $file === '' ) {
|
||||||
|
status_header( 400 );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dir = mm_proxy_dir();
|
||||||
|
$path = $dir['path'] . $file;
|
||||||
|
$fresh = is_file( $path ) && ( time() - filemtime( $path ) ) < MM_PROXY_TTL;
|
||||||
|
|
||||||
|
if ( ! $fresh ) {
|
||||||
|
$miss_key = 'mm_proxy_miss_' . md5( $file );
|
||||||
|
|
||||||
|
// Nach einem Fehlschlag 10 Minuten nicht erneut versuchen.
|
||||||
|
if ( get_transient( $miss_key ) ) {
|
||||||
|
$fresh = false;
|
||||||
|
} elseif ( ! mm_rate_limit( 'proxy', 40, MINUTE_IN_SECONDS ) ) {
|
||||||
|
status_header( 429 );
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$templates = array( $kinds[ $kind ]['url'] );
|
||||||
|
if ( $kind === 'ytthumb' ) {
|
||||||
|
// Nicht jedes Video hat die höchste Auflösung.
|
||||||
|
$templates[] = 'https://img.youtube.com/vi/{id}/hqdefault.jpg';
|
||||||
|
}
|
||||||
|
$ok = false;
|
||||||
|
|
||||||
|
foreach ( $templates as $tpl ) {
|
||||||
|
$url = str_replace(
|
||||||
|
array( '{id}', '{size}' ),
|
||||||
|
array( rawurlencode( $id ), mm_proxy_size( $size ) ),
|
||||||
|
$tpl
|
||||||
|
);
|
||||||
|
$res = wp_remote_get( $url, array( 'timeout' => 5, 'redirection' => 2, 'limit_response_size' => 2 * MB_IN_BYTES ) );
|
||||||
|
|
||||||
|
if ( is_wp_error( $res ) || (int) wp_remote_retrieve_response_code( $res ) !== 200 ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$body = wp_remote_retrieve_body( $res );
|
||||||
|
// Nur echte Bilder annehmen.
|
||||||
|
if ( $body !== '' && strlen( $body ) <= 2 * MB_IN_BYTES && @getimagesizefromstring( $body ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors
|
||||||
|
if ( wp_mkdir_p( $dir['path'] ) ) {
|
||||||
|
if ( ! is_file( $dir['path'] . 'index.html' ) ) {
|
||||||
|
file_put_contents( $dir['path'] . 'index.html', '' );
|
||||||
|
}
|
||||||
|
$ok = false !== file_put_contents( $path, $body, LOCK_EX );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! $ok ) {
|
||||||
|
set_transient( $miss_key, 1, 10 * MINUTE_IN_SECONDS );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auch eine veraltete Datei ist besser als gar kein Bild.
|
||||||
|
if ( ! is_file( $path ) ) {
|
||||||
|
status_header( 404 );
|
||||||
|
header( 'Cache-Control: public, max-age=300' );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$info = @getimagesize( $path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors
|
||||||
|
header( 'Content-Type: ' . ( $info && ! empty( $info['mime'] ) ? $info['mime'] : 'image/png' ) );
|
||||||
|
header( 'Content-Length: ' . filesize( $path ) );
|
||||||
|
header( 'Cache-Control: public, max-age=86400' );
|
||||||
|
header( 'X-Content-Type-Options: nosniff' );
|
||||||
|
readfile( $path );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
add_action( 'wp_ajax_mm_proxy', 'mm_proxy_serve' );
|
||||||
|
add_action( 'wp_ajax_nopriv_mm_proxy', 'mm_proxy_serve' );
|
||||||
|
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// Gravatar abschalten
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
/** Customizer-Schalter. */
|
||||||
|
function mm_privacy_customizer( $wp_customize ) {
|
||||||
|
$wp_customize->add_setting( 'mm_gravatar_enabled', array(
|
||||||
|
'default' => false,
|
||||||
|
'sanitize_callback' => 'wp_validate_boolean',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_gravatar_enabled', array(
|
||||||
|
'label' => __( 'Gravatar erlauben', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Aus: Autoren- und Kommentarbilder werden lokal erzeugt, es wird nichts an gravatar.com übertragen (empfohlen). An: Besucher-IP und E-Mail-Prüfsumme gehen an Gravatar - das muss in der Datenschutzerklärung stehen.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_cookie_banner_section',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
add_action( 'customize_register', 'mm_privacy_customizer', 20 );
|
||||||
|
|
||||||
|
/** Neutrales Platzhalterbild aus dem Theme. */
|
||||||
|
function mm_privacy_default_avatar() {
|
||||||
|
return get_template_directory_uri() . '/images/default-avatar.svg';
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_privacy_avatar_data( $args ) {
|
||||||
|
if ( get_theme_mod( 'mm_gravatar_enabled', false ) ) {
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
$args['url'] = mm_privacy_default_avatar();
|
||||||
|
$args['found_avatar'] = true;
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
add_filter( 'pre_get_avatar_data', 'mm_privacy_avatar_data', 20 );
|
||||||
@@ -0,0 +1,203 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Regelwerk: Reihenfolge per Drag & Drop festlegen.
|
||||||
|
*
|
||||||
|
* Backend-Seite "Regelwerk → Reihenfolge". Dort lassen sich sowohl die
|
||||||
|
* Kategorien (= Paragraphen §1, §2 …) als auch die Regeln innerhalb einer
|
||||||
|
* Kategorie mit der Maus sortieren.
|
||||||
|
*
|
||||||
|
* Gespeichert wird:
|
||||||
|
* - Kategorien: Term-Meta "mm_order"
|
||||||
|
* - Regeln: das WordPress-Feld "Reihenfolge" (menu_order)
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sortiert Regel-Kategorien nach der gespeicherten Reihenfolge.
|
||||||
|
* Kategorien ohne Wert (neu angelegt) landen alphabetisch am Ende.
|
||||||
|
*
|
||||||
|
* @param WP_Term[] $terms
|
||||||
|
* @return WP_Term[]
|
||||||
|
*/
|
||||||
|
function mm_rules_sort_terms( $terms ) {
|
||||||
|
$order = array();
|
||||||
|
foreach ( $terms as $term ) {
|
||||||
|
$value = get_term_meta( $term->term_id, 'mm_order', true );
|
||||||
|
$order[ $term->term_id ] = '' === $value ? PHP_INT_MAX : (int) $value;
|
||||||
|
}
|
||||||
|
usort( $terms, function ( $a, $b ) use ( $order ) {
|
||||||
|
if ( $order[ $a->term_id ] !== $order[ $b->term_id ] ) {
|
||||||
|
return $order[ $a->term_id ] <=> $order[ $b->term_id ];
|
||||||
|
}
|
||||||
|
return strcasecmp( $a->name, $b->name );
|
||||||
|
} );
|
||||||
|
return $terms;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_rules_order_menu() {
|
||||||
|
if ( ! mm_rules_enabled() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
add_submenu_page(
|
||||||
|
'edit.php?post_type=mm_rule',
|
||||||
|
__( 'Reihenfolge des Regelwerks', 'minecraft-modern-theme' ),
|
||||||
|
__( 'Reihenfolge', 'minecraft-modern-theme' ),
|
||||||
|
'edit_others_posts',
|
||||||
|
'mm-rules-order',
|
||||||
|
'mm_rules_order_page'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action( 'admin_menu', 'mm_rules_order_menu' );
|
||||||
|
|
||||||
|
function mm_rules_order_assets( $hook ) {
|
||||||
|
if ( 'mm_rule_page_mm-rules-order' !== $hook ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$dir = get_template_directory();
|
||||||
|
$uri = get_template_directory_uri();
|
||||||
|
wp_enqueue_style( 'mm-rules-order', $uri . '/css/rules-order-admin.css', array(), filemtime( $dir . '/css/rules-order-admin.css' ) );
|
||||||
|
// jQuery UI Sortable liefert WordPress selbst mit.
|
||||||
|
wp_enqueue_script( 'mm-rules-order', $uri . '/js/rules-order-admin.js', array( 'jquery', 'jquery-ui-sortable' ), filemtime( $dir . '/js/rules-order-admin.js' ), true );
|
||||||
|
wp_localize_script( 'mm-rules-order', 'mmRulesOrder', array(
|
||||||
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
||||||
|
'nonce' => wp_create_nonce( 'mm_rules_order' ),
|
||||||
|
'i18n' => array(
|
||||||
|
'saving' => __( 'Speichert …', 'minecraft-modern-theme' ),
|
||||||
|
'saved' => __( 'Reihenfolge gespeichert.', 'minecraft-modern-theme' ),
|
||||||
|
'error' => __( 'Speichern fehlgeschlagen. Bitte Seite neu laden und erneut versuchen.', 'minecraft-modern-theme' ),
|
||||||
|
'dirty' => __( 'Ungespeicherte Änderungen', 'minecraft-modern-theme' ),
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
add_action( 'admin_enqueue_scripts', 'mm_rules_order_assets' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hinweis auf allen Regelwerk-Seiten im Backend, solange die Website die
|
||||||
|
* Regeln aus dem Plugin liest – sonst pflegt man hier Regeln, die niemand sieht.
|
||||||
|
*/
|
||||||
|
function mm_rules_plugin_source_notice() {
|
||||||
|
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
|
||||||
|
if ( ! $screen || 'mm_rule' !== $screen->post_type || ! mm_rules_enabled() || ! mm_rules_uses_plugin() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo '<div class="notice notice-warning"><p>'
|
||||||
|
. esc_html__( 'Die Seite /regelwerk zeigt aktuell die Regeln aus dem Plugin „Multi Rules“. Die Regeln hier im Theme (und ihre Reihenfolge) werden nicht angezeigt. Umstellen: Customizer → Module → Quelle der Regeln.', 'minecraft-modern-theme' )
|
||||||
|
. '</p></div>';
|
||||||
|
}
|
||||||
|
add_action( 'admin_notices', 'mm_rules_plugin_source_notice' );
|
||||||
|
|
||||||
|
function mm_rules_order_page() {
|
||||||
|
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$groups = mm_rules_get_groups( true );
|
||||||
|
?>
|
||||||
|
<div class="wrap mm-rules-order">
|
||||||
|
<h1><?php esc_html_e( 'Reihenfolge des Regelwerks', 'minecraft-modern-theme' ); ?></h1>
|
||||||
|
<p class="description">
|
||||||
|
<?php esc_html_e( 'Kategorien und Regeln mit der Maus am Griff verschieben, dann speichern. Die Nummern (§1, §1.1 …) ergeben sich aus der Reihenfolge.', 'minecraft-modern-theme' ); ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<?php if ( empty( $groups ) ) : ?>
|
||||||
|
<p><?php esc_html_e( 'Es gibt noch keine Regeln.', 'minecraft-modern-theme' ); ?></p>
|
||||||
|
<?php else : ?>
|
||||||
|
|
||||||
|
<div class="mm-rules-order__bar">
|
||||||
|
<button type="button" class="button button-primary" id="mm-rules-order-save"><?php esc_html_e( 'Reihenfolge speichern', 'minecraft-modern-theme' ); ?></button>
|
||||||
|
<span class="mm-rules-order__status" id="mm-rules-order-status" role="status" aria-live="polite"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="mm-rules-order__groups" id="mm-rules-order-groups">
|
||||||
|
<?php foreach ( $groups as $group ) :
|
||||||
|
$fixed = empty( $group['term_id'] ); // "Allgemein" (ohne Kategorie) steht immer oben.
|
||||||
|
?>
|
||||||
|
<li class="mm-rules-order__group<?php echo $fixed ? ' is-fixed' : ''; ?>" data-term="<?php echo (int) $group['term_id']; ?>">
|
||||||
|
<div class="mm-rules-order__group-head">
|
||||||
|
<?php if ( ! $fixed ) : ?>
|
||||||
|
<span class="mm-rules-order__handle dashicons dashicons-menu" aria-hidden="true"></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
<strong class="mm-rules-order__no"></strong>
|
||||||
|
<span class="mm-rules-order__name"><?php echo esc_html( $group['name'] ); ?></span>
|
||||||
|
<?php if ( $fixed ) : ?>
|
||||||
|
<em><?php esc_html_e( '(Regeln ohne Kategorie – immer zuerst)', 'minecraft-modern-theme' ); ?></em>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<ul class="mm-rules-order__rules">
|
||||||
|
<?php foreach ( $group['rules'] as $rule ) : ?>
|
||||||
|
<li class="mm-rules-order__rule" data-id="<?php echo (int) $rule->ID; ?>">
|
||||||
|
<span class="mm-rules-order__handle dashicons dashicons-menu" aria-hidden="true"></span>
|
||||||
|
<span class="mm-rules-order__no"></span>
|
||||||
|
<span class="mm-rules-order__name"><?php echo esc_html( get_the_title( $rule ) ); ?></span>
|
||||||
|
<?php if ( 'publish' !== $rule->post_status ) : ?>
|
||||||
|
<em>(<?php echo esc_html( get_post_status_object( $rule->post_status )->label ?? $rule->post_status ); ?>)</em>
|
||||||
|
<?php endif; ?>
|
||||||
|
<a class="mm-rules-order__edit" href="<?php echo esc_url( get_edit_post_link( $rule->ID ) ); ?>"><?php esc_html_e( 'Bearbeiten', 'minecraft-modern-theme' ); ?></a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AJAX: Reihenfolge speichern.
|
||||||
|
*
|
||||||
|
* Erwartet "terms" (Kategorie-IDs in Anzeige-Reihenfolge) und "rules"
|
||||||
|
* (Regel-IDs in Anzeige-Reihenfolge ueber alle Kategorien hinweg).
|
||||||
|
*/
|
||||||
|
function mm_rules_order_save() {
|
||||||
|
check_ajax_referer( 'mm_rules_order', 'nonce' );
|
||||||
|
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
||||||
|
wp_send_json_error( null, 403 );
|
||||||
|
}
|
||||||
|
|
||||||
|
$terms = isset( $_POST['terms'] ) ? array_map( 'absint', (array) wp_unslash( $_POST['terms'] ) ) : array();
|
||||||
|
$rules = isset( $_POST['rules'] ) ? array_map( 'absint', (array) wp_unslash( $_POST['rules'] ) ) : array();
|
||||||
|
|
||||||
|
$position = 0;
|
||||||
|
foreach ( array_filter( $terms ) as $term_id ) {
|
||||||
|
if ( term_exists( $term_id, 'mm_rule_category' ) ) {
|
||||||
|
update_term_meta( $term_id, 'mm_order', ++$position );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eine Regel in mehreren Kategorien kommt mehrfach vor – die erste Position zaehlt.
|
||||||
|
$position = 0;
|
||||||
|
foreach ( array_unique( array_filter( $rules ) ) as $post_id ) {
|
||||||
|
if ( 'mm_rule' !== get_post_type( $post_id ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$position++;
|
||||||
|
if ( (int) get_post_field( 'menu_order', $post_id ) !== $position ) {
|
||||||
|
// Direkt in der Tabelle, damit kein neuer Revisionsstand und kein
|
||||||
|
// geaendertes "Stand:"-Datum entsteht – der Inhalt bleibt ja gleich.
|
||||||
|
global $wpdb;
|
||||||
|
$wpdb->update( $wpdb->posts, array( 'menu_order' => $position ), array( 'ID' => $post_id ), array( '%d' ), array( '%d' ) );
|
||||||
|
clean_post_cache( $post_id );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_send_json_success();
|
||||||
|
}
|
||||||
|
add_action( 'wp_ajax_mm_rules_order_save', 'mm_rules_order_save' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Alle Regeln" im Backend standardmaessig in der festgelegten Reihenfolge anzeigen.
|
||||||
|
*/
|
||||||
|
function mm_rules_admin_list_order( $query ) {
|
||||||
|
if ( is_admin() && $query->is_main_query() && 'mm_rule' === $query->get( 'post_type' ) && ! $query->get( 'orderby' ) ) {
|
||||||
|
$query->set( 'orderby', array( 'menu_order' => 'ASC', 'title' => 'ASC' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'pre_get_posts', 'mm_rules_admin_list_order' );
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Gemeinsame Schutzfunktionen fuer oeffentliche AJAX-Endpunkte.
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liefert einen nicht umkehrbaren Schluessel fuer den aktuellen Besucher.
|
||||||
|
* Die IP wird nur gehasht (mit dem WordPress-Salt) verwendet und nie im
|
||||||
|
* Klartext als Transient-Name gespeichert.
|
||||||
|
*/
|
||||||
|
function mm_client_key() {
|
||||||
|
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : 'unknown';
|
||||||
|
return substr( wp_hash( $ip ), 0, 20 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Einfaches Anfrage-Limit pro Besucher (festes Zeitfenster).
|
||||||
|
*
|
||||||
|
* @param string $bucket Name des Limits, z. B. "assistant".
|
||||||
|
* @param int $max Erlaubte Anfragen pro Fenster.
|
||||||
|
* @param int $window Fensterlaenge in Sekunden.
|
||||||
|
* @return bool True, wenn die Anfrage erlaubt ist; false, wenn das Limit erreicht ist.
|
||||||
|
*/
|
||||||
|
function mm_rate_limit( $bucket, $max, $window ) {
|
||||||
|
$max = (int) apply_filters( 'mm_rate_limit_max', $max, $bucket );
|
||||||
|
$window = (int) apply_filters( 'mm_rate_limit_window', $window, $bucket );
|
||||||
|
if ( $max < 1 ) {
|
||||||
|
return true; // Limit per Filter abgeschaltet.
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = 'mm_rl_' . sanitize_key( $bucket ) . '_' . mm_client_key();
|
||||||
|
$data = get_transient( $key );
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
if ( ! is_array( $data ) || empty( $data['until'] ) || $data['until'] <= $now ) {
|
||||||
|
$data = array( 'count' => 0, 'until' => $now + $window );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $data['count'] >= $max ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['count']++;
|
||||||
|
// Ablaufzeit bleibt das urspruengliche Fensterende, damit jede weitere
|
||||||
|
// Anfrage das Fenster nicht verlaengert.
|
||||||
|
set_transient( $key, $data, max( 1, $data['until'] - $now ) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,318 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Open-Graph-/Twitter-Tags und strukturierte Daten (JSON-LD).
|
||||||
|
*
|
||||||
|
* Sorgt fuer Vorschaukarten beim Teilen (Discord, WhatsApp, X …) und fuer
|
||||||
|
* Rich Results (FAQ, Artikel). Ist ein SEO-Plugin aktiv, haelt sich das
|
||||||
|
* Theme komplett zurueck, damit keine doppelten Tags entstehen.
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True, wenn das Theme Meta-Tags ausgeben soll.
|
||||||
|
*/
|
||||||
|
function mm_seo_enabled() {
|
||||||
|
if ( ! get_theme_mod( 'mm_seo_enabled', true ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$plugin_active = defined( 'WPSEO_VERSION' ) // Yoast SEO
|
||||||
|
|| defined( 'RANK_MATH_VERSION' ) // Rank Math
|
||||||
|
|| defined( 'SEOPRESS_VERSION' ) // SEOPress
|
||||||
|
|| defined( 'AIOSEO_VERSION' ) // All in One SEO
|
||||||
|
|| class_exists( 'The_SEO_Framework\Load' ); // The SEO Framework
|
||||||
|
|
||||||
|
return (bool) apply_filters( 'mm_seo_enabled', ! $plugin_active );
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_seo_customizer( $wp_customize ) {
|
||||||
|
$wp_customize->add_section( 'mm_seo_section', array(
|
||||||
|
'title' => __( 'SEO & Teilen-Vorschau', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Open-Graph-Tags und strukturierte Daten. Wird automatisch abgeschaltet, sobald ein SEO-Plugin (Yoast, Rank Math, SEOPress, AIOSEO) aktiv ist.', 'minecraft-modern-theme' ),
|
||||||
|
'priority' => 85,
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_seo_enabled', array(
|
||||||
|
'default' => true,
|
||||||
|
'sanitize_callback' => 'wp_validate_boolean',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_seo_enabled', array(
|
||||||
|
'label' => __( 'Meta-Tags und strukturierte Daten ausgeben', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_seo_section',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_seo_default_image', array(
|
||||||
|
'sanitize_callback' => 'esc_url_raw',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'mm_seo_default_image', array(
|
||||||
|
'label' => __( 'Standard-Vorschaubild', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Wird beim Teilen verwendet, wenn eine Seite kein Beitragsbild hat. Empfohlen: 1200 × 630 px.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_seo_section',
|
||||||
|
) ) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_seo_home_description', array(
|
||||||
|
'sanitize_callback' => 'sanitize_textarea_field',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_seo_home_description', array(
|
||||||
|
'label' => __( 'Beschreibung der Startseite', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Leer = Untertitel der Website. Ideal sind 120–160 Zeichen.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_seo_section',
|
||||||
|
'type' => 'textarea',
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
add_action( 'customize_register', 'mm_seo_customizer' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kuerzt Text auf eine fuer Meta-Beschreibungen sinnvolle Laenge.
|
||||||
|
*/
|
||||||
|
function mm_seo_trim( $text, $length = 160 ) {
|
||||||
|
$text = trim( preg_replace( '/\s+/', ' ', wp_strip_all_tags( strip_shortcodes( (string) $text ) ) ) );
|
||||||
|
if ( mb_strlen( $text ) <= $length ) {
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
$cut = mb_substr( $text, 0, $length - 1 );
|
||||||
|
$space = mb_strrpos( $cut, ' ' );
|
||||||
|
if ( $space > $length * 0.6 ) {
|
||||||
|
$cut = mb_substr( $cut, 0, $space );
|
||||||
|
}
|
||||||
|
return rtrim( $cut, " ,.;:-" ) . '…';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True auf der FAQ-Uebersicht (CPT-Archiv oder die automatisch angelegte Seite "FAQ").
|
||||||
|
*/
|
||||||
|
function mm_seo_is_faq_overview() {
|
||||||
|
if ( ! post_type_exists( 'faq' ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( is_post_type_archive( 'faq' ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$obj = get_queried_object();
|
||||||
|
return is_page() && $obj instanceof WP_Post && 'FAQ' === $obj->post_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sammelt Titel, Beschreibung, Bild und URL der aktuellen Ansicht.
|
||||||
|
*/
|
||||||
|
function mm_seo_context() {
|
||||||
|
$ctx = array(
|
||||||
|
'type' => 'website',
|
||||||
|
'title' => wp_get_document_title(),
|
||||||
|
'description' => '',
|
||||||
|
'url' => '',
|
||||||
|
'image' => '',
|
||||||
|
'image_w' => 0,
|
||||||
|
'image_h' => 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( is_singular() ) {
|
||||||
|
$post = get_queried_object();
|
||||||
|
$ctx['url'] = get_permalink( $post );
|
||||||
|
$ctx['description'] = has_excerpt( $post ) ? get_the_excerpt( $post ) : $post->post_content;
|
||||||
|
if ( is_singular( 'post' ) ) {
|
||||||
|
$ctx['type'] = 'article';
|
||||||
|
}
|
||||||
|
if ( has_post_thumbnail( $post ) ) {
|
||||||
|
$img = wp_get_attachment_image_src( get_post_thumbnail_id( $post ), 'large' );
|
||||||
|
if ( $img ) {
|
||||||
|
list( $ctx['image'], $ctx['image_w'], $ctx['image_h'] ) = $img;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ( is_category() || is_tag() || is_tax() ) {
|
||||||
|
$ctx['url'] = get_term_link( get_queried_object() );
|
||||||
|
$ctx['description'] = term_description();
|
||||||
|
} elseif ( is_post_type_archive() ) {
|
||||||
|
$ctx['url'] = get_post_type_archive_link( get_query_var( 'post_type' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_front_page() ) {
|
||||||
|
$ctx['url'] = home_url( '/' );
|
||||||
|
$home_desc = get_theme_mod( 'mm_seo_home_description', '' );
|
||||||
|
$ctx['description'] = $home_desc ? $home_desc : get_bloginfo( 'description' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_wp_error( $ctx['url'] ) || empty( $ctx['url'] ) ) {
|
||||||
|
$ctx['url'] = '';
|
||||||
|
}
|
||||||
|
if ( empty( $ctx['description'] ) ) {
|
||||||
|
$ctx['description'] = get_bloginfo( 'description' );
|
||||||
|
}
|
||||||
|
$ctx['description'] = mm_seo_trim( $ctx['description'] );
|
||||||
|
|
||||||
|
if ( empty( $ctx['image'] ) ) {
|
||||||
|
$ctx['image'] = get_theme_mod( 'mm_seo_default_image', '' );
|
||||||
|
}
|
||||||
|
if ( empty( $ctx['image'] ) && has_site_icon() ) {
|
||||||
|
$ctx['image'] = get_site_icon_url( 512 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return apply_filters( 'mm_seo_context', $ctx );
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_seo_meta_tags() {
|
||||||
|
if ( ! mm_seo_enabled() || is_404() || is_search() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$ctx = mm_seo_context();
|
||||||
|
|
||||||
|
echo "\n<!-- Minecraft Modern Theme: Meta -->\n";
|
||||||
|
if ( $ctx['description'] ) {
|
||||||
|
printf( "<meta name=\"description\" content=\"%s\">\n", esc_attr( $ctx['description'] ) );
|
||||||
|
printf( "<meta property=\"og:description\" content=\"%s\">\n", esc_attr( $ctx['description'] ) );
|
||||||
|
}
|
||||||
|
printf( "<meta property=\"og:type\" content=\"%s\">\n", esc_attr( $ctx['type'] ) );
|
||||||
|
printf( "<meta property=\"og:title\" content=\"%s\">\n", esc_attr( $ctx['title'] ) );
|
||||||
|
printf( "<meta property=\"og:site_name\" content=\"%s\">\n", esc_attr( get_bloginfo( 'name' ) ) );
|
||||||
|
printf( "<meta property=\"og:locale\" content=\"%s\">\n", esc_attr( get_locale() ) );
|
||||||
|
if ( $ctx['url'] ) {
|
||||||
|
printf( "<meta property=\"og:url\" content=\"%s\">\n", esc_url( $ctx['url'] ) );
|
||||||
|
}
|
||||||
|
if ( $ctx['image'] ) {
|
||||||
|
printf( "<meta property=\"og:image\" content=\"%s\">\n", esc_url( $ctx['image'] ) );
|
||||||
|
if ( $ctx['image_w'] && $ctx['image_h'] ) {
|
||||||
|
printf( "<meta property=\"og:image:width\" content=\"%d\">\n", (int) $ctx['image_w'] );
|
||||||
|
printf( "<meta property=\"og:image:height\" content=\"%d\">\n", (int) $ctx['image_h'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Grosse Karte nur mit echtem Vorschaubild, sonst kompakte Karte.
|
||||||
|
$large = $ctx['image'] && ( $ctx['image_w'] >= 600 || get_theme_mod( 'mm_seo_default_image', '' ) === $ctx['image'] );
|
||||||
|
printf( "<meta name=\"twitter:card\" content=\"%s\">\n", $large ? 'summary_large_image' : 'summary' );
|
||||||
|
// Farbe des Balkens in der Discord-Vorschau und der Browserleiste auf Mobilgeraeten.
|
||||||
|
printf( "<meta name=\"theme-color\" content=\"%s\">\n", esc_attr( get_theme_mod( 'primary_accent_color', '#00d4ff' ) ) );
|
||||||
|
|
||||||
|
if ( 'article' === $ctx['type'] ) {
|
||||||
|
$post = get_queried_object();
|
||||||
|
printf( "<meta property=\"article:published_time\" content=\"%s\">\n", esc_attr( get_post_time( 'c', true, $post ) ) );
|
||||||
|
printf( "<meta property=\"article:modified_time\" content=\"%s\">\n", esc_attr( get_post_modified_time( 'c', true, $post ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'wp_head', 'mm_seo_meta_tags', 5 );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Baut die JSON-LD-Knoten fuer die aktuelle Ansicht.
|
||||||
|
*/
|
||||||
|
function mm_seo_schema_graph() {
|
||||||
|
$graph = array();
|
||||||
|
$home = home_url( '/' );
|
||||||
|
|
||||||
|
if ( is_front_page() ) {
|
||||||
|
$org = array(
|
||||||
|
'@type' => 'Organization',
|
||||||
|
'@id' => $home . '#organization',
|
||||||
|
'name' => get_bloginfo( 'name' ),
|
||||||
|
'url' => $home,
|
||||||
|
);
|
||||||
|
$logo_id = get_theme_mod( 'custom_logo' );
|
||||||
|
if ( $logo_id ) {
|
||||||
|
$logo = wp_get_attachment_image_url( $logo_id, 'full' );
|
||||||
|
if ( $logo ) {
|
||||||
|
$org['logo'] = $logo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$same_as = array();
|
||||||
|
foreach ( array( 'discord', 'youtube', 'twitter', 'facebook', 'instagram', 'tiktok', 'twitch', 'bluesky', 'mastodon', 'threads', 'github', 'reddit' ) as $network ) {
|
||||||
|
$url = get_theme_mod( 'social_' . $network );
|
||||||
|
if ( $url ) {
|
||||||
|
$same_as[] = esc_url_raw( $url );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $same_as ) {
|
||||||
|
$org['sameAs'] = $same_as;
|
||||||
|
}
|
||||||
|
$graph[] = $org;
|
||||||
|
|
||||||
|
$graph[] = array(
|
||||||
|
'@type' => 'WebSite',
|
||||||
|
'@id' => $home . '#website',
|
||||||
|
'url' => $home,
|
||||||
|
'name' => get_bloginfo( 'name' ),
|
||||||
|
'description' => get_bloginfo( 'description' ),
|
||||||
|
'inLanguage' => get_bloginfo( 'language' ),
|
||||||
|
'publisher' => array( '@id' => $home . '#organization' ),
|
||||||
|
'potentialAction' => array(
|
||||||
|
'@type' => 'SearchAction',
|
||||||
|
'target' => $home . '?s={search_term_string}',
|
||||||
|
'query-input' => 'required name=search_term_string',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_singular( 'post' ) ) {
|
||||||
|
$post = get_queried_object();
|
||||||
|
$article = array(
|
||||||
|
'@type' => 'Article',
|
||||||
|
'headline' => mm_seo_trim( get_the_title( $post ), 110 ),
|
||||||
|
'datePublished' => get_post_time( 'c', true, $post ),
|
||||||
|
'dateModified' => get_post_modified_time( 'c', true, $post ),
|
||||||
|
'mainEntityOfPage' => get_permalink( $post ),
|
||||||
|
'author' => array(
|
||||||
|
'@type' => 'Person',
|
||||||
|
'name' => get_the_author_meta( 'display_name', $post->post_author ),
|
||||||
|
),
|
||||||
|
'publisher' => array(
|
||||||
|
'@type' => 'Organization',
|
||||||
|
'name' => get_bloginfo( 'name' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if ( has_post_thumbnail( $post ) ) {
|
||||||
|
$article['image'] = get_the_post_thumbnail_url( $post, 'large' );
|
||||||
|
}
|
||||||
|
$graph[] = $article;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mm_seo_is_faq_overview() ) {
|
||||||
|
$faqs = get_posts( array(
|
||||||
|
'post_type' => 'faq',
|
||||||
|
'posts_per_page' => 100,
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'order' => 'ASC',
|
||||||
|
) );
|
||||||
|
$entities = array();
|
||||||
|
foreach ( $faqs as $faq ) {
|
||||||
|
$answer = trim( wp_strip_all_tags( strip_shortcodes( $faq->post_content ) ) );
|
||||||
|
if ( '' === $answer ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$entities[] = array(
|
||||||
|
'@type' => 'Question',
|
||||||
|
'name' => get_the_title( $faq ),
|
||||||
|
'acceptedAnswer' => array(
|
||||||
|
'@type' => 'Answer',
|
||||||
|
'text' => $answer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( $entities ) {
|
||||||
|
$graph[] = array(
|
||||||
|
'@type' => 'FAQPage',
|
||||||
|
'mainEntity' => $entities,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return apply_filters( 'mm_seo_schema_graph', $graph );
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_seo_schema_output() {
|
||||||
|
if ( ! mm_seo_enabled() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$graph = mm_seo_schema_graph();
|
||||||
|
if ( empty( $graph ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$data = array(
|
||||||
|
'@context' => 'https://schema.org',
|
||||||
|
'@graph' => $graph,
|
||||||
|
);
|
||||||
|
// JSON_HEX_TAG verhindert, dass ein "</script>" im Inhalt den Block beendet.
|
||||||
|
echo '<script type="application/ld+json">' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG ) . "</script>\n";
|
||||||
|
}
|
||||||
|
add_action( 'wp_head', 'mm_seo_schema_output', 6 );
|
||||||
@@ -0,0 +1,497 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Server-Status: Online-Anzeige, Spielerzahl und IP zum Kopieren.
|
||||||
|
*
|
||||||
|
* Die Abfrage laeuft ausschliesslich serverseitig (Minecraft Server List Ping
|
||||||
|
* direkt an den eigenen Server, ohne Drittanbieter-API) und wird 60 Sekunden
|
||||||
|
* zwischengespeichert. Der Browser des Besuchers spricht nur mit der eigenen
|
||||||
|
* Website.
|
||||||
|
*
|
||||||
|
* Ausgabe ueber:
|
||||||
|
* - Startseiten-Sektion (Customizer → Startseiten-Sektionen)
|
||||||
|
* - Shortcode [mm_server_status]
|
||||||
|
* - Widget "Minecraft Server-Status"
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_server_status_customizer( $wp_customize ) {
|
||||||
|
$wp_customize->add_section( 'mm_server_status_section', array(
|
||||||
|
'title' => __( 'Server-Status', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Zeigt, ob der Minecraft-Server online ist und wie viele Spieler gerade spielen. Einbinden per Startseiten-Sektion, Widget oder Shortcode [mm_server_status].', 'minecraft-modern-theme' ),
|
||||||
|
'priority' => 22,
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_server_address', array(
|
||||||
|
'default' => '',
|
||||||
|
'sanitize_callback' => 'mm_server_sanitize_address',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_server_address', array(
|
||||||
|
'label' => __( 'Server-Adresse', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'z. B. play.meinserver.de oder play.meinserver.de:25566. Leer = Adresse aus dem Assistent-Setup.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_server_status_section',
|
||||||
|
'type' => 'text',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_server_display_address', array(
|
||||||
|
'default' => '',
|
||||||
|
'sanitize_callback' => 'sanitize_text_field',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_server_display_address', array(
|
||||||
|
'label' => __( 'Angezeigte Adresse (optional)', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'Falls Besucher eine andere Adresse kopieren sollen als die, die abgefragt wird.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_server_status_section',
|
||||||
|
'type' => 'text',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_server_show_version', array(
|
||||||
|
'default' => true,
|
||||||
|
'sanitize_callback' => 'wp_validate_boolean',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_server_show_version', array(
|
||||||
|
'label' => __( 'Minecraft-Version anzeigen', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_server_status_section',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$wp_customize->add_setting( 'mm_server_version_text', array(
|
||||||
|
'default' => '',
|
||||||
|
'sanitize_callback' => 'sanitize_text_field',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'mm_server_version_text', array(
|
||||||
|
'label' => __( 'Versions-Text (optional)', 'minecraft-modern-theme' ),
|
||||||
|
'description' => __( 'z. B. „1.8 – 1.21“. Leer = Version aus dem Assistent-Setup bzw. die vom Server gemeldete.', 'minecraft-modern-theme' ),
|
||||||
|
'section' => 'mm_server_status_section',
|
||||||
|
'type' => 'text',
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
add_action( 'customize_register', 'mm_server_status_customizer' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Laesst nur Hostnamen/IPs mit optionalem Port zu.
|
||||||
|
*/
|
||||||
|
function mm_server_sanitize_address( $value ) {
|
||||||
|
$value = strtolower( trim( sanitize_text_field( $value ) ) );
|
||||||
|
$value = preg_replace( '#^[a-z]+://#', '', $value );
|
||||||
|
return preg_match( '/^[a-z0-9.\-]+(:\d{1,5})?$/', $value ) ? $value : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abzufragende Adresse: Customizer-Feld, sonst die IP aus dem Assistent-Setup.
|
||||||
|
*/
|
||||||
|
function mm_server_get_address() {
|
||||||
|
$address = get_theme_mod( 'mm_server_address', '' );
|
||||||
|
if ( empty( $address ) ) {
|
||||||
|
$bot = get_option( 'mm_bot_data', array() );
|
||||||
|
$address = mm_server_sanitize_address( $bot['server_ip'] ?? '' );
|
||||||
|
}
|
||||||
|
return $address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ermittelt, wohin die Abfrage gehen muss: Host, Port und IPv4-Adresse.
|
||||||
|
*
|
||||||
|
* Das Ergebnis wird 12 Stunden zwischengespeichert. Die DNS-Abfragen (vor
|
||||||
|
* allem der SRV-Eintrag) haben in PHP keine einstellbare Zeitgrenze und
|
||||||
|
* koennen mehrere Sekunden dauern – frueher liefen sie bei JEDER Abfrage mit
|
||||||
|
* und haben den Seitenaufbau spuerbar ausgebremst.
|
||||||
|
*
|
||||||
|
* @return array{host:string,port:int,ip:string} "host" fuer den Handshake, "ip" fuer die Verbindung.
|
||||||
|
*/
|
||||||
|
function mm_server_resolve( $address ) {
|
||||||
|
$key = 'mm_server_status_dns_' . md5( $address );
|
||||||
|
$cached = get_transient( $key );
|
||||||
|
if ( is_array( $cached ) && isset( $cached['host'], $cached['port'], $cached['ip'] ) ) {
|
||||||
|
return $cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
$host = $address;
|
||||||
|
$port = 0;
|
||||||
|
if ( false !== strpos( $address, ':' ) ) {
|
||||||
|
list( $host, $port ) = explode( ':', $address, 2 );
|
||||||
|
$port = (int) $port;
|
||||||
|
}
|
||||||
|
$is_ip = (bool) filter_var( $host, FILTER_VALIDATE_IP );
|
||||||
|
|
||||||
|
if ( ! $port ) {
|
||||||
|
$port = 25565;
|
||||||
|
// Viele Server nutzen einen SRV-Eintrag, damit Spieler keinen Port tippen muessen.
|
||||||
|
if ( ! $is_ip && function_exists( 'dns_get_record' ) ) {
|
||||||
|
$records = @dns_get_record( '_minecraft._tcp.' . $host, DNS_SRV ); // phpcs:ignore WordPress.PHP.NoSilencedErrors
|
||||||
|
if ( ! empty( $records[0]['target'] ) && ! empty( $records[0]['port'] ) ) {
|
||||||
|
$host = $records[0]['target'];
|
||||||
|
$port = (int) $records[0]['port'];
|
||||||
|
$is_ip = (bool) filter_var( $host, FILTER_VALIDATE_IP );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gezielt die IPv4-Adresse verwenden: mit dem Hostnamen probiert PHP sonst
|
||||||
|
// nacheinander alle Adressen (auch nicht erreichbare IPv6) – jeweils bis
|
||||||
|
// zur vollen Zeitgrenze.
|
||||||
|
$ip = $is_ip ? $host : gethostbyname( $host );
|
||||||
|
|
||||||
|
$resolved = array( 'host' => $host, 'port' => $port, 'ip' => $ip );
|
||||||
|
set_transient( $key, $resolved, 12 * HOUR_IN_SECONDS );
|
||||||
|
return $resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kodiert eine Zahl als VarInt (Minecraft-Protokoll).
|
||||||
|
*/
|
||||||
|
function mm_server_varint( $value ) {
|
||||||
|
$out = '';
|
||||||
|
do {
|
||||||
|
$byte = $value & 0x7F;
|
||||||
|
$value = ( $value >> 7 ) & 0x01FFFFFF;
|
||||||
|
$out .= chr( $value ? ( $byte | 0x80 ) : $byte );
|
||||||
|
} while ( $value );
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liest einen VarInt vom Socket. Gibt false bei Fehler zurueck.
|
||||||
|
*/
|
||||||
|
function mm_server_read_varint( $socket ) {
|
||||||
|
$result = 0;
|
||||||
|
for ( $i = 0; $i < 5; $i++ ) {
|
||||||
|
$char = fread( $socket, 1 );
|
||||||
|
if ( false === $char || '' === $char ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$byte = ord( $char );
|
||||||
|
$result |= ( $byte & 0x7F ) << ( 7 * $i );
|
||||||
|
if ( ! ( $byte & 0x80 ) ) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fuehrt einen Server List Ping (Java Edition, ab 1.7) aus.
|
||||||
|
*
|
||||||
|
* @return array|false Dekodierte Status-Antwort oder false, wenn der Server nicht antwortet.
|
||||||
|
*/
|
||||||
|
function mm_server_ping( $host, $port, $timeout = 2, $connect_to = '' ) {
|
||||||
|
// $connect_to: bereits aufgeloeste IP; $host wird nur im Handshake genannt.
|
||||||
|
$socket = @fsockopen( $connect_to ? $connect_to : $host, $port, $errno, $errstr, $timeout ); // phpcs:ignore WordPress.PHP.NoSilencedErrors
|
||||||
|
if ( ! $socket ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
stream_set_timeout( $socket, $timeout );
|
||||||
|
|
||||||
|
// Handshake: Paket-ID 0, Protokollversion -1 (unbekannt), Host, Port, naechster Status = 1.
|
||||||
|
$handshake = "\x00" . "\xFF\xFF\xFF\xFF\x0F"
|
||||||
|
. mm_server_varint( strlen( $host ) ) . $host
|
||||||
|
. pack( 'n', $port )
|
||||||
|
. "\x01";
|
||||||
|
fwrite( $socket, mm_server_varint( strlen( $handshake ) ) . $handshake );
|
||||||
|
fwrite( $socket, "\x01\x00" ); // Status-Anfrage
|
||||||
|
|
||||||
|
$length = mm_server_read_varint( $socket ); // Paketlaenge
|
||||||
|
$packet = false !== $length ? mm_server_read_varint( $socket ) : false; // Paket-ID
|
||||||
|
$json_len = ( 0 === $packet ) ? mm_server_read_varint( $socket ) : false;
|
||||||
|
|
||||||
|
// Obergrenze, damit ein fehlerhafter Server keinen Speicher belegen kann.
|
||||||
|
if ( false === $json_len || $json_len < 2 || $json_len > 262144 ) {
|
||||||
|
fclose( $socket );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = '';
|
||||||
|
while ( strlen( $json ) < $json_len ) {
|
||||||
|
$chunk = fread( $socket, $json_len - strlen( $json ) );
|
||||||
|
if ( false === $chunk || '' === $chunk ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$json .= $chunk;
|
||||||
|
}
|
||||||
|
fclose( $socket );
|
||||||
|
|
||||||
|
$data = json_decode( $json, true );
|
||||||
|
return is_array( $data ) ? $data : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Macht aus dem Versionstext des Servers eine kurze Anzeige.
|
||||||
|
*
|
||||||
|
* Proxys stellen ihren Namen voran und melden einen Bereich, z. B.
|
||||||
|
* "BungeeCord 1.8.x-26.x" oder "Velocity 1.7.2-1.21.4". Daraus wird
|
||||||
|
* "1.8.x – 26.x" bzw. "1.7.2 – 1.21.4"; ein einzelner Server ("Paper 1.21.4")
|
||||||
|
* ergibt "1.21.4". Platzhalter wie ".x" bleiben erhalten – frueher fiel
|
||||||
|
* "26.x" durchs Raster und es wurde nur "1.8" angezeigt.
|
||||||
|
*/
|
||||||
|
function mm_server_parse_version( $name ) {
|
||||||
|
$name = sanitize_text_field( $name );
|
||||||
|
// Versionsnummer: Zahlen mit Punkten, optional mit ".x" am Ende (1.8, 1.21.4, 1.8.x, 26.x).
|
||||||
|
if ( preg_match_all( '/\d+(?:\.\d+)+(?:\.x)?|\d+\.x/i', $name, $m ) && $m[0] ) {
|
||||||
|
$first = $m[0][0];
|
||||||
|
$last = end( $m[0] );
|
||||||
|
return $first === $last ? $first : $first . ' – ' . $last;
|
||||||
|
}
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liefert den (zwischengespeicherten) Server-Status.
|
||||||
|
*
|
||||||
|
* Der letzte bekannte Stand bleibt einen Tag gespeichert und gilt 60 Sekunden
|
||||||
|
* als frisch. Ist er aelter, fragt genau EINE Anfrage den Server neu ab (per
|
||||||
|
* Sperre); alle anderen bekommen sofort den letzten Stand. So wartet nie mehr
|
||||||
|
* als ein PHP-Prozess auf den Minecraft-Server, egal wie viele Besucher die
|
||||||
|
* Seite gerade offen haben.
|
||||||
|
*
|
||||||
|
* @param bool $cache_only True: nur den gespeicherten Stand lesen und nie selbst abfragen.
|
||||||
|
* So blockiert der Seitenaufbau nie auf dem Ping.
|
||||||
|
* @return array|null null = unbekannt (noch nie abgefragt, keine Adresse).
|
||||||
|
*/
|
||||||
|
function mm_server_status_get( $cache_only = false ) {
|
||||||
|
$address = mm_server_get_address();
|
||||||
|
if ( empty( $address ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = 'mm_server_status_' . md5( $address );
|
||||||
|
$cached = get_transient( $key );
|
||||||
|
$stale = is_array( $cached ) && isset( $cached['online'] ) ? $cached : null;
|
||||||
|
$fresh = $stale && ( time() - (int) ( $stale['checked'] ?? 0 ) ) < MINUTE_IN_SECONDS;
|
||||||
|
|
||||||
|
if ( $fresh || $cache_only ) {
|
||||||
|
return $stale;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Laeuft schon eine Abfrage? Dann nicht anstellen, sondern den letzten Stand liefern.
|
||||||
|
$lock = 'mm_server_status_lock_' . md5( $address );
|
||||||
|
if ( get_transient( $lock ) ) {
|
||||||
|
return $stale;
|
||||||
|
}
|
||||||
|
set_transient( $lock, 1, 20 );
|
||||||
|
|
||||||
|
$target = mm_server_resolve( $address );
|
||||||
|
$raw = mm_server_ping( $target['host'], $target['port'], 2, $target['ip'] );
|
||||||
|
|
||||||
|
$status = array(
|
||||||
|
'online' => false,
|
||||||
|
'players' => 0,
|
||||||
|
'max' => 0,
|
||||||
|
'version' => '',
|
||||||
|
);
|
||||||
|
if ( $raw ) {
|
||||||
|
$status['online'] = true;
|
||||||
|
$status['players'] = (int) ( $raw['players']['online'] ?? 0 );
|
||||||
|
$status['max'] = (int) ( $raw['players']['max'] ?? 0 );
|
||||||
|
$status['version'] = mm_server_parse_version( (string) ( $raw['version']['name'] ?? '' ) );
|
||||||
|
} else {
|
||||||
|
// Nicht erreichbar: beim naechsten Mal neu aufloesen, falls sich die
|
||||||
|
// IP geaendert hat (dynamisches DNS).
|
||||||
|
delete_transient( 'mm_server_status_dns_' . md5( $address ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = apply_filters( 'mm_server_status', $status, $address );
|
||||||
|
$status['checked'] = time();
|
||||||
|
set_transient( $key, $status, DAY_IN_SECONDS );
|
||||||
|
delete_transient( $lock );
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Angezeigte Version: fester Text aus dem Customizer, sonst die Version aus
|
||||||
|
* dem Assistent-Setup, sonst das, was der Server selbst meldet. Proxys melden
|
||||||
|
* oft nur ihre aelteste unterstuetzte Version (z. B. "1.8") – dafuer gibt es
|
||||||
|
* das Feld zum Ueberschreiben.
|
||||||
|
*/
|
||||||
|
function mm_server_version_label( $status ) {
|
||||||
|
$label = get_theme_mod( 'mm_server_version_text', '' );
|
||||||
|
if ( '' === $label ) {
|
||||||
|
$bot = get_option( 'mm_bot_data', array() );
|
||||||
|
$label = sanitize_text_field( $bot['server_ver'] ?? '' );
|
||||||
|
}
|
||||||
|
if ( '' === $label ) {
|
||||||
|
$label = (string) ( $status['version'] ?? '' );
|
||||||
|
}
|
||||||
|
return $label;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fuellstand des Auslastungsbalkens in Prozent. Bei mindestens einem Spieler
|
||||||
|
* bleibt ein schmaler Rest sichtbar, damit der Balken nicht leer wirkt.
|
||||||
|
*/
|
||||||
|
function mm_server_fill_percent( $online, $max ) {
|
||||||
|
if ( $max < 1 || $online < 1 ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (int) max( 4, min( 100, round( $online / $max * 100 ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AJAX: aktuellen Status liefern. Oeffentlich lesbar, deshalb ohne Nonce.
|
||||||
|
*/
|
||||||
|
function mm_server_status_ajax() {
|
||||||
|
// Kein eigenes Anfrage-Limit noetig: die Antwort kommt aus dem Cache, und
|
||||||
|
// die Sperre in mm_server_status_get() laesst nur eine Abfrage zugleich zu.
|
||||||
|
$status = mm_server_status_get();
|
||||||
|
if ( null === $status ) {
|
||||||
|
wp_send_json_error();
|
||||||
|
}
|
||||||
|
unset( $status['checked'] );
|
||||||
|
$status['version'] = $status['online'] ? mm_server_version_label( $status ) : '';
|
||||||
|
wp_send_json_success( $status );
|
||||||
|
}
|
||||||
|
add_action( 'wp_ajax_mm_server_status', 'mm_server_status_ajax' );
|
||||||
|
add_action( 'wp_ajax_nopriv_mm_server_status', 'mm_server_status_ajax' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bindet Skript und Stylesheet der Community-Bausteine ein.
|
||||||
|
*/
|
||||||
|
function mm_community_assets() {
|
||||||
|
$dir = get_template_directory();
|
||||||
|
$uri = get_template_directory_uri();
|
||||||
|
|
||||||
|
wp_enqueue_style( 'mm-community', $uri . '/css/community.css', array( 'minecraft-modern-style' ), filemtime( $dir . '/css/community.css' ) );
|
||||||
|
|
||||||
|
if ( ! wp_script_is( 'mm-server-status', 'registered' ) ) {
|
||||||
|
wp_register_script( 'mm-server-status', $uri . '/js/server-status.js', array(), filemtime( $dir . '/js/server-status.js' ), true );
|
||||||
|
wp_localize_script( 'mm-server-status', 'mmServerStatus', array(
|
||||||
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
||||||
|
'i18n' => array(
|
||||||
|
'online' => __( 'Online', 'minecraft-modern-theme' ),
|
||||||
|
'offline' => __( 'Offline', 'minecraft-modern-theme' ),
|
||||||
|
'copied' => __( 'Kopiert!', 'minecraft-modern-theme' ),
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Früh registrieren, damit Shortcodes und Widgets im Seiteninhalt die Dateien
|
||||||
|
// noch in den <head> bekommen.
|
||||||
|
add_action( 'wp_enqueue_scripts', 'mm_community_assets', 15 );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rendert die Status-Karte.
|
||||||
|
*
|
||||||
|
* @param array $args 'layout' => 'bar' (breit, Startseite) oder 'card' (Widget/Shortcode).
|
||||||
|
* @return string HTML.
|
||||||
|
*/
|
||||||
|
function mm_server_status_render( $args = array() ) {
|
||||||
|
$args = wp_parse_args( $args, array( 'layout' => 'card' ) );
|
||||||
|
$address = mm_server_get_address();
|
||||||
|
if ( empty( $address ) ) {
|
||||||
|
if ( current_user_can( 'edit_theme_options' ) ) {
|
||||||
|
return '<p class="mm-server-status-hint">' . esc_html__( 'Server-Status: Bitte im Customizer unter „Server-Status“ eine Adresse eintragen.', 'minecraft-modern-theme' ) . '</p>';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_enqueue_script( 'mm-server-status' );
|
||||||
|
|
||||||
|
$display = get_theme_mod( 'mm_server_display_address', '' );
|
||||||
|
if ( empty( $display ) ) {
|
||||||
|
// Standardport nicht anzeigen – Spieler brauchen ihn nicht einzutippen.
|
||||||
|
$display = preg_replace( '/:25565$/', '', $address );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nur den Cache lesen: ist er leer, zeigt die Karte "wird geprüft" und das
|
||||||
|
// Skript holt den Status nach. So wartet der Seitenaufbau nie auf den Ping.
|
||||||
|
$status = mm_server_status_get( true );
|
||||||
|
$state = null === $status ? 'unknown' : ( $status['online'] ? 'online' : 'offline' );
|
||||||
|
$labels = array(
|
||||||
|
'unknown' => __( 'Wird geprüft …', 'minecraft-modern-theme' ),
|
||||||
|
'online' => __( 'Online', 'minecraft-modern-theme' ),
|
||||||
|
'offline' => __( 'Offline', 'minecraft-modern-theme' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$is_online = $status && $status['online'];
|
||||||
|
$online = $is_online ? (int) $status['players'] : 0;
|
||||||
|
$max = $is_online ? (int) $status['max'] : 0;
|
||||||
|
$show_version = get_theme_mod( 'mm_server_show_version', true );
|
||||||
|
$version = $is_online ? mm_server_version_label( $status ) : '';
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
?>
|
||||||
|
<div class="mm-server-status mm-server-status--<?php echo esc_attr( $args['layout'] ); ?>" data-mm-server-status data-state="<?php echo esc_attr( $state ); ?>">
|
||||||
|
<div class="mm-server-status__top">
|
||||||
|
<span class="mm-server-status__pill" role="status" aria-live="polite">
|
||||||
|
<span class="mm-server-status__dot" aria-hidden="true"></span>
|
||||||
|
<span class="mm-server-status__label" data-mm-label><?php echo esc_html( $labels[ $state ] ); ?></span>
|
||||||
|
</span>
|
||||||
|
<?php if ( $show_version ) : ?>
|
||||||
|
<span class="mm-server-status__version" data-mm-version<?php echo $version ? '' : ' hidden'; ?>>
|
||||||
|
<span class="screen-reader-text"><?php esc_html_e( 'Minecraft-Version', 'minecraft-modern-theme' ); ?></span>
|
||||||
|
<span data-mm-version-text><?php echo esc_html( $version ); ?></span>
|
||||||
|
</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="mm-server-status__players" data-mm-players<?php echo $is_online ? '' : ' hidden'; ?>>
|
||||||
|
<p class="mm-server-status__count">
|
||||||
|
<strong data-mm-online><?php echo esc_html( number_format_i18n( $online ) ); ?></strong>
|
||||||
|
<span class="mm-server-status__of">/ <span data-mm-max><?php echo esc_html( number_format_i18n( $max ) ); ?></span> <?php esc_html_e( 'Spieler online', 'minecraft-modern-theme' ); ?></span>
|
||||||
|
</p>
|
||||||
|
<div class="mm-server-status__meter" aria-hidden="true">
|
||||||
|
<span data-mm-meter style="width: <?php echo esc_attr( mm_server_fill_percent( $online, $max ) ); ?>%;"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="mm-server-status__ip" data-mm-copy="<?php echo esc_attr( $display ); ?>"
|
||||||
|
aria-label="<?php
|
||||||
|
/* translators: %s: server address */
|
||||||
|
echo esc_attr( sprintf( __( 'Server-Adresse %s kopieren', 'minecraft-modern-theme' ), $display ) ); ?>">
|
||||||
|
<span class="mm-server-status__ip-text" data-mm-copy-text><?php echo esc_html( $display ); ?></span>
|
||||||
|
<i class="fas fa-copy" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
return ob_get_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_server_status_shortcode( $atts ) {
|
||||||
|
$atts = shortcode_atts( array( 'layout' => 'card' ), $atts, 'mm_server_status' );
|
||||||
|
return mm_server_status_render( array( 'layout' => 'bar' === $atts['layout'] ? 'bar' : 'card' ) );
|
||||||
|
}
|
||||||
|
add_shortcode( 'mm_server_status', 'mm_server_status_shortcode' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget fuer Sidebar und Footer.
|
||||||
|
*/
|
||||||
|
class MM_Server_Status_Widget extends WP_Widget {
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(
|
||||||
|
'mm_server_status',
|
||||||
|
__( 'Minecraft Server-Status', 'minecraft-modern-theme' ),
|
||||||
|
array( 'description' => __( 'Online-Status, Spielerzahl und Server-Adresse zum Kopieren.', 'minecraft-modern-theme' ) )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function widget( $args, $instance ) {
|
||||||
|
$html = mm_server_status_render( array( 'layout' => 'card' ) );
|
||||||
|
if ( '' === $html ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput
|
||||||
|
$title = apply_filters( 'widget_title', $instance['title'] ?? '' );
|
||||||
|
if ( $title ) {
|
||||||
|
echo $args['before_title'] . esc_html( $title ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput
|
||||||
|
}
|
||||||
|
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput -- in mm_server_status_render() escaped.
|
||||||
|
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form( $instance ) {
|
||||||
|
$title = $instance['title'] ?? __( 'Server-Status', 'minecraft-modern-theme' );
|
||||||
|
?>
|
||||||
|
<p>
|
||||||
|
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Titel:', 'minecraft-modern-theme' ); ?></label>
|
||||||
|
<input class="widefat" type="text" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
|
||||||
|
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $title ); ?>">
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update( $new_instance, $old_instance ) {
|
||||||
|
return array( 'title' => sanitize_text_field( $new_instance['title'] ?? '' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,19 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
|
|
||||||
// === Theme Setup ===
|
// === Theme Setup ===
|
||||||
function minecraft_modern_setup() {
|
function minecraft_modern_setup() {
|
||||||
|
// Übersetzungen aus /languages laden (z. B. minecraft-modern-theme-en_US.mo).
|
||||||
|
load_theme_textdomain( 'minecraft-modern-theme', get_template_directory() . '/languages' );
|
||||||
|
|
||||||
add_theme_support( 'title-tag' );
|
add_theme_support( 'title-tag' );
|
||||||
|
add_theme_support( 'automatic-feed-links' );
|
||||||
|
|
||||||
|
// Block-Editor: breite Ausrichtung, responsive Einbettungen, Standard-Blockstile
|
||||||
|
// und dieselbe Optik im Editor wie im Frontend (css/editor-style.css).
|
||||||
|
add_theme_support( 'align-wide' );
|
||||||
|
add_theme_support( 'responsive-embeds' );
|
||||||
|
add_theme_support( 'wp-block-styles' );
|
||||||
|
add_theme_support( 'editor-styles' );
|
||||||
|
add_editor_style( 'css/editor-style.css' );
|
||||||
add_theme_support( 'post-thumbnails' );
|
add_theme_support( 'post-thumbnails' );
|
||||||
|
|
||||||
add_theme_support( 'custom-logo', array(
|
add_theme_support( 'custom-logo', array(
|
||||||
@@ -40,6 +52,41 @@ function minecraft_modern_setup() {
|
|||||||
}
|
}
|
||||||
add_action( 'after_setup_theme', 'minecraft_modern_setup' );
|
add_action( 'after_setup_theme', 'minecraft_modern_setup' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximale Inhaltsbreite – WordPress nutzt sie für Einbettungen und Bildgrößen.
|
||||||
|
*/
|
||||||
|
function minecraft_modern_content_width() {
|
||||||
|
$GLOBALS['content_width'] = apply_filters( 'minecraft_modern_content_width', 1200 );
|
||||||
|
}
|
||||||
|
add_action( 'after_setup_theme', 'minecraft_modern_content_width', 0 );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True, wenn auf der aktuellen Seite der Hero-Slider ausgegeben wird.
|
||||||
|
*/
|
||||||
|
function mm_is_slider_active() {
|
||||||
|
return is_front_page() && get_theme_mod( 'slider_enabled', false );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True auf Seiten, die das Video-Modul anzeigen (Archiv bzw. Seite "videos").
|
||||||
|
*/
|
||||||
|
function mm_is_video_view() {
|
||||||
|
if ( is_post_type_archive( 'mm_video' ) || is_singular( array( 'mm_video', 'mm_livestream' ) ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ( is_page() ) {
|
||||||
|
$obj = get_queried_object();
|
||||||
|
if ( $obj instanceof WP_Post && 'videos' === $obj->post_name ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( is_singular() ) {
|
||||||
|
$obj = get_queried_object();
|
||||||
|
return $obj instanceof WP_Post && has_shortcode( (string) $obj->post_content, 'mm_video' );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// LOKALE SCHRIFTEN (DSGVO)
|
// LOKALE SCHRIFTEN (DSGVO)
|
||||||
@@ -121,14 +168,48 @@ function minecraft_modern_scripts() {
|
|||||||
filemtime( get_template_directory() . '/css/fontawesome.min.css' )
|
filemtime( get_template_directory() . '/css/fontawesome.min.css' )
|
||||||
);
|
);
|
||||||
|
|
||||||
// Swiper.js CSS (lokal statt CDN)
|
// Barrierefreiheit: Skip-Link, Tastaturfokus, reduzierte Bewegung.
|
||||||
wp_enqueue_style(
|
wp_enqueue_style(
|
||||||
'swiper-css',
|
'mm-a11y',
|
||||||
get_template_directory_uri() . '/css/swiper-bundle.min.css',
|
get_template_directory_uri() . '/css/a11y.css',
|
||||||
array(),
|
array( 'minecraft-modern-style' ),
|
||||||
filemtime( get_template_directory() . '/css/swiper-bundle.min.css' )
|
filemtime( get_template_directory() . '/css/a11y.css' )
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Seitenbezogene Styles: nur registrieren und dort laden, wo sie gebraucht
|
||||||
|
// werden. Vorher steckte alles in style.css und wurde auf jeder Seite geladen.
|
||||||
|
wp_register_style(
|
||||||
|
'mm-video',
|
||||||
|
get_template_directory_uri() . '/css/video.css',
|
||||||
|
array( 'minecraft-modern-style' ),
|
||||||
|
filemtime( get_template_directory() . '/css/video.css' )
|
||||||
|
);
|
||||||
|
wp_register_style(
|
||||||
|
'mm-bewerbung',
|
||||||
|
get_template_directory_uri() . '/css/bewerbung.css',
|
||||||
|
array( 'minecraft-modern-style' ),
|
||||||
|
filemtime( get_template_directory() . '/css/bewerbung.css' )
|
||||||
|
);
|
||||||
|
if ( mm_is_video_view() ) {
|
||||||
|
wp_enqueue_style( 'mm-video' );
|
||||||
|
}
|
||||||
|
if ( is_page( 'bewerbung' ) ) {
|
||||||
|
wp_enqueue_style( 'mm-bewerbung' );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swiper wird nur für den Hero-Slider der Startseite gebraucht.
|
||||||
|
$slider_active = mm_is_slider_active();
|
||||||
|
|
||||||
|
// Swiper.js CSS (lokal statt CDN)
|
||||||
|
if ( $slider_active ) {
|
||||||
|
wp_enqueue_style(
|
||||||
|
'swiper-css',
|
||||||
|
get_template_directory_uri() . '/css/swiper-bundle.min.css',
|
||||||
|
array(),
|
||||||
|
filemtime( get_template_directory() . '/css/swiper-bundle.min.css' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Header-Scroll + Suche Toggle
|
// Header-Scroll + Suche Toggle
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'minecraft-modern-header-script',
|
'minecraft-modern-header-script',
|
||||||
@@ -147,25 +228,27 @@ function minecraft_modern_scripts() {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
// Swiper.js (lokal statt CDN)
|
if ( $slider_active ) {
|
||||||
wp_enqueue_script(
|
// Swiper.js (lokal statt CDN)
|
||||||
'swiper-js',
|
wp_enqueue_script(
|
||||||
get_template_directory_uri() . '/js/swiper-bundle.min.js',
|
'swiper-js',
|
||||||
array(),
|
get_template_directory_uri() . '/js/swiper-bundle.min.js',
|
||||||
filemtime( get_template_directory() . '/js/swiper-bundle.min.js' ),
|
array(),
|
||||||
true
|
filemtime( get_template_directory() . '/js/swiper-bundle.min.js' ),
|
||||||
);
|
true
|
||||||
|
);
|
||||||
|
|
||||||
// Slider-Init
|
// Slider-Init
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'minecraft-modern-slider-script',
|
'minecraft-modern-slider-script',
|
||||||
get_template_directory_uri() . '/js/slider-init.js',
|
get_template_directory_uri() . '/js/slider-init.js',
|
||||||
array( 'swiper-js' ),
|
array( 'swiper-js' ),
|
||||||
filemtime( get_template_directory() . '/js/slider-init.js' ),
|
filemtime( get_template_directory() . '/js/slider-init.js' ),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Theme Toggle
|
// Theme Toggle (die Klasse am <html> setzt schon mm_theme_mode_head() vor dem ersten Rendern)
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'theme-toggle-script',
|
'theme-toggle-script',
|
||||||
get_template_directory_uri() . '/js/theme-toggle.js',
|
get_template_directory_uri() . '/js/theme-toggle.js',
|
||||||
@@ -188,17 +271,28 @@ function minecraft_modern_scripts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIX: 'loop' ergänzt – war in slider-init.js als sliderSettings.loop referenziert, aber nie übergeben
|
// FIX: 'loop' ergänzt – war in slider-init.js als sliderSettings.loop referenziert, aber nie übergeben
|
||||||
|
if ( $slider_active ) {
|
||||||
|
wp_localize_script(
|
||||||
|
'minecraft-modern-slider-script',
|
||||||
|
'sliderSettings',
|
||||||
|
array(
|
||||||
|
'hideArrows' => get_theme_mod( 'slider_hide_arrows', false ) ? '1' : '0',
|
||||||
|
'hidePagination' => get_theme_mod( 'slider_hide_pagination', false ) ? '1' : '0',
|
||||||
|
'loop' => get_theme_mod( 'slider_loop', true ) ? '1' : '0',
|
||||||
|
'prevLabel' => __( 'Vorheriges Bild', 'minecraft-modern-theme' ),
|
||||||
|
'nextLabel' => __( 'Nächstes Bild', 'minecraft-modern-theme' ),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Der Standard-Modus hing früher an sliderSettings. Da das Slider-Skript
|
||||||
|
// jetzt nur noch auf der Startseite geladen wird, bekommt der Theme-Toggle
|
||||||
|
// seine eigene Einstellung.
|
||||||
wp_localize_script(
|
wp_localize_script(
|
||||||
'minecraft-modern-slider-script',
|
'theme-toggle-script',
|
||||||
'sliderSettings',
|
'mmTheme',
|
||||||
array(
|
array(
|
||||||
'hideArrows' => get_theme_mod( 'slider_hide_arrows', false ) ? '1' : '0',
|
'defaultMode' => get_theme_mod( 'default_theme_mode', 'dark' ),
|
||||||
'hidePagination' => get_theme_mod( 'slider_hide_pagination', false ) ? '1' : '0',
|
|
||||||
'effect' => get_theme_mod( 'slider_effect', 'fade' ),
|
|
||||||
'direction' => get_theme_mod( 'slider_direction', 'horizontal' ),
|
|
||||||
'defaultMode' => get_theme_mod( 'default_theme_mode', 'dark' ),
|
|
||||||
'loop' => get_theme_mod( 'slider_loop', true ) ? '1' : '0',
|
|
||||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -265,3 +359,19 @@ function minecraft_modern_remove_emoji_dns_prefetch( $urls, $relation_type ) {
|
|||||||
return $urls;
|
return $urls;
|
||||||
}
|
}
|
||||||
add_filter( 'wp_resource_hints', 'minecraft_modern_remove_emoji_dns_prefetch', 10, 2 );
|
add_filter( 'wp_resource_hints', 'minecraft_modern_remove_emoji_dns_prefetch', 10, 2 );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hell/Dunkel-Modus vor dem ersten Rendern setzen.
|
||||||
|
*
|
||||||
|
* theme-toggle.js läuft erst am Seitenende. Ohne dieses kurze Skript im <head>
|
||||||
|
* würde die Seite für Besucher im hellen Modus erst kurz dunkel aufblitzen.
|
||||||
|
* Die Reihenfolge der Entscheidung ist dieselbe wie in js/theme-toggle.js:
|
||||||
|
* gespeicherte Auswahl, sonst Systemeinstellung "hell", sonst Standard aus dem Customizer.
|
||||||
|
*/
|
||||||
|
function mm_theme_mode_head() {
|
||||||
|
$default = 'light' === get_theme_mod( 'default_theme_mode', 'dark' ) ? 'light' : 'dark';
|
||||||
|
echo '<script>(function(){try{var m=localStorage.getItem("themeMode");'
|
||||||
|
. 'if(!m){m=(window.matchMedia&&matchMedia("(prefers-color-scheme: light)").matches)?"light":"' . $default . '";}'
|
||||||
|
. 'if(m==="light"){document.documentElement.classList.add("light-mode");}}catch(e){}})();</script>' . "\n";
|
||||||
|
}
|
||||||
|
add_action( 'wp_head', 'mm_theme_mode_head', 1 );
|
||||||
|
|||||||
@@ -0,0 +1,233 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Theme-Werkzeuge im Backend (Design → Theme-Werkzeuge).
|
||||||
|
*
|
||||||
|
* Ersetzt die frueher lose im Theme-Ordner liegenden Debug-Skripte
|
||||||
|
* (clear-cache.php, clear-livestream-cache.php, test-api-key.php,
|
||||||
|
* list-posts.php …). Alle Aktionen laufen ueber admin-post.php mit
|
||||||
|
* Nonce und Rechtepruefung statt ueber direkt aufrufbare PHP-Dateien.
|
||||||
|
*
|
||||||
|
* @package Minecraft-Modern-Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transient-Praefixe, die das Theme anlegt – gruppiert nach Werkzeug.
|
||||||
|
*/
|
||||||
|
function mm_tools_cache_groups() {
|
||||||
|
return array(
|
||||||
|
'livestream' => array(
|
||||||
|
'label' => __( 'Livestream- und YouTube-Cache', 'minecraft-modern-theme' ),
|
||||||
|
'prefixes' => array(
|
||||||
|
'mm_channel_id_', 'mm_live_status_', 'mm_live_id_', 'mm_id_for_',
|
||||||
|
'mm_yt_live', 'mm_yt_status_',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'server' => array(
|
||||||
|
'label' => __( 'Server-Status-Cache', 'minecraft-modern-theme' ),
|
||||||
|
'prefixes' => array( 'mm_srv_', 'mm_server_status_', 'mm_discord_widget_' ),
|
||||||
|
),
|
||||||
|
'limits' => array(
|
||||||
|
'label' => __( 'Anfrage-Limits (Assistent, Bewerbung)', 'minecraft-modern-theme' ),
|
||||||
|
'prefixes' => array( 'mm_rl_' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loescht alle Transients mit den angegebenen Praefixen.
|
||||||
|
*
|
||||||
|
* @param string[] $prefixes Transient-Namen ohne "_transient_".
|
||||||
|
* @return int Anzahl geloeschter Transients.
|
||||||
|
*/
|
||||||
|
function mm_tools_delete_transients( $prefixes ) {
|
||||||
|
global $wpdb;
|
||||||
|
$deleted = 0;
|
||||||
|
|
||||||
|
foreach ( $prefixes as $prefix ) {
|
||||||
|
$like = $wpdb->esc_like( '_transient_' . $prefix ) . '%';
|
||||||
|
$names = $wpdb->get_col(
|
||||||
|
$wpdb->prepare( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", $like )
|
||||||
|
);
|
||||||
|
foreach ( $names as $name ) {
|
||||||
|
if ( delete_transient( substr( $name, strlen( '_transient_' ) ) ) ) {
|
||||||
|
$deleted++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mm_tools_menu() {
|
||||||
|
add_theme_page(
|
||||||
|
__( 'Theme-Werkzeuge', 'minecraft-modern-theme' ),
|
||||||
|
__( 'Theme-Werkzeuge', 'minecraft-modern-theme' ),
|
||||||
|
'manage_options',
|
||||||
|
'mm-tools',
|
||||||
|
'mm_tools_render_page'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action( 'admin_menu', 'mm_tools_menu' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache leeren.
|
||||||
|
*/
|
||||||
|
function mm_tools_handle_clear_cache() {
|
||||||
|
if ( ! current_user_can( 'manage_options' ) ) {
|
||||||
|
wp_die( esc_html__( 'Keine Berechtigung.', 'minecraft-modern-theme' ), 403 );
|
||||||
|
}
|
||||||
|
check_admin_referer( 'mm_tools_clear_cache' );
|
||||||
|
|
||||||
|
$groups = mm_tools_cache_groups();
|
||||||
|
$group = isset( $_POST['group'] ) ? sanitize_key( wp_unslash( $_POST['group'] ) ) : '';
|
||||||
|
$count = isset( $groups[ $group ] ) ? mm_tools_delete_transients( $groups[ $group ]['prefixes'] ) : 0;
|
||||||
|
|
||||||
|
wp_safe_redirect( add_query_arg(
|
||||||
|
array( 'page' => 'mm-tools', 'mm_cleared' => $count ),
|
||||||
|
admin_url( 'themes.php' )
|
||||||
|
) );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
add_action( 'admin_post_mm_tools_clear_cache', 'mm_tools_handle_clear_cache' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* YouTube-API-Key pruefen. Das Ergebnis wird kurz zwischengespeichert und
|
||||||
|
* nach dem Redirect angezeigt; der Key selbst wird nie ausgegeben.
|
||||||
|
*/
|
||||||
|
function mm_tools_handle_test_youtube() {
|
||||||
|
if ( ! current_user_can( 'manage_options' ) ) {
|
||||||
|
wp_die( esc_html__( 'Keine Berechtigung.', 'minecraft-modern-theme' ), 403 );
|
||||||
|
}
|
||||||
|
check_admin_referer( 'mm_tools_test_youtube' );
|
||||||
|
|
||||||
|
$key = get_theme_mod( 'youtube_api_key', '' );
|
||||||
|
if ( empty( $key ) && defined( 'YOUTUBE_API_KEY' ) ) {
|
||||||
|
$key = YOUTUBE_API_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $key ) ) {
|
||||||
|
$result = array( 'ok' => false, 'msg' => __( 'Es ist kein YouTube-API-Key hinterlegt (Customizer → Video & Livestream oder YOUTUBE_API_KEY in der wp-config.php).', 'minecraft-modern-theme' ) );
|
||||||
|
} else {
|
||||||
|
// "videoCategories" kostet nur 1 Quota-Einheit und braucht keine Video-ID.
|
||||||
|
$response = wp_remote_get(
|
||||||
|
'https://www.googleapis.com/youtube/v3/videoCategories?part=snippet®ionCode=DE&key=' . rawurlencode( $key ),
|
||||||
|
array( 'timeout' => 10 )
|
||||||
|
);
|
||||||
|
if ( is_wp_error( $response ) ) {
|
||||||
|
$result = array( 'ok' => false, 'msg' => $response->get_error_message() );
|
||||||
|
} else {
|
||||||
|
$code = wp_remote_retrieve_response_code( $response );
|
||||||
|
$data = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||||
|
if ( 200 === $code ) {
|
||||||
|
$result = array( 'ok' => true, 'msg' => __( 'Der API-Key funktioniert.', 'minecraft-modern-theme' ) );
|
||||||
|
} else {
|
||||||
|
$detail = isset( $data['error']['message'] ) ? $data['error']['message'] : '';
|
||||||
|
$result = array(
|
||||||
|
'ok' => false,
|
||||||
|
/* translators: 1: HTTP status code, 2: error message from the API */
|
||||||
|
'msg' => sprintf( __( 'API-Fehler (HTTP %1$d): %2$s', 'minecraft-modern-theme' ), $code, $detail ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set_transient( 'mm_tools_result_' . get_current_user_id(), $result, 60 );
|
||||||
|
wp_safe_redirect( add_query_arg( array( 'page' => 'mm-tools' ), admin_url( 'themes.php' ) ) );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
add_action( 'admin_post_mm_tools_test_youtube', 'mm_tools_handle_test_youtube' );
|
||||||
|
|
||||||
|
function mm_tools_render_page() {
|
||||||
|
if ( ! current_user_can( 'manage_options' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result_key = 'mm_tools_result_' . get_current_user_id();
|
||||||
|
$result = get_transient( $result_key );
|
||||||
|
if ( $result ) {
|
||||||
|
delete_transient( $result_key );
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php esc_html_e( 'Theme-Werkzeuge', 'minecraft-modern-theme' ); ?></h1>
|
||||||
|
|
||||||
|
<?php if ( isset( $_GET['mm_cleared'] ) ) : ?>
|
||||||
|
<div class="notice notice-success is-dismissible"><p>
|
||||||
|
<?php
|
||||||
|
/* translators: %d: number of deleted cache entries */
|
||||||
|
printf( esc_html__( '%d Cache-Einträge gelöscht.', 'minecraft-modern-theme' ), absint( $_GET['mm_cleared'] ) );
|
||||||
|
?>
|
||||||
|
</p></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ( is_array( $result ) ) : ?>
|
||||||
|
<div class="notice <?php echo $result['ok'] ? 'notice-success' : 'notice-error'; ?> is-dismissible">
|
||||||
|
<p><?php echo esc_html( $result['msg'] ); ?></p>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<h2><?php esc_html_e( 'Zwischenspeicher leeren', 'minecraft-modern-theme' ); ?></h2>
|
||||||
|
<table class="widefat striped" style="max-width:760px;">
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ( mm_tools_cache_groups() as $id => $group ) : ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo esc_html( $group['label'] ); ?></td>
|
||||||
|
<td style="text-align:right;">
|
||||||
|
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
|
||||||
|
<input type="hidden" name="action" value="mm_tools_clear_cache">
|
||||||
|
<input type="hidden" name="group" value="<?php echo esc_attr( $id ); ?>">
|
||||||
|
<?php wp_nonce_field( 'mm_tools_clear_cache' ); ?>
|
||||||
|
<button type="submit" class="button"><?php esc_html_e( 'Leeren', 'minecraft-modern-theme' ); ?></button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2><?php esc_html_e( 'YouTube-API', 'minecraft-modern-theme' ); ?></h2>
|
||||||
|
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
|
||||||
|
<input type="hidden" name="action" value="mm_tools_test_youtube">
|
||||||
|
<?php wp_nonce_field( 'mm_tools_test_youtube' ); ?>
|
||||||
|
<button type="submit" class="button button-secondary"><?php esc_html_e( 'API-Key testen', 'minecraft-modern-theme' ); ?></button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php if ( post_type_exists( 'mm_livestream' ) ) : ?>
|
||||||
|
<h2><?php esc_html_e( 'Livestream-Einträge', 'minecraft-modern-theme' ); ?></h2>
|
||||||
|
<?php
|
||||||
|
$streams = get_posts( array(
|
||||||
|
'post_type' => 'mm_livestream',
|
||||||
|
'posts_per_page' => 100,
|
||||||
|
'post_status' => 'any',
|
||||||
|
) );
|
||||||
|
?>
|
||||||
|
<?php if ( $streams ) : ?>
|
||||||
|
<table class="widefat striped">
|
||||||
|
<thead><tr>
|
||||||
|
<th><?php esc_html_e( 'Titel', 'minecraft-modern-theme' ); ?></th>
|
||||||
|
<th><?php esc_html_e( 'Status', 'minecraft-modern-theme' ); ?></th>
|
||||||
|
<th><?php esc_html_e( 'Profil-URL', 'minecraft-modern-theme' ); ?></th>
|
||||||
|
<th><?php esc_html_e( 'Player-URL', 'minecraft-modern-theme' ); ?></th>
|
||||||
|
</tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ( $streams as $stream ) : ?>
|
||||||
|
<tr>
|
||||||
|
<td><a href="<?php echo esc_url( get_edit_post_link( $stream->ID ) ); ?>"><?php echo esc_html( get_the_title( $stream ) ); ?></a></td>
|
||||||
|
<td><?php echo esc_html( $stream->post_status ); ?></td>
|
||||||
|
<td><?php echo esc_html( get_post_meta( $stream->ID, '_mm_livestream_url', true ) ); ?></td>
|
||||||
|
<td><?php echo esc_html( get_post_meta( $stream->ID, '_mm_livestream_player_url', true ) ); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php else : ?>
|
||||||
|
<p><?php esc_html_e( 'Keine Livestream-Einträge vorhanden.', 'minecraft-modern-theme' ); ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
@@ -1193,6 +1193,10 @@ function mm_video_render_livestream_group( $group, $index = 0 ) {
|
|||||||
|
|
||||||
// --- 4. Embed HTML rendern ---
|
// --- 4. Embed HTML rendern ---
|
||||||
function mm_video_render_embed( $url, $args = array() ) {
|
function mm_video_render_embed( $url, $args = array() ) {
|
||||||
|
// Fallback für Stellen, die mm_is_video_view() nicht erkennt (Widgets,
|
||||||
|
// Page-Builder): Style spätestens jetzt anfordern.
|
||||||
|
wp_enqueue_style( 'mm-video' );
|
||||||
|
|
||||||
$embed_url = mm_video_get_embed_url( $url );
|
$embed_url = mm_video_get_embed_url( $url );
|
||||||
if ( ! $embed_url ) return '<p class="mm-video-error">' . __('Ungültige Video-URL.', 'minecraft-modern-theme') . '</p>';
|
if ( ! $embed_url ) return '<p class="mm-video-error">' . __('Ungültige Video-URL.', 'minecraft-modern-theme') . '</p>';
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
tabButtons.forEach(button => {
|
tabButtons.forEach(button => {
|
||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
// 1. Aktive Klassen von allen Buttons und Panes entfernen
|
// 1. Aktive Klassen von allen Buttons und Panes entfernen
|
||||||
tabButtons.forEach(btn => btn.classList.remove('active'));
|
tabButtons.forEach(btn => { btn.classList.remove('active'); btn.setAttribute('aria-pressed', 'false'); });
|
||||||
tabPanes.forEach(pane => pane.classList.remove('active'));
|
tabPanes.forEach(pane => pane.classList.remove('active'));
|
||||||
|
|
||||||
// 2. Aktive Klasse zum geklickten Button hinzufügen
|
// 2. Aktive Klasse zum geklickten Button hinzufügen
|
||||||
button.classList.add('active');
|
button.classList.add('active');
|
||||||
|
button.setAttribute('aria-pressed', 'true');
|
||||||
|
|
||||||
// 3. Den zugehörigen Inhalt (Pane) finden und aktivieren
|
// 3. Den zugehörigen Inhalt (Pane) finden und aktivieren
|
||||||
const targetCategory = button.getAttribute('data-category');
|
const targetCategory = button.getAttribute('data-category');
|
||||||
@@ -34,6 +35,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
question.addEventListener('click', () => {
|
question.addEventListener('click', () => {
|
||||||
// 'active' Klasse zum aktuellen Item togglen
|
// 'active' Klasse zum aktuellen Item togglen
|
||||||
const isActive = item.classList.toggle('active');
|
const isActive = item.classList.toggle('active');
|
||||||
|
question.setAttribute('aria-expanded', isActive ? 'true' : 'false');
|
||||||
|
|
||||||
// Höhe der Antwort anpassen für smooth slide
|
// Höhe der Antwort anpassen für smooth slide
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/**
|
||||||
|
* Regelwerk → Reihenfolge: Drag & Drop für Kategorien und Regeln.
|
||||||
|
* Erwartet mmRulesOrder (ajaxUrl, nonce, i18n) aus wp_localize_script.
|
||||||
|
*/
|
||||||
|
jQuery(function ($) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var $groups = $('#mm-rules-order-groups');
|
||||||
|
var $save = $('#mm-rules-order-save');
|
||||||
|
var $status = $('#mm-rules-order-status');
|
||||||
|
if (!$groups.length) return;
|
||||||
|
|
||||||
|
var dirty = false;
|
||||||
|
|
||||||
|
// §-Nummern so anzeigen, wie sie auf der Website erscheinen werden.
|
||||||
|
function renumber() {
|
||||||
|
$groups.children('.mm-rules-order__group').each(function (i) {
|
||||||
|
var groupNo = i + 1;
|
||||||
|
$(this).find('> .mm-rules-order__group-head .mm-rules-order__no').text('§' + groupNo);
|
||||||
|
$(this).find('.mm-rules-order__rule').each(function (j) {
|
||||||
|
$(this).find('.mm-rules-order__no').text('§' + groupNo + '.' + (j + 1));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function markDirty() {
|
||||||
|
dirty = true;
|
||||||
|
$status.removeClass('is-error is-ok').text(mmRulesOrder.i18n.dirty);
|
||||||
|
renumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kategorien sortieren; "Allgemein" (ohne Kategorie) bleibt oben stehen.
|
||||||
|
$groups.sortable({
|
||||||
|
items: '> .mm-rules-order__group:not(.is-fixed)',
|
||||||
|
handle: '> .mm-rules-order__group-head .mm-rules-order__handle',
|
||||||
|
axis: 'y',
|
||||||
|
placeholder: 'mm-rules-order__placeholder',
|
||||||
|
forcePlaceholderSize: true,
|
||||||
|
update: markDirty
|
||||||
|
});
|
||||||
|
|
||||||
|
// Regeln innerhalb ihrer Kategorie sortieren.
|
||||||
|
$groups.find('.mm-rules-order__rules').sortable({
|
||||||
|
handle: '.mm-rules-order__handle',
|
||||||
|
axis: 'y',
|
||||||
|
placeholder: 'mm-rules-order__placeholder',
|
||||||
|
forcePlaceholderSize: true,
|
||||||
|
update: markDirty
|
||||||
|
});
|
||||||
|
|
||||||
|
$save.on('click', function () {
|
||||||
|
var terms = $groups.children('.mm-rules-order__group').map(function () {
|
||||||
|
return $(this).data('term');
|
||||||
|
}).get();
|
||||||
|
var rules = $groups.find('.mm-rules-order__rule').map(function () {
|
||||||
|
return $(this).data('id');
|
||||||
|
}).get();
|
||||||
|
|
||||||
|
$save.prop('disabled', true);
|
||||||
|
$status.removeClass('is-error is-ok').text(mmRulesOrder.i18n.saving);
|
||||||
|
|
||||||
|
$.post(mmRulesOrder.ajaxUrl, {
|
||||||
|
action: 'mm_rules_order_save',
|
||||||
|
nonce: mmRulesOrder.nonce,
|
||||||
|
terms: terms,
|
||||||
|
rules: rules
|
||||||
|
}).done(function (res) {
|
||||||
|
if (res && res.success) {
|
||||||
|
dirty = false;
|
||||||
|
$status.addClass('is-ok').text(mmRulesOrder.i18n.saved);
|
||||||
|
} else {
|
||||||
|
$status.addClass('is-error').text(mmRulesOrder.i18n.error);
|
||||||
|
}
|
||||||
|
}).fail(function () {
|
||||||
|
$status.addClass('is-error').text(mmRulesOrder.i18n.error);
|
||||||
|
}).always(function () {
|
||||||
|
$save.prop('disabled', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Warnen, wenn die Seite mit ungespeicherter Reihenfolge verlassen wird.
|
||||||
|
$(window).on('beforeunload', function () {
|
||||||
|
if (dirty) return mmRulesOrder.i18n.dirty;
|
||||||
|
});
|
||||||
|
|
||||||
|
renumber();
|
||||||
|
});
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
/**
|
||||||
|
* Regelwerk: immer nur eine Kategorie anzeigen, Regeln auf- und zuklappen.
|
||||||
|
*
|
||||||
|
* Das Inhaltsverzeichnis schaltet zwischen den Kategorien um. Direktlinks
|
||||||
|
* funktionieren weiter: #regeln-<kategorie> öffnet die Kategorie,
|
||||||
|
* #regel-1-2 öffnet zusätzlich die Regel und springt dorthin.
|
||||||
|
*/
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var root = document.querySelector('[data-mm-rules-tabs]');
|
||||||
|
if (!root) return;
|
||||||
|
|
||||||
|
var groups = Array.prototype.slice.call(root.querySelectorAll('.mm-rules__group'));
|
||||||
|
var tabs = Array.prototype.slice.call(root.querySelectorAll('[data-mm-rules-tab]'));
|
||||||
|
if (!groups.length) return;
|
||||||
|
|
||||||
|
function setRule(rule, open) {
|
||||||
|
var toggle = rule.querySelector('.mm-rules__toggle');
|
||||||
|
rule.classList.toggle('is-open', open);
|
||||||
|
if (toggle) toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateExpandButton(group) {
|
||||||
|
var button = group.querySelector('[data-mm-rules-expand]');
|
||||||
|
if (!button) return;
|
||||||
|
var rules = group.querySelectorAll('.mm-rules__rule');
|
||||||
|
var allOpen = rules.length > 0 && group.querySelectorAll('.mm-rules__rule.is-open').length === rules.length;
|
||||||
|
button.textContent = allOpen ? button.getAttribute('data-close') : button.getAttribute('data-open');
|
||||||
|
button.setAttribute('aria-pressed', allOpen ? 'true' : 'false');
|
||||||
|
}
|
||||||
|
|
||||||
|
function showGroup(id) {
|
||||||
|
var found = false;
|
||||||
|
groups.forEach(function (group) {
|
||||||
|
var active = group.id === id;
|
||||||
|
group.classList.toggle('is-active', active);
|
||||||
|
if (active) found = true;
|
||||||
|
});
|
||||||
|
if (!found) return false;
|
||||||
|
tabs.forEach(function (tab) {
|
||||||
|
if (tab.getAttribute('data-mm-rules-tab') === id) {
|
||||||
|
tab.setAttribute('aria-current', 'true');
|
||||||
|
} else {
|
||||||
|
tab.removeAttribute('aria-current');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setHash(id) {
|
||||||
|
if (history.replaceState) {
|
||||||
|
history.replaceState(null, '', '#' + id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Öffnet, was die Adresse (#…) verlangt. Gibt true zurück, wenn etwas gepasst hat.
|
||||||
|
function openFromHash(scroll) {
|
||||||
|
var id = decodeURIComponent(location.hash.replace(/^#/, ''));
|
||||||
|
if (!id) return false;
|
||||||
|
var target = document.getElementById(id);
|
||||||
|
if (!target || !root.contains(target)) return false;
|
||||||
|
|
||||||
|
if (target.classList.contains('mm-rules__group')) {
|
||||||
|
showGroup(id);
|
||||||
|
if (scroll) target.scrollIntoView({ block: 'start' });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (target.classList.contains('mm-rules__rule')) {
|
||||||
|
var group = target.closest('.mm-rules__group');
|
||||||
|
if (group) showGroup(group.id);
|
||||||
|
root.querySelectorAll('.mm-rules__rule.is-linked').forEach(function (r) { r.classList.remove('is-linked'); });
|
||||||
|
setRule(target, true);
|
||||||
|
target.classList.add('is-linked');
|
||||||
|
if (group) updateExpandButton(group);
|
||||||
|
if (scroll) target.scrollIntoView({ block: 'start' });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
root.addEventListener('click', function (e) {
|
||||||
|
// Kategorie wechseln
|
||||||
|
var tab = e.target.closest('[data-mm-rules-tab]');
|
||||||
|
if (tab) {
|
||||||
|
e.preventDefault();
|
||||||
|
var id = tab.getAttribute('data-mm-rules-tab');
|
||||||
|
if (showGroup(id)) {
|
||||||
|
setHash(id);
|
||||||
|
// Auf schmalen Bildschirmen steht das Inhaltsverzeichnis über
|
||||||
|
// dem Inhalt – dann zur gewählten Kategorie springen.
|
||||||
|
var group = document.getElementById(id);
|
||||||
|
if (group && group.getBoundingClientRect().top > window.innerHeight * 0.6) {
|
||||||
|
group.scrollIntoView({ block: 'start' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Einzelne Regel auf-/zuklappen
|
||||||
|
var toggle = e.target.closest('.mm-rules__toggle');
|
||||||
|
if (toggle) {
|
||||||
|
var rule = toggle.closest('.mm-rules__rule');
|
||||||
|
setRule(rule, !rule.classList.contains('is-open'));
|
||||||
|
updateExpandButton(rule.closest('.mm-rules__group'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alle Regeln der Kategorie auf-/zuklappen
|
||||||
|
var expand = e.target.closest('[data-mm-rules-expand]');
|
||||||
|
if (expand) {
|
||||||
|
var grp = expand.closest('.mm-rules__group');
|
||||||
|
var rules = Array.prototype.slice.call(grp.querySelectorAll('.mm-rules__rule'));
|
||||||
|
var allOpen = rules.every(function (r) { return r.classList.contains('is-open'); });
|
||||||
|
rules.forEach(function (r) { setRule(r, !allOpen); });
|
||||||
|
updateExpandButton(grp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('hashchange', function () { openFromHash(true); });
|
||||||
|
|
||||||
|
// Start: Ziel aus der Adresse, sonst die erste Kategorie.
|
||||||
|
if (!openFromHash(true)) {
|
||||||
|
showGroup(groups[0].id);
|
||||||
|
}
|
||||||
|
groups.forEach(updateExpandButton);
|
||||||
|
})();
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
* Server-Status: Live-Aktualisierung und "Adresse kopieren".
|
||||||
|
* Erwartet mmServerStatus (ajaxUrl, i18n) aus wp_localize_script.
|
||||||
|
*/
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
if (typeof mmServerStatus === 'undefined') return;
|
||||||
|
|
||||||
|
var REFRESH_MS = 60000;
|
||||||
|
var boxes = [];
|
||||||
|
|
||||||
|
function apply(box, status) {
|
||||||
|
var online = !!status.online;
|
||||||
|
box.setAttribute('data-state', online ? 'online' : 'offline');
|
||||||
|
|
||||||
|
var label = box.querySelector('[data-mm-label]');
|
||||||
|
if (label) label.textContent = online ? mmServerStatus.i18n.online : mmServerStatus.i18n.offline;
|
||||||
|
|
||||||
|
var players = box.querySelector('[data-mm-players]');
|
||||||
|
if (players) {
|
||||||
|
players.hidden = !online;
|
||||||
|
if (online) {
|
||||||
|
var count = Number(status.players) || 0;
|
||||||
|
var max = Number(status.max) || 0;
|
||||||
|
var onlineEl = players.querySelector('[data-mm-online]');
|
||||||
|
var maxEl = players.querySelector('[data-mm-max]');
|
||||||
|
var meter = players.querySelector('[data-mm-meter]');
|
||||||
|
if (onlineEl) onlineEl.textContent = count.toLocaleString();
|
||||||
|
if (maxEl) maxEl.textContent = max.toLocaleString();
|
||||||
|
if (meter) {
|
||||||
|
// Wie in PHP: ab einem Spieler mindestens 4 % sichtbar.
|
||||||
|
var fill = (max < 1 || count < 1) ? 0 : Math.max(4, Math.min(100, Math.round(count / max * 100)));
|
||||||
|
meter.style.width = fill + '%';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var version = box.querySelector('[data-mm-version]');
|
||||||
|
if (version) {
|
||||||
|
version.hidden = !(online && status.version);
|
||||||
|
var vText = version.querySelector('[data-mm-version-text]');
|
||||||
|
if (vText) vText.textContent = status.version || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function refresh() {
|
||||||
|
// Im Hintergrund-Tab nicht abfragen.
|
||||||
|
if (document.hidden || !boxes.length) return;
|
||||||
|
|
||||||
|
fetch(mmServerStatus.ajaxUrl + '?action=mm_server_status', { credentials: 'same-origin' })
|
||||||
|
.then(function (r) { return r.ok ? r.json() : null; })
|
||||||
|
.then(function (res) {
|
||||||
|
if (!res || !res.success || !res.data) return;
|
||||||
|
boxes.forEach(function (box) { apply(box, res.data); });
|
||||||
|
})
|
||||||
|
.catch(function () { /* Anzeige bleibt beim letzten bekannten Stand */ });
|
||||||
|
}
|
||||||
|
|
||||||
|
function copy(button) {
|
||||||
|
var value = button.getAttribute('data-mm-copy');
|
||||||
|
var text = button.querySelector('[data-mm-copy-text]');
|
||||||
|
if (!value || !text) return;
|
||||||
|
|
||||||
|
function done() {
|
||||||
|
var original = value;
|
||||||
|
text.textContent = mmServerStatus.i18n.copied;
|
||||||
|
button.classList.add('is-copied');
|
||||||
|
setTimeout(function () {
|
||||||
|
text.textContent = original;
|
||||||
|
button.classList.remove('is-copied');
|
||||||
|
}, 1800);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
|
navigator.clipboard.writeText(value).then(done).catch(function () {});
|
||||||
|
} else {
|
||||||
|
// Fallback für http:// und ältere Browser.
|
||||||
|
var field = document.createElement('textarea');
|
||||||
|
field.value = value;
|
||||||
|
field.setAttribute('readonly', '');
|
||||||
|
field.style.position = 'fixed';
|
||||||
|
field.style.opacity = '0';
|
||||||
|
document.body.appendChild(field);
|
||||||
|
field.select();
|
||||||
|
try { if (document.execCommand('copy')) done(); } catch (e) { /* nicht unterstützt */ }
|
||||||
|
document.body.removeChild(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
boxes = Array.prototype.slice.call(document.querySelectorAll('[data-mm-server-status]'));
|
||||||
|
if (!boxes.length) return;
|
||||||
|
|
||||||
|
document.addEventListener('click', function (e) {
|
||||||
|
var button = e.target.closest ? e.target.closest('[data-mm-copy]') : null;
|
||||||
|
if (button) copy(button);
|
||||||
|
});
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
setInterval(refresh, REFRESH_MS);
|
||||||
|
document.addEventListener('visibilitychange', function () {
|
||||||
|
if (!document.hidden) refresh();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -12,6 +12,10 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nutzer mit Systemeinstellung "Bewegung reduzieren" bekommen keinen
|
||||||
|
// automatischen Wechsel; Pfeile und Punkte funktionieren weiterhin.
|
||||||
|
const reduceMotion = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||||
|
|
||||||
const swiperConfig = {
|
const swiperConfig = {
|
||||||
effect: 'fade',
|
effect: 'fade',
|
||||||
fadeEffect: {
|
fadeEffect: {
|
||||||
@@ -20,12 +24,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
loop: sliderSettings.loop === '1',
|
loop: sliderSettings.loop === '1',
|
||||||
|
|
||||||
autoplay: {
|
autoplay: reduceMotion ? false : {
|
||||||
delay: 5000,
|
delay: 5000,
|
||||||
disableOnInteraction: false,
|
disableOnInteraction: false,
|
||||||
|
// BUG-FIX: stand vorher außerhalb von "autoplay" und wurde von
|
||||||
|
// Swiper deshalb ignoriert.
|
||||||
|
pauseOnMouseEnter: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
pauseOnMouseEnter: true,
|
a11y: {
|
||||||
|
prevSlideMessage: (window.sliderSettings && sliderSettings.prevLabel) || 'Previous slide',
|
||||||
|
nextSlideMessage: (window.sliderSettings && sliderSettings.nextLabel) || 'Next slide',
|
||||||
|
},
|
||||||
|
|
||||||
navigation: sliderSettings.hideArrows !== '1' ? {
|
navigation: sliderSettings.hideArrows !== '1' ? {
|
||||||
nextEl: '.swiper-button-next',
|
nextEl: '.swiper-button-next',
|
||||||
|
|||||||
@@ -6,12 +6,20 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
const iconMoon = toggle.querySelector('.icon-moon');
|
const iconMoon = toggle.querySelector('.icon-moon');
|
||||||
const iconSun = toggle.querySelector('.icon-sun');
|
const iconSun = toggle.querySelector('.icon-sun');
|
||||||
|
|
||||||
const defaultMode = typeof sliderSettings !== 'undefined' && sliderSettings.defaultMode
|
const defaultMode = typeof mmTheme !== 'undefined' && mmTheme.defaultMode
|
||||||
? sliderSettings.defaultMode
|
? mmTheme.defaultMode
|
||||||
: 'dark';
|
: 'dark';
|
||||||
|
|
||||||
// Gespeicherten Wert laden oder OS-Schema/Theme-Default als Fallback
|
// Gespeicherten Wert laden oder OS-Schema/Theme-Default als Fallback
|
||||||
let saved = localStorage.getItem('themeMode');
|
// localStorage kann gesperrt sein (privates Fenster, blockierte Website-Daten).
|
||||||
|
function readMode() {
|
||||||
|
try { return localStorage.getItem('themeMode'); } catch (e) { return null; }
|
||||||
|
}
|
||||||
|
function writeMode( mode ) {
|
||||||
|
try { localStorage.setItem('themeMode', mode); } catch (e) { /* Auswahl gilt dann nur für diesen Besuch */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
let saved = readMode();
|
||||||
if ( ! saved ) {
|
if ( ! saved ) {
|
||||||
saved = ( window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches )
|
saved = ( window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches )
|
||||||
? 'light'
|
? 'light'
|
||||||
@@ -39,13 +47,13 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
const isCurrentlyLight = html.classList.contains('light-mode');
|
const isCurrentlyLight = html.classList.contains('light-mode');
|
||||||
const newMode = isCurrentlyLight ? 'dark' : 'light';
|
const newMode = isCurrentlyLight ? 'dark' : 'light';
|
||||||
applyMode( newMode );
|
applyMode( newMode );
|
||||||
localStorage.setItem('themeMode', newMode);
|
writeMode( newMode );
|
||||||
});
|
});
|
||||||
|
|
||||||
// Live-Reaktion auf OS-Umschalten (nur wenn keine manuelle Auswahl)
|
// Live-Reaktion auf OS-Umschalten (nur wenn keine manuelle Auswahl)
|
||||||
if ( window.matchMedia ) {
|
if ( window.matchMedia ) {
|
||||||
window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', function( e ) {
|
window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', function( e ) {
|
||||||
if ( ! localStorage.getItem('themeMode') ) {
|
if ( ! readMode() ) {
|
||||||
applyMode( e.matches ? 'light' : 'dark' );
|
applyMode( e.matches ? 'light' : 'dark' );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user