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