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