PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.17.4
Independent Analytics – WordPress Analytics Plugin v1.17.4
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 / index.php
independent-analytics Last commit date
IAWP 3 years ago dist 3 years ago freemius 3 years ago img 3 years ago languages 3 years ago templates 3 years ago vendor 3 years ago iawp.php 3 years ago index.php 3 years ago readme.txt 3 years ago
index.php
218 lines
1 <?php
2
3 namespace IAWP;
4
5 define( 'IAWP_DIRECTORY', rtrim( plugin_dir_path( __FILE__ ), DIRECTORY_SEPARATOR ) );
6 define( 'IAWP_URL', rtrim( plugin_dir_url( __FILE__ ), '/' ) );
7 define( 'IAWP_VERSION', '1.17.4' );
8 define( 'IAWP_LANGUAGES_DIRECTORY', dirname( plugin_basename( __FILE__ ) ) . '/languages' );
9 function iawp_log( $log )
10 {
11 if ( WP_DEBUG === true ) {
12
13 if ( is_array( $log ) || is_object( $log ) ) {
14 error_log( print_r( $log, true ) );
15 } else {
16 error_log( $log );
17 }
18
19 }
20 }
21
22 function path_to( $path )
23 {
24 $path = trim( $path, DIRECTORY_SEPARATOR );
25 return implode( DIRECTORY_SEPARATOR, [ IAWP_DIRECTORY, $path ] );
26 }
27
28 function url_to( $path )
29 {
30 $path = trim( $path, '/' );
31 return implode( '/', [ IAWP_URL, $path ] );
32 }
33
34 // Load scoped composer autoloader
35 require_once path_to( 'vendor/scoper-autoload.php' );
36 // Load scoped composer autoloader
37 require_once path_to( 'vendor/scoper-autoload.php' );
38 // Load class utilities needed for other require calls to work
39 require_once path_to( 'IAWP/utils/singleton.php' );
40 // Load utils
41 require_once path_to( 'IAWP/utils/array_to_csv.php' );
42 require_once path_to( 'IAWP/utils/date_format.php' );
43 require_once path_to( 'IAWP/utils/exact_range.php' );
44 require_once path_to( 'IAWP/utils/number_formatter.php' );
45 require_once path_to( 'IAWP/models/visitor.php' );
46 require_once path_to( 'IAWP/utils/request.php' );
47 require_once path_to( 'IAWP/utils/salt.php' );
48 require_once path_to( 'IAWP/utils/security.php' );
49 require_once path_to( 'IAWP/utils/string.php' );
50 require_once path_to( 'IAWP/utils/timezone.php' );
51 require_once path_to( 'IAWP/utils/relative_range.php' );
52 require_once path_to( 'IAWP/utils/url.php' );
53 require_once path_to( 'IAWP/utils/wp-async-request.php' );
54 // Load ajax
55 require_once path_to( 'IAWP/ajax/ajax.php' );
56 require_once path_to( 'IAWP/ajax/cleared_cache_ajax.php' );
57 require_once path_to( 'IAWP/ajax/create_campaign_ajax.php' );
58 require_once path_to( 'IAWP/ajax/delete_data_ajax.php' );
59 require_once path_to( 'IAWP/ajax/export_campaigns_ajax.php' );
60 require_once path_to( 'IAWP/ajax/export_geo_ajax.php' );
61 require_once path_to( 'IAWP/ajax/export_referrers_ajax.php' );
62 require_once path_to( 'IAWP/ajax/export_views_ajax.php' );
63 require_once path_to( 'IAWP/ajax/filters_ajax.php' );
64 require_once path_to( 'IAWP/ajax/migration_status_ajax.php' );
65 require_once path_to( 'IAWP/ajax/real_time_ajax.php' );
66 require_once path_to( 'IAWP/ajax/test_email_ajax.php' );
67 require_once path_to( 'IAWP/ajax/update_capabilities_ajax.php' );
68 // Load models
69 require_once path_to( 'IAWP/models/view_stats.php' );
70 require_once path_to( 'IAWP/models/wc_stats.php' );
71 require_once path_to( 'IAWP/models/page.php' );
72 require_once path_to( 'IAWP/models/page_author_archive.php' );
73 require_once path_to( 'IAWP/models/page_date_archive.php' );
74 require_once path_to( 'IAWP/models/page_home.php' );
75 require_once path_to( 'IAWP/models/page_not_found.php' );
76 require_once path_to( 'IAWP/models/page_post_type_archive.php' );
77 require_once path_to( 'IAWP/models/page_search.php' );
78 require_once path_to( 'IAWP/models/page_singular.php' );
79 require_once path_to( 'IAWP/models/page_term_archive.php' );
80 require_once path_to( 'IAWP/models/campaign.php' );
81 require_once path_to( 'IAWP/models/current_traffic.php' );
82 require_once path_to( 'IAWP/models/geo.php' );
83 require_once path_to( 'IAWP/models/referrer.php' );
84 // Load queries
85 require_once path_to( 'IAWP/queries/range_query.php' );
86 require_once path_to( 'IAWP/queries/campaigns.php' );
87 require_once path_to( 'IAWP/queries/city_statistics.php' );
88 require_once path_to( 'IAWP/queries/country_statistics.php' );
89 require_once path_to( 'IAWP/queries/current_traffic_finder.php' );
90 require_once path_to( 'IAWP/queries/referrers.php' );
91 require_once path_to( 'IAWP/queries/reset_database.php' );
92 require_once path_to( 'IAWP/queries/resources.php' );
93 require_once path_to( 'IAWP/queries/view.php' );
94 require_once path_to( 'IAWP/queries/views.php' );
95 require_once path_to( 'IAWP/queries/visitors_over_time_finder.php' );
96 // Load root files
97 require_once path_to( 'IAWP/campaign_builder.php' );
98 require_once path_to( 'IAWP/capability_manager.php' );
99 require_once path_to( 'IAWP/chart.php' );
100 require_once path_to( 'IAWP/chart_geo.php' );
101 require_once path_to( 'IAWP/chart_svg.php' );
102 require_once path_to( 'IAWP/dashboard_options.php' );
103 require_once path_to( 'IAWP/dashboard_widget.php' );
104 require_once path_to( 'IAWP/query.php' );
105 require_once path_to( 'IAWP/email_reports.php' );
106 require_once path_to( 'IAWP/filters.php' );
107 require_once path_to( 'IAWP/geo_database.php' );
108 require_once path_to( 'IAWP/geo_database_download_job.php' );
109 require_once path_to( 'IAWP/health_check.php' );
110 require_once path_to( 'IAWP/independent_analytics.php' );
111 require_once path_to( 'IAWP/known_referrers.php' );
112 require_once path_to( 'IAWP/pdf.php' );
113 require_once path_to( 'IAWP/quick_stats.php' );
114 require_once path_to( 'IAWP/real_time.php' );
115 require_once path_to( 'IAWP/rest_api.php' );
116 require_once path_to( 'IAWP/settings.php' );
117 require_once path_to( 'IAWP/tables/column.php' );
118 require_once path_to( 'IAWP/tables/table.php' );
119 require_once path_to( 'IAWP/tables/table_campaigns.php' );
120 require_once path_to( 'IAWP/tables/table_geo.php' );
121 require_once path_to( 'IAWP/tables/table_referrers.php' );
122 require_once path_to( 'IAWP/tables/table_views.php' );
123 require_once path_to( 'IAWP/track_resource_changes.php' );
124 require_once path_to( 'IAWP/view_counter.php' );
125 // Initialize independent analytics
126 function IAWP()
127 {
128 return Independent_Analytics::getInstance();
129 }
130
131 IAWP();
132 add_filter( 'pre_option_iawp_is_migrating', function ( $default ) {
133 global $wpdb ;
134 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", 'iawp_is_migrating' ) );
135
136 if ( is_object( $row ) ) {
137 $value = $row->option_value;
138 } else {
139 $value = $default;
140 }
141
142 return apply_filters( 'option_iawp_is_migrating', maybe_unserialize( $value ), 'iawp_is_migrating' );
143 } );
144 add_filter( 'pre_option_iawp_is_database_downloading', function ( $default ) {
145 global $wpdb ;
146 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", 'iawp_is_database_downloading' ) );
147
148 if ( is_object( $row ) ) {
149 $value = $row->option_value;
150 } else {
151 $value = $default;
152 }
153
154 return apply_filters( 'option_iawp_is_database_downloading', maybe_unserialize( $value ), 'iawp_is_database_downloading' );
155 } );
156 add_filter( 'pre_option_iawp_db_version', function ( $default ) {
157 global $wpdb ;
158 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", 'iawp_db_version' ) );
159
160 if ( is_object( $row ) ) {
161 $value = $row->option_value;
162 } else {
163 $value = $default;
164 }
165
166 return apply_filters( 'option_iawp_db_version', maybe_unserialize( $value ), 'iawp_db_version' );
167 } );
168 register_activation_hook( __DIR__ . '/iawp.php', function () {
169
170 if ( get_option( 'iawp_db_version', '0' ) === '0' ) {
171 // If there is no database installed, run migration on current process
172 Migrations\Migration::create_or_migrate();
173 } else {
174 // If there is a database, run migration in a background process
175 Migrations\Migration_Job::maybe_dispatch();
176 }
177
178 $geo_database = new Geo_Database();
179 $geo_database->maybe_download();
180 update_option( 'iawp_need_clear_cache', true );
181 } );
182 register_deactivation_hook( __DIR__ . '/iawp.php', function () {
183 } );
184 /*
185 * The admin_init hook will fire when the dashboard is loaded or an admin ajax request is made
186 */
187 add_action( 'admin_init', function () {
188 new Migrations\Migration_Job();
189
190 if ( get_option( 'iawp_db_version', '0' ) === '0' ) {
191 // If there is no database installed, run migration on current process
192 Migrations\Migration::create_or_migrate();
193 } else {
194 // If there is a database, run migration in a background process
195 Migrations\Migration_Job::maybe_dispatch();
196 }
197
198 $geo_database = new Geo_Database();
199 $geo_database->maybe_download();
200 } );
201 // Since WC 4.3.0
202 add_action( 'woocommerce_checkout_order_created', function ( $order ) {
203 global $wpdb ;
204 $visitor = new Visitor( Request::ip(), Request::user_agent() );
205 $views_table = Query::get_table_name( Query::VIEWS );
206 $sessions_table = Query::get_table_name( Query::SESSIONS );
207 $view = $wpdb->get_row( $wpdb->prepare( "SELECT views.id as id FROM {$views_table} AS views LEFT JOIN {$sessions_table} AS sessions ON sessions.session_id = views.session_id WHERE sessions.visitor_id = %s ORDER BY views.viewed_at DESC LIMIT 1", $visitor->id() ) );
208
209 if ( isset( $view ) ) {
210 $wc_orders_table = Query::get_table_name( Query::WC_ORDERS );
211 $wpdb->insert( $wc_orders_table, [
212 'view_id' => $view->id,
213 'order_id' => $order->id,
214 'created_at' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ),
215 ] );
216 }
217
218 } );