PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.11.1
Independent Analytics – WordPress Analytics Plugin v2.11.1
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 1 year ago dist 1 year ago freemius 1 year ago img 1 year ago javascript-source 1 year ago languages 1 year ago vendor 1 year ago views 1 year ago iawp-bootstrap.php 1 year ago iawp-click-endpoint.php 1 year ago iawp.php 1 year ago readme.txt 1 year ago
iawp-bootstrap.php
357 lines
1 <?php
2
3 namespace IAWPSCOPED;
4
5 use IAWP\Click_Tracking\Click_Processing_Job;
6 use IAWP\Click_Tracking\Config_File_Manager;
7 use IAWP\Custom_WordPress_Columns\Views_Column;
8 use IAWP\Dashboard_Options;
9 use IAWP\Data_Pruning\Pruning_Scheduler;
10 use IAWP\Database;
11 use IAWP\Date_Range\Exact_Date_Range;
12 use IAWP\Ecommerce\SureCart_Event_Sync_Job;
13 use IAWP\Ecommerce\SureCart_Store;
14 use IAWP\Env;
15 use IAWP\Geo_Database_Background_Job;
16 use IAWP\Independent_Analytics;
17 use IAWP\Interrupt;
18 use IAWP\MainWP;
19 use IAWP\Migration_Fixer_Job;
20 use IAWP\Migrations;
21 use IAWP\Overview\Module_Refresh_Job;
22 use IAWP\Overview\Modules\Module;
23 use IAWP\Patch;
24 use IAWP\Public_API\Analytics;
25 use IAWP\Public_API\Singular_Analytics;
26 use IAWP\Utils\BladeOne;
27 use IAWP\WP_Option_Cache_Bust;
28 \define( 'IAWP_DIRECTORY', \rtrim( \plugin_dir_path( __FILE__ ), \DIRECTORY_SEPARATOR ) );
29 \define( 'IAWP_URL', \rtrim( \plugin_dir_url( __FILE__ ), '/' ) );
30 \define( 'IAWP_VERSION', '2.11.1' );
31 \define( 'IAWP_DATABASE_VERSION', '43' );
32 \define( 'IAWP_LANGUAGES_DIRECTORY', \dirname( \plugin_basename( __FILE__ ) ) . '/languages' );
33 \define( 'IAWP_PLUGIN_FILE', __DIR__ . '/iawp.php' );
34 if ( \file_exists( \IAWPSCOPED\iawp_path_to( 'vendor/scoper-autoload.php' ) ) ) {
35 require_once \IAWPSCOPED\iawp_path_to( 'vendor/scoper-autoload.php' );
36 } else {
37 require_once \IAWPSCOPED\iawp_path_to( 'vendor/autoload.php' );
38 }
39 /**
40 * @param $log
41 *
42 * @return void
43 * @internal
44 */
45 function iawp_log( $log ) : void {
46 if ( \WP_DEBUG === \true && \WP_DEBUG_LOG === \true ) {
47 if ( \is_array( $log ) || \is_object( $log ) ) {
48 \error_log( \print_r( $log, \true ) );
49 } else {
50 \error_log( $log );
51 }
52 }
53 }
54
55 /** @internal */
56 function iawp_path_to( string $path ) : string {
57 $path = \trim( $path, \DIRECTORY_SEPARATOR );
58 return \implode( \DIRECTORY_SEPARATOR, [\IAWP_DIRECTORY, $path] );
59 }
60
61 /** @internal */
62 function iawp_url_to( string $path ) : string {
63 $path = \trim( $path, '/' );
64 return \implode( '/', [\IAWP_URL, $path] );
65 }
66
67 /**
68 * add_filter('iawp_temp_directory_path', function ($value) {
69 * return '/Users/andrew/site/wp-content/uploads/iawp';
70 * });
71 *
72 * @param string $path
73 *
74 * @return string
75 * @throws Exception
76 * @internal
77 */
78 function iawp_temp_path_to( string $path ) : string {
79 $temp_directory = ( \defined( 'IAWP_TEMP_DIR' ) ? \IAWP_TEMP_DIR : \apply_filters( 'iawp_temp_directory_path', 'temp' ) );
80 $path = \rtrim( $path, \DIRECTORY_SEPARATOR );
81 if ( $temp_directory === 'temp' ) {
82 return \IAWPSCOPED\iawp_path_to( \implode( \DIRECTORY_SEPARATOR, [$temp_directory, $path] ) );
83 }
84 $temp_directory = \rtrim( $temp_directory, \DIRECTORY_SEPARATOR );
85 if ( !\is_writable( $temp_directory ) ) {
86 \wp_mkdir_p( $temp_directory );
87 // Separate condition to see if wp_mkdir_p call fixed the issue
88 if ( !\is_writable( $temp_directory ) ) {
89 throw new \Exception('The temp directory set with the iawp_temp_directory_path filter is missing or is not writable: ' . $temp_directory);
90 }
91 }
92 return \implode( \DIRECTORY_SEPARATOR, [$temp_directory, $path] );
93 }
94
95 /**
96 * @param string $path
97 * @param bool $prefer_parent_site_upload_path If it's a multisite installation, use the parent sites upload folder
98 * @return string
99 * @internal
100 */
101 function iawp_upload_path_to( string $path, bool $prefer_parent_site_upload_path = \false ) : string {
102 $path = \trim( $path, \DIRECTORY_SEPARATOR );
103 $upload_directory = \wp_upload_dir()['basedir'];
104 if ( $prefer_parent_site_upload_path && \is_multisite() ) {
105 $site = \get_site();
106 if ( $site !== null ) {
107 \switch_to_blog( \intval( $site->site_id ) );
108 $upload_directory = \wp_upload_dir()['basedir'];
109 \restore_current_blog();
110 }
111 }
112 return \implode( \DIRECTORY_SEPARATOR, [$upload_directory, $path] );
113 }
114
115 /** @internal */
116 function iawp_upload_url_to( string $path ) : string {
117 $upload_url = \wp_upload_dir()['baseurl'];
118 $path = \trim( $path, '/' );
119 return \implode( '/', [$upload_url, $path] );
120 }
121
122 /**
123 * Determines if the user is running a licensed pro version
124 *
125 * @return bool
126 * @internal
127 */
128 function iawp_is_pro() : bool {
129 return \false;
130 }
131
132 /**
133 * Determines if the user is running a free version or an unlicensed pro version
134 * @return bool
135 * @internal
136 */
137 function iawp_is_free() : bool {
138 return !\IAWPSCOPED\iawp_is_pro();
139 }
140
141 /** @internal */
142 function iawp_dashboard_url( array $query_arguments = [] ) : string {
143 $default_query_arguments = [
144 'page' => 'independent-analytics',
145 ];
146 return \add_query_arg( \array_merge( $default_query_arguments, $query_arguments ), \admin_url( 'admin.php' ) );
147 }
148
149 /** @internal */
150 function iawp_blade() {
151 if ( !\file_exists( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) ) ) {
152 \wp_mkdir_p( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) );
153 }
154 $blade = BladeOne::create();
155 $blade->share( 'env', new Env() );
156 return $blade;
157 }
158
159 /** @internal */
160 function iawp_render( string $view, array $variables = [] ) : string {
161 if ( !\file_exists( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) ) ) {
162 \wp_mkdir_p( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) );
163 }
164 $blade = BladeOne::create();
165 $blade->share( 'env', new Env() );
166 return $blade->run( $view, $variables );
167 }
168
169 /** @internal */
170 function iawp_icon( string $icon ) : string {
171 try {
172 return \IAWPSCOPED\iawp_blade()->run( 'icons.plugins.' . $icon );
173 } catch ( \Throwable $e ) {
174 return '';
175 }
176 }
177
178 /**
179 * Get the currently installed database version
180 *
181 * @return int
182 * @internal
183 */
184 function iawp_db_version() : int {
185 return \intval( \get_option( 'iawp_db_version', '0' ) );
186 }
187
188 /** @internal */
189 function iawp_intify( $value ) {
190 if ( \is_string( $value ) && \ctype_digit( $value ) ) {
191 return \intval( $value );
192 }
193 return $value;
194 }
195
196 /**
197 * iawp_singular_analytics('60', new DateTime('-3 days'), new DateTime());
198 *
199 * @param string|int $singular_id
200 * @param DateTime $from
201 * @param DateTime $to
202 *
203 * @return Singular_Analytics|null
204 * @internal
205 */
206 function iawp_singular_analytics( $singular_id, \DateTime $from, \DateTime $to ) : ?Singular_Analytics {
207 $date_range = new Exact_Date_Range($from, $to);
208 return Singular_Analytics::for( $singular_id, $date_range );
209 }
210
211 /**
212 * iawp_analytics(new DateTime('-3 days'), new DateTime());
213 *
214 * @param DateTime $from
215 * @param DateTime $to
216 *
217 * @return Analytics
218 * @internal
219 */
220 function iawp_analytics( \DateTime $from, \DateTime $to ) : Analytics {
221 $date_range = new Exact_Date_Range($from, $to);
222 return Analytics::for( $date_range );
223 }
224
225 if ( !\extension_loaded( 'pdo' ) || !\extension_loaded( 'pdo_mysql' ) ) {
226 $interrupt = new Interrupt('interrupt.pdo');
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 global $wpdb;
238 if ( \strlen( $wpdb->prefix ) > 25 ) {
239 $interrupt = new Interrupt('interrupt.database-prefix-too-long');
240 $interrupt->render( [
241 'prefix' => $wpdb->prefix,
242 'length' => \strlen( $wpdb->prefix ),
243 ] );
244 return;
245 }
246 if ( Migrations\Migrations::is_database_ahead_of_plugin() ) {
247 $interrupt = new Interrupt('interrupt.database-ahead-of-plugin');
248 $interrupt->render();
249 return;
250 }
251 if ( \get_option( 'iawp_missing_tables' ) === '1' ) {
252 if ( \IAWPSCOPED\iawp_db_version() === 0 ) {
253 \delete_option( 'iawp_missing_tables' );
254 } else {
255 $interrupt = new Interrupt('interrupt.missing-database-tables');
256 $interrupt->render();
257 return;
258 }
259 }
260 // These can be updated in background jobs. Always get the actual value from the database.
261 WP_Option_Cache_Bust::register( 'iawp_is_migrating' );
262 WP_Option_Cache_Bust::register( 'iawp_should_refresh_modules' );
263 WP_Option_Cache_Bust::register( 'iawp_migration_started_at' );
264 WP_Option_Cache_Bust::register( 'iawp_is_database_downloading' );
265 WP_Option_Cache_Bust::register( 'iawp_db_version' );
266 WP_Option_Cache_Bust::register( 'iawp_geo_database_version' );
267 WP_Option_Cache_Bust::register( 'iawp_overview_modules' );
268 WP_Option_Cache_Bust::register( 'iawp_default_modules_added' );
269 /** @internal */
270 function iawp() {
271 return Independent_Analytics::getInstance();
272 }
273
274 \IAWPSCOPED\iawp();
275 \register_activation_hook( \IAWP_PLUGIN_FILE, function () {
276 \wp_mkdir_p( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) );
277 if ( \IAWPSCOPED\iawp_db_version() === 0 ) {
278 // If there is no database installed, run migration on current process
279 Migrations\Migrations::create_or_migrate();
280 } else {
281 // If there is a database, run migration in a background process
282 Migrations\Migration_Job::maybe_dispatch();
283 }
284 Geo_Database_Background_Job::maybe_dispatch();
285 \update_option( 'iawp_need_clear_cache', \true, \true );
286 if ( \get_option( 'iawp_show_gsg' ) == '' ) {
287 \update_option( 'iawp_show_gsg', '1', \true );
288 }
289 \IAWPSCOPED\iawp()->cron_manager->schedule_refresh_salt();
290 ( new Pruning_Scheduler() )->schedule();
291 if ( \IAWPSCOPED\iawp_is_pro() ) {
292 \IAWPSCOPED\iawp()->email_reports->schedule();
293 }
294 // Set current version for changelog notifications
295 \update_option( 'iawp_last_update_viewed', \IAWP_VERSION, \true );
296 if ( \IAWPSCOPED\iawp_db_version() > 0 && Database::is_missing_all_tables() ) {
297 \update_option( 'iawp_missing_tables', '1', \true );
298 }
299 } );
300 \register_deactivation_hook( \IAWP_PLUGIN_FILE, function () {
301 \IAWPSCOPED\iawp()->cron_manager->unschedule_daily_salt_refresh();
302 ( new Pruning_Scheduler() )->unschedule();
303 if ( \IAWPSCOPED\iawp_is_pro() ) {
304 \IAWPSCOPED\iawp()->email_reports->unschedule();
305 ( new Click_Processing_Job() )->unschedule();
306 ( new Module_Refresh_Job() )->unschedule();
307 ( new SureCart_Event_Sync_Job() )->unschedule();
308 ( new Migration_Fixer_Job() )->unschedule();
309 }
310 \wp_delete_file( \trailingslashit( \WPMU_PLUGIN_DIR ) . 'iawp-performance-boost.php' );
311 \delete_option( 'iawp_must_use_directory_not_writable' );
312 } );
313 // This fires for the original version of the plugin and not the updated version of the plugin
314 \add_action( 'upgrader_process_complete', function () {
315 // Trigger the click processing cron job so no clicks are lost
316 \do_action( 'iawp_click_processing' );
317 } );
318 \add_action( 'init', function () {
319 Config_File_Manager::ensure();
320 if ( \IAWPSCOPED\iawp_is_pro() ) {
321 ( new Click_Processing_Job() )->schedule();
322 ( new Module_Refresh_Job() )->schedule();
323 ( new Migration_Fixer_Job() )->schedule();
324 }
325 if ( \IAWPSCOPED\iawp()->is_surecart_support_enabled() ) {
326 ( new SureCart_Event_Sync_Job() )->schedule();
327 }
328 if ( \IAWPSCOPED\iawp()->is_surecart_support_enabled() && \in_array( \get_option( 'iawp_surecart_currency_code' ), ['', \false] ) ) {
329 SureCart_Store::cache_currency_code();
330 }
331 } );
332 \add_action( 'admin_init', function () {
333 Migrations\Migrations::handle_migration_18_error();
334 Migrations\Migrations::handle_migration_22_error();
335 Migrations\Migrations::handle_migration_29_error();
336 Patch::patch_2_6_2_incorrect_email_report_schedule();
337 Patch::patch_2_8_7_potential_duplicates();
338 Config_File_Manager::ensure();
339 $options = Dashboard_Options::getInstance();
340 $options->maybe_redirect();
341 new Migrations\Migration_Job();
342 if ( \get_option( 'iawp_db_version', '0' ) === '0' ) {
343 // If there is no database installed, run migration on current process
344 Migrations\Migrations::create_or_migrate();
345 } else {
346 // If there is a database, run migration in a background process
347 Migrations\Migration_Job::maybe_dispatch();
348 }
349 Geo_Database_Background_Job::maybe_dispatch();
350 if ( \get_option( 'iawp_should_refresh_modules', '0' ) === '1' ) {
351 \update_option( 'iawp_should_refresh_modules', '0', \true );
352 Module::queue_full_module_refresh();
353 }
354 } );
355 new \IAWP\Overview\Sync_Module_Background_Job();
356 Views_Column::initialize();
357 MainWP::initialize();