|
Server IP : 10.131.40.8 / Your IP : 216.73.216.37 Web Server : Apache System : Linux webd008.cluster131.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 User : ludmqhh ( 137773) PHP Version : 8.4.10 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/ludmqhh/www/hotel-forum/wp-content/plugins/wp-hotelier/includes/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
/**
* Hotelier Price Functions.
*
* @author Benito Lopez <hello@lopezb.com>
* @category Core
* @package Hotelier/Functions
* @version 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Return the thousand separator for prices
* @return string
*/
function htl_get_price_thousand_separator() {
$separator = stripslashes( htl_get_option( 'thousands_separator', ',' ) );
return $separator;
}
/**
* Return the decimal separator for prices
* @return string
*/
function htl_get_price_decimal_separator() {
$separator = stripslashes( htl_get_option( 'decimal_separator', '.' ) );
return $separator ? $separator : '.';
}
/**
* Return the number of decimals after the decimal point.
* @return int
*/
function htl_get_price_decimals() {
return absint( htl_get_option( 'price_num_decimals', 2 ) );
}
/**
* Get full list of currency codes.
*/
function htl_get_currencies() {
$currencies = array(
'USD' => esc_html__( 'US Dollars ($)', 'wp-hotelier' ),
'EUR' => esc_html__( 'Euros (€)', 'wp-hotelier' ),
'GBP' => esc_html__( 'Pounds Sterling (£)', 'wp-hotelier' ),
'AUD' => esc_html__( 'Australian Dollars ($)', 'wp-hotelier' ),
'BRL' => esc_html__( 'Brazilian Real (R$)', 'wp-hotelier' ),
'CAD' => esc_html__( 'Canadian Dollars ($)', 'wp-hotelier' ),
'CZK' => esc_html__( 'Czech Koruna', 'wp-hotelier' ),
'DKK' => esc_html__( 'Danish Krone', 'wp-hotelier' ),
'HKD' => esc_html__( 'Hong Kong Dollar ($)', 'wp-hotelier' ),
'HUF' => esc_html__( 'Hungarian Forint', 'wp-hotelier' ),
'ILS' => esc_html__( 'Israeli Shekel (₪)', 'wp-hotelier' ),
'JPY' => esc_html__( 'Japanese Yen (¥)', 'wp-hotelier' ),
'MYR' => esc_html__( 'Malaysian Ringgits', 'wp-hotelier' ),
'MXN' => esc_html__( 'Mexican Peso ($)', 'wp-hotelier' ),
'NZD' => esc_html__( 'New Zealand Dollar ($)', 'wp-hotelier' ),
'NOK' => esc_html__( 'Norwegian Krone', 'wp-hotelier' ),
'PHP' => esc_html__( 'Philippine Pesos', 'wp-hotelier' ),
'PLN' => esc_html__( 'Polish Zloty', 'wp-hotelier' ),
'SGD' => esc_html__( 'Singapore Dollar ($)', 'wp-hotelier' ),
'SEK' => esc_html__( 'Swedish Krona', 'wp-hotelier' ),
'CHF' => esc_html__( 'Swiss Franc', 'wp-hotelier' ),
'TWD' => esc_html__( 'Taiwan New Dollars', 'wp-hotelier' ),
'THB' => esc_html__( 'Thai Baht (฿)', 'wp-hotelier' ),
'INR' => esc_html__( 'Indian Rupee (₹)', 'wp-hotelier' ),
'TRY' => esc_html__( 'Turkish Lira (₺)', 'wp-hotelier' ),
'RUB' => esc_html__( 'Russian Rubles', 'wp-hotelier' )
);
return apply_filters( 'hotelier_currencies', $currencies );
}
/**
* Get Base Currency Code.
* @return string
*/
function htl_get_currency() {
return apply_filters( 'hotelier_currency', htl_get_option( 'currency', 'USD' ) );
}
/**
* Get Currency symbol.
* @param string $currency (default: '')
* @return string
*/
function htl_get_currency_symbol( $currency = '' ) {
if ( ! $currency ) {
$currency = htl_get_currency();
}
switch ( $currency ) {
case 'AUD' :
case 'CAD' :
case 'HKD' :
case 'MXN' :
case 'NZD' :
case 'SGD' :
case 'USD' :
$currency_symbol = '$';
break;
case 'BRL' :
$currency_symbol = 'R$';
break;
case 'CHF' :
$currency_symbol = 'CHF';
break;
case 'JPY' :
$currency_symbol = '¥';
break;
case 'CZK' :
$currency_symbol = 'Kč';
break;
case 'DKK' :
$currency_symbol = 'DKK';
break;
case 'EUR' :
$currency_symbol = '€';
break;
case 'GBP' :
$currency_symbol = '£';
break;
case 'HUF' :
$currency_symbol = 'Ft';
break;
case 'ILS' :
$currency_symbol = '₪';
break;
case 'INR' :
$currency_symbol = 'Rs.';
break;
case 'MYR' :
$currency_symbol = 'RM';
break;
case 'NOK' :
$currency_symbol = 'kr';
break;
case 'PHP' :
$currency_symbol = '₱';
break;
case 'PLN' :
$currency_symbol = 'zł';
break;
case 'RUB' :
$currency_symbol = 'руб.';
break;
case 'SEK' :
$currency_symbol = 'kr';
break;
case 'THB' :
$currency_symbol = '฿';
break;
case 'TRY' :
$currency_symbol = '₺';
break;
case 'TWD' :
$currency_symbol = 'NT$';
break;
default :
$currency_symbol = '';
break;
}
return apply_filters( 'hotelier_currency_symbol', $currency_symbol, $currency );
}
if ( ! function_exists( 'htl_price' ) ) {
/**
* Format the price with a currency symbol.
*
* @param float $price
* @param string $currency
* @return string
*/
function htl_price( $price, $currency = '' ) {
$thousands_sep = htl_get_price_thousand_separator();
$decimal_sep = htl_get_price_decimal_separator();
$decimals = htl_get_price_decimals();
$position = htl_get_option( 'currency_position', 'before' );
$price = number_format( (double) $price, $decimals, $decimal_sep, $thousands_sep );
$price = ( $position == 'before' ) ? htl_get_currency_symbol( $currency ) . $price : $price . htl_get_currency_symbol( $currency );
$return = '<span class="amount">' . $price . '</span>';
return apply_filters( 'hotelier_price', $return, $price );
}
}
if ( ! function_exists( 'htl_price_raw' ) ) {
/**
* Format the price with a currency symbol. Without HTML tags.
*
* @param float $price
* @param string $currency
* @return string
*/
function htl_price_raw( $price, $currency = '' ) {
$thousands_sep = htl_get_price_thousand_separator();
$decimal_sep = htl_get_price_decimal_separator();
$decimals = htl_get_price_decimals();
$position = htl_get_option( 'currency_position', 'before' );
$price = number_format( (double) $price, $decimals, $decimal_sep, $thousands_sep );
$price = ( $position == 'before' ) ? htl_get_currency_symbol( $currency ) . $price : $price . htl_get_currency_symbol( $currency );
$return = $price;
return apply_filters( 'hotelier_price_raw', $return, $price );
}
}
/**
* Count cents in prices (prices are stored as integers).
*
* @param int $amount
* @return float
*/
function htl_convert_to_cents( $amount ) {
$amount = $amount / 100;
return apply_filters( 'hotelier_convert_to_cents', $amount );
}
/**
* Calculates the deposit with a currency symbol.
*
* @param int $price
* @param int $deposit
* @param string $currency
* @return string
*/
function htl_calculate_deposit( $price, $deposit, $currency = '' ) {
$price = $price / 100;
$price = ( $price * $deposit ) / 100;
$price = htl_price( $price, $currency );
return apply_filters( 'hotelier_calculate_deposit', $price );
}
/**
* Gets seasonal prices schema.
*
* @return array
*/
function htl_get_seasonal_prices_schema() {
$schema = htl_get_option( 'seasonal_prices_schema', array() );
return $schema;
}
