diff --git a/mc-multiserver-gallery-pro.php b/mc-multiserver-gallery-pro.php index 787c4b4..be60c54 100644 --- a/mc-multiserver-gallery-pro.php +++ b/mc-multiserver-gallery-pro.php @@ -1,199 +1,306 @@ -

MC Gallery PRO: Dieses Plugin benötigt PHP 7.0 oder höher.

'; - }); - } - return; -} - -if (defined('MCGALLERY_PRO_VERSION')) { return; } - -define('MCGALLERY_PRO_VERSION', '2.5.2'); -define('MCGALLERY_PRO_DIR', plugin_dir_path(__FILE__)); -define('MCGALLERY_PRO_URL', plugin_dir_url(__FILE__)); -define('MCGALLERY_TOKEN_TTL', 300); -define('MCGALLERY_OPTION_KEY', 'mc_gallery_tokens_store'); - -function mc_gallery_pro_safe_require($path) { - if (!file_exists($path)) { - if (is_admin()) { - add_action('admin_notices', function() use ($path) { - echo '

MC Gallery PRO Fehler: Datei nicht gefunden: ' . esc_html($path) . '.

'; - }); - } - return false; - } - require_once $path; - return true; -} - -function mc_gallery_pro_load_textdomain() { - load_plugin_textdomain('mc-multiserver-gallery-pro', false, basename(dirname(__FILE__)) . '/languages'); -} -add_action('plugins_loaded', 'mc_gallery_pro_load_textdomain'); - - $core_files = [ - 'class-mc-gallery-helpers.php', - 'class-mc-gallery-core.php', - 'class-mc-gallery-shortcodes.php' -]; - -if (!is_dir(MCGALLERY_PRO_DIR . 'includes')) { - add_action('admin_notices', function() { - echo '

MC Gallery PRO Fehler: Der Ordner includes/ fehlt.

'; - }); -} else { - foreach ($core_files as $file) { - if (!mc_gallery_pro_safe_require(MCGALLERY_PRO_DIR . 'includes/' . $file)) { - return; - } - } -} - -function mc_gallery_pro_activate_callback() { - if (class_exists('MC_Gallery_Core')) { - if (!get_option(MC_Gallery_Core::OPTION_THUMB_H)) { - update_option(MC_Gallery_Core::OPTION_THUMB_H, 200); - } - } - if (get_option(MCGALLERY_OPTION_KEY) === false) { - update_option(MCGALLERY_OPTION_KEY, []); - } -} -register_activation_hook(__FILE__, 'mc_gallery_pro_activate_callback'); - -function mc_gallery_pro_uninstall_callback() { - delete_option(MCGALLERY_OPTION_KEY); - if (class_exists('MC_Gallery_Core')) { - delete_option(MC_Gallery_Core::OPTION_THUMB_H); - } -} -register_uninstall_hook(__FILE__, 'mc_gallery_pro_uninstall_callback'); - -if (class_exists('MC_Gallery_Core')) { - add_action('plugins_loaded', ['MC_Gallery_Core', 'init']); -} -if (class_exists('MC_Gallery_Shortcodes')) { - 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 ) { - ?> -
- - MC Bild des Tages - -
- Keine Bilder verfügbar.

'; - } - - echo $args['after_widget']; - } - - // Backend Formular - public function form( $instance ) { - $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages'; - ?> -

- - -

-

- 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. -

- 10] + ); + + if ( ! is_wp_error($response) && 200 === wp_remote_retrieve_response_code($response) ) { + $body = wp_remote_retrieve_body($response); + $data = json_decode($body, true); + + if ( $data && isset($data['tag_name']) ) { + $tag = ltrim( $data['tag_name'], 'vV' ); + + $release_info = [ + 'version' => $tag, + 'download_url' => $data['zipball_url'] ?? '', + 'notes' => $data['body'] ?? '', + 'published_at' => $data['published_at'] ?? '', + ]; + + set_transient( $transient_key, $release_info, 6 * HOUR_IN_SECONDS ); + } else { + set_transient( $transient_key, [], HOUR_IN_SECONDS ); + } + } else { + set_transient( $transient_key, [], HOUR_IN_SECONDS ); + } + } + + return $release_info; +} + +// Admin-Update-Hinweis anzeigen +function mc_gallery_show_update_notice() { + if ( ! current_user_can('manage_options') ) { + return; + } + + $current_version = mc_gallery_get_plugin_version(); + $latest_release = mc_gallery_get_latest_release_info(); + + if ( ! empty($latest_release['version']) && version_compare($current_version, $latest_release['version'], '<') ) { + + $refresh_url = wp_nonce_url( + admin_url('plugins.php?mc_gallery_clear_cache=1'), + 'mc_gallery_clear_cache_action' + ); + ?> +
+

MC MultiServer Gallery PRO – Update verfügbar

+

+ Installiert:
+ Neueste Version: +

+

+ + Update herunterladen + + + Release Notes + + + Jetzt neu prüfen + +

+
+

MC Gallery PRO: Dieses Plugin benötigt PHP 7.0 oder höher.

'; + }); + } + return; +} + +if (defined('MCGALLERY_PRO_VERSION')) { return; } + +define('MCGALLERY_PRO_VERSION', '2.5.2'); +define('MCGALLERY_PRO_DIR', plugin_dir_path(__FILE__)); +define('MCGALLERY_PRO_URL', plugin_dir_url(__FILE__)); +define('MCGALLERY_TOKEN_TTL', 300); +define('MCGALLERY_OPTION_KEY', 'mc_gallery_tokens_store'); + +function mc_gallery_pro_safe_require($path) { + if (!file_exists($path)) { + if (is_admin()) { + add_action('admin_notices', function() use ($path) { + echo '

MC Gallery PRO Fehler: Datei nicht gefunden: ' . esc_html($path) . '.

'; + }); + } + return false; + } + require_once $path; + return true; +} + +function mc_gallery_pro_load_textdomain() { + load_plugin_textdomain('mc-multiserver-gallery-pro', false, basename(dirname(__FILE__)) . '/languages'); +} +add_action('plugins_loaded', 'mc_gallery_pro_load_textdomain'); + + $core_files = [ + 'class-mc-gallery-helpers.php', + 'class-mc-gallery-core.php', + 'class-mc-gallery-shortcodes.php' +]; + +if (!is_dir(MCGALLERY_PRO_DIR . 'includes')) { + add_action('admin_notices', function() { + echo '

MC Gallery PRO Fehler: Der Ordner includes/ fehlt.

'; + }); +} else { + foreach ($core_files as $file) { + if (!mc_gallery_pro_safe_require(MCGALLERY_PRO_DIR . 'includes/' . $file)) { + return; + } + } +} + +function mc_gallery_pro_activate_callback() { + if (class_exists('MC_Gallery_Core')) { + if (!get_option(MC_Gallery_Core::OPTION_THUMB_H)) { + update_option(MC_Gallery_Core::OPTION_THUMB_H, 200); + } + } + if (get_option(MCGALLERY_OPTION_KEY) === false) { + update_option(MCGALLERY_OPTION_KEY, []); + } +} +register_activation_hook(__FILE__, 'mc_gallery_pro_activate_callback'); + +function mc_gallery_pro_uninstall_callback() { + delete_option(MCGALLERY_OPTION_KEY); + if (class_exists('MC_Gallery_Core')) { + delete_option(MC_Gallery_Core::OPTION_THUMB_H); + } +} +register_uninstall_hook(__FILE__, 'mc_gallery_pro_uninstall_callback'); + +if (class_exists('MC_Gallery_Core')) { + add_action('plugins_loaded', ['MC_Gallery_Core', 'init']); +} +if (class_exists('MC_Gallery_Shortcodes')) { + 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 ) { + ?> +
+ + MC Bild des Tages + +
+ Keine Bilder verfügbar.

'; + } + + echo $args['after_widget']; + } + + // Backend Formular + public function form( $instance ) { + $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Bild des Tages'; + ?> +

+ + +

+

+ 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. +

+