AJAX
2 years ago
Date_Range
2 years ago
Interval
3 years ago
Menu_Bar_Stats
2 years ago
Migrations
2 years ago
Models
2 years ago
Queries
2 years ago
Statistics
2 years ago
Tables
2 years ago
Utils
2 years ago
Campaign_Builder.php
2 years ago
Capability_Manager.php
3 years ago
Chart.php
3 years ago
Chart_Geo.php
2 years ago
Chart_SVG.php
3 years ago
City_To_Country_Converter.php
3 years ago
Dashboard_Options.php
2 years ago
Dashboard_Widget.php
3 years ago
Email_Chart.php
2 years ago
Email_Reports.php
2 years ago
Env.php
2 years ago
Filters.php
2 years ago
Geo_Database_Background_Job.php
2 years ago
Geo_Database_Downloader.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
3 years ago
Independent_Analytics.php
2 years ago
Interrupt.php
2 years ago
Known_Referrers.php
3 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
Reset_Database.php
3 years ago
Resource_Identifier.php
3 years ago
Settings.php
2 years ago
Sort_Configuration.php
3 years ago
Track_Resource_Changes.php
3 years ago
View.php
2 years ago
View_Counter.php
2 years ago
WP_Option_Cache_Bust.php
2 years ago
WooCommerce_Order.php
2 years ago
Independent_Analytics.php
415 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_Campaign_AJAX; |
| 8 | use IAWP_SCOPED\IAWP\AJAX\Delete_Data_AJAX; |
| 9 | use IAWP_SCOPED\IAWP\AJAX\Export_Campaigns_AJAX; |
| 10 | use IAWP_SCOPED\IAWP\AJAX\Export_Devices_AJAX; |
| 11 | use IAWP_SCOPED\IAWP\AJAX\Export_Geo_AJAX; |
| 12 | use IAWP_SCOPED\IAWP\AJAX\Export_Pages_AJAX; |
| 13 | use IAWP_SCOPED\IAWP\AJAX\Export_Referrers_AJAX; |
| 14 | use IAWP_SCOPED\IAWP\AJAX\Filters_AJAX; |
| 15 | use IAWP_SCOPED\IAWP\AJAX\Migration_Status_AJAX; |
| 16 | use IAWP_SCOPED\IAWP\AJAX\Real_Time_AJAX; |
| 17 | use IAWP_SCOPED\IAWP\AJAX\Test_Email_AJAX; |
| 18 | use IAWP_SCOPED\IAWP\AJAX\Update_Capabilities_AJAX; |
| 19 | use IAWP_SCOPED\IAWP\Menu_Bar_Stats\Menu_Bar_Stats; |
| 20 | use IAWP_SCOPED\IAWP\Migrations\Migration; |
| 21 | use IAWP_SCOPED\IAWP\Statistics\Campaign_Statistics; |
| 22 | use IAWP_SCOPED\IAWP\Statistics\Country_Statistics; |
| 23 | use IAWP_SCOPED\IAWP\Statistics\Device_Statistics; |
| 24 | use IAWP_SCOPED\IAWP\Statistics\Page_Statistics; |
| 25 | use IAWP_SCOPED\IAWP\Statistics\Referrer_Statistics; |
| 26 | use IAWP_SCOPED\IAWP\Tables\Table; |
| 27 | use IAWP_SCOPED\IAWP\Tables\Table_Campaigns; |
| 28 | use IAWP_SCOPED\IAWP\Tables\Table_Devices; |
| 29 | use IAWP_SCOPED\IAWP\Tables\Table_Geo; |
| 30 | use IAWP_SCOPED\IAWP\Tables\Table_Pages; |
| 31 | use IAWP_SCOPED\IAWP\Tables\Table_Referrers; |
| 32 | use IAWP_SCOPED\IAWP\Utils\Security; |
| 33 | use IAWP_SCOPED\IAWP\Utils\Singleton; |
| 34 | class Independent_Analytics |
| 35 | { |
| 36 | use Singleton; |
| 37 | public $settings; |
| 38 | public $email_reports; |
| 39 | // This is where we attach functions to WP hooks |
| 40 | private function __construct() |
| 41 | { |
| 42 | $this->settings = new Settings(); |
| 43 | new REST_API(); |
| 44 | new Dashboard_Widget(); |
| 45 | new View_Counter(); |
| 46 | new Delete_Data_AJAX(); |
| 47 | new Filters_AJAX(); |
| 48 | new Export_Geo_AJAX(); |
| 49 | new Export_Devices_AJAX(); |
| 50 | new Export_Referrers_AJAX(); |
| 51 | new Export_Pages_AJAX(); |
| 52 | new Migration_Status_AJAX(); |
| 53 | new Update_Capabilities_AJAX(); |
| 54 | new Cleared_Cache_AJAX(); |
| 55 | new Track_Resource_Changes(); |
| 56 | Menu_Bar_Stats::register(); |
| 57 | WooCommerce_Order::initialize_order_tracker(); |
| 58 | if (\IAWP_SCOPED\iawp_is_pro()) { |
| 59 | $this->email_reports = new Email_Reports(); |
| 60 | new Export_Campaigns_AJAX(); |
| 61 | new Create_Campaign_AJAX(); |
| 62 | new Delete_Campaign_AJAX(); |
| 63 | new Campaign_Builder(); |
| 64 | new Real_Time_AJAX(); |
| 65 | new Test_Email_AJAX(); |
| 66 | } |
| 67 | \add_filter('admin_body_class', function ($classes) { |
| 68 | if (\get_option('iawp_dark_mode')) { |
| 69 | $classes .= ' iawp-dark-mode '; |
| 70 | } |
| 71 | return $classes; |
| 72 | }); |
| 73 | \add_action('admin_menu', [$this, 'add_admin_menu_pages']); |
| 74 | \add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']); |
| 75 | \add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']); |
| 76 | \add_filter('plugin_action_links_independent-analytics/iawp.php', [$this, 'plugin_action_links']); |
| 77 | \add_filter('admin_footer_text', [$this, 'ip_db_attribution'], 1, 1); |
| 78 | \add_filter('admin_head', [$this, 'style_premium_menu_item']); |
| 79 | \add_action('init', [$this, 'polylang_translations']); |
| 80 | \add_action('init', [$this, 'load_textdomain']); |
| 81 | IAWP_FS()->add_filter('connect_message_on_update', [$this, 'filter_connect_message_on_update'], 10, 6); |
| 82 | IAWP_FS()->add_filter('connect_message', [$this, 'filter_connect_message_on_update'], 10, 6); |
| 83 | IAWP_FS()->add_filter('is_submenu_visible', [$this, 'hide_freemius_sub_menus'], 10, 2); |
| 84 | IAWP_FS()->add_filter('pricing_url', [$this, 'change_freemius_pricing_url'], 10); |
| 85 | IAWP_FS()->add_filter('show_deactivation_feedback_form', function () { |
| 86 | return \false; |
| 87 | }); |
| 88 | } |
| 89 | public function load_textdomain() |
| 90 | { |
| 91 | \load_plugin_textdomain('independent-analytics', \false, \IAWP_LANGUAGES_DIRECTORY); |
| 92 | } |
| 93 | public function polylang_translations() |
| 94 | { |
| 95 | if (\function_exists('IAWP_SCOPED\\pll_register_string')) { |
| 96 | pll_register_string('view_counter', 'Views:', 'Independent Analytics'); |
| 97 | } |
| 98 | } |
| 99 | // Settings page where the analytics will appear |
| 100 | public function add_admin_menu_pages() |
| 101 | { |
| 102 | $title = Capability_Manager::white_labeled() ? \esc_html__('Analytics', 'independent-analytics') : 'Independent Analytics'; |
| 103 | \add_menu_page($title, \esc_html__('Analytics', 'independent-analytics'), Capability_Manager::can_view_string(), 'independent-analytics', [$this, 'render_analytics_page'], 'dashicons-analytics', 3); |
| 104 | if (!Capability_Manager::white_labeled()) { |
| 105 | \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')); |
| 106 | } |
| 107 | if (\IAWP_SCOPED\iawp_is_free() && !Capability_Manager::white_labeled()) { |
| 108 | \add_submenu_page('independent-analytics', \esc_html__('Upgrade to Pro →', 'independent-analytics'), \esc_html__('Upgrade to Pro →', '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')); |
| 109 | } |
| 110 | } |
| 111 | public function hide_freemius_sub_menus($is_visible, $menu_id) |
| 112 | { |
| 113 | if ('pricing' == $menu_id) { |
| 114 | return \false; |
| 115 | } elseif ('support' == $menu_id && Capability_Manager::white_labeled()) { |
| 116 | return \false; |
| 117 | } else { |
| 118 | return \true; |
| 119 | } |
| 120 | } |
| 121 | public function change_freemius_pricing_url() |
| 122 | { |
| 123 | return 'https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Account'; |
| 124 | } |
| 125 | // The submenu item needs to be styled on all admin pages, and we only load stylesheets on our page |
| 126 | public function style_premium_menu_item() |
| 127 | { |
| 128 | if (\IAWP_SCOPED\iawp_is_free()) { |
| 129 | echo '<style>#toplevel_page_independent-analytics .wp-submenu li:nth-child(4) a { color: #F69D0A; }</style>'; |
| 130 | } |
| 131 | } |
| 132 | public function render_analytics_page() |
| 133 | { |
| 134 | if (!Capability_Manager::can_view()) { |
| 135 | return; |
| 136 | } |
| 137 | if (Migration::is_migrating()) { |
| 138 | $interrupt = new Interrupt('interrupt.migration-is-running'); |
| 139 | $interrupt->render(); |
| 140 | return; |
| 141 | } |
| 142 | $tab = $this->get_current_tab(); |
| 143 | ?> |
| 144 | <div id="iawp-parent" class="iawp-parent"> |
| 145 | <?php |
| 146 | if (!Capability_Manager::white_labeled()) { |
| 147 | echo \IAWP_SCOPED\iawp_blade()->run('partials.brand-header', ['show_review' => \true]); |
| 148 | } |
| 149 | echo \IAWP_SCOPED\iawp_blade()->run('partials.toolbar'); |
| 150 | ?> |
| 151 | <div class="iawp-tab-content"><?php |
| 152 | $options = new Dashboard_Options(); |
| 153 | $date_rage = $options->get_date_range(); |
| 154 | $date_label = $date_rage->label(); |
| 155 | $columns = $options->columns(); |
| 156 | if ($tab == 'views') { |
| 157 | $table = new Table_Pages($columns); |
| 158 | $statistics = new Page_Statistics($date_rage, null, $options->chart_interval()); |
| 159 | $stats = new Quick_Stats(null, $statistics); |
| 160 | $chart = new Chart($statistics, $date_label); |
| 161 | $this->interface($table, $stats, $chart); |
| 162 | } elseif ($tab == 'referrers') { |
| 163 | $table = new Table_Referrers($columns); |
| 164 | $statistics = new Referrer_Statistics($date_rage, null, $options->chart_interval()); |
| 165 | $stats = new Quick_Stats(null, $statistics); |
| 166 | $chart = new Chart($statistics, $date_label); |
| 167 | $this->interface($table, $stats, $chart); |
| 168 | } elseif ($tab == 'geo') { |
| 169 | $table = new Table_Geo($columns, $options->group()); |
| 170 | $statistics = new Country_Statistics($date_rage); |
| 171 | $stats = new Quick_Stats(null, $statistics); |
| 172 | $table_data_class = $table->group()->table_data_class(); |
| 173 | $geo_data = new $table_data_class($date_rage); |
| 174 | if ($options->group() === 'city') { |
| 175 | $country_rows = City_To_Country_Converter::convert($geo_data->rows()); |
| 176 | $chart = new Chart_Geo($country_rows, $date_label); |
| 177 | } else { |
| 178 | $chart = new Chart_Geo($geo_data->rows(), $date_label); |
| 179 | } |
| 180 | $this->interface($table, $stats, $chart); |
| 181 | } elseif ($tab === 'campaigns') { |
| 182 | $table = new Table_Campaigns($columns); |
| 183 | $statistics = new Campaign_Statistics($date_rage, null, $options->chart_interval()); |
| 184 | $stats = new Quick_Stats(null, $statistics); |
| 185 | $chart = new Chart($statistics, $date_label); |
| 186 | $this->interface($table, $stats, $chart); |
| 187 | } elseif ($tab == 'campaign-builder') { |
| 188 | (new Campaign_Builder())->render_campaign_builder(); |
| 189 | } elseif ($tab == 'devices') { |
| 190 | $table = new Table_Devices($columns, $options->group()); |
| 191 | $statistics = new Device_Statistics($date_rage); |
| 192 | $stats = new Quick_Stats(null, $statistics); |
| 193 | $chart = new Chart($statistics, $date_label); |
| 194 | $this->interface($table, $stats, $chart); |
| 195 | } elseif ($tab === 'real-time') { |
| 196 | (new Real_Time())->render_real_time_analytics(); |
| 197 | } elseif ($tab == 'settings') { |
| 198 | echo '<div id="iawp-dashboard" class="iawp-dashboard">'; |
| 199 | if (Capability_Manager::can_edit()) { |
| 200 | $this->settings->render_settings(); |
| 201 | } else { |
| 202 | echo '<p class="permission-blocked">' . \esc_html__('You do not have permission to edit the settings.', 'independent-analytics') . '</p>'; |
| 203 | } |
| 204 | echo '</div>'; |
| 205 | } elseif ($tab == 'learn') { |
| 206 | echo '<div id="iawp-dashboard" class="iawp-dashboard">'; |
| 207 | echo \IAWP_SCOPED\iawp_blade()->run('learn.learn'); |
| 208 | echo '</div>'; |
| 209 | } |
| 210 | ?> |
| 211 | </div> |
| 212 | <div id="loading-icon" class="loading-icon"><img |
| 213 | src="<?php |
| 214 | echo \esc_url(\IAWP_SCOPED\iawp_url_to('img/loading.svg')); |
| 215 | ?>"/> |
| 216 | </div> |
| 217 | <button id="scroll-to-top" class="scroll-to-top"><span |
| 218 | class="dashicons dashicons-arrow-up-alt"></span> |
| 219 | </button> |
| 220 | </div> |
| 221 | <?php |
| 222 | } |
| 223 | public function interface(Table $table, $stats, $chart) |
| 224 | { |
| 225 | $options = new Dashboard_Options(); |
| 226 | // Todo - Silly that I use table to get the params just to pass them back into table |
| 227 | $sort_configuration = $table->sanitize_sort_parameters($options->sort_by(), $options->sort_direction()); |
| 228 | ?> |
| 229 | <div id="iawp-dashboard" |
| 230 | class="iawp-dashboard" |
| 231 | data-controller="report" |
| 232 | data-report-relative-range-id-value="<?php |
| 233 | echo Security::attr($options->relative_range_id()); |
| 234 | ?>" |
| 235 | data-report-exact-start-value="<?php |
| 236 | echo Security::attr($options->start()); |
| 237 | ?>" |
| 238 | data-report-exact-end-value="<?php |
| 239 | echo Security::attr($options->end()); |
| 240 | ?>" |
| 241 | data-report-group-value="<?php |
| 242 | echo Security::attr($options->group()); |
| 243 | ?>" |
| 244 | data-report-filters-value="<?php |
| 245 | \esc_attr_e(Security::json_encode($options->filters())); |
| 246 | ?>" |
| 247 | data-report-chart-interval-value="<?php |
| 248 | echo Security::attr($options->chart_interval()->id()); |
| 249 | ?>" |
| 250 | data-report-columns-value="<?php |
| 251 | \esc_attr_e(Security::json_encode($table->visible_column_ids())); |
| 252 | ?>" |
| 253 | data-report-visible-datasets-value="<?php |
| 254 | \esc_attr_e(Security::json_encode($options->visible_datasets())); |
| 255 | ?>" |
| 256 | > |
| 257 | <?php |
| 258 | $table->output_toolbar(); |
| 259 | ?> |
| 260 | <?php |
| 261 | echo $stats->get_html(); |
| 262 | ?> |
| 263 | <?php |
| 264 | echo $chart->get_html($options->visible_datasets()); |
| 265 | ?> |
| 266 | <?php |
| 267 | echo $table->get_table_markup($sort_configuration->column(), $sort_configuration->is_ascending() ? 'asc' : 'desc'); |
| 268 | ?> |
| 269 | </div> |
| 270 | <div class="iawp-notices"><?php |
| 271 | $plugin_conflict_detector = new Plugin_Conflict_Detector(); |
| 272 | if (!$plugin_conflict_detector->has_conflict()) { |
| 273 | echo \IAWP_SCOPED\iawp_blade()->run('settings.notice', ['notice_text' => $plugin_conflict_detector->get_error(), 'button_text' => \false, 'notice' => 'iawp-error', 'url' => 'https://independentwp.com/knowledgebase/common-questions/views-not-recording/']); |
| 274 | } |
| 275 | if (\get_option('iawp_need_clear_cache')) { |
| 276 | echo \IAWP_SCOPED\iawp_blade()->run('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/']); |
| 277 | } |
| 278 | ?> |
| 279 | </div><?php |
| 280 | } |
| 281 | public function enqueue_admin_scripts($hook) |
| 282 | { |
| 283 | $this->enqueue_translations(); |
| 284 | if ($hook == 'toplevel_page_independent-analytics') { |
| 285 | $tab = $this->get_current_tab(); |
| 286 | \wp_register_style('iawp-style', \IAWP_SCOPED\iawp_url_to('dist/styles/style.css'), [], \IAWP_VERSION); |
| 287 | \wp_enqueue_style('iawp-style'); |
| 288 | \wp_register_script('iawp-js', \IAWP_SCOPED\iawp_url_to('dist/js/index.js'), [], \IAWP_VERSION); |
| 289 | \wp_enqueue_script('iawp-js'); |
| 290 | \wp_add_inline_script('iawp-js', 'const IAWP_DELETE_DATA_NONCE = ' . \json_encode(\wp_create_nonce('iawp_delete_data')), 'before'); |
| 291 | if ($tab === 'views' || $tab === 'referrers' || $tab === 'geo' || $tab === 'campaigns' || $tab === 'campaign-builder' || $tab === 'devices') { |
| 292 | \wp_register_script('iawp-data-table', \IAWP_SCOPED\iawp_url_to('dist/js/data-table.js'), [], \IAWP_VERSION); |
| 293 | \wp_enqueue_script('iawp-data-table'); |
| 294 | \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'), 'delete_campaign_nonce' => \wp_create_nonce('iawp_delete_campaign'), 'copied_text' => \esc_html__('Copied!', 'independent-analytics'), 'iawp_need_clear_cache_nonce' => \wp_create_nonce('iawp_need_clear_cache')]), 'before'); |
| 295 | } elseif ($tab == 'settings') { |
| 296 | \wp_enqueue_style('wp-color-picker'); |
| 297 | \wp_register_script('iawp-settings', \IAWP_SCOPED\iawp_url_to('dist/js/settings.js'), ['wp-color-picker'], \IAWP_VERSION); |
| 298 | \wp_enqueue_script('iawp-settings'); |
| 299 | \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_devices_nonce' => \wp_create_nonce('iawp_export_devices'), '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_devices_text' => \esc_html__('Export Devices', 'independent-analytics'), 'exporting_devices_text' => \esc_html__('Exporting Devices...', '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'); |
| 300 | } elseif ($tab == 'learn') { |
| 301 | \wp_register_script('iawp-learn', \IAWP_SCOPED\iawp_url_to('dist/js/learn.js'), [], \IAWP_VERSION); |
| 302 | \wp_enqueue_script('iawp-learn'); |
| 303 | } |
| 304 | } elseif ($hook == 'index.php') { |
| 305 | \wp_register_script('iawp-dashboard-widget', \IAWP_SCOPED\iawp_url_to('dist/js/dashboard_widget.js'), [], \IAWP_VERSION); |
| 306 | \wp_enqueue_script('iawp-dashboard-widget'); |
| 307 | \wp_register_style('iawp-dashboard-widget-css', \IAWP_SCOPED\iawp_url_to('dist/styles/dashboard_widget.css'), [], \IAWP_VERSION); |
| 308 | \wp_enqueue_style('iawp-dashboard-widget-css'); |
| 309 | } |
| 310 | $this->maybe_enqueue_menu_bar_stats_styles(); |
| 311 | } |
| 312 | public function enqueue_scripts($hook) |
| 313 | { |
| 314 | $this->maybe_enqueue_menu_bar_stats_styles(); |
| 315 | } |
| 316 | public function enqueue_translations() |
| 317 | { |
| 318 | \wp_register_script('iawp-translations', ''); |
| 319 | \wp_enqueue_script('iawp-translations'); |
| 320 | \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'); |
| 321 | } |
| 322 | public function maybe_enqueue_menu_bar_stats_styles() |
| 323 | { |
| 324 | if (Menu_Bar_Stats::is_option_enabled()) { |
| 325 | \wp_register_style('iawp-front-end-css', \IAWP_SCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION); |
| 326 | \wp_enqueue_style('iawp-front-end-css'); |
| 327 | } |
| 328 | } |
| 329 | public function get_option($name, $default) |
| 330 | { |
| 331 | $option = \get_option($name, $default); |
| 332 | return $option === '' ? $default : $option; |
| 333 | } |
| 334 | public function get_authors() |
| 335 | { |
| 336 | $roles = []; |
| 337 | foreach (\wp_roles()->roles as $role_name => $role_obj) { |
| 338 | if (!empty($role_obj['capabilities']['edit_posts'])) { |
| 339 | $roles[] = $role_name; |
| 340 | } |
| 341 | } |
| 342 | $users = \get_users(['role__in' => $roles]); |
| 343 | return $users; |
| 344 | } |
| 345 | public function get_custom_types(bool $tax = \false) |
| 346 | { |
| 347 | $args = ['public' => \true, '_builtin' => \false]; |
| 348 | if ($tax) { |
| 349 | return \get_taxonomies($args); |
| 350 | } else { |
| 351 | return \get_post_types($args); |
| 352 | } |
| 353 | } |
| 354 | public function filter_connect_message_on_update($message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link) |
| 355 | { |
| 356 | // Add the heading HTML. |
| 357 | $plugin_name = 'Independent Analytics'; |
| 358 | $title = '<h3>' . \sprintf(\esc_html__('We hope you love %1$s', 'independent-analytics'), $plugin_name) . '</h3>'; |
| 359 | $html = ''; |
| 360 | // Add the introduction HTML. |
| 361 | $html .= '<p>'; |
| 362 | $html .= \sprintf(\esc_html__('Hi, %1$s! This is an invitation to help the %2$s community.', 'independent-analytics'), $user_first_name, $plugin_name); |
| 363 | $html .= '<strong>'; |
| 364 | $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); |
| 365 | $html .= '</strong>'; |
| 366 | $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); |
| 367 | $html .= '</p>'; |
| 368 | $html .= '<p>'; |
| 369 | $html .= \sprintf(\esc_html__('And if you skip this, that\'s okay! %1$s will still work just fine.', 'independent-analytics'), $plugin_name); |
| 370 | $html .= '</p>'; |
| 371 | return $title . $html; |
| 372 | } |
| 373 | public function plugin_action_links($links) |
| 374 | { |
| 375 | // Create the link |
| 376 | $settings_link = '<a class="calendar-link" href="' . \esc_url(\IAWP_SCOPED\iawp_dashboard_url()) . '">' . \esc_html__('Analytics Dashboard', 'independent-analytics') . '</a>'; |
| 377 | // Add the link to the start of the array |
| 378 | \array_unshift($links, $settings_link); |
| 379 | return $links; |
| 380 | } |
| 381 | public function set_time_limit($limit = 0) |
| 382 | { |
| 383 | if (!\function_exists('set_time_limit') && \false !== \strpos(\ini_get('disable_functions'), 'set_time_limit') && \ini_get('safe_mode')) { |
| 384 | return \false; |
| 385 | } |
| 386 | return @\set_time_limit($limit); |
| 387 | } |
| 388 | public function ip_db_attribution($text) |
| 389 | { |
| 390 | if ($this->get_current_tab() === 'geo') { |
| 391 | $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>.'; |
| 392 | } |
| 393 | return $text; |
| 394 | } |
| 395 | public function pagination_page_size() |
| 396 | { |
| 397 | return 50; |
| 398 | } |
| 399 | private function get_current_tab() |
| 400 | { |
| 401 | if (\IAWP_SCOPED\iawp_is_pro()) { |
| 402 | $valid_tabs = ['views', 'referrers', 'geo', 'devices', 'campaigns', 'campaign-builder', 'real-time', 'settings', 'learn']; |
| 403 | } else { |
| 404 | $valid_tabs = ['views', 'referrers', 'geo', 'devices', 'settings', 'learn']; |
| 405 | } |
| 406 | $default_tab = $valid_tabs[0]; |
| 407 | $tab = \array_key_exists('tab', $_GET) ? \sanitize_text_field($_GET['tab']) : \false; |
| 408 | $is_valid = \array_search($tab, $valid_tabs) != \false; |
| 409 | if (!$tab || !$is_valid) { |
| 410 | $tab = $default_tab; |
| 411 | } |
| 412 | return $tab; |
| 413 | } |
| 414 | } |
| 415 |