4 Commits
2.5.5 ... main

View File

@@ -1,330 +1,337 @@
<?php <?php
/* /*
Plugin Name: MC MultiServer Gallery PRO Plugin Name: MC MultiServer Gallery PRO
Description: Professionelle Minecraft-Galerie mit Ingame-Verification, modernem UI, Lightbox und AJAX-Upload (multi-server fähig). Plugin URI:https://git.viper.ipv64.net/M_Viper/Wordpress-MC-Gallery
Version: 2.5.5 Description: Professionelle Minecraft-Galerie mit Ingame-Verification, modernem UI, Lightbox und AJAX-Upload (multi-server fähig).
Author: M_Viper Version: 2.5.5
Plugin URI: https://git.viper.ipv64.net/M_Viper/Wordpress-MC-Gallery/releases Author: M_Viper
Author URI: https://m-viper.de Author URI: https://m-viper.de
Text Domain: mc-multiserver-gallery-pro Requires at least: 6.8
Domain Path: /languages Tested up to: 6.8
*/ PHP Version: 7.4
License: GPL2
if (!defined('ABSPATH')) exit; License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: mc-multiserver-gallery-pro
// =========================================== Tags: Gallery, Minecraft, MultiServer, Ingame-Verification, AJAX-Upload, Lightbox, Shortcode, Widget
// MC GALLERY PRO - UPDATE NOTICE SYSTEM Support: [Discord Support](https://discord.com/invite/FdRs4BRd8D)
// =========================================== Support: [Telegram Support](https://t.me/M_Viper04)
*/
// Plugin-Version aus Header lesen (NICHT aus Konstante)
function mc_gallery_get_plugin_version() { if (!defined('ABSPATH')) exit;
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php'; // ===========================================
} // MC GALLERY PRO - UPDATE NOTICE SYSTEM
// ===========================================
$plugin_data = get_plugin_data( __FILE__ );
return $plugin_data['Version'] ?? '0.0.0'; // Plugin-Version aus Header lesen (NICHT aus Konstante)
} function mc_gallery_get_plugin_version() {
if ( ! function_exists( 'get_plugin_data' ) ) {
// Cache manuell leeren require_once ABSPATH . 'wp-admin/includes/plugin.php';
function mc_gallery_clear_update_cache() { }
if ( isset($_GET['mc_gallery_clear_cache']) && current_user_can('manage_options') ) {
check_admin_referer('mc_gallery_clear_cache_action'); $plugin_data = get_plugin_data( __FILE__ );
delete_transient('mc_gallery_latest_release'); return $plugin_data['Version'] ?? '0.0.0';
wp_redirect( admin_url('plugins.php') ); }
exit;
} // Cache manuell leeren
} function mc_gallery_clear_update_cache() {
add_action('admin_init', 'mc_gallery_clear_update_cache'); if ( isset($_GET['mc_gallery_clear_cache']) && current_user_can('manage_options') ) {
check_admin_referer('mc_gallery_clear_cache_action');
// Neueste Release-Infos von Gitea holen delete_transient('mc_gallery_latest_release');
function mc_gallery_get_latest_release_info( $force_refresh = false ) { wp_redirect( admin_url('plugins.php') );
$transient_key = 'mc_gallery_latest_release'; exit;
}
if ( $force_refresh ) { }
delete_transient( $transient_key ); add_action('admin_init', 'mc_gallery_clear_update_cache');
}
// Neueste Release-Infos von Gitea holen
$release_info = get_transient( $transient_key ); function mc_gallery_get_latest_release_info( $force_refresh = false ) {
$transient_key = 'mc_gallery_latest_release';
if ( false === $release_info ) {
$response = wp_remote_get( if ( $force_refresh ) {
'https://git.viper.ipv64.net/api/v1/repos/M_Viper/Wordpress-MC-Gallery/releases/latest', delete_transient( $transient_key );
['timeout' => 10] }
);
$release_info = get_transient( $transient_key );
if ( ! is_wp_error($response) && 200 === wp_remote_retrieve_response_code($response) ) {
$body = wp_remote_retrieve_body($response); if ( false === $release_info ) {
$data = json_decode($body, true); $response = wp_remote_get(
'https://git.viper.ipv64.net/api/v1/repos/M_Viper/Wordpress-MC-Gallery/releases/latest',
if ( $data && isset($data['tag_name']) ) { ['timeout' => 10]
$tag = ltrim( $data['tag_name'], 'vV' ); );
$release_info = [ if ( ! is_wp_error($response) && 200 === wp_remote_retrieve_response_code($response) ) {
'version' => $tag, $body = wp_remote_retrieve_body($response);
'download_url' => $data['zipball_url'] ?? '', $data = json_decode($body, true);
'notes' => $data['body'] ?? '',
'published_at' => $data['published_at'] ?? '', if ( $data && isset($data['tag_name']) ) {
]; $tag = ltrim( $data['tag_name'], 'vV' );
set_transient( $transient_key, $release_info, 6 * HOUR_IN_SECONDS ); $release_info = [
} else { 'version' => $tag,
set_transient( $transient_key, [], HOUR_IN_SECONDS ); 'download_url' => $data['zipball_url'] ?? '',
} 'notes' => $data['body'] ?? '',
} else { 'published_at' => $data['published_at'] ?? '',
set_transient( $transient_key, [], HOUR_IN_SECONDS ); ];
}
} set_transient( $transient_key, $release_info, 6 * HOUR_IN_SECONDS );
} else {
return $release_info; set_transient( $transient_key, [], HOUR_IN_SECONDS );
} }
} else {
// Admin-Update-Hinweis anzeigen set_transient( $transient_key, [], HOUR_IN_SECONDS );
function mc_gallery_show_update_notice() { }
if ( ! current_user_can('manage_options') ) { }
return;
} return $release_info;
}
$current_version = mc_gallery_get_plugin_version();
$latest_release = mc_gallery_get_latest_release_info(); // Admin-Update-Hinweis anzeigen
function mc_gallery_show_update_notice() {
if ( ! empty($latest_release['version']) && version_compare($current_version, $latest_release['version'], '<') ) { if ( ! current_user_can('manage_options') ) {
return;
$refresh_url = wp_nonce_url( }
admin_url('plugins.php?mc_gallery_clear_cache=1'),
'mc_gallery_clear_cache_action' $current_version = mc_gallery_get_plugin_version();
); $latest_release = mc_gallery_get_latest_release_info();
?>
<div class="notice notice-warning is-dismissible"> if ( ! empty($latest_release['version']) && version_compare($current_version, $latest_release['version'], '<') ) {
<h3>MC MultiServer Gallery PRO Update verfügbar</h3>
<p> $refresh_url = wp_nonce_url(
Installiert: <strong><?php echo esc_html($current_version); ?></strong><br> admin_url('plugins.php?mc_gallery_clear_cache=1'),
Neueste Version: <strong><?php echo esc_html($latest_release['version']); ?></strong> 'mc_gallery_clear_cache_action'
</p> );
<p> ?>
<a href="<?php echo esc_url($latest_release['download_url']); ?>" class="button button-primary" target="_blank"> <div class="notice notice-warning is-dismissible">
Update herunterladen <h3>MC MultiServer Gallery PRO Update verfügbar</h3>
</a> <p>
<a href="https://git.viper.ipv64.net/M_Viper/Wordpress-MC-Gallery/releases" class="button" target="_blank"> Installiert: <strong><?php echo esc_html($current_version); ?></strong><br>
Release Notes Neueste Version: <strong><?php echo esc_html($latest_release['version']); ?></strong>
</a> </p>
<a href="<?php echo esc_url($refresh_url); ?>" class="button"> <p>
Jetzt neu prüfen <a href="<?php echo esc_url($latest_release['download_url']); ?>" class="button button-primary" target="_blank">
</a> Update herunterladen
</p> </a>
</div> <a href="https://git.viper.ipv64.net/M_Viper/Wordpress-MC-Gallery/releases" class="button" target="_blank">
<?php Release Notes
} </a>
} <a href="<?php echo esc_url($refresh_url); ?>" class="button">
add_action('admin_notices', 'mc_gallery_show_update_notice'); Jetzt neu prüfen
</a>
</p>
if (version_compare(PHP_VERSION, '7.0', '<')) { </div>
if (is_admin()) { <?php
add_action('admin_notices', function() { }
echo '<div class="error"><p><strong>MC Gallery PRO:</strong> Dieses Plugin benötigt PHP 7.0 oder höher.</p></div>'; }
}); add_action('admin_notices', 'mc_gallery_show_update_notice');
}
return;
} if (version_compare(PHP_VERSION, '7.0', '<')) {
if (is_admin()) {
if (defined('MCGALLERY_PRO_VERSION')) { return; } add_action('admin_notices', function() {
echo '<div class="error"><p><strong>MC Gallery PRO:</strong> Dieses Plugin benötigt PHP 7.0 oder höher.</p></div>';
define('MCGALLERY_PRO_VERSION', '2.5.4'); });
define('MCGALLERY_PRO_DIR', plugin_dir_path(__FILE__)); }
define('MCGALLERY_PRO_URL', plugin_dir_url(__FILE__)); return;
define('MCGALLERY_TOKEN_TTL', 300); }
define('MCGALLERY_OPTION_KEY', 'mc_gallery_tokens_store');
if (defined('MCGALLERY_PRO_VERSION')) { return; }
function mc_gallery_pro_safe_require($path) {
if (!file_exists($path)) { define('MCGALLERY_PRO_VERSION', '2.5.4');
if (is_admin()) { define('MCGALLERY_PRO_DIR', plugin_dir_path(__FILE__));
add_action('admin_notices', function() use ($path) { define('MCGALLERY_PRO_URL', plugin_dir_url(__FILE__));
echo '<div class="error"><p><strong>MC Gallery PRO Fehler:</strong> Datei nicht gefunden: <code>' . esc_html($path) . '</code>.</p></div>'; define('MCGALLERY_TOKEN_TTL', 300);
}); define('MCGALLERY_OPTION_KEY', 'mc_gallery_tokens_store');
}
return false; function mc_gallery_pro_safe_require($path) {
} if (!file_exists($path)) {
require_once $path; if (is_admin()) {
return true; add_action('admin_notices', function() use ($path) {
} echo '<div class="error"><p><strong>MC Gallery PRO Fehler:</strong> Datei nicht gefunden: <code>' . esc_html($path) . '</code>.</p></div>';
});
function mc_gallery_pro_load_textdomain() { }
load_plugin_textdomain('mc-multiserver-gallery-pro', false, basename(dirname(__FILE__)) . '/languages'); return false;
} }
add_action('plugins_loaded', 'mc_gallery_pro_load_textdomain'); require_once $path;
return true;
$core_files = [ }
'class-mc-gallery-helpers.php',
'class-mc-gallery-core.php', function mc_gallery_pro_load_textdomain() {
'class-mc-gallery-shortcodes.php', load_plugin_textdomain('mc-multiserver-gallery-pro', false, basename(dirname(__FILE__)) . '/languages');
]; }
add_action('plugins_loaded', 'mc_gallery_pro_load_textdomain');
if (!is_dir(MCGALLERY_PRO_DIR . 'includes')) {
add_action('admin_notices', function() { $core_files = [
echo '<div class="error"><p><strong>MC Gallery PRO Fehler:</strong> Der Ordner <code>includes/</code> fehlt.</p></div>'; 'class-mc-gallery-helpers.php',
}); 'class-mc-gallery-core.php',
} else { 'class-mc-gallery-shortcodes.php',
foreach ($core_files as $file) { ];
if (!mc_gallery_pro_safe_require(MCGALLERY_PRO_DIR . 'includes/' . $file)) {
return; if (!is_dir(MCGALLERY_PRO_DIR . 'includes')) {
} add_action('admin_notices', function() {
} echo '<div class="error"><p><strong>MC Gallery PRO Fehler:</strong> Der Ordner <code>includes/</code> fehlt.</p></div>';
});
// ── WP Business Forum — optionale Bridge ───────────────────────────────── } else {
// Wird nur geladen wenn das Forum-Plugin ebenfalls aktiv ist. foreach ($core_files as $file) {
// Keine harte Abhängigkeit — Gallery funktioniert ohne Forum genauso wie vorher. if (!mc_gallery_pro_safe_require(MCGALLERY_PRO_DIR . 'includes/' . $file)) {
add_action('plugins_loaded', function() { return;
$bridge_file = MCGALLERY_PRO_DIR . 'includes/class-mc-gallery-forum-bridge.php'; }
if ( file_exists($bridge_file) && class_exists('WBF_Auth') ) { }
require_once $bridge_file;
MC_Gallery_Forum_Bridge::init(); // ── WP Business Forum — optionale Bridge ─────────────────────────────────
// Wird nur geladen wenn das Forum-Plugin ebenfalls aktiv ist.
// Shortcode für manuelles Einbetten des Verify-Panels auf beliebigen Seiten: // Keine harte Abhängigkeit — Gallery funktioniert ohne Forum genauso wie vorher.
// [mc_gallery_forum_login server_id="survival"] add_action('plugins_loaded', function() {
add_shortcode('mc_gallery_forum_login', ['MC_Gallery_Forum_Bridge', 'shortcode_verify_panel']); $bridge_file = MCGALLERY_PRO_DIR . 'includes/class-mc-gallery-forum-bridge.php';
} if ( file_exists($bridge_file) && class_exists('WBF_Auth') ) {
}, 20); // Prio 20 → nach Forum (Prio 1) und Gallery-Core (Prio 10) require_once $bridge_file;
} MC_Gallery_Forum_Bridge::init();
// ── Aktivierungs- / Deinstallations-Hooks ──────────────────────────────────── // Shortcode für manuelles Einbetten des Verify-Panels auf beliebigen Seiten:
// [mc_gallery_forum_login server_id="survival"]
function mc_gallery_pro_activate_callback() { add_shortcode('mc_gallery_forum_login', ['MC_Gallery_Forum_Bridge', 'shortcode_verify_panel']);
if (class_exists('MC_Gallery_Core')) { }
if (!get_option(MC_Gallery_Core::OPTION_THUMB_H)) { }, 20); // Prio 20 → nach Forum (Prio 1) und Gallery-Core (Prio 10)
update_option(MC_Gallery_Core::OPTION_THUMB_H, 200); }
}
} // ── Aktivierungs- / Deinstallations-Hooks ────────────────────────────────────
if (get_option(MCGALLERY_OPTION_KEY) === false) {
update_option(MCGALLERY_OPTION_KEY, []); function mc_gallery_pro_activate_callback() {
} if (class_exists('MC_Gallery_Core')) {
} if (!get_option(MC_Gallery_Core::OPTION_THUMB_H)) {
register_activation_hook(__FILE__, 'mc_gallery_pro_activate_callback'); update_option(MC_Gallery_Core::OPTION_THUMB_H, 200);
}
function mc_gallery_pro_uninstall_callback() { }
delete_option(MCGALLERY_OPTION_KEY); if (get_option(MCGALLERY_OPTION_KEY) === false) {
if (class_exists('MC_Gallery_Core')) { update_option(MCGALLERY_OPTION_KEY, []);
delete_option(MC_Gallery_Core::OPTION_THUMB_H); }
} }
} register_activation_hook(__FILE__, 'mc_gallery_pro_activate_callback');
register_uninstall_hook(__FILE__, 'mc_gallery_pro_uninstall_callback');
function mc_gallery_pro_uninstall_callback() {
// ── Core-Klassen initialisieren ─────────────────────────────────────────────── delete_option(MCGALLERY_OPTION_KEY);
if (class_exists('MC_Gallery_Core')) {
if (class_exists('MC_Gallery_Core')) { delete_option(MC_Gallery_Core::OPTION_THUMB_H);
add_action('plugins_loaded', ['MC_Gallery_Core', 'init']); }
} }
if (class_exists('MC_Gallery_Shortcodes')) { register_uninstall_hook(__FILE__, 'mc_gallery_pro_uninstall_callback');
add_action('plugins_loaded', ['MC_Gallery_Shortcodes', 'init']);
} // ── Core-Klassen initialisieren ───────────────────────────────────────────────
/* ================= SIDEBAR WIDGET: BILD DES TAGES ================= */ if (class_exists('MC_Gallery_Core')) {
class MC_Daily_Image_Widget extends WP_Widget { add_action('plugins_loaded', ['MC_Gallery_Core', 'init']);
}
public function __construct() { if (class_exists('MC_Gallery_Shortcodes')) {
parent::__construct( add_action('plugins_loaded', ['MC_Gallery_Shortcodes', 'init']);
'mc_daily_image_widget', }
'MC Bild des Tages',
array( 'description' => 'Zeigt jeden Tag ein anderes, zufälliges Bild aus allen MC Galerien an.' ) /* ================= SIDEBAR WIDGET: BILD DES TAGES ================= */
); class MC_Daily_Image_Widget extends WP_Widget {
}
public function __construct() {
// Frontend-Ausgabe parent::__construct(
public function widget( $args, $instance ) { 'mc_daily_image_widget',
$title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages'; 'MC Bild des Tages',
array( 'description' => 'Zeigt jeden Tag ein anderes, zufälliges Bild aus allen MC Galerien an.' )
echo $args['before_widget']; );
if ( ! empty( $title ) ) { }
echo $args['before_title'] . apply_filters( 'widget_title', $title ) . $args['after_title'];
} // Frontend-Ausgabe
public function widget( $args, $instance ) {
// 1. Eindeutiger Key für heute (z.B. mc_daily_image_2023-10-27) $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages';
$today_key = 'mc_daily_image_' . date('Y-m-d');
echo $args['before_widget'];
// 2. Prüfen, ob wir heute schon ein Bild ausgewählt haben if ( ! empty( $title ) ) {
$image_id = get_transient( $today_key ); echo $args['before_title'] . apply_filters( 'widget_title', $title ) . $args['after_title'];
}
// Falls kein Bild für heute im Cache ist:
if ( false === $image_id ) { // 1. Eindeutiger Key für heute (z.B. mc_daily_image_2023-10-27)
$today_key = 'mc_daily_image_' . date('Y-m-d');
// Alle MC Galerien finden
$galleries = get_posts([ // 2. Prüfen, ob wir heute schon ein Bild ausgewählt haben
'post_type' => 'mc_gallery', $image_id = get_transient( $today_key );
'numberposts' => -1,
'fields' => 'ids', // Falls kein Bild für heute im Cache ist:
'post_status' => 'publish', if ( false === $image_id ) {
]);
// Alle MC Galerien finden
if ( ! empty( $galleries ) ) { $galleries = get_posts([
// Ein zufälliges Bild aus diesen Galerien holen 'post_type' => 'mc_gallery',
$random_image = get_posts([ 'numberposts' => -1,
'post_type' => 'attachment', 'fields' => 'ids',
'post_mime_type' => 'image', 'post_status' => 'publish',
'post_parent__in' => $galleries, ]);
'numberposts' => 1,
'orderby' => 'rand', if ( ! empty( $galleries ) ) {
'suppress_filters' => false, // Ein zufälliges Bild aus diesen Galerien holen
]); $random_image = get_posts([
'post_type' => 'attachment',
if ( ! empty( $random_image ) ) { 'post_mime_type' => 'image',
$image_id = $random_image[0]->ID; 'post_parent__in' => $galleries,
// Das Bild für 24 Stunden (bis morgen) speichern 'numberposts' => 1,
set_transient( $today_key, $image_id, DAY_IN_SECONDS ); 'orderby' => 'rand',
} 'suppress_filters' => false,
} ]);
}
if ( ! empty( $random_image ) ) {
// 3. Bild anzeigen (wird aus Cache oder neu geladen) $image_id = $random_image[0]->ID;
if ( $image_id && wp_attachment_is_image( $image_id ) ) { // Das Bild für 24 Stunden (bis morgen) speichern
set_transient( $today_key, $image_id, DAY_IN_SECONDS );
$img_src = wp_get_attachment_image_src( $image_id, 'medium' ); }
$full_src = wp_get_attachment_image_src( $image_id, 'full' ); }
}
if ( $img_src ) {
?> // 3. Bild anzeigen (wird aus Cache oder neu geladen)
<div class="mc-daily-image-container" style="text-align: center;"> if ( $image_id && wp_attachment_is_image( $image_id ) ) {
<a href="<?php echo esc_url( $full_src[0] ); ?>" target="_blank" title="Vollbild anzeigen">
<img src="<?php echo esc_url( $img_src[0] ); ?>" alt="MC Bild des Tages" $img_src = wp_get_attachment_image_src( $image_id, 'medium' );
style="max-width: 100%; height: auto; border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);" /> $full_src = wp_get_attachment_image_src( $image_id, 'full' );
</a>
</div> if ( $img_src ) {
<?php ?>
} <div class="mc-daily-image-container" style="text-align: center;">
} else { <a href="<?php echo esc_url( $full_src[0] ); ?>" target="_blank" title="Vollbild anzeigen">
echo '<p style="text-align:center; color:#888;">Keine Bilder verfügbar.</p>'; <img src="<?php echo esc_url( $img_src[0] ); ?>" alt="MC Bild des Tages"
} style="max-width: 100%; height: auto; border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);" />
</a>
echo $args['after_widget']; </div>
} <?php
}
// Backend Formular } else {
public function form( $instance ) { echo '<p style="text-align:center; color:#888;">Keine Bilder verfügbar.</p>';
$title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages'; }
?>
<p> echo $args['after_widget'];
<label for="<?php echo $this->get_field_id( 'title' ); ?>">Titel:</label> }
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" // Backend Formular
value="<?php echo esc_attr( $title ); ?>"> public function form( $instance ) {
</p> $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages';
<p class="description" style="font-size: 0.9em; color: #666;"> ?>
Dieses Widget wählt einmal pro Tag (um 00:00 Uhr) ein zufälliges Bild aus allen Spieler-Galerien aus und zeigt es an. Der Bildtext ist ausgeblendet. <p>
</p> <label for="<?php echo $this->get_field_id( 'title' ); ?>">Titel:</label>
<?php <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
} name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
value="<?php echo esc_attr( $title ); ?>">
// Speichern der Einstellungen </p>
public function update( $new_instance, $old_instance ) { <p class="description" style="font-size: 0.9em; color: #666;">
$instance = array(); Dieses Widget wählt einmal pro Tag (um 00:00 Uhr) ein zufälliges Bild aus allen Spieler-Galerien aus und zeigt es an. Der Bildtext ist ausgeblendet.
$instance['title'] = ( ! empty( $new_instance['title'] ) ) </p>
? sanitize_text_field( $new_instance['title'] ) <?php
: 'Bild des Tages'; }
return $instance;
} // Speichern der Einstellungen
} public function update( $new_instance, $old_instance ) {
$instance = array();
// Widget registrieren $instance['title'] = ( ! empty( $new_instance['title'] ) )
function mc_register_daily_image_widget() { ? sanitize_text_field( $new_instance['title'] )
register_widget( 'MC_Daily_Image_Widget' ); : 'Bild des Tages';
} return $instance;
}
}
// Widget registrieren
function mc_register_daily_image_widget() {
register_widget( 'MC_Daily_Image_Widget' );
}
add_action( 'widgets_init', 'mc_register_daily_image_widget' ); add_action( 'widgets_init', 'mc_register_daily_image_widget' );