Changeset 3425814
- Timestamp:
- 12/23/2025 06:14:50 AM (3 months ago)
- Location:
- download-manager/trunk
- Files:
-
- 3 edited
-
download-manager.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
src/__/Session.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
download-manager/trunk/download-manager.php
r3425719 r3425814 6 6 Author: W3 Eden, Inc. 7 7 Author URI: https://www.wpdownloadmanager.com/ 8 Version: 3.3.3 88 Version: 3.3.39 9 9 Text Domain: download-manager 10 10 Domain Path: /languages … … 41 41 global $WPDM; 42 42 43 define('WPDM_VERSION','3.3.3 7');43 define('WPDM_VERSION','3.3.39'); 44 44 45 45 define('WPDM_TEXT_DOMAIN','download-manager'); -
download-manager/trunk/readme.txt
r3425719 r3425814 6 6 Tested up to: 6.9 7 7 License: GPLv3 8 Stable tag: 3.3.3 88 Stable tag: 3.3.39 9 9 10 10 … … 204 204 == Changelog == 205 205 206 = 3.3.39 - 2025.12.23 = 207 * Fixed a fatal error with Session class during early WordPress initialization 208 * Added fallbacks for WordPress functions not available during plugin loading 209 * Improved compatibility with various server configurations 210 206 211 = 3.3.38 - 2025.12.23 = 207 212 * Added Color Scheme option (System/Light/Dark) in UI settings -
download-manager/trunk/src/__/Session.php
r3425719 r3425814 25 25 self::$initialized = true; 26 26 27 self::$store = get_option('__wpdm_tmp_storage', 'db'); 27 // get_option should be available, but fallback to 'db' if not 28 self::$store = \function_exists('get_option') ? \get_option('__wpdm_tmp_storage', 'db') : 'db'; 28 29 self::initDeviceID(); 29 30 30 31 if (self::$store === 'file') { 31 32 self::loadFileSession(); 32 register_shutdown_function([__CLASS__, 'saveSession']);33 \register_shutdown_function([__CLASS__, 'saveSession']); 33 34 } 34 35 } … … 57 58 58 59 // Generate new ID (random is more reliable than IP+UA) 59 $deviceID = wp_generate_password(32, false); 60 // Use wp_generate_password if available, otherwise fallback to PHP random 61 if (\function_exists('wp_generate_password')) { 62 $deviceID = \wp_generate_password(32, false); 63 } else { 64 // Fallback for early initialization before WordPress is fully loaded 65 $deviceID = \bin2hex(\random_bytes(16)); 66 } 60 67 self::$deviceID = $deviceID; 61 68 self::setDeviceCookie($deviceID); … … 69 76 private static function setDeviceCookie($deviceID) 70 77 { 71 if (defined('WPDM_ACCEPT_COOKIE') && WPDM_ACCEPT_COOKIE === false) return; 72 if (!apply_filters('wpdm_user_accept_cookies', true)) return; 73 74 $domain = wp_parse_url(home_url(), PHP_URL_HOST); 75 @setcookie('__wpdm_client', $deviceID, 0, "/", $domain, is_ssl(), true); 78 if (\defined('WPDM_ACCEPT_COOKIE') && WPDM_ACCEPT_COOKIE === false) return; 79 80 // Check if apply_filters is available (WordPress fully loaded) 81 if (\function_exists('apply_filters') && !\apply_filters('wpdm_user_accept_cookies', true)) return; 82 83 // Get domain - with fallback for early initialization 84 if (\function_exists('home_url')) { 85 $domain = \wp_parse_url(\home_url(), PHP_URL_HOST); 86 } else { 87 // Fallback: parse from server variables 88 $domain = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; 89 $domain = \preg_replace('/:\d+$/', '', $domain); // Remove port if present 90 } 91 92 $secure = \function_exists('is_ssl') ? \is_ssl() : (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'); 93 @\setcookie('__wpdm_client', $deviceID, 0, "/", $domain, $secure, true); 76 94 $_COOKIE['__wpdm_client'] = $deviceID; 77 95 } … … 106 124 if (!self::$initialized) self::init(); 107 125 108 $expireTime = time() + $expire;126 $expireTime = \time() + $expire; 109 127 110 128 // Always cache in memory … … 121 139 $wpdb->query($wpdb->prepare( 122 140 "REPLACE INTO {$wpdb->prefix}ahm_sessions (deviceID, name, value, expire) VALUES (%s, %s, %s, %d)", 123 self::$deviceID, $name, maybe_serialize($value), $expireTime141 self::$deviceID, $name, \maybe_serialize($value), $expireTime 124 142 )); 125 143 } else { … … 141 159 if (isset(self::$data[$name])) { 142 160 $cached = self::$data[$name]; 143 if ($cached['expire'] > time()) {161 if ($cached['expire'] > \time()) { 144 162 return $cached['value']; 145 163 } … … 158 176 "SELECT value FROM {$wpdb->prefix}ahm_sessions 159 177 WHERE deviceID = %s AND name = %s AND expire > %d", 160 self::$deviceID, $name, time()178 self::$deviceID, $name, \time() 161 179 )); 162 180 163 181 if ($value !== null) { 164 $unserialized = maybe_unserialize($value);182 $unserialized = \maybe_unserialize($value); 165 183 // Cache for subsequent calls in same request 166 self::$data[$name] = ['value' => $unserialized, 'expire' => time() + 300];184 self::$data[$name] = ['value' => $unserialized, 'expire' => \time() + 300]; 167 185 return $unserialized; 168 186 } … … 203 221 $wpdb->query($wpdb->prepare( 204 222 "DELETE FROM {$wpdb->prefix}ahm_sessions WHERE expire < %d AND deviceID != 'alldevice'", 205 time()223 \time() 206 224 )); 207 225 } … … 230 248 { 231 249 $file = WPDM_CACHE_DIR . "/session-" . self::$deviceID . ".txt"; 232 $realpath = realpath($file);233 if ($realpath && file_exists($realpath) &&substr_count($realpath, WPDM_CACHE_DIR)) {234 $data = file_get_contents($realpath);250 $realpath = \realpath($file); 251 if ($realpath && \file_exists($realpath) && \substr_count($realpath, WPDM_CACHE_DIR)) { 252 $data = \file_get_contents($realpath); 235 253 $data = Crypt::decrypt($data, true); 236 self::$data = is_array($data) ? $data : [];254 self::$data = \is_array($data) ? $data : []; 237 255 } 238 256 } … … 246 264 247 265 // Filter out expired entries before saving 248 $now = time();249 self::$data = array_filter(self::$data, function($v) use ($now) {266 $now = \time(); 267 self::$data = \array_filter(self::$data, function($v) use ($now) { 250 268 return $v['expire'] > $now; 251 269 }); … … 253 271 if (empty(self::$data)) return; 254 272 255 if (! file_exists(WPDM_CACHE_DIR)) {256 @ mkdir(WPDM_CACHE_DIR, 0755, true);273 if (!\file_exists(WPDM_CACHE_DIR)) { 274 @\mkdir(WPDM_CACHE_DIR, 0755, true); 257 275 } 258 276 259 277 $data = Crypt::encrypt(self::$data); 260 file_put_contents(WPDM_CACHE_DIR . 'session-' . self::$deviceID . '.txt', $data);278 \file_put_contents(WPDM_CACHE_DIR . 'session-' . self::$deviceID . '.txt', $data); 261 279 } 262 280 }
Note: See TracChangeset
for help on using the changeset viewer.