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3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-tracker.php
woocommerce / includes Last commit date
abstracts 2 years ago admin 2 years ago blocks 5 years ago cli 3 years ago customizer 3 years ago data-stores 2 years ago emails 2 years ago export 2 years ago gateways 2 years ago import 3 years ago integrations 4 years ago interfaces 3 years ago legacy 2 years ago libraries 3 years ago log-handlers 4 years ago payment-tokens 5 years ago queue 4 years ago react-admin 2 years ago rest-api 3 years ago shipping 2 years ago shortcodes 2 years ago theme-support 3 years ago tracks 2 years ago traits 5 years ago walkers 5 years ago wccom-site 2 years ago widgets 3 years ago class-wc-ajax.php 2 years ago class-wc-api.php 4 years ago class-wc-auth.php 4 years ago class-wc-autoloader.php 5 years ago class-wc-background-emailer.php 5 years ago class-wc-background-updater.php 5 years ago class-wc-breadcrumb.php 5 years ago class-wc-cache-helper.php 3 years ago class-wc-cart-fees.php 5 years ago class-wc-cart-session.php 3 years ago class-wc-cart-totals.php 2 years ago class-wc-cart.php 3 years ago class-wc-checkout.php 3 years ago class-wc-cli.php 3 years ago class-wc-comments.php 3 years ago class-wc-countries.php 2 years ago class-wc-coupon.php 3 years ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 4 years ago class-wc-customer.php 3 years ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 3 years ago class-wc-discounts.php 3 years ago class-wc-download-handler.php 3 years ago class-wc-emails.php 3 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 3 years ago class-wc-frontend-scripts.php 3 years ago class-wc-geo-ip.php 4 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 3 years ago class-wc-https.php 2 years ago class-wc-install.php 3 years ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 5 years ago class-wc-logger.php 4 years ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 3 years ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 4 years ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 4 years ago class-wc-order-item-shipping.php 4 years ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 4 years ago class-wc-order-query.php 4 years ago class-wc-order-refund.php 3 years ago class-wc-order.php 2 years ago class-wc-payment-gateways.php 4 years ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 3 years ago class-wc-post-types.php 3 years ago class-wc-privacy-background-process.php 5 years ago class-wc-privacy-erasers.php 4 years ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 4 years ago class-wc-product-attribute.php 4 years ago class-wc-product-download.php 4 years ago class-wc-product-external.php 5 years ago class-wc-product-factory.php 5 years ago class-wc-product-grouped.php 8 years ago class-wc-product-query.php 5 years ago class-wc-product-simple.php 3 years ago class-wc-product-variable.php 3 years ago class-wc-product-variation.php 4 years ago class-wc-query.php 3 years ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 3 years ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 3 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 2 years ago class-wc-shipping-rate.php 3 years ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 4 years ago class-wc-shortcodes.php 5 years ago class-wc-structured-data.php 3 years ago class-wc-tax.php 2 years ago class-wc-template-loader.php 3 years ago class-wc-tracker.php 2 years ago class-wc-validation.php 3 years ago class-wc-webhook.php 3 years ago class-woocommerce.php 2 years ago wc-account-functions.php 3 years ago wc-attribute-functions.php 3 years ago wc-cart-functions.php 3 years ago wc-conditional-functions.php 3 years ago wc-core-functions.php 3 years ago wc-coupon-functions.php 3 years ago wc-deprecated-functions.php 3 years ago wc-formatting-functions.php 2 years ago wc-notice-functions.php 3 years ago wc-order-functions.php 3 years ago wc-order-item-functions.php 3 years ago wc-page-functions.php 2 years ago wc-product-functions.php 3 years ago wc-rest-functions.php 3 years ago wc-stock-functions.php 3 years ago wc-template-functions.php 2 years ago wc-template-hooks.php 5 years ago wc-term-functions.php 3 years ago wc-update-functions.php 3 years ago wc-user-functions.php 2 years ago wc-webhook-functions.php 4 years ago wc-widget-functions.php 5 years ago
class-wc-tracker.php
1145 lines
1 <?php
2 /**
3 * WooCommerce Tracker
4 *
5 * The WooCommerce tracker class adds functionality to track WooCommerce usage based on if the customer opted in.
6 * No personal information is tracked, only general WooCommerce settings, general product, order and user counts and admin email for discount code.
7 *
8 * @class WC_Tracker
9 * @since 2.3.0
10 * @package WooCommerce\Classes
11 */
12
13 use Automattic\Jetpack\Constants;
14 use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
15 use Automattic\WooCommerce\Utilities\{ FeaturesUtil, OrderUtil, PluginUtil };
16 use Automattic\WooCommerce\Internal\Utilities\BlocksUtil;
17
18 defined( 'ABSPATH' ) || exit;
19
20 // phpcs:disable Squiz.Classes.ClassFileName.NoMatch, Squiz.Classes.ValidClassName.NotCamelCaps -- Backwards compatibility.
21 /**
22 * WooCommerce Tracker Class
23 */
24 class WC_Tracker {
25
26 // phpcs:enable
27 /**
28 * URL to the WooThemes Tracker API endpoint.
29 *
30 * @var string
31 */
32 private static $api_url = 'https://tracking.woocommerce.com/v1/';
33
34 /**
35 * Hook into cron event.
36 */
37 public static function init() { // phpcs:ignore WooCommerce.Functions.InternalInjectionMethod.MissingFinal, WooCommerce.Functions.InternalInjectionMethod.MissingInternalTag -- Not an injection.
38 add_action( 'woocommerce_tracker_send_event', array( __CLASS__, 'send_tracking_data' ) );
39 }
40
41 /**
42 * Decide whether to send tracking data or not.
43 *
44 * @param boolean $override Should override?.
45 */
46 public static function send_tracking_data( $override = false ) {
47 // Don't trigger this on AJAX Requests.
48 if ( Constants::is_true( 'DOING_AJAX' ) ) {
49 return;
50 }
51
52 /**
53 * Filter whether to send tracking data or not.
54 *
55 * @since 2.3.0
56 */
57 if ( ! apply_filters( 'woocommerce_tracker_send_override', $override ) ) {
58 // Send a maximum of once per week by default.
59 $last_send = self::get_last_send_time();
60 if ( $last_send && $last_send > apply_filters( 'woocommerce_tracker_last_send_interval', strtotime( '-1 week' ) ) ) { // phpcs:ignore
61 return;
62 }
63 } else {
64 // Make sure there is at least a 1 hour delay between override sends, we don't want duplicate calls due to double clicking links.
65 $last_send = self::get_last_send_time();
66 if ( $last_send && $last_send > strtotime( '-1 hours' ) ) {
67 return;
68 }
69 }
70
71 // Update time first before sending to ensure it is set.
72 update_option( 'woocommerce_tracker_last_send', time() );
73
74 $params = self::get_tracking_data();
75 wp_safe_remote_post(
76 self::$api_url,
77 array(
78 'method' => 'POST',
79 'timeout' => 45,
80 'redirection' => 5,
81 'httpversion' => '1.0',
82 'blocking' => false,
83 'headers' => array( 'user-agent' => 'WooCommerceTracker/' . md5( esc_url_raw( home_url( '/' ) ) ) . ';' ),
84 'body' => wp_json_encode( $params ),
85 'cookies' => array(),
86 )
87 );
88 }
89
90 /**
91 * Get the last time tracking data was sent.
92 *
93 * @return int|bool
94 */
95 private static function get_last_send_time() {
96 /**
97 * Filter the last time tracking data was sent.
98 *
99 * @since 2.3.0
100 */
101 return apply_filters( 'woocommerce_tracker_last_send_time', get_option( 'woocommerce_tracker_last_send', false ) );
102 }
103
104 /**
105 * Test whether this site is a staging site according to the Jetpack criteria.
106 *
107 * With Jetpack 8.1+, Jetpack::is_staging_site has been deprecated.
108 * \Automattic\Jetpack\Status::is_staging_site is the replacement.
109 * However, there are version of JP where \Automattic\Jetpack\Status exists, but does *not* contain is_staging_site method,
110 * so with those, code still needs to use the previous check as a fallback.
111 *
112 * @return bool
113 */
114 private static function is_jetpack_staging_site() {
115 if ( class_exists( '\Automattic\Jetpack\Status' ) ) {
116 // Preferred way of checking with Jetpack 8.1+.
117 $jp_status = new \Automattic\Jetpack\Status();
118 if ( is_callable( array( $jp_status, 'is_staging_site' ) ) ) {
119 return $jp_status->is_staging_site();
120 }
121 }
122
123 return ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_staging_site' ) && Jetpack::is_staging_site() );
124 }
125
126 /**
127 * Get all the tracking data.
128 *
129 * @return array
130 */
131 public static function get_tracking_data() {
132 $data = array();
133
134 // General site info.
135 $data['url'] = home_url();
136 /**
137 * Filter the admin email that's sent with data.
138 *
139 * @since 2.3.0
140 */
141 $data['email'] = apply_filters( 'woocommerce_tracker_admin_email', get_option( 'admin_email' ) );
142 $data['theme'] = self::get_theme_info();
143
144 // WordPress Info.
145 $data['wp'] = self::get_wordpress_info();
146
147 // Server Info.
148 $data['server'] = self::get_server_info();
149
150 // Plugin info.
151 $all_plugins = self::get_all_plugins();
152 $data['active_plugins'] = $all_plugins['active_plugins'];
153 $data['inactive_plugins'] = $all_plugins['inactive_plugins'];
154
155 // Jetpack & WooCommerce Connect.
156 $data['jetpack_version'] = Constants::is_defined( 'JETPACK__VERSION' ) ? Constants::get_constant( 'JETPACK__VERSION' ) : 'none';
157 $data['jetpack_connected'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_active' ) && Jetpack::is_active() ) ? 'yes' : 'no';
158 $data['jetpack_is_staging'] = self::is_jetpack_staging_site() ? 'yes' : 'no';
159 $data['connect_installed'] = class_exists( 'WC_Connect_Loader' ) ? 'yes' : 'no';
160 $data['connect_active'] = ( class_exists( 'WC_Connect_Loader' ) && wp_next_scheduled( 'wc_connect_fetch_service_schemas' ) ) ? 'yes' : 'no';
161 $data['helper_connected'] = self::get_helper_connected();
162
163 // Store count info.
164 $data['users'] = self::get_user_counts();
165 $data['products'] = self::get_product_counts();
166 $data['orders'] = self::get_orders();
167 $data['reviews'] = self::get_review_counts();
168 $data['categories'] = self::get_category_counts();
169
170 // Payment gateway info.
171 $data['gateways'] = self::get_active_payment_gateways();
172
173 // WcPay settings info.
174 $data['wcpay_settings'] = self::get_wcpay_settings();
175
176 // Shipping method info.
177 $data['shipping_methods'] = self::get_active_shipping_methods();
178
179 // Features.
180 $data['enabled_features'] = self::get_enabled_features();
181
182 // Get all WooCommerce options info.
183 $data['settings'] = self::get_all_woocommerce_options_values();
184
185 // Template overrides.
186 $data['template_overrides'] = self::get_all_template_overrides();
187
188 // Cart & checkout tech (blocks or shortcodes).
189 $data['cart_checkout'] = self::get_cart_checkout_info();
190
191 // Mini Cart block, which only exists since wp 5.9.
192 if ( version_compare( get_bloginfo( 'version' ), '5.9', '>=' ) ) {
193 $data['mini_cart_block'] = self::get_mini_cart_info();
194 }
195
196 /**
197 * Filter whether to disable admin tracking.
198 *
199 * @since 5.2.0
200 */
201 $data['wc_admin_disabled'] = apply_filters( 'woocommerce_admin_disabled', false ) ? 'yes' : 'no';
202
203 // Mobile info.
204 $data['wc_mobile_usage'] = self::get_woocommerce_mobile_usage();
205
206 /**
207 * Filter the data that's sent with the tracker.
208 *
209 * @since 2.3.0
210 */
211 return apply_filters( 'woocommerce_tracker_data', $data );
212 }
213
214 /**
215 * Get the current theme info, theme name and version.
216 *
217 * @return array
218 */
219 public static function get_theme_info() {
220 $theme_data = wp_get_theme();
221 $theme_child_theme = wc_bool_to_string( is_child_theme() );
222 $theme_wc_support = wc_bool_to_string( current_theme_supports( 'woocommerce' ) );
223 $theme_is_block_theme = wc_bool_to_string( wc_current_theme_is_fse_theme() );
224
225 return array(
226 'name' => $theme_data->Name, // @phpcs:ignore
227 'version' => $theme_data->Version, // @phpcs:ignore
228 'child_theme' => $theme_child_theme,
229 'wc_support' => $theme_wc_support,
230 'block_theme' => $theme_is_block_theme,
231 );
232 }
233
234 /**
235 * Get WordPress related data.
236 *
237 * @return array
238 */
239 private static function get_wordpress_info() {
240 $wp_data = array();
241
242 $memory = wc_let_to_num( WP_MEMORY_LIMIT );
243
244 if ( function_exists( 'memory_get_usage' ) ) {
245 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- False positive.
246 $system_memory = wc_let_to_num( @ini_get( 'memory_limit' ) );
247 $memory = max( $memory, $system_memory );
248 }
249
250 // WordPress 5.5+ environment type specification.
251 // 'production' is the default in WP, thus using it as a default here, too.
252 $environment_type = 'production';
253 if ( function_exists( 'wp_get_environment_type' ) ) {
254 $environment_type = wp_get_environment_type();
255 }
256
257 $wp_data['memory_limit'] = size_format( $memory );
258 $wp_data['debug_mode'] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No';
259 $wp_data['locale'] = get_locale();
260 $wp_data['version'] = get_bloginfo( 'version' );
261 $wp_data['multisite'] = is_multisite() ? 'Yes' : 'No';
262 $wp_data['env_type'] = $environment_type;
263 $wp_data['dropins'] = array_keys( get_dropins() );
264
265 return $wp_data;
266 }
267
268 /**
269 * Get server related info.
270 *
271 * @return array
272 */
273 private static function get_server_info() {
274 $server_data = array();
275
276 if ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
277 $server_data['software'] = $_SERVER['SERVER_SOFTWARE']; // @phpcs:ignore
278 }
279
280 if ( function_exists( 'phpversion' ) ) {
281 $server_data['php_version'] = phpversion();
282 }
283
284 if ( function_exists( 'ini_get' ) ) {
285 $server_data['php_post_max_size'] = size_format( wc_let_to_num( ini_get( 'post_max_size' ) ) );
286 $server_data['php_time_limt'] = ini_get( 'max_execution_time' );
287 $server_data['php_max_input_vars'] = ini_get( 'max_input_vars' );
288 $server_data['php_suhosin'] = extension_loaded( 'suhosin' ) ? 'Yes' : 'No';
289 }
290
291 $database_version = wc_get_server_database_version();
292 $server_data['mysql_version'] = $database_version['number'];
293
294 $server_data['php_max_upload_size'] = size_format( wp_max_upload_size() );
295 $server_data['php_default_timezone'] = date_default_timezone_get();
296 $server_data['php_soap'] = class_exists( 'SoapClient' ) ? 'Yes' : 'No';
297 $server_data['php_fsockopen'] = function_exists( 'fsockopen' ) ? 'Yes' : 'No';
298 $server_data['php_curl'] = function_exists( 'curl_init' ) ? 'Yes' : 'No';
299
300 return $server_data;
301 }
302
303 /**
304 * Get all plugins grouped into activated or not.
305 *
306 * @return array
307 */
308 private static function get_all_plugins() {
309 // Ensure get_plugins function is loaded.
310 if ( ! function_exists( 'get_plugins' ) ) {
311 include ABSPATH . '/wp-admin/includes/plugin.php';
312 }
313
314 $plugins = get_plugins();
315 $active_plugins_keys = get_option( 'active_plugins', array() );
316 $active_plugins = array();
317
318 foreach ( $plugins as $k => $v ) {
319 // Take care of formatting the data how we want it.
320 $formatted = array();
321 $formatted['name'] = wp_strip_all_tags( $v['Name'] );
322 if ( isset( $v['Version'] ) ) {
323 $formatted['version'] = wp_strip_all_tags( $v['Version'] );
324 }
325 if ( isset( $v['Author'] ) ) {
326 $formatted['author'] = wp_strip_all_tags( $v['Author'] );
327 }
328 if ( isset( $v['Network'] ) ) {
329 $formatted['network'] = wp_strip_all_tags( $v['Network'] );
330 }
331 if ( isset( $v['PluginURI'] ) ) {
332 $formatted['plugin_uri'] = wp_strip_all_tags( $v['PluginURI'] );
333 }
334 $formatted['feature_compatibility'] = array();
335 if ( wc_get_container()->get( PluginUtil::class )->is_woocommerce_aware_plugin( $k ) ) {
336 $formatted['feature_compatibility'] = array_filter( FeaturesUtil::get_compatible_features_for_plugin( $k ) );
337 }
338 if ( in_array( $k, $active_plugins_keys, true ) ) {
339 // Remove active plugins from list so we can show active and inactive separately.
340 unset( $plugins[ $k ] );
341 $active_plugins[ $k ] = $formatted;
342 } else {
343 $plugins[ $k ] = $formatted;
344 }
345 }
346
347 return array(
348 'active_plugins' => $active_plugins,
349 'inactive_plugins' => $plugins,
350 );
351 }
352
353 /**
354 * Get the settings of WooCommerce Payments plugin
355 *
356 * @return array
357 */
358 private static function get_wcpay_settings() {
359 return get_option( 'woocommerce_woocommerce_payments_settings' );
360 }
361
362 /**
363 * Check to see if the helper is connected to woocommerce.com
364 *
365 * @return string
366 */
367 private static function get_helper_connected() {
368 if ( class_exists( 'WC_Helper_Options' ) && is_callable( 'WC_Helper_Options::get' ) ) {
369 $authenticated = WC_Helper_Options::get( 'auth' );
370 } else {
371 $authenticated = '';
372 }
373 return ( ! empty( $authenticated ) ) ? 'yes' : 'no';
374 }
375
376
377 /**
378 * Get user totals based on user role.
379 *
380 * @return array
381 */
382 private static function get_user_counts() {
383 $user_count = array();
384 $user_count_data = count_users();
385 $user_count['total'] = $user_count_data['total_users'];
386
387 // Get user count based on user role.
388 foreach ( $user_count_data['avail_roles'] as $role => $count ) {
389 $user_count[ $role ] = $count;
390 }
391
392 return $user_count;
393 }
394
395 /**
396 * Get product totals based on product type.
397 *
398 * @return array
399 */
400 public static function get_product_counts() {
401 $product_count = array();
402 $product_count_data = wp_count_posts( 'product' );
403 $product_count['total'] = $product_count_data->publish;
404
405 $product_statuses = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
406 foreach ( $product_statuses as $product_status ) {
407 $product_count[ $product_status->name ] = $product_status->count;
408 }
409
410 return $product_count;
411 }
412
413 /**
414 * Get order counts.
415 *
416 * @return array
417 */
418 private static function get_order_counts() {
419 $order_count = array();
420 foreach ( wc_get_order_statuses() as $status_slug => $status_name ) {
421 $order_count[ $status_slug ] = wc_orders_count( $status_slug );
422 }
423 return $order_count;
424 }
425
426 /**
427 * Combine all order data.
428 *
429 * @return array
430 */
431 private static function get_orders() {
432 $order_dates = self::get_order_dates();
433 $order_counts = self::get_order_counts();
434 $order_totals = self::get_order_totals();
435 $order_gateways = self::get_orders_by_gateway();
436 $order_origin = self::get_orders_origins();
437
438 return array_merge( $order_dates, $order_counts, $order_totals, $order_gateways, $order_origin );
439 }
440
441 /**
442 * Get order totals.
443 *
444 * @since 5.4.0
445 * @return array
446 */
447 private static function get_order_totals() {
448 global $wpdb;
449
450 $orders_table = OrdersTableDataStore::get_orders_table_name();
451
452 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
453 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
454 $gross_total = $wpdb->get_var(
455 "
456 SELECT SUM(total_amount) AS 'gross_total'
457 FROM $orders_table
458 WHERE status in ('wc-completed', 'wc-refunded');
459 "
460 );
461 // phpcs:enable
462 } else {
463 $gross_total = $wpdb->get_var(
464 "
465 SELECT
466 SUM( order_meta.meta_value ) AS 'gross_total'
467 FROM {$wpdb->prefix}posts AS orders
468 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
469 WHERE order_meta.meta_key = '_order_total'
470 AND orders.post_status in ( 'wc-completed', 'wc-refunded' )
471 GROUP BY order_meta.meta_key
472 "
473 );
474 }
475
476 if ( is_null( $gross_total ) ) {
477 $gross_total = 0;
478 }
479
480 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
481 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
482 $processing_gross_total = $wpdb->get_var(
483 "
484 SELECT SUM(total_amount) AS 'gross_total'
485 FROM $orders_table
486 WHERE status = 'wc-processing';
487 "
488 );
489 // phpcs:enable
490 } else {
491 $processing_gross_total = $wpdb->get_var(
492 "
493 SELECT
494 SUM( order_meta.meta_value ) AS 'gross_total'
495 FROM {$wpdb->prefix}posts AS orders
496 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
497 WHERE order_meta.meta_key = '_order_total'
498 AND orders.post_status = 'wc-processing'
499 GROUP BY order_meta.meta_key
500 "
501 );
502 }
503
504 if ( is_null( $processing_gross_total ) ) {
505 $processing_gross_total = 0;
506 }
507
508 return array(
509 'gross' => $gross_total,
510 'processing_gross' => $processing_gross_total,
511 );
512 }
513
514 /**
515 * Get last order date.
516 *
517 * @return string
518 */
519 private static function get_order_dates() {
520 global $wpdb;
521
522 $orders_table = OrdersTableDataStore::get_orders_table_name();
523 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
524 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
525 $min_max = $wpdb->get_row(
526 "
527 SELECT
528 MIN( date_created_gmt ) as 'first', MAX( date_created_gmt ) as 'last'
529 FROM $orders_table
530 WHERE status = 'wc-completed';
531 ",
532 ARRAY_A
533 );
534 // phpcs:enable
535 } else {
536 $min_max = $wpdb->get_row(
537 "
538 SELECT
539 MIN( post_date_gmt ) as 'first', MAX( post_date_gmt ) as 'last'
540 FROM {$wpdb->prefix}posts
541 WHERE post_type = 'shop_order'
542 AND post_status = 'wc-completed'
543 ",
544 ARRAY_A
545 );
546 }
547
548 if ( is_null( $min_max ) ) {
549 $min_max = array(
550 'first' => '-',
551 'last' => '-',
552 );
553 }
554
555 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
556 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
557 $processing_min_max = $wpdb->get_row(
558 "
559 SELECT
560 MIN( date_created_gmt ) as 'processing_first', MAX( date_created_gmt ) as 'processing_last'
561 FROM $orders_table
562 WHERE status = 'wc-processing';
563 ",
564 ARRAY_A
565 );
566 // phpcs:enable
567 } else {
568 $processing_min_max = $wpdb->get_row(
569 "
570 SELECT
571 MIN( post_date_gmt ) as 'processing_first', MAX( post_date_gmt ) as 'processing_last'
572 FROM {$wpdb->prefix}posts
573 WHERE post_type = 'shop_order'
574 AND post_status = 'wc-processing'
575 ",
576 ARRAY_A
577 );
578 }
579
580 if ( is_null( $processing_min_max ) ) {
581 $processing_min_max = array(
582 'processing_first' => '-',
583 'processing_last' => '-',
584 );
585 }
586
587 return array_merge( $min_max, $processing_min_max );
588 }
589
590 /**
591 * Extract the group key for an associative array of objects which have unique ids in the key.
592 * A 'group_key' property is introduced in the object.
593 * For example, two objects with keys like 'WooDataPay ** #123' and 'WooDataPay ** #78' would
594 * both have a group_key of 'WooDataPay **' after this function call.
595 *
596 * @param array $objects The array of objects that need to be grouped.
597 * @param string $default_key The property that will be the default group_key.
598 * @return array Contains the objects with a group_key property.
599 */
600 private static function extract_group_key( $objects, $default_key ) {
601 $keys = array_keys( $objects );
602
603 // Sort keys by length and then by characters within the same length keys.
604 usort(
605 $keys,
606 function( $a, $b ) {
607 if ( strlen( $a ) === strlen( $b ) ) {
608 return strcmp( $a, $b );
609 }
610 return ( strlen( $a ) < strlen( $b ) ) ? -1 : 1;
611 }
612 );
613
614 // Look for common tokens in every pair of adjacent keys.
615 $prev = '';
616 foreach ( $keys as $key ) {
617 if ( $prev ) {
618 $comm_tokens = array();
619
620 // Tokenize the current and previous gateway names.
621 $curr_tokens = preg_split( '/[ :,\-_]+/', $key );
622 $prev_tokens = preg_split( '/[ :,\-_]+/', $prev );
623
624 $len_curr = count( $curr_tokens );
625 $len_prev = count( $prev_tokens );
626
627 $index_unique = -1;
628 // Gather the common tokens.
629 // Let us allow for the unique reference id to be anywhere in the name.
630 for ( $i = 0; $i < $len_curr && $i < $len_prev; $i++ ) {
631 if ( $curr_tokens[ $i ] === $prev_tokens[ $i ] ) {
632 $comm_tokens[] = $curr_tokens[ $i ];
633 } elseif ( preg_match( '/\d/', $curr_tokens[ $i ] ) && preg_match( '/\d/', $prev_tokens[ $i ] ) ) {
634 $index_unique = $i;
635 }
636 }
637
638 // If only one token is different, and those tokens contain digits, then that could be the unique id.
639 if ( count( $curr_tokens ) - count( $comm_tokens ) <= 1 && count( $comm_tokens ) > 0 && $index_unique > -1 ) {
640 $objects[ $key ]->group_key = implode( ' ', $comm_tokens );
641 $objects[ $prev ]->group_key = implode( ' ', $comm_tokens );
642 } else {
643 $objects[ $key ]->group_key = $objects[ $key ]->$default_key;
644 }
645 } else {
646 $objects[ $key ]->group_key = $objects[ $key ]->$default_key;
647 }
648 $prev = $key;
649 }
650 return $objects;
651 }
652
653 /**
654 * Get order details by gateway.
655 *
656 * @return array
657 */
658 private static function get_orders_by_gateway() {
659 global $wpdb;
660
661 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
662 $orders_table = OrdersTableDataStore::get_orders_table_name();
663 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
664 $orders_and_gateway_details = $wpdb->get_results(
665 "
666 SELECT payment_method AS gateway, currency AS currency, SUM( total_amount ) AS totals, count( id ) AS counts
667 FROM $orders_table
668 WHERE status IN ( 'wc-completed', 'wc-processing', 'wc-refunded' )
669 GROUP BY gateway, currency;
670 "
671 );
672 // phpcs:enable
673 } else {
674 $orders_and_gateway_details = $wpdb->get_results(
675 "
676 SELECT
677 gateway, currency, SUM(total) AS totals, COUNT(order_id) AS counts
678 FROM (
679 SELECT
680 orders.id AS order_id,
681 MAX(CASE WHEN meta_key = '_payment_method' THEN meta_value END) gateway,
682 MAX(CASE WHEN meta_key = '_order_total' THEN meta_value END) total,
683 MAX(CASE WHEN meta_key = '_order_currency' THEN meta_value END) currency
684 FROM
685 {$wpdb->prefix}posts orders
686 LEFT JOIN
687 {$wpdb->prefix}postmeta order_meta ON order_meta.post_id = orders.id
688 WHERE orders.post_type = 'shop_order'
689 AND orders.post_status in ( 'wc-completed', 'wc-processing', 'wc-refunded' )
690 AND meta_key in( '_payment_method','_order_total','_order_currency')
691 GROUP BY orders.id
692 ) order_gateways
693 GROUP BY gateway, currency
694 "
695 );
696 }
697
698 $orders_by_gateway_currency = array();
699
700 // The associative array that is created as the result of array_reduce is passed to extract_group_key()
701 // This function has the logic that will remove specific transaction identifiers that may sometimes be part of a
702 // payment method. For example, two payments methods like 'WooDataPay ** #123' and 'WooDataPay ** #78' would
703 // both have the same group_key 'WooDataPay **'.
704 $orders_by_gateway = self::extract_group_key(
705 // Convert into an associative array with a combination of currency and gateway as key.
706 array_reduce(
707 $orders_and_gateway_details,
708 function( $result, $item ) {
709 $item->gateway = preg_replace( '/\s+/', ' ', $item->gateway );
710
711 // Introduce currency as a prefix for the key.
712 $key = $item->currency . '==' . $item->gateway;
713
714 $result[ $key ] = $item;
715 return $result;
716 },
717 array()
718 ),
719 'gateway'
720 );
721
722 // Aggregate using group_key.
723 foreach ( $orders_by_gateway as $orders_details ) {
724 $gkey = $orders_details->group_key;
725
726 // Remove currency as prefix of key for backward compatibility.
727 if ( str_contains( $gkey, '==' ) ) {
728 $tokens = preg_split( '/==/', $gkey );
729 $key = $tokens[1];
730 } else {
731 $key = $gkey;
732 }
733
734 $key = str_replace( array( 'payment method', 'payment gateway', 'gateway' ), '', strtolower( $key ) );
735 $key = trim( preg_replace( '/[: ,#*\-_]+/', ' ', $key ) );
736
737 // Add currency as postfix of gateway for backward compatibility.
738 $key = 'gateway_' . $key . '_' . $orders_details->currency;
739 $count_key = $key . '_count';
740 $total_key = $key . '_total';
741
742 if ( array_key_exists( $count_key, $orders_by_gateway_currency ) || array_key_exists( $total_key, $orders_by_gateway_currency ) ) {
743 $orders_by_gateway_currency[ $count_key ] = $orders_by_gateway_currency[ $count_key ] + $orders_details->counts;
744 $orders_by_gateway_currency[ $total_key ] = $orders_by_gateway_currency[ $total_key ] + $orders_details->totals;
745 } else {
746 $orders_by_gateway_currency[ $count_key ] = $orders_details->counts;
747 $orders_by_gateway_currency[ $total_key ] = $orders_details->totals;
748 }
749 }
750
751 return $orders_by_gateway_currency;
752 }
753
754 /**
755 * Get orders origin details.
756 *
757 * @return array
758 */
759 private static function get_orders_origins() {
760 global $wpdb;
761
762 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
763 $op_table_name = OrdersTableDataStore::get_operational_data_table_name();
764 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
765 $orders_origin = $wpdb->get_results(
766 "
767 SELECT created_via as origin, COUNT( order_id ) as count
768 FROM $op_table_name
769 GROUP BY created_via;
770 "
771 );
772 // phpcs:enable
773 } else {
774 $orders_origin = $wpdb->get_results(
775 "
776 SELECT
777 meta_value as origin, COUNT( DISTINCT ( orders.id ) ) as count
778 FROM
779 $wpdb->posts orders
780 LEFT JOIN
781 $wpdb->postmeta order_meta ON order_meta.post_id = orders.id
782 WHERE
783 meta_key = '_created_via'
784 GROUP BY
785 meta_value;
786 "
787 );
788 }
789
790 // The associative array that is created as the result of array_reduce is passed to extract_group_key()
791 // This function has the logic that will remove specific identifiers that may sometimes be part of an origin.
792 // For example, two origins like 'Import #123' and 'Import ** #78' would both have a group_key 'Import **'.
793 $orders_and_origins = self::extract_group_key(
794 // Convert into an associative array with the origin as key.
795 array_reduce(
796 $orders_origin,
797 function( $result, $item ) {
798 $key = $item->origin;
799
800 $result[ $key ] = $item;
801 return $result;
802 },
803 array()
804 ),
805 'origin'
806 );
807
808 $orders_by_origin = array();
809
810 // Aggregate using group_key.
811 foreach ( $orders_and_origins as $origin ) {
812 $key = strtolower( $origin->group_key );
813
814 if ( array_key_exists( $key, $orders_by_origin ) ) {
815 $orders_by_origin[ $key ] = $orders_by_origin[ $key ] + (int) $origin->count;
816 } else {
817 $orders_by_origin[ $key ] = (int) $origin->count;
818 }
819 }
820
821 return array( 'created_via' => $orders_by_origin );
822 }
823
824 /**
825 * Get review counts for different statuses.
826 *
827 * @return array
828 */
829 private static function get_review_counts() {
830 global $wpdb;
831 $review_count = array( 'total' => 0 );
832 $status_map = array(
833 '0' => 'pending',
834 '1' => 'approved',
835 'trash' => 'trash',
836 'spam' => 'spam',
837 );
838 $counts = $wpdb->get_results(
839 "
840 SELECT comment_approved, COUNT(*) AS num_reviews
841 FROM {$wpdb->comments}
842 WHERE comment_type = 'review'
843 GROUP BY comment_approved
844 ",
845 ARRAY_A
846 );
847
848 if ( ! $counts ) {
849 return $review_count;
850 }
851
852 foreach ( $counts as $count ) {
853 $status = $count['comment_approved'];
854 if ( array_key_exists( $status, $status_map ) ) {
855 $review_count[ $status_map[ $status ] ] = $count['num_reviews'];
856 }
857 $review_count['total'] += $count['num_reviews'];
858 }
859
860 return $review_count;
861 }
862
863 /**
864 * Get the number of product categories.
865 *
866 * @return int
867 */
868 private static function get_category_counts() {
869 return wp_count_terms( 'product_cat' );
870 }
871
872 /**
873 * Get a list of all active payment gateways.
874 *
875 * @return array
876 */
877 private static function get_active_payment_gateways() {
878 $active_gateways = array();
879 $gateways = WC()->payment_gateways->payment_gateways();
880 foreach ( $gateways as $id => $gateway ) {
881 if ( isset( $gateway->enabled ) && 'yes' === $gateway->enabled ) {
882 $active_gateways[ $id ] = array(
883 'title' => $gateway->title,
884 'supports' => $gateway->supports,
885 );
886 }
887 }
888
889 return $active_gateways;
890 }
891
892
893 /**
894 * Get a list of all active shipping methods.
895 *
896 * @return array
897 */
898 private static function get_active_shipping_methods() {
899 $active_methods = array();
900 $shipping_methods = WC()->shipping()->get_shipping_methods();
901 foreach ( $shipping_methods as $id => $shipping_method ) {
902 if ( isset( $shipping_method->enabled ) && 'yes' === $shipping_method->enabled ) {
903 $active_methods[ $id ] = array(
904 'title' => $shipping_method->title,
905 'tax_status' => $shipping_method->tax_status,
906 );
907 }
908 }
909
910 return $active_methods;
911 }
912
913 /**
914 * Get an array of slugs for WC features that are enabled on the site.
915 *
916 * @return string[]
917 */
918 private static function get_enabled_features() {
919 $all_features = FeaturesUtil::get_features( true, true );
920 $enabled_features = array_filter(
921 $all_features,
922 function( $feature ) {
923 return $feature['is_enabled'];
924 }
925 );
926
927 return array_keys( $enabled_features );
928 }
929
930 /**
931 * Get all options starting with woocommerce_ prefix.
932 *
933 * @return array
934 */
935 private static function get_all_woocommerce_options_values() {
936 return array(
937 'version' => WC()->version,
938 'currency' => get_woocommerce_currency(),
939 'base_location' => WC()->countries->get_base_country(),
940 'base_state' => WC()->countries->get_base_state(),
941 'base_postcode' => WC()->countries->get_base_postcode(),
942 'selling_locations' => WC()->countries->get_allowed_countries(),
943 'api_enabled' => get_option( 'woocommerce_api_enabled' ),
944 'weight_unit' => get_option( 'woocommerce_weight_unit' ),
945 'dimension_unit' => get_option( 'woocommerce_dimension_unit' ),
946 'download_method' => get_option( 'woocommerce_file_download_method' ),
947 'download_require_login' => get_option( 'woocommerce_downloads_require_login' ),
948 'calc_taxes' => get_option( 'woocommerce_calc_taxes' ),
949 'coupons_enabled' => get_option( 'woocommerce_enable_coupons' ),
950 'guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
951 'checkout_login_reminder' => get_option( 'woocommerce_enable_checkout_login_reminder' ),
952 'secure_checkout' => get_option( 'woocommerce_force_ssl_checkout' ),
953 'enable_signup_and_login_from_checkout' => get_option( 'woocommerce_enable_signup_and_login_from_checkout' ),
954 'enable_myaccount_registration' => get_option( 'woocommerce_enable_myaccount_registration' ),
955 'registration_generate_username' => get_option( 'woocommerce_registration_generate_username' ),
956 'registration_generate_password' => get_option( 'woocommerce_registration_generate_password' ),
957 'hpos_enabled' => get_option( 'woocommerce_feature_custom_order_tables_enabled' ),
958 'hpos_sync_enabled' => get_option( 'woocommerce_custom_orders_table_data_sync_enabled' ),
959 'hpos_cot_authoritative' => get_option( 'woocommerce_custom_orders_table_enabled' ),
960 'hpos_transactions_enabled' => get_option( 'woocommerce_use_db_transactions_for_custom_orders_table_data_sync' ),
961 'hpos_transactions_level' => get_option( 'woocommerce_db_transactions_isolation_level_for_custom_orders_table_data_sync' ),
962 'show_marketplace_suggestions' => get_option( 'woocommerce_show_marketplace_suggestions' ),
963 );
964 }
965
966 /**
967 * Look for any template override and return filenames.
968 *
969 * @return array
970 */
971 private static function get_all_template_overrides() {
972 $override_data = array();
973 /**
974 * Filter the paths to scan for template overrides.
975 *
976 * @since 2.3.0
977 */
978 $template_paths = apply_filters( 'woocommerce_template_overrides_scan_paths', array( 'WooCommerce' => WC()->plugin_path() . '/templates/' ) );
979 $scanned_files = array();
980
981 require_once WC()->plugin_path() . '/includes/admin/class-wc-admin-status.php';
982
983 foreach ( $template_paths as $plugin_name => $template_path ) {
984 $scanned_files[ $plugin_name ] = WC_Admin_Status::scan_template_files( $template_path );
985 }
986
987 foreach ( $scanned_files as $plugin_name => $files ) {
988 foreach ( $files as $file ) {
989 if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
990 $theme_file = get_stylesheet_directory() . '/' . $file;
991 } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) {
992 $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file;
993 } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
994 $theme_file = get_template_directory() . '/' . $file;
995 } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) {
996 $theme_file = get_template_directory() . '/' . WC()->template_path() . $file;
997 } else {
998 $theme_file = false;
999 }
1000
1001 if ( false !== $theme_file ) {
1002 $override_data[] = basename( $theme_file );
1003 }
1004 }
1005 }
1006 return $override_data;
1007 }
1008
1009 /**
1010 * Search a specific post for text content.
1011 *
1012 * @param integer $post_id The id of the post to search.
1013 * @param string $text The text to search for.
1014 * @return string 'Yes' if post contains $text (otherwise 'No').
1015 */
1016 public static function post_contains_text( $post_id, $text ) {
1017 global $wpdb;
1018
1019 // Search for the text anywhere in the post.
1020 $wildcarded = "%{$text}%";
1021
1022 $result = $wpdb->get_var(
1023 $wpdb->prepare(
1024 "
1025 SELECT COUNT( * ) FROM {$wpdb->prefix}posts
1026 WHERE ID=%d
1027 AND {$wpdb->prefix}posts.post_content LIKE %s
1028 ",
1029 array( $post_id, $wildcarded )
1030 )
1031 );
1032
1033 return ( '0' !== $result ) ? 'Yes' : 'No';
1034 }
1035
1036
1037 /**
1038 * Get tracker data for a specific block type on a woocommerce page.
1039 *
1040 * @param string $block_name The name (id) of a block, e.g. `woocommerce/cart`.
1041 * @param string $woo_page_name The woo page to search, e.g. `cart`.
1042 * @return array Associative array of tracker data with keys:
1043 * - page_contains_block
1044 * - block_attributes
1045 */
1046 public static function get_block_tracker_data( $block_name, $woo_page_name ) {
1047 $blocks = WC_Blocks_Utils::get_blocks_from_page( $block_name, $woo_page_name );
1048
1049 $block_present = false;
1050 $attributes = array();
1051 if ( $blocks && count( $blocks ) ) {
1052 // Return any customised attributes from the first block.
1053 $block_present = true;
1054 $attributes = $blocks[0]['attrs'];
1055 }
1056
1057 return array(
1058 'page_contains_block' => $block_present ? 'Yes' : 'No',
1059 'block_attributes' => $attributes,
1060 );
1061 }
1062
1063 /**
1064 * Get tracker data for a pickup location method.
1065 *
1066 * @return array Associative array of tracker data with keys:
1067 * - pickup_location_enabled
1068 * - pickup_locations_count
1069 */
1070 public static function get_pickup_location_data() {
1071 $pickup_location_enabled = false;
1072 $pickup_locations_count = count( get_option( 'pickup_location_pickup_locations', array() ) );
1073
1074 // Get the available shipping methods.
1075 $shipping_methods = WC()->shipping()->get_shipping_methods();
1076
1077 // Check if the desired shipping method is enabled.
1078 if ( isset( $shipping_methods['pickup_location'] ) && $shipping_methods['pickup_location']->is_enabled() ) {
1079 $pickup_location_enabled = true;
1080 }
1081
1082 return array(
1083 'pickup_location_enabled' => $pickup_location_enabled,
1084 'pickup_locations_count' => $pickup_locations_count,
1085 );
1086 }
1087
1088 /**
1089 * Get info about the cart & checkout pages.
1090 *
1091 * @return array
1092 */
1093 public static function get_cart_checkout_info() {
1094 $cart_page_id = wc_get_page_id( 'cart' );
1095 $checkout_page_id = wc_get_page_id( 'checkout' );
1096
1097 $cart_block_data = self::get_block_tracker_data( 'woocommerce/cart', 'cart' );
1098 $checkout_block_data = self::get_block_tracker_data( 'woocommerce/checkout', 'checkout' );
1099
1100 $pickup_location_data = self::get_pickup_location_data();
1101
1102 return array(
1103 'cart_page_contains_cart_shortcode' => self::post_contains_text(
1104 $cart_page_id,
1105 '[woocommerce_cart]'
1106 ),
1107 'checkout_page_contains_checkout_shortcode' => self::post_contains_text(
1108 $checkout_page_id,
1109 '[woocommerce_checkout]'
1110 ),
1111
1112 'cart_page_contains_cart_block' => $cart_block_data['page_contains_block'],
1113 'cart_block_attributes' => $cart_block_data['block_attributes'],
1114 'checkout_page_contains_checkout_block' => $checkout_block_data['page_contains_block'],
1115 'checkout_block_attributes' => $checkout_block_data['block_attributes'],
1116 'pickup_location' => $pickup_location_data,
1117 );
1118 }
1119
1120 /**
1121 * Get info about the Mini Cart Block.
1122 *
1123 * @return array
1124 */
1125 private static function get_mini_cart_info() {
1126 $mini_cart_block_name = 'woocommerce/mini-cart';
1127 $mini_cart_block_data = wc_current_theme_is_fse_theme() ? BlocksUtil::get_block_from_template_part( $mini_cart_block_name, 'header' ) : BlocksUtil::get_blocks_from_widget_area( $mini_cart_block_name );
1128 return array(
1129 'mini_cart_used' => empty( $mini_cart_block_data[0] ) ? 'No' : 'Yes',
1130 'mini_cart_block_attributes' => empty( $mini_cart_block_data[0] ) ? array() : $mini_cart_block_data[0]['attrs'],
1131 );
1132 }
1133
1134 /**
1135 * Get info about WooCommerce Mobile App usage
1136 *
1137 * @return array
1138 */
1139 public static function get_woocommerce_mobile_usage() {
1140 return get_option( 'woocommerce_mobile_app_usage' );
1141 }
1142 }
1143
1144 WC_Tracker::init();
1145