Plugin Directory

Changeset 3086841


Ignore:
Timestamp:
05/15/2024 06:19:11 AM (23 months ago)
Author:
ShortPixel
Message:

Version 1.0.23 Bugfixes, , added ability to serve cached page for logged in user

Location:
fastpixel-website-accelerator
Files:
2 added
27 edited
19 copied

Legend:

Unmodified
Added
Removed
  • fastpixel-website-accelerator/tags/1.0.23/README.md

    r3083363 r3086841  
    55Tested up to: 6.4
    66Requires PHP: 5.6
    7 Stable tag: 1.0.22
     7Stable tag: 1.0.23
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • fastpixel-website-accelerator/tags/1.0.23/advanced-cache.php

    r3083183 r3086841  
    1414        $includes = [
    1515            'FASTPIXEL\FASTPIXEL_Debug'        => 'debug.php',
     16            'FASTPIXEL\FASTPIXEL_Functions'    => 'functions.php',
    1617            'FASTPIXEL\FASTPIXEL_Url'          => 'url.php',
    17             'FASTPIXEL\FASTPIXEL_Functions'    => 'functions.php',
    1818            'FASTPIXEL\FASTPIXEL_Config_Model' => 'config-model.php',
    1919            'FASTPIXEL\FASTPIXEL_Diag_Test'    => 'backend/models/diag.php',
  • fastpixel-website-accelerator/tags/1.0.23/fastpixel.php

    r3083363 r3086841  
    55 * Description: Faster WordPress made easy - the latest technology to speed up your website, packaged in a 1-minute setup plugin.
    66 * Author:      ShortPixel
    7  * Version:     1.0.22
     7 * Version:     1.0.23
    88 * Text Domain: fastpixel-website-accelerator
    99 * Domain Path: /languages
     
    2121defined('ABSPATH') || exit;
    2222
    23 define('FASTPIXEL_VERSION', '1.0.22');
     23define('FASTPIXEL_VERSION', '1.0.23');
    2424define('FASTPIXEL_NAME', 'FastPixel');
    2525if (!defined('FASTPIXEL_PLUGIN_DIR'))
  • fastpixel-website-accelerator/tags/1.0.23/inc/autoload.php

    r3083183 r3086841  
    99$includes = [
    1010    'FASTPIXEL\FASTPIXEL_Debug'        => 'debug.php',
     11    'FASTPIXEL\FASTPIXEL_Url'          => 'url.php',
    1112    'FASTPIXEL\FASTPIXEL_Functions'    => 'functions.php',
    12     'FASTPIXEL\FASTPIXEL_Url'          => 'url.php',
     13    'FASTPIXEL\FASTPIXEL_Config_Model' => 'config-model.php',
    1314    'FASTPIXEL\FASTPIXEL_Exclude'      => 'exclude-model.php',
    1415    'FASTPIXEL\FASTPIXEL_Excludes'     => 'excludes.php',
    15     'FASTPIXEL\FASTPIXEL_Config_Model' => 'config-model.php',
    1616    'FASTPIXEL\FASTPIXEL_Cache'        => 'cache.php',
    1717    'FASTPIXEL\FASTPIXEL_Plugin'       => 'plugin.php'
    1818];
    1919foreach ($includes as $class_name => $class_path) {
    20     if (!class_exists($class_name)) {
     20    if (!class_exists($class_name) && file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $class_path)) {
    2121        require_once FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $class_path;
    2222    }
     
    2525// // rest_api_init not called if permalinks set to 'Plain'
    2626add_action('rest_api_init', function () {
    27     require FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'rest-api.php';
     27    if (file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'rest-api.php')) {
     28        require FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'rest-api.php';
     29    }
    2830});
    2931//require backend functions
    30 require FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'autoload.php';
     32if (file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'autoload.php')) {
     33    require FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'autoload.php';
     34}
  • fastpixel-website-accelerator/tags/1.0.23/inc/backend/autoload.php

    r3083183 r3086841  
    22defined('ABSPATH') || exit;
    33
    4 //include abstract models
    5 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/api-key.php';
    6 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/action.php';
    7 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/diag.php';
    8 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/ui-tab.php';
    9 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/ui.php';
     4//include models
     5$models = array(
     6    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/api-key.php',
     7    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/action.php',
     8    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/diag.php',
     9    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/ui-tab.php',
     10    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/ui.php',
     11   
     12    //include posts table model
     13    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/posts-ui.php'
     14);
     15foreach($models as $model) {
     16    if (file_exists($model)) {
     17        include_once $model;
     18    }
     19}
    1020
    1121//include action models
     
    1323    while (false !== ($entry = readdir($handle))) {
    1424        if (!in_array($entry, ['.', '..'])) {
    15             include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/actions/' . $entry;
     25            try {
     26                include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/actions/' . $entry;
     27            } catch(Exception $e) {
     28                FASTPIXEL\FASTPIXEL_Debug::log('Error occure while including action model -> ' . $e->getMessage());
     29            }
    1630        }
    1731    }
    1832    closedir($handle);
    1933}
    20 //include posts table model
    21 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/posts-ui.php';
    2234
    2335//include controllers
    24 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/functions.php';
    25 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/notices.php';
    26 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/controller.php';
    27 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/actions.php';
    28 //ui controllers
    29 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui-single.php';
    30 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui-multi.php';
    31 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui.php';
     36$controllers = array(
     37    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/functions.php',
     38    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/notices.php',
     39    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/controller.php',
     40    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/actions.php',
     41    //ui controllers
     42    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui-single.php',
     43    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui-multi.php',
     44    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui.php',
    3245
    33 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/cache.php';
    34 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/diag.php';
     46    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/cache.php',
     47    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/diag.php'
     48);
     49foreach ($controllers as $controller) {
     50    if (file_exists($controller)) {
     51        include_once $controller;
     52    }
     53}
  • fastpixel-website-accelerator/tags/1.0.23/inc/backend/controllers/cache.php

    r3083363 r3086841  
    112112                $current_term = get_term($term_id);
    113113                if ($current_term->slug != $args['slug']) {
    114                     $url = new FASTPIXEL_Url(null, get_term_link($current_term));
     114                    $url = new FASTPIXEL_Url(get_term_link($current_term));
    115115                    $this->delete_url_cache($url);
    116116                }}, 10, 3);
     
    118118                FASTPIXEL_DEBUG::log('ACTION delete_term');
    119119                if (!empty($deleted_term)) {
    120                     $url = new FASTPIXEL_Url(null, get_term_link($deleted_term));
     120                    $url = new FASTPIXEL_Url(get_term_link($deleted_term));
    121121                    $this->delete_url_cache($url);
    122122                }
     
    129129                    $term->slug = $args['slug'];
    130130                }
    131                 $url = new FASTPIXEL_Url(null, get_term_link($term));
     131                $url = new FASTPIXEL_Url(get_term_link($term));
    132132                $this->functions->update_post_cache($url->get_url_path(), true);
    133133            }, 10, 3);
     
    149149                    if ($post->post_status == 'publish' && $data['post_status'] != 'trash') {
    150150                        //resetting/removing cache when post is "unpublished"
    151                         $url = new FASTPIXEL_Url($post_id);
     151                        $url = new FASTPIXEL_Url( (int)$post_id);
    152152                        $this->delete_url_cache($url);
    153153                    }
    154154                    //if post was published and still have publish status then we need to check slug, it can be changed too
    155155                    if ($post->post_status == 'publish' && $post->post_status == $data['post_status'] && $post->post_name != $data['post_name']) {
    156                         $url = new FASTPIXEL_Url($post_id);
     156                        $url = new FASTPIXEL_Url( (int)$post_id);
    157157                        $this->delete_url_cache($url);
    158158                    }
     
    160160                    if ($data['post_status'] == 'trash' && $post->post_status == 'publish') {
    161161                        $post->post_name = preg_replace('/__trashed/i', '', $post->post_name);
    162                         $url = new FASTPIXEL_Url(null, get_the_permalink($post));
     162                        $url = new FASTPIXEL_Url(get_the_permalink($post));
    163163                        $this->delete_url_cache($url);
    164164                    }
     
    171171                    //need to delete old cached slug
    172172                    FASTPIXEL_Debug::log('PRE_POST_UPDATE: Slug changed. Old post slug that should be removed', get_the_permalink($post));
    173                     $url = new FASTPIXEL_Url(null, get_the_permalink($post));
     173                    $url = new FASTPIXEL_Url(get_the_permalink($post));
    174174                    $this->delete_url_cache($url);
    175175                }
     
    178178                    //need to delete old cached slug
    179179                    FASTPIXEL_Debug::log('PRE_POST_UPDATE: Parent changed. Old post slug that should be removed', get_the_permalink($post));
    180                     $url = new FASTPIXEL_Url(null, get_the_permalink($post));
     180                    $url = new FASTPIXEL_Url(get_the_permalink($post));
    181181                    $this->delete_url_cache($url);
    182182                }
     
    229229            }
    230230
    231             $url = new FASTPIXEL_Url($post_id);
     231            $url = new FASTPIXEL_Url( (int)$post_id);
    232232            $path = untrailingslashit($url->get_url_path());
    233233            //need to check if request already was sent, because on post save much hooks are fired and each can trigger cache request
     
    290290                wp_cache_flush();
    291291            }
    292             do_action('fastpixel_purge_all');
     292            do_action('fastpixel/purge/all');
    293293            return true;
    294294        }
     
    358358                }
    359359            } else if ($post_id == 'homepage') {
    360                 $url = new FASTPIXEL_Url(null, get_home_url());
     360                $url = new FASTPIXEL_Url(get_home_url());
    361361                $path = untrailingslashit($url->get_url_path());
    362362                $this->functions->update_post_cache($path, true);
     
    451451                $permalink = get_permalink($post_id);
    452452            }
    453             $url = new FASTPIXEL_Url(null, $permalink);
     453            $url = new FASTPIXEL_Url($permalink);
    454454            if ($this->delete_url_cache($url)) {
    455455                $post_status = $this->be_functions->cache_status_display($url->get_url());
     
    481481                WP_Filesystem();
    482482            }
    483             $url = new FASTPIXEL_Url(null, get_home_url());
     483            $url = new FASTPIXEL_Url(get_home_url());
    484484            $path = untrailingslashit($url->get_url_path());
    485485            //need to check if request already was sent, because on post save much hooks are fired and each can trigger cache request
     
    531531                    // if blog page is set then it needs to be reset
    532532                    $blog_page_id = get_option('page_for_posts');
    533                     $blog_url = new FASTPIXEL_Url($blog_page_id);
     533                    $blog_url = new FASTPIXEL_Url( (int)$blog_page_id);
    534534                    $this->functions->update_post_cache($blog_url->get_url_path(), true);
    535535                }
     
    539539                    $archive_url = get_post_type_archive_link($post_type);
    540540                    if ($archive_url) {
    541                         $url = new FASTPIXEL_Url(null, $archive_url);
     541                        $url = new FASTPIXEL_Url($archive_url);
    542542                        $path = untrailingslashit($url->get_url_path());
    543543                        $this->functions->update_post_cache($path, true);
     
    561561                                $term_link = get_term_link($term);
    562562                                if (!empty($term_link)) {
    563                                     $url = new FASTPIXEL_Url(null, $term_link);
     563                                    $url = new FASTPIXEL_Url($term_link);
    564564                                    $path = untrailingslashit($url->get_url_path());
    565565                                    $this->functions->update_post_cache($path, true);
     
    607607                $url = get_the_permalink($post_id);
    608608            }
    609             $url = new FASTPIXEL_Url(null, $url);
     609            $url = new FASTPIXEL_Url($url);
    610610            if ($this->delete_url_cache($url)) {
    611611                /* translators: %1 should be a url*/
  • fastpixel-website-accelerator/tags/1.0.23/inc/backend/controllers/tabs/settings.php

    r3083183 r3086841  
    4545                'fastpixel_settings_section'
    4646            );
    47             // add_settings_field(
    48             //     'fastpixel_display_cached_for_logged',
    49             //     esc_html__('Logged-in users', 'fastpixel-website-accelerator'),
    50             //     [$this, 'fastpixel_display_cached_for_logged_cb'],
    51             //     FASTPIXEL_TEXTDOMAIN,
    52             //     'fastpixel_settings_section'
    53             // );
     47            add_settings_field(
     48                'fastpixel_display_cached_for_logged',
     49                esc_html__('Logged-in users', 'fastpixel-website-accelerator'),
     50                [$this, 'fastpixel_display_cached_for_logged_cb'],
     51                FASTPIXEL_TEXTDOMAIN,
     52                'fastpixel_settings_section'
     53            );
    5454            add_settings_field(
    5555                'fastpixel_exclusions',
     
    144144                    //deleting existing cache files for excludes
    145145                    foreach($excludes as $exclude) {
    146                         $exclude_url = new FASTPIXEL_Url(null, $home_url . $exclude);
     146                        $exclude_url = new FASTPIXEL_Url($home_url . $exclude);
    147147                        if (!empty($exclude)) {
    148148                            $this->functions->delete_cached_files($exclude_url->get_url_path());
  • fastpixel-website-accelerator/tags/1.0.23/inc/cache.php

    r3083363 r3086841  
    33
    44defined('ABSPATH') || exit;
    5 use FASTPIXEL\FASTPIXEL_Config_Model;
    65
    76if (!class_exists('FASTPIXEL\FASTPIXEL_Cache')) {
     
    4544        public function __construct() {
    4645            self::$instance  = $this;
     46            //checking for classes to avoid breakdown
     47            if (!class_exists('FASTPIXEL\FASTPIXEL_Debug') || !class_exists('FASTPIXEL\FASTPIXEL_Url') ||
     48                !class_exists('FASTPIXEL\FASTPIXEL_Functions') || !class_exists('FASTPIXEL\FASTPIXEL_Config_Model')) {
     49                return false;
     50            }
    4751            $this->functions = FASTPIXEL_Functions::get_instance();
    4852            $this->config    = FASTPIXEL_Config_Model::get_instance();
     
    5963                define('FASTPIXEL_API_URL', FASTPIXEL_API_HOST . '/api/v1/enqueue');
    6064            }
    61             do_action('fastpixel_early_init');
    62 
    63             //moving initialization to mu_plugin_loaded because we need sanitization and escaping function initialized
    64             add_action('mu_plugin_loaded', [$this, 'init']);
     65            do_action('fastpixel/init/early');
     66
     67            //running initialization to check for cached page and return it early if exists
     68            $this->init();
    6569        }
    6670
    6771        public function init() {
    68             if (!$this->check_request_agent()) {
    69                 return;
    70             }
    71             if (!$this->check_request()) {
    72                 return;
    73             }
    74 
     72            //initializing url
     73            $this->url = new FASTPIXEL_Url();
    7574            $this->cache_dir = $this->functions->get_cache_dir();
    76             $this->url = new FASTPIXEL_Url();
    7775            $this->url_path = $this->url->get_url_path();
    7876            $this->html_path = $this->cache_dir . DIRECTORY_SEPARATOR . $this->url_path . 'index.html';
     
    8179            $this->meta_path = $this->cache_dir . DIRECTORY_SEPARATOR . $this->url_path . 'meta';
    8280
    83             //if no cache files exists registering function for cache request
     81            if (!$this->check_request_agent()) {
     82                return;
     83            }
     84            if (!$this->check_request()) {
     85                return;
     86            }
     87
     88            //registering function for cache request
    8489            register_shutdown_function([$this, 'request_page_cache']);
    8590
     91            //returning cached file if it exists
    8692            $this->return_cached_if_exists();
    8793        }
     
    125131            */
    126132            if (isset($_SERVER['HTTP_USER_AGENT']) && !empty($_SERVER['HTTP_USER_AGENT']) &&
    127             (strpos(sanitize_text_field($_SERVER['HTTP_USER_AGENT']), 'FastPixel') !== false)
     133            (strpos($this->functions->sanitize_text_field($_SERVER['HTTP_USER_AGENT']), 'FastPixel') !== false)
    128134            ) {
    129135                //need to check if this is required
     
    138144            */
    139145            if (isset($_SERVER['QUERY_STRING']) &&
    140                 strpos(sanitize_text_field($_SERVER['QUERY_STRING']), 'fastpixeldebug') !== false) {
     146                strpos($this->functions->sanitize_text_field($_SERVER['QUERY_STRING']), 'fastpixeldebug') !== false) {
    141147                $this->debug_mode = true;
    142148            }
     
    144150            * Don't ever cache non-GET requests.
    145151            */
    146             if (!isset($_SERVER['REQUEST_METHOD']) || 'GET' !== sanitize_text_field($_SERVER['REQUEST_METHOD'])) {
     152            if (!isset($_SERVER['REQUEST_METHOD']) || 'GET' !== $this->functions->sanitize_text_field($_SERVER['REQUEST_METHOD'])) {
    147153                FASTPIXEL_DEBUG::log('CHECKING REQUEST: Not GET request, stopped');
    148154                return false;
     
    155161                defined('DOING_AJAX') ||
    156162                (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
    157                 strtolower(sanitize_text_field($_SERVER['HTTP_X_REQUESTED_WITH'])) == 'xmlhttprequest')
     163                strtolower($this->functions->sanitize_text_field($_SERVER['HTTP_X_REQUESTED_WITH'])) == 'xmlhttprequest')
    158164            ) {
    159165                return false;
     
    162168            * getting request url
    163169            */
    164             $requested_url = new FASTPIXEL_Url();
     170            $requested_url = $this->url;
    165171            /**
    166172            * no need to activate class on api request
     
    173179            * run only for index.php
    174180            */
    175             if (!in_array(sanitize_text_field($_SERVER['SCRIPT_NAME']), ['/index.php'])) {
     181            if (!in_array($this->functions->sanitize_text_field($_SERVER['SCRIPT_NAME']), ['/index.php'])) {
    176182                return false;
    177183            }
     
    204210            * don't cache request with nocache query
    205211            */
    206             if(isset($_SERVER['QUERY_STRING']) && strpos(sanitize_text_field($_SERVER['QUERY_STRING']), 'fastpixeldisable') !== false) {
     212            if(isset($_SERVER['QUERY_STRING']) && strpos($this->functions->sanitize_text_field($_SERVER['QUERY_STRING']), 'fastpixeldisable') !== false) {
    207213                return false;
    208214            }
     
    380386            }
    381387
     388            //extra check if file is inside cache folder
     389            if (strpos(realpath($path), realpath($this->functions->get_cache_dir())) !== 0) {
     390                return false;
     391            }
     392
    382393            if (@file_exists($path) && @is_readable($path)) {
    383394                $modified_time = (int) @filemtime($path);
     
    417428                    }
    418429                }
    419                 /*
    420                 * displaying .html file, generated by our service
    421                 * no need to escape output, escape functions are not available in advanced-cache.php
    422                 */
    423                 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- direct file output to the browser.
    424                 readfile($path); // phpcs:ignore
    425                 echo '<!-- Optimized and served by FastPixel.io -->';
    426                 define('FASTPIXEL_STOP_REQUEST', true);
    427                 @ob_end_flush();
    428                 flush();
    429                 exit();
     430                if ($this->config->get_option('fastpixel_display_cached_for_logged') && $this->check_is_logged_in()) {
     431                     //registering hook that will display cached page before page rendering should begin
     432                    add_action('template_redirect', [$this, 'display_cached_for_logged'], 999);
     433                } else {
     434                    /*
     435                     * displaying .html file, generated by our service
     436                     * no need to escape output, escape functions are not available in advanced-cache.php
     437                     */
     438                    // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- direct file output to the browser.
     439                    readfile($path); // phpcs:ignore
     440                    echo '<!-- Optimized and served by FastPixel.io -->';
     441                    define('FASTPIXEL_STOP_REQUEST', true);
     442                    @ob_end_flush();
     443                    flush();
     444                    exit();
     445                }
    430446            }
    431447        }
     
    592608                $request_path = $this->url->get_url_path();
    593609            } else if (isset($post_id) && !is_null($post_id) && !empty($post_id)) {
    594                 $url = new FASTPIXEL_Url($post_id);
     610                $url = new FASTPIXEL_Url( (int)$post_id);
    595611                $request_url = $url->get_url();
    596612                $request_path = $url->get_url_path();
    597613            } else if (isset($post->ID) && !empty($post->ID)) {
    598                 $url = new FASTPIXEL_Url($post->ID);
     614                $url = new FASTPIXEL_Url( (int)$post->ID);
    599615                $request_url = $url->get_url();
    600616                $request_path = $url->get_url_path();
     
    630646                return false;
    631647            }
    632             $diag = FASTPIXEL_Diag::get_instance();
    633             if (!$diag->run_activation_tests()) {
    634                 FASTPIXEL_Debug::log('Common Validation: Stopped. Diagnostics errors');
    635                 return false;
     648            if (class_exists('FASTPIXEL_Diag')) {
     649                $diag = FASTPIXEL_Diag::get_instance();
     650                if (!$diag->run_activation_tests()) {
     651                    FASTPIXEL_Debug::log('Common Validation: Stopped. Diagnostics errors');
     652                    return false;
     653                }
    636654            }
    637655            return true;
     
    642660                return false;
    643661            }
    644             $url = new FASTPIXEL_Url(null, $input_url);
     662            $url = new FASTPIXEL_Url($input_url);
    645663            //check for pages that should be excluded from cache
    646664            $excludes = FASTPIXEL_Excludes::get_instance();
     
    716734            if (!preg_match('/^'.$compare_rest_url_domain.'/i', $compare_reset_url_domain)) {
    717735                FASTPIXEL_DEBUG::log('CACHE REQUEST Error: $reset_url not match FASTPIXEL_REST_URL, request stopped');
     736                FASTPIXEL_DEBUG::log('CACHE REQUEST Error: '.var_export($compare_rest_url_domain, true) . ', '.var_export($compare_reset_url_domain, true), ', '.var_export(FASTPIXEL_REST_URL, true));
    718737                return false;
    719738            }
     
    943962        public function load_modules()
    944963        {
    945             if (!class_exists('FASTPIXEL\FASTPIXEL_Module')) {
     964            //checking if file exists before loading
     965            if (!class_exists('FASTPIXEL\FASTPIXEL_Module')
     966                && file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'module.php')) {
    946967                include_once FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'module.php';
    947             }
    948             if (file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'modules')) {
     968            } else {
     969                return false;
     970            }
     971            //including modules
     972            if (class_exists('FASTPIXEL\FASTPIXEL_Module') && file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'modules')) {
    949973                if ($handle = opendir(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'modules')) {
    950974                    while (false !== ($entry = readdir($handle))) {
     
    961985            }
    962986        }
     987
     988        public function display_cached_for_logged() {
     989            global $wp_styles, $wp_scripts;
     990            ob_start();
     991            $post_id = get_the_ID();
     992            do_action('fastpixel/loggeduser/adminbar/beforerender', $post_id);
     993            foreach ($wp_styles->queue as $handle) {
     994                wp_print_styles($handle);
     995            }
     996            foreach ($wp_scripts->queue as $handle) {
     997                wp_print_scripts($handle);
     998            }
     999            wp_admin_bar_render();
     1000            do_action('fastpixel/loggeduser/adminbar/afterrender', $post_id);
     1001            $admin_bar_output = ob_get_clean();
     1002            ob_start(function ($buffer) use ($admin_bar_output) {
     1003                $regex = '/<\s*\/\s*body/s';
     1004                $buffer = preg_replace($regex, $admin_bar_output . '</body', $buffer);
     1005                return $buffer;
     1006            });
     1007            /*
     1008             * displaying .html file, generated by our service
     1009             * no need to escape output, escape functions are not available in advanced-cache.php
     1010             */
     1011            // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- direct file output to the browser.
     1012            if (@file_exists($this->html_path) && @is_readable($this->html_path)) {
     1013                readfile($this->html_path); // phpcs:ignore
     1014            }
     1015            ob_get_flush();
     1016            exit;
     1017        }
    9631018    }
    9641019    new FASTPIXEL_Cache();
  • fastpixel-website-accelerator/tags/1.0.23/inc/config-model.php

    r3083183 r3086841  
    5858
    5959        public function save_file() {
    60             do_action('save_fastpixel_settings_config', $this);
     60            do_action('fastpixel/settings/config/save', $this);
    6161            if (!file_exists($this->config_dir)) {
    6262                wp_mkdir_p($this->config_dir);
  • fastpixel-website-accelerator/tags/1.0.23/inc/excludes.php

    r3083183 r3086841  
    4343                return false;
    4444            }
    45             $url = new FASTPIXEL_Url(null, $url);
     45            $url = new FASTPIXEL_Url($url);
    4646            foreach ($this->tests as $test) {
    4747                $test_result = $test->check_is_exclusion($url);
  • fastpixel-website-accelerator/tags/1.0.23/inc/functions.php

    r3083183 r3086841  
    137137                return false;
    138138            } else {
    139                 $url = new FASTPIXEL_Url(null, $post_url);
     139                $url = new FASTPIXEL_Url($post_url);
    140140            }
    141141            $data = [
     
    414414                }
    415415            }
    416             $url = new FASTPIXEL_Url(null, $url);
     416            $url = new FASTPIXEL_Url($url);
    417417            $dirs = explode(DIRECTORY_SEPARATOR, $url->get_url_path());
    418418            $path = $cache_dir;
     
    511511            return false;
    512512        }
     513
     514        public function esc_url($url) {
     515            if (function_exists('esc_url')) {
     516                return esc_url($url);
     517            }
     518            return $url;
     519        }
     520
     521        public function sanitize_text_field($field) {
     522            if (function_exists('sanitize_text_field')) {
     523                return sanitize_text_field($field);
     524            }
     525            return $field;
     526        }
    513527    }
    514528
  • fastpixel-website-accelerator/tags/1.0.23/inc/modules/endurance.php

    r3083183 r3086841  
    1515
    1616        public function init() {
    17             add_action('save_fastpixel_settings_config', [$this, 'save_fastpixel_config'], 10, 1);
     17            add_action('fastpixel/settings/config/save', [$this, 'save_fastpixel_config'], 10, 1);
    1818            //early init and api init only if module is enabled       
    1919            if ($this->enabled) {
     
    2424
    2525        public function api_init() {
    26             add_action('fastpixel_cache_files_saved', [$this, 'reset_page_cache'], 10, 1);
     26            add_action('fastpixel/cachefiles/saved', [$this, 'reset_page_cache'], 10, 1);
    2727        }
    2828
     
    7878                return;
    7979            }
    80             $url = new FASTPIXEL_Url(null, $input_url);
     80            $url = new FASTPIXEL_Url($input_url);
    8181            $url->add_query_param('epc_nocache');
    8282            return $url->get_url();
  • fastpixel-website-accelerator/tags/1.0.23/inc/modules/kinsta.php

    r3083183 r3086841  
    1818
    1919        public function init() {
    20             add_action('save_fastpixel_settings_config', [$this, 'save_fastpixel_config'], 10, 1);
     20            add_action('fastpixel/settings/config/save', [$this, 'save_fastpixel_config'], 10, 1);
    2121
    2222            //early init and api init only if module is enabled       
     
    2424                add_filter('fastpixel_cache_url_before_request', [$this, 'add_nocache_to_url'], 10, 1);
    2525                add_filter('fastpixel_request_purge_all', function ($request) { return false; }, 10, 1);
    26                 add_action('fastpixel_purge_all', [$this, 'purge_all'], 10);
     26                add_action('fastpixel/purge/all', [$this, 'purge_all'], 10);
    2727                add_action('admin_bar_menu', [$this, 'update_admin_bar_menu'], 101);
    2828
    29                 add_action('fastpixel_early_init', [$this, 'early_init'], 10);
     29                add_action('fastpixel/init/early', [$this, 'early_init'], 10);
    3030                add_action('rest_api_init', [$this, 'api_init'], 10);
    3131            }
     
    3434        public function api_init() {
    3535            add_filter('fastpixel_cache_url_before_request', [$this, 'add_nocache_to_url'], 10, 1);
    36             add_action('fastpixel_cache_files_saved', [$this, 'reset_page_cache'], 10, 1);
     36            add_action('fastpixel/cachefiles/saved', [$this, 'reset_page_cache'], 10, 1);
    3737        }
    3838
     
    4949                $kinsta_muplugin->kinsta_cache_purge->initiate_purge($post_id);
    5050            } else {
    51                 $input_url = new FASTPIXEL_Url(null, $cached_url);
    52                 $home_url  = new FASTPIXEL_Url(null, home_url());
     51                $input_url = new FASTPIXEL_Url($cached_url);
     52                $home_url  = new FASTPIXEL_Url(home_url());
    5353                $reset_url = preg_replace('/https?:\/\//i', '', $input_url->get_url());
    5454                if ($input_url->get_url() == $home_url->get_url()) {
     
    8080                return;
    8181            }
    82             $url = new FASTPIXEL_Url(null, $input_url);
     82            $url = new FASTPIXEL_Url($input_url);
    8383            $url->add_query_param('nocache');
    8484            return $url->get_url();
  • fastpixel-website-accelerator/tags/1.0.23/inc/rest-api.php

    r3083183 r3086841  
    5858            $is_exclusion = $excludes->check_is_exclusion($parameters['url']);
    5959            $cache_dir = $this->functions->get_cache_dir();
    60             $url = new FASTPIXEL_Url(false, $parameters['url']);
     60            $url = new FASTPIXEL_Url($parameters['url']);
    6161            if ($is_exclusion) {
    6262                //trying to delete existing files if page is exclusion and for some reason cached page exists
     
    112112            }
    113113
    114             do_action('fastpixel_cache_files_saved', $parameters['url']);
     114            do_action('fastpixel/cachefiles/saved', $parameters['url']);
    115115            return true;
    116116        }
  • fastpixel-website-accelerator/tags/1.0.23/inc/url.php

    r3083183 r3086841  
    140140        private $url_path;
    141141
    142         public function __construct($post_id = null, $url = null) {
    143             if (function_exists('get_permalink') && !empty($post_id)) {
    144                 $this->original_url = get_permalink($post_id);
     142        public function __construct($url = null) {
     143            if (is_int($url) && !empty($url) && function_exists('get_permalink')) {
     144                $this->original_url = get_permalink($url);
    145145                FASTPIXEL_DEBUG::log('Getting URL by $post_id', $this->original_url);
    146             } else if (!empty($url)) {
     146            } else if (is_string($url) && !empty($url) && filter_var($url, FILTER_VALIDATE_URL)) {
    147147                $this->original_url = $url;
    148148            } else {
     
    165165        protected function get_data_from_request()
    166166        {
    167             return \esc_url((isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] ? sanitize_text_field($_SERVER['HTTP_X_FORWARDED_PROTO']) : (isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] ? sanitize_text_field($_SERVER['REQUEST_SCHEME']) : (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http'))) . '://' . sanitize_text_field($_SERVER['HTTP_HOST']) . sanitize_text_field($_SERVER['REQUEST_URI']));
     167            $functions = FASTPIXEL_Functions::get_instance();
     168            return $functions->esc_url(
     169                (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] ? $functions->sanitize_text_field($_SERVER['HTTP_X_FORWARDED_PROTO']) :
     170                (isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] ? $functions->sanitize_text_field($_SERVER['REQUEST_SCHEME']) :
     171                (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http'))) . '://' . $functions->sanitize_text_field($_SERVER['HTTP_HOST']) . $functions->sanitize_text_field($_SERVER['REQUEST_URI']));
    168172        }
    169173        public function get_path()
     
    237241            return implode('&', $pairs);
    238242        }
    239 
    240         /*
    241          * function that escape url
    242          * based on wordpress default functions which are not accessible in advanced-cache.php
    243          * used only for secaping urls get from global $_SERVER
    244          */
    245         /*protected function esc_url($url) {
    246             $url = str_replace(' ', '%20', ltrim($url));
    247             $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url);
    248             if ('' === $url) {
    249                 return $url;
    250             }
    251 
    252             $strip = array('%0d', '%0a', '%0D', '%0A');
    253             $count = 1;
    254             while ($count) {
    255                 $url = str_replace($strip, '', $url, $count);
    256             }
    257 
    258             $url = str_replace(';//', '://', $url);
    259             if (
    260                 !$this->str_contains($url, ':') && !in_array($url[0], array('/', '#', '?'), true) &&
    261                 !preg_match('/^[a-z0-9-]+?\.php/i', $url)
    262             ) {
    263                 $url = 'http://' . $url;
    264             }
    265             if ($this->str_contains($url, '[') || $this->str_contains($url, ']')) {
    266                 /*
    267                  * can't use here wordpress native function wp_parse_url because this function fires early in advanced-cache.php
    268                  */
    269                 // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -- none available before WordPress is loaded.
    270                 /*$parsed = parse_url($url); //phpcs:ignore
    271                 $front = '';
    272                 if (isset($parsed['scheme'])) {
    273                     $front .= $parsed['scheme'] . '://';
    274                 } elseif ('/' === $url[0]) {
    275                     $front .= '//';
    276                 }
    277                 if (isset($parsed['user'])) {
    278                     $front .= $parsed['user'];
    279                 }
    280                 if (isset($parsed['pass'])) {
    281                     $front .= ':' . $parsed['pass'];
    282                 }
    283                 if (isset($parsed['user']) || isset($parsed['pass'])) {
    284                     $front .= '@';
    285                 }
    286                 if (isset($parsed['host'])) {
    287                     $front .= $parsed['host'];
    288                 }
    289                 if (isset($parsed['port'])) {
    290                     $front .= ':' . $parsed['port'];
    291                 }
    292                 $end_dirty = str_replace($front, '', $url);
    293                 $end_clean = str_replace(array('[', ']'), array('%5B', '%5D'), $end_dirty);
    294                 $url = str_replace($end_dirty, $end_clean, $url);
    295             }
    296             if ('/' === $url[0]) {
    297                 $good_protocol_url = $url;
    298             } else {
    299                 $allowed_protocols = array('http', 'https');
    300                 $url = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $url);
    301                 $url = preg_replace('/\\\\+0+/', '', $url);
    302                 // Short-circuit if the string starts with `https://` or `http://`. Most common cases.
    303                 if (
    304                     ($this->str_starts_with($url, 'https://') && in_array('https', $allowed_protocols, true)) ||
    305                     ($this->str_starts_with($url, 'http://') && in_array('http', $allowed_protocols, true))
    306                 ) {
    307                     $good_protocol_url = $url;
    308                 }
    309                 if (strtolower($good_protocol_url) !== strtolower($url)) {
    310                     return '';
    311                 }
    312             }
    313             return $good_protocol_url;
    314         }
    315 
    316         protected function str_contains($haystack, $needle) {
    317             if (function_exists('str_contains')) {
    318                 return str_contains($haystack, $needle);
    319             }
    320             return strpos($haystack, $needle) !== false;
    321         }
    322 
    323         protected function str_starts_with($haystack, $needle) {
    324             if (function_exists('str_starts_with')) {
    325                 return str_starts_with($haystack, $needle);
    326             }
    327             if ('' === $needle) {
    328                 return true;
    329             }
    330             return 0 === strpos($haystack, $needle);
    331         }*/
    332243    }
    333244}
  • fastpixel-website-accelerator/tags/1.0.23/readme.txt

    r3084429 r3086841  
    55Tested up to: 6.5
    66Requires PHP: 5.6
    7 Stable tag: 1.0.22
     7Stable tag: 1.0.23
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    141141== Changelog ==
    142142
     143= 1.0.23 =
     144Release date: May 15, 2024
     145* Bugfixes, added ability to serve cached page for logged in user
     146
    143147= 1.0.22 =
    144148Release date: May 8, 2024
  • fastpixel-website-accelerator/tags/1.0.23/vendor/composer/installed.php

    r3083363 r3086841  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '258ef55266a10bc93a17b3be690199a63248223b',
     6        'reference' => '04d640b2dbe51f82f5e430c8086521d5107a1bdd',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '258ef55266a10bc93a17b3be690199a63248223b',
     16            'reference' => '04d640b2dbe51f82f5e430c8086521d5107a1bdd',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
  • fastpixel-website-accelerator/trunk/README.md

    r3083363 r3086841  
    55Tested up to: 6.4
    66Requires PHP: 5.6
    7 Stable tag: 1.0.22
     7Stable tag: 1.0.23
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • fastpixel-website-accelerator/trunk/advanced-cache.php

    r3083183 r3086841  
    1414        $includes = [
    1515            'FASTPIXEL\FASTPIXEL_Debug'        => 'debug.php',
     16            'FASTPIXEL\FASTPIXEL_Functions'    => 'functions.php',
    1617            'FASTPIXEL\FASTPIXEL_Url'          => 'url.php',
    17             'FASTPIXEL\FASTPIXEL_Functions'    => 'functions.php',
    1818            'FASTPIXEL\FASTPIXEL_Config_Model' => 'config-model.php',
    1919            'FASTPIXEL\FASTPIXEL_Diag_Test'    => 'backend/models/diag.php',
  • fastpixel-website-accelerator/trunk/fastpixel.php

    r3083363 r3086841  
    55 * Description: Faster WordPress made easy - the latest technology to speed up your website, packaged in a 1-minute setup plugin.
    66 * Author:      ShortPixel
    7  * Version:     1.0.22
     7 * Version:     1.0.23
    88 * Text Domain: fastpixel-website-accelerator
    99 * Domain Path: /languages
     
    2121defined('ABSPATH') || exit;
    2222
    23 define('FASTPIXEL_VERSION', '1.0.22');
     23define('FASTPIXEL_VERSION', '1.0.23');
    2424define('FASTPIXEL_NAME', 'FastPixel');
    2525if (!defined('FASTPIXEL_PLUGIN_DIR'))
  • fastpixel-website-accelerator/trunk/inc/autoload.php

    r3083183 r3086841  
    99$includes = [
    1010    'FASTPIXEL\FASTPIXEL_Debug'        => 'debug.php',
     11    'FASTPIXEL\FASTPIXEL_Url'          => 'url.php',
    1112    'FASTPIXEL\FASTPIXEL_Functions'    => 'functions.php',
    12     'FASTPIXEL\FASTPIXEL_Url'          => 'url.php',
     13    'FASTPIXEL\FASTPIXEL_Config_Model' => 'config-model.php',
    1314    'FASTPIXEL\FASTPIXEL_Exclude'      => 'exclude-model.php',
    1415    'FASTPIXEL\FASTPIXEL_Excludes'     => 'excludes.php',
    15     'FASTPIXEL\FASTPIXEL_Config_Model' => 'config-model.php',
    1616    'FASTPIXEL\FASTPIXEL_Cache'        => 'cache.php',
    1717    'FASTPIXEL\FASTPIXEL_Plugin'       => 'plugin.php'
    1818];
    1919foreach ($includes as $class_name => $class_path) {
    20     if (!class_exists($class_name)) {
     20    if (!class_exists($class_name) && file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $class_path)) {
    2121        require_once FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $class_path;
    2222    }
     
    2525// // rest_api_init not called if permalinks set to 'Plain'
    2626add_action('rest_api_init', function () {
    27     require FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'rest-api.php';
     27    if (file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'rest-api.php')) {
     28        require FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'rest-api.php';
     29    }
    2830});
    2931//require backend functions
    30 require FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'autoload.php';
     32if (file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'autoload.php')) {
     33    require FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'autoload.php';
     34}
  • fastpixel-website-accelerator/trunk/inc/backend/autoload.php

    r3083183 r3086841  
    22defined('ABSPATH') || exit;
    33
    4 //include abstract models
    5 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/api-key.php';
    6 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/action.php';
    7 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/diag.php';
    8 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/ui-tab.php';
    9 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/ui.php';
     4//include models
     5$models = array(
     6    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/api-key.php',
     7    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/action.php',
     8    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/diag.php',
     9    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/ui-tab.php',
     10    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/ui.php',
     11   
     12    //include posts table model
     13    FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/posts-ui.php'
     14);
     15foreach($models as $model) {
     16    if (file_exists($model)) {
     17        include_once $model;
     18    }
     19}
    1020
    1121//include action models
     
    1323    while (false !== ($entry = readdir($handle))) {
    1424        if (!in_array($entry, ['.', '..'])) {
    15             include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/actions/' . $entry;
     25            try {
     26                include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/actions/' . $entry;
     27            } catch(Exception $e) {
     28                FASTPIXEL\FASTPIXEL_Debug::log('Error occure while including action model -> ' . $e->getMessage());
     29            }
    1630        }
    1731    }
    1832    closedir($handle);
    1933}
    20 //include posts table model
    21 include_once FASTPIXEL_PLUGIN_DIR . '/inc/backend/models/posts-ui.php';
    2234
    2335//include controllers
    24 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/functions.php';
    25 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/notices.php';
    26 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/controller.php';
    27 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/actions.php';
    28 //ui controllers
    29 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui-single.php';
    30 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui-multi.php';
    31 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui.php';
     36$controllers = array(
     37    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/functions.php',
     38    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/notices.php',
     39    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/controller.php',
     40    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/actions.php',
     41    //ui controllers
     42    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui-single.php',
     43    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui-multi.php',
     44    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/ui.php',
    3245
    33 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/cache.php';
    34 require FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/diag.php';
     46    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/cache.php',
     47    FASTPIXEL_PLUGIN_DIR . '/inc/backend/controllers/diag.php'
     48);
     49foreach ($controllers as $controller) {
     50    if (file_exists($controller)) {
     51        include_once $controller;
     52    }
     53}
  • fastpixel-website-accelerator/trunk/inc/backend/controllers/cache.php

    r3083363 r3086841  
    112112                $current_term = get_term($term_id);
    113113                if ($current_term->slug != $args['slug']) {
    114                     $url = new FASTPIXEL_Url(null, get_term_link($current_term));
     114                    $url = new FASTPIXEL_Url(get_term_link($current_term));
    115115                    $this->delete_url_cache($url);
    116116                }}, 10, 3);
     
    118118                FASTPIXEL_DEBUG::log('ACTION delete_term');
    119119                if (!empty($deleted_term)) {
    120                     $url = new FASTPIXEL_Url(null, get_term_link($deleted_term));
     120                    $url = new FASTPIXEL_Url(get_term_link($deleted_term));
    121121                    $this->delete_url_cache($url);
    122122                }
     
    129129                    $term->slug = $args['slug'];
    130130                }
    131                 $url = new FASTPIXEL_Url(null, get_term_link($term));
     131                $url = new FASTPIXEL_Url(get_term_link($term));
    132132                $this->functions->update_post_cache($url->get_url_path(), true);
    133133            }, 10, 3);
     
    149149                    if ($post->post_status == 'publish' && $data['post_status'] != 'trash') {
    150150                        //resetting/removing cache when post is "unpublished"
    151                         $url = new FASTPIXEL_Url($post_id);
     151                        $url = new FASTPIXEL_Url( (int)$post_id);
    152152                        $this->delete_url_cache($url);
    153153                    }
    154154                    //if post was published and still have publish status then we need to check slug, it can be changed too
    155155                    if ($post->post_status == 'publish' && $post->post_status == $data['post_status'] && $post->post_name != $data['post_name']) {
    156                         $url = new FASTPIXEL_Url($post_id);
     156                        $url = new FASTPIXEL_Url( (int)$post_id);
    157157                        $this->delete_url_cache($url);
    158158                    }
     
    160160                    if ($data['post_status'] == 'trash' && $post->post_status == 'publish') {
    161161                        $post->post_name = preg_replace('/__trashed/i', '', $post->post_name);
    162                         $url = new FASTPIXEL_Url(null, get_the_permalink($post));
     162                        $url = new FASTPIXEL_Url(get_the_permalink($post));
    163163                        $this->delete_url_cache($url);
    164164                    }
     
    171171                    //need to delete old cached slug
    172172                    FASTPIXEL_Debug::log('PRE_POST_UPDATE: Slug changed. Old post slug that should be removed', get_the_permalink($post));
    173                     $url = new FASTPIXEL_Url(null, get_the_permalink($post));
     173                    $url = new FASTPIXEL_Url(get_the_permalink($post));
    174174                    $this->delete_url_cache($url);
    175175                }
     
    178178                    //need to delete old cached slug
    179179                    FASTPIXEL_Debug::log('PRE_POST_UPDATE: Parent changed. Old post slug that should be removed', get_the_permalink($post));
    180                     $url = new FASTPIXEL_Url(null, get_the_permalink($post));
     180                    $url = new FASTPIXEL_Url(get_the_permalink($post));
    181181                    $this->delete_url_cache($url);
    182182                }
     
    229229            }
    230230
    231             $url = new FASTPIXEL_Url($post_id);
     231            $url = new FASTPIXEL_Url( (int)$post_id);
    232232            $path = untrailingslashit($url->get_url_path());
    233233            //need to check if request already was sent, because on post save much hooks are fired and each can trigger cache request
     
    290290                wp_cache_flush();
    291291            }
    292             do_action('fastpixel_purge_all');
     292            do_action('fastpixel/purge/all');
    293293            return true;
    294294        }
     
    358358                }
    359359            } else if ($post_id == 'homepage') {
    360                 $url = new FASTPIXEL_Url(null, get_home_url());
     360                $url = new FASTPIXEL_Url(get_home_url());
    361361                $path = untrailingslashit($url->get_url_path());
    362362                $this->functions->update_post_cache($path, true);
     
    451451                $permalink = get_permalink($post_id);
    452452            }
    453             $url = new FASTPIXEL_Url(null, $permalink);
     453            $url = new FASTPIXEL_Url($permalink);
    454454            if ($this->delete_url_cache($url)) {
    455455                $post_status = $this->be_functions->cache_status_display($url->get_url());
     
    481481                WP_Filesystem();
    482482            }
    483             $url = new FASTPIXEL_Url(null, get_home_url());
     483            $url = new FASTPIXEL_Url(get_home_url());
    484484            $path = untrailingslashit($url->get_url_path());
    485485            //need to check if request already was sent, because on post save much hooks are fired and each can trigger cache request
     
    531531                    // if blog page is set then it needs to be reset
    532532                    $blog_page_id = get_option('page_for_posts');
    533                     $blog_url = new FASTPIXEL_Url($blog_page_id);
     533                    $blog_url = new FASTPIXEL_Url( (int)$blog_page_id);
    534534                    $this->functions->update_post_cache($blog_url->get_url_path(), true);
    535535                }
     
    539539                    $archive_url = get_post_type_archive_link($post_type);
    540540                    if ($archive_url) {
    541                         $url = new FASTPIXEL_Url(null, $archive_url);
     541                        $url = new FASTPIXEL_Url($archive_url);
    542542                        $path = untrailingslashit($url->get_url_path());
    543543                        $this->functions->update_post_cache($path, true);
     
    561561                                $term_link = get_term_link($term);
    562562                                if (!empty($term_link)) {
    563                                     $url = new FASTPIXEL_Url(null, $term_link);
     563                                    $url = new FASTPIXEL_Url($term_link);
    564564                                    $path = untrailingslashit($url->get_url_path());
    565565                                    $this->functions->update_post_cache($path, true);
     
    607607                $url = get_the_permalink($post_id);
    608608            }
    609             $url = new FASTPIXEL_Url(null, $url);
     609            $url = new FASTPIXEL_Url($url);
    610610            if ($this->delete_url_cache($url)) {
    611611                /* translators: %1 should be a url*/
  • fastpixel-website-accelerator/trunk/inc/backend/controllers/tabs/settings.php

    r3083183 r3086841  
    4545                'fastpixel_settings_section'
    4646            );
    47             // add_settings_field(
    48             //     'fastpixel_display_cached_for_logged',
    49             //     esc_html__('Logged-in users', 'fastpixel-website-accelerator'),
    50             //     [$this, 'fastpixel_display_cached_for_logged_cb'],
    51             //     FASTPIXEL_TEXTDOMAIN,
    52             //     'fastpixel_settings_section'
    53             // );
     47            add_settings_field(
     48                'fastpixel_display_cached_for_logged',
     49                esc_html__('Logged-in users', 'fastpixel-website-accelerator'),
     50                [$this, 'fastpixel_display_cached_for_logged_cb'],
     51                FASTPIXEL_TEXTDOMAIN,
     52                'fastpixel_settings_section'
     53            );
    5454            add_settings_field(
    5555                'fastpixel_exclusions',
     
    144144                    //deleting existing cache files for excludes
    145145                    foreach($excludes as $exclude) {
    146                         $exclude_url = new FASTPIXEL_Url(null, $home_url . $exclude);
     146                        $exclude_url = new FASTPIXEL_Url($home_url . $exclude);
    147147                        if (!empty($exclude)) {
    148148                            $this->functions->delete_cached_files($exclude_url->get_url_path());
  • fastpixel-website-accelerator/trunk/inc/cache.php

    r3083363 r3086841  
    33
    44defined('ABSPATH') || exit;
    5 use FASTPIXEL\FASTPIXEL_Config_Model;
    65
    76if (!class_exists('FASTPIXEL\FASTPIXEL_Cache')) {
     
    4544        public function __construct() {
    4645            self::$instance  = $this;
     46            //checking for classes to avoid breakdown
     47            if (!class_exists('FASTPIXEL\FASTPIXEL_Debug') || !class_exists('FASTPIXEL\FASTPIXEL_Url') ||
     48                !class_exists('FASTPIXEL\FASTPIXEL_Functions') || !class_exists('FASTPIXEL\FASTPIXEL_Config_Model')) {
     49                return false;
     50            }
    4751            $this->functions = FASTPIXEL_Functions::get_instance();
    4852            $this->config    = FASTPIXEL_Config_Model::get_instance();
     
    5963                define('FASTPIXEL_API_URL', FASTPIXEL_API_HOST . '/api/v1/enqueue');
    6064            }
    61             do_action('fastpixel_early_init');
    62 
    63             //moving initialization to mu_plugin_loaded because we need sanitization and escaping function initialized
    64             add_action('mu_plugin_loaded', [$this, 'init']);
     65            do_action('fastpixel/init/early');
     66
     67            //running initialization to check for cached page and return it early if exists
     68            $this->init();
    6569        }
    6670
    6771        public function init() {
    68             if (!$this->check_request_agent()) {
    69                 return;
    70             }
    71             if (!$this->check_request()) {
    72                 return;
    73             }
    74 
     72            //initializing url
     73            $this->url = new FASTPIXEL_Url();
    7574            $this->cache_dir = $this->functions->get_cache_dir();
    76             $this->url = new FASTPIXEL_Url();
    7775            $this->url_path = $this->url->get_url_path();
    7876            $this->html_path = $this->cache_dir . DIRECTORY_SEPARATOR . $this->url_path . 'index.html';
     
    8179            $this->meta_path = $this->cache_dir . DIRECTORY_SEPARATOR . $this->url_path . 'meta';
    8280
    83             //if no cache files exists registering function for cache request
     81            if (!$this->check_request_agent()) {
     82                return;
     83            }
     84            if (!$this->check_request()) {
     85                return;
     86            }
     87
     88            //registering function for cache request
    8489            register_shutdown_function([$this, 'request_page_cache']);
    8590
     91            //returning cached file if it exists
    8692            $this->return_cached_if_exists();
    8793        }
     
    125131            */
    126132            if (isset($_SERVER['HTTP_USER_AGENT']) && !empty($_SERVER['HTTP_USER_AGENT']) &&
    127             (strpos(sanitize_text_field($_SERVER['HTTP_USER_AGENT']), 'FastPixel') !== false)
     133            (strpos($this->functions->sanitize_text_field($_SERVER['HTTP_USER_AGENT']), 'FastPixel') !== false)
    128134            ) {
    129135                //need to check if this is required
     
    138144            */
    139145            if (isset($_SERVER['QUERY_STRING']) &&
    140                 strpos(sanitize_text_field($_SERVER['QUERY_STRING']), 'fastpixeldebug') !== false) {
     146                strpos($this->functions->sanitize_text_field($_SERVER['QUERY_STRING']), 'fastpixeldebug') !== false) {
    141147                $this->debug_mode = true;
    142148            }
     
    144150            * Don't ever cache non-GET requests.
    145151            */
    146             if (!isset($_SERVER['REQUEST_METHOD']) || 'GET' !== sanitize_text_field($_SERVER['REQUEST_METHOD'])) {
     152            if (!isset($_SERVER['REQUEST_METHOD']) || 'GET' !== $this->functions->sanitize_text_field($_SERVER['REQUEST_METHOD'])) {
    147153                FASTPIXEL_DEBUG::log('CHECKING REQUEST: Not GET request, stopped');
    148154                return false;
     
    155161                defined('DOING_AJAX') ||
    156162                (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
    157                 strtolower(sanitize_text_field($_SERVER['HTTP_X_REQUESTED_WITH'])) == 'xmlhttprequest')
     163                strtolower($this->functions->sanitize_text_field($_SERVER['HTTP_X_REQUESTED_WITH'])) == 'xmlhttprequest')
    158164            ) {
    159165                return false;
     
    162168            * getting request url
    163169            */
    164             $requested_url = new FASTPIXEL_Url();
     170            $requested_url = $this->url;
    165171            /**
    166172            * no need to activate class on api request
     
    173179            * run only for index.php
    174180            */
    175             if (!in_array(sanitize_text_field($_SERVER['SCRIPT_NAME']), ['/index.php'])) {
     181            if (!in_array($this->functions->sanitize_text_field($_SERVER['SCRIPT_NAME']), ['/index.php'])) {
    176182                return false;
    177183            }
     
    204210            * don't cache request with nocache query
    205211            */
    206             if(isset($_SERVER['QUERY_STRING']) && strpos(sanitize_text_field($_SERVER['QUERY_STRING']), 'fastpixeldisable') !== false) {
     212            if(isset($_SERVER['QUERY_STRING']) && strpos($this->functions->sanitize_text_field($_SERVER['QUERY_STRING']), 'fastpixeldisable') !== false) {
    207213                return false;
    208214            }
     
    380386            }
    381387
     388            //extra check if file is inside cache folder
     389            if (strpos(realpath($path), realpath($this->functions->get_cache_dir())) !== 0) {
     390                return false;
     391            }
     392
    382393            if (@file_exists($path) && @is_readable($path)) {
    383394                $modified_time = (int) @filemtime($path);
     
    417428                    }
    418429                }
    419                 /*
    420                 * displaying .html file, generated by our service
    421                 * no need to escape output, escape functions are not available in advanced-cache.php
    422                 */
    423                 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- direct file output to the browser.
    424                 readfile($path); // phpcs:ignore
    425                 echo '<!-- Optimized and served by FastPixel.io -->';
    426                 define('FASTPIXEL_STOP_REQUEST', true);
    427                 @ob_end_flush();
    428                 flush();
    429                 exit();
     430                if ($this->config->get_option('fastpixel_display_cached_for_logged') && $this->check_is_logged_in()) {
     431                     //registering hook that will display cached page before page rendering should begin
     432                    add_action('template_redirect', [$this, 'display_cached_for_logged'], 999);
     433                } else {
     434                    /*
     435                     * displaying .html file, generated by our service
     436                     * no need to escape output, escape functions are not available in advanced-cache.php
     437                     */
     438                    // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- direct file output to the browser.
     439                    readfile($path); // phpcs:ignore
     440                    echo '<!-- Optimized and served by FastPixel.io -->';
     441                    define('FASTPIXEL_STOP_REQUEST', true);
     442                    @ob_end_flush();
     443                    flush();
     444                    exit();
     445                }
    430446            }
    431447        }
     
    592608                $request_path = $this->url->get_url_path();
    593609            } else if (isset($post_id) && !is_null($post_id) && !empty($post_id)) {
    594                 $url = new FASTPIXEL_Url($post_id);
     610                $url = new FASTPIXEL_Url( (int)$post_id);
    595611                $request_url = $url->get_url();
    596612                $request_path = $url->get_url_path();
    597613            } else if (isset($post->ID) && !empty($post->ID)) {
    598                 $url = new FASTPIXEL_Url($post->ID);
     614                $url = new FASTPIXEL_Url( (int)$post->ID);
    599615                $request_url = $url->get_url();
    600616                $request_path = $url->get_url_path();
     
    630646                return false;
    631647            }
    632             $diag = FASTPIXEL_Diag::get_instance();
    633             if (!$diag->run_activation_tests()) {
    634                 FASTPIXEL_Debug::log('Common Validation: Stopped. Diagnostics errors');
    635                 return false;
     648            if (class_exists('FASTPIXEL_Diag')) {
     649                $diag = FASTPIXEL_Diag::get_instance();
     650                if (!$diag->run_activation_tests()) {
     651                    FASTPIXEL_Debug::log('Common Validation: Stopped. Diagnostics errors');
     652                    return false;
     653                }
    636654            }
    637655            return true;
     
    642660                return false;
    643661            }
    644             $url = new FASTPIXEL_Url(null, $input_url);
     662            $url = new FASTPIXEL_Url($input_url);
    645663            //check for pages that should be excluded from cache
    646664            $excludes = FASTPIXEL_Excludes::get_instance();
     
    716734            if (!preg_match('/^'.$compare_rest_url_domain.'/i', $compare_reset_url_domain)) {
    717735                FASTPIXEL_DEBUG::log('CACHE REQUEST Error: $reset_url not match FASTPIXEL_REST_URL, request stopped');
     736                FASTPIXEL_DEBUG::log('CACHE REQUEST Error: '.var_export($compare_rest_url_domain, true) . ', '.var_export($compare_reset_url_domain, true), ', '.var_export(FASTPIXEL_REST_URL, true));
    718737                return false;
    719738            }
     
    943962        public function load_modules()
    944963        {
    945             if (!class_exists('FASTPIXEL\FASTPIXEL_Module')) {
     964            //checking if file exists before loading
     965            if (!class_exists('FASTPIXEL\FASTPIXEL_Module')
     966                && file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'module.php')) {
    946967                include_once FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'module.php';
    947             }
    948             if (file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'modules')) {
     968            } else {
     969                return false;
     970            }
     971            //including modules
     972            if (class_exists('FASTPIXEL\FASTPIXEL_Module') && file_exists(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'modules')) {
    949973                if ($handle = opendir(FASTPIXEL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'modules')) {
    950974                    while (false !== ($entry = readdir($handle))) {
     
    961985            }
    962986        }
     987
     988        public function display_cached_for_logged() {
     989            global $wp_styles, $wp_scripts;
     990            ob_start();
     991            $post_id = get_the_ID();
     992            do_action('fastpixel/loggeduser/adminbar/beforerender', $post_id);
     993            foreach ($wp_styles->queue as $handle) {
     994                wp_print_styles($handle);
     995            }
     996            foreach ($wp_scripts->queue as $handle) {
     997                wp_print_scripts($handle);
     998            }
     999            wp_admin_bar_render();
     1000            do_action('fastpixel/loggeduser/adminbar/afterrender', $post_id);
     1001            $admin_bar_output = ob_get_clean();
     1002            ob_start(function ($buffer) use ($admin_bar_output) {
     1003                $regex = '/<\s*\/\s*body/s';
     1004                $buffer = preg_replace($regex, $admin_bar_output . '</body', $buffer);
     1005                return $buffer;
     1006            });
     1007            /*
     1008             * displaying .html file, generated by our service
     1009             * no need to escape output, escape functions are not available in advanced-cache.php
     1010             */
     1011            // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- direct file output to the browser.
     1012            if (@file_exists($this->html_path) && @is_readable($this->html_path)) {
     1013                readfile($this->html_path); // phpcs:ignore
     1014            }
     1015            ob_get_flush();
     1016            exit;
     1017        }
    9631018    }
    9641019    new FASTPIXEL_Cache();
  • fastpixel-website-accelerator/trunk/inc/config-model.php

    r3083183 r3086841  
    5858
    5959        public function save_file() {
    60             do_action('save_fastpixel_settings_config', $this);
     60            do_action('fastpixel/settings/config/save', $this);
    6161            if (!file_exists($this->config_dir)) {
    6262                wp_mkdir_p($this->config_dir);
  • fastpixel-website-accelerator/trunk/inc/excludes.php

    r3083183 r3086841  
    4343                return false;
    4444            }
    45             $url = new FASTPIXEL_Url(null, $url);
     45            $url = new FASTPIXEL_Url($url);
    4646            foreach ($this->tests as $test) {
    4747                $test_result = $test->check_is_exclusion($url);
  • fastpixel-website-accelerator/trunk/inc/functions.php

    r3083183 r3086841  
    137137                return false;
    138138            } else {
    139                 $url = new FASTPIXEL_Url(null, $post_url);
     139                $url = new FASTPIXEL_Url($post_url);
    140140            }
    141141            $data = [
     
    414414                }
    415415            }
    416             $url = new FASTPIXEL_Url(null, $url);
     416            $url = new FASTPIXEL_Url($url);
    417417            $dirs = explode(DIRECTORY_SEPARATOR, $url->get_url_path());
    418418            $path = $cache_dir;
     
    511511            return false;
    512512        }
     513
     514        public function esc_url($url) {
     515            if (function_exists('esc_url')) {
     516                return esc_url($url);
     517            }
     518            return $url;
     519        }
     520
     521        public function sanitize_text_field($field) {
     522            if (function_exists('sanitize_text_field')) {
     523                return sanitize_text_field($field);
     524            }
     525            return $field;
     526        }
    513527    }
    514528
  • fastpixel-website-accelerator/trunk/inc/modules/endurance.php

    r3083183 r3086841  
    1515
    1616        public function init() {
    17             add_action('save_fastpixel_settings_config', [$this, 'save_fastpixel_config'], 10, 1);
     17            add_action('fastpixel/settings/config/save', [$this, 'save_fastpixel_config'], 10, 1);
    1818            //early init and api init only if module is enabled       
    1919            if ($this->enabled) {
     
    2424
    2525        public function api_init() {
    26             add_action('fastpixel_cache_files_saved', [$this, 'reset_page_cache'], 10, 1);
     26            add_action('fastpixel/cachefiles/saved', [$this, 'reset_page_cache'], 10, 1);
    2727        }
    2828
     
    7878                return;
    7979            }
    80             $url = new FASTPIXEL_Url(null, $input_url);
     80            $url = new FASTPIXEL_Url($input_url);
    8181            $url->add_query_param('epc_nocache');
    8282            return $url->get_url();
  • fastpixel-website-accelerator/trunk/inc/modules/kinsta.php

    r3083183 r3086841  
    1818
    1919        public function init() {
    20             add_action('save_fastpixel_settings_config', [$this, 'save_fastpixel_config'], 10, 1);
     20            add_action('fastpixel/settings/config/save', [$this, 'save_fastpixel_config'], 10, 1);
    2121
    2222            //early init and api init only if module is enabled       
     
    2424                add_filter('fastpixel_cache_url_before_request', [$this, 'add_nocache_to_url'], 10, 1);
    2525                add_filter('fastpixel_request_purge_all', function ($request) { return false; }, 10, 1);
    26                 add_action('fastpixel_purge_all', [$this, 'purge_all'], 10);
     26                add_action('fastpixel/purge/all', [$this, 'purge_all'], 10);
    2727                add_action('admin_bar_menu', [$this, 'update_admin_bar_menu'], 101);
    2828
    29                 add_action('fastpixel_early_init', [$this, 'early_init'], 10);
     29                add_action('fastpixel/init/early', [$this, 'early_init'], 10);
    3030                add_action('rest_api_init', [$this, 'api_init'], 10);
    3131            }
     
    3434        public function api_init() {
    3535            add_filter('fastpixel_cache_url_before_request', [$this, 'add_nocache_to_url'], 10, 1);
    36             add_action('fastpixel_cache_files_saved', [$this, 'reset_page_cache'], 10, 1);
     36            add_action('fastpixel/cachefiles/saved', [$this, 'reset_page_cache'], 10, 1);
    3737        }
    3838
     
    4949                $kinsta_muplugin->kinsta_cache_purge->initiate_purge($post_id);
    5050            } else {
    51                 $input_url = new FASTPIXEL_Url(null, $cached_url);
    52                 $home_url  = new FASTPIXEL_Url(null, home_url());
     51                $input_url = new FASTPIXEL_Url($cached_url);
     52                $home_url  = new FASTPIXEL_Url(home_url());
    5353                $reset_url = preg_replace('/https?:\/\//i', '', $input_url->get_url());
    5454                if ($input_url->get_url() == $home_url->get_url()) {
     
    8080                return;
    8181            }
    82             $url = new FASTPIXEL_Url(null, $input_url);
     82            $url = new FASTPIXEL_Url($input_url);
    8383            $url->add_query_param('nocache');
    8484            return $url->get_url();
  • fastpixel-website-accelerator/trunk/inc/rest-api.php

    r3083183 r3086841  
    5858            $is_exclusion = $excludes->check_is_exclusion($parameters['url']);
    5959            $cache_dir = $this->functions->get_cache_dir();
    60             $url = new FASTPIXEL_Url(false, $parameters['url']);
     60            $url = new FASTPIXEL_Url($parameters['url']);
    6161            if ($is_exclusion) {
    6262                //trying to delete existing files if page is exclusion and for some reason cached page exists
     
    112112            }
    113113
    114             do_action('fastpixel_cache_files_saved', $parameters['url']);
     114            do_action('fastpixel/cachefiles/saved', $parameters['url']);
    115115            return true;
    116116        }
  • fastpixel-website-accelerator/trunk/inc/url.php

    r3083183 r3086841  
    140140        private $url_path;
    141141
    142         public function __construct($post_id = null, $url = null) {
    143             if (function_exists('get_permalink') && !empty($post_id)) {
    144                 $this->original_url = get_permalink($post_id);
     142        public function __construct($url = null) {
     143            if (is_int($url) && !empty($url) && function_exists('get_permalink')) {
     144                $this->original_url = get_permalink($url);
    145145                FASTPIXEL_DEBUG::log('Getting URL by $post_id', $this->original_url);
    146             } else if (!empty($url)) {
     146            } else if (is_string($url) && !empty($url) && filter_var($url, FILTER_VALIDATE_URL)) {
    147147                $this->original_url = $url;
    148148            } else {
     
    165165        protected function get_data_from_request()
    166166        {
    167             return \esc_url((isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] ? sanitize_text_field($_SERVER['HTTP_X_FORWARDED_PROTO']) : (isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] ? sanitize_text_field($_SERVER['REQUEST_SCHEME']) : (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http'))) . '://' . sanitize_text_field($_SERVER['HTTP_HOST']) . sanitize_text_field($_SERVER['REQUEST_URI']));
     167            $functions = FASTPIXEL_Functions::get_instance();
     168            return $functions->esc_url(
     169                (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] ? $functions->sanitize_text_field($_SERVER['HTTP_X_FORWARDED_PROTO']) :
     170                (isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] ? $functions->sanitize_text_field($_SERVER['REQUEST_SCHEME']) :
     171                (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http'))) . '://' . $functions->sanitize_text_field($_SERVER['HTTP_HOST']) . $functions->sanitize_text_field($_SERVER['REQUEST_URI']));
    168172        }
    169173        public function get_path()
     
    237241            return implode('&', $pairs);
    238242        }
    239 
    240         /*
    241          * function that escape url
    242          * based on wordpress default functions which are not accessible in advanced-cache.php
    243          * used only for secaping urls get from global $_SERVER
    244          */
    245         /*protected function esc_url($url) {
    246             $url = str_replace(' ', '%20', ltrim($url));
    247             $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url);
    248             if ('' === $url) {
    249                 return $url;
    250             }
    251 
    252             $strip = array('%0d', '%0a', '%0D', '%0A');
    253             $count = 1;
    254             while ($count) {
    255                 $url = str_replace($strip, '', $url, $count);
    256             }
    257 
    258             $url = str_replace(';//', '://', $url);
    259             if (
    260                 !$this->str_contains($url, ':') && !in_array($url[0], array('/', '#', '?'), true) &&
    261                 !preg_match('/^[a-z0-9-]+?\.php/i', $url)
    262             ) {
    263                 $url = 'http://' . $url;
    264             }
    265             if ($this->str_contains($url, '[') || $this->str_contains($url, ']')) {
    266                 /*
    267                  * can't use here wordpress native function wp_parse_url because this function fires early in advanced-cache.php
    268                  */
    269                 // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -- none available before WordPress is loaded.
    270                 /*$parsed = parse_url($url); //phpcs:ignore
    271                 $front = '';
    272                 if (isset($parsed['scheme'])) {
    273                     $front .= $parsed['scheme'] . '://';
    274                 } elseif ('/' === $url[0]) {
    275                     $front .= '//';
    276                 }
    277                 if (isset($parsed['user'])) {
    278                     $front .= $parsed['user'];
    279                 }
    280                 if (isset($parsed['pass'])) {
    281                     $front .= ':' . $parsed['pass'];
    282                 }
    283                 if (isset($parsed['user']) || isset($parsed['pass'])) {
    284                     $front .= '@';
    285                 }
    286                 if (isset($parsed['host'])) {
    287                     $front .= $parsed['host'];
    288                 }
    289                 if (isset($parsed['port'])) {
    290                     $front .= ':' . $parsed['port'];
    291                 }
    292                 $end_dirty = str_replace($front, '', $url);
    293                 $end_clean = str_replace(array('[', ']'), array('%5B', '%5D'), $end_dirty);
    294                 $url = str_replace($end_dirty, $end_clean, $url);
    295             }
    296             if ('/' === $url[0]) {
    297                 $good_protocol_url = $url;
    298             } else {
    299                 $allowed_protocols = array('http', 'https');
    300                 $url = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $url);
    301                 $url = preg_replace('/\\\\+0+/', '', $url);
    302                 // Short-circuit if the string starts with `https://` or `http://`. Most common cases.
    303                 if (
    304                     ($this->str_starts_with($url, 'https://') && in_array('https', $allowed_protocols, true)) ||
    305                     ($this->str_starts_with($url, 'http://') && in_array('http', $allowed_protocols, true))
    306                 ) {
    307                     $good_protocol_url = $url;
    308                 }
    309                 if (strtolower($good_protocol_url) !== strtolower($url)) {
    310                     return '';
    311                 }
    312             }
    313             return $good_protocol_url;
    314         }
    315 
    316         protected function str_contains($haystack, $needle) {
    317             if (function_exists('str_contains')) {
    318                 return str_contains($haystack, $needle);
    319             }
    320             return strpos($haystack, $needle) !== false;
    321         }
    322 
    323         protected function str_starts_with($haystack, $needle) {
    324             if (function_exists('str_starts_with')) {
    325                 return str_starts_with($haystack, $needle);
    326             }
    327             if ('' === $needle) {
    328                 return true;
    329             }
    330             return 0 === strpos($haystack, $needle);
    331         }*/
    332243    }
    333244}
  • fastpixel-website-accelerator/trunk/readme.txt

    r3084429 r3086841  
    55Tested up to: 6.5
    66Requires PHP: 5.6
    7 Stable tag: 1.0.22
     7Stable tag: 1.0.23
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    141141== Changelog ==
    142142
     143= 1.0.23 =
     144Release date: May 15, 2024
     145* Bugfixes, added ability to serve cached page for logged in user
     146
    143147= 1.0.22 =
    144148Release date: May 8, 2024
  • fastpixel-website-accelerator/trunk/vendor/composer/installed.php

    r3083363 r3086841  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '258ef55266a10bc93a17b3be690199a63248223b',
     6        'reference' => '04d640b2dbe51f82f5e430c8086521d5107a1bdd',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '258ef55266a10bc93a17b3be690199a63248223b',
     16            'reference' => '04d640b2dbe51f82f5e430c8086521d5107a1bdd',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.