Changeset 3266664
- Timestamp:
- 04/04/2025 02:50:12 AM (12 months ago)
- Location:
- flash-cache
- Files:
-
- 35 added
- 7 edited
-
tags/3.5 (added)
-
tags/3.5/README.md (added)
-
tags/3.5/assets (added)
-
tags/3.5/assets/css (added)
-
tags/3.5/assets/css/icons.css (added)
-
tags/3.5/assets/css/style.css (added)
-
tags/3.5/assets/img (added)
-
tags/3.5/assets/img/flash-cache-icon.png (added)
-
tags/3.5/assets/js (added)
-
tags/3.5/assets/js/settings.js (added)
-
tags/3.5/can_create_cache.txt (added)
-
tags/3.5/can_cron.txt (added)
-
tags/3.5/flash_cache.php (added)
-
tags/3.5/includes (added)
-
tags/3.5/includes/cache.tpl (added)
-
tags/3.5/includes/enviroment.php (added)
-
tags/3.5/includes/functions.php (added)
-
tags/3.5/includes/lib (added)
-
tags/3.5/includes/lib/jsmin.php (added)
-
tags/3.5/includes/notices.php (added)
-
tags/3.5/includes/optimize_fonts.php (added)
-
tags/3.5/includes/optimize_scripts.php (added)
-
tags/3.5/includes/optimize_styles.php (added)
-
tags/3.5/includes/patterns.php (added)
-
tags/3.5/includes/plugin_functions.php (added)
-
tags/3.5/includes/posts.php (added)
-
tags/3.5/includes/preload.php (added)
-
tags/3.5/includes/process.php (added)
-
tags/3.5/includes/settings.php (added)
-
tags/3.5/includes/version.php (added)
-
tags/3.5/languages (added)
-
tags/3.5/languages/flash-cache.pot (added)
-
tags/3.5/readme.txt (added)
-
tags/3.5/screenshot-1.jpg (added)
-
tags/3.5/screenshot-2.jpg (added)
-
trunk/flash_cache.php (modified) (6 diffs)
-
trunk/includes/cache.tpl (modified) (1 diff)
-
trunk/includes/functions.php (modified) (1 diff)
-
trunk/includes/patterns.php (modified) (5 diffs)
-
trunk/includes/process.php (modified) (38 diffs)
-
trunk/includes/settings.php (modified) (16 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
flash-cache/trunk/flash_cache.php
r3125571 r3266664 4 4 * Plugin URI: https://flashcache.net 5 5 * Description: Flash Cache is a plugin to really improve performance of Wordpress Websites. If you like it, please rate it 5 stars to allow us to improve its development. 6 * Version: 3. 46 * Version: 3.5 7 7 * Author: Etruel Developments LLC 8 8 * Author URI: https://etruel.com/ … … 21 21 // Plugin version 22 22 if (!defined('FLASH_CACHE_VERSION')) { 23 define('FLASH_CACHE_VERSION', '3. 4');23 define('FLASH_CACHE_VERSION', '3.5'); 24 24 } 25 25 … … 48 48 self::$instance = new self(); 49 49 self::$instance->constants(); 50 self::$instance->load_text_domain();51 50 self::$instance->hooks(); 52 51 self::$instance->includes(); … … 111 110 register_uninstall_hook(__FILE__, array(__CLASS__, 'uninstall')); 112 111 add_action('permalink_structure_changed', 'flash_cache_changes_permalinks', 10, 2); 112 add_action('init', [self::$instance, 'load_textdomain'] ); 113 113 114 } 114 115 115 116 /** 116 * Static function load_text _domain117 * Static function load_textdomain 117 118 * Load the text domain. 118 119 * @access public … … 120 121 * @since 1.0.0 121 122 */ 122 public static function load_text _domain() {123 public static function load_textdomain() { 123 124 // Set filter for plugin's languages directory 124 125 $lang_dir = dirname(plugin_basename(__FILE__)) . '/languages/'; 125 126 $lang_dir = apply_filters('flash_cache_languages_directory', $lang_dir); 126 127 // Traditional WordPress plugin locale filter 128 $locale = apply_filters('plugin_locale', get_locale(), 'flash-cache'); 129 $mofile = sprintf('%1$s-%2$s.mo', 'flash-cache', $locale); 130 131 // Setup paths to current locale file 132 $mofile_local = $lang_dir . $mofile; 133 $mofile_global = WP_LANG_DIR . '/flash-cache/' . $mofile; 134 135 if (file_exists($mofile_global)) { 136 // Look in global /wp-content/languages/flash_cache/ folder 137 load_textdomain('flash-cache', $mofile_global); 138 } elseif (file_exists($mofile_local)) { 139 // Look in local /wp-content/plugins/flash_cache/languages/ folder 140 load_textdomain('flash-cache', $mofile_local); 141 } else { 142 // Load the default language files 143 load_plugin_textdomain('flash-cache', false, $lang_dir); 144 } 127 load_plugin_textdomain('flash-cache', false, $lang_dir); 145 128 } 146 129 … … 214 197 215 198 add_action('plugins_loaded', 'Flash_Cache_load'); 216 ?> -
flash-cache/trunk/includes/cache.tpl
r2872713 r3266664 27 27 include $home_path.'index.php'; 28 28 } 29 30 ?> -
flash-cache/trunk/includes/functions.php
r3125571 r3266664 834 834 return isset($updated) ? $updated : false; 835 835 } 836 ?> -
flash-cache/trunk/includes/patterns.php
r3007708 r3266664 13 13 14 14 class flash_cache_patterns { 15 15 16 16 17 /** … … 287 288 288 289 </table>'; 289 echo '<table class="form-table"> 290 290 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), flash_cache_settings::default_advanced_options()); 291 $values['cache_type'] = ($advanced_settings['disable_widget_cache'] == 1) ? 'php' : $values['cache_type']; 292 echo '<table class="form-table"> 291 293 <tr valign="top"> 292 294 <th scope="row">' . __('Cache Type', 'flash-cache') . '</th> 293 295 <td> 294 296 <div class="radio-group"> 295 <input type="radio" ' . checked($values['cache_type'], 'html', false) . ' name="cache_type" value="html"/>' . __('HTML static (Ultra fast)', 'flash-cache') . ' 297 <input type="radio" ' . 298 checked($values['cache_type'], 'html', false) . 299 ($advanced_settings['disable_widget_cache'] == 1 ? ' disabled' : '') . 300 ' name="cache_type" value="html"/>' . 301 __('HTML static (Ultra fast)', 'flash-cache') . ' 296 302 <p class="description">' . __('Create a cache in HTML format, in this way avoid the PHP execution in the front-end accelerating the load of the page, plus reducing the server CPU cost.', 'flash-cache') . '</p> 297 303 </div> 298 304 299 305 <div class="radio-group"> 300 <input type="radio" ' . checked($values['cache_type'], 'php', false) . ' name="cache_type" value="php"/>' . __('PHP Files (Accept GET and POST params)', 'flash-cache') . ' 306 <input type="radio" ' . 307 checked($values['cache_type'], 'php', false) . 308 ' name="cache_type" value="php"/>' . 309 __('PHP Files (Accept GET and POST params)', 'flash-cache') . ' 301 310 <p class="description">' . __('Create cache from pages which has parameters GET or POST like Feed or WordPress search; this option is less optimal than HTML static.', 'flash-cache') . '</p> 302 311 </div> … … 304 313 </tr> 305 314 </table>'; 315 306 316 echo '<table class="form-table"> 307 317 … … 323 333 </table></div>'; 324 334 } 335 325 336 326 337 /** … … 545 556 546 557 flash_cache_patterns::hooks(); 547 ?> -
flash-cache/trunk/includes/process.php
r3125571 r3266664 1 1 <?php 2 2 3 /** 3 4 * @package etruel\Flash Cache … … 13 14 class flash_cache_process { 14 15 15 public static $origin_url = null;16 public static $template_redirect = false;17 public static $optional_post_id = 0;18 public static $current_query = array();19 public static $url_to_cache = '';20 public static $pattern = null;21 public static $cache_type = 'html';22 public static $first_ob_output = true;23 public static $current_buffer = '';24 public static $force_process_type = null;25 public static $force_permalink = false;26 public static $advanced_settings = null;27 public static $can_cache_handler = null;16 public static $origin_url = null; 17 public static $template_redirect = false; 18 public static $optional_post_id = 0; 19 public static $current_query = array(); 20 public static $url_to_cache = ''; 21 public static $pattern = null; 22 public static $cache_type = 'html'; 23 public static $first_ob_output = true; 24 public static $current_buffer = ''; 25 public static $force_process_type = null; 26 public static $force_permalink = false; 27 public static $advanced_settings = null; 28 public static $can_cache_handler = null; 28 29 29 30 /* Added for validation in optimize process. */ … … 44 45 */ 45 46 public static function get_file_lock($path_file) { 46 47 47 if (!file_exists($path_file)) { 48 48 @mkdir($path_file, 0777, true); … … 56 56 return flock(self::$can_cache_handler, LOCK_EX | LOCK_NB); 57 57 } 58 58 59 59 public static function get_db_lock($path_file) { 60 60 global $wpdb; 61 61 $wpdb->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE'); 62 62 $wpdb->query('START TRANSACTION'); 63 64 63 65 64 $option_lock = 'flash_cache_db_lock_' . hash('sha256', $path_file); 66 65 67 66 $results = $wpdb->get_results( 68 67 $wpdb->prepare( 69 "SELECT * FROM " . flash_cache_settings::$flash_cache_table ." WHERE option_lock = %s LIMIT 0, 25 FOR UPDATE NOWAIT",68 "SELECT * FROM " . flash_cache_settings::$flash_cache_table . " WHERE option_lock = %s LIMIT 0, 25 FOR UPDATE NOWAIT", 70 69 $option_lock 71 70 ) … … 80 79 $wpdb->query( 81 80 $wpdb->prepare( 82 "INSERT INTO " . flash_cache_settings::$flash_cache_table ." (option_lock, option_value) VALUES(%s, 1)",81 "INSERT INTO " . flash_cache_settings::$flash_cache_table . " (option_lock, option_value) VALUES(%s, 1)", 83 82 $option_lock 84 83 ) 85 ); 84 ); 86 85 } 87 86 … … 93 92 return true; 94 93 } 94 95 95 /** 96 96 * Static function can_create_cache … … 100 100 */ 101 101 public static function start_create_cache($path_file) { 102 103 102 $advanced_settings = flash_cache_get_advanced_settings(); 104 103 if (empty($advanced_settings)) { … … 143 142 } 144 143 $cache_dir = flash_cache_get_home_path() . self::$advanced_settings['cache_dir']; 145 $log_file = $cache_dir . flash_cache_get_server_name() . '/cache_debug.log';144 $log_file = $cache_dir . flash_cache_get_server_name() . '/cache_debug.log'; 146 145 if (!file_exists($cache_dir . flash_cache_get_server_name())) { 147 146 @mkdir($cache_dir . flash_cache_get_server_name(), 0777, true); 148 147 } 149 148 150 149 $request_URI = sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])); 151 150 152 151 // Convert arrays and objects to string 153 152 if (is_array($message) || is_object($message)) { 154 153 $message = print_r($message, true); 155 154 } 156 155 157 156 $log_message = date('H:i:s') . " " . getmypid() . " {$request_URI} {$message}\n\r"; 158 157 error_log($log_message, 3, $log_file); … … 166 165 */ 167 166 public static function cache_response_html($response, $url_to_cache) { 168 $defer_flash_cache_js = '<script type="text/javascript">167 $defer_flash_cache_js = '<script type="text/javascript"> 169 168 function flash_cache_onloadjs() { 170 169 var pattern_minimum = ' . absint(self::$pattern['ttl_minimum']) . '; … … 183 182 } 184 183 </script>'; 185 $response = str_replace('</body>', $defer_flash_cache_js . '</body>', $response);184 $response = str_replace('</body>', $defer_flash_cache_js . '</body>', $response); 186 185 return $response; 187 186 } 188 187 189 188 public static function create_cache_html() { 190 191 189 if (is_null(self::$origin_url)) { 192 190 self::$origin_url = get_site_url(null, '/'); … … 194 192 self::$origin_url = flash_cache_sanitize_origin_url(self::$origin_url); 195 193 196 $advanced_settings = flash_cache_get_advanced_settings(); 197 $cache_dir = flash_cache_get_home_path() . $advanced_settings['cache_dir']; 198 199 // Delete initial path 200 $path = str_replace(self::$origin_url, '', self::$url_to_cache); 201 $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path); 202 203 194 $advanced_settings = flash_cache_get_advanced_settings(); 195 $cache_dir = rtrim(flash_cache_get_home_path() . $advanced_settings['cache_dir'], '/') . '/'; 196 $server_name = trim(flash_cache_get_server_name(), '/'); 197 198 if (empty($server_name)) { 199 error_log('Error: flash_cache_get_server_name() devolvió un valor vacío.'); 200 $server_name = 'default'; 201 } 202 203 if (filter_var(self::$url_to_cache, FILTER_VALIDATE_URL)) { 204 $parsed_url = parse_url(self::$url_to_cache); 205 $host_to_remove = $parsed_url['host'] ?? ''; 206 $relative_path = str_replace($parsed_url['scheme'] . '://' . $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''), '', self::$url_to_cache); 207 } else { 208 preg_match('~flash_cache/([^/]+)/~', self::$url_to_cache, $matches); 209 $host_to_remove = $matches[1] ?? ''; 210 $relative_path = str_replace($host_to_remove, '', self::$url_to_cache); 211 } 212 213 $path = trim(str_replace(self::$origin_url, '', $relative_path), '/'); 214 $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path); 215 $response = flash_cache_get_content(self::$url_to_cache); 216 217 $parent_dir = $cache_dir . $server_name; 218 if (!file_exists($parent_dir)) { 219 220 @mkdir($parent_dir, 0777, true); 221 } 204 222 if (!file_exists($cache_path)) { 223 205 224 @mkdir($cache_path, 0777, true); 206 225 } 226 227 207 228 if (!self::start_create_cache($cache_path)) { 208 229 self::end_create_cache(); 209 230 return false; 210 231 } 211 212 $response = flash_cache_get_content(self::$url_to_cache); 213 232 233 234 235 236 214 237 if (empty($response['response'])) { 215 238 return; 216 239 } 217 240 218 219 220 self::debug('Creating HTML cache file path:' . $path . ' -URL:' . self::$url_to_cache); 241 self::debug('Creating HTML cache file path:' . $path . ' - URL:' . self::$url_to_cache); 221 242 222 243 $response['response'] = apply_filters('flash_cache_response_html', $response['response'], self::$url_to_cache); … … 224 245 $gzip_html = gzencode($response['response']); 225 246 file_put_contents($cache_path . 'index-cache.html', $response['response']); 226 file_put_contents($cache_path . 'index-cache.html.gz', gzencode($response['response']));247 file_put_contents($cache_path . 'index-cache.html.gz', $gzip_html); 227 248 flash_cache_increment_disk_usage(mb_strlen($response['response'], '8bit')); 228 249 flash_cache_increment_disk_usage(mb_strlen($gzip_html, '8bit')); 250 229 251 self::end_create_cache(); 230 252 } 231 253 232 254 public static function create_cache_php() { 233 global $wp_query;255 global $wp_query; 234 256 if (is_null(self::$origin_url)) { 235 257 self::$origin_url = get_site_url(null, '/'); 236 258 } 237 self::$origin_url = flash_cache_sanitize_origin_url(self::$origin_url);259 self::$origin_url = flash_cache_sanitize_origin_url(self::$origin_url); 238 260 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), flash_cache_settings::default_advanced_options()); 239 240 $home_path = flash_cache_get_home_path(); 241 $cache_dir = $home_path . $advanced_settings['cache_dir']; 242 243 $path = str_replace(self::$origin_url, '', self::$url_to_cache); 244 261 $home_path = flash_cache_get_home_path(); 262 $cache_dir = $home_path . $advanced_settings['cache_dir']; 263 264 $parsed_url = parse_url(self::$url_to_cache); 265 266 $relative_url = str_replace($parsed_url['scheme'] . '://' . $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''), '', self::$url_to_cache); 267 268 $path = str_replace(self::$origin_url, '', $relative_url); 245 269 $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path); 246 270 … … 254 278 } 255 279 280 $cache_template = apply_filters('flash_cache_template_file', FLASH_CACHE_PLUGIN_DIR . 'includes/' . 'cache.tpl', $advanced_settings); 281 256 282 self::debug('Creating PHP cache file path:' . $path . ' - URL:' . self::$url_to_cache); 257 $template_php = file_get_contents(FLASH_CACHE_PLUGIN_DIR . 'includes/cache.tpl'); 258 $template_php = str_replace('{home_path}', "'" . $home_path . "'", $template_php); 259 $template_php = str_replace('{url_path}', "'" . self::$url_to_cache . "'", $template_php); 260 $template_php = str_replace('{minimum_ttl}', self::$pattern['ttl_minimum'], $template_php); 261 $template_php = str_replace('{maximum_ttl}', self::$pattern['ttl_maximum'], $template_php); 262 263 if (!file_exists($cache_path . 'index-cache.php')) { 264 file_put_contents($cache_path . 'index-cache.php', $template_php); 265 flash_cache_increment_disk_usage(mb_strlen($template_php, '8bit')); 266 } 267 $request_url = flash_cache_get_content_to_php(self::$url_to_cache); 283 $template_php = file_get_contents($cache_template); 284 $template_php = str_replace('{home_path}', "'" . $home_path . "'", $template_php); 285 $template_php = str_replace('{url_path}', "'" . self::$url_to_cache . "'", $template_php); 286 $template_php = str_replace('{minimum_ttl}', self::$pattern['ttl_minimum'], $template_php); 287 $template_php = str_replace('{maximum_ttl}', self::$pattern['ttl_maximum'], $template_php); 288 $request_url = flash_cache_get_content_to_php(self::$url_to_cache); 289 268 290 if (defined('FLASH_CACHE_NOT_USE_THIS_REQUEST')) { 269 291 $request = hash('sha256', http_build_query(array())); … … 276 298 @mkdir($cache_path . $request_path, 0777, true); 277 299 } 278 $request_file_path = $cache_path . $request_path . $request . '.html'; 279 $header_file_path = $cache_path . $request_path . $request . '.header'; 300 301 if (!file_exists($cache_path . 'index-cache.php')) { 302 file_put_contents($cache_path . 'index-cache.php', $template_php); 303 flash_cache_increment_disk_usage(mb_strlen($template_php, '8bit')); 304 } 305 306 $request_file_path = $cache_path . $request_path . $request . '.html'; 307 $header_file_path = $cache_path . $request_path . $request . '.header'; 280 308 281 309 if (is_search() && $wp_query->post_count > 0) { 282 310 file_put_contents($request_file_path, $request_url['response']); 283 311 file_put_contents($header_file_path, $request_url['content_type']); 284 } elseif(!is_search()){312 } elseif (!is_search()) { 285 313 file_put_contents($request_file_path, $request_url['response']); 286 314 file_put_contents($header_file_path, $request_url['content_type']); … … 293 321 294 322 public static function process_cache_from_query($current_query, $opcional_url = '') { 295 296 $current_url = '';297 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), flash_cache_settings::default_advanced_options());298 299 self::$cache_type = 'html';300 $create_cache = false;301 $args = array('post_type' => 'flash_cache_patterns', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1);302 $patterns = get_posts($args);303 $is_post = false;323 324 $current_url = ''; 325 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), flash_cache_settings::default_advanced_options()); 326 327 self::$cache_type = 'html'; 328 $create_cache = false; 329 $args = array('post_type' => 'flash_cache_patterns', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1); 330 $patterns = get_posts($args); 331 $is_post = false; 304 332 305 333 // We validate if it is post … … 327 355 $pattern = flash_cache_patterns::get_data($pt->ID); 328 356 329 $url_must_contain_array = array();330 $line_arr = explode("\n", $pattern['url_must_contain']);357 $url_must_contain_array = array(); 358 $line_arr = explode("\n", $pattern['url_must_contain']); 331 359 332 360 foreach ($line_arr as $key => $value) { … … 337 365 } 338 366 339 367 340 368 if (!empty($url_must_contain_array)) { 341 369 foreach ($url_must_contain_array as $km => $url_must_contain) { … … 346 374 } 347 375 348 $url_not_contain_array = array();349 $line_arr = explode("\n", $pattern['url_not_contain']);376 $url_not_contain_array = array(); 377 $line_arr = explode("\n", $pattern['url_not_contain']); 350 378 351 379 foreach ($line_arr as $key => $value) { … … 367 395 if ($pattern['page_type']['single'] && ($current_query['is_single'] || $current_query['is_page']) && !$current_query['is_feed']) { 368 396 if (empty($pattern['page_type']['posts'])) { 369 $create_cache = true;370 self::$cache_type = $pattern['cache_type'];397 $create_cache = true; 398 self::$cache_type = $pattern['cache_type']; 371 399 break; 372 400 } else { 373 401 foreach ($pattern['page_type']['posts'] as $pcpt => $pp) { 374 402 if ($pcpt == $post->post_type) { 375 $create_cache = true;376 self::$cache_type = $pattern['cache_type'];403 $create_cache = true; 404 self::$cache_type = $pattern['cache_type']; 377 405 break; 378 406 } … … 383 411 384 412 if ($pattern['page_type']['search'] && $current_query['is_search'] && !$current_query['is_feed']) { 385 $create_cache = true;386 self::$cache_type = $pattern['cache_type'];413 $create_cache = true; 414 self::$cache_type = $pattern['cache_type']; 387 415 break; 388 416 } 389 417 if ($pattern['page_type']['archives'] && $current_query['is_archive'] && !$current_query['is_feed']) { 390 $create_cache = true;391 self::$cache_type = $pattern['cache_type'];418 $create_cache = true; 419 self::$cache_type = $pattern['cache_type']; 392 420 break; 393 421 } 394 422 if ($pattern['page_type']['category'] && $current_query['is_category'] && !$current_query['is_feed']) { 395 $create_cache = true;396 self::$cache_type = $pattern['cache_type'];423 $create_cache = true; 424 self::$cache_type = $pattern['cache_type']; 397 425 break; 398 426 } 399 427 if ($pattern['page_type']['tag'] && $current_query['is_tag'] && !$current_query['is_feed']) { 400 $create_cache = true;401 self::$cache_type = $pattern['cache_type'];428 $create_cache = true; 429 self::$cache_type = $pattern['cache_type']; 402 430 break; 403 431 } 404 432 if ($pattern['page_type']['frontpage'] && $current_query['is_front_page']) { 405 $create_cache = true;406 self::$cache_type = $pattern['cache_type'];433 $create_cache = true; 434 self::$cache_type = $pattern['cache_type']; 407 435 break; 408 436 } 409 437 if ($pattern['page_type']['home'] && $current_query['is_home']) { 410 $create_cache = true;411 self::$cache_type = $pattern['cache_type'];438 $create_cache = true; 439 self::$cache_type = $pattern['cache_type']; 412 440 break; 413 441 } 414 442 if ($pattern['page_type']['author'] && $current_query['is_author'] && !$current_query['is_feed']) { 415 $create_cache = true;416 self::$cache_type = $pattern['cache_type'];443 $create_cache = true; 444 self::$cache_type = $pattern['cache_type']; 417 445 break; 418 446 } 419 447 if ($pattern['page_type']['feed'] && $current_query['is_feed']) { 420 $create_cache = true;421 self::$cache_type = $pattern['cache_type'];448 $create_cache = true; 449 self::$cache_type = $pattern['cache_type']; 422 450 break; 423 451 } … … 425 453 426 454 if ($create_cache) { 427 428 429 430 455 431 456 self::$current_query = $current_query; 432 457 self::$url_to_cache = $current_url; 433 458 self::$pattern = $pattern; 434 459 435 460 $process_type = $advanced_settings['process_type']; 436 461 if (!empty(self::$force_process_type)) { … … 438 463 } 439 464 440 441 442 465 if ($create_cache) { 466 443 467 if ($process_type == 'ob_with_curl_request') { 468 444 469 ob_start(array(__CLASS__, 'ob_callback')); 445 470 } else { … … 455 480 456 481 public static function process_patterns() { 457 482 458 483 if (isset($_COOKIE["flash_cache"]) || isset($_COOKIE["flash_cache_backend"])) { 459 484 return true; … … 469 494 } 470 495 471 472 $general_settings = wp_parse_args(get_option('flash_cache_settings', array()), flash_cache_settings::default_general_options()); 473 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), flash_cache_settings::default_advanced_options()); 496 $general_settings = wp_parse_args(get_option('flash_cache_settings', array()), flash_cache_settings::default_general_options()); 497 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), flash_cache_settings::default_advanced_options()); 474 498 if (!$general_settings['activate']) { 475 499 return true; … … 538 562 } 539 563 540 $p = sanitize_text_field($_GET['p']);541 $token = sanitize_text_field($_GET['token']);564 $p = sanitize_text_field($_GET['p']); 565 $token = sanitize_text_field($_GET['token']); 542 566 543 567 $checksum = hash('sha256', $p . wp_salt('nonce')); … … 554 578 } 555 579 556 $url_parse = parse_url($url);557 $origin_parse = parse_url(self::$origin_url);580 $url_parse = parse_url($url); 581 $origin_parse = parse_url(self::$origin_url); 558 582 if ($url_parse['host'] != $origin_parse['host']) { 559 583 exit; … … 561 585 562 586 do_action('onload_cache_file', $url); 563 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), flash_cache_settings::default_advanced_options());564 $cache_dir = flash_cache_get_home_path() . $advanced_settings['cache_dir'];565 $path = str_replace(self::$origin_url, '', $url);566 $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path);567 $cache_file = $cache_path . 'index-cache.html';587 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), flash_cache_settings::default_advanced_options()); 588 $cache_dir = flash_cache_get_home_path() . $advanced_settings['cache_dir']; 589 $path = str_replace(self::$origin_url, '', $url); 590 $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path); 591 $cache_file = $cache_path . 'index-cache.html'; 568 592 if (file_exists($cache_file)) { 569 593 $cache_response = file_get_contents($cache_file); … … 580 604 exit; 581 605 } else { 582 $opcional_url = self::$origin_url . $path;583 $current_query = flash_cache_get_var_javascript('current_query', $cache_response);584 $current_query = json_decode(base64_decode($current_query), true);606 $opcional_url = self::$origin_url . $path; 607 $current_query = flash_cache_get_var_javascript('current_query', $cache_response); 608 $current_query = json_decode(base64_decode($current_query), true); 585 609 self::debug('Procesing a new pattern from onload_cache:' . var_export($current_query, true)); 586 self::$force_process_type = 'curl';587 self::$optional_post_id = flash_cache_get_var_javascript('flash_cache_optional_post_id', $cache_response);610 self::$force_process_type = 'curl'; 611 self::$optional_post_id = flash_cache_get_var_javascript('flash_cache_optional_post_id', $cache_response); 588 612 self::process_cache_from_query($current_query, $opcional_url); 589 613 } … … 607 631 */ 608 632 public static function create_cache_from_ob($buffer, $use_curl) { 609 self::$current_buffer .= $buffer;610 $new_cache = true;633 self::$current_buffer .= $buffer; 634 $new_cache = true; 611 635 if (!preg_match(apply_filters('flash_cache_end_of_tags', '/(<\/html>|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i'), self::$current_buffer)) { 612 636 // No closing html tag. Not caching. … … 639 663 $advanced_settings = flash_cache_get_advanced_settings(); 640 664 641 $cache_dir = flash_cache_get_home_path() . $advanced_settings['cache_dir'];642 $path = self::get_path(self::$optional_post_id);643 $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path);665 $cache_dir = flash_cache_get_home_path() . $advanced_settings['cache_dir']; 666 $path = self::get_path(self::$optional_post_id); 667 $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path); 644 668 645 669 if (!self::start_create_cache($cache_path)) { … … 665 689 666 690 $gzip_response = gzencode($response); 691 if (file_exists($cache_path . 'index-cache.html') && file_exists($cache_path . 'index-cache.html.gz')) { 692 return false; 693 } 667 694 file_put_contents($cache_path . 'index-cache.html', $response); 668 695 file_put_contents($cache_path . 'index-cache.html.gz', $gzip_response); … … 674 701 675 702 public static function create_cache_ob_php($response, $use_curl) { 676 global $wp_query;703 global $wp_query; 677 704 if (is_null(self::$origin_url)) { 678 705 self::$origin_url = get_site_url(null, '/'); 679 706 } 680 self::$origin_url = flash_cache_sanitize_origin_url(self::$origin_url); 681 $advanced_settings = flash_cache_get_advanced_settings(); 682 $home_path = flash_cache_get_home_path(); 683 $cache_dir = $home_path . $advanced_settings['cache_dir']; 684 $path = self::get_path(self::$optional_post_id); 685 $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path); 707 self::$origin_url = flash_cache_sanitize_origin_url(self::$origin_url); 708 $advanced_settings = flash_cache_get_advanced_settings(); 709 $home_path = flash_cache_get_home_path(); 710 $cache_dir = $home_path . $advanced_settings['cache_dir']; 711 $path = self::get_path(self::$optional_post_id); 712 $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path); 713 686 714 if (!file_exists($cache_path)) { 687 715 @mkdir($cache_path, 0777, true); … … 693 721 694 722 self::debug('Creating OB PHP cache file path:' . $path . ' - URL:' . self::$url_to_cache); 695 $template_php = file_get_contents(FLASH_CACHE_PLUGIN_DIR . 'includes/cache.tpl'); 696 $template_php = str_replace('{home_path}', "'" . $home_path . "'", $template_php); 697 $template_php = str_replace('{url_path}', "'" . self::$url_to_cache . "'", $template_php); 698 $template_php = str_replace('{minimum_ttl}', self::$pattern['ttl_minimum'], $template_php); 699 $template_php = str_replace('{maximum_ttl}', self::$pattern['ttl_maximum'], $template_php); 723 724 $cache_template = apply_filters('flash_cache_template_file', FLASH_CACHE_PLUGIN_DIR . 'includes/' . 'cache.tpl', $advanced_settings); 725 726 $template_php = file_get_contents($cache_template); 727 $template_php = str_replace('{home_path}', "'" . $home_path . "'", $template_php); 728 $template_php = str_replace('{url_path}', "'" . self::$url_to_cache . "'", $template_php); 729 $template_php = str_replace('{minimum_ttl}', self::$pattern['ttl_minimum'], $template_php); 730 $template_php = str_replace('{maximum_ttl}', self::$pattern['ttl_maximum'], $template_php); 700 731 701 732 if (!file_exists($cache_path . 'index-cache.php')) { … … 717 748 @mkdir($cache_path . $request_path, 0777, true); 718 749 } 719 $request_file_path = $cache_path . $request_path . $request . '.html';720 $header_file_path = $cache_path . $request_path . $request . '.header';721 $current_content_type = 'text/html; charset=UTF-8';722 $headers = headers_list();750 $request_file_path = $cache_path . $request_path . $request . '.html'; 751 $header_file_path = $cache_path . $request_path . $request . '.header'; 752 $current_content_type = 'text/html; charset=UTF-8'; 753 $headers = headers_list(); 723 754 foreach ($headers as $header) { 724 755 if (stripos($header, 'Content-Type') !== FALSE) { 725 $headerParts = explode(':', $header);726 $current_content_type = trim($headerParts[1]);756 $headerParts = explode(':', $header); 757 $current_content_type = trim($headerParts[1]); 727 758 break; 728 759 } … … 732 763 file_put_contents($request_file_path, $response); 733 764 file_put_contents($header_file_path, $current_content_type); 734 } elseif(!is_search()){765 } elseif (!is_search()) { 735 766 file_put_contents($request_file_path, $response); 736 767 file_put_contents($header_file_path, $current_content_type); … … 751 782 $uri = ''; 752 783 if ($post_id != 0) { 753 $site_url = site_url();754 $permalink = get_permalink($post_id);784 $site_url = site_url(); 785 $permalink = get_permalink($post_id); 755 786 if (false === strpos($permalink, $site_url)) { 756 787 … … 782 813 if ($process_type == 'ob_with_curl_request' && false === strpos(self::$url_to_cache, self::$origin_url)) { 783 814 $request_URI = sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])); 784 $uri = strtolower($request_URI);815 $uri = strtolower($request_URI); 785 816 } else { 786 817 $uri = str_replace(self::$origin_url, '', self::$url_to_cache); … … 789 820 return $uri; 790 821 } 791 792 822 } 793 823 794 824 flash_cache_process::hooks(); 795 ?> -
flash-cache/trunk/includes/settings.php
r3125571 r3266664 69 69 'flash_cache_setting', 70 70 array(__CLASS__, 'general_settings_page'), 71 FLASH_CACHE_PLUGIN_URL . 'assets/img/flash-cache-icon.png', 29); 71 FLASH_CACHE_PLUGIN_URL . 'assets/img/flash-cache-icon.png', 72 29 73 ); 72 74 $page = add_submenu_page( 73 75 'flash_cache_setting', … … 81 83 82 84 public static function all_WP_admin_styles() { 83 ?><style type="text/css"> 85 ?> 86 <style type="text/css"> 84 87 #adminmenu .toplevel_page_flash_cache_setting .wp-menu-image img { 85 88 padding-top: 5px; … … 89 92 90 93 public static function default_general_options() { 91 $array = array(94 $array = array( 92 95 'activate' => false, 93 96 ); 94 $array = apply_filters('flash_cache_default_general_options', $array);97 $array = apply_filters('flash_cache_default_general_options', $array); 95 98 return $array; 96 99 } … … 163 166 164 167 public static function default_advanced_options() { 165 $array = array(168 $array = array( 166 169 'cache_dir' => 'flash_cache/', 167 170 'viewer_protocol_policy' => 'http_and_https', … … 183 186 'avoid_optimize_text' => '', 184 187 'lock_type' => 'file', 188 'disable_widget_cache' => false, 185 189 ); 186 $array = apply_filters('flash_cache_default_advanced_options', $array);190 $array = apply_filters('flash_cache_default_advanced_options', $array); 187 191 return $array; 188 192 } … … 213 217 if ($typenow == 'flash_cache_patterns') { 214 218 ?> 215 <div class="clear"></div></div> 216 <div class="clear"></div></div> 217 <div class="clear"></div></div> 219 <div class="clear"></div> 220 </div> 221 <div class="clear"></div> 222 </div> 223 <div class="clear"></div> 224 </div> 218 225 <?php 219 226 } … … 226 233 ?> 227 234 </div> <!-- wpfooter fix --> 228 <div class="clear"></div></div> 229 <div class="clear"></div></div> 230 <div class="clear"></div></div> 235 <div class="clear"></div> 236 </div> 237 <div class="clear"></div> 238 </div> 239 <div class="clear"></div> 240 </div> 231 241 <div id="wpfooter" role="contentinfo"> 232 242 <?php … … 235 245 236 246 public static function advanced_settings_page() { 237 $values = wp_parse_args(get_option('flash_cache_advanced_settings', array()), self::default_advanced_options());247 $values = wp_parse_args(get_option('flash_cache_advanced_settings', array()), self::default_advanced_options()); 238 248 239 249 echo '<div class="wrap wpm_container show_menu"><div class="flash-wrap-notices"></div> … … 320 330 </td> 321 331 </tr>'; 322 echo ' 332 echo '<tr valign="top" class="wrap-row"> 333 <th scope="row">' . __('Disable Cache in Widgets', 'flash-cache') . '</th> 334 <td>'; 335 336 $nopro = '<p class="description">' . __('Widget cache disabling is available in the Pro version.', 'flash-cache') . '</p>'; 337 echo apply_filters('flash_cache_disable_cache_option', $nopro, $values); 338 339 echo '</td> 340 </tr>'; 341 echo ' 323 342 <tr valign="top" class="wrap-row"> 324 343 <th scope="row">' . __('Optimize styles', 'flash-cache') . '</th> … … 354 373 </span> 355 374 </div> 356 <p class="description">' . __('Optimize and combine all your JavaScript files into one, this allows your site to request fewer files and get better page load performance.', 'flash-cache') . '</p> 357 '; 358 375 <p class="description">' . __('Optimize and combine all your JavaScript files into one, this allows your site to request fewer files and get better page load performance.', 'flash-cache') . '</p>'; 376 359 377 // new advanced options for javascripts 360 378 // since 3.1 version … … 429 447 </table> 430 448 </div>'; 431 echo apply_filters('flash_cache_optimize_scripts_extra_html', '', $values) . ' 449 450 echo apply_filters('flash_cache_optimize_scripts_extra_html', '', $values) . ' 451 432 452 </td> 433 453 </tr>'; … … 525 545 } 526 546 } 547 527 548 /** Sanitize all inputs and only accept the valid settings */ 528 549 $post_values = flash_cache_sanitize_settings_deep(self::default_advanced_options(), $post_values); 529 530 $new_options = wp_parse_args($post_values, self::default_advanced_options());531 $new_options = apply_filters('flash_cache_check_advanced_settings', $new_options);532 if ($old_value_lock = flash_cache_get_option('lock_type')) {550 551 $new_options = wp_parse_args($post_values, self::default_advanced_options()); 552 $new_options = apply_filters('flash_cache_check_advanced_settings', $new_options); 553 if ($old_value_lock = flash_cache_get_option('lock_type')) { 533 554 if ($old_value_lock != $new_options['lock_type']) { 534 555 $cache_dir = flash_cache_get_option('cache_dir'); 535 if (isset($cache_dir) && $cache_dir != '/'){556 if (isset($cache_dir) && $cache_dir != '/') { 536 557 $cache_dir = flash_cache_get_home_path() . $cache_dir; 537 558 flash_cache_delete_dir($cache_dir, true); … … 539 560 } 540 561 } 562 563 564 $new_options = apply_filters('flash_cache_save_advanced_options', $new_options, $post_values); 565 566 $redirect_url = apply_filters('flash_cache_save_advanced_redirect_url', sanitize_url($_POST['_wp_http_referer'])); 567 541 568 update_option('flash_cache_advanced_settings', $new_options); 569 // Update .htaccess file 542 570 flash_cache_update_htaccess(); 571 572 // Adds new notice to notify the Saved Options. 543 573 flash_cache_notices::add(__('Settings updated', 'flash-cache')); 544 wp_redirect(sanitize_url($_POST['_wp_http_referer'])); 574 wp_redirect($redirect_url); 575 576 // Delete current cache by the new options 577 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), self::default_advanced_options()); 578 $cache_dir = get_home_path() . $advanced_settings['cache_dir']; 579 flash_cache_delete_dir($cache_dir, true); 545 580 exit; 581 } 582 583 public static function is_widget_cache_disabled() { 584 $flash_cache_advanced = get_option('flash_cache_advanced_settings'); 585 return isset($flash_cache_advanced['disable_widget_cache']) && $flash_cache_advanced['disable_widget_cache']; 546 586 } 547 587 … … 560 600 wp_die(__('Security check', 'flash-cache')); 561 601 } 562 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), self::default_advanced_options());563 $cache_dir = get_home_path() . $advanced_settings['cache_dir'];602 $advanced_settings = wp_parse_args(get_option('flash_cache_advanced_settings', array()), self::default_advanced_options()); 603 $cache_dir = get_home_path() . $advanced_settings['cache_dir']; 564 604 flash_cache_delete_dir($cache_dir, true); 565 605 flash_cache_notices::add(__('The cache files have been deleted.', 'flash-cache')); … … 598 638 public static function flash_cache_check_permalinks() { 599 639 global $current_screen; 600 if (isset($current_screen->id) &&601 ($current_screen->id == 'toplevel_page_flash_cache_setting' || $current_screen->id == 'options-permalink')640 if( isset($current_screen->id) && 641 ($current_screen->id == 'toplevel_page_flash_cache_setting' || $current_screen->id == 'options-permalink') 602 642 ) { 603 643 if (get_option('permalink_structure') == '') { … … 615 655 616 656 flash_cache_settings::hooks(); 617 ?> -
flash-cache/trunk/readme.txt
r3125571 r3266664 1 1 === Flash Cache === 2 Contributors: etruel, khaztiel, sniuk, Gerarjos142 Contributors: etruel, khaztiel, Gerarjos14, sniuk 3 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7267TH4PT3GSW 4 4 Tags: cache, performance, speed, optimize, wp cache 5 5 Requires at least: 3.6 6 Tested up to: 6. 66 Tested up to: 6.7.2 7 7 Requires PHP: 5.6 8 Stable tag: 3. 48 Stable tag: 3.5 9 9 License: GPLv2 or later 10 10 … … 92 92 == Changelog == 93 93 94 = 3.5 Apr 3, 2025 = 95 * Improved many some filters to allow pro version to be more efficient by avoiding caching widgets. 96 * Fixes getting cache initial path on creating cache for special url of some files. 97 * Fixes double compression some times serving zipped files. 98 * Fixes Cache PHP mode to be used with avoid cache widgets feature of PRO Version. 99 * Fixed an issue to prevent WP framework to being loaded in caches generated on PHP mode. 100 * Fixes bug Notice Function _load_textdomain_just_in_time was called incorrectly. 101 94 102 = 3.4 Jul 25, 2024 = 95 103 * Added compatibility with pro version to cache external fonts.
Note: See TracChangeset
for help on using the changeset viewer.