Update from Git Manager GUI
This commit is contained in:
41
assets/js/forum-bridge.js
Normal file
41
assets/js/forum-bridge.js
Normal file
@@ -0,0 +1,41 @@
|
||||
(function($){
|
||||
$(document).on('click', '.mc-bridge-verify-trigger', function(){
|
||||
console.log('[MC-Gallery] Forum-Login Button geklickt!');
|
||||
if (typeof $ === 'undefined') { alert('jQuery nicht geladen!'); return; }
|
||||
var $btn = $(this).prop('disabled', true);
|
||||
var ajax = $btn.data('ajax');
|
||||
var nonce = $btn.data('nonce');
|
||||
var server = $btn.data('server') || $btn.closest('[data-server]').data('server') || '';
|
||||
|
||||
$btn.html('<i class="fas fa-spinner fa-spin"></i> Prüfe…');
|
||||
|
||||
$.post(ajax, {
|
||||
action: 'mc_forum_verify_upload',
|
||||
nonce: nonce,
|
||||
server_id: server
|
||||
})
|
||||
.done(function(r){
|
||||
if ( r.success ) {
|
||||
$(document).trigger('mc_gallery_forum_verified', [ r.data ]);
|
||||
if ( typeof window.mcGalleryOnVerified === 'function' ) {
|
||||
window.mcGalleryOnVerified( r.data );
|
||||
}
|
||||
$btn.closest('.mc-bridge-verify-wrap')
|
||||
.html('<div class="mc-bridge-success">'
|
||||
+ '<i class="fas fa-check-circle"></i> Verifiziert als <strong>'
|
||||
+ $('<span>').text(r.data.mc_username).html()
|
||||
+ '</strong></div>');
|
||||
} else {
|
||||
var msg = (r.data && r.data.message) ? r.data.message : 'Fehler bei der Verifikation.';
|
||||
$btn.closest('.mc-bridge-verify-wrap').find('.mc-bridge-error').remove();
|
||||
$btn.closest('.mc-bridge-forum-linked, .mc-bridge-not-linked')
|
||||
.after('<p class="mc-bridge-error"><i class="fas fa-times-circle"></i> ' + msg + '</p>');
|
||||
$btn.prop('disabled', false).html('<i class="fas fa-sign-in-alt"></i> Mit Forum-Login verifizieren');
|
||||
}
|
||||
})
|
||||
.fail(function(){
|
||||
$btn.prop('disabled', false).html('<i class="fas fa-sign-in-alt"></i> Mit Forum-Login verifizieren');
|
||||
alert('Netzwerkfehler. Bitte erneut versuchen.');
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
@@ -119,16 +119,15 @@
|
||||
function loadAlbums() {
|
||||
const $select = $('#mc-upload-album');
|
||||
$select.html('<option value="">Kein Album</option>').prop('disabled', true);
|
||||
|
||||
if (!sessionData.token || !sessionData.verified) return;
|
||||
|
||||
// Auch ohne Token laden, wenn Forum-Session aktiv
|
||||
if ((!sessionData.token && !sessionData.verified) || !sessionData.username) return;
|
||||
fetch(api + '/albums', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
token: sessionData.token,
|
||||
username: sessionData.username,
|
||||
server_id: sessionData.serverId
|
||||
token: sessionData.token || '',
|
||||
username: sessionData.username,
|
||||
server_id: sessionData.serverId || ''
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
@@ -235,6 +234,23 @@
|
||||
|
||||
resetModal();
|
||||
loadServers();
|
||||
|
||||
// Wenn User bereits forum-verifiziert ist: direkt zu Schritt 3 springen
|
||||
if (mcGalleryPro.forumVerified) {
|
||||
const fv = mcGalleryPro.forumVerified;
|
||||
sessionData.verified = true;
|
||||
sessionData.username = fv.mc_username;
|
||||
sessionData.serverId = fv.server_id;
|
||||
sessionData.token = null;
|
||||
|
||||
$('#mc-session-user').text(fv.display_name || fv.mc_username);
|
||||
$('#mc_form_username').val(fv.mc_username);
|
||||
$('#mc_form_server').val(fv.server_id);
|
||||
$('#mc_form_token').val('');
|
||||
|
||||
switchStep(3);
|
||||
loadAlbums();
|
||||
}
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
@@ -245,6 +261,30 @@
|
||||
setTimeout(resetModal, 300);
|
||||
}
|
||||
|
||||
// Forum-Login: Auf globales Event reagieren
|
||||
$(document).on('mc_gallery_forum_verified', function(e, data) {
|
||||
if (!data || !data.mc_username || !data.server_id) {
|
||||
showFeedback('Forum-Login: Ungültige Antwort vom Server.', 'error');
|
||||
return;
|
||||
}
|
||||
sessionData.verified = true;
|
||||
sessionData.username = data.mc_username;
|
||||
sessionData.serverId = data.server_id;
|
||||
sessionData.token = null; // Kein Token nötig
|
||||
|
||||
$('#mc-session-user').text(data.display_name || data.mc_username);
|
||||
$('#mc_form_username').val(data.mc_username);
|
||||
$('#mc_form_server').val(data.server_id);
|
||||
$('#mc_form_token').val('');
|
||||
|
||||
showFeedback('✓ Erfolgreich mit Forum-Login verifiziert!', 'success');
|
||||
setTimeout(() => {
|
||||
switchStep(3);
|
||||
console.log('[MC-Gallery] mc_gallery_forum_verified: switchStep(3) ausgeführt, Upload-Schritt sollte sichtbar sein.');
|
||||
loadAlbums();
|
||||
}, 800);
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
loadServers();
|
||||
@@ -264,6 +304,53 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Forum-Login-Button im Modal (Schritt 1) — einmalig binden, NICHT inside btn-generate
|
||||
$(document).on('click', '#mc-btn-forum-login', function () {
|
||||
const serverId = $('#mc-upload-server').val();
|
||||
if (!serverId || serverId === '') {
|
||||
showFeedback('Bitte wähle einen Server aus.', 'error');
|
||||
return;
|
||||
}
|
||||
const $btn = $(this);
|
||||
const originalText = $btn.html();
|
||||
$btn.prop('disabled', true).html('<span class="mc-loading"></span> Prüfe Forum-Login...');
|
||||
|
||||
$.ajax({
|
||||
url: ajaxUrl,
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'mc_forum_verify_upload',
|
||||
nonce: mcGalleryPro.forumNonce || mcGalleryPro.nonce,
|
||||
server_id: serverId
|
||||
},
|
||||
success: function (data) {
|
||||
$btn.prop('disabled', false).html(originalText);
|
||||
if (data.success && data.data && data.data.mc_username) {
|
||||
sessionData.verified = true;
|
||||
sessionData.username = data.data.mc_username;
|
||||
sessionData.serverId = data.data.server_id;
|
||||
sessionData.token = null;
|
||||
|
||||
$('#mc-session-user').text(data.data.display_name || data.data.mc_username);
|
||||
$('#mc_form_username').val(data.data.mc_username);
|
||||
$('#mc_form_server').val(data.data.server_id);
|
||||
$('#mc_form_token').val('');
|
||||
|
||||
showFeedback('✓ Erfolgreich mit Forum-Login verifiziert!', 'success');
|
||||
setTimeout(() => { switchStep(3); loadAlbums(); }, 800);
|
||||
} else {
|
||||
const msg = (data.data && data.data.message) ? data.data.message : (data.message || 'Verifizierung fehlgeschlagen.');
|
||||
showFeedback(msg, 'error');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$btn.prop('disabled', false).html(originalText);
|
||||
showFeedback('Netzwerkfehler bei der Forum-Login-Prüfung', 'error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#mc-btn-generate').on('click', function () {
|
||||
const username = $('#mc-upload-username').val().trim();
|
||||
const serverId = $('#mc-upload-server').val();
|
||||
@@ -432,9 +519,9 @@
|
||||
const formData = new FormData();
|
||||
formData.append('action', 'mc_gallery_create_album');
|
||||
formData.append('mc_upload_nonce', mcGalleryPro.nonce);
|
||||
formData.append('mc_token', sessionData.token);
|
||||
formData.append('mc_token', sessionData.token || '');
|
||||
formData.append('mc_username', sessionData.username);
|
||||
formData.append('mc_server_id', sessionData.serverId);
|
||||
formData.append('mc_server_id', sessionData.serverId || '');
|
||||
formData.append('album_name', albumName);
|
||||
|
||||
fetch(ajaxUrl, {
|
||||
@@ -477,10 +564,16 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Auch ohne Token erlauben, wenn Forum-Session aktiv
|
||||
if (!sessionData.verified || !sessionData.username) {
|
||||
showFeedback('Bitte verifiziere dich zuerst.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('action', 'mc_gallery_upload');
|
||||
formData.append('mc_upload_nonce', mcGalleryPro.nonce);
|
||||
formData.append('mc_token', sessionData.token);
|
||||
formData.append('mc_token', sessionData.token || '');
|
||||
formData.append('mc_username', sessionData.username);
|
||||
formData.append('mc_server_id', sessionData.serverId);
|
||||
formData.append('mc_album_id', $('#mc-upload-album').val() || '');
|
||||
@@ -546,6 +639,77 @@
|
||||
$('#mc-upload-file').click();
|
||||
});
|
||||
|
||||
// === VOTE BUTTONS (Daumen hoch / runter) ===
|
||||
if (mcGalleryPro.votingEnabled) {
|
||||
|
||||
// Cookie-Zustand initialisieren
|
||||
function initVoteBtns() {
|
||||
$('.mc-vote-wrap').each(function() {
|
||||
const aid = $(this).data('attach-id');
|
||||
const up = document.cookie.split(';').some(c => c.trim() === 'mc_vote_' + aid + '=up');
|
||||
const down = document.cookie.split(';').some(c => c.trim() === 'mc_vote_' + aid + '=down');
|
||||
if (up) $(this).find('.mc-vote-up').addClass('mc-vote-btn--active');
|
||||
if (down) $(this).find('.mc-vote-down').addClass('mc-vote-btn--active');
|
||||
});
|
||||
}
|
||||
initVoteBtns();
|
||||
|
||||
$(document).on('click', '.mc-vote-btn', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
const $btn = $(this);
|
||||
const $wrap = $btn.closest('.mc-vote-wrap');
|
||||
const aid = $wrap.data('attach-id');
|
||||
const nonce = $wrap.data('nonce');
|
||||
const type = $btn.data('type'); // 'up' oder 'down'
|
||||
const ck = 'mc_vote_' + aid;
|
||||
const current = document.cookie.split(';').find(c => c.trim().startsWith(ck + '='));
|
||||
const curVal = current ? current.trim().split('=')[1] : null;
|
||||
|
||||
if ($btn.prop('disabled')) return;
|
||||
$wrap.find('.mc-vote-btn').prop('disabled', true);
|
||||
|
||||
// Toggle-Logik: nochmal klicken = entfernen
|
||||
const isActive = $btn.hasClass('mc-vote-btn--active');
|
||||
const action = isActive ? 'remove' : 'add';
|
||||
|
||||
$.post(ajaxUrl, {
|
||||
action: 'mc_gallery_vote',
|
||||
attach_id: aid,
|
||||
vote_type: type,
|
||||
vote_action: action,
|
||||
nonce: nonce
|
||||
})
|
||||
.done(function(r) {
|
||||
if (r.success) {
|
||||
$wrap.find('.mc-vote-up-count').text(r.data.votes_up);
|
||||
$wrap.find('.mc-vote-down-count').text(r.data.votes_down);
|
||||
|
||||
if (action === 'add') {
|
||||
// Gegenpart deaktivieren falls aktiv
|
||||
const other = type === 'up' ? 'down' : 'up';
|
||||
$wrap.find('.mc-vote-' + other).removeClass('mc-vote-btn--active');
|
||||
$btn.addClass('mc-vote-btn--active');
|
||||
const exp = new Date(); exp.setDate(exp.getDate() + 30);
|
||||
document.cookie = ck + '=' + type + '; expires=' + exp.toUTCString() + '; path=/; SameSite=Lax';
|
||||
} else {
|
||||
$btn.removeClass('mc-vote-btn--active');
|
||||
document.cookie = ck + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
|
||||
}
|
||||
|
||||
// Lightbox-Zähler synchronisieren
|
||||
$('.mc-vote-wrap[data-attach-id="' + aid + '"] .mc-vote-up-count').text(r.data.votes_up);
|
||||
$('.mc-vote-wrap[data-attach-id="' + aid + '"] .mc-vote-down-count').text(r.data.votes_down);
|
||||
}
|
||||
$wrap.find('.mc-vote-btn').prop('disabled', false);
|
||||
})
|
||||
.fail(function() {
|
||||
$wrap.find('.mc-vote-btn').prop('disabled', false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// === LIGHTBOX & VIEW COUNT ===
|
||||
$(document).on('click', '.mc-gallery-item', function (e) {
|
||||
e.preventDefault();
|
||||
@@ -566,31 +730,40 @@
|
||||
}
|
||||
|
||||
const player = $item.data('player') || $item.find('.mc-watermark').text().trim();
|
||||
const date = $item.data('date') || '';
|
||||
const album = $item.data('album') || '';
|
||||
const views = $item.data('views') || 0;
|
||||
const date = $item.data('date') || '';
|
||||
const album = $item.data('album') || '';
|
||||
|
||||
const $lightbox = $('<div class="mc-lightbox active"></div>');
|
||||
const $content = $('<div class="mc-lightbox-content"></div>');
|
||||
const $img = $('<img>').attr({
|
||||
'src': href,
|
||||
'alt': player
|
||||
});
|
||||
const $close = $('<button class="mc-lightbox-close" aria-label="Schließen">×</button>');
|
||||
|
||||
const $content = $('<div class="mc-lightbox-content"></div>');
|
||||
const $img = $('<img>').attr({ src: href, alt: player });
|
||||
const $close = $('<button class="mc-lightbox-close" aria-label="Schließen">×</button>');
|
||||
|
||||
// Info-Zeile
|
||||
let infoHtml = '';
|
||||
if (player) infoHtml += `👤 ${player}`;
|
||||
if (date && player) infoHtml += ' • ';
|
||||
if (date) infoHtml += `📅 ${date}`;
|
||||
if (album) infoHtml += ` • 📁 ${album}`;
|
||||
// Views auch in Lightbox zeigen
|
||||
if (views) infoHtml += ' • 👁️ ' + views;
|
||||
|
||||
if (infoHtml) {
|
||||
const $info = $('<div class="mc-lightbox-info"></div>').html(infoHtml);
|
||||
$content.append($info);
|
||||
}
|
||||
|
||||
// Vote-Buttons in Lightbox
|
||||
if (attachId) {
|
||||
const $voteWrap = $item.find('.mc-vote-wrap').clone();
|
||||
if ($voteWrap.length) {
|
||||
$voteWrap.addClass('mc-vote-wrap--lightbox');
|
||||
$content.append($voteWrap);
|
||||
// Cookie-Zustand wiederherstellen
|
||||
const ck = 'mc_vote_' + attachId;
|
||||
const cur = document.cookie.split(';').find(c => c.trim().startsWith(ck + '='));
|
||||
const curV = cur ? cur.trim().split('=')[1] : null;
|
||||
if (curV === 'up') $voteWrap.find('.mc-vote-up').addClass('mc-vote-btn--active');
|
||||
if (curV === 'down') $voteWrap.find('.mc-vote-down').addClass('mc-vote-btn--active');
|
||||
}
|
||||
}
|
||||
|
||||
$content.append($close).append($img);
|
||||
$lightbox.append($content).appendTo('body');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user