155 lines
3.5 KiB
PHP
155 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* Plugin settings helper.
|
|
*
|
|
* @package YachtBooking
|
|
*/
|
|
|
|
namespace YachtBooking;
|
|
|
|
// Exit if accessed directly.
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Settings helper class.
|
|
*/
|
|
class Settings {
|
|
|
|
/**
|
|
* Check if online booking is enabled.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function is_booking_enabled() {
|
|
return '1' === get_option( 'yacht_booking_enabled', '1' );
|
|
}
|
|
|
|
/**
|
|
* Get default booking status.
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function get_default_status() {
|
|
$status = get_option( 'yacht_booking_default_status', 'pending' );
|
|
return in_array( $status, array( 'pending', 'confirmed' ), true ) ? $status : 'pending';
|
|
}
|
|
|
|
/**
|
|
* Get email from name.
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function get_email_from_name() {
|
|
$value = get_option( 'yacht_booking_email_from_name', get_bloginfo( 'name' ) );
|
|
return is_string( $value ) && '' !== $value ? $value : get_bloginfo( 'name' );
|
|
}
|
|
|
|
/**
|
|
* Get email from address.
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function get_email_from_address() {
|
|
$value = get_option( 'yacht_booking_email_from', '' );
|
|
|
|
// Backward compatibility with older option name.
|
|
if ( empty( $value ) ) {
|
|
$value = get_option( 'yacht_booking_email_from_address', get_option( 'admin_email' ) );
|
|
}
|
|
|
|
return is_email( $value ) ? $value : get_option( 'admin_email' );
|
|
}
|
|
|
|
/**
|
|
* Get supported date formats.
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function get_supported_date_formats() {
|
|
return array( 'Y-m-d', 'd/m/Y', 'm/d/Y', 'd.m.Y' );
|
|
}
|
|
|
|
/**
|
|
* Get date format.
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function get_date_format() {
|
|
$format = get_option( 'yacht_booking_date_format', 'Y-m-d' );
|
|
return in_array( $format, self::get_supported_date_formats(), true ) ? $format : 'Y-m-d';
|
|
}
|
|
|
|
/**
|
|
* Format date using plugin settings.
|
|
*
|
|
* @param string $date Date string.
|
|
* @return string
|
|
*/
|
|
public static function format_date( $date ) {
|
|
$timestamp = strtotime( (string) $date );
|
|
return false !== $timestamp ? date_i18n( self::get_date_format(), $timestamp ) : '';
|
|
}
|
|
|
|
/**
|
|
* Get currency symbol.
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function get_currency_symbol() {
|
|
$symbol = get_option( 'yacht_booking_currency_symbol', 'zł' );
|
|
$symbol = is_string( $symbol ) ? trim( $symbol ) : '';
|
|
return '' !== $symbol ? $symbol : 'zł';
|
|
}
|
|
|
|
/**
|
|
* Format price using plugin settings.
|
|
*
|
|
* @param float $amount Amount.
|
|
* @return string
|
|
*/
|
|
public static function format_price( $amount ) {
|
|
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.
|
|
*
|
|
* @return int
|
|
*/
|
|
public static function get_terms_page_id() {
|
|
return absint( get_option( 'yacht_booking_terms_page_id', 0 ) );
|
|
}
|
|
|
|
/**
|
|
* Get terms page URL.
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function get_terms_page_url() {
|
|
$page_id = self::get_terms_page_id();
|
|
if ( ! $page_id ) {
|
|
return '';
|
|
}
|
|
|
|
$url = get_permalink( $page_id );
|
|
return $url ? $url : '';
|
|
}
|
|
}
|
|
|