[ __CLASS__, 'sanitize_style' ] ] ); } public static function sanitize_style( mixed $input ): array { $defaults = self::get_style_defaults(); if ( ! is_array( $input ) ) { return $defaults; } $clean = []; $color_keys = [ 'text_color', 'bg_color', 'button_bg', 'button_text', 'button_hover_bg', 'button_hover_text', ]; foreach ( $color_keys as $key ) { $val = isset( $input[ $key ] ) ? sanitize_text_field( $input[ $key ] ) : ''; $clean[ $key ] = self::sanitize_hex_color( $val ) ?? $defaults[ $key ]; } $clean['custom_css'] = isset( $input['custom_css'] ) ? wp_strip_all_tags( $input['custom_css'] ) : ''; return $clean; } private static function sanitize_hex_color( string $color ): ?string { if ( preg_match( '/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/', $color ) ) { return $color; } return null; } public static function get_style_defaults(): array { return [ 'text_color' => '#ffffff', 'bg_color' => '#111111', 'button_bg' => '#2043B7', 'button_text' => '#ffffff', 'button_hover_bg' => '#1a369a', 'button_hover_text' => '#ffffff', 'custom_css' => '', ]; } public static function get_style(): array { $saved = get_option( CB_STYLE_OPTION, [] ); return wp_parse_args( is_array( $saved ) ? $saved : [], self::get_style_defaults() ); } /** Returns all services from the option, always as a list. */ public static function get_services(): array { $raw = get_option( CB_OPTION, [] ); return is_array( $raw ) ? array_values( $raw ) : []; } /** Returns a single service by id, or null. */ public static function get_service( string $id ): ?array { foreach ( self::get_services() as $svc ) { if ( isset( $svc['id'] ) && $svc['id'] === $id ) { return $svc; } } return null; } public static function save_services(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Keine Berechtigung.', 'gdpr-content-blocker' ) ); } check_admin_referer( 'cb_save_services', 'cb_nonce' ); $raw_services = isset( $_POST['cb_services'] ) && is_array( $_POST['cb_services'] ) ? $_POST['cb_services'] : []; $services = []; foreach ( $raw_services as $item ) { if ( ! is_array( $item ) ) { continue; } $id = sanitize_key( $item['id'] ?? '' ); if ( $id === '' ) { continue; } $services[] = [ 'id' => $id, 'name' => sanitize_text_field( $item['name'] ?? '' ), 'enabled' => ! empty( $item['enabled'] ), 'match_pattern' => sanitize_text_field( $item['match_pattern'] ?? '' ), 'recipient' => sanitize_text_field( $item['recipient'] ?? '' ), 'third_country' => ! empty( $item['third_country'] ), 'sets_cookie' => ! empty( $item['sets_cookie'] ), 'loads_script' => ! empty( $item['loads_script'] ), 'purpose' => sanitize_textarea_field( $item['purpose'] ?? '' ), 'privacy_url' => esc_url_raw( $item['privacy_url'] ?? '' ), 'placeholder_text' => sanitize_textarea_field( $item['placeholder_text'] ?? '' ), ]; } update_option( CB_OPTION, $services ); wp_safe_redirect( admin_url( 'options-general.php?page=gdpr-content-blocker&cb_saved=1' ) ); exit; } public static function enqueue_admin_assets( string $hook ): void { if ( $hook !== 'settings_page_gdpr-content-blocker' ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'dashicons' ); wp_enqueue_script( 'cb-admin', CB_URL . 'assets/admin.js', [ 'wp-color-picker', 'jquery' ], CB_VERSION, true ); wp_localize_script( 'cb-admin', 'cbAdmin', [ 'confirmRemove' => __( 'Dienst wirklich entfernen?', 'gdpr-content-blocker' ), 'presets' => self::get_presets(), 'newServiceLbl' => __( 'Neuer Dienst', 'gdpr-content-blocker' ), 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'scanNonce' => wp_create_nonce( 'cb_scan' ), 'i18n' => [ 'scanning' => __( 'Scanne Webseite …', 'gdpr-content-blocker' ), 'scanError' => __( 'Scan fehlgeschlagen:', 'gdpr-content-blocker' ), 'noFindings' => __( 'Keine externen Einbindungen gefunden.', 'gdpr-content-blocker' ), 'host' => __( 'Anbieter / Host', 'gdpr-content-blocker' ), 'type' => __( 'Typ', 'gdpr-content-blocker' ), 'count' => __( 'Anzahl', 'gdpr-content-blocker' ), 'example' => __( 'Beispiel-URL', 'gdpr-content-blocker' ), 'status' => __( 'Status', 'gdpr-content-blocker' ), 'action' => __( 'Aktion', 'gdpr-content-blocker' ), 'covered' => __( 'abgedeckt', 'gdpr-content-blocker' ), 'thirdParty' => __( 'Drittanbieter', 'gdpr-content-blocker' ), 'firstParty' => __( 'eigene Domain', 'gdpr-content-blocker' ), 'addService' => __( 'Als Dienst übernehmen', 'gdpr-content-blocker' ), 'useTemplate' => __( 'Vorlage übernehmen', 'gdpr-content-blocker' ), 'templateAvail' => __( 'Vorlage verfügbar', 'gdpr-content-blocker' ), 'scannedPages'=> __( 'Gescannte Seiten:', 'gdpr-content-blocker' ), 'foundOn' => __( 'Gefunden auf', 'gdpr-content-blocker' ), ], ] ); } /** * Ready-made templates for the most common third-party iframes. * Everything stays editable after insertion. */ public static function get_presets(): array { return [ 'google-maps' => [ 'id' => 'google-maps', 'name' => 'Google Maps', 'match_pattern' => 'google.com/maps', 'recipient' => __( 'Google Ireland Ltd., Irland / Google LLC, USA', 'gdpr-content-blocker' ), 'third_country' => true, 'sets_cookie' => true, 'loads_script' => true, 'purpose' => __( 'Darstellung interaktiver Karten und Standortinformationen.', 'gdpr-content-blocker' ), 'privacy_url' => 'https://policies.google.com/privacy', ], 'youtube' => [ 'id' => 'youtube', 'name' => 'YouTube', 'match_pattern' => 'youtube', 'recipient' => __( 'Google Ireland Ltd., Irland / Google LLC, USA', 'gdpr-content-blocker' ), 'third_country' => true, 'sets_cookie' => true, 'loads_script' => true, 'purpose' => __( 'Einbettung und Wiedergabe von Videos.', 'gdpr-content-blocker' ), 'privacy_url' => 'https://policies.google.com/privacy', ], 'openstreetmap' => [ 'id' => 'openstreetmap', 'name' => 'OpenStreetMap', 'match_pattern' => 'openstreetmap.org', 'recipient' => __( 'OpenStreetMap Foundation, Großbritannien', 'gdpr-content-blocker' ), 'third_country' => true, 'sets_cookie' => false, 'loads_script' => true, 'purpose' => __( 'Darstellung interaktiver Karten.', 'gdpr-content-blocker' ), 'privacy_url' => 'https://wiki.osmfoundation.org/wiki/Privacy_Policy', ], 'vimeo' => [ 'id' => 'vimeo', 'name' => 'Vimeo', 'match_pattern' => 'player.vimeo.com', 'recipient' => __( 'Vimeo LLC, USA', 'gdpr-content-blocker' ), 'third_country' => true, 'sets_cookie' => true, 'loads_script' => true, 'purpose' => __( 'Einbettung und Wiedergabe von Videos.', 'gdpr-content-blocker' ), 'privacy_url' => 'https://vimeo.com/privacy', ], ]; } public static function render_page(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } $services = self::get_services(); $style = self::get_style(); $saved = isset( $_GET['cb_saved'] ) && $_GET['cb_saved'] === '1'; $settings_saved = isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] === 'true'; ?>
| '; echo ' | |
|---|---|
| '; echo ' | ';
echo ' ' . esc_html__( 'Wird nach den CSS-Variablen eingebunden und kann diese überschreiben. Tipp: denselben Präfix verwenden, z. B. .cb-blocker .cb-blocker__button { … }', 'gdpr-content-blocker' ) . ' |
' . esc_html( $s ) . '';
?>
| , , , , , , |