PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.0.7
Brevo – Email, SMS, Web Push, Chat, and more. v3.0.7
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
263 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 <?php
138 if (!empty($emailCampaigns)) {
139 ?>
140 <table id="ws_statistics_table" class="wc_shipping widefat wp-list-table" cellspacing="0">
141 <thead>
142 <tr>
143 <th class="sort">&nbsp;</th>
144 <th class=""><?php esc_attr_e( 'Name', 'sib_lang' );?></th>
145 <th class=""><?php esc_attr_e('Recipients','sib_lang');?></th>
146 <th class=""><?php esc_attr_e('Deliverability Rate','sib_lang');?></th>
147 <th class=""><?php esc_attr_e('Opens','sib_lang');?></th>
148 <th class=""><?php esc_attr_e('Clicks','sib_lang');?></th>
149 <th class=""><?php esc_attr_e('Unsubscriptions','sib_lang');?></th>
150 <th class=""><?php esc_attr_e('Bounces','sib_lang');?></th>
151 <th class=""><?php esc_attr_e('Date','sib_lang');?></th>
152 </tr>
153 </thead>
154 <tbody class="ui-sortable">
155
156 <div>
157 <h3 class="title"><?php esc_attr_e( 'Email Campaigns', 'sib_lang' );?></h3>
158 </div>
159 <?php
160 foreach($emailCampaigns as $campaign){ ?>
161 <tr id="<?php echo str_replace(' ', '-', $campaign['name']);?>">
162 <td width="1%" class="sort ui-sortable-handle">
163 <input type="hidden" name="method_order[flat_rate]" value="">
164 </td>
165 <td class=""><?php echo $campaign['name'];?></td>
166 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['sent'];?></td>
167 <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>
168 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['viewed'];?></td>
169 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['clickers'];?></td>
170 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['unsubscriptions'];?></td>
171 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['softBounces'] + $campaign['statistics']['globalStats']['hardBounces'];?></td>
172 <td class="sib-statistics-data-value sib-last-column-value"><?php echo (new DateTime($campaign['sentDate']))->format('Y-m-d H:i:s');?></td>
173 </tr>
174 <?php } ?>
175 </tbody>
176 </table>
177 <?php }?>
178 <?php
179 if (!empty($smsCampaigns)) {
180 ?>
181 <table id="ws_statistics_table" class="wc_shipping widefat wp-list-table" cellspacing="0">
182 <thead>
183 <tr>
184 <th class="sort">&nbsp;</th>
185 <th class=""><?php esc_attr_e( 'Name', 'sib_lang' );?></th>
186 <th class=""><?php esc_attr_e('Recipients','sib_lang');?></th>
187 <th class=""><?php esc_attr_e('Deliverability Rate','sib_lang');?></th>
188 <th class=""><?php esc_attr_e('Answeres','sib_lang');?></th>
189 <th class=""><?php esc_attr_e('Unsubscriptions','sib_lang');?></th>
190 <th class=""><?php esc_attr_e('Bounces','sib_lang');?></th>
191 <th class=""><?php esc_attr_e('Date','sib_lang');?></th>
192 </tr>
193 </thead>
194 <tbody class="ui-sortable">
195
196 <div>
197 <h3 class="title"><?php esc_attr_e( 'SMS Campaigns', 'sib_lang' );?></h3>
198 </div>
199 <?php
200 foreach($smsCampaigns as $smsCampaign){ ?>
201 <tr id="<?php echo str_replace(' ', '-', $smsCampaign['name']);?>">
202 <td width="1%" class="sort ui-sortable-handle">
203 <input type="hidden" name="method_order[flat_rate]" value="">
204 </td>
205 <td class=""><?php echo $smsCampaign['name'];?></td>
206 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['sent'];?></td>
207 <td class="sib-statistics-data-value"><?php echo empty($smsCampaign['statistics']['sent']) ? 0 : round($smsCampaign['statistics']['delivered'] * 100 / $smsCampaign['statistics']['sent'], 2);?>%</td>
208 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['answered'];?></td>
209 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['unsubscriptions'];?></td>
210 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['softBounces'] + $campaign['statistics']['hardBounces'];?></td>
211 <td class="sib-statistics-data-value sib-last-column-value"><?php echo (new DateTime($smsCampaign['sentDate']))->format('Y-m-d H:i:s');?></td>
212 </tr>
213 <?php } ?>
214 </tbody>
215 </table>
216 <?php }
217 }
218
219 /** Generate welcome page */
220 function generate_welcome_page() {
221 ?>
222 <img src="<?php echo esc_url( SIB_Manager::$plugin_url . '/img/background/statistics.png' ); ?>" style="width: 100%;">
223 <?php
224 SIB_Page_Home::print_disable_popup();
225 }
226
227 function get_selected_statistics_dates() {
228 $startDate = (new DateTime())->format(self::START_DATE_FORMAT);
229 $endDate = (new DateTime())->format(self::END_DATE_FORMAT_NOW);
230
231 if (empty($_POST['sib-statistics-date'])) {
232 $statisticsDate = date('Y-m-d');
233 } else {
234 $statisticsDate = sanitize_text_field($_POST['sib-statistics-date']);
235 $date = explode(' - ', $statisticsDate);
236
237 if (count($date) === 1) {
238 $date[] = $date[0];
239 }
240
241 $startDate = (new DateTime($date[0]));
242 $endDate = (new DateTime($date[1]));
243 if ($date[0] >= date('Y-m-d') || $date[1] >= date('Y-m-d')) {
244 $startDate = $startDate->format(self::START_DATE_FORMAT);
245 $endDate = (new DateTime())->format(self::END_DATE_FORMAT_NOW);
246 } elseif ($date[0] === $date[1]) {
247 $startDate = $startDate->format(self::START_DATE_FORMAT);
248 $endDate = $endDate->format(self::END_DATE_FORMAT);
249 } else {
250 $startDate = $startDate->format(self::START_DATE_FORMAT);
251 $endDate = $endDate->format(self::END_DATE_FORMAT);
252 }
253 }
254
255 return [
256 'statisticsDate' => $statisticsDate,
257 'startDate' => $startDate,
258 'endDate' => $endDate,
259 ];
260 }
261 }
262 }
263