PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.24.1
Independent Analytics – WordPress Analytics Plugin v1.24.1
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Independent_Analytics.php
independent-analytics / IAWP Last commit date
AJAX 3 years ago Date_Range 3 years ago Interval 3 years ago Menu_Bar_Stats 3 years ago Migrations 3 years ago Models 3 years ago Queries 3 years ago Statistics 3 years ago Tables 3 years ago Utils 3 years ago Campaign_Builder.php 3 years ago Capability_Manager.php 3 years ago Chart.php 3 years ago Chart_Geo.php 3 years ago Chart_SVG.php 3 years ago Dashboard_Options.php 3 years ago Dashboard_Widget.php 3 years ago Email_Reports.php 3 years ago Filters.php 3 years ago Geo_Database.php 3 years ago Geo_Database_Download_Job.php 3 years ago Health_Check.php 3 years ago Illuminate_Builder.php 3 years ago Independent_Analytics.php 3 years ago Known_Referrers.php 3 years ago PDF.php 3 years ago Query.php 3 years ago Quick_Stats.php 3 years ago REST_API.php 3 years ago Real_Time.php 3 years ago Reset_Database.php 3 years ago Resource_Identifier.php 3 years ago Settings.php 3 years ago Track_Resource_Changes.php 3 years ago View.php 3 years ago View_Counter.php 3 years ago WP_Option_Cache_Bust.php 3 years ago WooCommerce_Order.php 3 years ago
Independent_Analytics.php
604 lines
1 <?php
2
3 namespace IAWP_SCOPED\IAWP;
4
5 use IAWP_SCOPED\IAWP\AJAX\Cleared_Cache_AJAX;
6 use IAWP_SCOPED\IAWP\AJAX\Create_Campaign_AJAX;
7 use IAWP_SCOPED\IAWP\AJAX\Delete_Data_AJAX;
8 use IAWP_SCOPED\IAWP\AJAX\Export_Campaigns_AJAX;
9 use IAWP_SCOPED\IAWP\AJAX\Export_Geo_AJAX;
10 use IAWP_SCOPED\IAWP\AJAX\Export_Referrers_AJAX;
11 use IAWP_SCOPED\IAWP\AJAX\Export_Views_AJAX;
12 use IAWP_SCOPED\IAWP\AJAX\Filters_AJAX;
13 use IAWP_SCOPED\IAWP\AJAX\Migration_Status_AJAX;
14 use IAWP_SCOPED\IAWP\AJAX\Real_Time_AJAX;
15 use IAWP_SCOPED\IAWP\AJAX\Test_Email_AJAX;
16 use IAWP_SCOPED\IAWP\AJAX\Update_Capabilities_AJAX;
17 use IAWP_SCOPED\IAWP\Menu_Bar_Stats\Menu_Bar_Stats;
18 use IAWP_SCOPED\IAWP\Queries\Country_Statistics;
19 use IAWP_SCOPED\IAWP\Statistics\Campaign_Statistics;
20 use IAWP_SCOPED\IAWP\Statistics\Geo_Statistics;
21 use IAWP_SCOPED\IAWP\Statistics\Page_Statistics;
22 use IAWP_SCOPED\IAWP\Statistics\Referrer_Statistics;
23 use IAWP_SCOPED\IAWP\Tables\Table_Campaigns;
24 use IAWP_SCOPED\IAWP\Tables\Table_Geo;
25 use IAWP_SCOPED\IAWP\Tables\Table_Pages;
26 use IAWP_SCOPED\IAWP\Tables\Table_Referrers;
27 use IAWP_SCOPED\IAWP\Utils\Security;
28 use IAWP_SCOPED\IAWP\Utils\Singleton;
29 class Independent_Analytics
30 {
31 use Singleton;
32 public $settings;
33 public $email_reports;
34 // This is where we attach functions to WP hooks
35 private function __construct()
36 {
37 $this->settings = new Settings();
38 new REST_API();
39 new Dashboard_Widget();
40 new View_Counter();
41 new Delete_Data_AJAX();
42 new Filters_AJAX();
43 new Export_Geo_AJAX();
44 new Export_Referrers_AJAX();
45 new Export_Views_AJAX();
46 new Migration_Status_AJAX();
47 new Update_Capabilities_AJAX();
48 new Cleared_Cache_AJAX();
49 new Track_Resource_Changes();
50 Menu_Bar_Stats::register();
51 WooCommerce_Order::initialize_order_tracker();
52 if (\IAWP_SCOPED\iawp_is_pro()) {
53 $this->email_reports = new Email_Reports();
54 new Export_Campaigns_AJAX();
55 new Create_Campaign_AJAX();
56 new Campaign_Builder();
57 new Real_Time_AJAX();
58 new Test_Email_AJAX();
59 }
60 \add_filter('admin_body_class', function ($classes) {
61 if (\get_option('iawp_dark_mode')) {
62 $classes .= ' iawp-dark-mode ';
63 }
64 return $classes;
65 });
66 \add_action('admin_menu', [$this, 'add_settings_page']);
67 \add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']);
68 \add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']);
69 \add_filter('plugin_action_links_independent-analytics/iawp.php', [$this, 'plugin_action_links']);
70 \add_filter('admin_footer_text', [$this, 'ip_db_attribution'], 1, 1);
71 \add_filter('admin_head', [$this, 'style_premium_menu_item']);
72 \add_action('init', [$this, 'polylang_translations']);
73 IAWP_FS()->add_filter('connect_message_on_update', [$this, 'filter_connect_message_on_update'], 10, 6);
74 IAWP_FS()->add_filter('connect_message', [$this, 'filter_connect_message_on_update'], 10, 6);
75 IAWP_FS()->add_filter('is_submenu_visible', [$this, 'hide_freemius_sub_menus'], 10, 2);
76 IAWP_FS()->add_filter('pricing_url', [$this, 'change_freemius_pricing_url'], 10);
77 IAWP_FS()->add_filter('show_deactivation_feedback_form', function () {
78 return \false;
79 });
80 }
81 public function polylang_translations()
82 {
83 if (\function_exists('IAWP_SCOPED\\pll_register_string')) {
84 pll_register_string('view_counter', 'Views:', 'Independent Analytics');
85 }
86 }
87 // Settings page where the analytics will appear
88 public function add_settings_page()
89 {
90 \add_menu_page('Independent Analytics', \esc_html__('Analytics', 'independent-analytics'), Capability_Manager::can_view_string(), 'independent-analytics', [$this, 'settings_page_markup'], 'dashicons-analytics', 3);
91 if (!Capability_Manager::white_labeled()) {
92 \add_submenu_page('independent-analytics', \esc_html__('Feedback', 'independent-analytics'), \esc_html__('Feedback', 'independent-analytics'), Capability_Manager::can_view_string(), \esc_url('https://feedback.independentwp.com/boards/feature-requests'));
93 }
94 if (\IAWP_SCOPED\iawp_is_free() && !Capability_Manager::white_labeled()) {
95 \add_submenu_page('independent-analytics', \esc_html__('Upgrade to Pro &rarr;', 'independent-analytics'), \esc_html__('Upgrade to Pro &rarr;', 'independent-analytics'), Capability_Manager::can_view_string(), \esc_url('https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Sidebar'));
96 }
97 }
98 public function hide_freemius_sub_menus($is_visible, $menu_id)
99 {
100 if ('pricing' == $menu_id) {
101 return \false;
102 } elseif ('support' == $menu_id && Capability_Manager::white_labeled()) {
103 return \false;
104 } else {
105 return \true;
106 }
107 }
108 public function change_freemius_pricing_url()
109 {
110 return 'https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Account';
111 }
112 // The submenu item needs to be styled on all admin pages, and we only load stylesheets on our page
113 public function style_premium_menu_item()
114 {
115 if (\IAWP_SCOPED\iawp_is_free()) {
116 echo '<style>#toplevel_page_independent-analytics .wp-submenu li:nth-child(4) a { color: #F69D0A; }</style>';
117 }
118 }
119 private function get_current_tab()
120 {
121 if (\IAWP_SCOPED\iawp_is_pro()) {
122 $valid_tabs = ['views', 'referrers', 'geo', 'campaigns', 'campaign-builder', 'real-time', 'settings', 'learn'];
123 } else {
124 $valid_tabs = ['views', 'referrers', 'geo', 'settings', 'learn'];
125 }
126 $default_tab = $valid_tabs[0];
127 $tab = \array_key_exists('tab', $_GET) ? \sanitize_text_field($_GET['tab']) : \false;
128 $is_valid = \array_search($tab, $valid_tabs) != \false;
129 if (!$tab || !$is_valid) {
130 $tab = $default_tab;
131 }
132 return $tab;
133 }
134 public function settings_page_markup()
135 {
136 if (!Capability_Manager::can_view()) {
137 return;
138 }
139 // ray(Migrations\Migration::has_newer_database_version());
140 if (Migrations\Migration::has_newer_database_version()) {
141 ?>
142 <div id="iawp-parent" class="iawp-parent">
143 <?php
144 echo \IAWP_SCOPED\iawp()->templates()->render('layout/header', ['show_review' => \false]);
145 ?>
146 <?php
147 echo \IAWP_SCOPED\iawp()->templates()->render('newer_database');
148 ?>
149 </div>
150 <?php
151 return;
152 } elseif (Migrations\Migration::is_migrating()) {
153 ?>
154 <div id="iawp-parent" class="iawp-parent">
155 <?php
156 echo \IAWP_SCOPED\iawp()->templates()->render('layout/header', ['show_review' => \false]);
157 ?>
158 <?php
159 echo \IAWP_SCOPED\iawp()->templates()->render('migration_running');
160 ?>
161 </div>
162 <?php
163 return;
164 }
165 $tab = $this->get_current_tab();
166 ?>
167 <div id="iawp-parent" class="iawp-parent">
168 <?php
169 if (!Capability_Manager::white_labeled()) {
170 echo \IAWP_SCOPED\iawp()->templates()->render('layout/header');
171 }
172 ?>
173 <nav class="nav">
174 <ul class="menu">
175 <li class="menu-item">
176 <a href="?page=independent-analytics"
177 data-controller="track-date-range"
178 data-test-menu="views"
179 class="menu-link link-dark <?php
180 if ($tab === 'views') {
181 ?>active<?php
182 }
183 ?>">
184 <?php
185 \esc_html_e('Pages', 'independent-analytics');
186 ?>
187 </a>
188 </li>
189 <li class="menu-item">
190 <a href="?page=independent-analytics&tab=referrers"
191 data-controller="track-date-range"
192 data-test-menu="referrers"
193 class="menu-link link-dark <?php
194 if ($tab === 'referrers') {
195 ?>active<?php
196 }
197 ?>">
198 <?php
199 \esc_html_e('Referrers', 'independent-analytics');
200 ?>
201 </a>
202 </li>
203 <li class="menu-item">
204 <a href="?page=independent-analytics&tab=geo"
205 data-controller="track-date-range"
206 data-test-menu="geo"
207 class="menu-link link-dark <?php
208 if ($tab === 'geo') {
209 ?>active<?php
210 }
211 ?>">
212 <?php
213 \esc_html_e('Geographic', 'independent-analytics');
214 ?>
215 </a>
216 </li>
217 <?php
218 if (\IAWP_SCOPED\iawp_is_pro()) {
219 ?>
220 <li class="menu-item">
221 <a href="?page=independent-analytics&tab=campaigns"
222 data-controller="track-date-range"
223 data-test-menu="campaigns"
224 class="menu-link link-dark <?php
225 if ($tab === 'campaigns' || $tab === 'campaign-builder') {
226 ?>active<?php
227 }
228 ?>">
229 <?php
230 \esc_html_e('Campaigns', 'independent-analytics');
231 ?>
232 </a>
233 <div class="sub-menu">
234 <ul>
235 <li class="menu-item">
236 <a href="?page=independent-analytics&tab=campaign-builder"
237 class="menu-link link-dark">
238 <?php
239 \esc_html_e('Campaign Builder', 'independent-analytics');
240 ?>
241 </a>
242 </li>
243 </ul>
244 </div>
245 </li>
246 <li class="menu-item">
247 <a href="?page=independent-analytics&tab=real-time"
248 data-test-menu="real-time"
249 class="menu-link link-dark <?php
250 if ($tab === 'real-time') {
251 ?>active<?php
252 }
253 ?>">
254 <?php
255 \esc_html_e('Real-time', 'independent-analytics');
256 ?>
257 </a>
258 </li>
259 <?php
260 }
261 ?>
262 <?php
263 if (Capability_Manager::can_edit()) {
264 ?>
265 <li class="menu-item">
266 <a href="?page=independent-analytics&tab=settings"
267 data-test-menu="settings"
268 class="menu-link link-dark <?php
269 if ($tab === 'settings') {
270 ?>active<?php
271 }
272 ?>">
273 <?php
274 \esc_html_e('Settings', 'independent-analytics');
275 ?>
276 </a>
277 </li>
278 <?php
279 }
280 ?>
281 <?php
282 if (!Capability_Manager::white_labeled()) {
283 ?>
284 <li class="menu-item">
285 <a href="?page=independent-analytics&tab=learn"
286 data-test-menu="learn"
287 class="menu-link link-dark <?php
288 if ($tab === 'learn') {
289 ?>active<?php
290 }
291 ?>">
292 <?php
293 \esc_html_e('Learn', 'independent-analytics');
294 ?>
295 </a>
296 </li>
297 <?php
298 }
299 ?>
300 <?php
301 if (!Capability_Manager::white_labeled() && \IAWP_SCOPED\iawp_is_free()) {
302 ?>
303 <li class="menu-item upgrade first" data-controller="modal">
304 <a href="#"
305 data-test-menu="campaigns"
306 data-action="modal#toggleModal"
307 data-modal-target="modalButton"
308 class="menu-link link-dark">
309 <?php
310 \esc_html_e('Campaigns', 'independent-analytics');
311 ?>
312 </a>
313 <div class="upgrade-popup"
314 data-modal-target="modal"
315 >
316 <div class="title">
317 <span class="name"><?php
318 \esc_html_e('Campaigns', 'independent-analytics');
319 ?></span>
320 <span class="iawp-label"><?php
321 \esc_html_e('PRO', 'independent-analytics');
322 ?></span>
323 </div>
324 <div class="description">
325 <p><?php
326 \esc_html_e("Campaigns let you track visits from individual links you share online, whether that's a Tweet, ad, or guest post.", 'independent-analytics');
327 ?></p>
328 <a class="iawp-button purple" target="_blank"
329 href="https://independentwp.com/features/campaigns/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Campaigns+menu+item&utm_content=Menu+item"><?php
330 \esc_html_e('Upgrade', 'independent-analytics');
331 ?></a>
332 </div>
333 </div>
334 </li>
335 <li class="menu-item upgrade" data-controller="modal">
336 <a href="#"
337 data-test-menu="real-time"
338 data-action="modal#toggleModal"
339 data-modal-target="modalButton"
340 class="menu-link link-dark">
341 <?php
342 \esc_html_e('Real-time', 'independent-analytics');
343 ?>
344 </a>
345 <div class="upgrade-popup"
346 data-modal-target="modal"
347 >
348 <div class="title">
349 <span class="name"><?php
350 \esc_html_e('Real-time analytics', 'independent-analytics');
351 ?></span>
352 <span class="iawp-label"><?php
353 \esc_html_e('PRO', 'independent-analytics');
354 ?></span>
355 </div>
356 <div class="description">
357 <p><?php
358 \esc_html_e("Real-time analytics let you see how many people are on your site right now, what pages they're viewing, and where they came from.", 'independent-analytics');
359 ?></p>
360 <a class="iawp-button purple" target="_blank"
361 href="https://independentwp.com/features/real-time/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Real-time+menu+item&utm_content=Menu+item"><?php
362 \esc_html_e('Upgrade', 'independent-analytics');
363 ?></a>
364 </div>
365 </div>
366 </li>
367 <?php
368 }
369 ?>
370 </ul>
371 </nav>
372 <div class="iawp-tab-content"><?php
373 $options = new Dashboard_Options();
374 $date_rage = $options->get_date_range();
375 $date_label = $date_rage->label();
376 $columns = $options->columns();
377 if ($tab == 'views') {
378 $table = new Table_Pages($columns);
379 $statistics = new Page_Statistics($date_rage);
380 $stats = new Quick_Stats($statistics, null);
381 $chart = new Chart($statistics, $date_label);
382 $this->interface($table, $stats, $chart);
383 } elseif ($tab == 'referrers') {
384 $table = new Table_Referrers($columns);
385 $statistics = new Referrer_Statistics($date_rage);
386 $stats = new Quick_Stats($statistics, null);
387 $chart = new Chart($statistics, $date_label);
388 $this->interface($table, $stats, $chart);
389 } elseif ($tab == 'geo') {
390 $table = new Table_Geo($columns);
391 $statistics = new Geo_Statistics($date_rage);
392 $stats = new Quick_Stats($statistics, null);
393 $country_statistics = new Country_Statistics($date_rage);
394 $chart = new Chart_Geo($country_statistics->fetch(), $date_label);
395 $this->interface($table, $stats, $chart);
396 } elseif ($tab === 'campaigns') {
397 $table = new Table_Campaigns($columns);
398 $statistics = new Campaign_Statistics($date_rage);
399 $stats = new Quick_Stats($statistics, null);
400 $chart = new Chart($statistics, $date_label);
401 $this->interface($table, $stats, $chart);
402 } elseif ($tab == 'campaign-builder') {
403 (new Campaign_Builder())->render_campaign_builder();
404 } elseif ($tab === 'real-time') {
405 (new Real_Time())->render_real_time_analytics();
406 } elseif ($tab == 'settings') {
407 echo '<div id="iawp-dashboard" class="iawp-dashboard">';
408 if (Capability_Manager::can_edit()) {
409 $this->settings->render_settings();
410 } else {
411 echo '<p class="permission-blocked">' . \esc_html__('You do not have permission to edit the settings.', 'independent-analytics') . '</p>';
412 }
413 echo '</div>';
414 } elseif ($tab == 'learn') {
415 echo '<div id="iawp-dashboard" class="iawp-dashboard">';
416 echo \IAWP_SCOPED\iawp()->templates()->render('learn/index');
417 echo '</div>';
418 }
419 ?>
420 </div>
421 <div id="loading-icon" class="loading-icon"><img
422 src="<?php
423 echo \esc_url(\IAWP_SCOPED\iawp_url_to('img/loading.svg'));
424 ?>"/>
425 </div>
426 <button id="scroll-to-top" class="scroll-to-top"><span
427 class="dashicons dashicons-arrow-up-alt"></span>
428 </button>
429 </div>
430 <?php
431 }
432 public function interface($table, $stats, $chart)
433 {
434 $opts = new Dashboard_Options();
435 ?>
436 <div id="iawp-dashboard"
437 class="iawp-dashboard"
438 data-controller="report"
439 data-report-relative-range-id-value="<?php
440 echo Security::attr($opts->relative_range_id());
441 ?>"
442 data-report-exact-start-value="<?php
443 echo Security::attr($opts->start());
444 ?>"
445 data-report-exact-end-value="<?php
446 echo Security::attr($opts->end());
447 ?>"
448 data-report-columns-value="<?php
449 \esc_attr_e(Security::json_encode($table->visible_column_ids()));
450 ?>"
451 >
452 <?php
453 $table->output_toolbar();
454 ?>
455 <?php
456 echo $stats->get_html();
457 ?>
458 <?php
459 echo $chart->get_html();
460 ?>
461 <?php
462 echo $table->get_table_markup();
463 ?>
464 </div>
465 <div class="iawp-notices"><?php
466 $health_check = new Health_Check();
467 if (!$health_check->healthy()) {
468 echo \IAWP_SCOPED\iawp()->templates()->render('settings/notice', ['notice_text' => $health_check->error(), 'button_text' => \false, 'notice' => 'iawp-error', 'url' => 'https://independentwp.com/knowledgebase/common-questions/views-not-recording/']);
469 }
470 if (\get_option('iawp_need_clear_cache')) {
471 echo \IAWP_SCOPED\iawp()->templates()->render('settings/notice', ['notice_text' => \__('Please clear your cache to ensure tracking works properly.', 'independent-analytics'), 'button_text' => \__('I\'ve cleared the cache', 'independent-analytics'), 'notice' => 'iawp-warning', 'url' => 'https://independentwp.com/knowledgebase/common-questions/views-not-recording/']);
472 }
473 ?>
474 </div><?php
475 }
476 public function enqueue_admin_scripts($hook)
477 {
478 if ($hook == 'toplevel_page_independent-analytics') {
479 $this->enqueue_translations();
480 $tab = $this->get_current_tab();
481 \wp_register_style('iawp-style', \IAWP_SCOPED\iawp_url_to('dist/styles/style.css'), [], \IAWP_VERSION);
482 \wp_enqueue_style('iawp-style');
483 \wp_register_script('iawp-js', \IAWP_SCOPED\iawp_url_to('dist/js/index.js'), [], \IAWP_VERSION);
484 \wp_enqueue_script('iawp-js');
485 \wp_add_inline_script('iawp-js', 'const IAWP_DELETE_DATA_NONCE = ' . \json_encode(\wp_create_nonce('iawp_delete_data')), 'before');
486 if ($tab === 'views' || $tab === 'referrers' || $tab === 'geo' || $tab === 'campaigns' || $tab === 'campaign-builder') {
487 \wp_register_script('iawp-data-table', \IAWP_SCOPED\iawp_url_to('dist/js/data-table.js'), [], \IAWP_VERSION);
488 \wp_enqueue_script('iawp-data-table');
489 \wp_add_inline_script('iawp-data-table', 'const IAWP_AJAX = ' . \json_encode(['filter_nonce' => \wp_create_nonce('iawp_filter'), 'create_campaign_nonce' => \wp_create_nonce('iawp_create_campaign'), 'copied_text' => \esc_html__('Copied!', 'independent-analytics'), 'iawp_need_clear_cache_nonce' => \wp_create_nonce('iawp_need_clear_cache')]), 'before');
490 } elseif ($tab == 'settings') {
491 \wp_register_script('iawp-settings', \IAWP_SCOPED\iawp_url_to('dist/js/settings.js'), [], \IAWP_VERSION);
492 \wp_enqueue_script('iawp-settings');
493 \wp_add_inline_script('iawp-settings', 'const IAWP_AJAX = ' . \json_encode(['export_views_nonce' => \wp_create_nonce('iawp_export_views'), 'export_referrers_nonce' => \wp_create_nonce('iawp_export_referrers'), 'export_geo_nonce' => \wp_create_nonce('iawp_export_geo'), 'export_campaigns_nonce' => \wp_create_nonce('iawp_export_campaigns'), 'iawp_capabilities_nonce' => \wp_create_nonce('iawp_capabilities'), 'iawp_test_email_nonce' => \wp_create_nonce('iawp_test_email'), 'exporting_views_text' => \esc_html__('Exporting Pages...', 'independent-analytics'), 'export_views_text' => \esc_html__('Export Pages', 'independent-analytics'), 'exporting_referrers_text' => \esc_html__('Exporting Referrers...', 'independent-analytics'), 'export_referrers_text' => \esc_html__('Export Referrers', 'independent-analytics'), 'exporting_geo_text' => \esc_html__('Exporting Geolocations...', 'independent-analytics'), 'export_geo_text' => \esc_html__('Export Geolocations', 'independent-analytics'), 'exporting_campaigns_text' => \esc_html__('Exporting Campaigns...', 'independent-analytics'), 'export_campaigns_text' => \esc_html__('Export Campaigns', 'independent-analytics')]), 'before');
494 } elseif ($tab == 'learn') {
495 \wp_register_script('iawp-learn', \IAWP_SCOPED\iawp_url_to('dist/js/learn.js'), [], \IAWP_VERSION);
496 \wp_enqueue_script('iawp-learn');
497 }
498 } elseif ($hook == 'index.php') {
499 $this->enqueue_translations();
500 \wp_register_script('iawp-dashboard-widget', \IAWP_SCOPED\iawp_url_to('dist/js/dashboard_widget.js'), [], \IAWP_VERSION);
501 \wp_enqueue_script('iawp-dashboard-widget');
502 \wp_register_style('iawp-dashboard-widget-css', \IAWP_SCOPED\iawp_url_to('dist/styles/dashboard_widget.css'), [], \IAWP_VERSION);
503 \wp_enqueue_style('iawp-dashboard-widget-css');
504 }
505 $this->maybe_enqueue_menu_bar_stats_styles();
506 }
507 public function enqueue_scripts($hook)
508 {
509 $this->enqueue_translations();
510 $this->maybe_enqueue_menu_bar_stats_styles();
511 }
512 public function enqueue_translations()
513 {
514 \wp_register_script('iawp-translations', '');
515 \wp_enqueue_script('iawp-translations');
516 \wp_add_inline_script('iawp-translations', 'const iawpText = ' . \json_encode(['visitors' => \__('Visitors', 'independent-analytics'), 'views' => \__('Views', 'independent-analytics'), 'sessions' => \__('Sessions', 'independent-analytics'), 'orders' => \__('Orders', 'independent-analytics'), 'netSales' => \__('Net Sales', 'independent-analytics'), 'country' => \__('country', 'independent-analytics'), 'exactDates' => \__('Apply Exact Dates', 'independent-analytics'), 'relativeDates' => \__('Apply Relative Dates', 'independent-analytics')]), 'before');
517 }
518 public function maybe_enqueue_menu_bar_stats_styles()
519 {
520 $menu_bar_stats = new Menu_Bar_Stats();
521 if ($menu_bar_stats->is_enabled()) {
522 \wp_register_style('iawp-front-end-css', \IAWP_SCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION);
523 \wp_enqueue_style('iawp-front-end-css');
524 }
525 }
526 /* WP uses $default when get_option() is empty, but it also saves empty fields
527 ** as empty strings, meaning the return value can be "" instead of the default. This is
528 ** a defensive function that guarantees we get the proper default when the setting is empty. */
529 public function get_option($name, $default)
530 {
531 $option = \get_option($name, $default);
532 return $option === '' ? $default : $option;
533 }
534 public function templates()
535 {
536 return new \IAWP_SCOPED\League\Plates\Engine(\IAWP_SCOPED\iawp_path_to('templates'));
537 }
538 public function get_users_can_write()
539 {
540 $roles = [];
541 foreach (\wp_roles()->roles as $role_name => $role_obj) {
542 if (!empty($role_obj['capabilities']['edit_posts'])) {
543 $roles[] = $role_name;
544 }
545 }
546 $users = \get_users(['role__in' => $roles]);
547 return $users;
548 }
549 public function get_custom_types(bool $tax = \false)
550 {
551 $args = ['public' => \true, '_builtin' => \false];
552 if ($tax) {
553 return \get_taxonomies($args);
554 } else {
555 return \get_post_types($args);
556 }
557 }
558 public function filter_connect_message_on_update($message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link)
559 {
560 // Add the heading HTML.
561 $plugin_name = 'Independent Analytics';
562 $title = '<h3>' . \sprintf(\esc_html__('We hope you love %1$s', 'independent-analytics'), $plugin_name) . '</h3>';
563 $html = '';
564 // Add the introduction HTML.
565 $html .= '<p>';
566 $html .= \sprintf(\esc_html__('Hi, %1$s! This is an invitation to help the %2$s community.', 'independent-analytics'), $user_first_name, $plugin_name);
567 $html .= '<strong>';
568 $html .= \sprintf(\esc_html__('If you opt-in, some data about your usage of %2$s will be shared with us', 'independent-analytics'), $user_first_name, $plugin_name);
569 $html .= '</strong>';
570 $html .= \sprintf(\esc_html__(' so we can improve %2$s. We will also share some helpful info on using the plugin so you can get the most out of your sites analytics.', 'independent-analytics'), $user_first_name, $plugin_name);
571 $html .= '</p>';
572 $html .= '<p>';
573 $html .= \sprintf(\esc_html__('And if you skip this, that\'s okay! %1$s will still work just fine.', 'independent-analytics'), $plugin_name);
574 $html .= '</p>';
575 return $title . $html;
576 }
577 public function plugin_action_links($links)
578 {
579 // Create the link
580 $settings_link = '<a class="calendar-link" href="' . \esc_url(\IAWP_SCOPED\iawp_dashboard_url()) . '">' . \esc_html__('Analytics Dashboard', 'independent-analytics') . '</a>';
581 // Add the link to the start of the array
582 \array_unshift($links, $settings_link);
583 return $links;
584 }
585 public function set_time_limit($limit = 0)
586 {
587 if (!\function_exists('set_time_limit') && \false !== \strpos(\ini_get('disable_functions'), 'set_time_limit') && \ini_get('safe_mode')) {
588 return \false;
589 }
590 return @\set_time_limit($limit);
591 }
592 public function ip_db_attribution($text)
593 {
594 if ($this->get_current_tab() === 'geo') {
595 $text = $text . ' ' . \esc_html_x('Geolocation data powered by', 'Following text is a noun: DB-IP', 'independent-analytics') . ' ' . '<a href="https://db-ip.com" class="geo-message" target="_blank">DB-IP</a>.';
596 }
597 return $text;
598 }
599 public function pagination_page_size()
600 {
601 return 50;
602 }
603 }
604