'#f4f5fa', 'card_color' => '#ffffff', 'text_color' => '#374151', 'accent_color' => '', 'font' => 'Helvetica, Arial, sans-serif', 'font_size' => 15, 'heading_size' => 20, 'radius' => 12, 'align' => 'left', 'shadow' => 'box-shadow:0 4px 16px rgba(15,23,42,0.08);', 'logo_height' => 40, ]; public static function wrap_template(string $content_html, string $heading = ''): string { $style = array_merge(self::STYLE, (array) apply_filters('funnelnode_email_style', [])); $branding = Settings::branding(); $site = (string) get_bloginfo('name'); $bg = (string) $style['bg_color']; $card = (string) $style['card_color']; $text = (string) $style['text_color']; $accent = (string) $style['accent_color'] ?: ((string) ($branding['primary_color'] ?? '') ?: '#6366f1'); $font = (string) $style['font']; $size = (int) $style['font_size']; $hsize = (int) $style['heading_size']; $radius = (int) $style['radius']; $align = 'center' === $style['align'] ? 'center' : 'left'; $shadow = (string) $style['shadow']; $lheight = (int) $style['logo_height']; $logo = (string) ($branding['logo_url'] ?? ''); $dim = '' !== $logo ? self::image_dimensions($logo) : null; $lwidth = ($dim && $dim[1] > 0) ? (int) round($dim[0] * $lheight / $dim[1]) : 0; $lmargin = 'center' === $align ? '0 auto' : '0'; $header = '' !== $logo ? '' . esc_attr($site) . ' 0 ? ' width="' . $lwidth . '" height="' . $lheight . '"' : '') . ' style="display:block;margin:' . $lmargin . ';border:0;outline:none;text-decoration:none;' . 'width:' . ($lwidth > 0 ? $lwidth . 'px' : 'auto') . ';height:auto;max-height:' . $lheight . 'px;" />' : '' . esc_html($site) . ''; $heading_html = '' !== $heading ? '

' . esc_html($heading) . '

' : ''; $content_html = (string) preg_replace('/' . esc_html($site) . ''; } return '' . '' . '
' . '' . '' . '' . '' . '
' . $header . '
' . $heading_html . $content_html . '
' . $footer . '
'; } public static function answers_table(array $rows): string { $out = ''; foreach ($rows as $index => $row) { $border = 0 === $index ? '' : 'border-top:1px solid #e5e7eb;'; $out .= '' . '' . '' . ''; } return $out . '
' . esc_html($row['label']) . '' . esc_html($row['value']) . '
'; } public static function last_error(): string { return self::$last_error; } public static function configure_phpmailer(object $phpmailer): void { if (! self::$sending) { return; } $email = Settings::all()['email']; $from_email = (string) $email['from_email']; $from_name = (string) $email['from_name']; if ('' !== $from_email && is_email($from_email)) { try { $phpmailer->setFrom($from_email, $from_name ?: $from_email, false); } catch (\Throwable) { } } do_action('funnelnode_phpmailer_init', $phpmailer, $email); } private static function image_dimensions(string $url): ?array { $id = attachment_url_to_postid($url); $path = ''; if ($id) { $meta = wp_get_attachment_metadata($id); if (is_array($meta) && ! empty($meta['width']) && ! empty($meta['height'])) { return [(int) $meta['width'], (int) $meta['height']]; } $path = (string) get_attached_file($id); } if ('' === $path || ! is_readable($path)) { return null; } if (preg_match('/\.svg$/i', $path)) { $svg = (string) file_get_contents($path); if (preg_match('/]*\bwidth="([\d.]+)[^"]*"[^>]*\bheight="([\d.]+)/i', $svg, $m) || preg_match('/]*\bheight="([\d.]+)[^"]*"[^>]*\bwidth="([\d.]+)/i', $svg, $mh)) { return isset($m) ? [(int) round((float) $m[1]), (int) round((float) $m[2])] : [(int) round((float) $mh[2]), (int) round((float) $mh[1])]; } if (preg_match('/viewBox="[\d.]+[ ,]+[\d.]+[ ,]+([\d.]+)[ ,]+([\d.]+)"/i', $svg, $vb)) { return [(int) round((float) $vb[1]), (int) round((float) $vb[2])]; } return null; } $size = @getimagesize($path); if (is_array($size) && $size[0] > 0 && $size[1] > 0) { return [(int) $size[0], (int) $size[1]]; } return null; } public static function capture_error(\WP_Error $error): void { if (self::$sending) { $message = wp_strip_all_tags(str_replace('<', ' <', $error->get_error_message())); self::$last_error = trim((string) preg_replace('/\s+/', ' ', $message)); } } private static function log(array $to, string $subject, bool $sent, array $context): void { global $wpdb; $wpdb->insert(Migrations::table(Migrations::TABLE_MAIL_LOG), [ 'recipient' => substr(implode(', ', $to), 0, 500), 'subject' => substr($subject, 0, 255), 'status' => $sent ? 'sent' : 'failed', 'error' => $sent ? null : (self::$last_error ?: __('Unknown error', 'funnelnode')), 'funnel_id' => (int) ($context['funnel_id'] ?? 0), 'submission_id' => (int) ($context['submission_id'] ?? 0), 'created_at' => current_time('mysql', true), ]); } public static function cleanup_log(): void { global $wpdb; $table = Migrations::table(Migrations::TABLE_MAIL_LOG); $cutoff = gmdate('Y-m-d H:i:s', time() - 30 * DAY_IN_SECONDS); $wpdb->query( $wpdb->prepare("DELETE FROM {$table} WHERE created_at < %s", $cutoff) // phpcs:ignore ); } }