File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/traits.tar
trait-yith-wcwl-extensible-singleton-trait.php 0000644 00000002644 15153773247 0015632 0 ustar 00 <?php
/**
* Extensible Singleton class trait.
* Useful to allow only one instance for Extended/Premium classes.
*
* @package YITH\Wishlist\Traits
* @author YITH <plugins@yithemes.com>
*/
if ( ! trait_exists( 'YITH_WCWL_Extensible_Singleton_Trait' ) ) {
/**
* Extensible Singleton trait.
*/
trait YITH_WCWL_Extensible_Singleton_Trait {
/**
* Instance of the class.
*
* @var self|null
*/
private static $instance = null;
/**
* Constructor
*
* @return void
*/
protected function __construct() {
}
/**
* Get class instance.
*
* @return self
*/
final public static function get_instance() {
if ( is_null( self::$instance ) ) {
$extensions = array( '_Premium', '_Extended' ); // Allowed extensions ordered by priority.
$called_class = get_called_class();
$class = $called_class;
$extensions_regex = array_map(
function ( $extension ) {
return '/' . preg_quote( $extension, '/' ) . '$/';
},
$extensions
);
$base_class = preg_replace( $extensions_regex, '', $called_class );
foreach ( $extensions as $extension ) {
$extension_class = $base_class . $extension;
if ( class_exists( $extension_class ) ) {
$class = $extension_class;
break;
}
}
self::$instance = new $class();
}
return self::$instance;
}
/**
* Prevent cloning.
*/
private function __clone() {
}
}
}
trait-yith-wcwl-rendering-method-access-trait.php 0000644 00000010245 15153773250 0016150 0 ustar 00 <?php
/**
* Trait to access to Template rendering method
*
* @since 4.0.0
* @package YITH\Wishlist\Traits
* @author YITH <plugins@yithemes.com>
*/
if ( ! trait_exists( 'YITH_WCWL_Rendering_Method_Access_Trait' ) ) {
trait YITH_WCWL_Rendering_Method_Access_Trait {
/**
* The option name that store the templates rendering method.
*
* @var string
*/
private static $rendering_method_option_name = 'yith_wcwl_rendering_method';
/**
* The option name that store the templates rendering method.
*
* @var string
*/
private static $rendering_method = null;
/**
* The cookie name
*
* @var string
*/
private static $react_preview_key = 'yith-wcwl-react-preview-mode';
/**
* The query param used to trigger the exit from preview mode
*
* @var string
*/
private static $exit_from_preview_mode_param = 'yith-wcwl-exit-from-preview-mode';
/**
* The query param used to convert the rendering method using React Components
*
* @var string
*/
private static $convert_to_react_rendering_param = 'yith-wcwl-convert-to-react';
/**
* Store whether the rendering method has been updated
*
* @var string
*/
private static $updated_rendering_method = false;
/**
* Get the templates rendering method option value
*
* @param string $default The default value.
* @param bool $force_update Whether is needed to force the retrieving of the option value.
*
* @return string
*/
public static function get_rendering_method( $default = 'react-components', $force_update = false ) {
if ( self::is_preview_mode() ) {
self::$rendering_method = 'react-components';
}
if ( is_null( self::$rendering_method ) || $force_update ) { // TODO: handle $force_update in preview mode.
self::$rendering_method = self::get_rendering_method_option( $default );
}
return apply_filters( 'yith_wcwl_rendering_method', self::$rendering_method, $default, $force_update );
}
/**
* get rendering method option value
*
* @param mixed $default The default value.
*
* @return string
*/
public static function get_rendering_method_option( $default = 'react-components' ) {
if ( is_null( self::$rendering_method ) ) {
self::$rendering_method = get_option( self::$rendering_method_option_name, $default );
}
return self::$rendering_method;
}
/**
* Set the templates rendering method option value
*
* @param string $value The value to set.
*
* @return string
*/
public static function update_rendering_method( $value ) {
if ( self::current_user_can_manage_rendering_method() ) {
self::$rendering_method = null;
return update_option( self::$rendering_method_option_name, $value );
}
}
/**
* Check whether the current user can manage the rendering method
*
* @return bool
*/
public static function current_user_can_manage_rendering_method() {
return current_user_can( 'manage_options' );
}
/**
* Check if is the React rendering preview mode
*
* @return bool
*/
public static function is_preview_mode() {
if ( 'php-templates' === self::get_rendering_method_option() ) {
if ( yith_getcookie( self::$react_preview_key ) ) {
return true;
}
if ( is_user_logged_in() ) {
$user_id = function_exists( 'get_current_user_id' ) ? get_current_user_id() : false;
if ( $user_id ) {
if ( get_user_meta( $user_id, self::$react_preview_key, true ) ) {
return true;
}
}
}
}
return false;
}
/**
* Check if is using the php-templates rendering method
*
* @return bool
*/
public static function is_php_templates_mode() {
return 'php-templates' === self::get_rendering_method();
}
/**
* Update options related to preview rendering method (Session cookie and User meta if is logged id)
*
* @param bool $value The options value
*
* @return void
*/
protected function update_preview_options( $value ) {
yith_setcookie( self::$react_preview_key, $value );
$user_id = function_exists( 'get_current_user_id' ) ? get_current_user_id() : false;
if ( $user_id ) {
update_user_meta( $user_id, self::$react_preview_key, $value );
}
}
}
}
trait-yith-wcwl-singleton-trait.php 0000644 00000001223 15153773250 0013454 0 ustar 00 <?php
/**
* Singleton class trait.
*
* @package YITH\Wishlist\Traits
*/
defined( 'YITH_WCWL' ) || exit; // Exit if accessed directly
/**
* Singleton trait.
*/
trait YITH_WCWL_Singleton_Trait {
/**
* The single instance of the class.
*
* @var self
*/
protected static $instance = null;
/**
* Constructor
*
* @return void
*/
protected function __construct() {
}
/**
* Get class instance.
*
* @return self
*/
final public static function get_instance() {
return ! is_null( static::$instance ) ? static::$instance : static::$instance = new static();
}
/**
* Prevent cloning.
*/
private function __clone() {
}
}
trait-wc-item-totals.php 0000644 00000004114 15154263150 0011251 0 ustar 00 <?php
/**
* This ongoing trait will have shared calculation logic between WC_Abstract_Order and WC_Cart_Totals classes.
*
* @package WooCommerce\Traits
* @version 3.9.0
*/
use Automattic\WooCommerce\Utilities\NumberUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Trait WC_Item_Totals.
*
* Right now this do not have much, but plan is to eventually move all shared calculation logic between Orders and Cart in this file.
*
* @since 3.9.0
*/
trait WC_Item_Totals {
/**
* Line items to calculate. Define in child class.
*
* @since 3.9.0
* @param string $field Field name to calculate upon.
*
* @return array having `total`|`subtotal` property.
*/
abstract protected function get_values_for_total( $field );
/**
* Return rounded total based on settings. Will be used by Cart and Orders.
*
* @since 3.9.0
*
* @param array $values Values to round. Should be with precision.
*
* @return float|int Appropriately rounded value.
*/
public static function get_rounded_items_total( $values ) {
return array_sum(
array_map(
array( self::class, 'round_item_subtotal' ),
$values
)
);
}
/**
* Apply rounding to item subtotal before summing.
*
* @since 3.9.0
* @param float $value Item subtotal value.
* @return float
*/
public static function round_item_subtotal( $value ) {
if ( ! self::round_at_subtotal() ) {
$value = NumberUtil::round( $value );
}
return $value;
}
/**
* Should always round at subtotal?
*
* @since 3.9.0
* @return bool
*/
protected static function round_at_subtotal() {
return 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' );
}
/**
* Apply rounding to an array of taxes before summing. Rounds to store DP setting, ignoring precision.
*
* @since 3.2.6
* @param float $value Tax value.
* @param bool $in_cents Whether precision of value is in cents.
* @return float
*/
protected static function round_line_tax( $value, $in_cents = true ) {
if ( ! self::round_at_subtotal() ) {
$value = wc_round_tax_total( $value, $in_cents ? 0 : null );
}
return $value;
}
}