PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.0.1
Brevo – Email, SMS, Web Push, Chat, and more. v3.0.1
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
261 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 }
78
79 /** Generate page script */
80 function generate() {
81 ?>
82 <div id="wrap1" class="box-border-box container-fluid">
83 <div id="main-content" class="row">
84 <?php
85 if ( SIB_Manager::is_done_validation() ) {
86 $this->generate_main_page();
87 } else {
88 $this->generate_welcome_page();
89 }
90 ?>
91 </div>
92 </div>
93 <style>
94 #wpcontent {
95 margin-left: 160px !important;
96 }
97
98 @media only screen and (max-width: 918px) {
99 #wpcontent {
100 margin-left: 40px !important;
101 }
102 }
103 </style>
104 <?php
105 }
106
107 /** Generate main page */
108 function generate_main_page() {
109 $client = new SendinblueApiClient();
110
111 $date = $this->get_selected_statistics_dates();
112 $data = [
113 'type' => 'classic',
114 'status' => 'sent',
115 'startDate' => $date['startDate'],
116 'endDate' => $date['endDate'],
117 'offset' => 0,
118 ];
119
120 $emailCampaigns = $client->getAllCampaignsByType(SendinblueApiClient::CAMPAIGN_TYPE_EMAIL, $data);
121 $smsCampaigns = $client->getAllCampaignsByType(SendinblueApiClient::CAMPAIGN_TYPE_SMS, $data);
122 /**
123 * Statistics on general options
124 */
125 ?>
126 <h3><?php _e('Statistics', 'wc_sendinblue'); ?></h3>
127 <div id="sib-statistics-date-container">
128 <form method="POST" id="sib-statistics-form">
129 <label for="sib-statistics-date"><?php esc_attr_e( 'Date', 'sib_lang' );?>: </label>
130 <input id="sib-statistics-date" name="sib-statistics-date" value="<?php echo $date['statisticsDate']; ?>" autocomplete="off" class="button show-settings">
131 <button id="apply-date-range" class="button action"><?php esc_attr_e( 'Apply', 'sib_lang'); ?></button>
132 <span class="sib-spinner spinner"></span>
133 </form>
134 </div>
135 <?php
136 if (!empty($emailCampaigns)) {
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 foreach($emailCampaigns as $campaign){ ?>
159 <tr id="<?php echo str_replace(' ', '-', $campaign['name']);?>">
160 <td width="1%" class="sort ui-sortable-handle">
161 <input type="hidden" name="method_order[flat_rate]" value="">
162 </td>
163 <td class=""><?php echo $campaign['name'];?></td>
164 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['sent'];?></td>
165 <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>
166 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['viewed'];?></td>
167 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['clickers'];?></td>
168 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['unsubscriptions'];?></td>
169 <td class="sib-statistics-data-value"><?php echo $campaign['statistics']['globalStats']['softBounces'] + $campaign['statistics']['globalStats']['hardBounces'];?></td>
170 <td class="sib-statistics-data-value sib-last-column-value"><?php echo (new DateTime($campaign['sentDate']))->format('Y-m-d H:i:s');?></td>
171 </tr>
172 <?php } ?>
173 </tbody>
174 </table>
175 <?php }?>
176 <?php
177 if (!empty($smsCampaigns)) {
178 ?>
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 foreach($smsCampaigns as $smsCampaign){ ?>
199 <tr id="<?php echo str_replace(' ', '-', $smsCampaign['name']);?>">
200 <td width="1%" class="sort ui-sortable-handle">
201 <input type="hidden" name="method_order[flat_rate]" value="">
202 </td>
203 <td class=""><?php echo $smsCampaign['name'];?></td>
204 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['sent'];?></td>
205 <td class="sib-statistics-data-value"><?php echo empty($smsCampaign['statistics']['sent']) ? 0 : round($smsCampaign['statistics']['delivered'] * 100 / $smsCampaign['statistics']['sent'], 2);?>%</td>
206 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['answered'];?></td>
207 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['unsubscriptions'];?></td>
208 <td class="sib-statistics-data-value"><?php echo $smsCampaign['statistics']['softBounces'] + $campaign['statistics']['hardBounces'];?></td>
209 <td class="sib-statistics-data-value sib-last-column-value"><?php echo (new DateTime($smsCampaign['sentDate']))->format('Y-m-d H:i:s');?></td>
210 </tr>
211 <?php } ?>
212 </tbody>
213 </table>
214 <?php }
215 }
216
217 /** Generate welcome page */
218 function generate_welcome_page() {
219 ?>
220 <img src="<?php echo esc_url( SIB_Manager::$plugin_url . '/img/background/statistics.png' ); ?>" style="width: 100%;">
221 <?php
222 SIB_Page_Home::print_disable_popup();
223 }
224
225 function get_selected_statistics_dates() {
226 $startDate = (new DateTime())->format(self::START_DATE_FORMAT);
227 $endDate = (new DateTime())->format(self::END_DATE_FORMAT_NOW);
228
229 if (empty($_POST['sib-statistics-date'])) {
230 $statisticsDate = date('Y-m-d');
231 } else {
232 $statisticsDate = sanitize_text_field($_POST['sib-statistics-date']);
233 $date = explode(' - ', $statisticsDate);
234
235 if (count($date) === 1) {
236 $date[] = $date[0];
237 }
238
239 $startDate = (new DateTime($date[0]));
240 $endDate = (new DateTime($date[1]));
241 if ($date[0] >= date('Y-m-d') || $date[1] >= date('Y-m-d')) {
242 $startDate = $startDate->format(self::START_DATE_FORMAT);
243 $endDate = (new DateTime())->format(self::END_DATE_FORMAT_NOW);
244 } elseif ($date[0] === $date[1]) {
245 $startDate = $startDate->format(self::START_DATE_FORMAT);
246 $endDate = $endDate->format(self::END_DATE_FORMAT);
247 } else {
248 $startDate = $startDate->format(self::START_DATE_FORMAT);
249 $endDate = $endDate->format(self::END_DATE_FORMAT);
250 }
251 }
252
253 return [
254 'statisticsDate' => $statisticsDate,
255 'startDate' => $startDate,
256 'endDate' => $endDate,
257 ];
258 }
259 }
260 }
261