| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Services\LandingPage; |
| 4 |
|
| 5 |
use FluentBooking\App\Models\Calendar; |
| 6 |
use FluentBooking\App\Services\Helper; |
| 7 |
use FluentBooking\Framework\Support\Arr; |
| 8 |
|
| 9 |
class LandingPageHelper |
| 10 |
{ |
| 11 |
public static function getSettings(Calendar $calendar, $scope = 'admin') |
| 12 |
{ |
| 13 |
$sharingSettings = $calendar->getMeta('sharing_settings', []); |
| 14 |
|
| 15 |
$defaults = [ |
| 16 |
'enabled' => 'no', |
| 17 |
'enabled_slots' => [], |
| 18 |
'show_type' => 'all' |
| 19 |
]; |
| 20 |
|
| 21 |
$settings = wp_parse_args($sharingSettings, $defaults); |
| 22 |
|
| 23 |
return apply_filters('fluent_booking/calendar/sharing_settings', $settings, $calendar, $scope); |
| 24 |
} |
| 25 |
|
| 26 |
public static function updateSettings(Calendar $calendar, $settings) |
| 27 |
{ |
| 28 |
$defaults = [ |
| 29 |
'enabled' => 'no', |
| 30 |
'enabled_slots' => [], |
| 31 |
'show_type' => 'all' |
| 32 |
]; |
| 33 |
|
| 34 |
$sharingSettings = Arr::only($settings, array_keys($defaults)); |
| 35 |
$sharingSettings = wp_parse_args($sharingSettings, $defaults); |
| 36 |
|
| 37 |
if ($sharingSettings['show_type'] == 'all' || $sharingSettings['enabled'] == 'no') { |
| 38 |
$sharingSettings['enabled_slots'] = []; |
| 39 |
} else { |
| 40 |
$sharingSettings['enabled_slots'] = array_map('intval', $sharingSettings['enabled_slots']); |
| 41 |
} |
| 42 |
|
| 43 |
$sharingSettings['enabled'] = $sharingSettings['enabled'] == 'yes' ? 'yes' : 'no'; |
| 44 |
|
| 45 |
$settings['show_type'] = sanitize_text_field($sharingSettings['show_type']); |
| 46 |
|
| 47 |
$calendar->updateMeta('sharing_settings', $sharingSettings); |
| 48 |
|
| 49 |
return $settings; |
| 50 |
} |
| 51 |
|
| 52 |
public static function getLandingBaseUrl() |
| 53 |
{ |
| 54 |
if (defined('FLUENT_BOOKING_LANDING_SLUG')) { |
| 55 |
return site_url(FLUENT_BOOKING_LANDING_SLUG . '/'); |
| 56 |
} |
| 57 |
|
| 58 |
return site_url('/?fluent-booking=calendar'); |
| 59 |
} |
| 60 |
|
| 61 |
public static function getPoweredByHtml() |
| 62 |
{ |
| 63 |
if (defined('FLUENT_BOOKING_PRO_DIR_FILE')) { |
| 64 |
return ''; |
| 65 |
} |
| 66 |
|
| 67 |
$html = '<div class="fcal_powered_by">'; |
| 68 |
$html .= esc_html__('Powered By', 'fluent-booking'); |
| 69 |
$html .= ' <span><a target="_blank" href="' . esc_url(Helper::getUpgradeUrl()) . '">'; |
| 70 |
$html .= esc_html__('FluentBooking', 'fluent-booking'); |
| 71 |
$html .= '</a></span>'; |
| 72 |
$html .= '</div>'; |
| 73 |
|
| 74 |
return $html; |
| 75 |
} |
| 76 |
} |
| 77 |
|