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