PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.27.0
Independent Analytics – WordPress Analytics Plugin v1.27.0
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 City_To_Country_Converter.php 3 years ago Dashboard_Options.php 3 years ago Dashboard_Widget.php 3 years ago Email_Chart.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 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 Sort_Configuration.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_Pages_AJAX;
11 use IAWP_SCOPED\IAWP\AJAX\Export_Referrers_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\Cities;
19 use IAWP_SCOPED\IAWP\Queries\Countries;
20 use IAWP_SCOPED\IAWP\Statistics\Campaign_Statistics;
21 use IAWP_SCOPED\IAWP\Statistics\Geo_Statistics;
22 use IAWP_SCOPED\IAWP\Statistics\Page_Statistics;
23 use IAWP_SCOPED\IAWP\Statistics\Referrer_Statistics;
24 use IAWP_SCOPED\IAWP\Tables\Table;
25 use IAWP_SCOPED\IAWP\Tables\Table_Campaigns;
26 use IAWP_SCOPED\IAWP\Tables\Table_Geo;
27 use IAWP_SCOPED\IAWP\Tables\Table_Pages;
28 use IAWP_SCOPED\IAWP\Tables\Table_Referrers;
29 use IAWP_SCOPED\IAWP\Utils\Security;
30 use IAWP_SCOPED\IAWP\Utils\Singleton;
31 class Independent_Analytics
32 {
33 use Singleton;
34 public $settings;
35 public $email_reports;
36 // This is where we attach functions to WP hooks
37 private function __construct()
38 {
39 $this->settings = new Settings();
40 new REST_API();
41 new Dashboard_Widget();
42 new View_Counter();
43 new Delete_Data_AJAX();
44 new Filters_AJAX();
45 new Export_Geo_AJAX();
46 new Export_Referrers_AJAX();
47 new Export_Pages_AJAX();
48 new Migration_Status_AJAX();
49 new Update_Capabilities_AJAX();
50 new Cleared_Cache_AJAX();
51 new Track_Resource_Changes();
52 Menu_Bar_Stats::register();
53 WooCommerce_Order::initialize_order_tracker();
54 if (\IAWP_SCOPED\iawp_is_pro()) {
55 $this->email_reports = new Email_Reports();
56 new Export_Campaigns_AJAX();
57 new Create_Campaign_AJAX();
58 new Campaign_Builder();
59 new Real_Time_AJAX();
60 new Test_Email_AJAX();
61 }
62 \add_filter('admin_body_class', function ($classes) {
63 if (\get_option('iawp_dark_mode')) {
64 $classes .= ' iawp-dark-mode ';
65 }
66 return $classes;
67 });
68 \add_action('admin_menu', [$this, 'add_settings_page']);
69 \add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']);
70 \add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']);
71 \add_filter('plugin_action_links_independent-analytics/iawp.php', [$this, 'plugin_action_links']);
72 \add_filter('admin_footer_text', [$this, 'ip_db_attribution'], 1, 1);
73 \add_filter('admin_head', [$this, 'style_premium_menu_item']);
74 \add_action('init', [$this, 'polylang_translations']);
75 IAWP_FS()->add_filter('connect_message_on_update', [$this, 'filter_connect_message_on_update'], 10, 6);
76 IAWP_FS()->add_filter('connect_message', [$this, 'filter_connect_message_on_update'], 10, 6);
77 IAWP_FS()->add_filter('is_submenu_visible', [$this, 'hide_freemius_sub_menus'], 10, 2);
78 IAWP_FS()->add_filter('pricing_url', [$this, 'change_freemius_pricing_url'], 10);
79 IAWP_FS()->add_filter('show_deactivation_feedback_form', function () {
80 return \false;
81 });
82 }
83 public function polylang_translations()
84 {
85 if (\function_exists('IAWP_SCOPED\\pll_register_string')) {
86 pll_register_string('view_counter', 'Views:', 'Independent Analytics');
87 }
88 }
89 // Settings page where the analytics will appear
90 public function add_settings_page()
91 {
92 $title = Capability_Manager::white_labeled() ? \esc_html__('Analytics', 'independent-analytics') : 'Independent Analytics';
93 \add_menu_page($title, \esc_html__('Analytics', 'independent-analytics'), Capability_Manager::can_view_string(), 'independent-analytics', [$this, 'settings_page_markup'], 'dashicons-analytics', 3);
94 if (!Capability_Manager::white_labeled()) {
95 \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'));
96 }
97 if (\IAWP_SCOPED\iawp_is_free() && !Capability_Manager::white_labeled()) {
98 \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'));
99 }
100 }
101 public function hide_freemius_sub_menus($is_visible, $menu_id)
102 {
103 if ('pricing' == $menu_id) {
104 return \false;
105 } elseif ('support' == $menu_id && Capability_Manager::white_labeled()) {
106 return \false;
107 } else {
108 return \true;
109 }
110 }
111 public function change_freemius_pricing_url()
112 {
113 return 'https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Account';
114 }
115 // The submenu item needs to be styled on all admin pages, and we only load stylesheets on our page
116 public function style_premium_menu_item()
117 {
118 if (\IAWP_SCOPED\iawp_is_free()) {
119 echo '<style>#toplevel_page_independent-analytics .wp-submenu li:nth-child(4) a { color: #F69D0A; }</style>';
120 }
121 }
122 public function settings_page_markup()
123 {
124 if (!Capability_Manager::can_view()) {
125 return;
126 }
127 if (Migrations\Migration::has_newer_database_version()) {
128 ?>
129 <div id="iawp-parent" class="iawp-parent">
130 <?php
131 echo \IAWP_SCOPED\iawp()->templates()->render('layout/header', ['show_review' => \false]);
132 ?>
133 <?php
134 echo \IAWP_SCOPED\iawp()->templates()->render('newer_database');
135 ?>
136 </div>
137 <?php
138 return;
139 } elseif (Migrations\Migration::is_migrating()) {
140 ?>
141 <div id="iawp-parent" class="iawp-parent">
142 <?php
143 echo \IAWP_SCOPED\iawp()->templates()->render('layout/header', ['show_review' => \false]);
144 ?>
145 <?php
146 echo \IAWP_SCOPED\iawp()->templates()->render('migration_running');
147 ?>
148 </div>
149 <?php
150 return;
151 }
152 $tab = $this->get_current_tab();
153 ?>
154 <div id="iawp-parent" class="iawp-parent">
155 <?php
156 if (!Capability_Manager::white_labeled()) {
157 echo \IAWP_SCOPED\iawp()->templates()->render('layout/header');
158 }
159 ?>
160 <nav class="nav">
161 <ul class="menu" data-testid="menu">
162 <li class="menu-item">
163 <a href="?page=independent-analytics"
164 data-controller="track-date-range"
165 data-test-menu="views"
166 class="menu-link link-dark <?php
167 if ($tab === 'views') {
168 ?>active<?php
169 }
170 ?>"><?php
171 \esc_html_e('Pages', 'independent-analytics');
172 ?></a>
173 </li>
174 <li class="menu-item">
175 <a href="?page=independent-analytics&tab=referrers"
176 data-controller="track-date-range"
177 data-test-menu="referrers"
178 class="menu-link link-dark <?php
179 if ($tab === 'referrers') {
180 ?>active<?php
181 }
182 ?>"><?php
183 \esc_html_e('Referrers', 'independent-analytics');
184 ?></a>
185 </li>
186 <li class="menu-item">
187 <a href="?page=independent-analytics&tab=geo"
188 data-controller="track-date-range"
189 data-test-menu="geo"
190 class="menu-link link-dark <?php
191 if ($tab === 'geo') {
192 ?>active<?php
193 }
194 ?>"><?php
195 \esc_html_e('Geographic', 'independent-analytics');
196 ?></a>
197 </li>
198 <?php
199 if (\IAWP_SCOPED\iawp_is_pro()) {
200 ?>
201 <li class="menu-item">
202 <a href="?page=independent-analytics&tab=campaigns"
203 data-controller="track-date-range"
204 data-test-menu="campaigns"
205 class="menu-link link-dark <?php
206 if ($tab === 'campaigns' || $tab === 'campaign-builder') {
207 ?>active<?php
208 }
209 ?>"><?php
210 \esc_html_e('Campaigns', 'independent-analytics');
211 ?></a>
212 <div class="sub-menu">
213 <ul>
214 <li class="menu-item">
215 <a href="?page=independent-analytics&tab=campaign-builder"
216 class="menu-link link-dark"><?php
217 \esc_html_e('Campaign Builder', 'independent-analytics');
218 ?></a>
219 </li>
220 </ul>
221 </div>
222 </li>
223 <li class="menu-item">
224 <a href="?page=independent-analytics&tab=real-time"
225 data-test-menu="real-time"
226 class="menu-link link-dark <?php
227 if ($tab === 'real-time') {
228 ?>active<?php
229 }
230 ?>"><?php
231 \esc_html_e('Real-time', 'independent-analytics');
232 ?></a>
233 </li>
234 <?php
235 }
236 ?>
237 <?php
238 if (Capability_Manager::can_edit()) {
239 ?>
240 <li class="menu-item">
241 <a href="?page=independent-analytics&tab=settings"
242 data-test-menu="settings"
243 class="menu-link link-dark <?php
244 if ($tab === 'settings') {
245 ?>active<?php
246 }
247 ?>"><?php
248 \esc_html_e('Settings', 'independent-analytics');
249 ?></a>
250 </li>
251 <?php
252 }
253 ?>
254 <?php
255 if (!Capability_Manager::white_labeled()) {
256 ?>
257 <li class="menu-item">
258 <a href="?page=independent-analytics&tab=learn"
259 data-test-menu="learn"
260 class="menu-link link-dark <?php
261 if ($tab === 'learn') {
262 ?>active<?php
263 }
264 ?>"><?php
265 \esc_html_e('Learn', 'independent-analytics');
266 ?></a>
267 </li>
268 <?php
269 }
270 ?>
271 <?php
272 if (!Capability_Manager::white_labeled() && \IAWP_SCOPED\iawp_is_free()) {
273 ?>
274 <li class="menu-item upgrade first" data-controller="modal">
275 <a href="#"
276 data-test-menu="campaigns"
277 data-action="modal#toggleModal"
278 data-modal-target="modalButton"
279 class="menu-link link-dark">
280 <?php
281 \esc_html_e('Campaigns', 'independent-analytics');
282 ?>
283 </a>
284 <div class="upgrade-popup"
285 data-modal-target="modal"
286 >
287 <div class="title">
288 <span class="name"><?php
289 \esc_html_e('Campaigns', 'independent-analytics');
290 ?></span>
291 <span class="iawp-label"><?php
292 \esc_html_e('PRO', 'independent-analytics');
293 ?></span>
294 </div>
295 <div class="description">
296 <p><?php
297 \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');
298 ?></p>
299 <a class="iawp-button purple" target="_blank"
300 href="https://independentwp.com/features/campaigns/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Campaigns+menu+item&utm_content=Menu+item"><?php
301 \esc_html_e('Learn more', 'independent-analytics');
302 ?></a>
303 </div>
304 </div>
305 </li>
306 <li class="menu-item upgrade" data-controller="modal">
307 <a href="#"
308 data-test-menu="real-time"
309 data-action="modal#toggleModal"
310 data-modal-target="modalButton"
311 class="menu-link link-dark">
312 <?php
313 \esc_html_e('Real-time', 'independent-analytics');
314 ?>
315 </a>
316 <div class="upgrade-popup"
317 data-modal-target="modal"
318 >
319 <div class="title">
320 <span class="name"><?php
321 \esc_html_e('Real-time analytics', 'independent-analytics');
322 ?></span>
323 <span class="iawp-label"><?php
324 \esc_html_e('PRO', 'independent-analytics');
325 ?></span>
326 </div>
327 <div class="description">
328 <p><?php
329 \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');
330 ?></p>
331 <a class="iawp-button purple" target="_blank"
332 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
333 \esc_html_e('Learn more', 'independent-analytics');
334 ?></a>
335 </div>
336 </div>
337 </li>
338 <?php
339 }
340 ?>
341 </ul>
342 </nav>
343 <div class="iawp-tab-content"><?php
344 $options = new Dashboard_Options();
345 $date_rage = $options->get_date_range();
346 $date_label = $date_rage->label();
347 $columns = $options->columns();
348 if ($tab == 'views') {
349 $table = new Table_Pages($columns);
350 $statistics = new Page_Statistics($date_rage, null, $options->chart_interval());
351 $stats = new Quick_Stats(null, $statistics);
352 $chart = new Chart($statistics, $date_label);
353 $this->interface($table, $stats, $chart);
354 } elseif ($tab == 'referrers') {
355 $table = new Table_Referrers($columns);
356 $statistics = new Referrer_Statistics($date_rage, null, $options->chart_interval());
357 $stats = new Quick_Stats(null, $statistics);
358 $chart = new Chart($statistics, $date_label);
359 $this->interface($table, $stats, $chart);
360 } elseif ($tab == 'geo') {
361 $table = new Table_Geo($columns, $options->group());
362 $statistics = new Geo_Statistics($date_rage);
363 $stats = new Quick_Stats(null, $statistics);
364 $data_class = $options->group() === 'city' ? Cities::class : Countries::class;
365 $country_statistics = new $data_class($date_rage);
366 if ($options->group() === 'city') {
367 $country_rows = City_To_Country_Converter::convert($country_statistics->rows());
368 $chart = new Chart_Geo($country_rows, $date_label);
369 } else {
370 $chart = new Chart_Geo($country_statistics->rows(), $date_label);
371 }
372 $this->interface($table, $stats, $chart);
373 } elseif ($tab === 'campaigns') {
374 $table = new Table_Campaigns($columns);
375 $statistics = new Campaign_Statistics($date_rage, null, $options->chart_interval());
376 $stats = new Quick_Stats(null, $statistics);
377 $chart = new Chart($statistics, $date_label);
378 $this->interface($table, $stats, $chart);
379 } elseif ($tab == 'campaign-builder') {
380 (new Campaign_Builder())->render_campaign_builder();
381 } elseif ($tab === 'real-time') {
382 (new Real_Time())->render_real_time_analytics();
383 } elseif ($tab == 'settings') {
384 echo '<div id="iawp-dashboard" class="iawp-dashboard">';
385 if (Capability_Manager::can_edit()) {
386 $this->settings->render_settings();
387 } else {
388 echo '<p class="permission-blocked">' . \esc_html__('You do not have permission to edit the settings.', 'independent-analytics') . '</p>';
389 }
390 echo '</div>';
391 } elseif ($tab == 'learn') {
392 echo '<div id="iawp-dashboard" class="iawp-dashboard">';
393 echo \IAWP_SCOPED\iawp()->templates()->render('learn/index');
394 echo '</div>';
395 }
396 ?>
397 </div>
398 <div id="loading-icon" class="loading-icon"><img
399 src="<?php
400 echo \esc_url(\IAWP_SCOPED\iawp_url_to('img/loading.svg'));
401 ?>"/>
402 </div>
403 <button id="scroll-to-top" class="scroll-to-top"><span
404 class="dashicons dashicons-arrow-up-alt"></span>
405 </button>
406 </div>
407 <?php
408 }
409 public function templates()
410 {
411 return new \IAWP_SCOPED\League\Plates\Engine(\IAWP_SCOPED\iawp_path_to('templates'));
412 }
413 public function interface(Table $table, $stats, $chart)
414 {
415 $options = new Dashboard_Options();
416 // Todo - Silly that I use table to get the params just to pass them back into table
417 $sort_configuration = $table->sanitize_sort_parameters($options->sort_by(), $options->sort_direction());
418 ?>
419 <div id="iawp-dashboard"
420 class="iawp-dashboard"
421 data-controller="report"
422 data-report-relative-range-id-value="<?php
423 echo Security::attr($options->relative_range_id());
424 ?>"
425 data-report-exact-start-value="<?php
426 echo Security::attr($options->start());
427 ?>"
428 data-report-exact-end-value="<?php
429 echo Security::attr($options->end());
430 ?>"
431 data-report-group-value="<?php
432 echo Security::attr($options->group());
433 ?>"
434 data-report-filters-value="<?php
435 \esc_attr_e(Security::json_encode($options->filters()));
436 ?>"
437 data-report-chart-interval-value="<?php
438 echo Security::attr($options->chart_interval()->id());
439 ?>"
440 data-report-columns-value="<?php
441 \esc_attr_e(Security::json_encode($table->visible_column_ids()));
442 ?>"
443 data-report-visible-datasets-value="<?php
444 \esc_attr_e(Security::json_encode($options->visible_datasets()));
445 ?>"
446 >
447 <?php
448 $table->output_toolbar();
449 ?>
450 <?php
451 echo $stats->get_html();
452 ?>
453 <?php
454 echo $chart->get_html($options->visible_datasets());
455 ?>
456 <?php
457 echo $table->get_table_markup($sort_configuration->column(), $sort_configuration->is_ascending() ? 'asc' : 'desc');
458 ?>
459 </div>
460 <div class="iawp-notices"><?php
461 $health_check = new Health_Check();
462 if (!$health_check->healthy()) {
463 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/']);
464 }
465 if (\get_option('iawp_need_clear_cache')) {
466 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/']);
467 }
468 ?>
469 </div><?php
470 }
471 public function enqueue_admin_scripts($hook)
472 {
473 $this->enqueue_translations();
474 if ($hook == 'toplevel_page_independent-analytics') {
475 $tab = $this->get_current_tab();
476 \wp_register_style('iawp-style', \IAWP_SCOPED\iawp_url_to('dist/styles/style.css'), [], \IAWP_VERSION);
477 \wp_enqueue_style('iawp-style');
478 \wp_register_script('iawp-js', \IAWP_SCOPED\iawp_url_to('dist/js/index.js'), [], \IAWP_VERSION);
479 \wp_enqueue_script('iawp-js');
480 \wp_add_inline_script('iawp-js', 'const IAWP_DELETE_DATA_NONCE = ' . \json_encode(\wp_create_nonce('iawp_delete_data')), 'before');
481 if ($tab === 'views' || $tab === 'referrers' || $tab === 'geo' || $tab === 'campaigns' || $tab === 'campaign-builder') {
482 \wp_register_script('iawp-data-table', \IAWP_SCOPED\iawp_url_to('dist/js/data-table.js'), [], \IAWP_VERSION);
483 \wp_enqueue_script('iawp-data-table');
484 \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');
485 } elseif ($tab == 'settings') {
486 \wp_register_script('iawp-settings', \IAWP_SCOPED\iawp_url_to('dist/js/settings.js'), [], \IAWP_VERSION);
487 \wp_enqueue_script('iawp-settings');
488 \wp_add_inline_script('iawp-settings', 'const IAWP_AJAX = ' . \json_encode(['export_views_nonce' => \wp_create_nonce('iawp_export_pages'), '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');
489 } elseif ($tab == 'learn') {
490 \wp_register_script('iawp-learn', \IAWP_SCOPED\iawp_url_to('dist/js/learn.js'), [], \IAWP_VERSION);
491 \wp_enqueue_script('iawp-learn');
492 }
493 } elseif ($hook == 'index.php') {
494 \wp_register_script('iawp-dashboard-widget', \IAWP_SCOPED\iawp_url_to('dist/js/dashboard_widget.js'), [], \IAWP_VERSION);
495 \wp_enqueue_script('iawp-dashboard-widget');
496 \wp_register_style('iawp-dashboard-widget-css', \IAWP_SCOPED\iawp_url_to('dist/styles/dashboard_widget.css'), [], \IAWP_VERSION);
497 \wp_enqueue_style('iawp-dashboard-widget-css');
498 }
499 $this->maybe_enqueue_menu_bar_stats_styles();
500 }
501 public function enqueue_scripts($hook)
502 {
503 $this->maybe_enqueue_menu_bar_stats_styles();
504 }
505 public function enqueue_translations()
506 {
507 \wp_register_script('iawp-translations', '');
508 \wp_enqueue_script('iawp-translations');
509 \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');
510 }
511 public function maybe_enqueue_menu_bar_stats_styles()
512 {
513 if (Menu_Bar_Stats::is_option_enabled()) {
514 \wp_register_style('iawp-front-end-css', \IAWP_SCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION);
515 \wp_enqueue_style('iawp-front-end-css');
516 }
517 }
518 public function get_option($name, $default)
519 {
520 $option = \get_option($name, $default);
521 return $option === '' ? $default : $option;
522 }
523 public function get_authors()
524 {
525 $roles = [];
526 foreach (\wp_roles()->roles as $role_name => $role_obj) {
527 if (!empty($role_obj['capabilities']['edit_posts'])) {
528 $roles[] = $role_name;
529 }
530 }
531 $users = \get_users(['role__in' => $roles]);
532 return $users;
533 }
534 public function get_custom_types(bool $tax = \false)
535 {
536 $args = ['public' => \true, '_builtin' => \false];
537 if ($tax) {
538 return \get_taxonomies($args);
539 } else {
540 return \get_post_types($args);
541 }
542 }
543 public function filter_connect_message_on_update($message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link)
544 {
545 // Add the heading HTML.
546 $plugin_name = 'Independent Analytics';
547 $title = '<h3>' . \sprintf(\esc_html__('We hope you love %1$s', 'independent-analytics'), $plugin_name) . '</h3>';
548 $html = '';
549 // Add the introduction HTML.
550 $html .= '<p>';
551 $html .= \sprintf(\esc_html__('Hi, %1$s! This is an invitation to help the %2$s community.', 'independent-analytics'), $user_first_name, $plugin_name);
552 $html .= '<strong>';
553 $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);
554 $html .= '</strong>';
555 $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);
556 $html .= '</p>';
557 $html .= '<p>';
558 $html .= \sprintf(\esc_html__('And if you skip this, that\'s okay! %1$s will still work just fine.', 'independent-analytics'), $plugin_name);
559 $html .= '</p>';
560 return $title . $html;
561 }
562 public function plugin_action_links($links)
563 {
564 // Create the link
565 $settings_link = '<a class="calendar-link" href="' . \esc_url(\IAWP_SCOPED\iawp_dashboard_url()) . '">' . \esc_html__('Analytics Dashboard', 'independent-analytics') . '</a>';
566 // Add the link to the start of the array
567 \array_unshift($links, $settings_link);
568 return $links;
569 }
570 public function set_time_limit($limit = 0)
571 {
572 if (!\function_exists('set_time_limit') && \false !== \strpos(\ini_get('disable_functions'), 'set_time_limit') && \ini_get('safe_mode')) {
573 return \false;
574 }
575 return @\set_time_limit($limit);
576 }
577 public function ip_db_attribution($text)
578 {
579 if ($this->get_current_tab() === 'geo') {
580 $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>.';
581 }
582 return $text;
583 }
584 public function pagination_page_size()
585 {
586 return 50;
587 }
588 private function get_current_tab()
589 {
590 if (\IAWP_SCOPED\iawp_is_pro()) {
591 $valid_tabs = ['views', 'referrers', 'geo', 'campaigns', 'campaign-builder', 'real-time', 'settings', 'learn'];
592 } else {
593 $valid_tabs = ['views', 'referrers', 'geo', 'settings', 'learn'];
594 }
595 $default_tab = $valid_tabs[0];
596 $tab = \array_key_exists('tab', $_GET) ? \sanitize_text_field($_GET['tab']) : \false;
597 $is_valid = \array_search($tab, $valid_tabs) != \false;
598 if (!$tab || !$is_valid) {
599 $tab = $default_tab;
600 }
601 return $tab;
602 }
603 }
604