| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- /**
- * Helper functions for the plugin.
- *
- * @package QDR_Temporary_Shared_Storage
- * @since 1.0.0
- */
- if (!defined('WPINC')) {
- die;
- }
- /**
- * Format bytes to human readable format.
- *
- * @since 1.0.0
- * @param int $bytes The size in bytes.
- * @param int $precision The number of decimal places.
- * @return string Human readable size.
- */
- function qdr_tss_format_bytes($bytes, $precision = 2) {
- $units = array('B', 'KB', 'MB', 'GB', 'TB');
-
- $bytes = max($bytes, 0);
- $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
- $pow = min($pow, count($units) - 1);
-
- $bytes /= pow(1024, $pow);
-
- return round($bytes, $precision) . ' ' . $units[$pow];
- }
- /**
- * Format date to localized format.
- *
- * @since 1.0.0
- * @param string $date_string Date string in MySQL format.
- * @return string Formatted date.
- */
- function qdr_tss_format_date($date_string) {
- if (!$date_string || $date_string === '0000-00-00 00:00:00') {
- return '-';
- }
-
- $date = strtotime($date_string);
- return date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $date);
- }
- /**
- * Check if a date is expired.
- *
- * @since 1.0.0
- * @param string $date_string Date string in MySQL format.
- * @return bool True if date is expired, false otherwise.
- */
- function qdr_tss_is_expired($date_string) {
- if (!$date_string || $date_string === '0000-00-00 00:00:00') {
- return false;
- }
-
- $expiry_date = strtotime($date_string);
- $current_time = current_time('timestamp');
-
- return $current_time > $expiry_date;
- }
- /**
- * Check if a date is in the future.
- *
- * @since 1.0.0
- * @param string $date_string Date string in MySQL format.
- * @return bool True if date is in the future, false otherwise.
- */
- function qdr_tss_is_future($date_string) {
- if (!$date_string || $date_string === '0000-00-00 00:00:00') {
- return false;
- }
-
- $future_date = strtotime($date_string);
- $current_time = current_time('timestamp');
-
- return $current_time < $future_date;
- }
- /**
- * Get file status class based on active dates.
- *
- * @since 1.0.0
- * @param string $active_from Active from date in MySQL format.
- * @param string $active_to Active to date in MySQL format.
- * @return string CSS class for status.
- */
- function qdr_tss_get_status_class($active_from, $active_to) {
- $current_time = current_time('timestamp');
- $from_time = strtotime($active_from);
- $to_time = strtotime($active_to);
-
- if ($current_time < $from_time) {
- return 'qdr-tss-status-pending';
- } elseif ($current_time > $to_time) {
- return 'qdr-tss-status-expired';
- } else {
- return 'qdr-tss-status-active';
- }
- }
- /**
- * Get file status label based on active dates.
- *
- * @since 1.0.0
- * @param string $active_from Active from date in MySQL format.
- * @param string $active_to Active to date in MySQL format.
- * @return string Status label.
- */
- function qdr_tss_get_status_label($active_from, $active_to) {
- $current_time = current_time('timestamp');
- $from_time = strtotime($active_from);
- $to_time = strtotime($active_to);
-
- if ($current_time < $from_time) {
- return __('Pending', 'qdr-temporary-shared-storage');
- } elseif ($current_time > $to_time) {
- return __('Expired', 'qdr-temporary-shared-storage');
- } else {
- return __('Active', 'qdr-temporary-shared-storage');
- }
- }
|