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