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