This commit is contained in:
2026-05-07 14:57:59 +02:00
parent c4a485e530
commit 811069a25c
35 changed files with 2980 additions and 30 deletions

View File

@@ -167,6 +167,7 @@ class Installer {
'yacht_booking_global_ical_import_url' => '',
'yacht_booking_global_ical_token' => '',
'yacht_booking_global_ical_last_import' => '',
'yacht_booking_ical_sync_mode' => 'per_yacht',
);
foreach ( $options as $key => $value ) {

View File

@@ -113,6 +113,20 @@ class Settings {
return trim( number_format_i18n( (float) $amount, 2 ) . ' ' . self::get_currency_symbol() );
}
/**
* Get iCal sync mode.
*
* Tryb synchronizacji iCal:
* - per_yacht: import po prefiksie SUMMARY ("Nazwa - opis"), wpisy do availability
* - global: wszystkie eventy zapisane jako wspólne wydarzenia kalendarza, bez wpływu na availability
*
* @return string
*/
public static function get_ical_sync_mode() {
$mode = get_option( 'yacht_booking_ical_sync_mode', 'per_yacht' );
return in_array( $mode, array( 'per_yacht', 'global' ), true ) ? $mode : 'per_yacht';
}
/**
* Get terms page ID.
*

View File

@@ -77,6 +77,9 @@ class Yacht_Booking {
require_once YACHT_BOOKING_PLUGIN_DIR . 'includes/class-booking.php';
require_once YACHT_BOOKING_PLUGIN_DIR . 'includes/class-availability.php';
// REST controller — eagerly loaded because View helpers use its color palette + stałe.
require_once YACHT_BOOKING_PLUGIN_DIR . 'api/class-rest-controller.php';
// Load admin classes
if ( is_admin() ) {
require_once YACHT_BOOKING_PLUGIN_DIR . 'admin/class-admin.php';
@@ -157,6 +160,24 @@ class Yacht_Booking {
true
);
// Calendar (all yachts) — wspólny widget. Załaduj tylko gdy strona go potrzebuje.
if ( $this->should_load_calendar_all_assets() ) {
wp_enqueue_style(
'yacht-booking-calendar-all',
YACHT_BOOKING_PLUGIN_URL . 'frontend/assets/css/calendar-all.css',
array( 'fullcalendar' ),
filemtime( YACHT_BOOKING_PLUGIN_DIR . 'frontend/assets/css/calendar-all.css' )
);
wp_enqueue_script(
'yacht-booking-calendar-all',
YACHT_BOOKING_PLUGIN_URL . 'frontend/assets/js/calendar-all.js',
array( 'jquery', 'fullcalendar', 'fullcalendar-pl' ),
filemtime( YACHT_BOOKING_PLUGIN_DIR . 'frontend/assets/js/calendar-all.js' ),
true
);
}
// Localize script
wp_localize_script(
'yacht-booking-calendar',
@@ -228,8 +249,53 @@ class Yacht_Booking {
return true;
}
// Check if post contains yacht calendar shortcode or widget
if ( $post && ( has_shortcode( $post->post_content, 'yacht_calendar' ) || $this->has_yacht_calendar_widget( $post->ID ) ) ) {
// Check if post contains yacht calendar shortcode or widget (per-jacht lub wszystkie)
if ( $post ) {
if ( has_shortcode( $post->post_content, 'yacht_calendar' )
|| has_shortcode( $post->post_content, 'yacht_calendar_all' )
|| $this->has_yacht_calendar_widget( $post->ID )
|| $this->has_yacht_calendar_all_widget( $post->ID ) ) {
return true;
}
}
return false;
}
/**
* Check if post contains the wspólny widget kalendarza floty.
*
* @param int $post_id Post ID.
* @return bool
*/
private function has_yacht_calendar_all_widget( $post_id ) {
if ( ! class_exists( '\Elementor\Plugin' ) ) {
return false;
}
$document = \Elementor\Plugin::$instance->documents->get( $post_id );
if ( ! $document ) {
return false;
}
$data = $document->get_elements_data();
return $this->find_widget_recursive( $data, 'yacht-calendar-all' );
}
/**
* Check if calendar-all (wspólny) assets should be loaded — used to enqueue
* dodatkowe pliki tylko na stronach które ich potrzebują.
*
* @return bool
*/
private function should_load_calendar_all_assets() {
global $post;
if ( class_exists( '\Elementor\Plugin' ) && \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
return true;
}
if ( $post && ( has_shortcode( $post->post_content, 'yacht_calendar_all' ) || $this->has_yacht_calendar_all_widget( $post->ID ) ) ) {
return true;
}
@@ -296,11 +362,13 @@ class Yacht_Booking {
* @param object $widgets_manager Elementor widgets manager.
*/
public function register_elementor_widgets( $widgets_manager ) {
// Load widget class
// Load widget classes
require_once YACHT_BOOKING_PLUGIN_DIR . 'frontend/class-calendar-widget.php';
require_once YACHT_BOOKING_PLUGIN_DIR . 'frontend/class-calendar-widget-all.php';
// Register widget
// Register widgets
$widgets_manager->register( new Calendar_Widget() );
$widgets_manager->register( new Calendar_Widget_All() );
}
/**