diff --git a/wp-business-forum.php b/wp-business-forum.php index b5c0cb4..73d86a7 100644 --- a/wp-business-forum.php +++ b/wp-business-forum.php @@ -3,7 +3,7 @@ * Plugin Name: WP Business Forum * Plugin URI: https://git.viper.ipv64.net/M_Viper/WP-Business-Forum * Description: Professionelles Forum mit eigenem Login, Rollen, Signaturen, Hierarchie und Moderations-Tools. - * Version: 1.0.1 + * Version: 1.0.2 * Author: M_Viper * Author URI: https://m-viper.de * Text Domain: wp-business-forum @@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; define( 'WBF_PATH', plugin_dir_path( __FILE__ ) ); define( 'WBF_URL', plugin_dir_url( __FILE__ ) ); -define( 'WBF_VERSION', '1.0.1' ); +define( 'WBF_VERSION', '1.0.2' ); require_once WBF_PATH . 'includes/class-forum-db.php'; require_once WBF_PATH . 'includes/class-forum-roles.php'; @@ -22,6 +22,7 @@ require_once WBF_PATH . 'includes/class-forum-bbcode.php'; require_once WBF_PATH . 'includes/class-forum-auth.php'; require_once WBF_PATH . 'includes/class-forum-shortcodes.php'; require_once WBF_PATH . 'includes/class-forum-ajax.php'; +require_once WBF_PATH . 'includes/class-forum-export.php'; require_once WBF_PATH . 'admin/forum-admin.php'; require_once WBF_PATH . 'admin/forum-settings.php'; require_once WBF_PATH . 'admin/forum-setup.php'; @@ -33,6 +34,11 @@ register_activation_hook( __FILE__, function() { set_transient( 'wbf_activation_redirect', true, 30 ); }); +// ── Export / Import Hooks ───────────────────────────────────────────────────── +add_action( 'plugins_loaded', function() { + WBF_Export::hooks(); +}, 5 ); + // ── Superadmin-Sync ─────────────────────────────────────────────────────────── add_action( 'wp_login', function() { WBF_Roles::sync_superadmin(); } ); add_action( 'init', function() { WBF_Roles::sync_superadmin(); } ); @@ -57,6 +63,7 @@ if ( ! wp_next_scheduled( 'wbf_check_expired_bans' ) ) { register_deactivation_hook( __FILE__, function() { wp_clear_scheduled_hook( 'wbf_check_expired_bans' ); + wp_clear_scheduled_hook( 'wbf_check_for_updates' ); } ); @@ -98,4 +105,156 @@ add_action( 'wp_enqueue_scripts', function() { 'forum_url' => wbf_get_forum_url(), 'reactions' => WBF_DB::get_allowed_reactions(), ]); -}); \ No newline at end of file +}); + + +// ══════════════════════════════════════════════════════════════════════════════ +// ── Update-Checker ──────────────────────────────────────────────────────────── +// Prüft täglich gegen die Gitea-Releases-API ob eine neue Version verfügbar ist. +// Releases-URL: https://git.viper.ipv64.net/M_Viper/WP-Business-Forum/releases +// ══════════════════════════════════════════════════════════════════════════════ + +define( 'WBF_UPDATE_API', 'https://git.viper.ipv64.net/api/v1/repos/M_Viper/WP-Business-Forum/releases?limit=1&page=1' ); +define( 'WBF_RELEASES_PAGE', 'https://git.viper.ipv64.net/M_Viper/WP-Business-Forum/releases' ); +define( 'WBF_UPDATE_TRANSIENT','wbf_update_check' ); + +/** + * Holt die neueste Release-Info von Gitea (gecacht per Transient, 12h). + * Gibt null zurück wenn kein Update verfügbar oder API nicht erreichbar. + * + * @return array|null ['version'=>string, 'url'=>string, 'name'=>string, 'published'=>string, 'body'=>string] + */ +function wbf_get_latest_release() { + $cached = get_transient( WBF_UPDATE_TRANSIENT ); + if ( $cached !== false ) { + return $cached ?: null; // false = noch nie gecacht, '' = kein Update + } + + $response = wp_remote_get( WBF_UPDATE_API, [ + 'timeout' => 8, + 'user-agent' => 'WP-Business-Forum/' . WBF_VERSION . '; ' . get_bloginfo('url'), + 'sslverify' => true, + ] ); + + if ( is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200 ) { + // Bei Fehler 1h warten bevor erneut versucht + set_transient( WBF_UPDATE_TRANSIENT, '', HOUR_IN_SECONDS ); + return null; + } + + $body = wp_remote_retrieve_body( $response ); + $releases = json_decode( $body, true ); + + if ( empty($releases) || ! is_array($releases) || empty($releases[0]) ) { + set_transient( WBF_UPDATE_TRANSIENT, '', 12 * HOUR_IN_SECONDS ); + return null; + } + + $latest = $releases[0]; + $version = ltrim( $latest['tag_name'] ?? '', 'v' ); // "v1.2.0" → "1.2.0" + + $info = [ + 'version' => $version, + 'url' => $latest['html_url'] ?? WBF_RELEASES_PAGE, + 'name' => $latest['name'] ?? $latest['tag_name'] ?? $version, + 'published' => $latest['published_at'] ?? '', + 'body' => wp_strip_all_tags( $latest['body'] ?? '' ), + ]; + + // 12 Stunden cachen + set_transient( WBF_UPDATE_TRANSIENT, $info, 12 * HOUR_IN_SECONDS ); + return $info; +} + +/** + * Prüft ob ein Update verfügbar ist. + * Gibt die Release-Info zurück wenn Gitea-Version > installierte Version. + */ +function wbf_update_available() { + $latest = wbf_get_latest_release(); + if ( ! $latest || empty($latest['version']) ) return null; + if ( version_compare( $latest['version'], WBF_VERSION, '>' ) ) { + return $latest; + } + return null; +} + +// ── Cron: täglich Update prüfen (Cache warm halten) ────────────────────────── +add_action( 'wbf_check_for_updates', function() { + delete_transient( WBF_UPDATE_TRANSIENT ); + wbf_get_latest_release(); +} ); + +if ( ! wp_next_scheduled( 'wbf_check_for_updates' ) ) { + wp_schedule_event( time(), 'twicedaily', 'wbf_check_for_updates' ); +} + +// ── Admin-Notice wenn Update verfügbar ─────────────────────────────────────── +add_action( 'admin_notices', function() { + if ( ! current_user_can('manage_options') ) return; + + $update = wbf_update_available(); + if ( ! $update ) return; + + // Notice ausblenden wenn der User sie weggeklickt hat (per GET-Parameter) + if ( isset($_GET['wbf_dismiss_update']) && check_admin_referer('wbf_dismiss_update') ) { + set_transient( 'wbf_update_dismissed_' . WBF_VERSION, $update['version'], 7 * DAY_IN_SECONDS ); + wp_safe_redirect( remove_query_arg(['wbf_dismiss_update','_wpnonce']) ); + exit; + } + + $dismissed = get_transient( 'wbf_update_dismissed_' . WBF_VERSION ); + if ( $dismissed === $update['version'] ) return; + + $dismiss_url = wp_nonce_url( + add_query_arg('wbf_dismiss_update', '1'), + 'wbf_dismiss_update' + ); + $changelog_url = esc_url( $update['url'] ); + $new_ver = esc_html( $update['version'] ); + $cur_ver = esc_html( WBF_VERSION ); + + echo " +
+ Version {$new_ver} ist verfügbar. Du verwendest {$cur_ver}. +
+