0, 'server_ids' => '', 'thumb_h' => 0 ], $atts); $thumb_h = intval($atts['thumb_h']) ?: MC_Gallery_Core::get_default_thumb_h(); $show_date = get_option(MC_Gallery_Core::OPTION_SHOW_DATE, true); $server_ids_to_search = []; // Server IDs sammeln if (!empty($atts['server_ids'])) { $raw_ids = explode(',', $atts['server_ids']); foreach ($raw_ids as $id) { $int_id = intval(trim($id)); if ($int_id > 0) $server_ids_to_search[] = $int_id; } } else if (!empty($atts['server_id'])) { $server_ids_to_search[] = intval($atts['server_id']); } else { // Alle aktiven Server laden $all_server_posts = get_posts([ 'post_type' => 'mc_server', 'meta_key' => 'mc_server_active', 'meta_value' => 1, 'numberposts' => -1 ]); foreach ($all_server_posts as $s) { $server_ids_to_search[] = $s->ID; } } if (empty($server_ids_to_search)) { return ''; } // Parameter auslesen $q_player = isset($_GET['player']) ? sanitize_text_field($_GET['player']) : ''; $q_server = isset($_GET['server']) ? intval($_GET['server']) : 0; $q_album = isset($_GET['album']) ? intval($_GET['album']) : 0; $current_url = remove_query_arg(['player', 'server', 'album']); // ============================== // 1. FALL: Album-Ansicht (wenn ?album=ID) // ============================== if ($q_album) { return self::shortcode_album_view(['album_id' => $q_album]); } // ============================== // 2. FALL: Spieler-Spezifische Ansicht // ============================== if ($q_player) { // Header erstellen $out = ''; return $out; } // ============================== // 3. FALL: Haupt-Übersicht (Kein Spieler gewählt) // ============================== // Alle mc_gallery Posts laden $galleries = get_posts([ 'post_type' => 'mc_gallery', 'posts_per_page' => -1, 'meta_query' => [ [ 'key' => 'mc_server', 'value' => $server_ids_to_search, 'compare' => 'IN' ] ], 'orderby' => 'date', 'order' => 'DESC' ]); if (empty($galleries)) { return ''; } $all_images = []; $players_list = []; $player_counts = []; foreach ($galleries as $gallery) { $player = get_post_meta($gallery->ID, 'mc_player', true); if (!in_array($player, $players_list)) { $players_list[] = $player; $player_counts[$player] = 0; } $images = get_posts([ 'post_type' => 'attachment', 'post_parent' => $gallery->ID, 'posts_per_page' => -1, 'post_mime_type' => 'image', 'orderby' => 'date', 'order' => 'DESC' ]); foreach ($images as $img) { $img->mc_player_name = $player; $img->mc_upload_date = $img->post_date; $img->mc_gallery_id = $gallery->ID; $all_images[] = $img; $player_counts[$player]++; } } usort($all_images, function($a, $b) { return strtotime($b->mc_upload_date) - strtotime($a->mc_upload_date); }); $out = ''; return $out; } public static function shortcode_player($atts) { $atts = shortcode_atts([ 'player' => '', 'server_id' => 0, 'thumb_h' => 0 ], $atts); $player = sanitize_text_field($atts['player']); $server_id = intval($atts['server_id']); $thumb_h = intval($atts['thumb_h']) ?: MC_Gallery_Core::get_default_thumb_h(); $show_date = get_option(MC_Gallery_Core::OPTION_SHOW_DATE, true); if (!$player || !$server_id) { return '
❌ Invalid request.
'; } $gallery = MC_Gallery_Helpers::find_or_create_gallery_post($player, $server_id); if (!$gallery) { return '
📁 Gallery not found.
'; } $images = get_posts([ 'post_type' => 'attachment', 'post_parent' => $gallery->ID, 'posts_per_page' => -1, 'post_mime_type' => 'image', 'orderby' => 'date', 'order' => 'DESC' ]); $albums = get_posts([ 'post_type' => 'mc_album', 'posts_per_page' => -1, 'meta_key' => 'mc_gallery_id', 'meta_value' => $gallery->ID, 'orderby' => 'date', 'order' => 'DESC' ]); if (empty($images) && empty($albums)) { return ''; } $current_url = remove_query_arg(['player', 'server', 'album']); $out = ''; return $out; } 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', 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC' ]); if (empty($albums)) { return ''; } $out = ''; return $out; } public static function shortcode_album_view($atts) { $atts = shortcode_atts([ 'album_id' => 0, 'server_id' => 0 ], $atts); $album_id = intval($atts['album_id']); $album = get_post($album_id); $show_date = get_option(MC_Gallery_Core::OPTION_SHOW_DATE, true); if (!$album || $album->post_type !== 'mc_album') { return '
❌ Album not found.
'; } $images = get_posts([ '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' ]); $gallery_id = get_post_meta($album_id, 'mc_gallery_id', true); $gallery = get_post($gallery_id); $player = $gallery ? get_post_meta($gallery_id, 'mc_player', true) : ''; $current_url = remove_query_arg(['album']); $out = ''; return $out; } 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(); ?>
'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(); ?>
Verifiziert als
oder
Mit Forum-Login verifizieren Forum Noch kein Konto? Jetzt registrieren 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): ?>
Verifiziert als
Minecraft-Konto verknüpfen Forum-Profil
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 ''; } // 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 ''; } $show_date = get_option(MC_Gallery_Core::OPTION_SHOW_DATE, true); $out = ''; 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 '
' // Daumen hoch .'' // Daumen runter .'' .'
'; } // 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.']); } } }