PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.17.1
Independent Analytics – WordPress Analytics Plugin v1.17.1
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
217 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.1' );
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/current_traffic_finder.php' );
88 require_once path_to( 'IAWP/queries/geos.php' );
89 require_once path_to( 'IAWP/queries/referrers.php' );
90 require_once path_to( 'IAWP/queries/reset_database.php' );
91 require_once path_to( 'IAWP/queries/resources.php' );
92 require_once path_to( 'IAWP/queries/view.php' );
93 require_once path_to( 'IAWP/queries/views.php' );
94 require_once path_to( 'IAWP/queries/visitors_over_time_finder.php' );
95 // Load root files
96 require_once path_to( 'IAWP/campaign_builder.php' );
97 require_once path_to( 'IAWP/capability_manager.php' );
98 require_once path_to( 'IAWP/chart.php' );
99 require_once path_to( 'IAWP/chart_geo.php' );
100 require_once path_to( 'IAWP/chart_svg.php' );
101 require_once path_to( 'IAWP/dashboard_options.php' );
102 require_once path_to( 'IAWP/dashboard_widget.php' );
103 require_once path_to( 'IAWP/query.php' );
104 require_once path_to( 'IAWP/email_reports.php' );
105 require_once path_to( 'IAWP/filters.php' );
106 require_once path_to( 'IAWP/geo_database.php' );
107 require_once path_to( 'IAWP/geo_database_download_job.php' );
108 require_once path_to( 'IAWP/health_check.php' );
109 require_once path_to( 'IAWP/independent_analytics.php' );
110 require_once path_to( 'IAWP/known_referrers.php' );
111 require_once path_to( 'IAWP/pdf.php' );
112 require_once path_to( 'IAWP/quick_stats.php' );
113 require_once path_to( 'IAWP/real_time.php' );
114 require_once path_to( 'IAWP/rest_api.php' );
115 require_once path_to( 'IAWP/settings.php' );
116 require_once path_to( 'IAWP/tables/column.php' );
117 require_once path_to( 'IAWP/tables/table.php' );
118 require_once path_to( 'IAWP/tables/table_campaigns.php' );
119 require_once path_to( 'IAWP/tables/table_geo.php' );
120 require_once path_to( 'IAWP/tables/table_referrers.php' );
121 require_once path_to( 'IAWP/tables/table_views.php' );
122 require_once path_to( 'IAWP/track_resource_changes.php' );
123 require_once path_to( 'IAWP/view_counter.php' );
124 // Initialize independent analytics
125 function IAWP()
126 {
127 return Independent_Analytics::getInstance();
128 }
129
130 IAWP();
131 add_filter( 'pre_option_iawp_is_migrating', function ( $default ) {
132 global $wpdb ;
133 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", 'iawp_is_migrating' ) );
134
135 if ( is_object( $row ) ) {
136 $value = $row->option_value;
137 } else {
138 $value = $default;
139 }
140
141 return apply_filters( 'option_iawp_is_migrating', maybe_unserialize( $value ), 'iawp_is_migrating' );
142 } );
143 add_filter( 'pre_option_iawp_is_database_downloading', function ( $default ) {
144 global $wpdb ;
145 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", 'iawp_is_database_downloading' ) );
146
147 if ( is_object( $row ) ) {
148 $value = $row->option_value;
149 } else {
150 $value = $default;
151 }
152
153 return apply_filters( 'option_iawp_is_database_downloading', maybe_unserialize( $value ), 'iawp_is_database_downloading' );
154 } );
155 add_filter( 'pre_option_iawp_db_version', function ( $default ) {
156 global $wpdb ;
157 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", 'iawp_db_version' ) );
158
159 if ( is_object( $row ) ) {
160 $value = $row->option_value;
161 } else {
162 $value = $default;
163 }
164
165 return apply_filters( 'option_iawp_db_version', maybe_unserialize( $value ), 'iawp_db_version' );
166 } );
167 register_activation_hook( __DIR__ . '/iawp.php', function () {
168
169 if ( get_option( 'iawp_db_version', '0' ) === '0' ) {
170 // If there is no database installed, run migration on current process
171 Migrations\Migration::create_or_migrate();
172 } else {
173 // If there is a database, run migration in a background process
174 Migrations\Migration_Job::maybe_dispatch();
175 }
176
177 $geo_database = new Geo_Database();
178 $geo_database->maybe_download();
179 update_option( 'iawp_need_clear_cache', true );
180 } );
181 register_deactivation_hook( __DIR__ . '/iawp.php', function () {
182 } );
183 /*
184 * The admin_init hook will fire when the dashboard is loaded or an admin ajax request is made
185 */
186 add_action( 'admin_init', function () {
187 new Migrations\Migration_Job();
188
189 if ( get_option( 'iawp_db_version', '0' ) === '0' ) {
190 // If there is no database installed, run migration on current process
191 Migrations\Migration::create_or_migrate();
192 } else {
193 // If there is a database, run migration in a background process
194 Migrations\Migration_Job::maybe_dispatch();
195 }
196
197 $geo_database = new Geo_Database();
198 $geo_database->maybe_download();
199 } );
200 // Since WC 4.3.0
201 add_action( 'woocommerce_checkout_order_created', function ( $order ) {
202 global $wpdb ;
203 $visitor = new Visitor( Request::ip(), Request::user_agent() );
204 $views_table = Query::get_table_name( Query::VIEWS );
205 $sessions_table = Query::get_table_name( Query::SESSIONS );
206 $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() ) );
207
208 if ( isset( $view ) ) {
209 $wc_orders_table = Query::get_table_name( Query::WC_ORDERS );
210 $wpdb->insert( $wc_orders_table, [
211 'view_id' => $view->id,
212 'order_id' => $order->id,
213 'created_at' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ),
214 ] );
215 }
216
217 } );