@@ -3,7 +3,7 @@
Plugin Name : WP Ingame Shop Pro
Plugin URI : https :// git . viper . ipv64 . net / M_Viper / WP - Ingame - Shop - Pro
Description : Vollautomatischer Shop mit Warenkorb ( kein echtgeld Handel )
Version : 2.1 . 3
Version : 2.1 . 4
Author : M_Viper
Author URI : https :// m - viper . de
Requires at least : 6.9 . 1
@@ -20,7 +20,7 @@ Support: [Telegram Support](https://t.me/M_Viper04)
if ( ! defined ( 'ABSPATH' )) exit ;
// Plugin Constants
define ( 'WIS_VERSION' , '2.1.3 ' );
define ( 'WIS_VERSION' , '2.1.4 ' );
define ( 'WIS_PLUGIN_DIR' , plugin_dir_path ( __FILE__ ));
define ( 'WIS_PLUGIN_URL' , plugin_dir_url ( __FILE__ ));
@@ -3778,6 +3778,19 @@ class WIS_Admin {
echo '<div class="updated"><p>✅ Status geändert!</p></div>' ;
}
// Bestellung manuell erneut senden: zurück auf 'pending', damit das
// Spigot-Plugin sie beim nächsten Abruf/Login wieder abholt.
if ( isset ( $_GET [ 'action' ], $_GET [ 'id' ]) && $_GET [ 'action' ] === 'resend' ) {
check_admin_referer ( 'wis_order_action' , '_wpnonce' );
WIS_DB :: update_order_status ( intval ( $_GET [ 'id' ]), 'pending' );
echo '<div class="updated"><p>✅ Bestellung #' . intval ( $_GET [ 'id' ]) . ' wird erneut gesendet (Status: Warte). Der Status aktualisiert sich automatisch.</p></div>' ;
// Aktion aus der Adresszeile entfernen, damit ein Neuladen (F5)
// die Bestellung nicht versehentlich noch einmal sendet.
echo '<script>(function(){var u=new URL(window.location.href);'
. '["action","id","_wpnonce"].forEach(function(k){u.searchParams.delete(k);});'
. 'window.history.replaceState({},"",u.toString());})();</script>' ;
}
if ( isset ( $_GET [ 'view' ])) {
$order = WIS_DB :: get_order ( intval ( $_GET [ 'view' ]));
if ( ! $order ) { echo '<div class="error"><p>Bestellung nicht gefunden.</p></div>' ; return ; }
@@ -3879,10 +3892,10 @@ class WIS_Admin {
< th > Inhalt </ th >
< th style = " width:90px; " > Preis </ th >
< th style = " width:110px; " > Status </ th >
< th style = " width:18 0px; " > Aktionen </ th >
< th style = " width:27 0px; " > Aktionen </ th >
</ tr >
</ thead >
< tbody >
< tbody id = " wis-orders-body " >
< ? php if ( empty ( $orders )) : ?>
< tr >< td colspan = " 9 " style = " text-align:center;padding:40px;color:#999; " > Keine Bestellungen gefunden .</ td ></ tr >
< ? php else : foreach ( $orders as $order ) : ?>
@@ -3897,6 +3910,9 @@ class WIS_Admin {
< td style = " color:<?php echo $status_colors[$order->status] ?? '#333'; ?>;font-weight:bold; " >< ? php echo $status_map [ $order -> status ] ? ? $order -> status ; ?> </td>
< td >
< a href = " <?php echo admin_url('admin.php?page=wis_orders&view=' . $order->id ); ?> " class = " button button-small " > Details </ a >
< ? php if ( $order -> status !== 'pending' ) : ?>
< a href = " <?php echo wp_nonce_url(admin_url('admin.php?page=wis_orders&action=resend&id=' . $order->id . ( $search ? " & s = $search " :'') . ( $f_status ? " & status = $f_status " :'') . ( $f_server ? " & server = $f_server " :'')), 'wis_order_action', '_wpnonce'); ?> " class = " button button-small " onclick = " return confirm('Bestellung #<?php echo intval( $order->id ); ?> erneut an den Server senden? Der Spieler erhält sie beim nächsten Abruf noch einmal.'); " > Erneut senden </ a >
< ? php endif ; ?>
< a href = " <?php echo wp_nonce_url(admin_url('admin.php?page=wis_orders&action=delete&id=' . $order->id . ( $search ? " & s = $search " :'') . ( $f_status ? " & status = $f_status " :'') . ( $f_server ? " & server = $f_server " :'')), 'wis_order_action', '_wpnonce'); ?> " class = " button button-small " onclick = " return confirm('Wirklich löschen?'); " style = " color:red; " > Löschen </ a >
</ td >
</ tr >
@@ -3904,6 +3920,31 @@ class WIS_Admin {
</ tbody >
</ table >
< script >
// Bestell-Liste alle 5 Sekunden im Hintergrund aktualisieren,
// damit Statuswechsel (z.B. Warte → Fertig) ohne Neuladen sichtbar werden.
( function () {
var body = document . getElementById ( 'wis-orders-body' );
if ( ! body || ! window . fetch || ! window . DOMParser ) return ;
function refresh () {
if ( document . hidden ) return ;
var u = new URL ( window . location . href );
// Niemals eine Aktion (resend/delete/complete) im Hintergrund wiederholen
[ 'action' , 'id' , '_wpnonce' ] . forEach ( function ( k ) { u . searchParams . delete ( k ); });
fetch ( u . toString (), { credentials : 'same-origin' })
. then ( function ( r ) { return r . ok ? r . text () : null ; })
. then ( function ( html ) {
if ( ! html ) return ;
var fresh = new DOMParser () . parseFromString ( html , 'text/html' )
. getElementById ( 'wis-orders-body' );
if ( fresh && fresh . innerHTML !== body . innerHTML ) body . innerHTML = fresh . innerHTML ;
})
. catch ( function () {});
}
setInterval ( refresh , 5000 );
})();
</ script >
< ? php if ( $total_pages > 1 ) : ?>
< div style = " margin-top:15px;display:flex;gap:6px;align-items:center;flex-wrap:wrap; " >
< ? php for ( $p = 1 ; $p <= $total_pages ; $p ++ ) :
@@ -4402,13 +4443,18 @@ class WIS_Admin {
$abo_id = intval ( $_POST [ 'wis_abo_id' ] ? ? 0 );
if ( $abo_id > 0 ) {
if ( $abo_type === 'fly ' ) {
if ( $abo_type === 'plot ' ) {
echo '<div class="error"><p>Plot-Abos werden im Spiel verwaltet (/plotabo, /plotabocancel).</p></div>' ;
$table = null ;
} elseif ( $abo_type === 'fly' ) {
$table = $wpdb -> prefix . 'wis_fly_abo_subs' ;
} else {
$table = $wpdb -> prefix . 'wis_item_abo_subs' ;
}
if ( $action === 'cancel' ) {
if ( $table === null ) {
// Plot-Abo bereits oben behandelt
} elseif ( $action === 'cancel' ) {
$wpdb -> update ( $table ,
[ 'cancelled' => 1 , 'cancelled_at' => current_time ( 'mysql' )],
[ 'id' => $abo_id ]
@@ -4434,19 +4480,51 @@ class WIS_Admin {
$currency = esc_html ( get_option ( 'wis_currency_name' , '$' ));
// ── Fly-Abos laden ──────────────────────────────────────────── ────
$fly_table = $wpdb -> prefix . 'wis_fly_abo_subs ' ;
// ── Fly-Abos laden (maßgeblich: Spiegel aus dem Spigot-Plugin) ────
$fly_table = $wpdb -> prefix . 'wis_fly_abos_mirror ' ;
$fly_exists = $wpdb -> get_var ( " SHOW TABLES LIKE ' { $fly_table } ' " );
$fly_rows = [];
// Solange der Spigot-Abgleich noch keine Fly-Abos geliefert hat, die bisherige WP-Tabelle anzeigen
if ( $fly_exists && ! ( int ) $wpdb -> get_var ( " SELECT COUNT(*) FROM { $fly_table } " )) {
$fly_exists = false ;
}
if ( ! $fly_exists ) {
$legacy_fly = $wpdb -> prefix . 'wis_fly_abo_subs' ;
if ( $wpdb -> get_var ( " SHOW TABLES LIKE ' { $legacy_fly } ' " ) && in_array ( $f_type , [ 'all' , 'fly' ])) {
$where = '1=1' ;
$args = [];
if ( $f_status === 'active' ) { $where .= " AND status = 'active' AND cancelled = 0 AND expires_at > NOW() " ; }
elseif ( $f_status === 'cancelled' ) { $where .= " AND cancelled = 1 " ; }
elseif ( $f_status === 'expired' ) { $where .= " AND (status = 'expired' OR expires_at <= NOW()) " ; }
if ( $f_player ) { $where .= " AND player_name LIKE %s " ; $args [] = '%' . $wpdb -> esc_like ( $f_player ) . '%' ; }
$sql = " SELECT *, 'fly' AS abo_type FROM { $legacy_fly } WHERE { $where } ORDER BY created_at DESC LIMIT 200 " ;
$fly_rows = $args ? $wpdb -> get_results ( $wpdb -> prepare ( $sql , ... $args )) : $wpdb -> get_results ( $sql );
}
}
if ( $fly_exists && in_array ( $f_type , [ 'all' , 'fly' ])) {
$where = '1=1' ;
$args = [];
if ( $f_status === 'active' ) { $where .= " AND status = 'active' AND cancelled = 0 AND expires_at > NOW() " ; }
if ( $f_status === 'active' ) { $where .= " AND period_end >= CURDATE() AND cancelled = 0 " ; }
elseif ( $f_status === 'cancelled' ) { $where .= " AND cancelled = 1 " ; }
elseif ( $f_status === 'expired' ) { $where .= " AND (status = 'expired' OR expires_at <= NOW() ) " ; }
if ( $f_player ) { $where .= " AND player_name LIKE %s " ; $args [] = '%' . $f_player . '%' ; }
$sql = " SELECT *, 'fly' AS abo_type FROM { $fly_table } WHERE { $where } ORDER BY crea ted_at DESC LIMIT 200 " ;
$fly_rows = $args ? $wpdb -> get_results ( $wpdb -> prepare ( $sql , ... $args )) : $wpdb -> get_results ( $sql );
elseif ( $f_status === 'expired' ) { $where .= " AND period_end < CURDATE( ) " ; }
if ( $f_player ) { $where .= " AND player_name LIKE %s " ; $args [] = '%' . $wpdb -> esc_like ( $ f_player) . '%' ; }
$sql = " SELECT * FROM { $fly_table } WHERE { $where } ORDER BY gran ted_at DESC LIMIT 200 " ;
$raw = $args ? $wpdb -> get_results ( $wpdb -> prepare ( $sql , ... $args )) : $wpdb -> get_results ( $sql );
foreach (( array ) $raw as $r ) {
$o = new stdClass ();
$o -> id = $r -> id ;
$o -> abo_type = 'fly' ;
$o -> player_name = $r -> player_name ;
$o -> server = '– ' ;
$o -> label = $r -> label ;
$o -> price = $r -> monthly_price ;
$o -> created_at = $r -> granted_at ;
$o -> expires_at = $r -> period_end . ' 23:59:59' ;
$o -> cancelled = ( int ) $r -> cancelled ;
$o -> status = ( strtotime ( $o -> expires_at ) > time ()) ? 'active' : 'expired' ;
$o -> readonly = true ;
$fly_rows [] = $o ;
}
}
// ── Item-Abos laden ───────────────────────────────────────────────
@@ -4464,8 +4542,39 @@ class WIS_Admin {
$item_rows = $args ? $wpdb -> get_results ( $wpdb -> prepare ( $sql , ... $args )) : $wpdb -> get_results ( $sql );
}
// ── Plot-Abos laden (Tabelle wird vom Spigot-Plugin verwaltet) ────
$plot_table = $wpdb -> prefix . 'wis_plot_abos_mirror' ;
if ( ! $wpdb -> get_var ( " SHOW TABLES LIKE ' { $plot_table } ' " )) $plot_table = '' ;
$plot_rows = [];
if ( $plot_table && in_array ( $f_type , [ 'all' , 'plot' ])) {
$where = '1=1' ;
$args = [];
if ( $f_status === 'active' ) { $where .= " AND period_end >= CURDATE() AND cancelled = 0 " ; }
elseif ( $f_status === 'cancelled' ) { $where .= " AND cancelled = 1 " ; }
elseif ( $f_status === 'expired' ) { $where .= " AND period_end < CURDATE() " ; }
if ( $f_player ) { $where .= " AND player_name LIKE %s " ; $args [] = '%' . $wpdb -> esc_like ( $f_player ) . '%' ; }
$sql = " SELECT * FROM { $plot_table } WHERE { $where } ORDER BY granted_at DESC LIMIT 200 " ;
$raw = $args ? $wpdb -> get_results ( $wpdb -> prepare ( $sql , ... $args )) : $wpdb -> get_results ( $sql );
foreach (( array ) $raw as $r ) {
$o = new stdClass ();
$o -> id = $r -> id ;
$o -> abo_type = 'plot' ;
$o -> player_name = $r -> player_name ;
$o -> server = '– ' ;
$o -> label = $r -> label ;
$o -> price = $r -> monthly_price ;
$o -> created_at = $r -> granted_at ;
$o -> expires_at = $r -> period_end . ' 23:59:59' ;
$o -> cancelled = ( int ) $r -> cancelled ;
$o -> status = ( strtotime ( $o -> expires_at ) > time ()) ? 'active' : 'expired' ;
$o -> slots = $r -> abo_slots ;
$o -> frozen_at = $r -> frozen_at ? ? null ;
$plot_rows [] = $o ;
}
}
// Zusammenführen und nach Datum sortieren
$all_rows = array_merge ( $fly_rows , $item_rows );
$all_rows = array_merge ( $fly_rows , $item_rows , $plot_rows );
usort ( $all_rows , fn ( $a , $b ) => strcmp ( $b -> created_at , $a -> created_at ));
$nonce = wp_create_nonce ( 'wis_abo_admin_action' );
@@ -4484,6 +4593,7 @@ class WIS_Admin {
< option value = " all " < ? php selected ( $f_type , 'all' ); ?> >Alle Typen</option>
< option value = " fly " < ? php selected ( $f_type , 'fly' ); ?> >✈ Fly-Abo</option>
< option value = " item " < ? php selected ( $f_type , 'item' ); ?> >📦 Item-Abo</option>
< option value = " plot " < ? php selected ( $f_type , 'plot' ); ?> >🏠 Plot-Abo</option>
</ select >
< select name = " abo_status " >
< option value = " active " < ? php selected ( $f_status , 'active' ); ?> >Aktiv</option>
@@ -4516,6 +4626,7 @@ class WIS_Admin {
< tbody >
< ? php foreach ( $all_rows as $row ) :
$is_fly = $row -> abo_type === 'fly' ;
$is_plot = $row -> abo_type === 'plot' ;
$is_active = $row -> status === 'active' && ! $row -> cancelled && strtotime ( $row -> expires_at ) > time ();
$is_cancelled = ( bool ) $row -> cancelled ;
$is_expired = ! $is_active && ! $is_cancelled ;
@@ -4525,24 +4636,30 @@ class WIS_Admin {
: ( $is_active
? '<span style="color:#27ae60;font-weight:600;">✔ Aktiv</span>'
: '<span style="color:#888;">⏱ Abgelaufen</span>' );
if ( $is_plot && ! empty ( $row -> frozen_at )) {
$left = max ( 0 , 7 - ( int ) floor (( time () - strtotime ( $row -> frozen_at )) / 86400 ));
$status_html = '<span style="color:#2980b9;font-weight:600;">❄ Eingefroren</span><br><small>Freigabe in ' . $left . ' Tg.</small>' ;
}
$detail = $is_fly
$detail = $is_plot
? '🏠 +' . intval ( $row -> slots ) . ' Plot-Slots · ' . number_format ( $row -> price ) . ' ' . $currency . '/Monat'
: ( $is_fly
? 'Fly-Abo · ' . number_format ( $row -> price ) . ' ' . $currency . '/Monat'
: '📦 ' . esc_html ( $row -> item_id ) . ' · ' . intval ( $row -> daily_qty ) . 'x täglich' ;
: '📦 ' . esc_html ( $row -> item_id ) . ' · ' . intval ( $row -> daily_qty ) . 'x täglich' ) ;
?>
< tr >
< td >< strong > #<?php echo $row->id; ?></strong></td>
< td >< ? php echo $is_fly ? '✈ Fly' : '📦 Item' ; ?> </td>
< td >< ? php echo $is_plot ? '🏠 Plot' : ( $is_ fly ? '✈ Fly' : '📦 Item' ) ; ?> </td>
< td >< strong >< ? php echo esc_html ( $row -> player_name ); ?> </strong></td>
< td >< ? php echo esc_html ( $row -> server ); ?> </td>
< td >
< strong >< ? php echo esc_html ( $row -> label ); ?> </strong>
< br >< small style = " color:#888; " >< ? php echo $detail ; ?> </small>
< ? php if ( ! $is_fly && ! empty ( $row -> last_delivered )) : ?>
< ? php if ( ! $is_fly && ! $is_plot && ! empty ( $row -> last_delivered )) : ?>
< br >< small style = " color:#aaa; " > Zuletzt geliefert : < ? php echo date ( 'd.m.Y' , strtotime ( $row -> last_delivered )); ?> </small>
< ? php endif ; ?>
</ td >
< td >< ? php echo $is_fly ? number_format ( $row -> price ) . ' ' . $currency : '– ' ; ?> </td>
< td >< ? php echo ( $is_fly || $is_plot ) ? number_format ( $row -> price ) . ' ' . $currency : '– ' ; ?> </td>
< td >< ? php echo date ( 'd.m.Y' , strtotime ( $row -> expires_at )); ?> </td>
< td >< ? php echo $status_html ; ?> </td>
< td >
@@ -4550,7 +4667,9 @@ class WIS_Admin {
< input type = " hidden " name = " wis_abo_nonce " value = " <?php echo $nonce ; ?> " >
< input type = " hidden " name = " wis_abo_type " value = " <?php echo esc_attr( $row->abo_type ); ?> " >
< input type = " hidden " name = " wis_abo_id " value = " <?php echo $row->id ; ?> " >
< ? php if ( $is_active ) : ?>
< ? php if ( $is_plot || ! empty ( $row -> readonly ) ): ?>
< small style = " color:#888; " > Verwaltung im Spiel </ small >
< ? php elseif ( $is_active ) : ?>
< button name = " wis_abo_action " value = " cancel "
class = " button button-small "
style = " color:#c0392b;border-color:#c0392b; "
@@ -4561,11 +4680,13 @@ class WIS_Admin {
style = " color:#27ae60;border-color:#27ae60; "
title = " Reaktivieren " > ✔ Reaktivieren </ button >
< ? php endif ; ?>
< ? php if ( ! $is_plot && empty ( $row -> readonly )) : ?>
< button name = " wis_abo_action " value = " delete "
class = " button button-small "
style = " color:#888; "
title = " Eintrag löschen "
onclick = " return confirm('Abo #<?php echo $row->id ; ?> wirklich dauerhaft löschen?'); " > 🗑 </ button >
< ? php endif ; ?>
</ form >
</ td >
</ tr >
@@ -5368,12 +5489,30 @@ class WIS_API {
'permission_callback' => [ WIS_Activator :: class , 'spigot_permission' ],
]);
register_rest_route ( 'wis/v1' , '/abo_offers' , [
'methods' => 'GET' ,
'callback' => [ self :: class , 'abo_offers' ],
'permission_callback' => [ WIS_Activator :: class , 'spigot_permission' ],
]);
register_rest_route ( 'wis/v1' , '/item_abo_reactivate' , [
'methods' => 'POST' ,
'callback' => [ self :: class , 'item_abo_reactivate' ],
'permission_callback' => [ WIS_Activator :: class , 'spigot_permission' ],
]);
register_rest_route ( 'wis/v1' , '/item_abo_cancel' , [
'methods' => 'POST' ,
'callback' => [ self :: class , 'item_abo_cancel' ],
'permission_callback' => [ WIS_Activator :: class , 'spigot_permission' ],
]);
register_rest_route ( 'wis/v1' , '/plot_abo_sync' , [
'methods' => 'POST' ,
'callback' => [ self :: class , 'plot_abo_sync' ],
'permission_callback' => [ WIS_Activator :: class , 'spigot_permission' ],
]);
register_rest_route ( 'wis/v1' , '/trigger_abo_delivery' , [
'methods' => 'POST' ,
'callback' => [ self :: class , 'trigger_abo_delivery' ],
@@ -5450,6 +5589,78 @@ class WIS_API {
* GET / wis / v1 / item_abo_status ? player =< name >
* Gibt alle aktiven Item - Abos eines Spielers zurück .
*/
/** Spigot schickt einen Snapshot aller Plot-Abos; wird als Spiegeltabelle für die Abo-Verwaltung abgelegt. */
public static function plot_abo_sync ( $request ) {
global $wpdb ;
$json = $request -> get_json_params ();
$abos = $json [ 'abos' ] ? ? null ;
if ( ! is_array ( $abos )) {
return new WP_REST_Response ([ 'success' => false , 'message' => 'abos fehlt' ], 400 );
}
$table = $wpdb -> prefix . 'wis_plot_abos_mirror' ;
$wpdb -> query ( " CREATE TABLE IF NOT EXISTS { $table } (
id INT AUTO_INCREMENT PRIMARY KEY ,
player_name VARCHAR ( 64 ) NOT NULL ,
label VARCHAR ( 128 ) NOT NULL ,
abo_slots INT NOT NULL DEFAULT 1 ,
monthly_price INT NOT NULL DEFAULT 0 ,
cancelled TINYINT ( 1 ) NOT NULL DEFAULT 0 ,
cancellation_reason VARCHAR ( 32 ) NULL ,
next_billing_date DATE NULL ,
period_end DATE NULL ,
frozen_at DATE NULL ,
granted_at DATETIME NULL
) " . $wpdb->get_charset_collate ());
$wpdb -> query ( " DELETE FROM { $table } " );
// Fly-Abos (Spigot ist maßgeblich für Preis/Laufzeit/Abbuchung)
$fly_table = $wpdb -> prefix . 'wis_fly_abos_mirror' ;
$wpdb -> query ( " CREATE TABLE IF NOT EXISTS { $fly_table } (
id INT AUTO_INCREMENT PRIMARY KEY ,
player_name VARCHAR ( 64 ) NOT NULL ,
label VARCHAR ( 128 ) NOT NULL ,
monthly_price INT NOT NULL DEFAULT 0 ,
cancelled TINYINT ( 1 ) NOT NULL DEFAULT 0 ,
cancellation_reason VARCHAR ( 32 ) NULL ,
next_billing_date DATE NULL ,
period_end DATE NULL ,
granted_at DATETIME NULL
) " . $wpdb->get_charset_collate ());
if ( isset ( $json [ 'fly' ]) && is_array ( $json [ 'fly' ])) {
$wpdb -> query ( " DELETE FROM { $fly_table } " );
foreach ( $json [ 'fly' ] as $f ) {
$wpdb -> insert ( $fly_table , [
'player_name' => sanitize_text_field ( $f [ 'player_name' ] ? ? '' ),
'label' => sanitize_text_field ( $f [ 'label' ] ? ? '' ),
'monthly_price' => intval ( $f [ 'monthly_price' ] ? ? 0 ),
'cancelled' => intval ( $f [ 'cancelled' ] ? ? 0 ),
'cancellation_reason' => ! empty ( $f [ 'cancellation_reason' ]) ? sanitize_text_field ( $f [ 'cancellation_reason' ]) : null ,
'next_billing_date' => sanitize_text_field ( $f [ 'next_billing_date' ] ? ? '' ) ? : null ,
'period_end' => sanitize_text_field ( $f [ 'period_end' ] ? ? '' ) ? : null ,
'granted_at' => sanitize_text_field ( $f [ 'granted_at' ] ? ? '' ) ? : null ,
]);
}
}
$n = 0 ;
foreach ( $abos as $a ) {
$wpdb -> insert ( $table , [
'player_name' => sanitize_text_field ( $a [ 'player_name' ] ? ? '' ),
'label' => sanitize_text_field ( $a [ 'label' ] ? ? '' ),
'abo_slots' => intval ( $a [ 'abo_slots' ] ? ? 0 ),
'monthly_price' => intval ( $a [ 'monthly_price' ] ? ? 0 ),
'cancelled' => intval ( $a [ 'cancelled' ] ? ? 0 ),
'cancellation_reason' => ! empty ( $a [ 'cancellation_reason' ]) ? sanitize_text_field ( $a [ 'cancellation_reason' ]) : null ,
'next_billing_date' => sanitize_text_field ( $a [ 'next_billing_date' ] ? ? '' ) ? : null ,
'period_end' => sanitize_text_field ( $a [ 'period_end' ] ? ? '' ) ? : null ,
'frozen_at' => ! empty ( $a [ 'frozen_at' ]) ? sanitize_text_field ( $a [ 'frozen_at' ]) : null ,
'granted_at' => sanitize_text_field ( $a [ 'granted_at' ] ? ? '' ) ? : null ,
]);
$n ++ ;
}
return new WP_REST_Response ([ 'success' => true , 'count' => $n ], 200 );
}
public static function item_abo_status ( $request ) {
global $wpdb ;
$player = sanitize_text_field ( $request -> get_param ( 'player' ) ? ? '' );
@@ -5489,6 +5700,69 @@ class WIS_API {
* Kündigt genau das Item - Abo mit der angegebenen ID – nur wenn es dem Spieler gehört .
* Gibt 200 bei Erfolg , 403 bei falschem Besitzer , 404 wenn nicht gefunden .
*/
/** Abo-Angebote aus dem Shop (Preis inkl. Steuer wie beim Kauf im Shop). */
public static function abo_offers ( $request ) {
global $wpdb ;
$server = sanitize_text_field ( $request -> get_param ( 'server' ) ? ? '' );
$items = $wpdb -> get_results (
" SELECT * FROM { $wpdb -> prefix } wis_items
WHERE status = 'publish' AND ( item_id REGEXP '^fly_abo' OR item_id REGEXP '^plot_abo_' OR item_id REGEXP '^item_abo_' )
ORDER BY name ASC "
);
$tax_rate = ( get_option ( 'wis_tax_enabled' , '0' ) === '1' ) ? floatval ( get_option ( 'wis_tax_rate' , '0' )) : 0 ;
$names = [];
foreach (( array ) $wpdb -> get_results ( " SELECT slug, name FROM { $wpdb -> prefix } wis_servers " ) as $sv ) {
$names [ $sv -> slug ] = $sv -> name ;
}
$out = [];
foreach (( array ) $items as $it ) {
$slugs = json_decode ( $it -> servers , true ) ? : [];
if ( $server !== '' && ! in_array ( $server , $slugs )) continue ;
$price = intval ( $it -> offer_price > 0 ? $it -> offer_price : $it -> price );
$tax = $tax_rate > 0 ? intval ( floor ( $price * $tax_rate / 100 )) : 0 ;
$type = preg_match ( '/^fly_abo/' , $it -> item_id ) ? 'fly' : ( preg_match ( '/^plot_abo_/' , $it -> item_id ) ? 'plot' : 'item' );
$slots = preg_match ( '/^plot_abo_(\d+)$/' , $it -> item_id , $m ) ? intval ( $m [ 1 ]) : 0 ;
$out [] = [
'id' => intval ( $it -> id ),
'item_id' => $it -> item_id ,
'title' => $it -> name ,
'type' => $type ,
'slots' => $slots ,
'price' => $price ,
'total' => $price + $tax ,
'servers' => implode ( ', ' , array_map ( function ( $s ) use ( $names ) { return $names [ $s ] ? ? $s ; }, $slugs )),
];
}
return new WP_REST_Response ([ 'offers' => $out ], 200 );
}
/** Kündigung eines noch laufenden Item-Abos zurücknehmen. */
public static function item_abo_reactivate ( $request ) {
global $wpdb ;
$body = json_decode ( $request -> get_body (), true );
$player = sanitize_text_field ( $body [ 'player' ] ? ? '' );
$abo_id = intval ( $body [ 'abo_id' ] ? ? 0 );
if ( empty ( $player ) || $abo_id <= 0 ) {
return new WP_REST_Response ([ 'success' => false , 'message' => 'Ungültige Parameter' ], 400 );
}
$table = $wpdb -> prefix . 'wis_item_abo_subs' ;
$row = $wpdb -> get_row ( $wpdb -> prepare (
" SELECT id, player_name FROM { $table }
WHERE id = % d AND status = 'active' AND cancelled = 1 AND expires_at > NOW () " ,
$abo_id
));
if ( ! $row ) {
return new WP_REST_Response ([ 'success' => false , 'message' => 'Abo nicht gefunden oder nicht gekündigt' ], 404 );
}
if ( strcasecmp ( $row -> player_name , $player ) !== 0 ) {
return new WP_REST_Response ([ 'success' => false , 'message' => 'Nicht dein Abo' ], 403 );
}
$wpdb -> update ( $table , [ 'cancelled' => 0 , 'cancelled_at' => null ], [ 'id' => $abo_id ]);
return new WP_REST_Response ([ 'success' => true ], 200 );
}
public static function item_abo_cancel ( $request ) {
global $wpdb ;
$body = json_decode ( $request -> get_body (), true );
@@ -5791,24 +6065,55 @@ class WIS_API {
return new WP_REST_Response ([ 'orders' => []]);
}
$table = $wpdb -> prefix . 'wis_orders' ;
// Gift-Orders werden genauso wie normale Orders für Spieler A gepollt.
// Spieler A muss zuerst ingame bestätigen (Geld abbuchen), erst dann
// bekommt Spieler B die Gift-Anfrage.
$results = $wpdb -> get_results ( $wpdb -> prepare (
" SELECT * FROM $table
WHERE player_name = % s AND status = 'pending'
ORDER BY created_at ASC LIMIT 5 " ,
$server = sanitize_text_field ( $request -> get_param ( 'server' ) ? ? '' );
return new WP_REST_Response ([ 'orders' => self :: claim_next_order ( $player , $server )]);
}
/**
* Gibt die nächste offene Order eines Spielers heraus und markiert genau diese als 'claimed' .
*
* - Mit $server werden nur Orders dieses Servers herausgegeben , damit kein anderer
* Server ( z . B . Lobby ) fremde Orders abholt und verwirft .
* - Es wird nur EINE Order herausgegeben , weil das Spigot - Plugin pro Abruf nur eine verarbeitet .
* - Abo - Lieferungen , die abgeholt aber nie ausgeliefert wurden , werden wieder freigegeben .
*/
private static function claim_next_order ( $player , $server ) {
global $wpdb ;
$table = $wpdb -> prefix . 'wis_orders' ;
$wpdb -> query ( $wpdb -> prepare (
" UPDATE $table SET status = 'pending'
WHERE player_name = % s AND status = 'claimed'
AND item_id = 'item_abo_delivery'
AND created_at < ( NOW () - INTERVAL 5 MINUTE )
AND created_at > ( NOW () - INTERVAL 48 HOUR ) " ,
$player
));
if ( ! empty ( $results )) {
$ids = implode ( ',' , array_map ( fn ( $o ) => intval ( $o -> id ), $results )) ;
$wpdb -> query ( " UPDATE $table SET status = 'claimed' WHERE id IN ( $ids ) AND status = 'pending' " );
$where = " player_name = %s AND status = 'pending' " ;
$args = [ $player ] ;
if ( ! empty ( $server )) {
$where .= " AND LOWER(server) = %s " ;
$args [] = strtolower ( $server );
}
return new WP_REST_Response ([ 'orders' => $results ]);
$results = $wpdb -> get_results ( $wpdb -> prepare (
" SELECT * FROM $table WHERE $where ORDER BY created_at ASC LIMIT 1 " ,
... $args
));
if ( ! empty ( $results )) {
$wpdb -> query ( $wpdb -> prepare (
" UPDATE $table SET status = 'claimed' WHERE id = %d AND status = 'pending' " ,
intval ( $results [ 0 ] -> id )
));
}
return $results ;
}
public static function get_pending_offline ( $request ) {
@@ -5823,38 +6128,59 @@ class WIS_API {
return new WP_REST_Response ([ 'orders' => []]);
}
$table = $wpdb -> prefix . 'wis_orders ';
$results = $wpdb -> get_results ( $wpdb -> prepare (
" SELECT * FROM $table
WHERE player_name = % s AND status = 'pending'
ORDER BY created_at ASC LIMIT 10 " ,
$player
));
$server = sanitize_text_field ( $request -> get_param ( 'server' ) ? ? ' ') ;
if ( ! empty ( $results )) {
$ids = implode ( ',' , array_map ( fn ( $o ) => intval ( $o -> id ), $results ));
$wpdb -> query ( " UPDATE $table SET status = 'claimed' WHERE id IN ( $ids ) AND status = 'pending' " );
}
return new WP_REST_Response ([ 'orders' => $results ]);
return new WP_REST_Response ([ 'orders' => self :: claim_next_order ( $player , $server )]);
}
public static function get_orders_history ( $request ) {
global $wpdb ;
$player = sanitize_text_field ( $request -> get_param ( 'player' ));
$limit = intval ( $request -> get_param ( 'limit' ));
$limit = $limit > 0 ? min ( $limit , 200 ) : 10 ;
if ( ! $player ) {
return new WP_REST_Response ([ 'orders' => []]);
}
// Tägliche Item-Abo-Lieferungen (0 $) sind keine Käufe und gehören nicht auf den Beleg
$results = $wpdb -> get_results ( $wpdb -> prepare (
" SELECT id, item_title, price, status, created_at
" SELECT id, item_title, price, quantity, server, status, created_at
FROM { $wpdb -> prefix } wis_orders
WHERE player_name = % s
ORDER BY created_at DESC LIMIT 10 " ,
$player
WHERE player_name = % s AND item_id <> 'item_abo_delivery'
ORDER BY created_at DESC , id DESC LIMIT % d " ,
$player , $limit
));
// Bei Abos: alle Server, auf denen das Abo nutzbar ist (aus dem Shop-Artikel)
$abo_re = '^(fly_abo|plot_abo|item_abo)' ;
$names = [];
foreach (( array ) $wpdb -> get_results ( " SELECT slug, name FROM { $wpdb -> prefix } wis_servers " ) as $sv ) {
$names [ $sv -> slug ] = $sv -> name ;
}
foreach (( array ) $results as $r ) {
$slugs = [];
$rows = $wpdb -> get_col ( $wpdb -> prepare (
" SELECT i.servers FROM { $wpdb -> prefix } wis_order_items oi
JOIN { $wpdb -> prefix } wis_items i ON i . item_id = oi . item_id
WHERE oi . order_id = % d AND ( oi . item_id REGEXP % s OR oi . item_type LIKE % s ) " ,
$r -> id , $abo_re , '%abo%'
));
if ( ! $rows ) {
// Fallback: Artikel anhand des Titels finden
$rows = $wpdb -> get_col ( $wpdb -> prepare (
" SELECT servers FROM { $wpdb -> prefix } wis_items WHERE name = %s AND item_id REGEXP %s " ,
$r -> item_title , $abo_re
));
}
foreach (( array ) $rows as $json ) {
foreach (( array ) ( json_decode ( $json , true ) ? : []) as $slug ) $slugs [ $slug ] = true ;
}
$labels = [];
foreach ( array_keys ( $slugs ) as $slug ) $labels [] = $names [ $slug ] ? ? $slug ;
$r -> usable_servers = implode ( ', ' , $labels );
}
return new WP_REST_Response ([ 'orders' => $results ]);
}