PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.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 sql 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
278 lines
1 <?php
2
3 namespace IAWP_SCOPED;
4
5 use IAWP_SCOPED\eftec\bladeone\BladeOne ;
6 use IAWP_SCOPED\IAWP\Dashboard_Options ;
7 use IAWP_SCOPED\IAWP\Date_Range\Exact_Date_Range ;
8 use IAWP_SCOPED\IAWP\Env ;
9 use IAWP_SCOPED\IAWP\Geo_Database_Background_Job ;
10 use IAWP_SCOPED\IAWP\Independent_Analytics ;
11 use IAWP_SCOPED\IAWP\Interrupt ;
12 use IAWP_SCOPED\IAWP\Migrations ;
13 use IAWP_SCOPED\IAWP\Public_API\Analytics ;
14 use IAWP_SCOPED\IAWP\Public_API\Singular_Analytics ;
15 use IAWP_SCOPED\IAWP\WP_Option_Cache_Bust ;
16 \define( 'IAWP_DIRECTORY', \rtrim( \plugin_dir_path( __FILE__ ), \DIRECTORY_SEPARATOR ) );
17 \define( 'IAWP_URL', \rtrim( \plugin_dir_url( __FILE__ ), '/' ) );
18 \define( 'IAWP_VERSION', '2.2.0' );
19 \define( 'IAWP_SCOPED\\IAWP_DATABASE_VERSION', '27' );
20 \define( 'IAWP_LANGUAGES_DIRECTORY', \dirname( \plugin_basename( __FILE__ ) ) . '/languages' );
21 \define( 'IAWP_SCOPED\\IAWP_PLUGIN_FILE', __DIR__ . '/iawp.php' );
22
23 if ( \file_exists( \IAWP_SCOPED\iawp_path_to( 'vendor/scoper-autoload.php' ) ) ) {
24 require_once \IAWP_SCOPED\iawp_path_to( 'vendor/scoper-autoload.php' );
25 } else {
26 require_once \IAWP_SCOPED\iawp_path_to( 'vendor/autoload.php' );
27 }
28
29 /**
30 * @param $log
31 *
32 * @return void
33 * @internal
34 */
35 function iawp_log( $log ) : void
36 {
37 if ( \WP_DEBUG === \true && \WP_DEBUG_LOG === \true ) {
38
39 if ( \is_array( $log ) || \is_object( $log ) ) {
40 \error_log( \print_r( $log, \true ) );
41 } else {
42 \error_log( $log );
43 }
44
45 }
46 }
47
48 /** @internal */
49 function iawp_path_to( string $path ) : string
50 {
51 $path = \trim( $path, \DIRECTORY_SEPARATOR );
52 return \implode( \DIRECTORY_SEPARATOR, [ \IAWP_DIRECTORY, $path ] );
53 }
54
55 /**
56 * add_filter('iawp_temp_directory_path', function ($value) {
57 * return '/Users/andrew/site/wp-content/uploads/iawp';
58 * });
59 *
60 * @param string $path
61 *
62 * @return string
63 * @throws Exception
64 * @internal
65 */
66 function iawp_temp_path_to( string $path ) : string
67 {
68 $temp_directory = \apply_filters( 'iawp_temp_directory_path', 'temp' );
69 $path = \rtrim( $path, \DIRECTORY_SEPARATOR );
70 if ( $temp_directory === 'temp' ) {
71 return \IAWP_SCOPED\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 {
87 $path = \trim( $path, '/' );
88 return \implode( '/', [ \IAWP_URL, $path ] );
89 }
90
91 /** @internal */
92 function iawp_upload_path_to( string $path ) : string
93 {
94 $path = \trim( $path, \DIRECTORY_SEPARATOR );
95 return \implode( \DIRECTORY_SEPARATOR, [ \wp_upload_dir()['basedir'], $path ] );
96 }
97
98 /**
99 * Determines if the user is running a licensed pro version
100 *
101 * @return bool
102 * @internal
103 */
104 function iawp_is_pro() : bool
105 {
106 return \false;
107 }
108
109 /**
110 * Determines if the user is running a free version or an unlicensed pro version
111 * @return bool
112 * @internal
113 */
114 function iawp_is_free() : bool
115 {
116 return !\IAWP_SCOPED\iawp_is_pro();
117 }
118
119 /**
120 * Determines if a pro user has WooCommerce activated
121 * @return bool
122 * @internal
123 */
124 function iawp_using_woocommerce() : bool
125 {
126 global $wpdb ;
127 if ( \IAWP_SCOPED\iawp_is_free() ) {
128 return \false;
129 }
130 $class_missing = \class_exists( '\\WooCommerce' ) === \false;
131 if ( $class_missing ) {
132 return \false;
133 }
134 $table_name = $wpdb->prefix . 'wc_order_stats';
135 $order_stats_table = $wpdb->get_row( $wpdb->prepare( '
136 SELECT * FROM INFORMATION_SCHEMA.TABLES
137 WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s
138 ', $wpdb->dbname, $table_name ) );
139 if ( \is_null( $order_stats_table ) ) {
140 return \false;
141 }
142 return \true;
143 }
144
145 /** @internal */
146 function iawp_dashboard_url( array $query_arguments = [] ) : string
147 {
148 $default_query_arguments = [
149 'page' => 'independent-analytics',
150 ];
151 return \add_query_arg( \array_merge( $default_query_arguments, $query_arguments ), \admin_url( 'admin.php' ) );
152 }
153
154 /** @internal */
155 function iawp_blade() : BladeOne
156 {
157 if ( !\file_exists( \IAWP_SCOPED\iawp_temp_path_to( 'template-cache' ) ) ) {
158 \wp_mkdir_p( \IAWP_SCOPED\iawp_temp_path_to( 'template-cache' ) );
159 }
160 $blade = new BladeOne( \IAWP_SCOPED\iawp_path_to( 'views' ), \IAWP_SCOPED\iawp_temp_path_to( 'template-cache' ) );
161 $blade->share( 'env', new Env() );
162 return $blade;
163 }
164
165 /**
166 * iawp_singular_analytics('60', new DateTime('-3 days'), new DateTime());
167 *
168 * @param string|int $singular_id
169 * @param DateTime $from
170 * @param DateTime $to
171 *
172 * @return Singular_Analytics|null
173 * @internal
174 */
175 function iawp_singular_analytics( $singular_id, \DateTime $from, \DateTime $to ) : ?Singular_Analytics
176 {
177 $date_range = new Exact_Date_Range( $from, $to );
178 return Singular_Analytics::for( $singular_id, $date_range );
179 }
180
181 /**
182 * iawp_analytics(new DateTime('-3 days'), new DateTime());
183 *
184 * @param DateTime $from
185 * @param DateTime $to
186 *
187 * @return Analytics
188 * @internal
189 */
190 function iawp_analytics( \DateTime $from, \DateTime $to ) : Analytics
191 {
192 $date_range = new Exact_Date_Range( $from, $to );
193 return Analytics::for( $date_range );
194 }
195
196
197 if ( !\extension_loaded( 'pdo' ) || !\extension_loaded( 'pdo_mysql' ) ) {
198 $interrupt = new Interrupt( 'interrupt.pdo', \false );
199 $interrupt->render();
200 return;
201 }
202
203 global $wpdb ;
204
205 if ( \strlen( $wpdb->prefix ) > 25 ) {
206 $interrupt = new Interrupt( 'interrupt.database-prefix-too-long', \false );
207 $interrupt->render( [
208 'prefix' => $wpdb->prefix,
209 'length' => \strlen( $wpdb->prefix ),
210 ] );
211 return;
212 }
213
214
215 if ( Migrations\Migrations::is_database_ahead_of_plugin() ) {
216 $interrupt = new Interrupt( 'interrupt.database-ahead-of-plugin', \false );
217 $interrupt->render();
218 return;
219 }
220
221 WP_Option_Cache_Bust::register( 'iawp_is_migrating' );
222 WP_Option_Cache_Bust::register( 'iawp_is_database_downloading' );
223 WP_Option_Cache_Bust::register( 'iawp_db_version' );
224 WP_Option_Cache_Bust::register( 'iawp_geo_database_version' );
225 /** @internal */
226 function iawp()
227 {
228 return Independent_Analytics::getInstance();
229 }
230
231 \IAWP_SCOPED\iawp();
232 \register_activation_hook( \IAWP_SCOPED\IAWP_PLUGIN_FILE, function () {
233 \wp_mkdir_p( \IAWP_SCOPED\iawp_temp_path_to( 'template-cache' ) );
234 \wp_mkdir_p( \IAWP_SCOPED\iawp_temp_path_to( 'device-data-cache' ) );
235
236 if ( \get_option( 'iawp_db_version', '0' ) === '0' ) {
237 // If there is no database installed, run migration on current process
238 Migrations\Migrations::create_or_migrate();
239 } else {
240 // If there is a database, run migration in a background process
241 Migrations\Migration_Job::maybe_dispatch();
242 }
243
244 Geo_Database_Background_Job::maybe_dispatch();
245 \update_option( 'iawp_need_clear_cache', \true );
246 \IAWP_SCOPED\iawp()->cron_manager->schedule_refresh_salt();
247 if ( \IAWP_SCOPED\iawp_is_pro() ) {
248 \IAWP_SCOPED\iawp()->email_reports->schedule_email_report();
249 }
250 } );
251 \register_deactivation_hook( \IAWP_SCOPED\IAWP_PLUGIN_FILE, function () {
252 \IAWP_SCOPED\iawp()->cron_manager->unschedule_daily_salt_refresh();
253 if ( \IAWP_SCOPED\iawp_is_pro() ) {
254 \IAWP_SCOPED\iawp()->email_reports->unschedule_email_report();
255 }
256 \wp_delete_file( \trailingslashit( \WPMU_PLUGIN_DIR ) . 'iawp-performance-boost.php' );
257 \delete_option( 'iawp_must_use_directory_not_writable' );
258 } );
259 /*
260 * The admin_init hook will fire when the dashboard is loaded or an admin ajax request is made
261 */
262 \add_action( 'admin_init', function () {
263 Migrations\Migrations::handle_migration_18_error();
264 Migrations\Migrations::handle_migration_22_error();
265 $options = new Dashboard_Options();
266 $options->maybe_redirect();
267 new Migrations\Migration_Job();
268
269 if ( \get_option( 'iawp_db_version', '0' ) === '0' ) {
270 // If there is no database installed, run migration on current process
271 Migrations\Migrations::create_or_migrate();
272 } else {
273 // If there is a database, run migration in a background process
274 Migrations\Migration_Job::maybe_dispatch();
275 }
276
277 Geo_Database_Background_Job::maybe_dispatch();
278 } );