Changeset 3309799
- Timestamp:
- 06/11/2025 12:32:13 PM (10 months ago)
- Location:
- mlsimport
- Files:
-
- 10 edited
- 1 copied
-
tags/6.0.7 (copied) (copied from mlsimport/trunk)
-
tags/6.0.7/README.MD (modified) (1 diff)
-
tags/6.0.7/admin/partials/mlsimport-admin-options.php (modified) (1 diff)
-
tags/6.0.7/includes/ThemeImport.php (modified) (3 diffs)
-
tags/6.0.7/mlsimport.php (modified) (2 diffs)
-
tags/6.0.7/readme.txt (modified) (1 diff)
-
trunk/README.MD (modified) (1 diff)
-
trunk/admin/partials/mlsimport-admin-options.php (modified) (1 diff)
-
trunk/includes/ThemeImport.php (modified) (3 diffs)
-
trunk/mlsimport.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
mlsimport/tags/6.0.7/README.MD
r3308382 r3309799 5 5 Tested up to: 6.7.1 6 6 Requires PHP: 7.4 7 Stable Tag: 6.0. 57 Stable Tag: 6.0.7 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html -
mlsimport/tags/6.0.7/admin/partials/mlsimport-admin-options.php
r3308300 r3309799 150 150 } 151 151 152 153 // Add before username fieldset 154 /* 155 global $mlsimport; 156 $current_token = $mlsimport->admin->mlsimport_saas_get_mls_api_token_from_transient(); 157 $token_expiry = get_option('mlsimport_token_expiry', 0); 158 159 160 $expiry_date = date('Y-m-d H:i:s', $token_expiry); 161 $is_expired = time() >= $token_expiry; 162 $status_color = $is_expired ? '#dc3545' : '#28a745'; 163 $status_text = $is_expired ? 'EXPIRED' : 'VALID'; 164 165 echo '<div style="background: #f9f9f9; padding: 15px; margin-bottom: 20px; border-radius: 5px;">'; 166 echo '<h4>Current Token Status</h4>'; 167 echo '<p><strong>Token:</strong> ' . esc_html(substr($current_token, 0, 20)) . '...</p>'; 168 echo '<p><strong>Status:</strong> <span style="color: ' . $status_color . '; font-weight: bold;">' . $status_text . '</span></p>'; 169 echo '<p><strong>Expires:</strong> ' . esc_html($expiry_date) . '</p>'; 170 echo '</div>'; 171 */ 152 172 153 173 -
mlsimport/tags/6.0.7/includes/ThemeImport.php
r3308300 r3309799 28 28 29 29 public function globalApiRequestCurlSaas($method, $valuesArray, $type = 'GET') { 30 31 30 32 global $mlsimport; 31 $url = MLSIMPORT_API_URL . $method; 33 34 // Skip validation for token requests 35 if ($method !== 'token') { 36 if (!self::validateAndRefreshToken()) { 37 return 'Token validation failed'; 38 } 39 } 40 41 $url = MLSIMPORT_API_URL . $method; 32 42 $headers = ['Content-Type' => 'text/plain']; 33 43 … … 92 102 public static function globalApiRequestSaas($method, $valuesArray, $type = 'GET') { 93 103 global $mlsimport; 104 // Skip validation for token and mls requests 105 if ($method !== 'token' && $method !== 'mls') { 106 if (!self::validateAndRefreshToken()) { 107 return [ 108 'success' => false, 109 'error_message' => 'Token validation failed' 110 ]; 111 } 112 } 113 114 94 115 $url = MLSIMPORT_API_URL . $method; 95 116 … … 138 159 139 160 140 161 162 /** 163 * Check if token is expired and refresh if needed 164 * Call this before any external API request 165 * 166 * @return bool True if token is valid, false if refresh failed 167 */ 168 private static function validateAndRefreshToken() { 169 global $mlsimport; 170 171 // Get stored expiry timestamp 172 $token_expiry = get_option('mlsimport_token_expiry', 0); 173 $current_time = time(); 174 175 // Check if token is expired 176 if ($current_time >= $token_expiry) { 177 // Token expired, refresh it 178 $refresh_result = self::refreshToken(); 179 180 if (!$refresh_result) { 181 error_log('MLSImport: Failed to refresh expired token'); 182 return false; 183 } 184 } 185 186 return true; 187 } 188 189 private static function refreshToken() { 190 global $mlsimport; 191 192 // Get credentials for token request 193 $options = get_option('mlsimport_admin_options'); 194 $username = isset($options['mlsimport_username']) ? $options['mlsimport_username'] : ''; 195 $password = isset($options['mlsimport_password']) ? $options['mlsimport_password'] : ''; 196 197 if (empty($username) || empty($password)) { 198 error_log('MLSImport: Missing credentials for token refresh'); 199 return false; 200 } 201 202 // Prepare token request 203 $url = MLSIMPORT_API_URL . 'token'; 204 $body = wp_json_encode(array( 205 'username' => $username, 206 'password' => $password 207 )); 208 209 $args = array( 210 'method' => 'POST', 211 'headers' => array( 212 'Content-Type' => 'application/json' 213 ), 214 'body' => $body, 215 'timeout' => 45 216 ); 217 218 // Make token request 219 $response = wp_remote_post($url, $args); 220 221 if (is_wp_error($response)) { 222 error_log('MLSImport: Token refresh request failed: ' . $response->get_error_message()); 223 return false; 224 } 225 226 $body = wp_remote_retrieve_body($response); 227 $data = json_decode($body, true); 228 229 if (!isset($data['success']) || !$data['success'] || !isset($data['token']) || !isset($data['expires'])) { 230 error_log('MLSImport: Invalid token refresh response'); 231 return false; 232 } 233 234 // Store new token and expiry 235 //$mlsimport->admin->mlsimport_saas_store_mls_api_token_transient($data['token']); 236 237 $expires_in = $data['expires'] - time(); 238 set_transient('mlsimport_saas_token', $data['token'], $expires_in); 239 240 update_option('mlsimport_token_expiry', intval($data['expires'])); 241 242 error_log('MLSImport: Token successfully refreshed. Expires: ' . date('Y-m-d H:i:s', $data['expires'])); 243 244 return true; 245 } 141 246 142 247 -
mlsimport/tags/6.0.7/mlsimport.php
r3308382 r3309799 4 4 * Plugin URI: https://mlsimport.com/ 5 5 * Description: "MLS Import - The MLSImport plugin facilitates the connection to your real estate MLS database, allowing you to download and synchronize real estate property data from the MLS. 6 * Version: 6.0. 57 * Stable tag: 6.0. 56 * Version: 6.0.7 7 * Stable tag: 6.0.7 8 8 * Requires at least: 5.2 9 9 * Requires PHP: 7.2 … … 22 22 23 23 24 define( 'MLSIMPORT_VERSION', '6.0. 5' );24 define( 'MLSIMPORT_VERSION', '6.0.7' ); 25 25 define( 'MLSIMPORT_CLUBLINK', 'mlsimport.com' ); 26 26 define( 'MLSIMPORT_CLUBLINKSSL', 'https' ); -
mlsimport/tags/6.0.7/readme.txt
r3308382 r3309799 5 5 Tested up to: 6.7.1 6 6 Requires PHP: 7.4 7 Stable Tag: 6.0. 57 Stable Tag: 6.0.7 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html -
mlsimport/trunk/README.MD
r3308382 r3309799 5 5 Tested up to: 6.7.1 6 6 Requires PHP: 7.4 7 Stable Tag: 6.0. 57 Stable Tag: 6.0.7 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html -
mlsimport/trunk/admin/partials/mlsimport-admin-options.php
r3308300 r3309799 150 150 } 151 151 152 153 // Add before username fieldset 154 /* 155 global $mlsimport; 156 $current_token = $mlsimport->admin->mlsimport_saas_get_mls_api_token_from_transient(); 157 $token_expiry = get_option('mlsimport_token_expiry', 0); 158 159 160 $expiry_date = date('Y-m-d H:i:s', $token_expiry); 161 $is_expired = time() >= $token_expiry; 162 $status_color = $is_expired ? '#dc3545' : '#28a745'; 163 $status_text = $is_expired ? 'EXPIRED' : 'VALID'; 164 165 echo '<div style="background: #f9f9f9; padding: 15px; margin-bottom: 20px; border-radius: 5px;">'; 166 echo '<h4>Current Token Status</h4>'; 167 echo '<p><strong>Token:</strong> ' . esc_html(substr($current_token, 0, 20)) . '...</p>'; 168 echo '<p><strong>Status:</strong> <span style="color: ' . $status_color . '; font-weight: bold;">' . $status_text . '</span></p>'; 169 echo '<p><strong>Expires:</strong> ' . esc_html($expiry_date) . '</p>'; 170 echo '</div>'; 171 */ 152 172 153 173 -
mlsimport/trunk/includes/ThemeImport.php
r3308300 r3309799 28 28 29 29 public function globalApiRequestCurlSaas($method, $valuesArray, $type = 'GET') { 30 31 30 32 global $mlsimport; 31 $url = MLSIMPORT_API_URL . $method; 33 34 // Skip validation for token requests 35 if ($method !== 'token') { 36 if (!self::validateAndRefreshToken()) { 37 return 'Token validation failed'; 38 } 39 } 40 41 $url = MLSIMPORT_API_URL . $method; 32 42 $headers = ['Content-Type' => 'text/plain']; 33 43 … … 92 102 public static function globalApiRequestSaas($method, $valuesArray, $type = 'GET') { 93 103 global $mlsimport; 104 // Skip validation for token and mls requests 105 if ($method !== 'token' && $method !== 'mls') { 106 if (!self::validateAndRefreshToken()) { 107 return [ 108 'success' => false, 109 'error_message' => 'Token validation failed' 110 ]; 111 } 112 } 113 114 94 115 $url = MLSIMPORT_API_URL . $method; 95 116 … … 138 159 139 160 140 161 162 /** 163 * Check if token is expired and refresh if needed 164 * Call this before any external API request 165 * 166 * @return bool True if token is valid, false if refresh failed 167 */ 168 private static function validateAndRefreshToken() { 169 global $mlsimport; 170 171 // Get stored expiry timestamp 172 $token_expiry = get_option('mlsimport_token_expiry', 0); 173 $current_time = time(); 174 175 // Check if token is expired 176 if ($current_time >= $token_expiry) { 177 // Token expired, refresh it 178 $refresh_result = self::refreshToken(); 179 180 if (!$refresh_result) { 181 error_log('MLSImport: Failed to refresh expired token'); 182 return false; 183 } 184 } 185 186 return true; 187 } 188 189 private static function refreshToken() { 190 global $mlsimport; 191 192 // Get credentials for token request 193 $options = get_option('mlsimport_admin_options'); 194 $username = isset($options['mlsimport_username']) ? $options['mlsimport_username'] : ''; 195 $password = isset($options['mlsimport_password']) ? $options['mlsimport_password'] : ''; 196 197 if (empty($username) || empty($password)) { 198 error_log('MLSImport: Missing credentials for token refresh'); 199 return false; 200 } 201 202 // Prepare token request 203 $url = MLSIMPORT_API_URL . 'token'; 204 $body = wp_json_encode(array( 205 'username' => $username, 206 'password' => $password 207 )); 208 209 $args = array( 210 'method' => 'POST', 211 'headers' => array( 212 'Content-Type' => 'application/json' 213 ), 214 'body' => $body, 215 'timeout' => 45 216 ); 217 218 // Make token request 219 $response = wp_remote_post($url, $args); 220 221 if (is_wp_error($response)) { 222 error_log('MLSImport: Token refresh request failed: ' . $response->get_error_message()); 223 return false; 224 } 225 226 $body = wp_remote_retrieve_body($response); 227 $data = json_decode($body, true); 228 229 if (!isset($data['success']) || !$data['success'] || !isset($data['token']) || !isset($data['expires'])) { 230 error_log('MLSImport: Invalid token refresh response'); 231 return false; 232 } 233 234 // Store new token and expiry 235 //$mlsimport->admin->mlsimport_saas_store_mls_api_token_transient($data['token']); 236 237 $expires_in = $data['expires'] - time(); 238 set_transient('mlsimport_saas_token', $data['token'], $expires_in); 239 240 update_option('mlsimport_token_expiry', intval($data['expires'])); 241 242 error_log('MLSImport: Token successfully refreshed. Expires: ' . date('Y-m-d H:i:s', $data['expires'])); 243 244 return true; 245 } 141 246 142 247 -
mlsimport/trunk/mlsimport.php
r3308382 r3309799 4 4 * Plugin URI: https://mlsimport.com/ 5 5 * Description: "MLS Import - The MLSImport plugin facilitates the connection to your real estate MLS database, allowing you to download and synchronize real estate property data from the MLS. 6 * Version: 6.0. 57 * Stable tag: 6.0. 56 * Version: 6.0.7 7 * Stable tag: 6.0.7 8 8 * Requires at least: 5.2 9 9 * Requires PHP: 7.2 … … 22 22 23 23 24 define( 'MLSIMPORT_VERSION', '6.0. 5' );24 define( 'MLSIMPORT_VERSION', '6.0.7' ); 25 25 define( 'MLSIMPORT_CLUBLINK', 'mlsimport.com' ); 26 26 define( 'MLSIMPORT_CLUBLINKSSL', 'https' ); -
mlsimport/trunk/readme.txt
r3308382 r3309799 5 5 Tested up to: 6.7.1 6 6 Requires PHP: 7.4 7 Stable Tag: 6.0. 57 Stable Tag: 6.0.7 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html
Note: See TracChangeset
for help on using the changeset viewer.