Changeset 3183932
- Timestamp:
- 11/07/2024 02:50:16 PM (17 months ago)
- Location:
- blizhost-cache-purge
- Files:
-
- 17 added
- 2 edited
-
tags/5.0.2 (added)
-
tags/5.0.2/blizhost-cache-purge.php (added)
-
tags/5.0.2/font (added)
-
tags/5.0.2/font/blizhost_logo.eot (added)
-
tags/5.0.2/font/blizhost_logo.svg (added)
-
tags/5.0.2/font/blizhost_logo.ttf (added)
-
tags/5.0.2/font/blizhost_logo.woff (added)
-
tags/5.0.2/font/index.php (added)
-
tags/5.0.2/font/style.css (added)
-
tags/5.0.2/js (added)
-
tags/5.0.2/js/bliz-purge.js (added)
-
tags/5.0.2/js/index.php (added)
-
tags/5.0.2/lang (added)
-
tags/5.0.2/lang/blizhost-cache-purge.pot (added)
-
tags/5.0.2/lang/index.php (added)
-
tags/5.0.2/readme.txt (added)
-
tags/5.0.2/wp-cli.php (added)
-
trunk/blizhost-cache-purge.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
blizhost-cache-purge/trunk/blizhost-cache-purge.php
r3180223 r3183932 4 4 Plugin URI: https://www.blizhost.com 5 5 Description: Automatic Cache Clearing and CloudCache Integration to Boost Speed and Protect Your Site with Enhanced Security. 6 Version: 5.0. 16 Version: 5.0.2 7 7 Author: Blizhost 8 8 Author URI: https://www.blizhost.com … … 24 24 protected $purgeUrls = array(); // URLs to be purged 25 25 protected $processedPosts = array(); // Posts that have been processed 26 public $p_version = '5.0. 1'; // Plugin version26 public $p_version = '5.0.2'; // Plugin version 27 27 public $do_full_purge = false; // Flag to trigger a full cache purge 28 28 … … 862 862 // Store the original URL 863 863 $original_url = $url; 864 864 865 865 // Handle protocol-relative URLs 866 866 if ( strpos( $url, '//' ) === 0 ) { 867 867 $url = ( $this->is_ssl ? 'https:' : 'http:' ) . $url; 868 868 } 869 870 // Use get_option('home') to get the base URL, including subdirectory but excluding language paths and other paths customized by plugins869 870 // Use get_option('home') to get the base URL, including subdirectory 871 871 $home_url_original = get_option( 'home' ); 872 872 … … 900 900 $dirname = dirname( $path ); 901 901 902 // Initialize width and height 903 $width = null; 904 $height = null; 905 906 // Check if filename has size suffix like -670x443 902 907 $pattern = '/^(.+)-(\d+)x(\d+)\.' . preg_quote( $extension, '/' ) . '$/i'; 903 908 if ( preg_match( $pattern, $filename, $matches ) ) { … … 907 912 $height = $matches[3]; 908 913 909 // Before reconstructing the original path, check if this filename is actually the original image 910 // Cache attachment IDs to avoid redundant queries 911 static $attachment_id_cache = array(); 912 if ( isset( $attachment_id_cache[ $url ] ) ) { 913 $attachment_id = $attachment_id_cache[ $url ]; 914 // Reconstruct the original filename 915 $original_filename = $base_filename . '.' . $extension; 916 $original_path = trailingslashit( $dirname ) . $original_filename; 917 918 // Build the full file paths 919 $upload_dir = wp_upload_dir(); 920 $upload_base_dir = $upload_dir['basedir']; // Absolute path to uploads directory 921 $upload_base_url = $upload_dir['baseurl']; // Base URL to uploads directory 922 923 // Remove the upload base URL from the original URL to get the relative path 924 $relative_original_path = str_replace( $upload_base_url, '', $home_url_original . $original_path ); 925 $original_file_full_path = trailingslashit( $upload_base_dir ) . ltrim( str_replace( '/', DIRECTORY_SEPARATOR, $relative_original_path ), DIRECTORY_SEPARATOR ); 926 927 // Check if original file exists without using file_exists unnecessarily 928 static $file_exists_cache = array(); 929 if ( isset( $file_exists_cache[ $original_file_full_path ] ) ) { 930 $original_file_exists = $file_exists_cache[ $original_file_full_path ]; 914 931 } else { 915 $attachment_id = attachment_url_to_postid( $url ); 916 $attachment_id_cache[ $url ] = $attachment_id; 917 } 918 919 if ( $attachment_id ) { 920 $metadata = wp_get_attachment_metadata( $attachment_id ); 921 if ( $metadata && isset( $metadata['file'] ) ) { 922 // Get the original filename from metadata 923 $original_file = basename( $metadata['file'] ); 924 if ( $original_file === $filename ) { 925 // The filename is the original image, do not modify 926 $original_path = $path; 927 $width = null; 928 $height = null; 929 } else { 930 // Reconstruct the path without size suffix 931 $original_path = trailingslashit( $dirname ) . $base_filename . '.' . $extension; 932 } 933 } else { 934 // Could not get metadata, proceed as before 935 $original_path = trailingslashit( $dirname ) . $base_filename . '.' . $extension; 936 } 932 $original_file_exists = file_exists( $original_file_full_path ); 933 $file_exists_cache[ $original_file_full_path ] = $original_file_exists; 934 } 935 936 if ( $original_file_exists ) { 937 // Original file exists, use it 938 $cdn_image_path = $original_path; 937 939 } else { 938 // Could not get attachment ID, proceed as before 939 $original_path = trailingslashit( $dirname ) . $base_filename . '.' . $extension; 940 // Original file does not exist, use the current path 941 $cdn_image_path = $path; 942 // Width and height are from filename 940 943 } 941 944 } else { 942 945 // No size suffix found; use the original path 943 $original_path = $path; 944 $width = null; 945 $height = null; 946 $cdn_image_path = $path; 947 948 // Attempt to get width and height from image metadata 949 // Build the full file path 950 $upload_dir = wp_upload_dir(); 951 $upload_base_dir = $upload_dir['basedir']; // Absolute path to uploads directory 952 $upload_base_url = $upload_dir['baseurl']; // Base URL to uploads directory 953 954 // Remove the upload base URL from the URL to get the relative path 955 $relative_path = str_replace( $upload_base_url, '', $url ); 956 $image_file_full_path = trailingslashit( $upload_base_dir ) . ltrim( str_replace( '/', DIRECTORY_SEPARATOR, $relative_path ), DIRECTORY_SEPARATOR ); 957 958 // Check if file exists and get dimensions 959 static $image_size_cache = array(); 960 if ( isset( $image_size_cache[ $image_file_full_path ] ) ) { 961 list( $width, $height ) = $image_size_cache[ $image_file_full_path ]; 962 } else { 963 if ( file_exists( $image_file_full_path ) ) { 964 $image_info = getimagesize( $image_file_full_path ); 965 if ( $image_info ) { 966 $width = $image_info[0]; 967 $height = $image_info[1]; 968 $image_size_cache[ $image_file_full_path ] = array( $width, $height ); 969 } 970 } 971 } 946 972 } 947 973 … … 951 977 if ( ! $cdn_domain ) { 952 978 // If CDN domain is not available, return original URL 953 return $ url;954 } 955 956 // Build the CDN URL including the original host and the originalpath957 $cdn_url = 'https://i' . $this->bliz_cdn_get_server_num( $url ) . '.' . $cdn_domain . '/' . $host . $ original_path;979 return $original_url; 980 } 981 982 // Build the CDN URL including the original host and the image path 983 $cdn_url = 'https://i' . $this->bliz_cdn_get_server_num( $url ) . '.' . $cdn_domain . '/' . $host . $cdn_image_path; 958 984 959 985 // Build the query parameters -
blizhost-cache-purge/trunk/readme.txt
r3180223 r3183932 5 5 Tested up to: 6.7 6 6 Requires PHP: 5.6 7 Stable tag: 5.0. 17 Stable tag: 5.0.2 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 102 102 103 103 == Changelog == 104 105 = 5.0.2 = 106 * Optimized CDN Image URL Replacement by removing database queries and utilizing filesystem checks. 107 * Enhanced Image Dimension Handling by extracting width and height from image files when size suffixes are absent. 108 * Implemented Caching Mechanism for file existence and image dimensions to improve performance. 109 * Maintained Compatibility with various scenarios and plugins, ensuring existing functionalities remain intact. 104 110 105 111 = 5.0.1 =
Note: See TracChangeset
for help on using the changeset viewer.