PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.31
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.31
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Scheduler / Scheduler.php

Scheduler.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 3.6.31, at app/Services/Scheduler/Scheduler.php

143 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\Scheduler;
4
5 use FluentForm\App\Services\Emogrifier\Emogrifier;
6 use FluentForm\View;
7
8 class Scheduler
9 {
10 public static function processEmailReport()
11 {
12 $defaults = [
13 'status' => 'yes',
14 'send_to_type' => 'admin_email',
15 'custom_recipients' => '',
16 'sending_day' => 'Mon'
17 ];
18 $settings = get_option('_fluentform_email_report_summary');
19 if($settings) {
20 $settings = wp_parse_args($settings, $defaults);
21 } else {
22 $settings = $defaults;
23 }
24 if($settings['status'] == 'no') {
25 return;
26 }
27
28 $currentDay = date('D');
29 $reportingDay = $settings['sending_day'];
30
31 $config = apply_filters('fluentform_email_summary_config', [
32 'status' => $currentDay == $reportingDay,
33 'days' => 7
34 ]);
35
36 if (!$config['status']) {
37 return;
38 }
39
40 $days = $config['days'];
41
42 if($settings['send_to_type'] == 'admin_email') {
43 $recipients = [get_option('admin_email')];
44 } else {
45 $custom_recipients = $settings['custom_recipients'];
46 $custom_recipients = explode(',', $custom_recipients);
47 $recipients = [];
48 foreach ($custom_recipients as $recipient) {
49 $recipient = trim($recipient);
50 if(is_email($recipient)) {
51 $recipients[] = $recipient;
52 }
53 }
54 }
55
56 if(!$recipients) {
57 return;
58 }
59
60
61 // Let's grab the reports
62 global $wpdb;
63 $days = intval($days);
64 if(!$days) {
65 $days = 7;
66 }
67
68 $reportDateFrom = date('Y-m-d', time() - $days * 86400); // 7 days
69 $submissionCounts = wpFluent()->table('fluentform_submissions')
70 ->select([
71 wpFluent()->raw("COUNT({$wpdb->prefix}fluentform_submissions.id) as total"),
72 'fluentform_submissions.form_id',
73 'fluentform_forms.title'
74 ])
75 ->groupBy('fluentform_submissions.form_id')
76 ->orderBy('total', 'DESC')
77 ->where('fluentform_submissions.created_at', '>', $reportDateFrom)
78 ->join('fluentform_forms', 'fluentform_forms.id', '=', 'fluentform_submissions.form_id')
79 ->limit(15)
80 ->get();
81
82 foreach ($submissionCounts as $submissionCount) {
83 $submissionCount->permalink = admin_url('admin.php?page=fluent_forms&route=entries&form_id='.$submissionCount->form_id);
84 }
85
86 if(!$submissionCounts) {
87 return; // Nothing found
88 }
89
90 $paymentCounts = [];
91 if(defined('FLUENTFORMPRO') && get_option('__fluentform_payment_module_settings')) {
92 $paymentCounts = wpFluent()->table('fluentform_transactions')
93 ->select([
94 wpFluent()->raw("SUM({$wpdb->prefix}fluentform_transactions.payment_total) as total_amount"),
95 'fluentform_transactions.form_id',
96 'fluentform_transactions.currency',
97 'fluentform_forms.title'
98 ])
99 ->groupBy('fluentform_transactions.form_id')
100 ->orderBy('total_amount', 'DESC')
101 ->where('fluentform_transactions.created_at', '>', $reportDateFrom)
102 ->where('fluentform_transactions.status', '=', 'paid')
103 ->join('fluentform_forms', 'fluentform_forms.id', '=', 'fluentform_transactions.form_id')
104 ->limit(15)
105 ->get();
106 foreach ($paymentCounts as $paymentCount) {
107 $paymentCount->readable_amount = $paymentCount->currency.' '.number_format($paymentCount->total_amount / 100);
108 }
109 }
110
111 $emailBody = View::make('email.report.body', array(
112 'submissions' => $submissionCounts,
113 'payments' => $paymentCounts,
114 'days' => $days
115 ));
116
117 $originalEmailBody = $emailBody;
118
119 ob_start();
120 try {
121 // apply CSS styles inline for picky email clients
122 $emogrifier = new Emogrifier($emailBody);
123 $emailBody = $emogrifier->emogrify();
124 } catch (\Exception $e) {
125
126 }
127 $maybeError = ob_get_clean();
128
129 if ($maybeError) {
130 $emailBody = $originalEmailBody;
131 }
132
133 $headers = [
134 'Content-Type: text/html; charset=utf-8'
135 ];
136
137 $emailSubject = sprintf( esc_html__( 'Email Summary of Your Forms (Last %d Days)', 'my-text-domain' ), $days );
138
139 $emailSubject = apply_filters('fluentform_email_summary_subject', $emailSubject);
140
141 return wp_mail($recipients, $emailSubject, $emailBody, $headers);
142 }
143 }