PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.11.2
Independent Analytics – WordPress Analytics Plugin v2.11.2
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
381 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.2' );
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 /**
200 * iawp_singular_analytics('60', new DateTime('-3 days'), new DateTime());
201 *
202 * @param string|int $singular_id
203 * @param DateTime $from
204 * @param DateTime $to
205 *
206 * @return Singular_Analytics|null
207 * @internal
208 */
209 function iawp_singular_analytics( $singular_id, \DateTime $from, \DateTime $to ) : ?Singular_Analytics {
210 $date_range = new Exact_Date_Range($from, $to);
211 return Singular_Analytics::for( $singular_id, $date_range );
212 }
213
214 /**
215 * iawp_top_posts();
216 *
217 * Retrieves top posts with customizable options.
218 *
219 * @param array{
220 * post_type: string, // Default: 'post'
221 * limit: int, // Default: 10
222 * from: \DateTimeInterface, // Default: 30 days ago
223 * to: \DateTimeInterface, // Default: today
224 * sort_by: string, // Default: 'views' - supports 'views', 'visitors', or 'sessions'
225 * } $options
226 *
227 * @return array
228 * @internal
229 */
230 function iawp_top_posts( array $options = [] ) : array {
231 return ( new Top_Posts($options) )->get();
232 }
233
234 /**
235 * iawp_analytics(new DateTime('-3 days'), new DateTime());
236 *
237 * @param DateTime $from
238 * @param DateTime $to
239 *
240 * @return Analytics
241 * @internal
242 */
243 function iawp_analytics( \DateTime $from, \DateTime $to ) : Analytics {
244 $date_range = new Exact_Date_Range($from, $to);
245 return Analytics::for( $date_range );
246 }
247
248 if ( !\extension_loaded( 'pdo' ) || !\extension_loaded( 'pdo_mysql' ) ) {
249 $interrupt = new Interrupt('interrupt.pdo');
250 $interrupt->render();
251 return;
252 }
253 if ( \IAWPSCOPED\iawp_db_version() === 0 && !Database::has_correct_database_privileges() ) {
254 $interrupt = new Interrupt('interrupt.missing-database-permissions');
255 $interrupt->render( [
256 'missing_privileges' => Database::missing_database_privileges(),
257 ] );
258 return;
259 }
260 global $wpdb;
261 if ( \strlen( $wpdb->prefix ) > 25 ) {
262 $interrupt = new Interrupt('interrupt.database-prefix-too-long');
263 $interrupt->render( [
264 'prefix' => $wpdb->prefix,
265 'length' => \strlen( $wpdb->prefix ),
266 ] );
267 return;
268 }
269 if ( Migrations\Migrations::is_database_ahead_of_plugin() ) {
270 $interrupt = new Interrupt('interrupt.database-ahead-of-plugin');
271 $interrupt->render();
272 return;
273 }
274 if ( \get_option( 'iawp_missing_tables' ) === '1' ) {
275 if ( \IAWPSCOPED\iawp_db_version() === 0 ) {
276 \delete_option( 'iawp_missing_tables' );
277 } else {
278 $interrupt = new Interrupt('interrupt.missing-database-tables');
279 $interrupt->render();
280 return;
281 }
282 }
283 // These can be updated in background jobs. Always get the actual value from the database.
284 WP_Option_Cache_Bust::register( 'iawp_is_migrating' );
285 WP_Option_Cache_Bust::register( 'iawp_should_refresh_modules' );
286 WP_Option_Cache_Bust::register( 'iawp_migration_started_at' );
287 WP_Option_Cache_Bust::register( 'iawp_is_database_downloading' );
288 WP_Option_Cache_Bust::register( 'iawp_db_version' );
289 WP_Option_Cache_Bust::register( 'iawp_geo_database_version' );
290 WP_Option_Cache_Bust::register( 'iawp_overview_modules' );
291 WP_Option_Cache_Bust::register( 'iawp_default_modules_added' );
292 /** @internal */
293 function iawp() {
294 return Independent_Analytics::getInstance();
295 }
296
297 \IAWPSCOPED\iawp();
298 \register_activation_hook( \IAWP_PLUGIN_FILE, function () {
299 \wp_mkdir_p( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) );
300 if ( \IAWPSCOPED\iawp_db_version() === 0 ) {
301 // If there is no database installed, run migration on current process
302 Migrations\Migrations::create_or_migrate();
303 } else {
304 // If there is a database, run migration in a background process
305 Migrations\Migration_Job::maybe_dispatch();
306 }
307 ( new Geo_Database_Manager() )->check_database_situation();
308 \update_option( 'iawp_need_clear_cache', \true, \true );
309 if ( \get_option( 'iawp_show_gsg' ) == '' ) {
310 \update_option( 'iawp_show_gsg', '1', \true );
311 }
312 \IAWPSCOPED\iawp()->cron_manager->schedule_refresh_salt();
313 ( new Pruning_Scheduler() )->schedule();
314 if ( \IAWPSCOPED\iawp_is_pro() ) {
315 \IAWPSCOPED\iawp()->email_reports->schedule();
316 }
317 // Set current version for changelog notifications
318 \update_option( 'iawp_last_update_viewed', \IAWP_VERSION, \true );
319 if ( \IAWPSCOPED\iawp_db_version() > 0 && Database::is_missing_all_tables() ) {
320 \update_option( 'iawp_missing_tables', '1', \true );
321 }
322 } );
323 \register_deactivation_hook( \IAWP_PLUGIN_FILE, function () {
324 \IAWPSCOPED\iawp()->cron_manager->unschedule_daily_salt_refresh();
325 ( new Pruning_Scheduler() )->unschedule();
326 if ( \IAWPSCOPED\iawp_is_pro() ) {
327 \IAWPSCOPED\iawp()->email_reports->unschedule();
328 ( new Click_Processing_Job() )->unschedule();
329 ( new Module_Refresh_Job() )->unschedule();
330 ( new SureCart_Event_Sync_Job() )->unschedule();
331 ( new Migration_Fixer_Job() )->unschedule();
332 }
333 \wp_delete_file( \trailingslashit( \WPMU_PLUGIN_DIR ) . 'iawp-performance-boost.php' );
334 \delete_option( 'iawp_must_use_directory_not_writable' );
335 } );
336 // This fires for the original version of the plugin and not the updated version of the plugin
337 \add_action( 'upgrader_process_complete', function () {
338 // Trigger the click processing cron job so no clicks are lost
339 \do_action( 'iawp_click_processing' );
340 } );
341 \add_action( 'init', function () {
342 Config_File_Manager::ensure();
343 if ( \IAWPSCOPED\iawp_is_pro() ) {
344 ( new Click_Processing_Job() )->schedule();
345 ( new Module_Refresh_Job() )->schedule();
346 ( new Migration_Fixer_Job() )->schedule();
347 }
348 if ( \IAWPSCOPED\iawp()->is_surecart_support_enabled() ) {
349 ( new SureCart_Event_Sync_Job() )->schedule();
350 }
351 if ( \IAWPSCOPED\iawp()->is_surecart_support_enabled() && \in_array( \get_option( 'iawp_surecart_currency_code' ), ['', \false] ) ) {
352 SureCart_Store::cache_currency_code();
353 }
354 } );
355 \add_action( 'admin_init', function () {
356 Migrations\Migrations::handle_migration_18_error();
357 Migrations\Migrations::handle_migration_22_error();
358 Migrations\Migrations::handle_migration_29_error();
359 Patch::patch_2_6_2_incorrect_email_report_schedule();
360 Patch::patch_2_8_7_potential_duplicates();
361 Config_File_Manager::ensure();
362 $options = Dashboard_Options::getInstance();
363 $options->maybe_redirect();
364 new Migrations\Migration_Job();
365 if ( \get_option( 'iawp_db_version', '0' ) === '0' ) {
366 // If there is no database installed, run migration on current process
367 Migrations\Migrations::create_or_migrate();
368 } else {
369 // If there is a database, run migration in a background process
370 Migrations\Migration_Job::maybe_dispatch();
371 }
372 ( new Geo_Database_Manager() )->check_database_situation();
373 if ( \get_option( 'iawp_should_refresh_modules', '0' ) === '1' ) {
374 \update_option( 'iawp_should_refresh_modules', '0', \true );
375 Module::queue_full_module_refresh();
376 }
377 } );
378 new Sync_Module_Background_Job();
379 new Geo_Database_Background_Job();
380 Views_Column::initialize();
381 MainWP::initialize();