PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.7.1
Independent Analytics – WordPress Analytics Plugin v2.7.1
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 2 years ago dist 2 years ago freemius 2 years ago img 2 years ago javascript-source 2 years ago javascript-unminified 2 years ago languages 2 years ago vendor 2 years ago views 2 years ago iawp-bootstrap.php 2 years ago iawp.php 2 years ago readme.txt 2 years ago
iawp-bootstrap.php
304 lines
1 <?php
2
3 namespace IAWPSCOPED;
4
5 use IAWP\Custom_WordPress_Columns\Views_Column;
6 use IAWP\Dashboard_Options;
7 use IAWP\Data_Pruning\Pruning_Scheduler;
8 use IAWP\Database;
9 use IAWP\Date_Range\Exact_Date_Range;
10 use IAWP\Env;
11 use IAWP\Geo_Database_Background_Job;
12 use IAWP\Independent_Analytics;
13 use IAWP\Interrupt;
14 use IAWP\Migrations;
15 use IAWP\Patch;
16 use IAWP\Public_API\Analytics;
17 use IAWP\Public_API\Singular_Analytics;
18 use IAWP\Utils\BladeOne;
19 use IAWP\WP_Option_Cache_Bust;
20 use IAWPSCOPED\Illuminate\Support\Carbon;
21 \define( 'IAWP_DIRECTORY', \rtrim( \plugin_dir_path( __FILE__ ), \DIRECTORY_SEPARATOR ) );
22 \define( 'IAWP_URL', \rtrim( \plugin_dir_url( __FILE__ ), '/' ) );
23 \define( 'IAWP_VERSION', '2.7.1' );
24 \define( 'IAWP_DATABASE_VERSION', '34' );
25 \define( 'IAWP_LANGUAGES_DIRECTORY', \dirname( \plugin_basename( __FILE__ ) ) . '/languages' );
26 \define( 'IAWP_PLUGIN_FILE', __DIR__ . '/iawp.php' );
27 if ( \file_exists( \IAWPSCOPED\iawp_path_to( 'vendor/scoper-autoload.php' ) ) ) {
28 require_once \IAWPSCOPED\iawp_path_to( 'vendor/scoper-autoload.php' );
29 } else {
30 require_once \IAWPSCOPED\iawp_path_to( 'vendor/autoload.php' );
31 }
32 // This is needed because something with age gate is preventing my own helpers from loading
33 // The problem is that in autoload_static.php, there's some sort of caching going on where it's trying
34 // to not load a file twice. I'm guessing that's normally a good thing, but in our case we've made changes (scoped)
35 // so we do indeed want to load our version even though age gate has alreawdy learned
36 require_once \IAWPSCOPED\iawp_path_to( 'vendor/illuminate/collections/helpers.php' );
37 /**
38 * @param $log
39 *
40 * @return void
41 * @internal
42 */
43 function iawp_log( $log ) : void {
44 if ( \WP_DEBUG === \true && \WP_DEBUG_LOG === \true ) {
45 if ( \is_array( $log ) || \is_object( $log ) ) {
46 \error_log( \print_r( $log, \true ) );
47 } else {
48 \error_log( $log );
49 }
50 }
51 }
52
53 /** @internal */
54 function iawp_path_to( string $path ) : string {
55 $path = \trim( $path, \DIRECTORY_SEPARATOR );
56 return \implode( \DIRECTORY_SEPARATOR, [\IAWP_DIRECTORY, $path] );
57 }
58
59 /**
60 * add_filter('iawp_temp_directory_path', function ($value) {
61 * return '/Users/andrew/site/wp-content/uploads/iawp';
62 * });
63 *
64 * @param string $path
65 *
66 * @return string
67 * @throws Exception
68 * @internal
69 */
70 function iawp_temp_path_to( string $path ) : string {
71 $temp_directory = ( \defined( 'IAWP_TEMP_DIR' ) ? \IAWP_TEMP_DIR : \apply_filters( 'iawp_temp_directory_path', 'temp' ) );
72 $path = \rtrim( $path, \DIRECTORY_SEPARATOR );
73 if ( $temp_directory === 'temp' ) {
74 return \IAWPSCOPED\iawp_path_to( \implode( \DIRECTORY_SEPARATOR, [$temp_directory, $path] ) );
75 }
76 $temp_directory = \rtrim( $temp_directory, \DIRECTORY_SEPARATOR );
77 if ( !\is_writable( $temp_directory ) ) {
78 \wp_mkdir_p( $temp_directory );
79 }
80 // Separate condition to see if wp_mkdir_p call fixed the issue
81 if ( !\is_writable( $temp_directory ) ) {
82 throw new \Exception('You have provided and missing or non-writable directory for the iawp_temp_directory_path filter: ' . $temp_directory);
83 }
84 return \implode( \DIRECTORY_SEPARATOR, [$temp_directory, $path] );
85 }
86
87 /** @internal */
88 function iawp_url_to( string $path ) : string {
89 $path = \trim( $path, '/' );
90 return \implode( '/', [\IAWP_URL, $path] );
91 }
92
93 /**
94 * @param string $path
95 * @param bool $prefer_parent_site_upload_path If it's a multisite installation, use the parent sites upload folder
96 * @return string
97 * @internal
98 */
99 function iawp_upload_path_to( string $path, bool $prefer_parent_site_upload_path = \false ) : string {
100 $path = \trim( $path, \DIRECTORY_SEPARATOR );
101 $upload_directory = \wp_upload_dir()['basedir'];
102 if ( $prefer_parent_site_upload_path && \is_multisite() ) {
103 $site = \get_site();
104 if ( $site !== null ) {
105 \switch_to_blog( \intval( $site->site_id ) );
106 $upload_directory = \wp_upload_dir()['basedir'];
107 \restore_current_blog();
108 }
109 }
110 return \implode( \DIRECTORY_SEPARATOR, [$upload_directory, $path] );
111 }
112
113 /**
114 * Determines if the user is running a licensed pro version
115 *
116 * @return bool
117 * @internal
118 */
119 function iawp_is_pro() : bool {
120 return \false;
121 }
122
123 /**
124 * Determines if the user is running a free version or an unlicensed pro version
125 * @return bool
126 * @internal
127 */
128 function iawp_is_free() : bool {
129 return !\IAWPSCOPED\iawp_is_pro();
130 }
131
132 /** @internal */
133 function iawp_dashboard_url( array $query_arguments = [] ) : string {
134 $default_query_arguments = [
135 'page' => 'independent-analytics',
136 ];
137 return \add_query_arg( \array_merge( $default_query_arguments, $query_arguments ), \admin_url( 'admin.php' ) );
138 }
139
140 /** @internal */
141 function iawp_blade() {
142 if ( !\file_exists( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) ) ) {
143 \wp_mkdir_p( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) );
144 }
145 $blade = BladeOne::create();
146 $blade->share( 'env', new Env() );
147 return $blade;
148 }
149
150 /** @internal */
151 function iawp_icon( string $icon ) : string {
152 try {
153 return \IAWPSCOPED\iawp_blade()->run( 'icons.plugins.' . $icon );
154 } catch ( \Throwable $e ) {
155 return '';
156 }
157 }
158
159 /**
160 * Get the currently installed database version
161 *
162 * @return int
163 * @internal
164 */
165 function iawp_db_version() : int {
166 return \intval( \get_option( 'iawp_db_version', '0' ) );
167 }
168
169 /** @internal */
170 function iawp_intify( $value ) {
171 if ( \is_string( $value ) && \ctype_digit( $value ) ) {
172 return \intval( $value );
173 }
174 return $value;
175 }
176
177 /**
178 * iawp_singular_analytics('60', new DateTime('-3 days'), new DateTime());
179 *
180 * @param string|int $singular_id
181 * @param DateTime $from
182 * @param DateTime $to
183 *
184 * @return Singular_Analytics|null
185 * @internal
186 */
187 function iawp_singular_analytics( $singular_id, \DateTime $from, \DateTime $to ) : ?Singular_Analytics {
188 $date_range = new Exact_Date_Range($from, $to);
189 return Singular_Analytics::for( $singular_id, $date_range );
190 }
191
192 /**
193 * iawp_analytics(new DateTime('-3 days'), new DateTime());
194 *
195 * @param DateTime $from
196 * @param DateTime $to
197 *
198 * @return Analytics
199 * @internal
200 */
201 function iawp_analytics( \DateTime $from, \DateTime $to ) : Analytics {
202 $date_range = new Exact_Date_Range($from, $to);
203 return Analytics::for( $date_range );
204 }
205
206 if ( !\extension_loaded( 'pdo' ) || !\extension_loaded( 'pdo_mysql' ) ) {
207 $interrupt = new Interrupt('interrupt.pdo');
208 $interrupt->render();
209 return;
210 }
211 if ( \IAWPSCOPED\iawp_db_version() === 0 && !Database::has_correct_database_privileges() ) {
212 $interrupt = new Interrupt('interrupt.missing-database-permissions');
213 $interrupt->render( [
214 'missing_privileges' => Database::missing_database_privileges(),
215 ] );
216 return;
217 }
218 global $wpdb;
219 if ( \strlen( $wpdb->prefix ) > 25 ) {
220 $interrupt = new Interrupt('interrupt.database-prefix-too-long');
221 $interrupt->render( [
222 'prefix' => $wpdb->prefix,
223 'length' => \strlen( $wpdb->prefix ),
224 ] );
225 return;
226 }
227 if ( Migrations\Migrations::is_database_ahead_of_plugin() ) {
228 $interrupt = new Interrupt('interrupt.database-ahead-of-plugin');
229 $interrupt->render();
230 return;
231 }
232 if ( \get_option( 'iawp_missing_tables' ) === '1' ) {
233 if ( \IAWPSCOPED\iawp_db_version() === 0 ) {
234 \delete_option( 'iawp_missing_tables' );
235 } else {
236 $interrupt = new Interrupt('interrupt.missing-database-tables');
237 $interrupt->render();
238 return;
239 }
240 }
241 // These can be updated in background jobs. Always get the actual value from the database.
242 WP_Option_Cache_Bust::register( 'iawp_is_migrating' );
243 WP_Option_Cache_Bust::register( 'iawp_is_database_downloading' );
244 WP_Option_Cache_Bust::register( 'iawp_db_version' );
245 WP_Option_Cache_Bust::register( 'iawp_geo_database_version' );
246 /** @internal */
247 function iawp() {
248 return Independent_Analytics::getInstance();
249 }
250
251 \IAWPSCOPED\iawp();
252 \register_activation_hook( \IAWP_PLUGIN_FILE, function () {
253 \wp_mkdir_p( \IAWPSCOPED\iawp_temp_path_to( 'template-cache' ) );
254 if ( \IAWPSCOPED\iawp_db_version() === 0 ) {
255 // If there is no database installed, run migration on current process
256 Migrations\Migrations::create_or_migrate();
257 } else {
258 // If there is a database, run migration in a background process
259 Migrations\Migration_Job::maybe_dispatch();
260 }
261 Geo_Database_Background_Job::maybe_dispatch();
262 \update_option( 'iawp_need_clear_cache', \true, \true );
263 \IAWPSCOPED\iawp()->cron_manager->schedule_refresh_salt();
264 ( new Pruning_Scheduler() )->schedule();
265 if ( \IAWPSCOPED\iawp_is_pro() ) {
266 \IAWPSCOPED\iawp()->email_reports->schedule();
267 }
268 // Set current version for changelog notifications
269 \update_option( 'iawp_last_update_viewed', \IAWP_VERSION, \true );
270 if ( \IAWPSCOPED\iawp_db_version() > 0 && Database::is_missing_all_tables() ) {
271 \update_option( 'iawp_missing_tables', '1', \true );
272 }
273 } );
274 \register_deactivation_hook( \IAWP_PLUGIN_FILE, function () {
275 \IAWPSCOPED\iawp()->cron_manager->unschedule_daily_salt_refresh();
276 ( new Pruning_Scheduler() )->unschedule();
277 if ( \IAWPSCOPED\iawp_is_pro() ) {
278 \IAWPSCOPED\iawp()->email_reports->unschedule();
279 }
280 \wp_delete_file( \trailingslashit( \WPMU_PLUGIN_DIR ) . 'iawp-performance-boost.php' );
281 \delete_option( 'iawp_must_use_directory_not_writable' );
282 } );
283 /*
284 * The admin_init hook will fire when the dashboard is loaded or an admin ajax request is made
285 */
286 \add_action( 'admin_init', function () {
287 Carbon::setLocale( \get_locale() );
288 Migrations\Migrations::handle_migration_18_error();
289 Migrations\Migrations::handle_migration_22_error();
290 Migrations\Migrations::handle_migration_29_error();
291 Patch::patch_2_6_2_incorrect_email_report_schedule();
292 $options = Dashboard_Options::getInstance();
293 $options->maybe_redirect();
294 new Migrations\Migration_Job();
295 if ( \get_option( 'iawp_db_version', '0' ) === '0' ) {
296 // If there is no database installed, run migration on current process
297 Migrations\Migrations::create_or_migrate();
298 } else {
299 // If there is a database, run migration in a background process
300 Migrations\Migration_Job::maybe_dispatch();
301 }
302 Geo_Database_Background_Job::maybe_dispatch();
303 } );
304 Views_Column::initialize();