ï»¿PK     £¦/]˜æ{«€  €    EmailFont.phpnu ßú¥ÿ        <?php
/**
 * EmailFont class file
 */

declare( strict_types = 1 );

namespace Automattic\WooCommerce\Internal\Email;

/**
 * Helper class for getting fonts for emails.
 *
 * @internal Just for internal use.
 */
class EmailFont {

	/**
	 * Array of font families supported in email templates
	 *
	 * @var string[]
	 */
	public static $font = array(
		'Arial'           => "Arial, 'Helvetica Neue', Helvetica, sans-serif",
		'Comic Sans MS'   => "'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif",
		'Courier New'     => "'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace",
		'Georgia'         => "Georgia, Times, 'Times New Roman', serif",
		'Helvetica'       => "'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif",
		'Lucida'          => "'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
		'Tahoma'          => 'Tahoma, Verdana, Segoe, sans-serif',
		'Times New Roman' => "'Times New Roman', Times, Baskerville, Georgia, serif",
		'Trebuchet MS'    => "'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Tahoma, sans-serif",
		'Verdana'         => 'Verdana, Geneva, sans-serif',
	);
}
PK     £¦/]êÂïµ      EmailStyleSync.phpnu ßú¥ÿ        <?php
declare( strict_types = 1 );

namespace Automattic\WooCommerce\Internal\Email;

use Automattic\WooCommerce\Internal\RegisterHooksInterface;

/**
 * Helper class for syncing email styles with theme styles.
 *
 * @internal Just for internal use.
 */
class EmailStyleSync implements RegisterHooksInterface {

	/**
	 * Option name for auto-sync setting.
	 */
	const AUTO_SYNC_OPTION = 'woocommerce_email_auto_sync_with_theme';

	/**
	 * Flag to prevent recursive syncing.
	 *
	 * @var bool
	 */
	private $is_syncing = false;

	/**
	 * Register hooks and filters.
	 */
	public function register() {
		// Hook into theme change events.
		add_action( 'after_switch_theme', array( $this, 'sync_email_styles_with_theme' ) );
		add_action( 'customize_save_after', array( $this, 'sync_email_styles_with_theme' ) );

		// Hook into theme.json and global styles changes.
		add_action( 'wp_theme_json_data_updated', array( $this, 'sync_email_styles_with_theme' ) );
		add_action( 'rest_after_insert_global_styles', array( $this, 'sync_email_styles_with_theme' ) );
		add_action( 'update_option_wp_global_styles', array( $this, 'sync_email_styles_with_theme' ) );
		add_action( 'save_post_wp_global_styles', array( $this, 'sync_email_styles_with_theme' ) );

		// Hook into the theme editor save action.
		add_action( 'wp_ajax_wp_save_styles', array( $this, 'sync_email_styles_with_theme' ), 999 );

		// Hook into auto-sync option update to trigger sync when enabled.
		add_action( 'update_option_' . self::AUTO_SYNC_OPTION, array( $this, 'maybe_sync_on_option_update' ), 10, 3 );
	}

	/**
	 * Trigger sync when auto-sync option is enabled.
	 *
	 * @param mixed  $old_value The old option value.
	 * @param mixed  $new_value The new option value.
	 * @param string $option    The option name.
	 */
	public function maybe_sync_on_option_update( $old_value, $new_value, $option ) {
		if ( 'yes' === $new_value && 'yes' !== $old_value ) {
			// Force sync regardless of current auto-sync setting since we know it's being enabled.
			$this->is_syncing = true;
			try {
				$this->update_email_colors();
			} finally {
				$this->is_syncing = false;
			}
		}
	}

	/**
	 * Check if auto-sync is enabled.
	 *
	 * @return bool Whether auto-sync is enabled.
	 */
	public function is_auto_sync_enabled() {
		return 'yes' === get_option( self::AUTO_SYNC_OPTION, 'no' );
	}

	/**
	 * Set auto-sync enabled status.
	 *
	 * @param bool $enabled Whether auto-sync should be enabled.
	 * @return bool Whether the option was updated.
	 */
	public function set_auto_sync( bool $enabled ) {
		return update_option( self::AUTO_SYNC_OPTION, $enabled ? 'yes' : 'no' );
	}

	/**
	 * Sync email styles with theme styles if auto-sync is enabled.
	 *
	 * Uses a flag to prevent recursive calls.
	 */
	public function sync_email_styles_with_theme() {
		if ( $this->is_syncing || ! $this->is_auto_sync_enabled() || ! wp_theme_has_theme_json() ) {
			return;
		}

		$this->is_syncing = true;

		try {
			$this->update_email_colors();
		} finally {
			$this->is_syncing = false;
		}
	}

	/**
	 * Update email colors from theme colors.
	 */
	protected function update_email_colors() {
		$colors = EmailColors::get_default_colors();
		if ( empty( $colors ) ) {
			return;
		}

		if ( ! empty( $colors['base'] ) ) {
			update_option( 'woocommerce_email_base_color', $colors['base'] );
		}

		if ( ! empty( $colors['bg'] ) ) {
			update_option( 'woocommerce_email_background_color', $colors['bg'] );
		}

		if ( ! empty( $colors['body_bg'] ) ) {
			update_option( 'woocommerce_email_body_background_color', $colors['body_bg'] );
		}

		if ( ! empty( $colors['body_text'] ) ) {
			update_option( 'woocommerce_email_text_color', $colors['body_text'] );
		}

		if ( ! empty( $colors['footer_text'] ) ) {
			update_option( 'woocommerce_email_footer_text_color', $colors['footer_text'] );
		}
	}
}
PK     £¦/]…Õ87Y  Y    EmailColors.phpnu ßú¥ÿ        <?php
/**
 * EmailColors class file
 */

declare( strict_types = 1 );

namespace Automattic\WooCommerce\Internal\Email;

use Automattic\WooCommerce\Utilities\FeaturesUtil;

/**
 * Helper class for email colors.
 *
 * @internal Just for internal use.
 */
class EmailColors {

	/**
	 * Get default colors for emails.
	 *
	 * @param bool|null $email_improvements_enabled Whether the email improvements feature is enabled.
	 * @return array Array of default email colors.
	 */
	public static function get_default_colors( ?bool $email_improvements_enabled = null ) {
		if ( null === $email_improvements_enabled ) {
			$email_improvements_enabled = FeaturesUtil::feature_is_enabled( 'email_improvements' );
		}

		$base        = '#720eec';
		$bg          = '#f7f7f7';
		$body_bg     = '#ffffff';
		$body_text   = '#3c3c3c';
		$footer_text = '#3c3c3c';

		if ( $email_improvements_enabled ) {
			$base        = '#8526ff';
			$bg          = '#ffffff';
			$body_bg     = '#ffffff';
			$body_text   = '#1e1e1e';
			$footer_text = '#787c82';

			$global_colors = static::get_colors_from_global_styles();

			if ( $global_colors ) {
				$base        = $global_colors['base'];
				$bg          = $global_colors['bg'];
				$body_bg     = $global_colors['body_bg'];
				$body_text   = $global_colors['body_text'];
				$footer_text = $global_colors['footer_text'];
			}
		}

		return compact(
			'base',
			'bg',
			'body_bg',
			'body_text',
			'footer_text',
		);
	}

	/**
	 * Get email colors from global styles.
	 *
	 * @return array|null Array of colors or null if global styles are not available or complete.
	 */
	public static function get_colors_from_global_styles() {
		$styles = static::get_global_styles_data();

		if ( ! $styles ) {
			return null;
		}

		$bg          = $styles['color']['background'] ?? null;
		$body_bg     = $styles['color']['background'] ?? null;
		$body_text   = $styles['color']['text'] ?? null;
		$base        = $styles['elements']['button']['color']['background'] ?? null;
		$footer_text = $styles['elements']['caption']['color']['text'] ?? null;

		$bg          = is_string( $bg ) ? sanitize_hex_color( $bg ) : '';
		$body_bg     = is_string( $body_bg ) ? sanitize_hex_color( $body_bg ) : '';
		$body_text   = is_string( $body_text ) ? sanitize_hex_color( $body_text ) : '';
		$base        = is_string( $base ) ? sanitize_hex_color( $base ) : $body_text;
		$footer_text = is_string( $footer_text ) ? sanitize_hex_color( $footer_text ) : $body_text;

		// Only return colors if all are set, otherwise email styles might not match and the email can become unreadable.
		if ( ! $bg || ! $body_bg || ! $body_text || ! $base || ! $footer_text ) {
			return null;
		}

		return compact(
			'base',
			'bg',
			'body_bg',
			'body_text',
			'footer_text',
		);
	}

	/**
	 * Method to retrieve global styles data.
	 *
	 * @return array|null
	 */
	protected static function get_global_styles_data() {
		if ( ! function_exists( 'wp_is_block_theme' ) || ! wp_is_block_theme() || ! function_exists( 'wp_get_global_styles' ) ) {
			return null;
		}
		return wp_get_global_styles( array(), array( 'transforms' => array( 'resolve-variables' ) ) );
	}
}
PK     £¦/]…5Z
  
    OrderPriceFormatter.phpnu ßú¥ÿ        <?php
/**
 * OrderPriceFormatter class file.
 */

declare( strict_types = 1 );

namespace Automattic\WooCommerce\Internal\Email;

use WC_Abstract_Order;
use WC_Order_Item;

/**
 * Helper class for formatting prices in order emails.
 *
 * @internal Just for internal use.
 */
class OrderPriceFormatter {

	/**
	 * Gets item subtotal - formatted for display in emails.
	 *
	 * @param WC_Abstract_Order $order Order instance.
	 * @param WC_Order_Item     $item Item to get unit price from.
	 * @param string            $tax_display 'incl' or 'excl' tax display mode.
	 * @return string Formatted item subtotal.
	 */
	public static function get_formatted_item_subtotal( WC_Abstract_Order $order, WC_Order_Item $item, string $tax_display ): string {
		$includes_tax  = 'excl' !== $tax_display;
		$item_subtotal = $order->get_item_subtotal( $item, $includes_tax );
		return self::format_price( $order, $item_subtotal, $includes_tax );
	}

	/**
	 * Helper method to format price with or without tax.
	 *
	 * @param WC_Abstract_Order $order Order instance.
	 * @param float             $amount The amount to format.
	 * @param bool              $includes_tax Whether to include tax in the formatted price.
	 * @return string Formatted price string.
	 */
	private static function format_price( WC_Abstract_Order $order, float $amount, bool $includes_tax ): string {
		return wc_price(
			$amount,
			array(
				'ex_tax_label' => ( ! $includes_tax && $order->get_prices_include_tax() ) ? 1 : 0,
				'currency'     => $order->get_currency(),
			)
		);
	}
}
PK       £¦/]˜æ{«€  €                  EmailFont.phpnu ßú¥ÿ        PK       £¦/]êÂïµ                ½  EmailStyleSync.phpnu ßú¥ÿ        PK       £¦/]…Õ87Y  Y              
  EmailColors.phpnu ßú¥ÿ        PK       £¦/]…5Z
  
              ¢   OrderPriceFormatter.phpnu ßú¥ÿ        PK      E  ó& 