From b0bec8359304f3723767071fbebc5e1b4e078839 Mon Sep 17 00:00:00 2001 From: M_Viper Date: Sun, 29 Mar 2026 13:35:46 +0200 Subject: [PATCH] Update from Git Manager GUI --- includes/class-mc-gallery-core.php | 373 +++++++++-- includes/class-mc-gallery-forum-bridge.php | 691 +++++++++++++++++++++ includes/class-mc-gallery-shortcodes.php | 473 +++++++++++++- 3 files changed, 1454 insertions(+), 83 deletions(-) create mode 100644 includes/class-mc-gallery-forum-bridge.php diff --git a/includes/class-mc-gallery-core.php b/includes/class-mc-gallery-core.php index 6eb4760..90816de 100644 --- a/includes/class-mc-gallery-core.php +++ b/includes/class-mc-gallery-core.php @@ -1,8 +1,13 @@ 'integer', 'sanitize_callback' => 'absint', 'default' => 100]); register_setting('mc_gallery_pro_group', self::OPTION_SHOW_DATE, [ 'type' => 'boolean', - 'sanitize_callback' => function($input) { return $input === '1'; }, + 'sanitize_callback' => function($input) { return $input == '1' || $input === true || $input === 'on'; }, 'default' => true ]); register_setting('mc_gallery_pro_group', self::OPTION_MAX_UPLOADS, [ @@ -210,13 +220,39 @@ class MC_Gallery_Core { 'sanitize_callback' => 'absint', 'default' => 5 ]); + register_setting('mc_gallery_pro_group', self::OPTION_FORUM_LOGIN, [ + 'type' => 'boolean', + 'sanitize_callback' => function($input) { return !empty($input) && $input !== '0'; }, + 'default' => false + ]); + register_setting('mc_gallery_pro_group', self::OPTION_VOTING, [ + 'type' => 'boolean', + 'sanitize_callback' => function($input) { return !empty($input) && $input !== '0'; }, + 'default' => true + ]); } public static function settings_page() { - $thumb_h = get_option(self::OPTION_THUMB_H, 200); - $resize_pct = get_option(self::OPTION_RESIZE_PCT, 100); - $show_date = get_option(self::OPTION_SHOW_DATE, true); + $thumb_h = get_option(self::OPTION_THUMB_H, 200); + $resize_pct = get_option(self::OPTION_RESIZE_PCT, 100); + $show_date = get_option(self::OPTION_SHOW_DATE, true); $max_uploads = get_option(self::OPTION_MAX_UPLOADS, 5); + $forum_login = get_option(self::OPTION_FORUM_LOGIN, false); + $forum_plugin_active = class_exists('WBF_Auth'); + + // Prüfen ob das Forum-Plugin zwar existiert (Datei vorhanden) aber nicht aktiv ist + $forum_plugin_installed = false; + if ( ! $forum_plugin_active ) { + $all_plugins = get_plugins(); + foreach ( $all_plugins as $plugin_file => $plugin_data ) { + if ( stripos( $plugin_data['Name'], 'WP Business Forum' ) !== false + || stripos( $plugin_data['TextDomain'], 'wp-business-forum' ) !== false + || stripos( $plugin_file, 'wp-business-forum' ) !== false ) { + $forum_plugin_installed = true; + break; + } + } + } ?>

MC Gallery PRO Settings

@@ -250,8 +286,84 @@ class MC_Gallery_Core {

How many images can a user upload at once? (Default: 5)

+ + + Forum-Login für Upload-Verifizierung +
Benötigt: WP Business Forum + + + + + +
+ + + WP Business Forum aktiv + +
+ +

+ Wenn aktiviert, können sich Nutzer die ihren Minecraft-Account im Forum-Profil verknüpft haben, direkt ohne Ingame-Token hochladen.
+ Der Shortcode: [mc_gallery_combined] ermöglicht eine kombinierte Verifizierung für Token und Forum. +

+ + + + +
+ ⚠ WP Business Forum ist installiert, aber nicht aktiviert.
+ Aktiviere das Plugin unter Plugins → Installierte Plugins, um diese Funktion zu nutzen. +
+ + + + + +
+ ✗ WP Business Forum ist nicht installiert.
+ + Dieses Feature benötigt das Plugin WP Business Forum von M_Viper.
+ + ↓ Jetzt herunterladen (Gitea) + +  ·  + + Plugins → Neu hinzufügen + +
+
+ +

+ Nach der Installation und Aktivierung von WP Business Forum wird diese Option freigeschaltet. +

+ + + + + + Abstimmung (Daumen hoch/runter) + + +

+ Besucher können Bilder mit 👍 oder 👎 bewerten. Jeder kann abstimmen (kein Login nötig).
+ Shortcode für die Bestenliste: [mc_gallery_vote] +

+ + - +
id ); + $verified = MC_Gallery_Forum_Bridge::is_verified( $forum_user->id ); + if ( $mc_user && $verified ) { + $forum_verified_data = [ + 'mc_username' => $mc_user, + 'server_id' => MC_Gallery_Forum_Bridge::get_mc_server( $forum_user->id ), + 'display_name' => $forum_user->display_name, + ]; + } + } + } + wp_localize_script('mc-gallery-pro-js', 'mcGalleryPro', [ - 'restBase' => esc_url_raw(rest_url('mc-gallery/v1')), - 'uploadUrl' => esc_url_raw(admin_url('admin-ajax.php')), - 'nonce' => wp_create_nonce('mc_gallery_upload_action'), - 'maxUploads' => intval(get_option(self::OPTION_MAX_UPLOADS, 5)) + 'restBase' => esc_url_raw(rest_url('mc-gallery/v1')), + 'uploadUrl' => esc_url_raw(admin_url('admin-ajax.php')), + 'nonce' => wp_create_nonce('mc_gallery_upload_action'), + 'forumNonce' => wp_create_nonce('mc_gallery_forum_bridge'), + 'maxUploads' => intval(get_option(self::OPTION_MAX_UPLOADS, 5)), + 'forumVerified' => $forum_verified_data, + 'votingEnabled' => get_option(self::OPTION_VOTING, true) ? true : false, ]); + + // Forum-Bridge-JS nur laden, wenn Option aktiv und Forum-Plugin vorhanden + $forum_login = get_option(self::OPTION_FORUM_LOGIN, false); + if ($forum_login && class_exists('WBF_Auth')) { + wp_enqueue_script('mc-gallery-forum-bridge', MCGALLERY_PRO_URL . 'assets/js/forum-bridge.js?v=' . $js_version, ['jquery'], null, true); + } } public static function register_rest_routes() { @@ -435,38 +574,60 @@ class MC_Gallery_Core { } public static function rest_get_albums($req) { - $params = $req->get_json_params(); - $token = sanitize_text_field($params['token'] ?? ''); - $username = sanitize_text_field($params['username'] ?? ''); - $server_id = intval($params['server_id'] ?? 0); - - if (!$token || !$username || !$server_id) { - return new WP_REST_Response(['success'=>false,'message'=>'Missing data'],400); + $params = $req->get_json_params(); + $token = sanitize_text_field($params['token'] ?? ''); + $username = sanitize_text_field($params['username'] ?? ''); + $server_id = sanitize_text_field($params['server_id'] ?? ''); + + if (!$username) { + return new WP_REST_Response(['success'=>false,'message'=>'Missing username'],400); } - - $tokens = MC_Gallery_Helpers::get_tokens(); - if (!isset($tokens[$token]) || !$tokens[$token]['claimed'] || $tokens[$token]['claimed_by'] !== $username) { + + // ── Autorisierung: Token-Session ODER Forum-Login ───────────────────── + $authorized = false; + + if ($token) { + $tokens = MC_Gallery_Helpers::get_tokens(); + if (isset($tokens[$token]) && $tokens[$token]['claimed'] && $tokens[$token]['claimed_by'] === $username) { + if (!$server_id) $server_id = $tokens[$token]['server_id'] ?? ''; + $authorized = true; + } + } elseif (class_exists('WBF_Auth') && class_exists('MC_Gallery_Forum_Bridge')) { + $forum_user = WBF_Auth::get_current_user(); + if ($forum_user) { + $linked = MC_Gallery_Forum_Bridge::get_mc_username($forum_user->id); + if ($linked && MC_Gallery_Forum_Bridge::is_verified($forum_user->id) + && strtolower($linked) === strtolower($username)) { + if (!$server_id) $server_id = MC_Gallery_Forum_Bridge::get_mc_server($forum_user->id); + $authorized = true; + } + } + } + + if (!$authorized) { return new WP_REST_Response(['success'=>false,'message'=>'Invalid session'],401); } - - $gallery = MC_Gallery_Helpers::find_or_create_gallery_post($username, $server_id); + + $server_id_val = is_numeric($server_id) ? intval($server_id) : $server_id; + + $gallery = MC_Gallery_Helpers::find_or_create_gallery_post($username, $server_id_val); if (!$gallery) { return MC_Gallery_Helpers::rest_response_success(['albums' => []]); } $albums = get_posts([ - 'post_type' => 'mc_album', + 'post_type' => 'mc_album', 'posts_per_page' => -1, - 'meta_key' => 'mc_gallery_id', - 'meta_value' => $gallery->ID, - 'orderby' => 'date', - 'order' => 'DESC' + 'meta_key' => 'mc_gallery_id', + 'meta_value' => $gallery->ID, + 'orderby' => 'date', + 'order' => 'DESC' ]); $out = []; foreach ($albums as $album) { $out[] = [ - 'id' => $album->ID, + 'id' => $album->ID, 'title' => $album->post_title ]; } @@ -495,30 +656,87 @@ class MC_Gallery_Core { wp_send_json_success(['views' => $count]); } + // NEU: Vote/Like Handler + public static function handle_vote() { + if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'mc_gallery_upload_action')) { + wp_send_json_error(['message' => 'Security check failed.']); + } + + if (!isset($_POST['attach_id']) || !is_numeric($_POST['attach_id'])) { + wp_send_json_error(['message' => 'Invalid ID.']); + } + + // Voting deaktiviert? + if (!get_option(self::OPTION_VOTING, true)) { + wp_send_json_error(['message' => 'Voting ist deaktiviert.']); + } + + $attach_id = intval($_POST['attach_id']); + $vote_type = sanitize_text_field($_POST['vote_type'] ?? 'up'); // 'up' oder 'down' + $vote_action = sanitize_text_field($_POST['vote_action'] ?? 'add'); // 'add' oder 'remove' + + $post = get_post($attach_id); + if (!$post || $post->post_type !== 'attachment' || strpos($post->post_mime_type, 'image/') !== 0) { + wp_send_json_error(['message' => 'Not a valid image.']); + } + + $meta_key = ($vote_type === 'down') ? 'mc_votes_down' : 'mc_votes_up'; + $count = (int) get_post_meta($attach_id, $meta_key, true); + $count = ($vote_action === 'remove') ? max(0, $count - 1) : $count + 1; + update_post_meta($attach_id, $meta_key, $count); + + wp_send_json_success([ + 'votes_up' => (int) get_post_meta($attach_id, 'mc_votes_up', true), + 'votes_down' => (int) get_post_meta($attach_id, 'mc_votes_down', true), + 'vote_type' => $vote_type, + 'vote_action'=> $vote_action, + ]); + } + public static function handle_create_album() { if (!isset($_POST['mc_upload_nonce']) || !wp_verify_nonce($_POST['mc_upload_nonce'], 'mc_gallery_upload_action')) { wp_send_json_error(['message' => 'Security check failed.']); } - $token = sanitize_text_field($_POST['mc_token'] ?? ''); - $username = sanitize_text_field($_POST['mc_username'] ?? ''); - $server_id = intval($_POST['mc_server_id'] ?? 0); - $album_name = sanitize_text_field($_POST['album_name'] ?? ''); - - if (!$token || !$username || !$server_id || !$album_name) { + $token = sanitize_text_field($_POST['mc_token'] ?? ''); + $username = sanitize_text_field($_POST['mc_username'] ?? ''); + $server_id = sanitize_text_field($_POST['mc_server_id'] ?? ''); + $album_name = sanitize_text_field($_POST['album_name'] ?? ''); + + if (!$username || !$album_name) { wp_send_json_error(['message' => 'Missing data']); } - - $tokens = MC_Gallery_Helpers::get_tokens(); - if (!isset($tokens[$token]) || !$tokens[$token]['claimed'] || $tokens[$token]['claimed_by'] !== $username) { - wp_send_json_error(['message' => 'Invalid session']); + + // ── Autorisierung: Token-Session ODER Forum-Login ───────────────────── + $authorized = false; + + if ($token) { + $tokens = MC_Gallery_Helpers::get_tokens(); + if (isset($tokens[$token]) && $tokens[$token]['claimed'] && $tokens[$token]['claimed_by'] === $username && $tokens[$token]['expires'] >= time()) { + if (!$server_id) $server_id = $tokens[$token]['server_id'] ?? ''; + $authorized = true; + } else { + wp_send_json_error(['message' => 'Invalid or expired session']); + } + } elseif (class_exists('WBF_Auth') && class_exists('MC_Gallery_Forum_Bridge')) { + $forum_user = WBF_Auth::get_current_user(); + if ($forum_user) { + $linked_mc = MC_Gallery_Forum_Bridge::get_mc_username($forum_user->id); + $verified = MC_Gallery_Forum_Bridge::is_verified($forum_user->id); + if ($linked_mc && $verified && strtolower($linked_mc) === strtolower($username)) { + if (!$server_id) $server_id = MC_Gallery_Forum_Bridge::get_mc_server($forum_user->id); + $authorized = true; + } + } } - - if ($tokens[$token]['expires'] < time()) { - wp_send_json_error(['message' => 'Session expired']); + + if (!$authorized) { + wp_send_json_error(['message' => 'Nicht autorisiert.']); } + + $server_id_val = is_numeric($server_id) ? intval($server_id) : $server_id; - $gallery = MC_Gallery_Helpers::find_or_create_gallery_post($username, $server_id); + $gallery = MC_Gallery_Helpers::find_or_create_gallery_post($username, $server_id_val); if (!$gallery) { wp_send_json_error(['message' => 'Gallery not found']); } @@ -551,27 +769,60 @@ class MC_Gallery_Core { wp_send_json_error(['message' => 'Security check failed.']); } - $token = sanitize_text_field($_POST['mc_token'] ?? ''); - $username = sanitize_text_field($_POST['mc_username'] ?? ''); - $server_id = intval($_POST['mc_server_id'] ?? 0); - $album_id = intval($_POST['mc_album_id'] ?? 0); - - if (!$token || !$username || !$server_id) { - wp_send_json_error(['message' => 'Token or data missing.']); + $token = sanitize_text_field($_POST['mc_token'] ?? ''); + $username = sanitize_text_field($_POST['mc_username'] ?? ''); + $server_id = sanitize_text_field($_POST['mc_server_id'] ?? ''); + $album_id = intval($_POST['mc_album_id'] ?? 0); + + if (!$username) { + wp_send_json_error(['message' => 'Benutzername fehlt.']); } - - $tokens = MC_Gallery_Helpers::get_tokens(); - if (!isset($tokens[$token])) { - wp_send_json_error(['message' => 'Invalid token.']); + + // ── Autorisierung: Token-Session ODER Forum-Login ───────────────────── + $authorized = false; + + if ($token) { + // Standard-Weg: Ingame-Token verifizieren + $tokens = MC_Gallery_Helpers::get_tokens(); + if (!isset($tokens[$token])) { + wp_send_json_error(['message' => 'Invalid token.']); + } + $t = $tokens[$token]; + if ($t['expires'] < time()) { + wp_send_json_error(['message' => 'Session expired.']); + } + if (!$t['claimed'] || $t['claimed_by'] !== $username) { + wp_send_json_error(['message' => 'Verification failed. Please go back to step 2 and use /verify']); + } + // server_id aus Token übernehmen falls nicht per POST übergeben + if (!$server_id) { + $server_id = $t['server_id'] ?? ''; + } + $authorized = true; + } elseif (class_exists('WBF_Auth') && class_exists('MC_Gallery_Forum_Bridge')) { + // Forum-Login-Weg: eingeloggten Forum-User prüfen + $forum_user = WBF_Auth::get_current_user(); + if ($forum_user) { + $linked_mc = MC_Gallery_Forum_Bridge::get_mc_username($forum_user->id); + $verified = MC_Gallery_Forum_Bridge::is_verified($forum_user->id); + if ($linked_mc && $verified && strtolower($linked_mc) === strtolower($username)) { + // server_id aus Profil holen falls nicht übergeben + if (!$server_id) { + $server_id = MC_Gallery_Forum_Bridge::get_mc_server($forum_user->id); + } + $authorized = true; + } + } } - - $t = $tokens[$token]; - if ($t['expires'] < time()) { - wp_send_json_error(['message' => 'Session expired.']); + + if (!$authorized) { + wp_send_json_error(['message' => 'Nicht autorisiert. Bitte zuerst verifizieren.']); } - - if (!$t['claimed'] || $t['claimed_by'] !== $username) { - wp_send_json_error(['message' => 'Verification failed. Please go back to step 2 and use /verify']); + + // server_id als Integer für wp_query (falls numeric), sonst als String belassen + $server_id_val = is_numeric($server_id) ? intval($server_id) : $server_id; + if (!$server_id_val) { + wp_send_json_error(['message' => 'Server-ID fehlt.']); } if (empty($_FILES['mc_images']) || !is_array($_FILES['mc_images']['name'])) { @@ -596,7 +847,7 @@ class MC_Gallery_Core { $errors = []; try { - $gallery_post = MC_Gallery_Helpers::find_or_create_gallery_post($username, $server_id); + $gallery_post = MC_Gallery_Helpers::find_or_create_gallery_post($username, $server_id_val); if (!$gallery_post) throw new Exception('Gallery not found.'); if (empty($_FILES['mc_images']) || !is_array($_FILES['mc_images']['name'])) { diff --git a/includes/class-mc-gallery-forum-bridge.php b/includes/class-mc-gallery-forum-bridge.php new file mode 100644 index 0000000..38c7c48 --- /dev/null +++ b/includes/class-mc-gallery-forum-bridge.php @@ -0,0 +1,691 @@ + ' Minecraft', + 'order' => 50, + ]; + return $tabs; + } + + public static function render_profile_tab( $content, $tab, $profile_user ) { + if ( $tab !== 'minecraft' ) return $content; + + $current = WBF_Auth::get_current_user(); + $is_own = $current && (int) $current->id === (int) $profile_user->id; + $is_mod = $current && WBF_Roles::can( $current, 'manage_users' ); + + $mc_user = self::get_mc_username( $profile_user->id ); + $verified = self::is_verified( $profile_user->id ); + $servers = self::get_server_list(); + + ob_start(); + ?> +
+ + +
+ +
+ + + + Verifiziert + + + + Ausstehend + + + id ); + if ( $sv ) echo ' ' . esc_html( $sv ) . ''; + ?> +
+ +
+ + + + + + +
+ +
+ + +
+ + Noch nicht verifiziert. Du kannst entweder auf Admin-Bestätigung warten + oder deinen Ingame-Token normal in der Galerie eingeben — dann wird + die Verknüpfung automatisch bestätigt. +
+ + + + +

+ Verknüpfe deinen Minecraft-Account mit deinem Forum-Profil. + Danach kannst du Bilder in der Galerie ohne Ingame-Token hochladen. +

+ + + +

Kein Minecraft-Account verknüpft.

+ + +
+ + + 32 ) { + wp_send_json_error( 'Ungültiger Minecraft-Name (2–32 Zeichen).' ); + } + if ( ! preg_match( '/^[a-zA-Z0-9_]+$/', $mc_user ) ) { + wp_send_json_error( 'Nur Buchstaben, Zahlen und _ erlaubt.' ); + } + + // Doppelte Verknüpfung verhindern + if ( self::mc_user_taken( $mc_user, $user->id ) ) { + wp_send_json_error( 'Dieser Minecraft-Name ist bereits mit einem anderen Forum-Konto verknüpft.' ); + } + + self::set_mc_username( $user->id, $mc_user ); + self::set_mc_server( $user->id, $server ); + // Verifizierung: automatisch wenn gültiger Ingame-Token vorliegt + $auto_verified = self::check_active_token_for( $mc_user ); + self::set_verified( $user->id, $auto_verified ); + + wp_send_json_success( [ + 'mc_username' => $mc_user, + 'verified' => $auto_verified, + ] ); + } + + /** Account-Verknüpfung trennen */ + public static function ajax_unlink_account() { + check_ajax_referer( self::NONCE_ACTION, 'nonce' ); + + $user = WBF_Auth::get_current_user(); + if ( ! $user ) wp_send_json_error( 'Nicht eingeloggt.' ); + + self::delete_mc_link( $user->id ); + wp_send_json_success(); + } + + /** Admin bestätigt eine ausstehende Verknüpfung */ + public static function ajax_admin_approve() { + check_ajax_referer( self::NONCE_ACTION, 'nonce' ); + + $current = WBF_Auth::get_current_user(); + if ( ! $current || ! WBF_Roles::can( $current, 'manage_users' ) ) { + wp_send_json_error( 'Keine Berechtigung.' ); + } + + $target_id = (int) ( $_POST['user_id'] ?? 0 ); + if ( ! $target_id ) wp_send_json_error( 'Ungültige Benutzer-ID.' ); + + self::set_verified( $target_id, true ); + wp_send_json_success(); + } + + /** + * Galerie-Verify via Forum-Login. + * Wird vom Frontend aufgerufen wenn der User auf "Mit Forum-Login verifizieren" klickt. + * Gibt bei Erfolg MC-Username + Server zurück, die das Gallery-JS dann als würden + * sie aus einem Token-Verify stammen weiterverarbeiten kann. + */ + public static function ajax_verify_upload() { + check_ajax_referer( self::NONCE_ACTION, 'nonce' ); + + $forum_user = WBF_Auth::get_current_user(); + if ( ! $forum_user ) { + wp_send_json_error( [ + 'code' => 'not_logged_in', + 'message' => 'Du musst im Forum eingeloggt sein.', + ] ); + } + + $mc_user = self::get_mc_username( $forum_user->id ); + $verified = self::is_verified( $forum_user->id ); + + if ( ! $mc_user ) { + wp_send_json_error( [ + 'code' => 'no_mc_link', + 'message' => 'Kein Minecraft-Konto verknüpft. Bitte zuerst im Profil verknüpfen.', + ] ); + } + + // Noch nicht verifiziert → Ingame-Token als letzten Ausweg prüfen + if ( ! $verified ) { + if ( self::check_active_token_for( $mc_user ) ) { + self::set_verified( $forum_user->id, true ); + $verified = true; + } + } + + if ( ! $verified ) { + wp_send_json_error( [ + 'code' => 'not_verified', + 'message' => 'Dein Account ist noch nicht verifiziert. Bitte einen Admin um Bestätigung oder nutze einmalig das Ingame-Token.', + ] ); + } + + $server_id = self::get_mc_server( $forum_user->id ) + ?: sanitize_text_field( $_POST['server_id'] ?? '' ); + + wp_send_json_success( [ + 'mc_username' => $mc_user, + 'server_id' => $server_id, + 'display_name' => $forum_user->display_name, + 'verify_type' => 'forum_login', + ] ); + } + + // ── Filter: Gallery-Upload-Berechtigung ─────────────────────────────────── + + /** + * Gibt true zurück wenn ein eingeloggter Forum-User einen verifizierten + * Link zu $mc_username hat — ersetzt dann die normale Token-Prüfung. + * Wird nur aufgerufen wenn die Gallery `apply_filters('mc_gallery_can_upload', …)` nutzt. + */ + public static function filter_upload_permission( $allowed, $mc_username, $server_id ) { + if ( $allowed ) return true; // schon erlaubt, nicht überschreiben + + $forum_user = WBF_Auth::get_current_user(); + if ( ! $forum_user ) return false; + + $linked = self::get_mc_username( $forum_user->id ); + if ( ! $linked ) return false; + if ( strtolower( $linked ) !== strtolower( $mc_username ) ) return false; + + return self::is_verified( $forum_user->id ); + } + + // ── Filter: Zusätzliche Verify-UI in der Gallery ────────────────────────── + + /** + * Hängt unter das normale Verify-Formular einen "Mit Forum-Login"-Bereich. + * Funktioniert wenn die Gallery `apply_filters('mc_gallery_verify_ui_extra', '', $server_id)` aufruft. + * + * Falls der Hook nicht existiert: eigenen Shortcode [mc_gallery_forum_login] nutzen. + */ + public static function render_verify_panel( $html, $server_id ) { + return $html . self::build_verify_panel( $server_id ); + } + + /** + * Shortcode [mc_gallery_forum_login server_id="survival"] + * Kann manuell auf der Upload-Seite eingebettet werden falls der Hook-Ansatz + * nicht greift. + */ + public static function shortcode_verify_panel( $atts ) { + $atts = shortcode_atts( [ 'server_id' => '' ], $atts ); + return self::build_verify_panel( sanitize_text_field( $atts['server_id'] ) ); + } + + /** Eigentliches HTML für das Verify-Panel */ + public static function build_verify_panel( $server_id ) { + $forum_user = WBF_Auth::get_current_user(); + $nonce = wp_create_nonce( self::NONCE_ACTION ); + $ajax_url = admin_url( 'admin-ajax.php' ); + + ob_start(); + ?> +
+
oder
+ + +
+
+
+ +
+
+
Forum-Login
+
+ Direkt hochladen ohne Ingame-Token – wenn dein Minecraft-Account mit dem Forum verknüpft ist. +
+
+ +
+
+ + id ); + $verified = self::is_verified( $forum_user->id ); + $forum_url = function_exists('wbf_get_forum_url') + ? wbf_get_forum_url() . '?forum_profile=' . (int) $forum_user->id . '#tab-minecraft' + : '#'; + ?> + + +
+ + Verifiziert als +
+ + +
+
+ +
+
Verknüpft · ausstehend
+
+ + · Noch nicht bestätigt +
+
+ +
+
+ + +
+
+
+ +
+
+
Eingeloggt als display_name ); ?>
+
+ Noch kein Minecraft-Konto verknüpft. +
+
+ +
+
+ + + + +
+ + + id ); + if ( ! $mc_user ) return; + + $verified = self::is_verified( $user->id ); + $nonce = wp_create_nonce( self::NONCE_ACTION ); + ?> + + + + + + + + + + + + + get_var( $wpdb->prepare( + "SELECT meta_value FROM {$wpdb->prefix}forum_user_meta + WHERE user_id = %d AND meta_key = %s + LIMIT 1", + (int) $user_id, $key + ) ); + } + + private static function set_meta( $user_id, $key, $value ) { + global $wpdb; + $table = $wpdb->prefix . 'forum_user_meta'; + + $exists = $wpdb->get_var( $wpdb->prepare( + "SELECT id FROM {$table} WHERE user_id = %d AND meta_key = %s", + (int) $user_id, $key + ) ); + + if ( $exists ) { + $wpdb->update( $table, + [ 'meta_value' => $value ], + [ 'user_id' => (int) $user_id, 'meta_key' => $key ] + ); + } else { + $wpdb->insert( $table, [ + 'user_id' => (int) $user_id, + 'meta_key' => $key, + 'meta_value' => $value, + ] ); + } + } + + private static function delete_meta( $user_id, $key ) { + global $wpdb; + $wpdb->delete( $wpdb->prefix . 'forum_user_meta', + [ 'user_id' => (int) $user_id, 'meta_key' => $key ] + ); + } + + // Öffentliche Getter/Setter + public static function get_mc_username( $user_id ) { return self::get_meta( $user_id, self::META_MC_USER ); } + public static function get_mc_server ( $user_id ) { return self::get_meta( $user_id, self::META_MC_SERVER ); } + public static function is_verified ( $user_id ) { return '1' === self::get_meta( $user_id, self::META_VERIFIED ); } + + public static function set_mc_username( $user_id, $val ) { self::set_meta( $user_id, self::META_MC_USER, $val ); } + public static function set_mc_server ( $user_id, $val ) { self::set_meta( $user_id, self::META_MC_SERVER, $val ); } + public static function set_verified ( $user_id, $bool ) { self::set_meta( $user_id, self::META_VERIFIED, $bool ? '1' : '0' ); } + + public static function delete_mc_link( $user_id ) { + self::delete_meta( $user_id, self::META_MC_USER ); + self::delete_meta( $user_id, self::META_MC_SERVER ); + self::delete_meta( $user_id, self::META_VERIFIED ); + } + + // Prüft ob ein MC-Name schon einem anderen Forum-User gehört + private static function mc_user_taken( $mc_user, $exclude_user_id ) { + global $wpdb; + return (bool) $wpdb->get_var( $wpdb->prepare( + "SELECT m.id FROM {$wpdb->prefix}forum_user_meta m + WHERE m.meta_key = %s + AND m.meta_value = %s + AND m.user_id != %d + LIMIT 1", + self::META_MC_USER, $mc_user, (int) $exclude_user_id + ) ); + } + + // Gibt true zurück wenn gerade ein gültiger Ingame-Token für diesen MC-Namen existiert + private static function check_active_token_for( $mc_username ) { + if ( ! class_exists( 'MC_Gallery_Helpers' ) ) return false; + $tokens = MC_Gallery_Helpers::get_tokens(); + $now = time(); + foreach ( $tokens as $token => $data ) { + if ( ! is_array( $data ) ) continue; + if ( ( $data['expires'] ?? 0 ) < $now ) continue; + if ( strtolower( $data['player'] ?? '' ) === strtolower( $mc_username ) ) { + return true; + } + } + return false; + } + + // Server-Liste aus Gallery-Config laden + private static function get_server_list() { + $servers = get_option( 'mc_gallery_servers', [] ); + if ( ! empty( $servers ) && is_array( $servers ) ) return $servers; + return [ 'default' => 'Standard-Server' ]; + } +} \ No newline at end of file diff --git a/includes/class-mc-gallery-shortcodes.php b/includes/class-mc-gallery-shortcodes.php index 884466a..79cde6a 100644 --- a/includes/class-mc-gallery-shortcodes.php +++ b/includes/class-mc-gallery-shortcodes.php @@ -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 .= '
'.$upload_date.'
'; } $out .= ''.esc_attr($q_player).''; + $out .= self::render_like_btn($img->ID); $out .= '