mc-multiserver-gallery-pro.php aktualisiert

This commit is contained in:
2026-02-11 19:22:57 +00:00
parent d6c23c086e
commit 92ecb0e719

View File

@@ -1,199 +1,306 @@
<?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). Description: Professionelle Minecraft-Galerie mit Ingame-Verification, modernem UI, Lightbox und AJAX-Upload (multi-server fähig).
Version: 2.5.3 Version: 2.5.4
Author: M_Viper Author: M_Viper
Text Domain: mc-multiserver-gallery-pro Text Domain: mc-multiserver-gallery-pro
Domain Path: /languages Domain Path: /languages
*/ */
if (!defined('ABSPATH')) exit; if (!defined('ABSPATH')) exit;
if (version_compare(PHP_VERSION, '7.0', '<')) { // ===========================================
if (is_admin()) { // MC GALLERY PRO - UPDATE NOTICE SYSTEM
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>';
}); // Plugin-Version aus Header lesen (NICHT aus Konstante)
} function mc_gallery_get_plugin_version() {
return; if ( ! function_exists( 'get_plugin_data' ) ) {
} require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if (defined('MCGALLERY_PRO_VERSION')) { return; }
$plugin_data = get_plugin_data( __FILE__ );
define('MCGALLERY_PRO_VERSION', '2.5.2'); return $plugin_data['Version'] ?? '0.0.0';
define('MCGALLERY_PRO_DIR', plugin_dir_path(__FILE__)); }
define('MCGALLERY_PRO_URL', plugin_dir_url(__FILE__));
define('MCGALLERY_TOKEN_TTL', 300); // Cache manuell leeren
define('MCGALLERY_OPTION_KEY', 'mc_gallery_tokens_store'); function mc_gallery_clear_update_cache() {
if ( isset($_GET['mc_gallery_clear_cache']) && current_user_can('manage_options') ) {
function mc_gallery_pro_safe_require($path) { check_admin_referer('mc_gallery_clear_cache_action');
if (!file_exists($path)) { delete_transient('mc_gallery_latest_release');
if (is_admin()) { wp_redirect( admin_url('plugins.php') );
add_action('admin_notices', function() use ($path) { exit;
echo '<div class="error"><p><strong>MC Gallery PRO Fehler:</strong> Datei nicht gefunden: <code>' . esc_html($path) . '</code>.</p></div>'; }
}); }
} add_action('admin_init', 'mc_gallery_clear_update_cache');
return false;
} // Neueste Release-Infos von Gitea holen
require_once $path; function mc_gallery_get_latest_release_info( $force_refresh = false ) {
return true; $transient_key = 'mc_gallery_latest_release';
}
if ( $force_refresh ) {
function mc_gallery_pro_load_textdomain() { delete_transient( $transient_key );
load_plugin_textdomain('mc-multiserver-gallery-pro', false, basename(dirname(__FILE__)) . '/languages'); }
}
add_action('plugins_loaded', 'mc_gallery_pro_load_textdomain'); $release_info = get_transient( $transient_key );
$core_files = [ if ( false === $release_info ) {
'class-mc-gallery-helpers.php', $response = wp_remote_get(
'class-mc-gallery-core.php', 'https://git.viper.ipv64.net/api/v1/repos/M_Viper/Wordpress-MC-Gallery/releases/latest',
'class-mc-gallery-shortcodes.php' ['timeout' => 10]
]; );
if (!is_dir(MCGALLERY_PRO_DIR . 'includes')) { if ( ! is_wp_error($response) && 200 === wp_remote_retrieve_response_code($response) ) {
add_action('admin_notices', function() { $body = wp_remote_retrieve_body($response);
echo '<div class="error"><p><strong>MC Gallery PRO Fehler:</strong> Der Ordner <code>includes/</code> fehlt.</p></div>'; $data = json_decode($body, true);
});
} else { if ( $data && isset($data['tag_name']) ) {
foreach ($core_files as $file) { $tag = ltrim( $data['tag_name'], 'vV' );
if (!mc_gallery_pro_safe_require(MCGALLERY_PRO_DIR . 'includes/' . $file)) {
return; $release_info = [
} 'version' => $tag,
} 'download_url' => $data['zipball_url'] ?? '',
} 'notes' => $data['body'] ?? '',
'published_at' => $data['published_at'] ?? '',
function mc_gallery_pro_activate_callback() { ];
if (class_exists('MC_Gallery_Core')) {
if (!get_option(MC_Gallery_Core::OPTION_THUMB_H)) { set_transient( $transient_key, $release_info, 6 * HOUR_IN_SECONDS );
update_option(MC_Gallery_Core::OPTION_THUMB_H, 200); } else {
} set_transient( $transient_key, [], HOUR_IN_SECONDS );
} }
if (get_option(MCGALLERY_OPTION_KEY) === false) { } else {
update_option(MCGALLERY_OPTION_KEY, []); set_transient( $transient_key, [], HOUR_IN_SECONDS );
} }
} }
register_activation_hook(__FILE__, 'mc_gallery_pro_activate_callback');
return $release_info;
function mc_gallery_pro_uninstall_callback() { }
delete_option(MCGALLERY_OPTION_KEY);
if (class_exists('MC_Gallery_Core')) { // Admin-Update-Hinweis anzeigen
delete_option(MC_Gallery_Core::OPTION_THUMB_H); function mc_gallery_show_update_notice() {
} if ( ! current_user_can('manage_options') ) {
} return;
register_uninstall_hook(__FILE__, 'mc_gallery_pro_uninstall_callback'); }
if (class_exists('MC_Gallery_Core')) { $current_version = mc_gallery_get_plugin_version();
add_action('plugins_loaded', ['MC_Gallery_Core', 'init']); $latest_release = mc_gallery_get_latest_release_info();
}
if (class_exists('MC_Gallery_Shortcodes')) { if ( ! empty($latest_release['version']) && version_compare($current_version, $latest_release['version'], '<') ) {
add_action('plugins_loaded', ['MC_Gallery_Shortcodes', 'init']);
} $refresh_url = wp_nonce_url(
admin_url('plugins.php?mc_gallery_clear_cache=1'),
/* ================= SIDEBAR WIDGET: BILD DES TAGES ================= */ 'mc_gallery_clear_cache_action'
class MC_Daily_Image_Widget extends WP_Widget { );
?>
public function __construct() { <div class="notice notice-warning is-dismissible">
parent::__construct( <h3>MC MultiServer Gallery PRO Update verfügbar</h3>
'mc_daily_image_widget', <p>
'MC Bild des Tages', Installiert: <strong><?php echo esc_html($current_version); ?></strong><br>
array( 'description' => 'Zeigt jeden Tag ein anderes, zufälliges Bild aus allen MC Galerien an.' ) Neueste Version: <strong><?php echo esc_html($latest_release['version']); ?></strong>
); </p>
} <p>
<a href="<?php echo esc_url($latest_release['download_url']); ?>" class="button button-primary" target="_blank">
// Frontend-Ausgabe Update herunterladen
public function widget( $args, $instance ) { </a>
$title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages'; <a href="https://git.viper.ipv64.net/M_Viper/Wordpress-MC-Gallery/releases" class="button" target="_blank">
Release Notes
echo $args['before_widget']; </a>
if ( ! empty( $title ) ) { <a href="<?php echo esc_url($refresh_url); ?>" class="button">
echo $args['before_title'] . apply_filters( 'widget_title', $title ) . $args['after_title']; Jetzt neu prüfen
} </a>
</p>
// 1. Eindeutiger Key für heute (z.B. mc_daily_image_2023-10-27) </div>
$today_key = 'mc_daily_image_' . date('Y-m-d'); <?php
}
// 2. Prüfen, ob wir heute schon ein Bild ausgewählt haben }
$image_id = get_transient( $today_key ); add_action('admin_notices', 'mc_gallery_show_update_notice');
// Falls kein Bild für heute im Cache ist:
if ( false === $image_id ) { if (version_compare(PHP_VERSION, '7.0', '<')) {
if (is_admin()) {
// Alle MC Galerien finden add_action('admin_notices', function() {
$galleries = get_posts([ echo '<div class="error"><p><strong>MC Gallery PRO:</strong> Dieses Plugin benötigt PHP 7.0 oder höher.</p></div>';
'post_type' => 'mc_gallery', });
'numberposts' => -1, }
'fields' => 'ids', return;
'post_status' => 'publish' }
]);
if (defined('MCGALLERY_PRO_VERSION')) { return; }
if ( ! empty( $galleries ) ) {
// Ein zufälliges Bild aus diesen Galerien holen define('MCGALLERY_PRO_VERSION', '2.5.2');
$random_image = get_posts([ define('MCGALLERY_PRO_DIR', plugin_dir_path(__FILE__));
'post_type' => 'attachment', define('MCGALLERY_PRO_URL', plugin_dir_url(__FILE__));
'post_mime_type' => 'image', define('MCGALLERY_TOKEN_TTL', 300);
'post_parent__in'=> $galleries, define('MCGALLERY_OPTION_KEY', 'mc_gallery_tokens_store');
'numberposts' => 1,
'orderby' => 'rand', // Zufällig wählen function mc_gallery_pro_safe_require($path) {
'suppress_filters' => false if (!file_exists($path)) {
]); if (is_admin()) {
add_action('admin_notices', function() use ($path) {
if ( ! empty( $random_image ) ) { echo '<div class="error"><p><strong>MC Gallery PRO Fehler:</strong> Datei nicht gefunden: <code>' . esc_html($path) . '</code>.</p></div>';
$image_id = $random_image[0]->ID; });
// Das Bild für 24 Stunden (bis morgen) speichern }
set_transient( $today_key, $image_id, DAY_IN_SECONDS ); return false;
} }
} require_once $path;
} return true;
}
// 3. Bild anzeigen (wird aus Cache oder neu geladen)
if ( $image_id && wp_attachment_is_image( $image_id ) ) { function mc_gallery_pro_load_textdomain() {
load_plugin_textdomain('mc-multiserver-gallery-pro', false, basename(dirname(__FILE__)) . '/languages');
$img_src = wp_get_attachment_image_src( $image_id, 'medium' ); }
$full_src = wp_get_attachment_image_src( $image_id, 'full' ); add_action('plugins_loaded', 'mc_gallery_pro_load_textdomain');
if ( $img_src ) { $core_files = [
?> 'class-mc-gallery-helpers.php',
<div class="mc-daily-image-container" style="text-align: center;"> 'class-mc-gallery-core.php',
<a href="<?php echo esc_url( $full_src[0] ); ?>" target="_blank" title="Vollbild anzeigen"> 'class-mc-gallery-shortcodes.php'
<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>
</div> if (!is_dir(MCGALLERY_PRO_DIR . 'includes')) {
<?php add_action('admin_notices', function() {
} echo '<div class="error"><p><strong>MC Gallery PRO Fehler:</strong> Der Ordner <code>includes/</code> fehlt.</p></div>';
} else { });
echo '<p style="text-align:center; color:#888;">Keine Bilder verfügbar.</p>'; } else {
} foreach ($core_files as $file) {
if (!mc_gallery_pro_safe_require(MCGALLERY_PRO_DIR . 'includes/' . $file)) {
echo $args['after_widget']; return;
} }
}
// Backend Formular }
public function form( $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages'; function mc_gallery_pro_activate_callback() {
?> if (class_exists('MC_Gallery_Core')) {
<p> if (!get_option(MC_Gallery_Core::OPTION_THUMB_H)) {
<label for="<?php echo $this->get_field_id( 'title' ); ?>">Titel:</label> update_option(MC_Gallery_Core::OPTION_THUMB_H, 200);
<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 ); ?>"> if (get_option(MCGALLERY_OPTION_KEY) === false) {
</p> update_option(MCGALLERY_OPTION_KEY, []);
<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> register_activation_hook(__FILE__, 'mc_gallery_pro_activate_callback');
<?php
} function mc_gallery_pro_uninstall_callback() {
delete_option(MCGALLERY_OPTION_KEY);
// Speichern der Einstellungen if (class_exists('MC_Gallery_Core')) {
public function update( $new_instance, $old_instance ) { delete_option(MC_Gallery_Core::OPTION_THUMB_H);
$instance = array(); }
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : 'Bild des Tages'; }
return $instance; register_uninstall_hook(__FILE__, 'mc_gallery_pro_uninstall_callback');
}
} if (class_exists('MC_Gallery_Core')) {
add_action('plugins_loaded', ['MC_Gallery_Core', 'init']);
// Widget registrieren }
function mc_register_daily_image_widget() { if (class_exists('MC_Gallery_Shortcodes')) {
register_widget( 'MC_Daily_Image_Widget' ); add_action('plugins_loaded', ['MC_Gallery_Shortcodes', 'init']);
} }
/* ================= SIDEBAR WIDGET: BILD DES TAGES ================= */
class MC_Daily_Image_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'mc_daily_image_widget',
'MC Bild des Tages',
array( 'description' => 'Zeigt jeden Tag ein anderes, zufälliges Bild aus allen MC Galerien an.' )
);
}
// Frontend-Ausgabe
public function widget( $args, $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages';
echo $args['before_widget'];
if ( ! empty( $title ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $title ) . $args['after_title'];
}
// 1. Eindeutiger Key für heute (z.B. mc_daily_image_2023-10-27)
$today_key = 'mc_daily_image_' . date('Y-m-d');
// 2. Prüfen, ob wir heute schon ein Bild ausgewählt haben
$image_id = get_transient( $today_key );
// Falls kein Bild für heute im Cache ist:
if ( false === $image_id ) {
// Alle MC Galerien finden
$galleries = get_posts([
'post_type' => 'mc_gallery',
'numberposts' => -1,
'fields' => 'ids',
'post_status' => 'publish'
]);
if ( ! empty( $galleries ) ) {
// Ein zufälliges Bild aus diesen Galerien holen
$random_image = get_posts([
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_parent__in'=> $galleries,
'numberposts' => 1,
'orderby' => 'rand', // Zufällig wählen
'suppress_filters' => false
]);
if ( ! empty( $random_image ) ) {
$image_id = $random_image[0]->ID;
// Das Bild für 24 Stunden (bis morgen) speichern
set_transient( $today_key, $image_id, DAY_IN_SECONDS );
}
}
}
// 3. Bild anzeigen (wird aus Cache oder neu geladen)
if ( $image_id && wp_attachment_is_image( $image_id ) ) {
$img_src = wp_get_attachment_image_src( $image_id, 'medium' );
$full_src = wp_get_attachment_image_src( $image_id, 'full' );
if ( $img_src ) {
?>
<div class="mc-daily-image-container" style="text-align: center;">
<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" style="max-width: 100%; height: auto; border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);" />
</a>
</div>
<?php
}
} else {
echo '<p style="text-align:center; color:#888;">Keine Bilder verfügbar.</p>';
}
echo $args['after_widget'];
}
// Backend Formular
public function form( $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages';
?>
<p>
<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"
value="<?php echo esc_attr( $title ); ?>">
</p>
<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>
<?php
}
// Speichern der Einstellungen
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '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' );