self::SEITE ), $args ), admin_url( 'admin.php' ) ); } /** Ein freundlicher Hinweis nach der Aktivierung, solange nichts verbunden ist. */ public static function hinweis_einrichten(): void { $bildschirm = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( Talkward_Api::verbunden() || ! current_user_can( self::recht() ) || ( $bildschirm && str_contains( (string) $bildschirm->id, self::SEITE ) ) || ! in_array( $bildschirm->id ?? '', array( 'plugins' ), true ) ) { return; } printf( '

Talkward · %s %s

', esc_html__( 'One more step: connect this site to show the chat.', 'talkward' ), esc_url( self::seiten_url() ), esc_html__( 'Set up now', 'talkward' ) ); } // ------------------------------------------------------------ Verbinden /** * Adressen in Talkward: dort anmelden oder ein kostenloses Konto anlegen, Marke wählen, dann kommt der Browser * mit ?talkward_code=… zurück. Beide Adressen tragen denselben Status-Wert. * * @return array{verbinden: string, neu: string} */ private static function verbinden_urls(): array { $state = wp_generate_password( 24, false ); update_user_meta( get_current_user_id(), 'talkward_state', array( 'wert' => $state, 'bis' => time() + 60 * MINUTE_IN_SECONDS ) ); $args = array( 'woo_seite' => Talkward_Api::seite(), 'woo_zurueck' => self::seiten_url( array( 'talkward_state' => $state ) ), 'woo_name' => get_bloginfo( 'name' ), 'lang' => str_starts_with( (string) get_user_locale(), 'de' ) ? 'de' : 'en', ); $ziel = '#/apps/woocommerce_quelle'; return array( 'verbinden' => Talkward_Api::url( '/' ) . '?' . http_build_query( $args ) . $ziel, 'neu' => Talkward_Api::url( '/' ) . '?' . http_build_query( array_merge( $args, array( 'registrieren' => 1 ) ) ) . $ziel, ); } /** Rückweg aus Talkward: Status prüfen (Schutz vor untergeschobenen Codes), Code tauschen, Abgleich starten. */ public static function rueckweg(): void { if ( self::SEITE !== sanitize_key( wp_unslash( $_GET['page'] ?? '' ) ) || empty( $_GET['talkward_code'] ) || ! current_user_can( self::recht() ) ) { // phpcs:ignore WordPress.Security.NonceVerification return; } $erwartet = get_user_meta( get_current_user_id(), 'talkward_state', true ); $state = sanitize_text_field( wp_unslash( $_GET['talkward_state'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification delete_user_meta( get_current_user_id(), 'talkward_state' ); if ( ! is_array( $erwartet ) || empty( $erwartet['wert'] ) || ! hash_equals( $erwartet['wert'], $state ) || time() > (int) $erwartet['bis'] ) { wp_safe_redirect( self::seiten_url( array( 'talkward_fehler' => 'state' ) ) ); exit; } $ergebnis = Talkward_Api::verbinden( sanitize_text_field( wp_unslash( $_GET['talkward_code'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification if ( is_wp_error( $ergebnis ) ) { set_transient( 'talkward_fehler_' . get_current_user_id(), $ergebnis->get_error_message(), 5 * MINUTE_IN_SECONDS ); wp_safe_redirect( self::seiten_url( array( 'talkward_fehler' => 'code' ) ) ); exit; } delete_option( 'talkward_getrennt_grund' ); // Erste Verbindung dieser Seite: der Chat ist gleich an (deshalb installiert man das Plugin). Wer den // Schalter schon einmal bewusst gestellt hat, behält seine Wahl. if ( null === get_option( Talkward_Widget::OPTION, null ) ) { update_option( Talkward_Widget::OPTION, true ); } Talkward_Sync::takt(); Talkward_Sync::starten(); wp_safe_redirect( self::seiten_url( array( 'talkward_neu' => 1 ) ) ); exit; } // ------------------------------------------------------------ Aktionen private static function pruefen( string $aktion ): void { if ( ! current_user_can( self::recht() ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'talkward' ) ); } check_admin_referer( $aktion ); } public static function widget_schalten(): void { self::pruefen( 'talkward_widget' ); update_option( Talkward_Widget::OPTION, '1' === sanitize_key( wp_unslash( $_POST['an'] ?? '' ) ) ); // phpcs:ignore WordPress.Security.NonceVerification Talkward_Sync::status(); wp_safe_redirect( self::seiten_url( array( 'talkward_ok' => 'widget' ) ) ); exit; } public static function abgleich(): void { self::pruefen( 'talkward_abgleich' ); Talkward_Sync::starten(); wp_safe_redirect( self::seiten_url() ); exit; } public static function trennen(): void { self::pruefen( 'talkward_trennen' ); Talkward_Api::senden( 'trennen', array(), 15 ); Talkward_Api::lokal_trennen(); // Option löschen statt ausschalten: nach dem nächsten Verbinden ist der Chat wieder an delete_option( Talkward_Widget::OPTION ); wp_safe_redirect( self::seiten_url( array( 'talkward_ok' => 'getrennt' ) ) ); exit; } public static function auto_updates(): void { self::pruefen( 'talkward_auto_updates' ); if ( class_exists( 'Talkward_Updater' ) && current_user_can( 'update_plugins' ) && Talkward_Updater::auto_updates_moeglich() ) { Talkward_Updater::auto_updates_setzen( '1' === sanitize_key( wp_unslash( $_POST['an'] ?? '' ) ) ); // phpcs:ignore WordPress.Security.NonceVerification } wp_safe_redirect( self::seiten_url() ); exit; } public static function fortschritt(): void { if ( ! current_user_can( self::recht() ) ) { wp_send_json_error( null, 403 ); } check_ajax_referer( 'talkward_fortschritt' ); wp_send_json_success( array( 'stand' => Talkward_Sync::stand(), 'info' => Talkward_Sync::info() ) ); } // ------------------------------------------------------------ Darstellung public static function stil( string $hook ): void { if ( ! str_contains( $hook, self::SEITE ) ) { return; } wp_register_style( 'talkward-admin', false, array(), TALKWARD_VERSION ); wp_enqueue_style( 'talkward-admin' ); wp_add_inline_style( 'talkward-admin', self::css() ); wp_register_script( 'talkward-admin', false, array(), TALKWARD_VERSION, true ); wp_enqueue_script( 'talkward-admin' ); wp_localize_script( 'talkward-admin', 'talkwardAdmin', array( 'ajax' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'talkward_fortschritt' ), 'texte' => array( /* translators: 1: synced orders, 2: total orders */ 'fortschritt' => __( '%1$s of %2$s orders', 'talkward' ), 'fertig' => __( 'All caught up', 'talkward' ), ), ) ); wp_add_inline_script( 'talkward-admin', self::js() ); } private static function zahl( $n ): string { return number_format_i18n( (int) $n ); } public static function seite(): void { // Beim Öffnen der Seite frischen Stand holen (höchstens alle 2 Minuten; holt auch Befehle ab). $info = Talkward_Sync::info(); if ( Talkward_Api::verbunden() && time() - (int) ( $info['kontakt'] ?? 0 ) > 2 * MINUTE_IN_SECONDS ) { Talkward_Sync::status(); $info = Talkward_Sync::info(); } $v = Talkward_Api::verbindung(); $stand = Talkward_Sync::stand(); $logo = TALKWARD_URL_PLUGIN . 'assets/talkward-logo.svg'; echo '
'; echo '
Talkwardv' . esc_html( TALKWARD_VERSION ) . '
'; self::meldungen(); self::update_karte(); if ( Talkward_Api::verbunden() ) { self::verbunden( $v, $info, $stand ); } else { self::nicht_verbunden(); } echo '
'; } private static function meldungen(): void { // phpcs:disable WordPress.Security.NonceVerification if ( ! empty( $_GET['talkward_neu'] ) ) { echo '
' . esc_html__( 'Connected!', 'talkward' ) . '
'; if ( Talkward_Widget::an() ) { printf( '%s %s', esc_html__( 'The chat is now live on your site.', 'talkward' ), esc_url( home_url( '/' ) ), esc_html__( 'Take a look', 'talkward' ) ); } if ( Talkward_Sync::shop() && Talkward_Api::daten() ) { echo ' ' . esc_html__( 'Your orders are on their way to Talkward. New orders follow within seconds.', 'talkward' ); } if ( class_exists( 'Talkward_Updater' ) && current_user_can( 'update_plugins' ) && Talkward_Updater::auto_updates_moeglich() && ! Talkward_Updater::auto_updates_an() ) { echo '
' . esc_html__( 'Tip: switch on automatic updates below, then the plugin keeps itself up to date.', 'talkward' ); } echo '
'; } if ( ! empty( $_GET['talkward_fehler'] ) ) { $text = 'state' === sanitize_key( wp_unslash( $_GET['talkward_fehler'] ) ) ? __( 'That connection link has expired. Please click “Connect with Talkward” again.', 'talkward' ) : (string) get_transient( 'talkward_fehler_' . get_current_user_id() ); echo '

' . esc_html( $text ?: __( 'The connection failed. Please try again.', 'talkward' ) ) . '

'; } if ( 'getrennt' === sanitize_key( wp_unslash( $_GET['talkward_ok'] ?? '' ) ) ) { echo '

' . esc_html__( 'Disconnected. The chat is off, and Talkward has deleted its copy of your orders.', 'talkward' ) . '

'; } // phpcs:enable if ( 'remote' === get_option( 'talkward_getrennt_grund' ) && ! Talkward_Api::verbunden() ) { echo '

' . esc_html__( 'The connection was ended in Talkward. Connect again whenever you like.', 'talkward' ) . '

'; } } /** „Version X ist da“: was neu ist und ein Klick zum Aktualisieren. */ private static function update_karte(): void { $neu = class_exists( 'Talkward_Updater' ) ? Talkward_Updater::neu() : null; if ( ! $neu ) { return; } echo '
'; /* translators: %s: new plugin version */ echo '

' . esc_html( sprintf( __( 'Version %s is out', 'talkward' ), $neu['version'] ) ) . '

'; if ( $neu['wichtig'] ) { echo '

' . esc_html__( 'This update contains an important fix. Please update soon.', 'talkward' ) . '

'; } echo '
'; if ( current_user_can( 'update_plugins' ) ) { printf( '%s', esc_url( Talkward_Updater::update_url() ), esc_html__( 'Update now', 'talkward' ) ); } /* translators: %s: installed plugin version */ echo '' . esc_html( sprintf( __( 'Installed: %s', 'talkward' ), TALKWARD_VERSION ) ) . '
'; } /** Schalter „Automatische Updates“ (WordPress-eigene Einstellung für dieses Plugin). */ private static function auto_updates_karte(): void { if ( ! class_exists( 'Talkward_Updater' ) || ! current_user_can( 'update_plugins' ) || ! Talkward_Updater::auto_updates_moeglich() ) { return; } $an = Talkward_Updater::auto_updates_an(); echo '

' . esc_html__( 'Automatic updates', 'talkward' ) . '

'; echo '

' . esc_html( $an ? __( 'On. WordPress installs new versions of this plugin by itself and emails you about it.', 'talkward' ) : __( 'Recommended: WordPress then installs new versions of this plugin by itself and emails you about it.', 'talkward' ) ) . '

'; self::formular( 'talkward_auto_updates', '' ); echo '
'; } private static function nicht_verbunden(): void { $vorteile = array( array( 'format-chat', __( 'Live chat on your site in two minutes', 'talkward' ), __( 'One switch, no code. The chat takes the colours and greeting you set in Talkward.', 'talkward' ) ), array( 'email-alt', __( 'One inbox for chat and email', 'talkward' ), __( 'Answer from the browser or the phone app. WhatsApp, Instagram and Facebook join the same inbox on paid plans.', 'talkward' ) ), ); if ( Talkward_Sync::shop() ) { $vorteile[] = array( 'cart', __( 'Orders next to every conversation', 'talkward' ), __( 'On the Professional plan, your team and the AI agent see status, payment and tracking of every WooCommerce order. Your store sends them, so firewalls stay as they are.', 'talkward' ) ); } else { $vorteile[] = array( 'superhero', __( 'An AI agent that knows your site', 'talkward' ), __( 'On the Professional plan, the AI answers around the clock from your pages and hands tricky cases to your team.', 'talkward' ) ); } $urls = self::verbinden_urls(); echo '
'; echo '

' . esc_html__( 'Talk to your visitors while they are on your site', 'talkward' ) . '

'; echo '

' . esc_html__( 'Create your free Talkward account, come straight back here, and the chat is live. The free plan stays free: one seat, live chat and email.', 'talkward' ) . '

'; echo '
'; printf( '%s ', esc_url( $urls['neu'] ), esc_html__( 'Create free account', 'talkward' ) ); printf( '%s', esc_url( $urls['verbinden'] ), esc_html__( 'I already have an account', 'talkward' ) ); echo '
'; echo '

' . esc_html__( 'Both buttons open Talkward. Nothing is sent from this site before you confirm the connection there.', 'talkward' ) . '

'; echo '
'; } private static function verbunden( array $v, array $info, array $stand ): void { $marke = $v['marke']['name'] ?? ''; $kontakt = (int) ( $info['kontakt'] ?? 0 ); $laeuft = ! empty( $stand['laeuft'] ); echo '
'; echo '
'; /* translators: %s: brand name in Talkward */ echo '

' . esc_html( $marke ? sprintf( __( 'Connected to Talkward · %s', 'talkward' ), $marke ) : __( 'Connected to Talkward', 'talkward' ) ) . '

'; if ( ! empty( $info['fehler'] ) ) { echo '

' . esc_html( $info['fehler'] ) . ' ' . esc_html__( 'We keep trying automatically.', 'talkward' ) . '

'; } echo '
'; $shop = Talkward_Sync::shop(); $daten = $shop && Talkward_Api::daten(); echo '
'; if ( $daten ) { printf( '
%s%s
', esc_html( self::zahl( $info['bestellungen'] ?? 0 ) ), esc_html__( 'orders in Talkward', 'talkward' ) ); } /* translators: %s: human readable time difference, e.g. "2 mins" */ printf( '
%s%s
', esc_html( $kontakt ? sprintf( __( '%s ago', 'talkward' ), human_time_diff( $kontakt ) ) : '—' ), esc_html__( 'last contact', 'talkward' ) ); if ( $shop ) { printf( '
%s%s
', esc_html( defined( 'WC_VERSION' ) ? WC_VERSION : '—' ), esc_html__( 'WooCommerce', 'talkward' ) ); } else { printf( '
%s%s
', esc_html( Talkward_Widget::an() ? __( 'On', 'talkward' ) : __( 'Off', 'talkward' ) ), esc_html__( 'chat on your site', 'talkward' ) ); } echo '
'; $gesamt = max( 1, (int) ( $stand['gesamt'] ?? 0 ) ); $fertig = min( $gesamt, (int) ( $stand['fertig'] ?? 0 ) ); if ( $daten ) { printf( '

%s

', $laeuft ? ' tw-aktiv' : '', $laeuft ? 1 : 0, (int) round( 100 * $fertig / $gesamt ), esc_html( $laeuft /* translators: 1: synced orders, 2: total orders */ ? sprintf( __( '%1$s of %2$s orders', 'talkward' ), number_format_i18n( $fertig ), number_format_i18n( $gesamt ) ) : __( 'All caught up. New and changed orders are sent within seconds.', 'talkward' ) ) ); } echo '
'; if ( $daten ) { self::formular( 'talkward_abgleich', '' ); } printf( '%s', esc_url( Talkward_Api::url( '/' ) ), esc_html__( 'Open Talkward', 'talkward' ) ); self::formular( 'talkward_trennen', '' ); echo '
'; // Widget $an = Talkward_Widget::an(); echo '

' . esc_html__( 'Chat widget', 'talkward' ) . '

'; echo '

' . esc_html( $an ? __( 'On. Visitors see the chat on every page. Look and greeting come from Talkward.', 'talkward' ) : __( 'Off. Switch it on to show the chat on every page. Look and greeting come from Talkward.', 'talkward' ) ) . '

'; self::formular( 'talkward_widget', '' ); echo '
'; // Mit WooCommerce, aber Tarif ohne Bestelldaten: sagen, was dazukäme (nur auf dieser Seite, kein Banner) if ( $shop && ! $daten ) { $ab = Talkward_Api::daten_ab(); echo '

' . esc_html__( 'Orders in every conversation', 'talkward' ) . '

'; /* translators: %s: name of the Talkward plan, e.g. "Professional" */ echo esc_html( sprintf( __( 'Your Talkward plan covers the chat. From the %s plan, this store also sends its orders: your team and the AI agent then see status, payment and tracking next to every conversation. Nothing to reconnect.', 'talkward' ), $ab ? $ab : 'Professional' ) ); echo '

'; printf( '%s', esc_url( Talkward_Api::url( '/#/einstellungen/abrechnung' ) ), esc_html__( 'See plans', 'talkward' ) ); echo '
'; } self::auto_updates_karte(); } private static function formular( string $aktion, string $inhalt ): void { echo '
'; wp_nonce_field( $aktion ); echo '' . $inhalt . '
'; // phpcs:ignore WordPress.Security.EscapeOutput -- $inhalt ist oben escaped zusammengesetzt } private static function css(): string { return <<<'CSS' .talkward{--tw:#016dca;--tw-dunkel:#0158a3;--tw-hell:#e8f2fc;max-width:880px} .talkward .tw-kopf{display:flex;align-items:center;gap:12px;margin:18px 0 20px} .talkward .tw-version{font-size:12px;color:#646970;background:#f0f0f1;border-radius:999px;padding:2px 10px} .talkward .tw-karte{background:#fff;border:1px solid #dcdcde;border-radius:14px;padding:24px 28px;margin-bottom:16px;box-shadow:0 1px 2px rgba(0,0,0,.04)} .talkward .tw-held{background:linear-gradient(135deg,#fff 55%,var(--tw-hell));padding:36px 40px} .talkward .tw-held h1{font-size:26px;line-height:1.25;margin:0 0 8px;padding:0} .talkward .tw-leise{color:#50575e;margin:0 0 4px;font-size:14px} .talkward .tw-klein{color:#646970;font-size:13px;margin-top:14px} .talkward .tw-vorteile{list-style:none;margin:22px 0 26px;padding:0;display:grid;gap:14px} .talkward .tw-vorteile li{display:flex;gap:14px;align-items:flex-start} .talkward .tw-vorteile .dashicons{color:var(--tw);background:var(--tw-hell);border-radius:10px;width:36px;height:36px;font-size:20px;line-height:36px;text-align:center;flex:none} .talkward .tw-vorteile strong{display:block;font-size:14px} .talkward .tw-vorteile span{color:#50575e} .talkward .tw-knopf{display:inline-flex;align-items:center;gap:8px;background:var(--tw);color:#fff;text-decoration:none;font-size:15px;font-weight:600;padding:12px 22px;border-radius:10px;transition:background .15s,transform .15s} .talkward .tw-knopf:hover,.talkward .tw-knopf:focus{background:var(--tw-dunkel);color:#fff;transform:translateY(-1px)} .talkward .tw-start{display:flex;gap:12px;flex-wrap:wrap;align-items:center} .talkward .tw-knopf-zweit{background:#fff;color:var(--tw-dunkel);box-shadow:inset 0 0 0 1px #c3c4c7} .talkward .tw-knopf-zweit:hover,.talkward .tw-knopf-zweit:focus{background:var(--tw-hell);color:var(--tw-dunkel)} .talkward .tw-zahlen.tw-zahlen-zwei{grid-template-columns:repeat(2,1fr)} .talkward .tw-status{display:flex;gap:14px;align-items:flex-start} .talkward .tw-status h2{margin:0;font-size:18px} .talkward .tw-punkt{width:12px;height:12px;border-radius:50%;background:#1f9d55;margin-top:6px;box-shadow:0 0 0 0 rgba(31,157,85,.5);animation:tw-puls 2s infinite;flex:none} .talkward .tw-punkt-warn{background:#d63638;animation:none} .talkward .tw-warn{color:#b32d2e;margin:4px 0 0} @keyframes tw-puls{0%{box-shadow:0 0 0 0 rgba(31,157,85,.45)}70%{box-shadow:0 0 0 10px rgba(31,157,85,0)}100%{box-shadow:0 0 0 0 rgba(31,157,85,0)}} .talkward .tw-zahlen{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin:22px 0} .talkward .tw-zahlen>div{background:#f6f7f7;border-radius:10px;padding:14px 16px;display:flex;flex-direction:column;gap:2px} .talkward .tw-zahl{font-size:22px;font-weight:600;color:#1d2327;font-variant-numeric:tabular-nums} .talkward .tw-zahlen span:last-child{color:#646970;font-size:12px} .talkward .tw-balken{height:8px;background:#f0f0f1;border-radius:999px;overflow:hidden;margin-bottom:8px} .talkward .tw-balken span{display:block;height:100%;background:var(--tw);border-radius:999px;transition:width .6s ease} .talkward .tw-aktiv .tw-balken span{background-image:linear-gradient(45deg,rgba(255,255,255,.25) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.25) 50%,rgba(255,255,255,.25) 75%,transparent 75%);background-size:16px 16px;animation:tw-streifen 1s linear infinite} @keyframes tw-streifen{to{background-position:16px 0}} .talkward .tw-abgleich:not(.tw-aktiv) .tw-balken{display:none} .talkward .tw-aktionen{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-top:18px} .talkward .tw-aktionen form{margin:0} .talkward .tw-gefahr{color:#b32d2e!important;margin-left:6px} .talkward .tw-update{border-color:var(--tw);background:linear-gradient(135deg,#fff 60%,var(--tw-hell))} .talkward .tw-update-wichtig{border-color:#d63638} .talkward .tw-update-kopf{display:flex;gap:12px;align-items:flex-start} .talkward .tw-update-kopf .dashicons{color:var(--tw);font-size:24px;width:24px;height:24px;margin-top:2px} .talkward .tw-update h2{margin:0;font-size:17px} .talkward .tw-neu{margin:14px 0 0 36px;list-style:disc;color:#3c434a} .talkward .tw-neu li{margin-bottom:4px} .talkward .tw-knopf-klein{font-size:14px;padding:8px 16px} .talkward .tw-widget{display:flex;justify-content:space-between;align-items:center;gap:24px} .talkward .tw-widget h2{margin:0 0 4px;font-size:16px} .talkward .tw-schalter{position:relative;width:46px;height:26px;border-radius:999px;border:0;background:#c3c4c7;cursor:pointer;transition:background .2s;flex:none;padding:0} .talkward .tw-schalter span{position:absolute;top:3px;left:3px;width:20px;height:20px;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.25);transition:left .2s} .talkward .tw-schalter.tw-an{background:var(--tw)} .talkward .tw-schalter.tw-an span{left:23px} .talkward .tw-erfolg{display:flex;gap:14px;align-items:center;background:#edfaef;border:1px solid #b8e6bf;border-radius:14px;padding:16px 20px;margin-bottom:16px;animation:tw-rein .5s ease} .talkward .tw-haken{width:32px;height:32px;border-radius:50%;background:#1f9d55;position:relative;flex:none;animation:tw-plopp .5s cubic-bezier(.2,1.6,.4,1)} .talkward .tw-haken:after{content:"";position:absolute;left:11px;top:6px;width:8px;height:15px;border:solid #fff;border-width:0 3px 3px 0;transform:rotate(45deg)} @keyframes tw-plopp{0%{transform:scale(0)}100%{transform:scale(1)}} @keyframes tw-rein{0%{opacity:0;transform:translateY(-6px)}100%{opacity:1;transform:none}} @media (max-width:782px){.talkward .tw-zahlen{grid-template-columns:1fr}.talkward .tw-held{padding:24px}.talkward .tw-widget{flex-direction:column;align-items:flex-start}} @media (prefers-reduced-motion:reduce){.talkward *{animation:none!important;transition:none!important}} CSS; } private static function js(): string { return <<<'JS' (function () { var box = document.querySelector('.talkward .tw-abgleich'); if (!box || box.getAttribute('data-laeuft') !== '1' || !window.talkwardAdmin) return; var fmt = function (n) { return Number(n || 0).toLocaleString(document.documentElement.lang || undefined); }; function holen() { var d = new FormData(); d.append('action', 'talkward_fortschritt'); d.append('_ajax_nonce', talkwardAdmin.nonce); fetch(talkwardAdmin.ajax, { method: 'POST', body: d, credentials: 'same-origin' }) .then(function (r) { return r.json(); }) .then(function (r) { if (!r || !r.success) return; var s = r.data.stand || {}, g = Math.max(1, s.gesamt || 0), f = Math.min(g, s.fertig || 0); box.querySelector('.tw-balken span').style.width = Math.round(100 * f / g) + '%'; var zahl = document.querySelector('.talkward [data-tw="bestellungen"]'); if (zahl && r.data.info && r.data.info.bestellungen) zahl.textContent = fmt(Math.max(r.data.info.bestellungen, f)); var text = box.querySelector('[data-tw="text"]'); if (s.laeuft) { text.textContent = talkwardAdmin.texte.fortschritt.replace('%1$s', fmt(f)).replace('%2$s', fmt(g)); setTimeout(holen, 2500); } else { box.classList.remove('tw-aktiv'); text.textContent = talkwardAdmin.texte.fertig; if (zahl) zahl.textContent = fmt(Math.max(f, Number((zahl.textContent || '0').replace(/\D/g, '')) || 0)); } }) .catch(function () { setTimeout(holen, 5000); }); } setTimeout(holen, 1500); })(); JS; } }