<?php
declare(strict_types=1);
namespace MPBC;
use MPBC\Post_Type\Statuses\Booking_Statuses;
use MPBC\Bundles;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Settings {
protected const DEFAULT_WP_DATE_FORMAT = 'F j, Y';
protected const DEFAULT_WP_TIME_FORMAT = 'H:i';
public static function get_default_booking_status(): string {
return Booking_Statuses::STATUS_CONFIRMED;
}
public static function get_booking_confirmation_page_id(): int {
return static::get_page_id( 'mpbc_booking_confirmation_page' );
}
public static function get_booking_confirmation_page_url(): string {
return static::get_page_url( static::get_booking_confirmation_page_id() );
}
/**
* @return string Currency code, like 'EUR'.
*/
public static function get_currency(): string {
return get_option( 'mpbc_currency', 'EUR' );
}
public static function get_default_currency(): string {
return 'EUR';
}
public static function get_currency_symbol(): string {
return Bundles::get_currency_symbol( static::get_currency() );
}
public static function get_currency_position(): string {
return get_option( 'mpbc_currency_position', 'before' );
}
public static function get_decimal_separator(): string {
return get_option( 'mpbc_decimal_separator', '.' );
}
public static function get_thousands_separator(): string {
return get_option( 'mpbc_thousands_separator', ',' );
}
public static function get_decimals_count(): int {
return (int) get_option( 'mpbc_number_of_decimals', 2 );
}
public static function get_admin_email(): string {
$admin_email = get_option( 'mpbc_admin_email', '' );
if ( $admin_email !== '' ) {
return $admin_email;
} else {
return static::get_default_admin_email();
}
}
public static function get_default_admin_email(): string {
return get_bloginfo( 'admin_email' );
}
public static function get_from_email(): string {
$from_email = get_option( 'mpbc_from_email', '' );
if ( $from_email !== '' ) {
return $from_email;
} else {
return static::get_admin_email();
}
}
public static function get_from_name(): string {
$from_name = get_option( 'mpbc_from_name', '' );
if ( $from_name !== '' ) {
return $from_name;
} else {
return static::get_default_from_name();
}
}
public static function get_default_from_name(): string {
return static::get_blog_name();
}
public static function has_logo_url(): bool {
return static::get_logo_url() !== '';
}
public static function get_logo_url(): string {
$logo_url = get_option( 'mpbc_logo_url', '' );
/**
* @param string $logo_url
*/
$logo_url = apply_filters( 'mpbc_logo_url', $logo_url );
return $logo_url;
}
public static function get_footer_text(): string {
$footer_text = get_option( 'mpbc_footer_text', '' );
if ( $footer_text !== '' ) {
return $footer_text;
} else {
return static::get_default_footer_text();
}
}
public static function get_default_footer_text(): string {
return __( '{site_link} — Built with {plugin_name}', 'motopress-booking-calendar' );
}
public static function get_email_base_color(): string {
$base_color = get_option( 'mpbc_email_base_color', '' );
if ( $base_color !== '' ) {
return $base_color;
} else {
return static::get_default_email_base_color();
}
}
public static function get_default_email_base_color(): string {
return '#557da1';
}
public static function get_email_background_color(): string {
$bg_color = get_option( 'mpbc_email_bg_color', '' );
if ( $bg_color !== '' ) {
return $bg_color;
} else {
return static::get_default_email_background_color();
}
}
public static function get_default_email_background_color(): string {
return '#f5f5f5';
}
public static function get_email_body_color(): string {
$body_color = get_option( 'mpbc_email_body_color', '' );
if ( $body_color !== '' ) {
return $body_color;
} else {
return static::get_default_email_body_color();
}
}
public static function get_default_email_body_color(): string {
return '#fdfdfd';
}
public static function get_email_text_color(): string {
$text_color = get_option( 'mpbc_email_text_color', '' );
if ( $text_color !== '' ) {
return $text_color;
} else {
return static::get_default_email_text_color();
}
}
public static function get_default_email_text_color(): string {
return '#505050';
}
public static function get_blog_name(): string {
return get_bloginfo( 'name' );
}
public static function get_current_language(): string {
/**
* @param string $current_language
*/
return apply_filters( 'mpbc_current_language', static::get_wp_locale() );
}
public static function get_flatpickr_locale(): string {
$wp_locale = static::get_wp_locale();
$flatpickr_locale = Bundles::get_flatpickr_locale( $wp_locale );
/**
* @param string $flatpickr_locale
* @param string $wp_locale
*/
$flatpickr_locale = apply_filters( 'mpbc_flatpickr_l10n', $flatpickr_locale, $wp_locale );
return $flatpickr_locale;
}
public static function get_start_of_week(): int {
return intval( get_option( 'start_of_week', '1' ) );
}
public static function get_public_date_format(): string {
return static::get_wp_date_format();
}
public static function get_public_datetime_format(): string {
return static::get_wp_datetime_format();
}
public static function get_public_time_format(): string {
return static::get_wp_time_format();
}
public static function get_wp_locale(): string {
return determine_locale();
}
public static function get_wp_timezone(): \DateTimeZone {
return wp_timezone();
}
/**
* @return int Time zone offset in seconds.
*/
public static function get_wp_timezone_offset(): int {
$gmt_offset = (float) get_option( 'gmt_offset', '0' );
return intval( $gmt_offset * HOUR_IN_SECONDS );
}
/**
* @return string "Europe/Rome", "-06:30", "+08:45" etc.
*/
public static function get_wp_timezone_string(): string {
return wp_timezone_string();
}
/**
* The default time zone used when creating a Date_Time object.
*/
public static function get_default_timezone(): \DateTimeZone {
return static::get_wp_timezone();
}
public static function get_wp_date_format(): string {
return get_option( 'date_format', static::DEFAULT_WP_DATE_FORMAT );
}
public static function get_wp_datetime_format(): string {
return static::get_wp_date_format() . ' ' . static::get_wp_time_format();
}
public static function get_wp_time_format(): string {
return get_option( 'time_format', static::DEFAULT_WP_TIME_FORMAT );
}
public static function get_post_datetime_format(): string {
return static::get_wp_date_format() . ' @ ' . static::get_wp_time_format();
}
private static function get_page_id( string $option_name ): int {
$page = get_option( $option_name, '' );
return $page !== '' ? (int) $page : 0;
}
private static function get_page_url( int $page_id ): string {
return $page_id !== 0 ? get_permalink( $page_id ) : '';
}
}