connection = $connection; } public function render( array $attrs, string $origin = 'shortcode' ): string { if ( ! $this->connection->is_connected() ) { if ( current_user_can( 'manage_options' ) ) { return '

' . esc_html__( 'Mowl form: the site is not connected to Mowl yet. Connect it under Mowl → Connection.', 'mowl-email' ) . '

'; } return ''; } $overrides = FormSettings::overrides( $attrs, $this->connection ); $s = array_merge( FormSettings::load(), $overrides ); $this->enqueue_assets(); ++self::$instance; $id = 'mowl-form-' . self::$instance; $page_url = $this->current_url(); // A blob csak a shortcode/block felülírásait hordozza, az admin // alapértékeit nem: így egy admin-mentés azonnal érvényes a (page // cache-ből is kiszolgált) formokon, a felülírásaik megtartásával. $cfg = $this->cfg_from_overrides( $overrides ); $cfg_b64 = base64_encode( (string) wp_json_encode( $cfg ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- nem obfuszkálás, hanem egy rejtett input értékének kódolása; a tartalom aláírt és a handler dekódolja. ob_start(); ?>
message_from_query( $s ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- belül escape-elve. ?>

'consent_text', 'success_message' => 'success', 'pending_message' => 'pending', 'confirm_redirect_url' => 'redirect', ) as $key => $cfg_key ) { if ( array_key_exists( $key, $overrides ) ) { $cfg[ $cfg_key ] = (string) $overrides[ $key ]; } } return $cfg; } /** A wp_enqueue_* handle-önként idempotens: több form egy oldalon is egyszer tölti be. */ public function enqueue_assets(): void { wp_enqueue_style( 'mowl-form', MOWL_URL . 'assets/form.css', array(), MOWL_VERSION ); wp_enqueue_script( 'mowl-form', MOWL_URL . 'assets/form.js', array(), MOWL_VERSION, true ); self::enqueue_turnstile(); } /** * A Turnstile widget-scriptje, ha be van kapcsolva — a „készleten van" * űrlap is ezt használja (közös handle, egyszer töltődik be). */ public static function enqueue_turnstile(): void { if ( ! Turnstile::enabled() ) { return; } // Verzió-paraméter nélkül: a Cloudflare a saját URL-jét verziózza. wp_enqueue_script( 'mowl-turnstile', Turnstile::SCRIPT_URL, array(), null, // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- külső szolgáltatás scriptje, a Cloudflare verziózza. array( 'strategy' => 'defer', 'in_footer' => true, ) ); } /** * A no-JS út visszairányítása után a státusz és a kód a query stringben * jön — sosem szabad szöveg (`mowl_msg`), mert egy `?mowl_msg=...` a * form saját dobozába íratna tetszőleges (pl. adathalász) szöveget. * A megjelenített szöveg mindig a whitelistelt `message_for()`-ból jön. */ private function message_from_query( array $settings ): string { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- csak megjelenítés, nem művelet. $status = isset( $_GET['mowl_status'] ) ? sanitize_key( wp_unslash( $_GET['mowl_status'] ) ) : ''; if ( ! in_array( $status, array( 'pending', 'ok', 'error' ), true ) ) { return ''; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- csak megjelenítés, nem művelet. $code = isset( $_GET['mowl_code'] ) ? sanitize_key( wp_unslash( $_GET['mowl_code'] ) ) : ''; $message = SubmissionHandler::message_for( $code, $status, $settings ); $ok = in_array( $status, array( 'pending', 'ok' ), true ); $class = $ok ? 'mowl-form__message--ok' : 'mowl-form__message--error'; $hint = SubmissionHandler::hint_for( $status ); $html = '

' . esc_html( $message ) . '

'; if ( '' !== $hint ) { $html .= '

' . esc_html( $hint ) . '

'; } return $html; } /** * Az oldal URL-je, ahová a no-JS út visszairányít (`_mowl_page`). A * `$wp->request` egyszerű permalinkek mellett üres (és a query stringet * is elveszti), ezért singular oldalon a permalink, máshol a REQUEST_URI * — a handler úgyis csak azonos hostú URL-t fogad el. Alkönyvtáras * telepítésen a REQUEST_URI már tartalmazza a home útvonalát, azt * levágjuk, hogy a home_url() ne duplázza (/blog/blog/...). */ private function current_url(): string { if ( is_singular() ) { $permalink = get_permalink(); if ( is_string( $permalink ) && '' !== $permalink ) { return $permalink; } } $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '/'; $home_path = rtrim( (string) wp_parse_url( home_url( '/' ), PHP_URL_PATH ), '/' ); if ( '' !== $home_path && ( $request_uri === $home_path || str_starts_with( $request_uri, $home_path . '/' ) || str_starts_with( $request_uri, $home_path . '?' ) ) ) { $request_uri = substr( $request_uri, strlen( $home_path ) ); } $url = esc_url_raw( home_url( '/' . ltrim( $request_uri, '/' ) ) ); return '' !== $url ? $url : home_url( '/' ); } }