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