138 lines
4.4 KiB
PHP
138 lines
4.4 KiB
PHP
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
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' );
|
|
settings_fields( 'mystat_api_settings' );
|
|
do_settings_sections( 'mystat-api-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'
|
|
);
|
|
|
|
// API Settings
|
|
register_setting(
|
|
'mystat_api_settings',
|
|
'mystat_api_options',
|
|
'mystat_sanitize_api_options'
|
|
);
|
|
|
|
add_settings_section(
|
|
'mystat_api_section',
|
|
'Ustawienia API',
|
|
'mystat_api_section_callback',
|
|
'mystat-api-section'
|
|
);
|
|
|
|
add_settings_field(
|
|
'mystat_enable_api',
|
|
'REST API',
|
|
'mystat_render_enable_api_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 = array();
|
|
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_api_section_callback() {
|
|
echo '<p>Ustawienia związane z integracją wtyczki z zewnętrznymi aplikacjami, np. mobilnymi.</p>';
|
|
}
|
|
|
|
function mystat_render_enable_api_field() {
|
|
$options = get_option( 'mystat_api_options' );
|
|
$checked = isset( $options['enable_api'] ) && $options['enable_api'] ? 'checked' : '';
|
|
echo "<label><input type='checkbox' name='mystat_api_options[enable_api]' value='1' {$checked} /> Włącz REST API</label>";
|
|
echo '<p class="description">Umożliwia zewnętrznym aplikacjom (np. na Androida) komunikację z wtyczką w celu dodawania i odczytywania aktywności. Jeśli nie korzystasz z takich integracji, możesz to wyłączyć dla większego bezpieczeństwa.</p>';
|
|
}
|
|
|
|
function mystat_sanitize_api_options( $input ) {
|
|
$sanitized_input = array();
|
|
// If the checkbox is not checked, it won't be in the $input array.
|
|
// So we check for its existence to determine if it's on or off.
|
|
$sanitized_input['enable_api'] = isset( $input['enable_api'] ) ? 1 : 0;
|
|
return $sanitized_input;
|
|
}
|