PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.0.0
Independent Analytics – WordPress Analytics Plugin v2.0.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 2 years ago dist 2 years ago freemius 2 years ago img 2 years ago languages 2 years ago sql 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
204 lines
1 <?php
2
3 namespace IAWP_SCOPED;
4
5 use IAWP_SCOPED\eftec\bladeone\BladeOne ;
6 use IAWP_SCOPED\IAWP\Env ;
7 use IAWP_SCOPED\IAWP\Geo_Database_Background_Job ;
8 use IAWP_SCOPED\IAWP\Independent_Analytics ;
9 use IAWP_SCOPED\IAWP\Interrupt ;
10 use IAWP_SCOPED\IAWP\Migrations ;
11 use IAWP_SCOPED\IAWP\WP_Option_Cache_Bust ;
12 \define( 'IAWP_DIRECTORY', \rtrim( \plugin_dir_path( __FILE__ ), \DIRECTORY_SEPARATOR ) );
13 \define( 'IAWP_URL', \rtrim( \plugin_dir_url( __FILE__ ), '/' ) );
14 \define( 'IAWP_VERSION', '2.0.0' );
15 \define( 'IAWP_LANGUAGES_DIRECTORY', \dirname( \plugin_basename( __FILE__ ) ) . '/languages' );
16 \define( 'IAWP_SCOPED\\IAWP_PLUGIN_FILE', __DIR__ . '/iawp.php' );
17
18 if ( \file_exists( \IAWP_SCOPED\iawp_path_to( 'vendor/scoper-autoload.php' ) ) ) {
19 require_once \IAWP_SCOPED\iawp_path_to( 'vendor/scoper-autoload.php' );
20 } else {
21 require_once \IAWP_SCOPED\iawp_path_to( 'vendor/autoload.php' );
22 }
23
24 /**
25 * @param $log
26 *
27 * @return void
28 */
29 function iawp_log( $log ) : void
30 {
31 if ( \WP_DEBUG === \true && \WP_DEBUG_LOG === \true ) {
32
33 if ( \is_array( $log ) || \is_object( $log ) ) {
34 \error_log( \print_r( $log, \true ) );
35 } else {
36 \error_log( $log );
37 }
38
39 }
40 }
41
42 function iawp_path_to( string $path ) : string
43 {
44 $path = \trim( $path, \DIRECTORY_SEPARATOR );
45 return \implode( \DIRECTORY_SEPARATOR, [ \IAWP_DIRECTORY, $path ] );
46 }
47
48 function iawp_url_to( string $path ) : string
49 {
50 $path = \trim( $path, '/' );
51 return \implode( '/', [ \IAWP_URL, $path ] );
52 }
53
54 function iawp_upload_path_to( string $path ) : string
55 {
56 $path = \trim( $path, \DIRECTORY_SEPARATOR );
57 return \implode( \DIRECTORY_SEPARATOR, [ \wp_upload_dir()['basedir'], $path ] );
58 }
59
60 /**
61 * Provide defaults for arguments provided as an associated array
62 *
63 * @param array $args
64 * @param array $defaults
65 *
66 * @return array
67 */
68 function iawp_default_args( array $args = array(), array $defaults = array() ) : array
69 {
70 $args = \array_filter( $args, function ( $value ) {
71 // Remove key/value pairs where value is null
72 return $value !== null;
73 } );
74 $args = \array_intersect_key( $args, $defaults );
75 return \array_replace( $defaults, $args );
76 }
77
78 /**
79 * Determines if the user is running a licensed pro version
80 *
81 * @return bool
82 */
83 function iawp_is_pro() : bool
84 {
85 return \false;
86 }
87
88 /**
89 * Determines if the user is running a free version or an unlicensed pro version
90 * @return bool
91 */
92 function iawp_is_free() : bool
93 {
94 return !\IAWP_SCOPED\iawp_is_pro();
95 }
96
97 /**
98 * Determines if a pro user has WooCommerce activated
99 * @return bool
100 */
101 function iawp_using_woocommerce() : bool
102 {
103 global $wpdb ;
104 if ( \IAWP_SCOPED\iawp_is_free() ) {
105 return \false;
106 }
107 $class_missing = \class_exists( '\\WooCommerce' ) === \false;
108 if ( $class_missing ) {
109 return \false;
110 }
111 $table_name = $wpdb->prefix . 'wc_order_stats';
112 $order_stats_table = $wpdb->get_row( $wpdb->prepare( '
113 SELECT * FROM INFORMATION_SCHEMA.TABLES
114 WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s
115 ', $wpdb->dbname, $table_name ) );
116 if ( \is_null( $order_stats_table ) ) {
117 return \false;
118 }
119 return \true;
120 }
121
122 function iawp_dashboard_url( array $query_arguments = array() ) : string
123 {
124 $default_query_arguments = [
125 'page' => 'independent-analytics',
126 ];
127 return \add_query_arg( \array_merge( $default_query_arguments, $query_arguments ), \admin_url( 'admin.php' ) );
128 }
129
130 function iawp_blade() : BladeOne
131 {
132 if ( !\file_exists( \IAWP_SCOPED\iawp_path_to( 'temp/template-cache' ) ) ) {
133 \wp_mkdir_p( \IAWP_SCOPED\iawp_path_to( 'temp/template-cache' ) );
134 }
135 $blade = new BladeOne( \IAWP_SCOPED\iawp_path_to( 'views' ), \IAWP_SCOPED\iawp_path_to( 'temp/template-cache' ) );
136 $blade->share( 'env', new Env() );
137 return $blade;
138 }
139
140
141 if ( !\extension_loaded( 'pdo' ) || !\extension_loaded( 'pdo_mysql' ) ) {
142 $interrupt = new Interrupt( 'interrupt.pdo', \false );
143 $interrupt->render();
144 return;
145 }
146
147
148 if ( Migrations\Migration::is_database_ahead_of_plugin() ) {
149 $interrupt = new Interrupt( 'interrupt.database-ahead-of-plugin', \false );
150 $interrupt->render();
151 return;
152 }
153
154 WP_Option_Cache_Bust::register( 'iawp_is_migrating' );
155 WP_Option_Cache_Bust::register( 'iawp_is_database_downloading' );
156 WP_Option_Cache_Bust::register( 'iawp_db_version' );
157 WP_Option_Cache_Bust::register( 'iawp_geo_database_version' );
158 function iawp()
159 {
160 return Independent_Analytics::getInstance();
161 }
162
163 \IAWP_SCOPED\iawp();
164 \register_activation_hook( \IAWP_SCOPED\IAWP_PLUGIN_FILE, function () {
165 \wp_mkdir_p( \IAWP_SCOPED\iawp_path_to( 'temp/template-cache' ) );
166 \wp_mkdir_p( \IAWP_SCOPED\iawp_path_to( 'temp/device-data-cache' ) );
167
168 if ( \get_option( 'iawp_db_version', '0' ) === '0' ) {
169 // If there is no database installed, run migration on current process
170 Migrations\Migration::create_or_migrate();
171 } else {
172 // If there is a database, run migration in a background process
173 Migrations\Migration_Job::maybe_dispatch();
174 }
175
176 Geo_Database_Background_Job::maybe_dispatch();
177 \update_option( 'iawp_need_clear_cache', \true );
178 if ( \IAWP_SCOPED\iawp_is_pro() ) {
179 \IAWP_SCOPED\iawp()->email_reports->schedule_email_report();
180 }
181 } );
182 \register_deactivation_hook( \IAWP_SCOPED\IAWP_PLUGIN_FILE, function () {
183 if ( \IAWP_SCOPED\iawp_is_pro() ) {
184 \IAWP_SCOPED\iawp()->email_reports->unschedule_email_report();
185 }
186 } );
187 /*
188 * The admin_init hook will fire when the dashboard is loaded or an admin ajax request is made
189 */
190 \add_action( 'admin_init', function () {
191 $options = new \IAWP_SCOPED\IAWP\Dashboard_Options();
192 $options->maybe_redirect();
193 new Migrations\Migration_Job();
194
195 if ( \get_option( 'iawp_db_version', '0' ) === '0' ) {
196 // If there is no database installed, run migration on current process
197 Migrations\Migration::create_or_migrate();
198 } else {
199 // If there is a database, run migration in a background process
200 Migrations\Migration_Job::maybe_dispatch();
201 }
202
203 Geo_Database_Background_Job::maybe_dispatch();
204 } );