update
This commit is contained in:
@@ -64,27 +64,6 @@ class Admin {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load Google Calendar classes if needed
|
||||
if ( file_exists( YACHT_BOOKING_PLUGIN_DIR . 'integrations/google-calendar/class-oauth-handler.php' ) ) {
|
||||
require_once YACHT_BOOKING_PLUGIN_DIR . 'integrations/google-calendar/class-oauth-handler.php';
|
||||
}
|
||||
if ( file_exists( YACHT_BOOKING_PLUGIN_DIR . 'integrations/google-calendar/class-gcal-service.php' ) ) {
|
||||
require_once YACHT_BOOKING_PLUGIN_DIR . 'integrations/google-calendar/class-gcal-service.php';
|
||||
}
|
||||
|
||||
// Handle OAuth callback
|
||||
if ( isset( $_GET['gcal_callback'] ) && isset( $_GET['code'] ) ) {
|
||||
$this->handle_oauth_callback();
|
||||
}
|
||||
|
||||
// Handle disconnect
|
||||
if ( isset( $_POST['yacht_booking_disconnect_gcal'] ) ) {
|
||||
check_admin_referer( 'yacht_booking_disconnect_gcal' );
|
||||
\YachtBooking\Integrations\GoogleCalendar\OAuth_Handler::disconnect();
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=yacht-bookings-settings&tab=google-calendar&disconnected=1' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Handle general settings save
|
||||
if ( isset( $_POST['yacht_booking_save_settings'] ) ) {
|
||||
check_admin_referer( 'yacht_booking_save_settings' );
|
||||
@@ -105,10 +84,30 @@ class Admin {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Handle credentials save
|
||||
if ( isset( $_POST['yacht_booking_save_gcal_credentials'] ) ) {
|
||||
check_admin_referer( 'yacht_booking_save_gcal_credentials' );
|
||||
$this->save_gcal_credentials();
|
||||
// Handle global iCal settings save.
|
||||
if ( isset( $_POST['yacht_booking_save_global_ical'] ) ) {
|
||||
check_admin_referer( 'yacht_booking_save_global_ical' );
|
||||
$import_url = isset( $_POST['global_ical_import_url'] ) ? esc_url_raw( wp_unslash( $_POST['global_ical_import_url'] ) ) : '';
|
||||
update_option( 'yacht_booking_global_ical_import_url', $import_url );
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=yacht-bookings-settings&tab=google-calendar&global_ical_saved=1' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Handle global iCal token regeneration.
|
||||
if ( isset( $_POST['yacht_booking_regenerate_global_ical_token'] ) ) {
|
||||
check_admin_referer( 'yacht_booking_regenerate_global_ical_token' );
|
||||
\YachtBooking\Integrations\ICal\ICal_Feed::regenerate_global_token();
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=yacht-bookings-settings&tab=google-calendar&token_regenerated=1' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Handle global iCal manual import trigger.
|
||||
if ( isset( $_POST['yacht_booking_run_global_ical_import'] ) ) {
|
||||
check_admin_referer( 'yacht_booking_run_global_ical_import' );
|
||||
$result = \YachtBooking\Integrations\ICal\ICal_Import::run_global_import();
|
||||
$arg = $result ? 'global_import_done=1' : 'global_import_failed=1';
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=yacht-bookings-settings&tab=google-calendar&' . $arg ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,24 +147,6 @@ class Admin {
|
||||
<?php
|
||||
}
|
||||
|
||||
// Success: Connected to Google Calendar
|
||||
if ( isset( $_GET['connected'] ) ) {
|
||||
?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><strong><?php esc_html_e( 'Połączono z Google Calendar pomyślnie!', 'yacht-booking' ); ?></strong></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
// Success: Disconnected from Google Calendar
|
||||
if ( isset( $_GET['disconnected'] ) ) {
|
||||
?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><strong><?php esc_html_e( 'Rozłączono z Google Calendar.', 'yacht-booking' ); ?></strong></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
// Error
|
||||
if ( isset( $_GET['error'] ) ) {
|
||||
?>
|
||||
@@ -174,6 +155,38 @@ class Admin {
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if ( isset( $_GET['global_ical_saved'] ) ) {
|
||||
?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><strong><?php esc_html_e( 'Globalne ustawienia iCal zostały zapisane.', 'yacht-booking' ); ?></strong></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if ( isset( $_GET['token_regenerated'] ) ) {
|
||||
?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><strong><?php esc_html_e( 'Wygenerowano nowy token globalnego feed iCal. Poprzedni URL został unieważniony — zaktualizuj subskrypcję w Google Calendar.', 'yacht-booking' ); ?></strong></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if ( isset( $_GET['global_import_done'] ) ) {
|
||||
?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><strong><?php esc_html_e( 'Globalny import iCal wykonany. Sprawdź listę rezerwacji.', 'yacht-booking' ); ?></strong></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if ( isset( $_GET['global_import_failed'] ) ) {
|
||||
?>
|
||||
<div class="notice notice-error is-dismissible">
|
||||
<p><strong><?php esc_html_e( 'Globalny import iCal nie powiódł się. Sprawdź czy URL jest poprawny i logi serwera.', 'yacht-booking' ); ?></strong></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,7 +377,6 @@ class Admin {
|
||||
// Validate
|
||||
$title = isset( $data['yacht_title'] ) ? sanitize_text_field( wp_unslash( $data['yacht_title'] ) ) : '';
|
||||
$content = isset( $data['yacht_description'] ) ? wp_kses_post( wp_unslash( $data['yacht_description'] ) ) : '';
|
||||
$gcal_id = isset( $data['yacht_gcal_id'] ) ? sanitize_text_field( wp_unslash( $data['yacht_gcal_id'] ) ) : '';
|
||||
|
||||
if ( empty( $title ) ) {
|
||||
return false;
|
||||
@@ -389,12 +401,9 @@ class Admin {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save meta
|
||||
Yacht::update_gcal_id( $saved_id, $gcal_id );
|
||||
|
||||
// Save iCal import URL
|
||||
$ical_import_url = isset( $data['yacht_ical_import_url'] ) ? esc_url_raw( wp_unslash( $data['yacht_ical_import_url'] ) ) : '';
|
||||
\YachtBooking\Integrations\ICal\ICal_Import::set_import_url( $saved_id, $ical_import_url );
|
||||
// Save GCal alias for global iCal import matching.
|
||||
$gcal_alias = isset( $data['yacht_gcal_alias'] ) ? sanitize_text_field( wp_unslash( $data['yacht_gcal_alias'] ) ) : '';
|
||||
Yacht::update_gcal_alias( $saved_id, $gcal_alias );
|
||||
|
||||
return $saved_id;
|
||||
}
|
||||
@@ -1221,181 +1230,115 @@ class Admin {
|
||||
* Render Google Calendar settings tab
|
||||
*/
|
||||
private function render_google_calendar_settings() {
|
||||
// Check if classes exist
|
||||
if ( ! class_exists( '\YachtBooking\Integrations\GoogleCalendar\OAuth_Handler' ) ||
|
||||
! class_exists( '\YachtBooking\Integrations\GoogleCalendar\GCal_Service' ) ) {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p><?php esc_html_e( 'Błąd: Klasy Google Calendar nie zostały załadowane. Skontaktuj się z administratorem.', 'yacht-booking' ); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
return;
|
||||
}
|
||||
|
||||
$is_connected = \YachtBooking\Integrations\GoogleCalendar\OAuth_Handler::is_connected();
|
||||
$connected_email = $is_connected ? \YachtBooking\Integrations\GoogleCalendar\OAuth_Handler::get_connected_email() : false;
|
||||
$credentials = \YachtBooking\Integrations\GoogleCalendar\OAuth_Handler::get_credentials();
|
||||
$calendar_id = \YachtBooking\Integrations\GoogleCalendar\GCal_Service::get_calendar_id();
|
||||
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Konfiguracja Google Calendar', 'yacht-booking' ); ?></h2>
|
||||
<h2><?php esc_html_e( 'Synchronizacja z Google Calendar (iCal)', 'yacht-booking' ); ?></h2>
|
||||
|
||||
<?php if ( ! $is_connected ) : ?>
|
||||
<!-- Step 1: Enter credentials -->
|
||||
<div class="card">
|
||||
<h3><?php esc_html_e( 'Krok 1: Dodaj dane OAuth', 'yacht-booking' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Aby połączyć się z Google Calendar, musisz utworzyć projekt w Google Cloud Console i pobrać Client ID oraz Client Secret.', 'yacht-booking' ); ?></p>
|
||||
|
||||
<ol>
|
||||
<li><?php esc_html_e( 'Przejdź do', 'yacht-booking' ); ?> <a href="https://console.cloud.google.com/" target="_blank">Google Cloud Console</a></li>
|
||||
<li><?php esc_html_e( 'Utwórz nowy projekt lub wybierz istniejący', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Włącz Google Calendar API', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Utwórz OAuth 2.0 Client ID (typ: Web application)', 'yacht-booking' ); ?></li>
|
||||
<li>
|
||||
<?php esc_html_e( 'Dodaj Authorized redirect URI:', 'yacht-booking' ); ?>
|
||||
<br>
|
||||
<code style="background: #f0f0f0; padding: 5px 10px; display: inline-block; margin: 5px 0;">https://jachty.pagedev.pl/wp-admin/admin.php?page=yacht-bookings-settings&tab=google-calendar&gcal_callback=1</code>
|
||||
<br>
|
||||
<button type="button" class="button button-small" onclick="navigator.clipboard.writeText('https://jachty.pagedev.pl/wp-admin/admin.php?page=yacht-bookings-settings&tab=google-calendar&gcal_callback=1'); this.textContent='Skopiowano!';">
|
||||
<?php esc_html_e( 'Kopiuj', 'yacht-booking' ); ?>
|
||||
</button>
|
||||
</li>
|
||||
<li><?php esc_html_e( 'Skopiuj Client ID i Client Secret', 'yacht-booking' ); ?></li>
|
||||
</ol>
|
||||
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field( 'yacht_booking_save_gcal_credentials' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="gcal_client_id"><?php esc_html_e( 'Client ID', 'yacht-booking' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="gcal_client_id" id="gcal_client_id" class="regular-text" value="<?php echo esc_attr( isset( $credentials['client_id'] ) ? $credentials['client_id'] : '' ); ?>" required>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="gcal_client_secret"><?php esc_html_e( 'Client Secret', 'yacht-booking' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="gcal_client_secret" id="gcal_client_secret" class="regular-text" value="<?php echo esc_attr( isset( $credentials['client_secret'] ) ? $credentials['client_secret'] : '' ); ?>" required>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p class="submit">
|
||||
<input type="submit" name="yacht_booking_save_gcal_credentials" class="button-primary" value="<?php esc_attr_e( 'Zapisz i przejdź do autoryzacji', 'yacht-booking' ); ?>">
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php if ( $credentials ) : ?>
|
||||
<!-- Step 2: Authorize -->
|
||||
<div class="card" style="margin-top: 20px;">
|
||||
<h3><?php esc_html_e( 'Krok 2: Autoryzuj połączenie', 'yacht-booking' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Kliknij poniższy przycisk aby autoryzować dostęp do Google Calendar.', 'yacht-booking' ); ?></p>
|
||||
|
||||
<?php
|
||||
$auth_url = \YachtBooking\Integrations\GoogleCalendar\OAuth_Handler::get_auth_url();
|
||||
if ( $auth_url ) :
|
||||
// Parse URL to extract redirect_uri for debugging
|
||||
$parsed_url = wp_parse_url( $auth_url );
|
||||
parse_str( isset( $parsed_url['query'] ) ? $parsed_url['query'] : '', $query_params );
|
||||
$redirect_uri_sent = isset( $query_params['redirect_uri'] ) ? $query_params['redirect_uri'] : '';
|
||||
?>
|
||||
<p>
|
||||
<a href="<?php echo esc_url( $auth_url ); ?>" class="button button-primary button-hero">
|
||||
<?php esc_html_e( 'Połącz z Google Calendar', 'yacht-booking' ); ?>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<!-- DEBUG: Show exact redirect_uri being sent -->
|
||||
<div style="margin-top: 15px; padding: 10px; background: #fff3cd; border-left: 4px solid #ffc107;">
|
||||
<strong>DEBUG - Redirect URI wysyłany do Google:</strong>
|
||||
<br>
|
||||
<code style="display: block; margin-top: 5px; padding: 5px; background: white; word-break: break-all;">
|
||||
<?php echo esc_html( $redirect_uri_sent ); ?>
|
||||
</code>
|
||||
<small style="color: #856404;">Porównaj dokładnie z tym co masz w Google Cloud Console (character-by-character)</small>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<p class="description" style="color: #d63638;">
|
||||
<?php esc_html_e( 'Błąd generowania URL autoryzacji. Sprawdź Client ID i Secret.', 'yacht-booking' ); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php else : ?>
|
||||
<!-- Connected status -->
|
||||
<div class="card">
|
||||
<h3><?php esc_html_e( 'Status połączenia', 'yacht-booking' ); ?></h3>
|
||||
<p>
|
||||
<span class="dashicons dashicons-yes-alt" style="color: #46b450; font-size: 20px;"></span>
|
||||
<strong><?php esc_html_e( 'Połączono z Google Calendar', 'yacht-booking' ); ?></strong>
|
||||
</p>
|
||||
<?php if ( $connected_email ) : ?>
|
||||
<p><?php esc_html_e( 'Konto:', 'yacht-booking' ); ?> <code><?php echo esc_html( $connected_email ); ?></code></p>
|
||||
<?php endif; ?>
|
||||
<p><?php esc_html_e( 'Kalendarz:', 'yacht-booking' ); ?> <code><?php echo esc_html( $calendar_id ); ?></code></p>
|
||||
|
||||
<form method="post" action="" onsubmit="return confirm('<?php esc_attr_e( 'Czy na pewno chcesz rozłączyć Google Calendar?', 'yacht-booking' ); ?>')">
|
||||
<?php wp_nonce_field( 'yacht_booking_disconnect_gcal' ); ?>
|
||||
<p class="submit">
|
||||
<input type="submit" name="yacht_booking_disconnect_gcal" class="button button-secondary" value="<?php esc_attr_e( 'Rozłącz', 'yacht-booking' ); ?>">
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Manual sync -->
|
||||
<div class="card" style="margin-top: 20px;">
|
||||
<h3><?php esc_html_e( 'Synchronizacja ręczna', 'yacht-booking' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Synchronizacja odbywa się automatycznie, ale możesz wymusić synchronizację ręcznie.', 'yacht-booking' ); ?></p>
|
||||
<p>
|
||||
<button type="button" id="yacht-booking-manual-sync" class="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'yacht_booking_manual_sync' ) ); ?>">
|
||||
<?php esc_html_e( 'Synchronizuj teraz', 'yacht-booking' ); ?>
|
||||
</button>
|
||||
<span id="yacht-booking-sync-status" style="margin-left: 10px;"></span>
|
||||
</p>
|
||||
<div id="yacht-booking-sync-result" style="margin-top: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 20px;">
|
||||
<h3><?php esc_html_e( 'Instrukcja: dodawanie rezerwacji po stronie Google Calendar', 'yacht-booking' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Poniższe kroki pozwalają dodać wydarzenie w Google Calendar tak, aby po synchronizacji zostało zablokowane w kalendarzu WordPress.', 'yacht-booking' ); ?></p>
|
||||
<ol style="margin-left: 20px;">
|
||||
<li><?php esc_html_e( 'Dodaj wydarzenie w tym samym kalendarzu, który jest połączony z pluginem (widoczny wyżej jako \"Kalendarz\").', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Ustaw datę rozpoczęcia i datę zakończenia (wydarzenie całodniowe lub godzinowe).', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Zapisz wydarzenie w Google Calendar.', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Kliknij \"Synchronizuj teraz\" albo poczekaj na automatyczną synchronizację (cron uruchamiany co godzinę).', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Po synchronizacji wydarzenie z Google zostanie zaimportowane do panelu jako rezerwacja techniczna (źródło: Google Calendar), którą można usunąć z poziomu listy rezerwacji.', 'yacht-booking' ); ?></li>
|
||||
</ol>
|
||||
<p class="description"><?php esc_html_e( 'Uwaga: import obejmuje wydarzenia od teraz do +1 roku i pomija wydarzenia, które zostały utworzone przez ten plugin (aby uniknąć duplikatów).', 'yacht-booking' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
}
|
||||
// =====================================================================
|
||||
// Globalna synchronizacja iCal (jeden wspólny kalendarz Google,
|
||||
// podział na jachty po prefiksie nazwy w tytule eventu).
|
||||
// Działa niezależnie od OAuth — wystarczy publiczny URL kalendarza Google.
|
||||
// =====================================================================
|
||||
$global_import_url = (string) get_option( 'yacht_booking_global_ical_import_url', '' );
|
||||
$global_export_url = \YachtBooking\Integrations\ICal\ICal_Feed::get_global_feed_url();
|
||||
$last_global_run = (string) get_option( 'yacht_booking_global_ical_last_import', '' );
|
||||
?>
|
||||
<div class="card" style="margin-top: 30px;">
|
||||
<h3><?php esc_html_e( 'Globalna synchronizacja iCal (jeden wspólny kalendarz)', 'yacht-booking' ); ?></h3>
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'Mechanizm dwukierunkowej synchronizacji wszystkich jachtów z jednym kalendarzem Google, bez OAuth. Plugin rozpoznaje jacht po prefiksie tytułu eventu w formacie: "Nazwa jachtu - opis" (np. "Maja - Kowalski 5 osób"). Eventy bez rozpoznanego prefiksu są ignorowane.', 'yacht-booking' ); ?>
|
||||
</p>
|
||||
|
||||
/**
|
||||
* Handle OAuth callback
|
||||
*/
|
||||
private function handle_oauth_callback() {
|
||||
if ( ! isset( $_GET['code'] ) ) {
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=yacht-bookings-settings&tab=google-calendar&error=1' ) );
|
||||
exit;
|
||||
}
|
||||
<h4><?php esc_html_e( 'Krok 1: Dodaj feed pluginu jako kalendarz w Google', 'yacht-booking' ); ?></h4>
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'Skopiuj poniższy URL i dodaj go w Google Calendar: "Inne kalendarze" → "+ Dodaj" → "Z URL-a". Rezerwacje ze strony pojawią się w Twoim Google Calendar (Google odświeża subskrypcję co kilka godzin).', 'yacht-booking' ); ?>
|
||||
</p>
|
||||
<p>
|
||||
<input
|
||||
type="text"
|
||||
readonly
|
||||
value="<?php echo esc_attr( $global_export_url ); ?>"
|
||||
class="regular-text code"
|
||||
id="yacht-global-ical-export-url"
|
||||
style="width: 100%; max-width: 600px;"
|
||||
onclick="this.select();"
|
||||
/>
|
||||
<button type="button" class="button" onclick="navigator.clipboard.writeText(document.getElementById('yacht-global-ical-export-url').value); this.textContent='<?php echo esc_js( __( 'Skopiowano!', 'yacht-booking' ) ); ?>';">
|
||||
<?php esc_html_e( 'Kopiuj', 'yacht-booking' ); ?>
|
||||
</button>
|
||||
</p>
|
||||
<form method="post" action="" style="margin-top: 10px;" onsubmit="return confirm('<?php echo esc_js( __( 'Wygenerować nowy token? Poprzedni URL przestanie działać.', 'yacht-booking' ) ); ?>')">
|
||||
<?php wp_nonce_field( 'yacht_booking_regenerate_global_ical_token' ); ?>
|
||||
<button type="submit" name="yacht_booking_regenerate_global_ical_token" class="button button-secondary">
|
||||
<?php esc_html_e( 'Wygeneruj nowy token', 'yacht-booking' ); ?>
|
||||
</button>
|
||||
<span class="description" style="margin-left: 10px;">
|
||||
<?php esc_html_e( 'Unieważnia bieżący URL — używaj gdy podejrzewasz wyciek.', 'yacht-booking' ); ?>
|
||||
</span>
|
||||
</form>
|
||||
|
||||
$code = sanitize_text_field( wp_unslash( $_GET['code'] ) );
|
||||
$result = \YachtBooking\Integrations\GoogleCalendar\OAuth_Handler::authenticate( $code );
|
||||
<h4 style="margin-top: 25px;"><?php esc_html_e( 'Krok 2: Wklej iCal URL Twojego kalendarza Google', 'yacht-booking' ); ?></h4>
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'W Google Calendar otwórz ustawienia kalendarza → "Tajny adres w formacie iCal" → skopiuj URL i wklej poniżej. Plugin pobiera ten kalendarz co godzinę i importuje rozpoznane eventy jako blokady.', 'yacht-booking' ); ?>
|
||||
</p>
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field( 'yacht_booking_save_global_ical' ); ?>
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="global_ical_import_url"><?php esc_html_e( 'iCal Import URL', 'yacht-booking' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input
|
||||
type="url"
|
||||
name="global_ical_import_url"
|
||||
id="global_ical_import_url"
|
||||
class="regular-text"
|
||||
value="<?php echo esc_attr( $global_import_url ); ?>"
|
||||
placeholder="https://calendar.google.com/calendar/ical/..."
|
||||
style="width: 100%; max-width: 600px;"
|
||||
/>
|
||||
<?php if ( $last_global_run ) : ?>
|
||||
<p class="description">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: timestamp */
|
||||
esc_html__( 'Ostatni import: %s', 'yacht-booking' ),
|
||||
esc_html( $last_global_run )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="submit">
|
||||
<input type="submit" name="yacht_booking_save_global_ical" class="button-primary" value="<?php esc_attr_e( 'Zapisz URL', 'yacht-booking' ); ?>">
|
||||
</p>
|
||||
</form>
|
||||
|
||||
if ( $result ) {
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=yacht-bookings-settings&tab=google-calendar&connected=1' ) );
|
||||
} else {
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=yacht-bookings-settings&tab=google-calendar&error=1' ) );
|
||||
}
|
||||
exit;
|
||||
<h4 style="margin-top: 25px;"><?php esc_html_e( 'Krok 3: Importuj teraz (opcjonalnie)', 'yacht-booking' ); ?></h4>
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'Cron godzinny pobiera kalendarz automatycznie. Możesz wymusić import ręcznie:', 'yacht-booking' ); ?>
|
||||
</p>
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field( 'yacht_booking_run_global_ical_import' ); ?>
|
||||
<button type="submit" name="yacht_booking_run_global_ical_import" class="button">
|
||||
<?php esc_html_e( 'Importuj teraz', 'yacht-booking' ); ?>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<h4 style="margin-top: 25px;"><?php esc_html_e( 'Jak to działa', 'yacht-booking' ); ?></h4>
|
||||
<ul style="margin-left: 20px; list-style: disc;">
|
||||
<li><?php esc_html_e( 'Tytuły eventów w Google Calendar muszą mieć format: "Nazwa jachtu - dowolny opis" (separator to spacja-myślnik-spacja).', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Dopasowanie po pełnej nazwie jachtu lub jego aliasie (pole "Alias dla Google Calendar" w edycji jachtu).', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Eventy bez separatora albo z nieznanym prefiksem są ignorowane (nie tworzą blokad).', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Usunięcie eventu w Google Calendar usuwa odpowiadającą blokadę po następnym imporcie.', 'yacht-booking' ); ?></li>
|
||||
<li><?php esc_html_e( 'Eventy zaimportowane z Google nie są wysyłane z powrotem (anti-loop).', 'yacht-booking' ); ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1441,23 +1384,6 @@ class Admin {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Google Calendar credentials
|
||||
*/
|
||||
private function save_gcal_credentials() {
|
||||
if ( isset( $_POST['gcal_client_id'] ) && isset( $_POST['gcal_client_secret'] ) ) {
|
||||
$credentials = array(
|
||||
'client_id' => sanitize_text_field( wp_unslash( $_POST['gcal_client_id'] ) ),
|
||||
'client_secret' => sanitize_text_field( wp_unslash( $_POST['gcal_client_secret'] ) ),
|
||||
);
|
||||
|
||||
\YachtBooking\Integrations\GoogleCalendar\OAuth_Handler::save_credentials( $credentials );
|
||||
}
|
||||
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=yacht-bookings-settings&tab=google-calendar&saved=1' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process booking actions (approve, cancel, delete)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user