Minecraft-BungeeCord-Status/minecraft-bungeecord-status.php aktualisiert
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: Minecraft BungeeCord Status – Network Edition
|
||||
* Description: Der ultimative Live-Status für dein BungeeCord Netzwerk (Border None Fix).
|
||||
* Tags: minecraft, bungeecord, server status, player list
|
||||
* Version: 3.6.4
|
||||
* Version: 3.6.5
|
||||
* Author: M_Viper
|
||||
* Requires at least: 6.0
|
||||
* Requires PHP: 7.4
|
||||
@@ -76,143 +76,115 @@ function mcss_get_3d_avatar($name, $uuid = null) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------- AUTO UPDATE (MCSS) ---------------- */
|
||||
if ( ! class_exists( 'MCSS_Auto_Update' ) ) {
|
||||
class MCSS_Auto_Update {
|
||||
|
||||
private $plugin_file;
|
||||
private $repo_owner = 'M_Viper';
|
||||
private $repo_name = 'Minecraft-BungeeCord-Status';
|
||||
private $api_url;
|
||||
private $transient_key;
|
||||
// ===============================
|
||||
// MCSS - UPDATE NOTICE SYSTEM
|
||||
// ===============================
|
||||
|
||||
public function __construct( $plugin_file ) {
|
||||
$this->plugin_file = $plugin_file;
|
||||
$this->api_url = 'https://git.viper.ipv64.net/api/v1/repos/' . rawurlencode( $this->repo_owner ) . '/' . rawurlencode( $this->repo_name ) . '/releases';
|
||||
$this->transient_key = 'mcss_update_check_' . md5( $this->repo_owner . '/' . $this->repo_name );
|
||||
|
||||
if ( is_admin() ) {
|
||||
add_action( 'admin_init', array( $this, 'check_for_update' ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function check_for_update() {
|
||||
if ( ! function_exists( 'get_file_data' ) ) {
|
||||
// Plugin-Version aus Header lesen
|
||||
function mcss_get_plugin_version() {
|
||||
if ( ! function_exists( 'get_plugin_data' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
$current = get_file_data( $this->plugin_file, array( 'Version' => 'Version' ), 'plugin' );
|
||||
$current_version = isset( $current['Version'] ) ? $current['Version'] : '0.0.0';
|
||||
$plugin_data = get_plugin_data( __FILE__ );
|
||||
return $plugin_data['Version'] ?? '0.0.0';
|
||||
}
|
||||
|
||||
$latest = $this->get_latest_release_info();
|
||||
// Cache manuell leeren
|
||||
function mcss_clear_update_cache() {
|
||||
if ( isset($_GET['mcss_clear_cache']) && current_user_can('manage_options') ) {
|
||||
check_admin_referer('mcss_clear_cache_action');
|
||||
delete_transient('mcss_latest_release');
|
||||
wp_redirect( admin_url('plugins.php') );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
add_action('admin_init', 'mcss_clear_update_cache');
|
||||
|
||||
if ( $latest && ! empty( $latest['version'] ) && ! empty( $latest['url'] ) ) {
|
||||
if ( version_compare( $latest['version'], $current_version, '>' ) ) {
|
||||
add_action( 'admin_notices', function() use ( $latest, $current_version ) {
|
||||
// Neueste Release-Infos von Gitea holen
|
||||
function mcss_get_latest_release_info( $force_refresh = false ) {
|
||||
$transient_key = 'mcss_latest_release';
|
||||
|
||||
if ( $force_refresh ) {
|
||||
delete_transient( $transient_key );
|
||||
}
|
||||
|
||||
$release_info = get_transient( $transient_key );
|
||||
|
||||
if ( false === $release_info ) {
|
||||
$response = wp_remote_get(
|
||||
'https://git.viper.ipv64.net/api/v1/repos/M_Viper/Minecraft-BungeeCord-Status/releases/latest',
|
||||
['timeout' => 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 mcss_show_update_notice() {
|
||||
if ( ! current_user_can('manage_options') ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current_version = mcss_get_plugin_version();
|
||||
$latest_release = mcss_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?mcss_clear_cache=1'),
|
||||
'mcss_clear_cache_action'
|
||||
);
|
||||
?>
|
||||
<div class="notice notice-warning is-dismissible">
|
||||
<h3>Minecraft BungeeCord Status – Update verfügbar</h3>
|
||||
<p>
|
||||
<strong>Minecraft BungeeCord Status – Update verfügbar</strong><br>
|
||||
Neue Version: <strong><?php echo esc_html( $latest['version'] ); ?></strong><br>
|
||||
Installiert: <strong><?php echo esc_html( $current_version ); ?></strong><br>
|
||||
<a href="<?php echo esc_url( $latest['url'] ); ?>" class="button button-primary" target="_blank" rel="noreferrer noopener">Direkter Download (ZIP)</a>
|
||||
<a href="<?php echo esc_url( 'https://git.viper.ipv64.net/' . rawurlencode( $this->repo_owner ) . '/' . rawurlencode( $this->repo_name ) . '/releases' ); ?>" class="button" target="_blank" style="margin-left:8px;" rel="noreferrer noopener">Releases ansehen</a>
|
||||
Installiert: <strong><?php echo esc_html($current_version); ?></strong><br>
|
||||
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">
|
||||
Update herunterladen
|
||||
</a>
|
||||
<a href="https://git.viper.ipv64.net/M_Viper/Minecraft-BungeeCord-Status/releases" class="button" target="_blank">
|
||||
Release Notes
|
||||
</a>
|
||||
<a href="<?php echo esc_url($refresh_url); ?>" class="button">
|
||||
Jetzt neu prüfen
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function get_latest_release_info() {
|
||||
$cached = get_transient( $this->transient_key );
|
||||
if ( false !== $cached && is_array( $cached ) && ! empty( $cached['version'] ) ) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$result = false;
|
||||
|
||||
$response = wp_remote_get( $this->api_url, array(
|
||||
'timeout' => 8,
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'User-Agent' => 'MCSS-Update-Checker/1.0',
|
||||
),
|
||||
) );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
set_transient( $this->transient_key, array( 'version' => '', 'url' => '' ), HOUR_IN_SECONDS );
|
||||
return false;
|
||||
}
|
||||
|
||||
$code = wp_remote_retrieve_response_code( $response );
|
||||
if ( 200 !== (int) $code ) {
|
||||
set_transient( $this->transient_key, array( 'version' => '', 'url' => '' ), HOUR_IN_SECONDS );
|
||||
return false;
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
$json = json_decode( $body, true );
|
||||
|
||||
if ( ! is_array( $json ) || empty( $json ) ) {
|
||||
set_transient( $this->transient_key, array( 'version' => '', 'url' => '' ), HOUR_IN_SECONDS );
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $json as $release ) {
|
||||
$tag = '';
|
||||
if ( ! empty( $release['tag_name'] ) ) {
|
||||
$tag = ltrim( (string) $release['tag_name'], 'vV' );
|
||||
} elseif ( ! empty( $release['name'] ) ) {
|
||||
$tag = ltrim( (string) $release['name'], 'vV' );
|
||||
}
|
||||
|
||||
if ( ! empty( $release['assets'] ) && is_array( $release['assets'] ) ) {
|
||||
foreach ( $release['assets'] as $asset ) {
|
||||
if ( empty( $asset['name'] ) || empty( $asset['browser_download_url'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( strtolower( $asset['name'] ) === 'minecraft-bungeecord-status.zip' ) {
|
||||
$version = $tag ?: $this->extract_version_from_string( $asset['name'] . ' ' . ( $release['name'] ?? '' ) );
|
||||
if ( $version ) {
|
||||
$result = array(
|
||||
'version' => $version,
|
||||
'url' => $asset['browser_download_url'],
|
||||
);
|
||||
break 2;
|
||||
} else {
|
||||
$result = array(
|
||||
'version' => ( $tag ?: (string) ( $release['name'] ?? '' ) ),
|
||||
'url' => $asset['browser_download_url'],
|
||||
);
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $result ) {
|
||||
set_transient( $this->transient_key, $result, 12 * HOUR_IN_SECONDS );
|
||||
return $result;
|
||||
}
|
||||
|
||||
set_transient( $this->transient_key, array( 'version' => '', 'url' => '' ), 6 * HOUR_IN_SECONDS );
|
||||
return false;
|
||||
}
|
||||
|
||||
private function extract_version_from_string( $str ) {
|
||||
if ( preg_match( '/([0-9]+\.[0-9]+(?:\.[0-9]+)?)/', $str, $m ) ) {
|
||||
return $m[1];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
new MCSS_Auto_Update( __FILE__ );
|
||||
}
|
||||
add_action('admin_notices', 'mcss_show_update_notice');
|
||||
|
||||
|
||||
|
||||
|
||||
/* ---------------- Assets ---------------- */
|
||||
add_action('admin_enqueue_scripts', function($hook){
|
||||
|
||||
Reference in New Issue
Block a user