PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.73
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.73
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 11 years ago page-form.php 2 years ago page-home.php 2 years ago page-scenarios.php 3 years ago page-statistics.php 2 years ago
page-statistics.php
269 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 global $wp_roles;
43 $wp_roles->add_cap( 'administrator', 'view_custom_menu' );
44 $wp_roles->add_cap( 'editor', 'view_custom_menu' );
45
46 $this->page_hook = add_submenu_page( SIB_Page_Home::PAGE_ID, __( 'Statistics', 'mailin' ), __( 'Statistics', 'mailin' ), 'view_custom_menu', self::PAGE_ID, array( &$this, 'generate' ) );
47 add_action( 'load-' . $this->page_hook, array( &$this, 'init' ) );
48 add_action( 'admin_print_scripts-' . $this->page_hook, array( $this, 'enqueue_scripts' ) );
49 add_action( 'admin_print_styles-' . $this->page_hook, array( $this, 'enqueue_styles' ) );
50 }
51
52 /**
53 * Init Process
54 */
55 function Init() {
56 SIB_Manager::is_done_validation();
57 add_action( 'admin_notices', array( 'SIB_Manager', 'language_admin_notice' ) );
58 }
59
60 /**
61 * Enqueue scripts of plugin
62 */
63 function enqueue_scripts() {
64 wp_enqueue_script( 'sib-admin-js' );
65 wp_enqueue_script( 'sib-bootstrap-js' );
66 wp_localize_script(
67 'sib-admin-js', 'ajax_sib_object',
68 array(
69 'ajax_url' => admin_url( 'admin-ajax.php' ),
70 )
71 );
72 }
73
74 /**
75 * Enqueue style sheets of plugin
76 */
77 function enqueue_styles() {
78 wp_enqueue_style( 'sib-admin-css' );
79 wp_enqueue_style( 'sib-bootstrap-css' );
80 wp_enqueue_style( 'sib-fontawesome-css' );
81 wp_enqueue_style( 'thickbox' );
82 wp_enqueue_style( 'sib-jquery-ui-datepicker', SIB_Manager::$plugin_url . '/css/datepicker.css', false, false, false );
83 }
84
85 /** Generate page script */
86 function generate() {
87 ?>
88 <div id="wrap1" class="box-border-box container-fluid">
89 <div id="main-content" class="row">
90 <?php
91 if ( SIB_Manager::is_api_key_set() ) {
92 $this->generate_main_page();
93 } else {
94 $this->generate_welcome_page();
95 }
96 ?>
97 </div>
98 </div>
99 <style>
100 #wpcontent {
101 margin-left: 160px !important;
102 }
103
104 @media only screen and (max-width: 918px) {
105 #wpcontent {
106 margin-left: 40px !important;
107 }
108 }
109 </style>
110 <?php
111 }
112
113 /** Generate main page */
114 function generate_main_page() {
115 $client = new SendinblueApiClient();
116
117 $date = $this->get_selected_statistics_dates();
118 $data = [
119 'type' => 'classic',
120 'status' => 'sent',
121 'startDate' => $date['startDate'],
122 'endDate' => $date['endDate'],
123 'offset' => 0,
124 ];
125
126 $emailCampaigns = $client->getAllCampaignsByType(SendinblueApiClient::CAMPAIGN_TYPE_EMAIL, $data);
127 $smsCampaigns = $client->getAllCampaignsByType(SendinblueApiClient::CAMPAIGN_TYPE_SMS, $data);
128 /**
129 * Statistics on general options
130 */
131 ?>
132 <h3 class="statistics_h3"><?php _e('Statistics', 'wc_sendinblue'); ?></h3>
133 <div id="sib-statistics-date-container">
134 <form method="POST" id="sib-statistics-form">
135 <label for="sib-statistics-date"><?php esc_attr_e( 'Date', 'mailin' );?>: </label>
136 <?php if (strtotime($date['statisticsDate']) !== false) { ?>
137 <input id="sib-statistics-date" name="sib-statistics-date" value="<?php echo esc_attr( $date['statisticsDate'] ); ?>" autocomplete="off" class="button show-settings">
138 <?php } else { ?>
139 <input id="sib-statistics-date" name="sib-statistics-date" value="<?php echo date('Y-m-d'); ?>" autocomplete="off" class="button show-settings">
140 <?php } ?>
141 <button id="apply-date-range" class="button action"><?php esc_attr_e( 'Apply', 'mailin'); ?></button>
142 <span class="sib-spinner spinner"></span>
143 </form>
144 </div>
145
146 <table aria-describedby="statistic-table" id="ws_statistics_table" class="wc_shipping widefat wp-list-table">
147 <thead>
148 <tr>
149 <th class="sort">&nbsp;</th>
150 <th class=""><?php esc_attr_e( 'Name', 'mailin' );?></th>
151 <th class=""><?php esc_attr_e('Recipients','mailin');?></th>
152 <th class=""><?php esc_attr_e('Deliverability Rate','mailin');?></th>
153 <th class=""><?php esc_attr_e('Opens','mailin');?></th>
154 <th class=""><?php esc_attr_e('Clicks','mailin');?></th>
155 <th class=""><?php esc_attr_e('Unsubscriptions','mailin');?></th>
156 <th class=""><?php esc_attr_e('Bounces','mailin');?></th>
157 <th class=""><?php esc_attr_e('Date','mailin');?></th>
158 </tr>
159 </thead>
160 <tbody class="ui-sortable">
161
162 <h3 class="statistics_h3"><?php esc_attr_e( 'Email Campaigns', 'mailin' );?></h3>
163 <?php
164 if (!empty($emailCampaigns)) {
165 foreach ($emailCampaigns as $campaign) { ?>
166 <tr id="<?php echo str_replace(' ', '-', esc_attr( $campaign['name'] ));?>">
167 <td width="1%" class="sort ui-sortable-handle">
168 <input type="hidden" name="method_order[flat_rate]" value="">
169 </td>
170 <td class=""><?php echo esc_attr( $campaign['name'] );?></td>
171 <td class="sib-statistics-data-value"><?php echo esc_attr( $campaign['statistics']['globalStats']['sent'] );?></td>
172 <td class="sib-statistics-data-value"><?php echo empty($campaign['statistics']['globalStats']['sent']) ? 0 : round(esc_attr( $campaign['statistics']['globalStats']['delivered'] ) * 100 / esc_attr( $campaign['statistics']['globalStats']['sent'] ), 2);?>%</td>
173 <td class="sib-statistics-data-value"><?php echo !empty($campaign['statistics']['globalStats']['viewed']) ? esc_attr( $campaign['statistics']['globalStats']['viewed'] ) : 0;?></td>
174 <td class="sib-statistics-data-value"><?php echo !empty($campaign['statistics']['globalStats']['clickers']) ? esc_attr( $campaign['statistics']['globalStats']['clickers'] ) : 0;?></td>
175 <td class="sib-statistics-data-value"><?php echo !empty($campaign['statistics']['globalStats']['unsubscriptions']) ? esc_attr( $campaign['statistics']['globalStats']['unsubscriptions'] ) : 0; ?></td>
176 <td class="sib-statistics-data-value"><?php echo esc_attr( $campaign['statistics']['globalStats']['softBounces'] ) + esc_attr( $campaign['statistics']['globalStats']['hardBounces'] );?></td>
177 <td class="sib-statistics-data-value sib-last-column-value"><?php echo (new DateTime($campaign['sentDate']))->format('Y-m-d H:i:s');?></td>
178 </tr>
179 <?php } ?>
180 <?php } else { ?>
181 <tr> <td colspan="9" style="text-align:center;"><?php esc_attr_e( 'No Stats Found', 'mailin' ); ?></td></tr>
182 <?php } ?>
183 </tbody>
184 </table>
185 <table aria-describedby="statistic-table" id="ws_statistics_table" class="wc_shipping widefat wp-list-table" cellspacing="0">
186 <thead>
187 <tr>
188 <th class="sort">&nbsp;</th>
189 <th class=""><?php esc_attr_e( 'Name', 'mailin' );?></th>
190 <th class=""><?php esc_attr_e('Recipients','mailin');?></th>
191 <th class=""><?php esc_attr_e('Deliverability Rate','mailin');?></th>
192 <th class=""><?php esc_attr_e('Answeres','mailin');?></th>
193 <th class=""><?php esc_attr_e('Unsubscriptions','mailin');?></th>
194 <th class=""><?php esc_attr_e('Bounces','mailin');?></th>
195 <th class=""><?php esc_attr_e('Date','mailin');?></th>
196 </tr>
197 </thead>
198 <tbody class="ui-sortable">
199
200 <h3 class="statistics_h3"><?php esc_attr_e( 'SMS Campaigns', 'mailin' );?></h3>
201 <?php
202 if (!empty($smsCampaigns)) {
203 foreach($smsCampaigns as $smsCampaign){ ?>
204 <tr id="<?php echo str_replace(' ', '-', esc_attr( $smsCampaign['name'] ));?>">
205 <td width="1%" class="sort ui-sortable-handle">
206 <input type="hidden" name="method_order[flat_rate]" value="">
207 </td>
208 <td class=""><?php echo esc_attr( $smsCampaign['name'] );?></td>
209 <td class="sib-statistics-data-value"><?php echo esc_attr( $smsCampaign['statistics']['sent'] );?></td>
210 <td class="sib-statistics-data-value"><?php echo empty($smsCampaign['statistics']['sent']) ? 0 : round(esc_attr( $smsCampaign['statistics']['delivered'] ) * 100 / esc_attr( $smsCampaign['statistics']['sent'] ), 2);?>%</td>
211 <td class="sib-statistics-data-value"><?php echo !empty($smsCampaign['statistics']['answered']) ? esc_attr( $smsCampaign['statistics']['answered'] ) : 0;?></td>
212 <td class="sib-statistics-data-value"><?php echo !empty($smsCampaign['statistics']['unsubscriptions']) ? esc_attr( $smsCampaign['statistics']['unsubscriptions'] ) : 0;?></td>
213 <td class="sib-statistics-data-value"><?php echo esc_attr( $smsCampaign['statistics']['softBounces'] ) + esc_attr( $smsCampaign['statistics']['hardBounces'] );?></td>
214 <td class="sib-statistics-data-value sib-last-column-value"><?php echo (new DateTime($smsCampaign['sentDate']))->format('Y-m-d H:i:s');?></td>
215 </tr>
216 <?php } ?>
217 <?php } else { ?>
218 <tr> <td colspan="9" style="text-align:center;"><?php esc_attr_e( 'No Stats Found', 'mailin' ); ?></td></tr>
219 <?php } ?>
220 </tbody>
221 </table>
222 <?php
223 }
224
225 /** Generate welcome page */
226 function generate_welcome_page() {
227 ?>
228 <img src="<?php echo esc_url( SIB_Manager::$plugin_url . '/img/background/statistics.png' ); ?>" alt="Statistics Background Image" style="width: 100%;">
229 <?php
230 SIB_Page_Home::print_disable_popup();
231 }
232
233 function get_selected_statistics_dates() {
234 $startDate = (new DateTime())->format(self::START_DATE_FORMAT);
235 $endDate = (new DateTime())->format(self::END_DATE_FORMAT_NOW);
236
237 if (empty($_POST['sib-statistics-date'])) {
238 $statisticsDate = date('Y-m-d');
239 } else {
240 $statisticsDate = sanitize_text_field($_POST['sib-statistics-date']);
241 $date = explode(' - ', $statisticsDate);
242
243 if (count($date) === 1) {
244 $date[] = $date[0];
245 }
246
247 $startDate = (new DateTime($date[0]));
248 $endDate = (new DateTime($date[1]));
249 if ($date[0] >= date('Y-m-d') || $date[1] >= date('Y-m-d')) {
250 $startDate = $startDate->format(self::START_DATE_FORMAT);
251 $endDate = (new DateTime())->format(self::END_DATE_FORMAT_NOW);
252 } elseif ($date[0] === $date[1]) {
253 $startDate = $startDate->format(self::START_DATE_FORMAT);
254 $endDate = $endDate->format(self::END_DATE_FORMAT);
255 } else {
256 $startDate = $startDate->format(self::START_DATE_FORMAT);
257 $endDate = $endDate->format(self::END_DATE_FORMAT);
258 }
259 }
260
261 return [
262 'statisticsDate' => $statisticsDate,
263 'startDate' => $startDate,
264 'endDate' => $endDate,
265 ];
266 }
267 }
268 }
269