Update from Git Manager GUI
This commit is contained in:
@@ -3,12 +3,16 @@ if (!defined('ABSPATH')) exit;
|
||||
|
||||
class MC_Gallery_Shortcodes {
|
||||
|
||||
private static $modal_rendered = false;
|
||||
|
||||
public static function init() {
|
||||
add_shortcode('mc_gallery_overview', [__CLASS__, 'shortcode_overview']);
|
||||
add_shortcode('mc_gallery_player', [__CLASS__, 'shortcode_player']);
|
||||
add_shortcode('mc_gallery_upload', [__CLASS__, 'shortcode_upload']);
|
||||
add_shortcode('mc_gallery_combined', [__CLASS__, 'shortcode_combined']);
|
||||
add_shortcode('mc_gallery_all_albums', [__CLASS__, 'shortcode_all_albums_overview']);
|
||||
|
||||
add_shortcode('mc_gallery_vote', [__CLASS__, 'shortcode_vote_board']);
|
||||
|
||||
add_shortcode('mc_gallery', [__CLASS__, 'shortcode_overview']);
|
||||
}
|
||||
|
||||
@@ -110,13 +114,15 @@ class MC_Gallery_Shortcodes {
|
||||
$albums = [];
|
||||
if (!empty($player_gallery_ids)) {
|
||||
$albums = get_posts([
|
||||
'post_type' => 'mc_album',
|
||||
'post_type' => 'mc_album',
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => 'mc_gallery_id',
|
||||
'value' => $player_gallery_ids,
|
||||
'compare' => 'IN',
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC'
|
||||
'meta_query' => [[
|
||||
'key' => 'mc_gallery_id',
|
||||
'value' => $player_gallery_ids,
|
||||
'compare' => 'IN',
|
||||
]],
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC'
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -128,12 +134,13 @@ class MC_Gallery_Shortcodes {
|
||||
|
||||
foreach ($albums as $album) {
|
||||
$album_images = get_posts([
|
||||
'post_type' => 'attachment',
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => 1,
|
||||
'post_mime_type' => 'image',
|
||||
'post_parent' => get_post_meta($album->ID, 'mc_gallery_id', true),
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC'
|
||||
'post_parent' => get_post_meta($album->ID, 'mc_gallery_id', true),
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC'
|
||||
]);
|
||||
|
||||
$cover_url = '';
|
||||
@@ -226,6 +233,7 @@ class MC_Gallery_Shortcodes {
|
||||
$out .= '<div class="mc-date-badge">'.$upload_date.'</div>';
|
||||
}
|
||||
$out .= '<img src="'.esc_url($thumb).'" alt="'.esc_attr($q_player).'" loading="lazy" style="aspect-ratio: '.$aspect_ratio.';">';
|
||||
$out .= self::render_like_btn($img->ID);
|
||||
$out .= '<div class="mc-gallery-overlay">';
|
||||
$out .= '<div class="mc-gallery-info">';
|
||||
$out .= '<div class="mc-watermark">'.esc_html($q_player).'</div>';
|
||||
@@ -382,6 +390,7 @@ class MC_Gallery_Shortcodes {
|
||||
$out .= '<div class="mc-date-badge">'.$upload_date.'</div>';
|
||||
}
|
||||
$out .= '<img src="'.esc_url($thumb).'" alt="'.esc_attr($player_name).'" loading="lazy" style="aspect-ratio: '.$aspect_ratio.';">';
|
||||
$out .= self::render_like_btn($img->ID);
|
||||
$out .= '<div class="mc-gallery-overlay">';
|
||||
$out .= '<div class="mc-gallery-info">';
|
||||
$out .= '<div class="mc-watermark">'.$player_name.'</div>';
|
||||
@@ -539,6 +548,7 @@ class MC_Gallery_Shortcodes {
|
||||
$out .= '<div class="mc-date-badge">'.$upload_date.'</div>';
|
||||
}
|
||||
$out .= '<img src="'.esc_url($thumb).'" alt="'.esc_attr($player).'" loading="lazy" style="aspect-ratio: '.$aspect_ratio.';">';
|
||||
$out .= self::render_like_btn($img->ID);
|
||||
$out .= '<div class="mc-gallery-overlay">';
|
||||
$out .= '<div class="mc-gallery-info">';
|
||||
$out .= '<div class="mc-watermark">'.esc_html($player).'</div>';
|
||||
@@ -560,6 +570,12 @@ class MC_Gallery_Shortcodes {
|
||||
public static function shortcode_all_albums_overview($atts) {
|
||||
$show_date = get_option(MC_Gallery_Core::OPTION_SHOW_DATE, true);
|
||||
$current_url = remove_query_arg(['player', 'server', 'album']);
|
||||
|
||||
// Album-Ansicht: wenn ?album=ID in der URL steht, direkt anzeigen
|
||||
$q_album = isset($_GET['album']) ? intval($_GET['album']) : 0;
|
||||
if ($q_album) {
|
||||
return self::shortcode_album_view(['album_id' => $q_album]);
|
||||
}
|
||||
|
||||
$albums = get_posts([
|
||||
'post_type' => 'mc_album',
|
||||
@@ -586,13 +602,14 @@ class MC_Gallery_Shortcodes {
|
||||
$album_count = get_post_meta($album->ID, 'mc_image_count', true) ?: 0;
|
||||
|
||||
$cover_images = get_posts([
|
||||
'post_type' => 'attachment',
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => 1,
|
||||
'post_mime_type' => 'image',
|
||||
'meta_key' => 'mc_album_id',
|
||||
'meta_value' => $album->ID,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC'
|
||||
'meta_key' => 'mc_album_id',
|
||||
'meta_value' => $album->ID,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC'
|
||||
]);
|
||||
|
||||
$cover_url = '';
|
||||
@@ -645,13 +662,14 @@ class MC_Gallery_Shortcodes {
|
||||
}
|
||||
|
||||
$images = get_posts([
|
||||
'post_type' => 'attachment',
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => -1,
|
||||
'post_mime_type' => 'image',
|
||||
'meta_key' => 'mc_album_id',
|
||||
'meta_value' => $album_id,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC'
|
||||
'meta_key' => 'mc_album_id',
|
||||
'meta_value' => $album_id,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC'
|
||||
]);
|
||||
|
||||
$gallery_id = get_post_meta($album_id, 'mc_gallery_id', true);
|
||||
@@ -700,6 +718,7 @@ class MC_Gallery_Shortcodes {
|
||||
$out .= '<div class="mc-date-badge">'.$upload_date.'</div>';
|
||||
}
|
||||
$out .= '<img src="'.esc_url($thumb).'" alt="" loading="lazy" style="aspect-ratio: '.$aspect_ratio.';">';
|
||||
$out .= self::render_like_btn($img->ID);
|
||||
$out .= '</div>';
|
||||
$out .= '</a>';
|
||||
}
|
||||
@@ -716,9 +735,12 @@ class MC_Gallery_Shortcodes {
|
||||
public static function shortcode_upload($atts) {
|
||||
$atts = shortcode_atts(['show' => '0'], $atts);
|
||||
$show_default = ($atts['show'] === '1');
|
||||
|
||||
// Option als String vergleichen, damit auch '1' als String erkannt wird
|
||||
$forum_login_enabled = get_option(MC_Gallery_Core::OPTION_FORUM_LOGIN, false) == '1';
|
||||
$forum_plugin = class_exists('WBF_Auth');
|
||||
ob_start();
|
||||
?>
|
||||
<!-- DEBUG: Forum-Login Option: <?php echo $forum_login_enabled ? 'aktiv' : 'inaktiv'; ?>, Forum-Plugin: <?php echo $forum_plugin ? 'geladen' : 'NICHT geladen'; ?> -->
|
||||
<div class="mc-upload-wrapper">
|
||||
<button id="mc-open-upload-modal" class="mc-btn mc-btn-primary">
|
||||
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
@@ -728,6 +750,7 @@ class MC_Gallery_Shortcodes {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php if (!self::$modal_rendered): self::$modal_rendered = true; ?>
|
||||
<div id="mc-upload-modal" class="mc-modal" aria-hidden="true" role="dialog">
|
||||
<div class="mc-modal-backdrop"></div>
|
||||
<div class="mc-modal-content">
|
||||
@@ -757,6 +780,18 @@ class MC_Gallery_Shortcodes {
|
||||
</svg>
|
||||
Session starten
|
||||
</button>
|
||||
<?php if ($forum_login_enabled && $forum_plugin): ?>
|
||||
<div style="margin-top:16px; text-align:center;">
|
||||
<button id="mc-btn-forum-login" class="mc-btn mc-btn-secondary mc-full-width" type="button">
|
||||
<svg width="18" height="18" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<circle cx="12" cy="12" r="10" stroke-width="2"/>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14a4 4 0 100-8 4 4 0 000 8zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/>
|
||||
</svg>
|
||||
Mit Forum-Login verifizieren
|
||||
</button>
|
||||
<p class="mc-small" style="margin-top:8px;">Optional: Wenn du im Forum eingeloggt bist und dein Minecraft-Account verknüpft ist, kannst du dich direkt verifizieren.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -866,6 +901,7 @@ class MC_Gallery_Shortcodes {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; // modal_rendered ?>
|
||||
|
||||
<?php if ($show_default): ?>
|
||||
<script>
|
||||
@@ -889,4 +925,397 @@ class MC_Gallery_Shortcodes {
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// === KOMBINIERTER SHORTCODE: Upload-Button + Forum-Panel ================
|
||||
// =========================================================================
|
||||
// Verwendung: [mc_gallery_combined] oder [mc_gallery_combined show="1"]
|
||||
// Ersetzt [mc_gallery_upload] + [mc_gallery_forum_login] auf einer Seite.
|
||||
|
||||
public static function shortcode_combined($atts) {
|
||||
$atts = shortcode_atts(['show' => '0', 'server_id' => ''], $atts);
|
||||
$show_default = ($atts['show'] === '1');
|
||||
$forum_login_enabled = get_option(MC_Gallery_Core::OPTION_FORUM_LOGIN, false) == '1';
|
||||
$forum_plugin = class_exists('WBF_Auth');
|
||||
$server_id = sanitize_text_field($atts['server_id']);
|
||||
|
||||
// Prüfen ob Forum-User bereits verifiziert ist (für Button-Zustand)
|
||||
$forum_verified = false;
|
||||
$forum_mc_name = '';
|
||||
if ($forum_plugin && class_exists('MC_Gallery_Forum_Bridge')) {
|
||||
$fu = WBF_Auth::get_current_user();
|
||||
if ($fu) {
|
||||
$mc = MC_Gallery_Forum_Bridge::get_mc_username($fu->id);
|
||||
$ver = MC_Gallery_Forum_Bridge::is_verified($fu->id);
|
||||
if ($mc && $ver) {
|
||||
$forum_verified = true;
|
||||
$forum_mc_name = $mc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="mc-combined-wrapper">
|
||||
|
||||
<?php if ($forum_verified): ?>
|
||||
<!-- Bereits verifiziert: Upload-Button + grüner Badge -->
|
||||
<button id="mc-open-upload-modal" class="mc-btn mc-btn-primary mc-combined-upload-btn">
|
||||
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/>
|
||||
</svg>
|
||||
Bilder hochladen
|
||||
</button>
|
||||
<div class="mc-combined-verified-row">
|
||||
<svg width="14" height="14" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M5 13l4 4L19 7"/>
|
||||
</svg>
|
||||
Verifiziert als <strong><?php echo esc_html($forum_mc_name); ?></strong>
|
||||
</div>
|
||||
|
||||
<?php elseif ($forum_login_enabled && $forum_plugin): ?>
|
||||
<!-- Zwei-Wege: Token-Upload + Forum-Login -->
|
||||
|
||||
<!-- Upload-Button (Token-Weg) -->
|
||||
<button id="mc-open-upload-modal" class="mc-btn mc-btn-primary mc-combined-upload-btn">
|
||||
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/>
|
||||
</svg>
|
||||
Bilder hochladen
|
||||
<span class="mc-combined-method-tag">Ingame-Token</span>
|
||||
</button>
|
||||
|
||||
<div class="mc-combined-divider"><span>oder</span></div>
|
||||
|
||||
<!-- Forum-Card direkt inline (ohne extra Divider aus build_verify_panel) -->
|
||||
<?php
|
||||
if (class_exists('MC_Gallery_Forum_Bridge')) {
|
||||
$fu = WBF_Auth::get_current_user();
|
||||
$nonce = wp_create_nonce('mc_gallery_forum_bridge');
|
||||
$ajax_url = admin_url('admin-ajax.php');
|
||||
|
||||
if (!$fu) :
|
||||
$forum_url = function_exists('wbf_get_forum_url') ? wbf_get_forum_url() : '#';
|
||||
$register_url = function_exists('wbf_get_forum_url') ? wbf_get_forum_url() . '?register=1' : '#';
|
||||
?>
|
||||
<a href="<?php echo esc_url($forum_url); ?>" class="mc-btn mc-combined-upload-btn mc-combined-forum-btn" style="text-decoration:none;display:flex;align-items:center;justify-content:center;gap:8px;">
|
||||
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1"/>
|
||||
</svg>
|
||||
Mit Forum-Login verifizieren
|
||||
<span class="mc-combined-method-tag" style="background:rgba(0,0,0,.2);">Forum</span>
|
||||
</a>
|
||||
<a href="<?php echo esc_url($register_url); ?>" class="mc-btn mc-btn-secondary mc-combined-upload-btn" style="">
|
||||
<svg width="18" height="18" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18 9v3m0 0v3m0-3h3m-3 0h-3m-2-5a4 4 0 11-8 0 4 4 0 018 0zM3 20a6 6 0 0112 0v1H3v-1z"/>
|
||||
</svg>
|
||||
Noch kein Konto? Jetzt registrieren
|
||||
</a>
|
||||
<?php
|
||||
else:
|
||||
$mc_user = MC_Gallery_Forum_Bridge::get_mc_username($fu->id);
|
||||
$verified = MC_Gallery_Forum_Bridge::is_verified($fu->id);
|
||||
$prof_url = function_exists('wbf_get_forum_url') ? wbf_get_forum_url() . '?forum_profile=' . (int)$fu->id . '#tab-minecraft' : '#';
|
||||
|
||||
if ($mc_user && $verified):
|
||||
?>
|
||||
<div class="mc-bridge-success">
|
||||
<i class="fas fa-check-circle"></i> Verifiziert als <strong><?php echo esc_html($mc_user); ?></strong>
|
||||
</div>
|
||||
<?php
|
||||
elseif ($mc_user):
|
||||
?>
|
||||
<button type="button" class="mc-bridge-verify-trigger mc-btn mc-combined-upload-btn"
|
||||
style="width:100%;justify-content:center;gap:8px;background:#f59e0b;border:none;color:#1c1008;padding:12px 20px;font-size:15px;font-weight:600;cursor:pointer;"
|
||||
data-ajax="<?php echo esc_attr($ajax_url); ?>"
|
||||
data-nonce="<?php echo esc_attr($nonce); ?>"
|
||||
data-server="<?php echo esc_attr($server_id); ?>">
|
||||
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
||||
</svg>
|
||||
Mit Forum verifizieren – <?php echo esc_html($mc_user); ?>
|
||||
<span class="mc-combined-method-tag" style="background:rgba(0,0,0,.2);">Ausstehend</span>
|
||||
</button>
|
||||
<?php
|
||||
else:
|
||||
?>
|
||||
<a href="<?php echo esc_url($prof_url); ?>" class="mc-btn mc-combined-upload-btn mc-combined-forum-btn" style="text-decoration:none;display:flex;align-items:center;justify-content:center;gap:8px;">
|
||||
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"/>
|
||||
</svg>
|
||||
Minecraft-Konto verknüpfen
|
||||
<span class="mc-combined-method-tag">Forum-Profil</span>
|
||||
</a>
|
||||
<?php
|
||||
endif;
|
||||
endif; // $fu
|
||||
} // class_exists
|
||||
?>
|
||||
|
||||
<?php else: ?>
|
||||
<!-- Nur Upload-Button -->
|
||||
<button id="mc-open-upload-modal" class="mc-btn mc-btn-primary mc-combined-upload-btn">
|
||||
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/>
|
||||
</svg>
|
||||
Bilder hochladen
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Modal HTML — nur einmal pro Seite ausgeben
|
||||
$forum_login_for_modal = $forum_login_enabled && $forum_plugin;
|
||||
if (!self::$modal_rendered): self::$modal_rendered = true;
|
||||
?>
|
||||
<div id="mc-upload-modal" class="mc-modal" aria-hidden="true" role="dialog">
|
||||
<div class="mc-modal-backdrop"></div>
|
||||
<div class="mc-modal-content">
|
||||
<button class="mc-modal-close" aria-label="Schließen">×</button>
|
||||
<div class="mc-upload-wizard">
|
||||
<div class="mc-step active" data-step="1">
|
||||
<div class="mc-step-header"><span class="mc-step-num">1</span><h3>Identifikation</h3></div>
|
||||
<div class="mc-step-body">
|
||||
<label for="mc-upload-username">Dein Minecraft Name</label>
|
||||
<input type="text" id="mc-upload-username" placeholder="z.B. Steve" autocomplete="off">
|
||||
<label for="mc-upload-server">Server wählen</label>
|
||||
<select id="mc-upload-server"><option>Lade Server...</option></select>
|
||||
<button id="mc-btn-generate" class="mc-btn mc-btn-primary mc-full-width">
|
||||
<svg width="18" height="18" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
|
||||
</svg>
|
||||
Session starten
|
||||
</button>
|
||||
<?php if ($forum_login_for_modal): ?>
|
||||
<div style="margin-top:16px; text-align:center;">
|
||||
<button id="mc-btn-forum-login" class="mc-btn mc-btn-secondary mc-full-width" type="button">
|
||||
<svg width="18" height="18" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<circle cx="12" cy="12" r="10" stroke-width="2"/>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14a4 4 0 100-8 4 4 0 000 8zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/>
|
||||
</svg>
|
||||
Mit Forum-Login verifizieren
|
||||
</button>
|
||||
<p class="mc-small" style="margin-top:8px;">Optional: Wenn du im Forum eingeloggt bist und dein Minecraft-Account verknüpft ist, kannst du dich direkt verifizieren.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mc-step" data-step="2">
|
||||
<div class="mc-step-header"><span class="mc-step-num">2</span><h3>Verifizierung</h3></div>
|
||||
<div class="mc-step-body">
|
||||
<div class="mc-info-box">🎮 Gehe auf den Server und führe den folgenden Befehl aus:</div>
|
||||
<div class="mc-token-box">
|
||||
<code id="mc-token-text">Waiting...</code>
|
||||
<button class="mc-copy-btn" title="Kopieren">📋</button>
|
||||
</div>
|
||||
<p class="mc-small">💡 Gib im Chat ein: <strong>/verify [dein-token]</strong></p>
|
||||
<button id="mc-btn-check" class="mc-btn mc-btn-primary mc-full-width">
|
||||
<svg width="18" height="18" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
||||
</svg>
|
||||
Verifizierung prüfen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mc-step" data-step="3">
|
||||
<div class="mc-step-header"><span class="mc-step-num">3</span><h3>Bilder hochladen</h3></div>
|
||||
<div class="mc-step-body">
|
||||
<div class="mc-session-info">
|
||||
<span class="mc-session-badge">✓ Session aktiv</span>
|
||||
<span id="mc-session-user"></span>
|
||||
</div>
|
||||
<label>Album wählen (optional)</label>
|
||||
<div class="mc-album-selector">
|
||||
<select id="mc-upload-album"><option value="">Kein Album</option></select>
|
||||
<button id="mc-btn-new-album" class="mc-btn mc-btn-ghost mc-btn-small" type="button">
|
||||
<svg width="14" height="14" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
|
||||
</svg>
|
||||
Neues Album
|
||||
</button>
|
||||
</div>
|
||||
<div id="mc-new-album-form" style="display:none;">
|
||||
<label>Album-Name</label>
|
||||
<input type="text" id="mc-new-album-name" placeholder="z.B. Meine Bauten">
|
||||
<button id="mc-btn-create-album" class="mc-btn mc-btn-primary mc-btn-small mc-full-width">Album erstellen</button>
|
||||
</div>
|
||||
<label>Bilder auswählen (mehrere möglich)</label>
|
||||
<div class="mc-file-drop">
|
||||
<input type="file" id="mc-upload-file" accept="image/*" multiple>
|
||||
<svg width="48" height="48" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="margin:0 auto 12px;display:block;color:var(--mc-primary);">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
<span id="mc-file-name">Keine Bilder gewählt</span>
|
||||
</div>
|
||||
<div id="mc-file-preview" class="mc-file-preview"></div>
|
||||
<form id="mc-upload-form" style="display:none;">
|
||||
<?php wp_nonce_field('mc_gallery_upload_action', 'mc_upload_nonce'); ?>
|
||||
<input type="hidden" name="mc_token" id="mc_form_token">
|
||||
<input type="hidden" name="mc_username" id="mc_form_username">
|
||||
<input type="hidden" name="mc_server_id" id="mc_form_server">
|
||||
<input type="hidden" name="mc_album_id" id="mc_form_album">
|
||||
</form>
|
||||
<div id="mc-upload-progress" style="display:none;">
|
||||
<div class="mc-progress-bar"><div class="mc-progress-fill" id="mc-progress-fill"></div></div>
|
||||
<p id="mc-progress-text">Uploading...</p>
|
||||
</div>
|
||||
<button id="mc-btn-final-upload" class="mc-btn mc-btn-success mc-full-width">
|
||||
<svg width="18" height="18" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/>
|
||||
</svg>
|
||||
<span id="mc-upload-btn-text">Bilder hochladen</span>
|
||||
</button>
|
||||
<button id="mc-btn-upload-more" class="mc-btn mc-btn-ghost mc-full-width" style="display:none;margin-top:12px;">
|
||||
<svg width="18" height="18" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
|
||||
</svg>
|
||||
Weitere Bilder hochladen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="mc-feedback-msg"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; // modal_rendered ?>
|
||||
|
||||
<?php if ($show_default): ?>
|
||||
<script>(function(){ setTimeout(function(){ var b=document.getElementById('mc-open-upload-modal'); if(b) b.click(); }, 500); })();</script>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// === ABSTIMMUNG / VOTE BOARD =============================================
|
||||
// =========================================================================
|
||||
// Verwendung: [mc_gallery_vote] — Zeigt alle Bilder sortiert nach Likes
|
||||
|
||||
public static function shortcode_vote_board($atts) {
|
||||
$atts = shortcode_atts(['limit' => 50, 'server_ids' => ''], $atts);
|
||||
|
||||
$server_ids = [];
|
||||
if (!empty($atts['server_ids'])) {
|
||||
foreach (explode(',', $atts['server_ids']) as $id) {
|
||||
$int = intval(trim($id));
|
||||
if ($int > 0) $server_ids[] = $int;
|
||||
}
|
||||
}
|
||||
|
||||
// Gallery-Posts ermitteln
|
||||
$gallery_args = ['post_type' => 'mc_gallery', 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => 'publish'];
|
||||
if (!empty($server_ids)) {
|
||||
$gallery_args['meta_query'] = [['key' => 'mc_server', 'value' => $server_ids, 'compare' => 'IN']];
|
||||
}
|
||||
$gallery_ids = get_posts($gallery_args);
|
||||
|
||||
if (empty($gallery_ids)) {
|
||||
return '<div class="mc-gallery-container"><div class="mc-empty-state">📷 Noch keine Bilder vorhanden.</div></div>';
|
||||
}
|
||||
|
||||
// Alle Bilder laden, nach Likes sortiert
|
||||
$images = get_posts([
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'post_mime_type' => 'image',
|
||||
'post_parent__in'=> $gallery_ids,
|
||||
'posts_per_page' => intval($atts['limit']),
|
||||
'meta_key' => 'mc_votes_up',
|
||||
'orderby' => 'meta_value_num',
|
||||
'order' => 'DESC',
|
||||
]);
|
||||
|
||||
// Auch Bilder ohne Votes holen
|
||||
if (count($images) < intval($atts['limit'])) {
|
||||
$voted_ids = array_map(fn($i) => $i->ID, $images);
|
||||
$rest_args = [
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'post_mime_type' => 'image',
|
||||
'post_parent__in'=> $gallery_ids,
|
||||
'posts_per_page' => intval($atts['limit']) - count($images),
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
];
|
||||
if (!empty($voted_ids)) $rest_args['post__not_in'] = $voted_ids;
|
||||
$images = array_merge($images, get_posts($rest_args));
|
||||
}
|
||||
|
||||
if (empty($images)) {
|
||||
return '<div class="mc-gallery-container"><div class="mc-empty-state">📷 Noch keine Bilder vorhanden.</div></div>';
|
||||
}
|
||||
|
||||
$show_date = get_option(MC_Gallery_Core::OPTION_SHOW_DATE, true);
|
||||
|
||||
$out = '<div class="mc-gallery-container mc-vote-board">';
|
||||
$out .= '<div class="mc-player-header">';
|
||||
$out .= '<div class="mc-player-title"><div class="mc-player-avatar">👍</div><h2>Abstimmung</h2></div>';
|
||||
$out .= '</div>';
|
||||
$out .= '<div class="mc-gallery-grid">';
|
||||
|
||||
foreach ($images as $img) {
|
||||
$full = wp_get_attachment_url($img->ID);
|
||||
$thumb_arr = wp_get_attachment_image_src($img->ID, 'medium');
|
||||
$thumb = $thumb_arr ? $thumb_arr[0] : $full;
|
||||
$views = (int) get_post_meta($img->ID, 'mc_views', true);
|
||||
$upload_date = date_i18n('d.m.Y', strtotime($img->post_date));
|
||||
$gallery_post = get_post($img->post_parent);
|
||||
$player_name = $gallery_post ? get_post_meta($gallery_post->ID, 'mc_player', true) : '';
|
||||
$metadata = wp_get_attachment_metadata($img->ID);
|
||||
$ratio = (($metadata['width'] ?? 0) && ($metadata['height'] ?? 0))
|
||||
? ($metadata['width'] / $metadata['height']) : 1;
|
||||
$data_date = $show_date ? 'data-date="'.esc_attr($upload_date).'"' : '';
|
||||
|
||||
$out .= '<a href="'.esc_url($full).'" class="mc-gallery-item" data-player="'.esc_attr($player_name).'" '.$data_date.' data-attach-id="'.$img->ID.'">';
|
||||
$out .= '<div class="mc-gallery-item-inner">';
|
||||
$out .= '<div class="mc-views-badge">👁️ <span class="mc-views-count">'.$views.'</span></div>';
|
||||
if ($show_date) $out .= '<div class="mc-date-badge">'.$upload_date.'</div>';
|
||||
$out .= '<img src="'.esc_url($thumb).'" alt="'.esc_attr($player_name).'" loading="lazy" style="aspect-ratio:'.$ratio.';">';
|
||||
$out .= self::render_vote_btns($img->ID);
|
||||
$out .= '<div class="mc-gallery-overlay"><div class="mc-gallery-info"><div class="mc-watermark">'.esc_html($player_name).'</div></div></div>';
|
||||
$out .= '</div>';
|
||||
$out .= '</a>';
|
||||
}
|
||||
|
||||
$out .= '</div></div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
// Hilfsfunktion: Like-Button HTML für normale Galerie-Items
|
||||
public static function render_vote_btns($attach_id) {
|
||||
if (!get_option(MC_Gallery_Core::OPTION_VOTING, true)) return '';
|
||||
$up = (int) get_post_meta($attach_id, 'mc_votes_up', true);
|
||||
$down = (int) get_post_meta($attach_id, 'mc_votes_down', true);
|
||||
$nonce = wp_create_nonce('mc_gallery_upload_action');
|
||||
$id = esc_attr($attach_id);
|
||||
$n = esc_attr($nonce);
|
||||
return
|
||||
'<div class="mc-vote-wrap" data-attach-id="'.$id.'" data-nonce="'.$n.'">'
|
||||
// Daumen hoch
|
||||
.'<button class="mc-vote-btn mc-vote-up" data-type="up" title="Daumen hoch">'
|
||||
.'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 10h4.764a2 2 0 011.789 2.894l-3.5 7A2 2 0 0115.263 21h-4.017c-.163 0-.326-.02-.485-.06L7 20m7-10V5a2 2 0 00-2-2h-.095c-.5 0-.905.405-.905.905 0 .714-.211 1.412-.608 2.006L7 11v9m7-10h-2M7 20H5a2 2 0 01-2-2v-6a2 2 0 012-2h2.5"/></svg>'
|
||||
.'<span class="mc-vote-count mc-vote-up-count">'.$up.'</span>'
|
||||
.'</button>'
|
||||
// Daumen runter
|
||||
.'<button class="mc-vote-btn mc-vote-down" data-type="down" title="Daumen runter">'
|
||||
.'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14H5.236a2 2 0 01-1.789-2.894l3.5-7A2 2 0 018.736 3h4.018c.163 0 .326.02.485.06L17 4m-7 10v2a2 2 0 002 2h.095c.5 0 .905-.405.905-.905 0-.714.211-1.412.608-2.006L17 13V4m-7 10h2m5-10h2a2 2 0 012 2v6a2 2 0 01-2 2h-2.5"/></svg>'
|
||||
.'<span class="mc-vote-count mc-vote-down-count">'.$down.'</span>'
|
||||
.'</button>'
|
||||
.'</div>';
|
||||
}
|
||||
|
||||
// Rückwärtskompatibilität
|
||||
public static function render_like_btn($attach_id) {
|
||||
return self::render_vote_btns($attach_id);
|
||||
}
|
||||
|
||||
public static function ajax_vote() {
|
||||
// Delegiert an MC_Gallery_Core::handle_vote()
|
||||
if (class_exists('MC_Gallery_Core')) {
|
||||
MC_Gallery_Core::handle_vote();
|
||||
} else {
|
||||
wp_send_json_error(['message' => 'Core nicht geladen.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user