PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.3.1
Independent Analytics – WordPress Analytics Plugin v2.3.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 2 years ago Admin_Page 2 years ago Date_Range 2 years ago Filter_Lists 2 years ago Interval 2 years ago Menu_Bar_Stats 2 years ago Migrations 2 years ago Models 2 years ago Public_API 2 years ago Rows 2 years ago Statistics 2 years ago Tables 2 years ago Utils 2 years ago Campaign_Builder.php 2 years ago Capability_Manager.php 2 years ago Chart.php 2 years ago Chart_Geo.php 2 years ago Cron_Manager.php 2 years ago Current_Traffic_Finder.php 2 years ago Dashboard_Options.php 2 years ago Dashboard_Widget.php 2 years ago Database.php 2 years ago Database_Manager.php 2 years ago Email_Chart.php 2 years ago Email_Reports.php 2 years ago Empty_Report_Option.php 2 years ago Env.php 2 years ago Filters.php 2 years ago Geo_Database_Background_Job.php 2 years ago Geo_Database_Manager.php 2 years ago Geoposition.php 2 years ago Icon_Directory.php 2 years ago Icon_Directory_Factory.php 2 years ago Illuminate_Builder.php 2 years ago Independent_Analytics.php 2 years ago Interrupt.php 2 years ago Known_Referrers.php 2 years ago Plugin_Conflict_Detector.php 2 years ago Query.php 2 years ago Quick_Stats.php 2 years ago REST_API.php 2 years ago Real_Time.php 2 years ago Report.php 2 years ago Report_Finder.php 2 years ago Report_Options_Parser.php 2 years ago Resource_Identifier.php 2 years ago Settings.php 2 years ago Sort_Configuration.php 2 years ago Track_Resource_Changes.php 2 years ago View.php 2 years ago View_Counter.php 2 years ago Visitors_Over_Time_Finder.php 2 years ago WP_Option_Cache_Bust.php 2 years ago WooCommerce_Order.php 2 years ago WooCommerce_Referrer_Meta_Box.php 2 years ago
Independent_Analytics.php
267 lines
1 <?php
2
3 namespace IAWP;
4
5 use IAWP\Admin_Page\Analytics_Page;
6 use IAWP\Admin_Page\Campaign_Builder_Page;
7 use IAWP\Admin_Page\Settings_Page;
8 use IAWP\Admin_Page\Support_Page;
9 use IAWP\Admin_Page\Updates_Page;
10 use IAWP\AJAX\AJAX_Manager;
11 use IAWP\Menu_Bar_Stats\Menu_Bar_Stats;
12 use IAWP\Migrations\Migrations;
13 use IAWP\Utils\Singleton;
14 /** @internal */
15 class Independent_Analytics
16 {
17 use Singleton;
18 public $settings;
19 public $email_reports;
20 public $cron_manager;
21 // This is where we attach functions to WP hooks
22 private function __construct()
23 {
24 $this->settings = new \IAWP\Settings();
25 new \IAWP\REST_API();
26 new \IAWP\Dashboard_Widget();
27 new \IAWP\View_Counter();
28 AJAX_Manager::getInstance();
29 if (!Migrations::is_migrating()) {
30 new \IAWP\Track_Resource_Changes();
31 Menu_Bar_Stats::register();
32 \IAWP\WooCommerce_Order::initialize_order_tracker();
33 }
34 $this->cron_manager = new \IAWP\Cron_Manager();
35 if (\IAWPSCOPED\iawp_is_pro()) {
36 $this->email_reports = new \IAWP\Email_Reports();
37 new \IAWP\Campaign_Builder();
38 new \IAWP\WooCommerce_Referrer_Meta_Box();
39 }
40 \add_filter('admin_body_class', function ($classes) {
41 if (\get_option('iawp_dark_mode')) {
42 $classes .= ' iawp-dark-mode ';
43 }
44 return $classes;
45 });
46 \add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts_and_styles'], 20);
47 // Called at 20 to dequeue other scripts
48 \add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_and_styles_front_end']);
49 \add_action('admin_menu', [$this, 'add_admin_menu_pages']);
50 \add_filter('plugin_action_links_independent-analytics/iawp.php', [$this, 'plugin_action_links']);
51 \add_filter('admin_footer_text', [$this, 'ip_db_attribution'], 1, 1);
52 \add_action('init', [$this, 'polylang_translations']);
53 \add_action('init', [$this, 'load_textdomain']);
54 \IAWP_FS()->add_filter('connect_message_on_update', [$this, 'filter_connect_message_on_update'], 10, 6);
55 \IAWP_FS()->add_filter('connect_message', [$this, 'filter_connect_message_on_update'], 10, 6);
56 \IAWP_FS()->add_filter('pricing_url', [$this, 'change_freemius_pricing_url'], 10);
57 \IAWP_FS()->add_filter('show_deactivation_feedback_form', function () {
58 return \false;
59 });
60 \add_action('admin_init', [$this, 'maybe_delete_mu_plugin']);
61 }
62 /**
63 * At one point in time, there was a must-use plugin that was created. The plugin file and the
64 * option need to get cleaned up.
65 * @return void
66 */
67 public function maybe_delete_mu_plugin()
68 {
69 $already_attempted = \get_option('iawp_attempted_to_delete_mu_plugin', '0');
70 if ($already_attempted === '1') {
71 return;
72 }
73 if (\get_option('iawp_must_use_directory_not_writable', '0') === '1') {
74 \delete_option('iawp_must_use_directory_not_writable');
75 }
76 $mu_plugin_file = \trailingslashit(\WPMU_PLUGIN_DIR) . 'iawp-performance-boost.php';
77 if (\file_exists($mu_plugin_file)) {
78 \unlink($mu_plugin_file);
79 }
80 \update_option('iawp_attempted_to_delete_mu_plugin', '1');
81 }
82 public function load_textdomain()
83 {
84 \load_plugin_textdomain('independent-analytics', \false, \IAWP_LANGUAGES_DIRECTORY);
85 }
86 public function polylang_translations()
87 {
88 if (\function_exists('IAWPSCOPED\\pll_register_string')) {
89 pll_register_string('view_counter', 'Views:', 'Independent Analytics');
90 }
91 }
92 // Changes the URL for the "Upgrade" tab in the Account menu
93 public function change_freemius_pricing_url()
94 {
95 return 'https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Account';
96 }
97 public function add_admin_menu_pages()
98 {
99 $title = \IAWP\Capability_Manager::white_labeled() ? \esc_html__('Analytics', 'independent-analytics') : 'Independent Analytics';
100 \add_menu_page($title, \esc_html__('Analytics', 'independent-analytics'), \IAWP\Capability_Manager::can_view_string(), 'independent-analytics', function () {
101 $analytics_page = new Analytics_Page();
102 $analytics_page->render();
103 }, 'dashicons-analytics', 3);
104 if (\IAWP\Capability_Manager::can_edit()) {
105 \add_submenu_page('independent-analytics', \esc_html__('Settings', 'independent-analytics'), \esc_html__('Settings', 'independent-analytics'), \IAWP\Capability_Manager::can_view_string(), 'independent-analytics-settings', function () {
106 $settings_page = new Settings_Page();
107 $settings_page->render(\false);
108 });
109 }
110 if (\IAWPSCOPED\iawp_is_pro()) {
111 \add_submenu_page('independent-analytics', \esc_html__('Campaign Builder', 'independent-analytics'), \esc_html__('Campaign Builder', 'independent-analytics'), \IAWP\Capability_Manager::can_view_string(), 'independent-analytics-campaign-builder', function () {
112 $campaign_builder_page = new Campaign_Builder_Page();
113 $campaign_builder_page->render(\false);
114 });
115 }
116 if (!\IAWP\Capability_Manager::white_labeled()) {
117 \add_submenu_page('independent-analytics', \esc_html__('Help & Support', 'independent-analytics'), \esc_html__('Help & Support', 'independent-analytics'), \IAWP\Capability_Manager::can_view_string(), 'independent-analytics-support-center', function () {
118 $support_page = new Support_Page();
119 $support_page->render(\false);
120 });
121 }
122 if (!\IAWP\Capability_Manager::white_labeled()) {
123 $count = $this->get_update_notification_count();
124 $menu_html = '<span class="menu-name">' . \esc_html__('Changelog', 'independent-analytics') . '</span>';
125 $menu_html = $count > 0 ? $menu_html . ' <span class="menu-counter">' . \absint($count) . '</span>' : $menu_html;
126 \add_submenu_page('independent-analytics', \esc_html__('Changelog', 'independent-analytics'), $menu_html, \IAWP\Capability_Manager::can_view_string(), 'independent-analytics-updates', function () {
127 $updates_page = new Updates_Page();
128 $updates_page->render(\false);
129 });
130 }
131 if (\IAWPSCOPED\iawp_is_free() && !\IAWP\Capability_Manager::white_labeled()) {
132 \add_submenu_page('independent-analytics', \esc_html__('Upgrade to Pro &rarr;', 'independent-analytics'), '<span style="color: #F69D0A;">' . \esc_html__('Upgrade to Pro &rarr;', 'independent-analytics') . '</span>', \IAWP\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'));
133 }
134 }
135 public function register_scripts_and_styles() : void
136 {
137 \wp_register_style('iawp-styles', \IAWPSCOPED\iawp_url_to('dist/styles/style.css'), [], \IAWP_VERSION);
138 \wp_register_style('iawp-dashboard-widget-styles', \IAWPSCOPED\iawp_url_to('dist/styles/dashboard_widget.css'), [], \IAWP_VERSION);
139 \wp_register_style('iawp-freemius-notice-styles', \IAWPSCOPED\iawp_url_to('dist/styles/freemius_notice_styles.css'), [], \IAWP_VERSION);
140 \wp_register_script('iawp-javascript', \IAWPSCOPED\iawp_url_to('dist/js/index.js'), [], \IAWP_VERSION);
141 \wp_register_script('iawp-dashboard-widget-javascript', \IAWPSCOPED\iawp_url_to('dist/js/dashboard_widget.js'), [], \IAWP_VERSION);
142 \wp_register_script('iawp-layout-javascript', \IAWPSCOPED\iawp_url_to('dist/js/layout.js'), [], \IAWP_VERSION);
143 \wp_register_script('iawp-settings-javascript', \IAWPSCOPED\iawp_url_to('dist/js/settings.js'), ['wp-color-picker'], \IAWP_VERSION);
144 if (Menu_Bar_Stats::is_option_enabled()) {
145 \wp_register_style('iawp-front-end-styles', \IAWPSCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION);
146 }
147 if (\is_rtl()) {
148 \wp_register_style('iawp-styles-rtl', \IAWPSCOPED\iawp_url_to('dist/styles/rtl.css'), [], \IAWP_VERSION);
149 }
150 }
151 public function register_scripts_and_styles_front_end() : void
152 {
153 if (Menu_Bar_Stats::is_option_enabled()) {
154 \wp_register_style('iawp-front-end-styles', \IAWPSCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION);
155 }
156 }
157 public function enqueue_scripts_and_styles($hook)
158 {
159 $this->register_scripts_and_styles();
160 $page = \IAWP\Env::get_page();
161 $this->enqueue_translations();
162 $this->enqueue_nonces();
163 \wp_enqueue_style('iawp-freemius-notice-styles');
164 if (\is_string($page)) {
165 \wp_enqueue_style('iawp-styles');
166 \wp_enqueue_script('iawp-javascript');
167 \wp_enqueue_script('iawp-layout-javascript');
168 $this->dequeue_bad_actors();
169 if (\is_rtl()) {
170 \wp_enqueue_style('iawp-styles-rtl');
171 }
172 }
173 if ($page === 'independent-analytics-settings') {
174 \wp_enqueue_style('wp-color-picker');
175 \wp_enqueue_script('iawp-settings-javascript');
176 } elseif ($hook === 'index.php') {
177 \wp_enqueue_script('iawp-dashboard-widget-javascript');
178 \wp_enqueue_style('iawp-dashboard-widget-styles');
179 }
180 if (Menu_Bar_Stats::is_option_enabled()) {
181 \wp_enqueue_style('iawp-front-end-styles');
182 }
183 }
184 public function enqueue_scripts_and_styles_front_end()
185 {
186 if (Menu_Bar_Stats::is_option_enabled()) {
187 $this->register_scripts_and_styles_front_end();
188 \wp_enqueue_style('iawp-front-end-styles');
189 }
190 }
191 public function enqueue_translations()
192 {
193 \wp_register_script('iawp-translations', '');
194 \wp_enqueue_script('iawp-translations');
195 \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'), 'copied' => \__('Copied', 'independent-analytics'), 'exportingPages' => \__('Exporting Pages...', 'independent-analytics'), 'exportPages' => \__('Export Pages', 'independent-analytics'), 'exportingReferrers' => \__('Exporting Referrers...', 'independent-analytics'), 'exportReferrers' => \__('Export Referrers', 'independent-analytics'), 'exportingGeolocations' => \__('Exporting Geolocations...', 'independent-analytics'), 'exportGeolocations' => \__('Export Geolocations', 'independent-analytics'), 'exportingDevices' => \__('Exporting Devices...', 'independent-analytics'), 'exportDevices' => \__('Export Devices', 'independent-analytics'), 'exportingCampaigns' => \__('Exporting Campaigns...', 'independent-analytics'), 'exportCampaigns' => \__('Export Campaigns', 'independent-analytics'), 'invalidReportArchive' => \__('This report archive is invalid. Please export your reports and try again.', 'independent-analytics'), 'openMobileMenu' => \__('Open menu', 'independent-analytics'), 'closeMobileMenu' => \__('Close menu', 'independent-analytics')]), 'before');
196 }
197 public function enqueue_nonces()
198 {
199 \wp_register_script('iawp-nonces', '');
200 \wp_enqueue_script('iawp-nonces');
201 \wp_add_inline_script('iawp-nonces', 'const iawpActions = ' . \json_encode(AJAX_Manager::getInstance()->get_action_signatures()), 'before');
202 }
203 public function get_option($name, $default)
204 {
205 $option = \get_option($name, $default);
206 return $option === '' ? $default : $option;
207 }
208 public function filter_connect_message_on_update($message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link)
209 {
210 // Add the heading HTML.
211 $plugin_name = 'Independent Analytics';
212 $title = '<h3>' . \sprintf(\esc_html__('We hope you love %1$s', 'independent-analytics'), $plugin_name) . '</h3>';
213 $html = '';
214 // Add the introduction HTML.
215 $html .= '<p>';
216 $html .= \sprintf(\esc_html__('Hi, %1$s! This is an invitation to help the %2$s community.', 'independent-analytics'), $user_first_name, $plugin_name);
217 $html .= '<strong>';
218 $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);
219 $html .= '</strong>';
220 $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);
221 $html .= '</p>';
222 $html .= '<p>';
223 $html .= \sprintf(\esc_html__('And if you skip this, that\'s okay! %1$s will still work just fine.', 'independent-analytics'), $plugin_name);
224 $html .= '</p>';
225 return $title . $html;
226 }
227 public function plugin_action_links($links)
228 {
229 // Create the link
230 $settings_link = '<a class="calendar-link" href="' . \esc_url(\IAWPSCOPED\iawp_dashboard_url()) . '">' . \esc_html__('Analytics Dashboard', 'independent-analytics') . '</a>';
231 // Add the link to the start of the array
232 \array_unshift($links, $settings_link);
233 return $links;
234 }
235 public function ip_db_attribution($text)
236 {
237 if (\IAWP\Env::get_tab() === 'geo') {
238 $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>.';
239 }
240 return $text;
241 }
242 public function pagination_page_size()
243 {
244 return 50;
245 }
246 public function dequeue_bad_actors()
247 {
248 // https://wordpress.org/plugins/comment-link-remove/
249 \wp_dequeue_style('qc_clr_admin_style_css');
250 // https://wordpress.org/plugins/webappick-pdf-invoice-for-woocommerce/
251 \wp_dequeue_style('woo-invoice');
252 // https://wordpress.org/plugins/wp-media-files-name-rename/
253 \wp_dequeue_style('wpcmp_bootstrap_css');
254 }
255 public function get_update_notification_count()
256 {
257 // https://api.wordpress.org/plugins/info/1.0/independent-analytics.json
258 $version_history = ['2.3.0', '2.2.0', '2.1.0'];
259 $last_update_viewed = $this->get_option('iawp_last_update_viewed', '0');
260 $notification_html = '';
261 $unseen_versions = \array_filter($version_history, function ($version) use($last_update_viewed) {
262 return \version_compare($last_update_viewed, $version, '<');
263 });
264 return \count($unseen_versions);
265 }
266 }
267