remove unneccessary dependencies

This commit is contained in:
David Stone
2025-02-07 11:36:39 -07:00
parent 10c292b0df
commit b40a4aaeab
18 changed files with 630 additions and 79 deletions

View File

@ -488,15 +488,11 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$month_list = array();
$start = date_i18n('Y-m-d 00:00:00', strtotime('first day of january this year'));
$current_year = date_i18n('Y');
for ($i = 0; $i < 12; $i++) {
$start_date = wu_date($start);
$month_list[] = date_i18n('M y', $start_date->addMonths($i)->format('U'));
} // end for;
for ($i = 1; $i <= 12; $i++) {
$month_list[] = date_i18n('M y', mktime(0, 0,0,$i,1, $current_year));
}
$statistics = new Dashboard_Statistics(array(
'start_date' => $this->start_date,

View File

@ -128,7 +128,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page {
),
);
$date = wu_date($swap_order->scheduled_date);
$date = new \DateTime($swap_order->scheduled_date);
// translators: %s is the date, using the site format options
$message = sprintf(__('There is a change scheduled to take place on this membership in <strong>%s</strong>. You can preview the changes here. Scheduled changes are usually created by downgrades.', 'wp-ultimo'), $date->format(get_option('date_format')));
@ -1078,7 +1078,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page {
),
);
$date = wu_date($swap_order->scheduled_date);
$date = new \DateTime($swap_order->scheduled_date);
// translators: %s is the date, using the site format options
$message = sprintf(__('This is a <strong>preview</strong>. This page displays the final stage of the membership after the changes scheduled for <strong>%s</strong>. Saving here will persist these changes, so be careful.', 'wp-ultimo'), $date->format(get_option('date_format')));

View File

@ -1255,7 +1255,7 @@ class WU_Transactions {
_deprecated_function(__CLASS__, '2.0.0', 'wu_date()');
$date = wu_date();
$date = new \DateTime();
return $type === 'mysql' ? $date->format('Y-m-d H:i:s') : $date->format('U');

View File

@ -9,11 +9,10 @@
namespace WP_Ultimo\Domain_Mapping;
use Spatie\SslCertificate\SslCertificate;
use Psr\Log\LogLevel;
// Exit if accessed directly
defined('ABSPATH') || exit;
defined( 'ABSPATH' ) || exit;
/**
* Helper class for domain mapping functionality.
@ -49,7 +48,7 @@ class Helper {
$site_url = site_url();
$is_development_mode = preg_match('#(localhost|staging.*\.|\.local|\.test)#', $site_url);
$is_development_mode = preg_match( '#(localhost|staging.*\.|\.local|\.test)#', $site_url );
/**
* Allow plugin developers to add additional tests
@ -61,21 +60,19 @@ class Helper {
* @param string $site_url The site URL.
* @return bool
*/
return apply_filters('wu_is_development_mode', $is_development_mode, $site_url);
return apply_filters( 'wu_is_development_mode', $is_development_mode, $site_url );
} // end is_development_mode;
/**
* Gets the local IP address of the network.
*
* Sometimes, this will be the same address as the public one, but we need different methods.
*
* @since 2.0.0
* @return string|bool
*/
public static function get_local_network_ip() {
return isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : false;
/**
* Gets the local IP address of the network.
*
* Sometimes, this will be the same address as the public one, but we need different methods.
*
* @since 2.0.0
* @return string|bool
*/
public static function get_local_network_ip() {
return isset( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : false;
} // end get_local_network_ip;
/**
@ -90,43 +87,38 @@ class Helper {
*/
public static function get_network_public_ip() {
if (self::is_development_mode()) {
if ( self::is_development_mode() ) {
$local_ip = self::get_local_network_ip();
/**
* See more about this filter below, on this same method.
*/
return apply_filters('wu_get_network_public_ip', $local_ip, true);
return apply_filters( 'wu_get_network_public_ip', $local_ip, true );
} // end if;
$_ip_address = get_site_transient('wu_public_network_ip');
if (!$_ip_address) {
$_ip_address = get_site_transient( 'wu_public_network_ip' );
if ( ! $_ip_address ) {
$ip_address = false;
foreach (self::$providers as $provider_url) {
foreach ( self::$providers as $provider_url ) {
$response = wp_remote_get(
$provider_url,
array(
'timeout' => 5,
)
);
$response = wp_remote_get($provider_url, array(
'timeout' => 5,
));
if (!is_wp_error($response)) {
$ip_address = trim(wp_remote_retrieve_body($response));
if ( ! is_wp_error( $response ) ) {
$ip_address = trim( wp_remote_retrieve_body( $response ) );
continue;
} // end if;
} // end foreach;
set_site_transient('wu_public_network_ip', $ip_address, 10 * DAY_IN_SECONDS);
set_site_transient( 'wu_public_network_ip', $ip_address, 10 * DAY_IN_SECONDS );
$_ip_address = $ip_address;
} // end if;
/**
@ -143,10 +135,8 @@ class Helper {
* @param bool $local True if this is a local network (localhost, .dev, etc.), false otherwise.
* @return string The new IP address.
*/
return apply_filters('wu_get_network_public_ip', $_ip_address, false);
return apply_filters( 'wu_get_network_public_ip', $_ip_address, false );
} // end get_network_public_ip;
/**
* Checks if a given domain name has a valid associated SSL certificate.
*
@ -156,24 +146,93 @@ class Helper {
* @return boolean
*/
public static function has_valid_ssl_certificate($domain = '') {
$is_valid = false;
// Ensure the domain is not empty.
if (empty($domain)) {
return $is_valid;
}
// Add 'https://' if not already present to use SSL context properly.
$domain = strpos($domain, 'https://') === 0 ? $domain : 'https://' . $domain;
try {
// Create SSL context to fetch the certificate.
$context = stream_context_create(
array(
'ssl' => array(
'capture_peer_cert' => true,
),
)
);
$certificate = SslCertificate::createForHostName($domain);
// Open a stream to the domain over SSL.
$stream = @stream_socket_client(
'ssl://' . parse_url($domain, PHP_URL_HOST) . ':443',
$errno,
$errstr,
10,
STREAM_CLIENT_CONNECT,
$context
);
$is_valid = $certificate->isValid($domain); // returns bool;
// If stream could not be established, SSL is invalid.
if (!$stream) {
throw new \Exception($errstr);
}
// Retrieve the certificate and parse its details.
$options = stream_context_get_options($context);
if (isset($options['ssl']['peer_certificate'])) {
$cert = openssl_x509_parse($options['ssl']['peer_certificate']);
if ($cert) {
// Verify the certificate's validity period.
$current_time = time();
$valid_from = $cert['validFrom_time_t'] ?? 0;
$valid_to = $cert['validTo_time_t'] ?? 0;
// Check if the certificate is currently valid.
if ($current_time >= $valid_from && $current_time <= $valid_to) {
$host = parse_url($domain, PHP_URL_HOST);
// Check that the domain matches the certificate.
$common_name = $cert['subject']['CN'] ?? ''; // Common Name (CN)
$alt_names = $cert['extensions']['subjectAltName'] ?? ''; // Subject Alternative Names (SAN)
// Parse SAN into an array if present.
$alt_names_array = array_filter(array_map('trim', explode(',', str_replace('DNS:', '', $alt_names))));
$alt_names_array[] = $common_name;
// Check if the host matches either the CN, any SAN entry, or supports a wildcard match.
if (
$host === $common_name ||
in_array( $host, $alt_names_array, true )
) {
$is_valid = true;
} else {
foreach ($alt_names_array as $alt_name) {
if ( strpos($alt_name, '*.') === 0 && str_ends_with( $host, substr($alt_name, 1) )) {
$is_valid = true;
break;
}
}
}
}
}
}
// Close the stream after processing.
fclose($stream);
} catch (\Exception $e) {
// translators: %s is the error message returned by the checker.
wu_log_add('domain-ssl-checks', sprintf(__('Certificate Invalid: %s', 'wp-ultimo'), $e->getMessage()), LogLevel::ERROR);
} // end try;
// Log the error message.
wu_log_add(
'domain-ssl-checks',
sprintf(__('Certificate Invalid: %s', 'wp-ultimo'), $e->getMessage()),
LogLevel::ERROR
);
}
return $is_valid;
} // end has_valid_ssl_certificate;
} // end class Helper;

View File

@ -55,17 +55,15 @@ function wu_validate_date($date, $format = 'Y-m-d H:i:s') {
* @see https://carbon.nesbot.com/docs/
*
* @param string|false $date Parsable date string.
* @return \Carbon\Carbon
* @return \DateTime
*/
function wu_date($date = false) {
if (!wu_validate_date($date)) {
$date = date_i18n('Y-m-d H:i:s');
}
} // end if;
return \Carbon\Carbon::parse($date);
return \DateTime::createFromFormat('Y-m-d H:i:s', $date);
} // end wu_date;
@ -86,7 +84,9 @@ function wu_get_days_ago($date_1, $date_2 = false) {
$datetime_2 = wu_date($date_2);
return - $datetime_1->diffInDays($datetime_2, false);
$dateIntervar = $datetime_1->diff($datetime_2, false);
return - $dateIntervar->days;
} // end wu_get_days_ago;

View File

@ -40,7 +40,7 @@ class Core_Installer extends Base_Installer {
if (!(defined('SUNRISE') && SUNRISE)) {
// translators: %s is a URL to a documentation link.
$closte_message = sprintf(__('You are using Closte and they prevent the wp-config.php file from being written to. <a href="%s" target="_blank">Follow these instructions to do it manually</a>.'), wu_get_documentation_url('wp-ultimo-closte-config'));
$closte_message = sprintf(__('You are using Closte and they prevent the wp-config.php file from being written to. <a href="%s" target="_blank">Follow these instructions to do it manually</a>.', 'wp-ultimo' ), wu_get_documentation_url('wp-ultimo-closte-config'));
throw new \Exception($closte_message);

View File

@ -1851,7 +1851,7 @@ class Migrator extends Base_Installer {
*/
$subscription_creation_date = wu_date($subscription->created_at);
$trial_end_date = $subscription_creation_date->addDays($subscription->trial)->endOfDay();
$trial_end_date = $subscription_creation_date->add( new \DateInterval( 'P' . $subscription->trial . 'D' ) )->setTime( 23, 59, 59 );
$date_trial_end = $trial_end_date->format('Y-m-d 23:59:59');

View File

@ -321,9 +321,9 @@ class Site_Manager extends Base_Manager {
// If membership is cancelled we do not add the grace period
$grace_period = $status !== Membership_Status::CANCELLED ? (int) wu_get_setting('block_frontend_grace_period', 0) : 0;
$expiration_time = wu_date($membership->get_date_expiration())->timestamp + $grace_period * DAY_IN_SECONDS;
$expiration_time = wu_date($membership->get_date_expiration())->getTimestamp() + $grace_period * DAY_IN_SECONDS;
if ($expiration_time < wu_date()->timestamp) {
if ($expiration_time < wu_date()->getTimestamp()) {
$checkout_pages = \WP_Ultimo\Checkout\Checkout_Pages::get_instance();

View File

@ -519,6 +519,8 @@ class Discount_Code extends Base_Model {
return new \WP_Error('discount_code', __('This coupon code is not valid.', 'wp-ultimo'));
return new \WP_Error( 'discount_code', __( 'The coupon code is not valid yet.', 'wp-ultimo' ) );
} // end if;
} // end if;
@ -527,7 +529,7 @@ class Discount_Code extends Base_Model {
$expiration_date_instance = wu_date($expiration_date);
if ($now > $expiration_date) {
if ($now > $expiration_date_instance) {
return new \WP_Error('discount_code', __('This coupon code is not valid.', 'wp-ultimo'));

View File

@ -2477,7 +2477,7 @@ class Membership extends Base_Model {
} // end if;
return floor($today->diffInDays($expiration_date));
return floor($today->diff($expiration_date)->days);
} // end get_remaining_days_in_cycle;

View File

@ -198,15 +198,11 @@ class Dashboard_Taxes_Tab {
$month_list = array();
$start = date_i18n('Y-m-d 00:00:00', strtotime('first day of january this year'));
$current_year = date_i18n('Y');
for ($i = 0; $i < 12; $i++) {
$start_date = wu_date($start);
$month_list[] = date_i18n('M y', $start_date->addMonths($i)->format('U'));
} // end for;
for ($i = 1; $i <= 12; $i++) {
$month_list[] = date_i18n('M y', mktime(0, 0,0,$i,1, $current_year));
}
wp_register_script('wu-tax-stats', wu_get_asset('tax-statistics.js', 'js'), array('jquery', 'wu-functions', 'wu-ajax-list-table', 'moment', 'wu-block-ui', 'dashboard', 'wu-apex-charts', 'wu-vue-apex-charts'), wu_get_version(), true);