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