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