Upload via GUI (1 Datei)
This commit is contained in:
+149
-13
@@ -22,6 +22,137 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// AVATAR-DIENSTE MIT FALLBACK
|
||||||
|
// Reihenfolge: mc-heads.net -> minotar.net -> crafatar.com
|
||||||
|
// ===============================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liefert eine Liste von Bild-URLs (Primär-Dienst zuerst, danach Fallbacks).
|
||||||
|
* $type: 'head' | 'body'. Crafatar kennt nur UUIDs und wird sonst übersprungen.
|
||||||
|
*/
|
||||||
|
function mcph_avatar_urls( $id, $size = 100, $type = 'head', $uuid = '' ) {
|
||||||
|
$id = trim( (string) $id );
|
||||||
|
$uuid = trim( (string) $uuid );
|
||||||
|
$size = max( 16, intval( $size ) );
|
||||||
|
$enc = rawurlencode( $id );
|
||||||
|
$uuid_re = '/^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i';
|
||||||
|
// Echte UUID für Dienste, die keine Namen kennen (mineatar)
|
||||||
|
$real_uuid = preg_match( $uuid_re, $uuid ) ? $uuid : ( preg_match( $uuid_re, $id ) ? $id : '' );
|
||||||
|
$scale = max( 1, (int) round( $size / 12.5 ) ); // mineatar arbeitet mit Skalierungsfaktor
|
||||||
|
|
||||||
|
$urls = array();
|
||||||
|
if ( $type === 'body' ) {
|
||||||
|
$urls[] = "https://mc-heads.net/body/{$enc}/{$size}";
|
||||||
|
$urls[] = "https://minotar.net/armor/body/{$enc}/{$size}.png";
|
||||||
|
// Letzte Reserve mit 3D-Optik: Kopf
|
||||||
|
if ( $real_uuid ) $urls[] = 'https://api.mineatar.io/head/' . rawurlencode( $real_uuid ) . "?scale={$scale}&overlay";
|
||||||
|
} else {
|
||||||
|
// 1. mc-heads.net (3D-Kopf) 2. mineatar.io (3D-Kopf, nur UUID) 3. minotar.net (flach, letzte Reserve)
|
||||||
|
$urls[] = "https://mc-heads.net/head/{$enc}/{$size}";
|
||||||
|
if ( $real_uuid ) $urls[] = 'https://api.mineatar.io/head/' . rawurlencode( $real_uuid ) . "?scale={$scale}&overlay";
|
||||||
|
$urls[] = "https://minotar.net/helm/{$enc}/{$size}.png";
|
||||||
|
}
|
||||||
|
return $urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gibt die Attribute src + data-mcph-fallbacks für ein <img> aus. */
|
||||||
|
function mcph_avatar_attrs( $id, $size = 100, $type = 'head', $uuid = '' ) {
|
||||||
|
$urls = mcph_avatar_urls( $id, $size, $type, $uuid );
|
||||||
|
return 'src="' . esc_url( $urls[0] ) . '" data-mcph-fallbacks="' . esc_attr( wp_json_encode( $urls ) ) . '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Welche Kennung wird für den Avatar genutzt? (gleiche Logik wie vorher:
|
||||||
|
* Bedrock-/Punkt-Namen und xuid -> UUID, sonst Benutzername)
|
||||||
|
*/
|
||||||
|
function mcph_avatar_identifier( $row ) {
|
||||||
|
$name = isset( $row->username ) ? (string) $row->username : '';
|
||||||
|
$uuid = isset( $row->uuid ) ? (string) $row->uuid : '';
|
||||||
|
if ( ( strpos( $name, '.' ) !== false || strpos( $uuid, 'xuid' ) === 0 ) && $uuid !== '' ) {
|
||||||
|
return $uuid;
|
||||||
|
}
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Globaler Fallback-Handler: wechselt bei Ladefehler ODER nach 4 s ohne Antwort
|
||||||
|
* auf die nächste URL. Arbeitet auch für per AJAX nachgeladene Bilder.
|
||||||
|
*/
|
||||||
|
add_action( 'wp_head', 'mcph_print_avatar_fallback_script', 1 );
|
||||||
|
function mcph_print_avatar_fallback_script() {
|
||||||
|
?>
|
||||||
|
<script>
|
||||||
|
(function(){
|
||||||
|
if (window.mcphAvatarFallback) return; window.mcphAvatarFallback = true;
|
||||||
|
var TTL = 10 * 60 * 1000, TIMEOUT = 4000, KEY = 'mcph_bad_hosts';
|
||||||
|
var bad = {}, since = {};
|
||||||
|
try { bad = JSON.parse(localStorage.getItem(KEY) || '{}') || {}; } catch (e) {}
|
||||||
|
function save() { try { localStorage.setItem(KEY, JSON.stringify(bad)); } catch (e) {} }
|
||||||
|
function host(u) { var a = document.createElement('a'); a.href = u; return a.host; }
|
||||||
|
function isBad(u) { var e = bad[host(u)]; return !!e && e > Date.now(); }
|
||||||
|
function markBad(u) { bad[host(u)] = Date.now() + TTL; save(); }
|
||||||
|
function getList(img) { try { return JSON.parse(img.getAttribute('data-mcph-fallbacks') || '[]'); } catch (e) { return []; } }
|
||||||
|
function idxOf(img, l) { var i = l.indexOf(img.getAttribute('src')); return i < 0 ? 0 : i; }
|
||||||
|
|
||||||
|
// Bild auf den ersten Dienst setzen, der nicht als "hängend" markiert ist
|
||||||
|
function fix(img) {
|
||||||
|
var l = getList(img); if (!l.length) return;
|
||||||
|
var j = idxOf(img, l);
|
||||||
|
while (j < l.length && isBad(l[j])) j++;
|
||||||
|
if (j < l.length && l[j] !== img.getAttribute('src')) img.src = l[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ladefehler: nächsten Dienst probieren
|
||||||
|
document.addEventListener('error', function (e) {
|
||||||
|
var img = e.target;
|
||||||
|
if (!img || img.tagName !== 'IMG' || !img.hasAttribute('data-mcph-fallbacks')) return;
|
||||||
|
var l = getList(img), j = idxOf(img, l) + 1;
|
||||||
|
while (j < l.length && isBad(l[j])) j++;
|
||||||
|
if (j < l.length) img.src = l[j]; else img.removeAttribute('data-mcph-fallbacks');
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
// Erfolgreich geladen: Timer für diese URL zurücksetzen (Dienst funktioniert)
|
||||||
|
document.addEventListener('load', function (e) {
|
||||||
|
var img = e.target;
|
||||||
|
if (img && img.tagName === 'IMG' && img.hasAttribute('data-mcph-fallbacks')) delete since[img.getAttribute('src')];
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
// Neu eingefügte Bilder (z. B. Live-Aktualisierung der Liste) sofort korrigieren
|
||||||
|
new MutationObserver(function (ms) {
|
||||||
|
ms.forEach(function (m) {
|
||||||
|
m.addedNodes.forEach(function (n) {
|
||||||
|
if (n.nodeType !== 1) return;
|
||||||
|
if (n.matches && n.matches('img[data-mcph-fallbacks]')) fix(n);
|
||||||
|
else if (n.querySelectorAll) n.querySelectorAll('img[data-mcph-fallbacks]').forEach(fix);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).observe(document.documentElement, { childList: true, subtree: true });
|
||||||
|
|
||||||
|
// Hängende Dienste (keine Antwort) erkennen. Zeitpunkt wird pro URL gemerkt,
|
||||||
|
// damit ein Austausch der Bilder den Timer nicht zurücksetzt.
|
||||||
|
setInterval(function () {
|
||||||
|
var imgs = document.querySelectorAll('img[data-mcph-fallbacks]');
|
||||||
|
for (var k = 0; k < imgs.length; k++) {
|
||||||
|
var img = imgs[k];
|
||||||
|
fix(img);
|
||||||
|
var u = img.getAttribute('src');
|
||||||
|
if (img.complete) { if (img.naturalWidth > 0) delete since[u]; continue; }
|
||||||
|
var r = img.getBoundingClientRect();
|
||||||
|
if (r.top > window.innerHeight + 300 || r.bottom < -300) continue; // Lazy-Bilder außerhalb des Bildschirms nicht anfassen
|
||||||
|
if (!since[u]) { since[u] = Date.now(); continue; }
|
||||||
|
if (Date.now() - since[u] > TIMEOUT) {
|
||||||
|
var l = getList(img);
|
||||||
|
if (idxOf(img, l) < l.length - 1) { markBad(u); fix(img); } // letzten Dienst nie sperren
|
||||||
|
delete since[u];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
// ===============================
|
// ===============================
|
||||||
// MC PLAYER HISTORY - UPDATE SYSTEM
|
// MC PLAYER HISTORY - UPDATE SYSTEM
|
||||||
// ===============================
|
// ===============================
|
||||||
@@ -809,12 +940,8 @@ function mcph_generate_player_html( $limit = 500, $only_online = false, $is_ajax
|
|||||||
$username = esc_html( $row->username );
|
$username = esc_html( $row->username );
|
||||||
$prefix = mcph_parse_minecraft_colors( $row->prefix );
|
$prefix = mcph_parse_minecraft_colors( $row->prefix );
|
||||||
|
|
||||||
// Avatar
|
// Avatar (mit Fallback-Diensten)
|
||||||
if ( strpos( $username, '.' ) !== false || ( isset($row->uuid) && strpos($row->uuid, 'xuid') === 0 ) ) {
|
$avatar_attrs = mcph_avatar_attrs( mcph_avatar_identifier( $row ), 100, 'head', isset( $row->uuid ) ? $row->uuid : '' );
|
||||||
$avatar = isset($row->uuid) && !empty($row->uuid) ? 'https://mc-heads.net/head/' . esc_attr($row->uuid) . '/100' : 'https://mc-heads.net/head/' . $username . '/100';
|
|
||||||
} else {
|
|
||||||
$avatar = 'https://mc-heads.net/head/' . $username . '/100';
|
|
||||||
}
|
|
||||||
|
|
||||||
$anim_style = ! $is_ajax ? 'animation: fadeInUp 0.5s ease forwards; opacity: 0; animation-delay: ' . ( $displayed_count * 0.05 ) . 's;' : '';
|
$anim_style = ! $is_ajax ? 'animation: fadeInUp 0.5s ease forwards; opacity: 0; animation-delay: ' . ( $displayed_count * 0.05 ) . 's;' : '';
|
||||||
|
|
||||||
@@ -827,7 +954,7 @@ function mcph_generate_player_html( $limit = 500, $only_online = false, $is_ajax
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo '<div class="mc-player-card" data-uuid="' . esc_attr( $row->uuid ) . '" data-username="' . esc_attr( $row->username ) . '" style="' . $anim_style . '">';
|
echo '<div class="mc-player-card" data-uuid="' . esc_attr( $row->uuid ) . '" data-username="' . esc_attr( $row->username ) . '" style="' . $anim_style . '">';
|
||||||
echo '<img src="' . $avatar . '" class="mc-avatar" alt="' . $username . '" loading="lazy">';
|
echo '<img ' . $avatar_attrs . ' class="mc-avatar" alt="' . $username . '" loading="lazy">';
|
||||||
echo '<div class="mc-info-stack">';
|
echo '<div class="mc-info-stack">';
|
||||||
if ( ! empty( $row->prefix ) && ! empty( $ds['show_prefix'] ) ) echo '<span class="mc-prefix">' . $prefix . '</span>';
|
if ( ! empty( $row->prefix ) && ! empty( $ds['show_prefix'] ) ) echo '<span class="mc-prefix">' . $prefix . '</span>';
|
||||||
echo '<span class="mc-name">' . $username . '</span>';
|
echo '<span class="mc-name">' . $username . '</span>';
|
||||||
@@ -1155,8 +1282,17 @@ function mcph_shortcode( $atts ) {
|
|||||||
if (!data.success) { panel.innerHTML = '<p style="color:red;text-align:center">Fehler beim Laden.</p>'; return; }
|
if (!data.success) { panel.innerHTML = '<p style="color:red;text-align:center">Fehler beim Laden.</p>'; return; }
|
||||||
const p = data.data;
|
const p = data.data;
|
||||||
|
|
||||||
const avatarHead = `https://mc-heads.net/head/${encodeURIComponent(p.uuid)}/120`;
|
// Avatar-Kette: Body (mc-heads -> minotar -> crafatar), danach Head als letzte Reserve
|
||||||
const avatarBody = `https://mc-heads.net/body/${encodeURIComponent(p.uuid)}/100`;
|
const mcphUuid = encodeURIComponent(p.uuid);
|
||||||
|
const mcphIsUuid = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i.test(p.uuid);
|
||||||
|
const avatarChain = [
|
||||||
|
`https://mc-heads.net/body/${mcphUuid}/100`,
|
||||||
|
`https://minotar.net/armor/body/${mcphUuid}/100.png`
|
||||||
|
];
|
||||||
|
avatarChain.push(`https://mc-heads.net/head/${mcphUuid}/120`);
|
||||||
|
if (mcphIsUuid) avatarChain.push(`https://api.mineatar.io/head/${mcphUuid}?scale=10&overlay`);
|
||||||
|
avatarChain.push(`https://minotar.net/helm/${mcphUuid}/120.png`);
|
||||||
|
const avatarChainAttr = JSON.stringify(avatarChain).replace(/'/g, '%27');
|
||||||
const prefixHtml = parseMinecraftColors(p.prefix);
|
const prefixHtml = parseMinecraftColors(p.prefix);
|
||||||
const onlineHtml = p.is_online
|
const onlineHtml = p.is_online
|
||||||
? '<span class="mc-status mc-online">🟢 Online</span>'
|
? '<span class="mc-status mc-online">🟢 Online</span>'
|
||||||
@@ -1198,7 +1334,7 @@ function mcph_shortcode( $atts ) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mc-profile-header-right">
|
<div class="mc-profile-header-right">
|
||||||
<img src="${avatarBody}" class="mc-profile-avatar" alt="${p.username}" onerror="this.src='${avatarHead}'">
|
<img src="${avatarChain[0]}" data-mcph-fallbacks='${avatarChainAttr}' class="mc-profile-avatar" alt="${p.username}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1477,12 +1613,12 @@ class MC_Top_Playtime_Widget extends WP_Widget {
|
|||||||
$time_string = self::format_duration( $row->playtime_seconds );
|
$time_string = self::format_duration( $row->playtime_seconds );
|
||||||
$raw_prefix = isset( $row->prefix ) ? $row->prefix : '';
|
$raw_prefix = isset( $row->prefix ) ? $row->prefix : '';
|
||||||
$prefix_html = self::parse_minecraft_color_codes_inline( $raw_prefix );
|
$prefix_html = self::parse_minecraft_color_codes_inline( $raw_prefix );
|
||||||
$avatar = isset( $row->uuid ) && ! empty( $row->uuid ) ? 'https://mc-heads.net/head/' . esc_attr( $row->uuid ) . '/50' : 'https://mc-heads.net/head/' . rawurlencode( $username ) . '/50';
|
$avatar_attrs = mcph_avatar_attrs( ( isset( $row->uuid ) && ! empty( $row->uuid ) ) ? $row->uuid : $row->username, 50, 'head' );
|
||||||
?>
|
?>
|
||||||
<?php if ( $columns === 1 ): ?>
|
<?php if ( $columns === 1 ): ?>
|
||||||
<div class="mc-top-item">
|
<div class="mc-top-item">
|
||||||
<div class="mc-top-rank"><?php echo esc_html( $rank ); ?></div>
|
<div class="mc-top-rank"><?php echo esc_html( $rank ); ?></div>
|
||||||
<img src="<?php echo esc_url( $avatar ); ?>" class="mc-top-avatar" alt="<?php echo $username; ?>">
|
<img <?php echo $avatar_attrs; ?> class="mc-top-avatar" alt="<?php echo $username; ?>">
|
||||||
<div class="mc-top-info">
|
<div class="mc-top-info">
|
||||||
<?php if ( ! empty( $prefix_html ) ): ?><div class="mc-top-prefix"><?php echo wp_kses_post( $prefix_html ); ?></div><?php endif; ?>
|
<?php if ( ! empty( $prefix_html ) ): ?><div class="mc-top-prefix"><?php echo wp_kses_post( $prefix_html ); ?></div><?php endif; ?>
|
||||||
<div class="mc-top-name"><?php echo $username; ?></div>
|
<div class="mc-top-name"><?php echo $username; ?></div>
|
||||||
@@ -1492,7 +1628,7 @@ class MC_Top_Playtime_Widget extends WP_Widget {
|
|||||||
<?php $rank++; ?>
|
<?php $rank++; ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<div class="mc-top-item mc-compact">
|
<div class="mc-top-item mc-compact">
|
||||||
<img src="<?php echo esc_url( $avatar ); ?>" class="mc-top-avatar" alt="<?php echo $username; ?>">
|
<img <?php echo $avatar_attrs; ?> class="mc-top-avatar" alt="<?php echo $username; ?>">
|
||||||
<?php if ( ! empty( $prefix_html ) ): ?><div class="mc-top-prefix"><?php echo wp_kses_post( $prefix_html ); ?></div><?php endif; ?>
|
<?php if ( ! empty( $prefix_html ) ): ?><div class="mc-top-prefix"><?php echo wp_kses_post( $prefix_html ); ?></div><?php endif; ?>
|
||||||
<div class="mc-top-name"><?php echo $username; ?></div>
|
<div class="mc-top-name"><?php echo $username; ?></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user