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