Update from Git Manager GUI
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
|
||||
class MC_Gallery_Core {
|
||||
|
||||
const OPTION_FORUM_LOGIN = 'mc_gallery_forum_login';
|
||||
const OPTION_VOTING = 'mc_gallery_voting_enabled';
|
||||
private static $forum_plugin_active = false;
|
||||
|
||||
const OPTION_THUMB_H = 'mc_gallery_thumb_h';
|
||||
const OPTION_RESIZE_PCT = 'mc_gallery_resize_pct';
|
||||
const OPTION_SHOW_DATE = 'mc_gallery_show_date';
|
||||
@@ -10,6 +15,8 @@ class MC_Gallery_Core {
|
||||
const SESSION_TTL = 3600; // 1 Stunde Session
|
||||
|
||||
public static function init() {
|
||||
// Prüfen, ob das Forum-Plugin aktiv ist
|
||||
self::$forum_plugin_active = class_exists('WBF_Auth');
|
||||
add_action('init', [__CLASS__, 'register_post_types']);
|
||||
add_action('rest_api_init', [__CLASS__, 'register_rest_routes']);
|
||||
|
||||
@@ -22,6 +29,9 @@ class MC_Gallery_Core {
|
||||
add_action('wp_ajax_mc_gallery_create_album', [__CLASS__, 'handle_create_album']);
|
||||
add_action('wp_ajax_nopriv_mc_gallery_create_album', [__CLASS__, 'handle_create_album']);
|
||||
|
||||
add_action('wp_ajax_mc_gallery_vote', [__CLASS__, 'handle_vote']);
|
||||
add_action('wp_ajax_nopriv_mc_gallery_vote', [__CLASS__, 'handle_vote']);
|
||||
|
||||
add_action('wp_enqueue_scripts', [__CLASS__, 'enqueue_assets']);
|
||||
|
||||
// Meta Boxen & UI
|
||||
@@ -202,7 +212,7 @@ class MC_Gallery_Core {
|
||||
register_setting('mc_gallery_pro_group', self::OPTION_RESIZE_PCT, ['type' => '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;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>MC Gallery PRO Settings</h1>
|
||||
@@ -250,8 +286,84 @@ class MC_Gallery_Core {
|
||||
<p class="description">How many images can a user upload at once? (Default: 5)</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
Forum-Login für Upload-Verifizierung
|
||||
<br><span style="font-weight:400;color:#646970;font-size:12px;">Benötigt: WP Business Forum</span>
|
||||
</th>
|
||||
<td>
|
||||
<?php if ( $forum_plugin_active ) : ?>
|
||||
|
||||
<?php /* ── Plugin aktiv & bereit ── */ ?>
|
||||
<div style="display:flex;align-items:center;gap:8px;margin-bottom:10px;">
|
||||
<span style="display:inline-flex;align-items:center;gap:5px;padding:3px 10px;border-radius:20px;background:#edfaef;border:1px solid #c3e6cb;color:#1a7431;font-size:12px;font-weight:600;">
|
||||
<span style="width:7px;height:7px;border-radius:50%;background:#22c55e;display:inline-block;"></span>
|
||||
WP Business Forum aktiv
|
||||
</span>
|
||||
</div>
|
||||
<label>
|
||||
<input type="checkbox" name="<?php echo esc_attr(self::OPTION_FORUM_LOGIN); ?>" value="1" <?php checked($forum_login, '1'); ?> />
|
||||
Forum-Login für Upload-Verifizierung erlauben
|
||||
</label>
|
||||
<p class="description" style="margin-top:6px;">
|
||||
Wenn aktiviert, können sich Nutzer die ihren Minecraft-Account im Forum-Profil verknüpft haben, direkt ohne Ingame-Token hochladen.<br>
|
||||
<strong>Der Shortcode:</strong> <code>[mc_gallery_combined]</code> <strong>ermöglicht eine kombinierte Verifizierung für Token und Forum.</strong>
|
||||
</p>
|
||||
|
||||
<?php elseif ( $forum_plugin_installed ) : ?>
|
||||
|
||||
<?php /* ── Plugin installiert aber nicht aktiviert ── */ ?>
|
||||
<div style="padding:12px 14px;background:#fff8e6;border:1px solid #f0c040;border-left:4px solid #f0c040;border-radius:0 6px 6px 0;margin-bottom:12px;">
|
||||
<strong style="color:#7a5400;">⚠ WP Business Forum ist installiert, aber nicht aktiviert.</strong><br>
|
||||
<span style="color:#7a5400;font-size:13px;">Aktiviere das Plugin unter <a href="<?php echo esc_url(admin_url('plugins.php')); ?>" style="color:#7a5400;text-decoration:underline;">Plugins → Installierte Plugins</a>, um diese Funktion zu nutzen.</span>
|
||||
</div>
|
||||
<label style="opacity:.5;pointer-events:none;">
|
||||
<input type="checkbox" disabled />
|
||||
Forum-Login für Upload-Verifizierung erlauben
|
||||
</label>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<?php /* ── Plugin nicht vorhanden ── */ ?>
|
||||
<div style="padding:12px 14px;background:#fef2f2;border:1px solid #fca5a5;border-left:4px solid #ef4444;border-radius:0 6px 6px 0;margin-bottom:12px;">
|
||||
<strong style="color:#991b1b;">✗ WP Business Forum ist nicht installiert.</strong><br>
|
||||
<span style="color:#991b1b;font-size:13px;">
|
||||
Dieses Feature benötigt das Plugin <em>WP Business Forum</em> von M_Viper.<br>
|
||||
<a href="https://git.viper.ipv64.net/M_Viper/WP-Business-Forum/releases" target="_blank" rel="noopener" style="color:#b91c1c;font-weight:600;text-decoration:underline;">
|
||||
↓ Jetzt herunterladen (Gitea)
|
||||
</a>
|
||||
·
|
||||
<a href="<?php echo esc_url(admin_url('plugin-install.php')); ?>" style="color:#b91c1c;text-decoration:underline;">
|
||||
Plugins → Neu hinzufügen
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<label style="opacity:.5;pointer-events:none;">
|
||||
<input type="checkbox" disabled />
|
||||
Forum-Login für Upload-Verifizierung erlauben
|
||||
</label>
|
||||
<p class="description" style="margin-top:6px;color:#888;">
|
||||
Nach der Installation und Aktivierung von WP Business Forum wird diese Option freigeschaltet.
|
||||
</p>
|
||||
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Abstimmung (Daumen hoch/runter)</th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="<?php echo esc_attr(self::OPTION_VOTING); ?>" value="1" <?php checked(get_option(self::OPTION_VOTING, true), true); ?> />
|
||||
Abstimmung auf Bilder aktivieren
|
||||
</label>
|
||||
<p class="description" style="margin-top:6px;">
|
||||
Besucher können Bilder mit 👍 oder 👎 bewerten. Jeder kann abstimmen (kein Login nötig).<br>
|
||||
Shortcode für die Bestenliste: <code>[mc_gallery_vote]</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php submit_button(); ?>
|
||||
<?php submit_button('Änderungen speichern'); ?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
@@ -268,16 +380,43 @@ class MC_Gallery_Core {
|
||||
}
|
||||
|
||||
public static function enqueue_assets() {
|
||||
$js_version = time(); // Zeitstempel für Cache-Busting
|
||||
wp_register_style('mc-gallery-pro-css', MCGALLERY_PRO_URL . 'assets/css/gallery-pro.css', [], MCGALLERY_PRO_VERSION);
|
||||
wp_register_script('mc-gallery-pro-js', MCGALLERY_PRO_URL . 'assets/js/gallery-pro.js', ['jquery'], MCGALLERY_PRO_VERSION, true);
|
||||
wp_register_script('mc-gallery-pro-js', MCGALLERY_PRO_URL . 'assets/js/gallery-pro.js?v=' . $js_version, ['jquery'], null, true);
|
||||
wp_enqueue_style('mc-gallery-pro-css');
|
||||
wp_enqueue_script('mc-gallery-pro-js');
|
||||
// Forum-Verified-Status für JS ermitteln
|
||||
$forum_verified_data = false;
|
||||
if ( class_exists('WBF_Auth') && class_exists('MC_Gallery_Forum_Bridge') ) {
|
||||
$forum_user = WBF_Auth::get_current_user();
|
||||
if ( $forum_user ) {
|
||||
$mc_user = MC_Gallery_Forum_Bridge::get_mc_username( $forum_user->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'])) {
|
||||
|
||||
Reference in New Issue
Block a user