PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.4.2
Independent Analytics – WordPress Analytics Plugin v2.4.2
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 / iawp-bootstrap.php
independent-analytics Last commit date
IAWP 2 years ago dist 2 years ago freemius 2 years ago img 2 years ago languages 2 years ago vendor 2 years ago views 2 years ago iawp-bootstrap.php 2 years ago iawp.php 2 years ago readme.txt 2 years ago
iawp-bootstrap.php
305 lines
1 <?php
2
3 namespace IAWPSCOPED;
4
5 use IAWP\Custom_WordPress_Columns\Views_Column;
6 use IAWP\Dashboard_Options;
7 use IAWP\Database;
8 use IAWP\Date_Range\Exact_Date_Range;
9 use IAWP\Env;
10 use IAWP\Geo_Database_Background_Job;
11 use IAWP\Independent_Analytics;
12 use IAWP\Interrupt;
13 use IAWP\Migrations;
14 use IAWP\Public_API\Analytics;
15 use IAWP\Public_API\Singular_Analytics;
16 use IAWP\Utils\BladeOne;
17 use IAWP\WP_Option_Cache_Bust;
18 \define( 'IAWP_DIRECTORY', \rtrim( \plugin_dir_path( __FILE__ ), \DIRECTORY_SEPARATOR ) );
19 \define( 'IAWP_URL', \rtrim( \plugin_dir_url( __FILE__ ), '/' ) );
20 \define( 'IAWP_VERSION', '2.4.2' );
21 \define( 'IAWP_DATABASE_VERSION', '30' );
22 \define( 'IAWP_LANGUAGES_DIRECTORY', \dirname( \plugin_basename( __FILE__ ) ) . '/languages' );
23 \define( 'IAWP_PLUGIN_FILE', __DIR__ . '/iawp.php' );
24 if ( \file_exists( \IAWPSCOPED\iawp_path_to( 'vendor/scoper-autoload.php' ) ) ) {
25 require_once \IAWPSCOPED\iawp_path_to( 'vendor/scoper-autoload.php' );
26 } else {
27 require_once \IAWPSCOPED\iawp_path_to( 'vendor/autoload.php' );
28 }
29 // This is needed because something with age gate is preventing my own helpers from loading
30 // The problem is that in autoload_static.php, there's some sort of caching going on where it's trying
31 // to not load a file twice. I'm guessing that's normally a good thing, but in our case we've made changes (scoped)
32 // so we do indeed want to load our version even though age gate has alreawdy learned
33 require_once \IAWPSCOPED\iawp_path_to( 'vendor/illuminate/collections/helpers.php' );
34 /**
35 * @param $log
36 *
37 * @return void
38 * @internal
39 */
40 function iawp_log( $log ) : void {
41 if ( \WP_DEBUG === \true && \WP_DEBUG_LOG === \true ) {
42 if ( \is_array( $log ) || \is_object( $log ) ) {
43 \error_log( \print_r( $log, \true ) );
44 } else {
45 \error_log( $log );
46 }
47 }
48 }
49
50 /** @internal */
51 function iawp_path_to( string $path ) : string {
52 $path = \trim( $path, \DIRECTORY_SEPARATOR );
53 return \implode( \DIRECTORY_SEPARATOR, [\IAWP_DIRECTORY, $path] );
54 }
55
56 /**
57 * add_filter('iawp_temp_directory_path', function ($value) {
58 * return '/Users/andrew/site/wp-content/uploads/iawp';
59 * });
60 *
61 * @param string $path
62 *
63 * @return string
64 * @throws Exception
65 * @internal
66 */
67 function iawp_temp_path_to( string $path ) : string {
68 $temp_directory = ( \defined( 'IAWP_TEMP_DIR' ) ? \IAWP_TEMP_DIR : \apply_filters( 'iawp_temp_directory_path', 'temp' ) );
69 $path = \rtrim( $path, \DIRECTORY_SEPARATOR );
70 if ( $temp_directory === 'temp' ) {
71 return \IAWPSCOPED\iawp_path_to( \implode( \DIRECTORY_SEPARATOR, [$temp_directory, $path] ) );
72 }
73 $temp_directory = \rtrim( $temp_directory, \DIRECTORY_SEPARATOR );
74 if ( !\is_writable( $temp_directory ) ) {
75 \wp_mkdir_p( $temp_directory );
76 }
77 // Separate condition to see if wp_mkdir_p call fixed the issue
78 if ( !\is_writable( $temp_directory ) ) {
79 throw new \Exception('You have provided and missing or non-writable directory for the iawp_temp_directory_path filter: ' . $temp_directory);
80 }
81 return \implode( \DIRECTORY_SEPARATOR, [$temp_directory, $path] );
82 }
83
84 /** @internal */
85 function iawp_url_to( string $path ) : string {
86 $path = \trim( $path, '/' );
87 return \implode( '/', [\IAWP_URL, $path] );
88 }
89
90 /**
91 * @param string $path
92 * @param bool $prefer_parent_site_upload_path If it's a multisite installation, use the parent sites upload folder
93 * @return string
94 * @internal
95 */
96 function iawp_upload_path_to( string $path, bool $prefer_parent_site_upload_path = \false ) : string {
97 $path = \trim( $path, \DIRECTORY_SEPARATOR );
98 $upload_directory = \wp_upload_dir()['basedir'];
99 if ( $prefer_parent_site_upload_path && \is_multisite() ) {
100 $site = \get_site();
101 if ( $site !== null ) {
102 \switch_to_blog( \intval( $site->site_id ) );
103 $upload_directory = \wp_upload_dir()['basedir'];
104 \restore_current_blog();
105 }
106 }
107 return \implode( \DIRECTORY_SEPARATOR, [$upload_directory, $path] );
108 }
109
110 /**
111 * Determines if the user is running a licensed pro version
112 *
113 * @return bool
114 * @internal
115 */
116 function iawp_is_pro() : bool {
117 return \false;
118 }
119
120 /**
121 * Determines if the user is running a free version or an unlicensed pro version
122 * @return bool
123 * @internal
124 */
125 function iawp_is_free() : bool {
126 return !\IAWPSCOPED\iawp_is_pro();
127 }
128
129 /**
130 * Determines if a pro user has WooCommerce activated
131 * @return bool
132 * @internal
133 */
134 function iawp_using_woocommerce() : bool {
135 global $wpdb;
136 if ( \IAWPSCOPED\iawp_is_free() ) {
137 return \false;
138 }
139 $class_missing = \class_exists( '\\WooCommerce' ) === \false;
140 if ( $class_missing ) {
141 return \false;
142 }
143 $table_name = $wpdb->prefix . 'wc_order_stats';
144 $order_stats_table = $wpdb->get_row( $wpdb->prepare( '
145 SELECT * FROM INFORMATION_SCHEMA.TABLES
146 WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s
147 ', $wpdb->dbname, $table_name ) );
148 if ( \is_null( $order_stats_table ) ) {
149 return \false;
150 }
151 return \true;
152 }
153
154 /** @internal */
155 function iawp_dashboard_url( array $query_arguments = [] ) : string {
156 $default_query_arguments = [
157 'page' => 'independent-analytics',
158 ];
159 return \add_query_arg( \array_merge( $default_query_arguments, $query_arguments ), \admin_url( 'admin.php' ) );
160 }
161
162 /** @internal */
163 function iawp_blade() {
164 if ( !\file_exists( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) ) ) {
165 \wp_mkdir_p( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) );
166 }
167 $blade = BladeOne::create();
168 $blade->share( 'env', new Env() );
169 return $blade;
170 }
171
172 /**
173 * Get the currently installed database version
174 *
175 * @return int
176 * @internal
177 */
178 function iawp_db_version() : int {
179 return \intval( \get_option( 'iawp_db_version', '0' ) );
180 }
181
182 /**
183 * iawp_singular_analytics('60', new DateTime('-3 days'), new DateTime());
184 *
185 * @param string|int $singular_id
186 * @param DateTime $from
187 * @param DateTime $to
188 *
189 * @return Singular_Analytics|null
190 * @internal
191 */
192 function iawp_singular_analytics( $singular_id, \DateTime $from, \DateTime $to ) : ?Singular_Analytics {
193 $date_range = new Exact_Date_Range($from, $to);
194 return Singular_Analytics::for( $singular_id, $date_range );
195 }
196
197 /**
198 * iawp_analytics(new DateTime('-3 days'), new DateTime());
199 *
200 * @param DateTime $from
201 * @param DateTime $to
202 *
203 * @return Analytics
204 * @internal
205 */
206 function iawp_analytics( \DateTime $from, \DateTime $to ) : Analytics {
207 $date_range = new Exact_Date_Range($from, $to);
208 return Analytics::for( $date_range );
209 }
210
211 if ( !\extension_loaded( 'pdo' ) || !\extension_loaded( 'pdo_mysql' ) ) {
212 $interrupt = new Interrupt('interrupt.pdo');
213 $interrupt->render();
214 return;
215 }
216 global $wpdb;
217 if ( \strlen( $wpdb->prefix ) > 25 ) {
218 $interrupt = new Interrupt('interrupt.database-prefix-too-long');
219 $interrupt->render( [
220 'prefix' => $wpdb->prefix,
221 'length' => \strlen( $wpdb->prefix ),
222 ] );
223 return;
224 }
225 if ( Migrations\Migrations::is_database_ahead_of_plugin() ) {
226 $interrupt = new Interrupt('interrupt.database-ahead-of-plugin');
227 $interrupt->render();
228 return;
229 }
230 if ( \IAWPSCOPED\iawp_db_version() === 0 && !Database::has_correct_database_privileges() ) {
231 $interrupt = new Interrupt('interrupt.missing-database-permissions');
232 $interrupt->render( [
233 'missing_privileges' => Database::missing_database_privileges(),
234 ] );
235 return;
236 }
237 if ( \get_option( 'iawp_missing_tables' ) === '1' ) {
238 if ( \IAWPSCOPED\iawp_db_version() === 0 ) {
239 \delete_option( 'iawp_missing_tables' );
240 } else {
241 $interrupt = new Interrupt('interrupt.missing-database-tables');
242 $interrupt->render();
243 return;
244 }
245 }
246 // These can be updated in background jobs. Always get the actual value from the database.
247 WP_Option_Cache_Bust::register( 'iawp_is_migrating' );
248 WP_Option_Cache_Bust::register( 'iawp_is_database_downloading' );
249 WP_Option_Cache_Bust::register( 'iawp_db_version' );
250 WP_Option_Cache_Bust::register( 'iawp_geo_database_version' );
251 /** @internal */
252 function iawp() {
253 return Independent_Analytics::getInstance();
254 }
255
256 \IAWPSCOPED\iawp();
257 \register_activation_hook( \IAWP_PLUGIN_FILE, function () {
258 \wp_mkdir_p( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) );
259 if ( \IAWPSCOPED\iawp_db_version() === 0 ) {
260 // If there is no database installed, run migration on current process
261 Migrations\Migrations::create_or_migrate();
262 } else {
263 // If there is a database, run migration in a background process
264 Migrations\Migration_Job::maybe_dispatch();
265 }
266 Geo_Database_Background_Job::maybe_dispatch();
267 \update_option( 'iawp_need_clear_cache', \true );
268 \IAWPSCOPED\iawp()->cron_manager->schedule_refresh_salt();
269 if ( \IAWPSCOPED\iawp_is_pro() ) {
270 \IAWPSCOPED\iawp()->email_reports->schedule_email_report();
271 }
272 // Set current version for changelog notifications
273 \update_option( 'iawp_last_update_viewed', \IAWP_VERSION );
274 if ( \IAWPSCOPED\iawp_db_version() > 0 && Database::is_missing_all_tables() ) {
275 \update_option( 'iawp_missing_tables', '1' );
276 }
277 } );
278 \register_deactivation_hook( \IAWP_PLUGIN_FILE, function () {
279 \IAWPSCOPED\iawp()->cron_manager->unschedule_daily_salt_refresh();
280 if ( \IAWPSCOPED\iawp_is_pro() ) {
281 \IAWPSCOPED\iawp()->email_reports->unschedule_email_report();
282 }
283 \wp_delete_file( \trailingslashit( \WPMU_PLUGIN_DIR ) . 'iawp-performance-boost.php' );
284 \delete_option( 'iawp_must_use_directory_not_writable' );
285 } );
286 /*
287 * The admin_init hook will fire when the dashboard is loaded or an admin ajax request is made
288 */
289 \add_action( 'admin_init', function () {
290 Migrations\Migrations::handle_migration_18_error();
291 Migrations\Migrations::handle_migration_22_error();
292 Migrations\Migrations::handle_migration_29_error();
293 $options = new Dashboard_Options();
294 $options->maybe_redirect();
295 new Migrations\Migration_Job();
296 if ( \get_option( 'iawp_db_version', '0' ) === '0' ) {
297 // If there is no database installed, run migration on current process
298 Migrations\Migrations::create_or_migrate();
299 } else {
300 // If there is a database, run migration in a background process
301 Migrations\Migration_Job::maybe_dispatch();
302 }
303 Geo_Database_Background_Job::maybe_dispatch();
304 } );
305 Views_Column::initialize();