Plugin Directory

Changeset 3266664


Ignore:
Timestamp:
04/04/2025 02:50:12 AM (12 months ago)
Author:
etruel
Message:

3.5 Apr 3, 2025

Location:
flash-cache
Files:
35 added
7 edited

Legend:

Unmodified
Added
Removed
  • flash-cache/trunk/flash_cache.php

    r3125571 r3266664  
    44 * Plugin URI: https://flashcache.net
    55 * 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.4
     6 * Version: 3.5
    77 * Author: Etruel Developments LLC
    88 * Author URI: https://etruel.com/
     
    2121// Plugin version
    2222if (!defined('FLASH_CACHE_VERSION')) {
    23     define('FLASH_CACHE_VERSION', '3.4');
     23    define('FLASH_CACHE_VERSION', '3.5');
    2424}
    2525
     
    4848            self::$instance = new self();
    4949            self::$instance->constants();
    50             self::$instance->load_text_domain();
    5150            self::$instance->hooks();
    5251            self::$instance->includes();
     
    111110        register_uninstall_hook(__FILE__, array(__CLASS__, 'uninstall'));
    112111        add_action('permalink_structure_changed', 'flash_cache_changes_permalinks', 10, 2);
     112        add_action('init', [self::$instance, 'load_textdomain'] );
     113
    113114    }
    114115
    115116    /**
    116      * Static function load_text_domain
     117     * Static function load_textdomain
    117118     * Load the text domain.
    118119     * @access public
     
    120121     * @since 1.0.0
    121122     */
    122     public static function load_text_domain() {
     123    public static function load_textdomain() {
    123124        // Set filter for plugin's languages directory
    124125        $lang_dir    = dirname(plugin_basename(__FILE__)) . '/languages/';
    125126        $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);
    145128    }
    146129
     
    214197
    215198add_action('plugins_loaded', 'Flash_Cache_load');
    216 ?>
  • flash-cache/trunk/includes/cache.tpl

    r2872713 r3266664  
    2727    include $home_path.'index.php';
    2828}
    29 
    30 ?>
  • flash-cache/trunk/includes/functions.php

    r3125571 r3266664  
    834834    return isset($updated) ? $updated : false;
    835835}
    836 ?>
  • flash-cache/trunk/includes/patterns.php

    r3007708 r3266664  
    1313
    1414class flash_cache_patterns {
     15   
    1516
    1617    /**
     
    287288                   
    288289                </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">
    291293                    <tr valign="top">
    292294                        <th scope="row">' . __('Cache Type', 'flash-cache') . '</th>
    293295                        <td>
    294296                            <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') . '
    296302                                <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>
    297303                            </div>
    298 
     304               
    299305                            <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') . '
    301310                                <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>
    302311                            </div>
     
    304313                    </tr>
    305314                </table>';
     315               
    306316        echo '<table class="form-table">
    307317                   
     
    323333                </table></div>';
    324334    }
     335
    325336
    326337    /**
     
    545556
    546557flash_cache_patterns::hooks();
    547 ?>
  • flash-cache/trunk/includes/process.php

    r3125571 r3266664  
    11<?php
     2
    23/**
    34 * @package         etruel\Flash Cache
     
    1314class flash_cache_process {
    1415
    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;
    2829
    2930    /* Added for validation in optimize process. */
     
    4445     */
    4546    public static function get_file_lock($path_file) {
    46 
    4747        if (!file_exists($path_file)) {
    4848            @mkdir($path_file, 0777, true);
     
    5656        return flock(self::$can_cache_handler, LOCK_EX | LOCK_NB);
    5757    }
    58    
     58
    5959    public static function get_db_lock($path_file) {
    6060        global $wpdb;
    6161        $wpdb->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE');
    6262        $wpdb->query('START TRANSACTION');
    63    
    64        
     63
    6564        $option_lock = 'flash_cache_db_lock_' . hash('sha256', $path_file);
    6665
    6766        $results = $wpdb->get_results(
    6867                $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",
    7069                        $option_lock
    7170                )
     
    8079            $wpdb->query(
    8180                    $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)",
    8382                            $option_lock
    8483                    )
    85             ); 
     84            );
    8685        }
    8786
     
    9392        return true;
    9493    }
     94
    9595    /**
    9696     * Static function can_create_cache
     
    100100     */
    101101    public static function start_create_cache($path_file) {
    102 
    103102        $advanced_settings = flash_cache_get_advanced_settings();
    104103        if (empty($advanced_settings)) {
     
    143142        }
    144143        $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';
    146145        if (!file_exists($cache_dir . flash_cache_get_server_name())) {
    147146            @mkdir($cache_dir . flash_cache_get_server_name(), 0777, true);
    148147        }
    149        
     148
    150149        $request_URI = sanitize_url(wp_unslash($_SERVER['REQUEST_URI']));
    151        
     150
    152151        // Convert arrays and objects to string
    153152        if (is_array($message) || is_object($message)) {
    154153            $message = print_r($message, true);
    155154        }
    156        
     155
    157156        $log_message = date('H:i:s') . " " . getmypid() . " {$request_URI} {$message}\n\r";
    158157        error_log($log_message, 3, $log_file);
     
    166165     */
    167166    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">
    169168        function flash_cache_onloadjs() {
    170169        var pattern_minimum = ' . absint(self::$pattern['ttl_minimum']) . ';
     
    183182        }
    184183        </script>';
    185         $response               = str_replace('</body>', $defer_flash_cache_js . '</body>', $response);
     184        $response             = str_replace('</body>', $defer_flash_cache_js . '</body>', $response);
    186185        return $response;
    187186    }
    188187
    189188    public static function create_cache_html() {
    190        
    191189        if (is_null(self::$origin_url)) {
    192190            self::$origin_url = get_site_url(null, '/');
     
    194192        self::$origin_url = flash_cache_sanitize_origin_url(self::$origin_url);
    195193
    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        }
    204222        if (!file_exists($cache_path)) {
     223
    205224            @mkdir($cache_path, 0777, true);
    206225        }
     226
     227
    207228        if (!self::start_create_cache($cache_path)) {
    208229            self::end_create_cache();
    209230            return false;
    210231        }
    211    
    212         $response = flash_cache_get_content(self::$url_to_cache);
    213    
     232
     233
     234
     235
     236
    214237        if (empty($response['response'])) {
    215238            return;
    216239        }
    217240
    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);
    221242
    222243        $response['response'] = apply_filters('flash_cache_response_html', $response['response'], self::$url_to_cache);
     
    224245        $gzip_html = gzencode($response['response']);
    225246        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);
    227248        flash_cache_increment_disk_usage(mb_strlen($response['response'], '8bit'));
    228249        flash_cache_increment_disk_usage(mb_strlen($gzip_html, '8bit'));
     250
    229251        self::end_create_cache();
    230252    }
    231253
    232254    public static function create_cache_php() {
    233         global  $wp_query;
     255        global $wp_query;
    234256        if (is_null(self::$origin_url)) {
    235257            self::$origin_url = get_site_url(null, '/');
    236258        }
    237         self::$origin_url = flash_cache_sanitize_origin_url(self::$origin_url);
     259        self::$origin_url  = flash_cache_sanitize_origin_url(self::$origin_url);
    238260        $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);
    245269        $cache_path = trailingslashit($cache_dir . flash_cache_get_server_name() . '/' . $path);
    246270
     
    254278        }
    255279
     280        $cache_template = apply_filters('flash_cache_template_file', FLASH_CACHE_PLUGIN_DIR . 'includes/' . 'cache.tpl', $advanced_settings);
     281
    256282        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
    268290        if (defined('FLASH_CACHE_NOT_USE_THIS_REQUEST')) {
    269291            $request = hash('sha256', http_build_query(array()));
     
    276298            @mkdir($cache_path . $request_path, 0777, true);
    277299        }
    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';
    280308
    281309        if (is_search() && $wp_query->post_count > 0) {
    282310            file_put_contents($request_file_path, $request_url['response']);
    283311            file_put_contents($header_file_path, $request_url['content_type']);
    284         }elseif(!is_search()){
     312        } elseif (!is_search()) {
    285313            file_put_contents($request_file_path, $request_url['response']);
    286314            file_put_contents($header_file_path, $request_url['content_type']);
     
    293321
    294322    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;
    304332
    305333        // We validate if it is post
     
    327355            $pattern = flash_cache_patterns::get_data($pt->ID);
    328356
    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']);
    331359
    332360            foreach ($line_arr as $key => $value) {
     
    337365            }
    338366
    339            
     367
    340368            if (!empty($url_must_contain_array)) {
    341369                foreach ($url_must_contain_array as $km => $url_must_contain) {
     
    346374            }
    347375
    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']);
    350378
    351379            foreach ($line_arr as $key => $value) {
     
    367395            if ($pattern['page_type']['single'] && ($current_query['is_single'] || $current_query['is_page']) && !$current_query['is_feed']) {
    368396                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'];
    371399                    break;
    372400                } else {
    373401                    foreach ($pattern['page_type']['posts'] as $pcpt => $pp) {
    374402                        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'];
    377405                            break;
    378406                        }
     
    383411
    384412            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'];
    387415                break;
    388416            }
    389417            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'];
    392420                break;
    393421            }
    394422            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'];
    397425                break;
    398426            }
    399427            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'];
    402430                break;
    403431            }
    404432            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'];
    407435                break;
    408436            }
    409437            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'];
    412440                break;
    413441            }
    414442            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'];
    417445                break;
    418446            }
    419447            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'];
    422450                break;
    423451            }
     
    425453
    426454        if ($create_cache) {
    427 
    428 
    429 
    430455
    431456            self::$current_query = $current_query;
    432457            self::$url_to_cache  = $current_url;
    433458            self::$pattern       = $pattern;
    434            
     459
    435460            $process_type = $advanced_settings['process_type'];
    436461            if (!empty(self::$force_process_type)) {
     
    438463            }
    439464
    440            
    441 
    442465            if ($create_cache) {
     466
    443467                if ($process_type == 'ob_with_curl_request') {
     468
    444469                    ob_start(array(__CLASS__, 'ob_callback'));
    445470                } else {
     
    455480
    456481    public static function process_patterns() {
    457        
     482
    458483        if (isset($_COOKIE["flash_cache"]) || isset($_COOKIE["flash_cache_backend"])) {
    459484            return true;
     
    469494        }
    470495
    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());
    474498        if (!$general_settings['activate']) {
    475499            return true;
     
    538562        }
    539563
    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']);
    542566
    543567        $checksum = hash('sha256', $p . wp_salt('nonce'));
     
    554578        }
    555579
    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);
    558582        if ($url_parse['host'] != $origin_parse['host']) {
    559583            exit;
     
    561585
    562586        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';
    568592        if (file_exists($cache_file)) {
    569593            $cache_response = file_get_contents($cache_file);
     
    580604            exit;
    581605        } 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);
    585609            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);
    588612            self::process_cache_from_query($current_query, $opcional_url);
    589613        }
     
    607631     */
    608632    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;
    611635        if (!preg_match(apply_filters('flash_cache_end_of_tags', '/(<\/html>|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i'), self::$current_buffer)) {
    612636            // No closing html tag. Not caching.
     
    639663        $advanced_settings = flash_cache_get_advanced_settings();
    640664
    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);
    644668
    645669        if (!self::start_create_cache($cache_path)) {
     
    665689
    666690        $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        }
    667694        file_put_contents($cache_path . 'index-cache.html', $response);
    668695        file_put_contents($cache_path . 'index-cache.html.gz', $gzip_response);
     
    674701
    675702    public static function create_cache_ob_php($response, $use_curl) {
    676         global  $wp_query;
     703        global $wp_query;
    677704        if (is_null(self::$origin_url)) {
    678705            self::$origin_url = get_site_url(null, '/');
    679706        }
    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
    686714        if (!file_exists($cache_path)) {
    687715            @mkdir($cache_path, 0777, true);
     
    693721
    694722        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);
    700731
    701732        if (!file_exists($cache_path . 'index-cache.php')) {
     
    717748            @mkdir($cache_path . $request_path, 0777, true);
    718749        }
    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();
    723754        foreach ($headers as $header) {
    724755            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]);
    727758                break;
    728759            }
     
    732763            file_put_contents($request_file_path, $response);
    733764            file_put_contents($header_file_path, $current_content_type);
    734         }elseif(!is_search()){
     765        } elseif (!is_search()) {
    735766            file_put_contents($request_file_path, $response);
    736767            file_put_contents($header_file_path, $current_content_type);
     
    751782        $uri = '';
    752783        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);
    755786            if (false === strpos($permalink, $site_url)) {
    756787
     
    782813            if ($process_type == 'ob_with_curl_request' && false === strpos(self::$url_to_cache, self::$origin_url)) {
    783814                $request_URI = sanitize_url(wp_unslash($_SERVER['REQUEST_URI']));
    784                 $uri = strtolower($request_URI);
     815                $uri        = strtolower($request_URI);
    785816            } else {
    786817                $uri = str_replace(self::$origin_url, '', self::$url_to_cache);
     
    789820        return $uri;
    790821    }
    791 
    792822}
    793823
    794824flash_cache_process::hooks();
    795 ?>
  • flash-cache/trunk/includes/settings.php

    r3125571 r3266664  
    6969                'flash_cache_setting',
    7070                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        );
    7274        $page = add_submenu_page(
    7375                'flash_cache_setting',
     
    8183
    8284    public static function all_WP_admin_styles() {
    83         ?><style type="text/css">
     85        ?>
     86        <style type="text/css">
    8487            #adminmenu .toplevel_page_flash_cache_setting .wp-menu-image img {
    8588                padding-top: 5px;
     
    8992
    9093    public static function default_general_options() {
    91         $array  = array(
     94        $array = array(
    9295            'activate' => false,
    9396        );
    94         $array  = apply_filters('flash_cache_default_general_options', $array);
     97        $array = apply_filters('flash_cache_default_general_options', $array);
    9598        return $array;
    9699    }
     
    163166
    164167    public static function default_advanced_options() {
    165         $array  = array(
     168        $array = array(
    166169            'cache_dir'              => 'flash_cache/',
    167170            'viewer_protocol_policy' => 'http_and_https',
     
    183186            'avoid_optimize_text'    => '',
    184187            'lock_type'              => 'file',
     188            'disable_widget_cache'   => false,
    185189        );
    186         $array  = apply_filters('flash_cache_default_advanced_options', $array);
     190        $array = apply_filters('flash_cache_default_advanced_options', $array);
    187191        return $array;
    188192    }
     
    213217        if ($typenow == 'flash_cache_patterns') {
    214218            ?>
    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>
    218225            <?php
    219226        }
     
    226233            ?>
    227234            </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>
    231241            <div id="wpfooter" role="contentinfo">
    232242            <?php
     
    235245
    236246    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());
    238248
    239249        echo '<div class="wrap wpm_container show_menu"><div class="flash-wrap-notices"></div>
     
    320330                        </td>
    321331                    </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 '
    323342                    <tr valign="top" class="wrap-row">
    324343                        <th scope="row">' . __('Optimize styles', 'flash-cache') . '</th>
     
    354373                                </span>
    355374                            </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
    359377        // new advanced options for javascripts
    360378        // since 3.1 version
     
    429447                                </table>
    430448                            </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           
    432452                        </td>
    433453                    </tr>';
     
    525545            }
    526546        }
     547
    527548        /** Sanitize all inputs and only accept the valid settings */
    528549        $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')) {
    533554            if ($old_value_lock != $new_options['lock_type']) {
    534555                $cache_dir = flash_cache_get_option('cache_dir');
    535                 if(isset($cache_dir) && $cache_dir != '/'){
     556                if (isset($cache_dir) && $cache_dir != '/') {
    536557                    $cache_dir = flash_cache_get_home_path() . $cache_dir;
    537558                    flash_cache_delete_dir($cache_dir, true);
     
    539560            }
    540561        }
     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
    541568        update_option('flash_cache_advanced_settings', $new_options);
     569        // Update .htaccess file
    542570        flash_cache_update_htaccess();
     571
     572        // Adds new notice to notify the Saved Options.
    543573        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);
    545580        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'];
    546586    }
    547587
     
    560600            wp_die(__('Security check', 'flash-cache'));
    561601        }
    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'];
    564604        flash_cache_delete_dir($cache_dir, true);
    565605        flash_cache_notices::add(__('The cache files have been deleted.', 'flash-cache'));
     
    598638    public static function flash_cache_check_permalinks() {
    599639        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')
    602642        ) {
    603643            if (get_option('permalink_structure') == '') {
     
    615655
    616656flash_cache_settings::hooks();
    617 ?>
  • flash-cache/trunk/readme.txt

    r3125571 r3266664  
    11=== Flash Cache ===
    2 Contributors: etruel, khaztiel, sniuk, Gerarjos14
     2Contributors: etruel, khaztiel, Gerarjos14, sniuk
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7267TH4PT3GSW
    44Tags: cache, performance, speed, optimize, wp cache
    55Requires at least: 3.6
    6 Tested up to: 6.6
     6Tested up to: 6.7.2
    77Requires PHP: 5.6
    8 Stable tag: 3.4
     8Stable tag: 3.5
    99License: GPLv2 or later
    1010
     
    9292== Changelog ==
    9393
     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
    94102= 3.4 Jul 25, 2024 =
    95103* Added compatibility with pro version to cache external fonts.
Note: See TracChangeset for help on using the changeset viewer.