From ce03ed5f64ea3547aef8c84d955fcb2cd4066af3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jacek=20Fefli=C5=84ski?= Ustawienia Wtyczki Statystyk
+
+
Aby znaleźć swoje współrzędne, kliknij prawym przyciskiem myszy na mapie Google w wybranym miejscu - współrzędne pojawią się jako pierwsza pozycja w menu.
'; +} + +function mystat_render_lat_field() { + $options = get_option( 'mystat_privacy_options' ); + $latitude = isset( $options['latitude'] ) ? esc_attr( $options['latitude'] ) : ''; + echo ""; +} + +function mystat_render_lon_field() { + $options = get_option( 'mystat_privacy_options' ); + $longitude = isset( $options['longitude'] ) ? esc_attr( $options['longitude'] ) : ''; + echo ""; +} + +function mystat_render_radius_field() { + $options = get_option( 'mystat_privacy_options' ); + $radius = isset( $options['radius'] ) ? esc_attr( $options['radius'] ) : '500'; + echo " metrów"; +} + +function mystat_sanitize_privacy_options( $input ) { + $sanitized_input = []; + if ( isset( $input['latitude'] ) ) { + $sanitized_input['latitude'] = floatval( str_replace( ',', '.', $input['latitude'] ) ); + } + if ( isset( $input['longitude'] ) ) { + $sanitized_input['longitude'] = floatval( str_replace( ',', '.', $input['longitude'] ) ); + } + if ( isset( $input['radius'] ) ) { + $sanitized_input['radius'] = abs( intval( $input['radius'] ) ); + } + return $sanitized_input; +} + function mystat_yearly_summary_page() { global $wpdb; $table_activities = $wpdb->prefix . 'mystat_activities'; @@ -688,6 +789,20 @@ function mystat_parse_gpx_data( $gpx_url ) { return []; } + // --- Privacy Zone --- + $privacy_options = get_option( 'mystat_privacy_options' ); + $privacy_enabled = false; + $privacy_center_lat = 0; + $privacy_center_lon = 0; + $privacy_radius_km = 0; + + if ( ! empty( $privacy_options['latitude'] ) && ! empty( $privacy_options['longitude'] ) && ! empty( $privacy_options['radius'] ) ) { + $privacy_enabled = true; + $privacy_center_lat = (float) $privacy_options['latitude']; + $privacy_center_lon = (float) $privacy_options['longitude']; + $privacy_radius_km = ( (int) $privacy_options['radius'] ) / 1000; // Convert meters to km + } + libxml_use_internal_errors( true ); $gpx = simplexml_load_string( $gpx_content ); libxml_clear_errors(); @@ -738,19 +853,27 @@ function mystat_parse_gpx_data( $gpx_url ) { }; foreach ( $raw_points as $i => $point ) { - $map_points[] = [ $point['lat'], $point['lon'] ]; - - if ( $i > 0 ) { - $prev_point = $raw_points[ $i - 1 ]; - $distance_increment = $haversine( $prev_point['lat'], $prev_point['lon'], $point['lat'], $point['lon'] ); - $cumulative_distance += $distance_increment; + // Check if point is inside privacy zone + $is_in_privacy_zone = false; + if ( $privacy_enabled ) { + $distance_from_center = $haversine( $privacy_center_lat, $privacy_center_lon, $point['lat'], $point['lon'] ); + if ( $distance_from_center <= $privacy_radius_km ) { + $is_in_privacy_zone = true; + } } - if ( ! is_null( $point['ele'] ) ) { - $elevation_profile[] = [ - 'distance' => round( $cumulative_distance, 3 ), // in km - 'elevation' => round( $point['ele'], 2 ), // in m - ]; + // Only process points outside the privacy zone + if ( ! $is_in_privacy_zone ) { + $map_points[] = [ $point['lat'], $point['lon'] ]; + + if ( $i > 0 ) { + $prev_point = $raw_points[ $i - 1 ]; + $cumulative_distance += $haversine( $prev_point['lat'], $prev_point['lon'], $point['lat'], $point['lon'] ); + } + + if ( ! is_null( $point['ele'] ) ) { + $elevation_profile[] = [ 'distance' => round( $cumulative_distance, 3 ), 'elevation' => round( $point['ele'], 2 ) ]; + } } }