Privacy Zones
This commit is contained in:
+134
-11
@@ -118,6 +118,7 @@ add_action( 'admin_menu', 'mystat_add_admin_menu' );
|
||||
function mystat_admin_init_setup() {
|
||||
add_filter( 'upload_mimes', 'mystat_add_gpx_mime_type' );
|
||||
add_filter( 'wp_check_filetype_and_ext', 'mystat_fix_gpx_upload_permission', 10, 4 );
|
||||
mystat_register_settings();
|
||||
}
|
||||
add_action( 'admin_init', 'mystat_admin_init_setup' );
|
||||
|
||||
@@ -249,6 +250,15 @@ function mystat_add_admin_menu() {
|
||||
'mystat-import-csv', // Slug podmenu
|
||||
'mystat_import_csv_page' // Funkcja renderująca
|
||||
);
|
||||
|
||||
$mystat_plugin_hooks[] = add_submenu_page(
|
||||
'moje-statystyki', // Slug rodzica
|
||||
'Ustawienia', // Tytuł strony
|
||||
'Ustawienia', // Tytuł w podmenu
|
||||
'manage_options', // Wymagane uprawnienia
|
||||
'mystat-settings', // Slug podmenu
|
||||
'mystat_settings_page' // Funkcja renderująca
|
||||
);
|
||||
}
|
||||
|
||||
function mystat_dashboard_page() {
|
||||
@@ -434,6 +444,97 @@ function mystat_equipment_page() {
|
||||
<?php
|
||||
}
|
||||
|
||||
function mystat_settings_page() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>Ustawienia Wtyczki Statystyk</h1>
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
settings_fields( 'mystat_privacy_settings' );
|
||||
do_settings_sections( 'mystat-privacy-section' );
|
||||
submit_button();
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function mystat_register_settings() {
|
||||
register_setting(
|
||||
'mystat_privacy_settings',
|
||||
'mystat_privacy_options',
|
||||
'mystat_sanitize_privacy_options'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'mystat_privacy_zone_section',
|
||||
'Strefa Prywatności GPX',
|
||||
'mystat_privacy_section_callback',
|
||||
'mystat-privacy-section'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'mystat_privacy_latitude',
|
||||
'Szerokość geograficzna (Latitude)',
|
||||
'mystat_render_lat_field',
|
||||
'mystat-privacy-section',
|
||||
'mystat_privacy_zone_section'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'mystat_privacy_longitude',
|
||||
'Długość geograficzna (Longitude)',
|
||||
'mystat_render_lon_field',
|
||||
'mystat-privacy-section',
|
||||
'mystat_privacy_zone_section'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'mystat_privacy_radius',
|
||||
'Promień strefy (w metrach)',
|
||||
'mystat_render_radius_field',
|
||||
'mystat-privacy-section',
|
||||
'mystat_privacy_zone_section'
|
||||
);
|
||||
}
|
||||
|
||||
function mystat_privacy_section_callback() {
|
||||
echo '<p>Zdefiniuj strefę prywatności, aby ukryć początek i koniec swoich tras GPX. Punkty wewnątrz tego okręgu nie będą wyświetlane na mapie.</p>';
|
||||
echo '<p>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.</p>';
|
||||
}
|
||||
|
||||
function mystat_render_lat_field() {
|
||||
$options = get_option( 'mystat_privacy_options' );
|
||||
$latitude = isset( $options['latitude'] ) ? esc_attr( $options['latitude'] ) : '';
|
||||
echo "<input type='text' name='mystat_privacy_options[latitude]' value='{$latitude}' placeholder='np. 52.2297' class='regular-text' />";
|
||||
}
|
||||
|
||||
function mystat_render_lon_field() {
|
||||
$options = get_option( 'mystat_privacy_options' );
|
||||
$longitude = isset( $options['longitude'] ) ? esc_attr( $options['longitude'] ) : '';
|
||||
echo "<input type='text' name='mystat_privacy_options[longitude]' value='{$longitude}' placeholder='np. 21.0122' class='regular-text' />";
|
||||
}
|
||||
|
||||
function mystat_render_radius_field() {
|
||||
$options = get_option( 'mystat_privacy_options' );
|
||||
$radius = isset( $options['radius'] ) ? esc_attr( $options['radius'] ) : '500';
|
||||
echo "<input type='number' name='mystat_privacy_options[radius]' value='{$radius}' class='small-text' /> 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 ) ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user