PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.0.4
Brevo – Email, SMS, Web Push, Chat, and more. v3.0.4
2.9.13 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.2 3.1.20 3.1.21 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.1.29 3.1.3 3.1.30 3.1.31 3.1.32 3.1.33 3.1.34 3.1.35 3.1.36 3.1.37 3.1.38 3.1.39 3.1.4 3.1.40 3.1.41 3.1.42 3.1.43 3.1.44 3.1.45 3.1.46 3.1.47 3.1.48 3.1.49 3.1.5 3.1.50 3.1.51 3.1.52 3.1.53 3.1.54 3.1.55 3.1.56 3.1.57 3.1.58 3.1.59 3.1.6 3.1.60 3.1.61 3.1.62 3.1.63 3.1.64 3.1.65 3.1.66 3.1.67 3.1.68 3.1.69 3.1.7 3.1.70 3.1.71 3.1.72 3.1.73 3.1.74 3.1.75 3.1.76 3.1.77 3.1.78 3.1.79 3.1.8 3.1.80 3.1.81 3.1.82 3.1.83 3.1.84 3.1.85 3.1.86 3.1.87 3.1.88 3.1.89 3.1.9 3.1.90 3.1.91 3.1.92 3.1.93 3.1.94 3.1.95 3.1.96 3.1.97 3.1.98 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 trunk 1.0 1.5 2.0.8 2.9.10 2.9.11 2.9.12
mailin / page / page-statistics.php
mailin / page Last commit date
index.php 5 years ago page-form.php 5 years ago page-home.php 5 years ago page-scenarios.php 5 years ago page-statistics.php 5 years ago
page-statistics.php
262 lines
1 <?php
2 /**
3 * Admin page : dashboard
4 *
5 * @package SIB_Page_Statistics
6 */
7
8 if ( ! class_exists( 'SIB_Page_Statistics' ) ) {
9 /**
10 * Page class that handles backend page <i>dashboard ( for admin )</i> with form generation and processing
11 *
12 * @package SIB_Page_Statistics
13 */
14 class SIB_Page_Statistics {
15
16 /**
17 * Page slug
18 */
19 const PAGE_ID = 'sib_page_statistics';
20
21 const START_DATE_FORMAT = 'Y-m-d\T00:00:00\Z';
22 const END_DATE_FORMAT = 'Y-m-d\T23:59:59\Z';
23 const END_DATE_FORMAT_NOW = 'Y-m-d\TH:i:s\Z';
24 /**
25 * Page hook
26 *
27 * @var string
28 */
29 protected $page_hook;
30
31 /**
32 * Page tabs
33 *
34 * @var mixed
35 */
36 protected $tabs;
37
38 /**
39 * Constructs new page object and adds entry to WordPress admin menu
40 */
41 function __construct() {
42 $this->page_hook = add_submenu_page( SIB_Page_Home::PAGE_ID, __( 'Statistics', 'sib_lang' ), __( 'Statistics', 'sib_lang' ), 'manage_options', self::PAGE_ID, array( &$this, 'generate' ) );
43 add_action( 'load-' . $this->page_hook, array( &$this, 'init' ) );
44 add_action( 'admin_print_scripts-' . $this->page_hook, array( $this, 'enqueue_scripts' ) );
45 add_action( 'admin_print_styles-' . $this->page_hook, array( $this, 'enqueue_styles' ) );
46 }
47
48 /**
49 * Init Process
50 */
51 function Init() {
52 add_action( 'admin_notices', array( 'SIB_Manager', 'language_admin_notice' ) );
53 }
54
55 /**
56 * Enqueue scripts of plugin
57 */
58 function enqueue_scripts() {
59 wp_enqueue_script( 'sib-admin-js' );
60 wp_enqueue_script( 'sib-bootstrap-js' );
61 wp_localize_script(
62 'sib-admin-js', 'ajax_sib_object',
63 array(
64 'ajax_url' => admin_url( 'admin-ajax.php' ),
65 )
66 );
67 }
68
69 /**
70 * Enqueue style sheets of plugin
71 */
72 function enqueue_styles() {
73 wp_enqueue_style( 'sib-admin-css' );
74 wp_enqueue_style( 'sib-bootstrap-css' );
75 wp_enqueue_style( 'sib-fontawesome-css' );
76 wp_enqueue_style( 'thickbox' );
77 wp_enqueue_style( 'sib-jquery-ui-datepicker', SIB_Manager::$plugin_url . '/css/datepicker.css', false, false, false );
78 }
79
80 /** Generate page script */
81 function generate() {
82 ?>
83 <div id="wrap1" class="box-border-box container-fluid">
84 <div id="main-content" class="row">
85 <?php
86 if ( SIB_Manager::is_done_validation() ) {
87 $this->generate_main_page();
88 } else {
89 $this->generate_welcome_page();
90 }
91 ?>
92 </div>
93 </div>
94 <style>
95 #wpcontent {
96 margin-left: 160px !important;
97 }
98
99 @media only screen and (max-width: 918px) {
100 #wpcontent {
101 margin-left: 40px !important;
102 }
103 }
104 </style>
105 <?php
106 }
107
108 /** Generate main page */
109 function generate_main_page() {
110 $client = new SendinblueApiClient();
111
112 $date = $this->get_selected_statistics_dates();
113 $data = [
114 'type' => 'classic',
115 'status' => 'sent',
116 'startDate' => $date['startDate'],
117 'endDate' => $date['endDate'],
118 'offset' => 0,
119 ];
120
121 $emailCampaigns = $client->getAllCampaignsByType(SendinblueApiClient::CAMPAIGN_TYPE_EMAIL, $data);
122 $smsCampaigns = $client->getAllCampaignsByType(SendinblueApiClient::CAMPAIGN_TYPE_SMS, $data);
123 /**
124 * Statistics on general options
125 */
126 ?>
127 <h3><?php _e('Statistics', 'wc_sendinblue'); ?></h3>
128 <div id="sib-statistics-date-container">
129 <form method="POST" id="sib-statistics-form">
130 <label for="sib-statistics-date"><?php esc_attr_e( 'Date', 'sib_lang' );?>: </label>
131 <input id="sib-statistics-date" name="sib-statistics-date" value="<?php echo $date['statisticsDate']; ?>" autocomplete="off" class="button show-settings">
132 <button id="apply-date-range" class="button action"><?php esc_attr_e( 'Apply', 'sib_lang'); ?></button>
133 <span class="sib-spinner spinner"></span>
134 </form>
135 </div>
136 <?php
137 if (!empty($emailCampaigns)) {
138 ?>
139 <table id="ws_statistics_table" class="wc_shipping widefat wp-list-table" cellspacing="0">
140 <thead>
141 <tr>
142 <th class="sort">&nbsp;</th>
143 <th class=""><?php esc_attr_e( 'Name', 'sib_lang' );?></th>
144 <th class=""><?php esc_attr_e('Recipients','sib_lang');?></th>
145 <th class=""><?php esc_attr_e('Deliverability Rate','sib_lang');?></th>
146 <th class=""><?php esc_attr_e('Opens','sib_lang');?></th>
147 <th class=""><?php esc_attr_e('Clicks','sib_lang');?></th>
148 <th class=""><?php esc_attr_e('Unsubscriptions','sib_lang');?></th>
149 <th class=""><?php esc_attr_e('Bounces','sib_lang');?></th>
150 <th class=""><?php esc_attr_e('Date','sib_lang');?></th>
151 </tr>
152 </thead>
153 <tbody class="ui-sortable">
154
155 <div>
156 <h3 class="title"><?php esc_attr_e( 'Email Campaigns', 'sib_lang' );?></h3>
157 </div>
158 <?php
159 foreach($emailCampaigns as $campaign){ ?>
160 <tr id="<?php echo str_replace(' ', '-', $campaign['name']);?>">
161 <td width="1%" class="sort ui-sortable-handle">
162 <input type="hidden" name="method_order[flat_rate]" value="">
163 </td>
164 <td class=""><?php echo $campaign['name'];?></td>
165 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['sent'];?></td>
166 <td class="sib-statistics-data-value"><?php echo empty($campaign['statistics']['globalStats']['sent']) ? 0 : round($campaign['statistics']['globalStats']['delivered'] * 100 / $campaign['statistics']['globalStats']['sent'], 2);?>%</td>
167 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['viewed'];?></td>
168 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['clickers'];?></td>
169 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['unsubscriptions'];?></td>
170 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['softBounces'] + $campaign['statistics']['globalStats']['hardBounces'];?></td>
171 <td class="sib-statistics-data-value sib-last-column-value"><?php echo (new DateTime($campaign['sentDate']))->format('Y-m-d H:i:s');?></td>
172 </tr>
173 <?php } ?>
174 </tbody>
175 </table>
176 <?php }?>
177 <?php
178 if (!empty($smsCampaigns)) {
179 ?>
180 <table id="ws_statistics_table" class="wc_shipping widefat wp-list-table" cellspacing="0">
181 <thead>
182 <tr>
183 <th class="sort">&nbsp;</th>
184 <th class=""><?php esc_attr_e( 'Name', 'sib_lang' );?></th>
185 <th class=""><?php esc_attr_e('Recipients','sib_lang');?></th>
186 <th class=""><?php esc_attr_e('Deliverability Rate','sib_lang');?></th>
187 <th class=""><?php esc_attr_e('Answeres','sib_lang');?></th>
188 <th class=""><?php esc_attr_e('Unsubscriptions','sib_lang');?></th>
189 <th class=""><?php esc_attr_e('Bounces','sib_lang');?></th>
190 <th class=""><?php esc_attr_e('Date','sib_lang');?></th>
191 </tr>
192 </thead>
193 <tbody class="ui-sortable">
194
195 <div>
196 <h3 class="title"><?php esc_attr_e( 'SMS Campaigns', 'sib_lang' );?></h3>
197 </div>
198 <?php
199 foreach($smsCampaigns as $smsCampaign){ ?>
200 <tr id="<?php echo str_replace(' ', '-', $smsCampaign['name']);?>">
201 <td width="1%" class="sort ui-sortable-handle">
202 <input type="hidden" name="method_order[flat_rate]" value="">
203 </td>
204 <td class=""><?php echo $smsCampaign['name'];?></td>
205 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['sent'];?></td>
206 <td class="sib-statistics-data-value"><?php echo empty($smsCampaign['statistics']['sent']) ? 0 : round($smsCampaign['statistics']['delivered'] * 100 / $smsCampaign['statistics']['sent'], 2);?>%</td>
207 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['answered'];?></td>
208 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['unsubscriptions'];?></td>
209 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['softBounces'] + $campaign['statistics']['hardBounces'];?></td>
210 <td class="sib-statistics-data-value sib-last-column-value"><?php echo (new DateTime($smsCampaign['sentDate']))->format('Y-m-d H:i:s');?></td>
211 </tr>
212 <?php } ?>
213 </tbody>
214 </table>
215 <?php }
216 }
217
218 /** Generate welcome page */
219 function generate_welcome_page() {
220 ?>
221 <img src="<?php echo esc_url( SIB_Manager::$plugin_url . '/img/background/statistics.png' ); ?>" style="width: 100%;">
222 <?php
223 SIB_Page_Home::print_disable_popup();
224 }
225
226 function get_selected_statistics_dates() {
227 $startDate = (new DateTime())->format(self::START_DATE_FORMAT);
228 $endDate = (new DateTime())->format(self::END_DATE_FORMAT_NOW);
229
230 if (empty($_POST['sib-statistics-date'])) {
231 $statisticsDate = date('Y-m-d');
232 } else {
233 $statisticsDate = sanitize_text_field($_POST['sib-statistics-date']);
234 $date = explode(' - ', $statisticsDate);
235
236 if (count($date) === 1) {
237 $date[] = $date[0];
238 }
239
240 $startDate = (new DateTime($date[0]));
241 $endDate = (new DateTime($date[1]));
242 if ($date[0] >= date('Y-m-d') || $date[1] >= date('Y-m-d')) {
243 $startDate = $startDate->format(self::START_DATE_FORMAT);
244 $endDate = (new DateTime())->format(self::END_DATE_FORMAT_NOW);
245 } elseif ($date[0] === $date[1]) {
246 $startDate = $startDate->format(self::START_DATE_FORMAT);
247 $endDate = $endDate->format(self::END_DATE_FORMAT);
248 } else {
249 $startDate = $startDate->format(self::START_DATE_FORMAT);
250 $endDate = $endDate->format(self::END_DATE_FORMAT);
251 }
252 }
253
254 return [
255 'statisticsDate' => $statisticsDate,
256 'startDate' => $startDate,
257 'endDate' => $endDate,
258 ];
259 }
260 }
261 }
262