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