PluginProbe ʕ •ᴥ•ʔ
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback / trunk
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback vtrunk
5.1.3 5.1.2 5.1.1 5.1 5.0 trunk 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 3.2.0 3.2.1 3.22 3.22.1 3.22.2 3.22.3 3.22.4 3.22.5 3.22.6 3.3.0 3.3.1 3.3.2 3.3.2.1 3.3.2.2 3.3.3 3.30 3.31 3.32 3.4 3.4.1 3.4.3 3.4.4 3.5 3.5.1 3.6 3.6.1 3.7 3.8 3.9 3.9.1 3.9.2 3.9.3 3.9.4 3.9.6 3.9.6.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2 4.2.1 4.2.2 4.3 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.4
atarim-visual-collaboration / third-party / forms / contact-form-7 / class-avcf-cf7-helpers.php
atarim-visual-collaboration / third-party / forms / contact-form-7 Last commit date
class-avcf-abilities-cf7-pro.php 4 weeks ago class-avcf-abilities-cf7.php 4 weeks ago class-avcf-cf7-detector.php 1 month ago class-avcf-cf7-helpers.php 1 month ago
class-avcf-cf7-helpers.php
108 lines
1 <?php
2 /**
3 * Contact Form 7 — shared helpers for the standalone CF7 ability cluster.
4 *
5 * CF7 config is read/written through the WPCF7_ContactForm model (prop /
6 * set_properties / save); fields are parsed from the [form] template markup;
7 * notifications are the "mail" and "mail_2" templates. CF7 stores no
8 * submissions — the entry side lives in the separate Flamingo cluster. Built on
9 * CF7's model; not runtime-tested here.
10 *
11 * @package atarim-visual-collaboration
12 */
13
14 if ( ! defined('ABSPATH') ) {
15 exit;
16 }
17
18 class AVCF_CF7_Helpers {
19
20 const PLUGIN_SLUG = 'cf7';
21 const PLUGIN_LABEL = 'Contact Form 7';
22
23 public static function get_cf7( $form_id ) {
24 return function_exists( 'wpcf7_contact_form' ) ? wpcf7_contact_form( (int) $form_id ) : null;
25 }
26
27 public static function parse_fields( $template ) {
28 $fields = [];
29 if ( (string) $template === '' ) { return $fields; }
30 if ( preg_match_all( '/\[([a-z][a-z0-9_]*\*?)\s+([a-zA-Z0-9_\-]+)/', (string) $template, $matches, PREG_SET_ORDER ) ) {
31 foreach ( $matches as $m ) {
32 $type = (string) $m[1];
33 $required = ( substr( $type, -1 ) === '*' );
34 if ( $required ) { $type = substr( $type, 0, -1 ); }
35 if ( in_array( $type, [ 'submit', 'response' ], true ) ) { continue; }
36 $fields[] = [ 'id' => (string) $m[2], 'type' => $type, 'label' => (string) $m[2], 'required' => $required, 'options' => [] ];
37 }
38 }
39 return $fields;
40 }
41
42 public static function map_mail( $mail, $key ) {
43 if ( ! is_array( $mail ) ) { return null; }
44 return [
45 'id' => $key,
46 'name' => $key === 'mail' ? 'Mail' : 'Mail (2)',
47 'recipient' => isset( $mail['recipient'] ) ? (string) $mail['recipient'] : '',
48 'recipients' => self::parse_recipients( isset( $mail['recipient'] ) ? (string) $mail['recipient'] : '' ),
49 'sender' => isset( $mail['sender'] ) ? (string) $mail['sender'] : '',
50 'subject' => isset( $mail['subject'] ) ? (string) $mail['subject'] : '',
51 'body' => isset( $mail['body'] ) ? (string) $mail['body'] : '',
52 'additional_headers' => isset( $mail['additional_headers'] ) ? (string) $mail['additional_headers'] : '',
53 'use_html' => ! empty( $mail['use_html'] ),
54 'active' => $key === 'mail' ? true : ! empty( $mail['active'] ),
55 ];
56 }
57
58 public static function map_form_summary( $post ) {
59 $form_id = (int) $post->ID;
60 return [
61 'id' => $form_id,
62 'plugin' => self::PLUGIN_SLUG,
63 'title' => (string) $post->post_title,
64 'status' => $post->post_status === 'publish' ? 'active' : (string) $post->post_status,
65 'entries_total' => null,
66 'last_submission' => null,
67 'created_at' => (string) $post->post_date,
68 ];
69 }
70
71 public static function map_form_full( $post, $cf7 ) {
72 $form_id = (int) $post->ID;
73 $fields = [];
74 $notifications = [];
75 if ( $cf7 && method_exists( $cf7, 'prop' ) ) {
76 $fields = self::parse_fields( (string) $cf7->prop( 'form' ) );
77 foreach ( [ 'mail', 'mail_2' ] as $key ) {
78 $m = self::map_mail( $cf7->prop( $key ), $key );
79 if ( $m && $m['recipient'] !== '' ) {
80 $notifications[] = [ 'id' => $key, 'name' => $m['name'], 'recipients' => $m['recipients'], 'subject' => $m['subject'], 'enabled' => $m['active'] ];
81 }
82 }
83 }
84 return [
85 'id' => $form_id,
86 'plugin' => self::PLUGIN_SLUG,
87 'title' => (string) $post->post_title,
88 'status' => $post->post_status === 'publish' ? 'active' : (string) $post->post_status,
89 'field_count' => count( $fields ),
90 'fields' => $fields,
91 'notifications' => $notifications,
92 'created_at' => (string) $post->post_date,
93 'modified_at' => (string) $post->post_modified,
94 'shortcode' => sprintf( '[contact-form-7 id="%d" title="%s"]', $form_id, esc_attr( $post->post_title ) ),
95 ];
96 }
97
98 public static function parse_recipients( $str ) {
99 if ( (string) $str === '' ) { return []; }
100 $out = [];
101 foreach ( (array) preg_split( '/[,\n;]+/', (string) $str ) as $part ) {
102 $clean = trim( (string) $part );
103 if ( $clean !== '' ) { $out[] = $clean; }
104 }
105 return $out;
106 }
107 }
108