HEX
Server: LiteSpeed
System: Linux pulsar191.sitesanctuary.org 5.14.0-284.30.1.el9.tuxcare.els9.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jan 10 17:34:05 UTC 2025 x86_64
User: lgooir (1604)
PHP: 8.1.32
Disabled: exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/lgooir/.trash/rising-bamboo/inc/helper/class-license.php
<?php
/**
 * RisingBambooCore
 *
 * @package RisingBambooCore.
 */

namespace RisingBambooCore\Helper;

/**
 * Helper Class.
 */
class License {

	/**
	 * Check Theme is active
	 *
	 * @param string|null $theme Theme stylesheet.
	 * @return array|false
	 */
	public static function is_activated( string $theme = null ) {
		$license = get_option(self::get_license_option_name($theme));
		if ( $license ) {
			if ( empty($license['expired']) || ! self::is_expired($license['expired']) ) {
				return $license;
			}
		}
		return false;
	}

	/**
	 * Check expired.
	 *
	 * @param string $expired_date Expired Date.
	 * @return bool
	 */
	public static function is_expired( string $expired_date ): bool {
		$current = current_datetime();
		$expired = self::create_date_with_timezone($expired_date);
		return $current > $expired;
	}

	/**
	 * Format Date.
	 *
	 * @param string $date Date.
	 * @return \DateTimeImmutable|false
	 */
	public static function create_date_with_timezone( string $date ) {
		return \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s+', $date)->setTimezone(wp_timezone());
	}

	/**
	 * Get API config
	 */
	public static function get_api_config(): array {
		$api_config            = [];
		$current_theme         = wp_get_theme();
		$api_theme_config_path = realpath(untrailingslashit($current_theme->get_template_directory()) . '/inc/config/api.php');
		if ( $api_theme_config_path ) {
			$api_theme_config = require $api_theme_config_path;
			$api_config       = wp_parse_args($api_theme_config, $api_config);
		}
		if ( Setting::get_option('development_mode') ) {
			$api_mock_path = realpath(untrailingslashit($current_theme->get_template_directory()) . '/mock/api.php');
			if ( $api_mock_path ) {
				$api_mock   = require $api_mock_path;
				$api_config = wp_parse_args($api_mock, $api_config);
			}
		}
		return $api_config;
	}

	/**
	 * Get license option name.
	 *
	 * @param null $theme Directory name for the theme. Defaults to active theme.
	 * @return string
	 */
	public static function get_license_option_name( $theme = null ): string {
		if ( ! $theme ) {
			$theme = wp_get_theme()->stylesheet;
		}
		return strtolower('rbb-' . $theme . '-license');
	}
}