Plugin Directory

Changeset 3435242


Ignore:
Timestamp:
01/08/2026 03:23:08 PM (3 months ago)
Author:
Lugat
Message:

Fixed logic of php cache fallback resolver

Location:
jinx-fast-cache/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • jinx-fast-cache/trunk/index.php

    r3435089 r3435242  
    55   * Plugin URI: https://wordpress.org/plugins/jixn-fast-cache/
    66   * Description: Blazing fast full-page caching for WordPress. Jinx Fast-Cache serves static HTML files, bypassing PHP and database overhead entirely.
    7    * Version: 0.9.1
     7   * Version: 0.9.2
    88   * Author: Jinx Digital <hello@jinx-digital.com>
    99   * Author URI: http://jinx-digital.com
  • jinx-fast-cache/trunk/readme.txt

    r3435089 r3435242  
    135135`do_action('jinx_fast_cache', ['ttl' => 3600, 'tags' => ['foo', 'bar']]);`
    136136
     137
    137138== Roadmap ==
    138139
  • jinx-fast-cache/trunk/src/Front.php

    r3435089 r3435242  
    2222
    2323      if (apply_filters('jinx_fast_cache_active', false)) {
    24        
     24
    2525        $files = Helper::getCacheFiles(Helper::getUrl());
    2626        if (file_exists($files['html'])) {
     
    4242     
    4343      add_action('template_redirect', [__CLASS__, 'capture'], PHP_INT_MAX);
    44      
    45       add_filter('jinx_fast_cache_active', function($cache) {
    46 
    47         if ($cache === true) {
    48          
    49           $disabled = null;
    50          
    51           // disable caching if
    52           // * in maintenance mode
    53           // * admin bar is showing
    54           // * is preview
    55           // * is user logged in
    56           if (wp_is_maintenance_mode() || is_admin_bar_showing() || is_preview()) {
    57             $disabled = true;
    58           } elseif (is_user_logged_in()) {
    59             $disabled = apply_filters('jinx_fast_cache_ignore_logged_in_users', true);
    60           } elseif (is_404()) {
    61             $disabled = apply_filters('jinx_fast_cache_ignore_404', true);
    62           } else {
    63          
    64             $metaKey = Helper::getDisabledMetaKey();
    65 
    66             $object = get_queried_object();
    67 
    68             if (is_a($object, 'WP_Post')) {
    69 
    70               $postTypes = Helper::getPostTypes();
    71 
    72               if (in_array($object->post_type, $postTypes)) {
    73                 $disabled = (bool) get_post_meta($object->ID, $metaKey, true);
    74               } else {
    75                 $disabled = true;
    76               }
    77 
    78             } elseif (is_a($object, 'WP_Term')) {
    79 
    80               $taxonomies = Helper::getTaxonomies();
    81 
    82               if (in_array($object->taxonomy, $taxonomies)) {
    83                 $disabled = (bool) get_term_meta($object->term_id, $metaKey, true);
    84               } else {
    85                 $disabled = true;
    86               }
    87              
    88             }
    89          
    90           }
    91          
    92           if (is_bool($disabled)) {   
    93             return !$disabled;
    94           }
    95          
    96         }
    97 
    98         return $cache;
    99 
    100       }, PHP_INT_MAX);
    10144     
    10245      // enqueue inject script only if injects exist
     
    11255        }
    11356             
    114       }, PHP_INT_MIN); 
     57      }, PHP_INT_MIN);
    11558     
    11659      add_action('wp_ajax_jinx-fast-cache-inject', [__CLASS__, 'ajaxInject']);
  • jinx-fast-cache/trunk/src/Helper.php

    r3434586 r3435242  
    212212    {
    213213     
    214         $host = $_SERVER['HTTP_HOST'] ?? '';
    215         $requestUri = $_SERVER['REQUEST_URI'] ?? '';
    216 
    217         $scriptDirectory = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
    218 
    219         if ($scriptDirectory !== '/' && strpos($requestUri, $scriptDirectory) === 0) {
    220           $path = substr($requestUri, strlen($scriptDirectory));
    221         } else {
    222           $path = $requestUri;
    223         }
    224 
    225         return rtrim(preg_replace('#/+#', '/', $host.'/'.$path), '/').'/';
     214      $host = $_SERVER['HTTP_HOST'] ?? '';
     215      $requestUri = $_SERVER['REQUEST_URI'] ?? '';
     216
     217      $uriParts = explode('?', $requestUri);
     218      $path = $uriParts[0];
     219      $queryString = isset($uriParts[1]) ? '?'.$uriParts[1] : '';
     220
     221      $scriptPath = str_replace('\\', '/', $_SERVER['SCRIPT_NAME']);
     222      $baseDir = str_replace('\\', '/', dirname($scriptPath));
     223
     224      if ($baseDir !== '/' && $baseDir !== '.' && strpos($path, $baseDir) === 0) {
     225        $path = substr($path, strlen($baseDir));
     226      }
     227
     228      return rtrim(preg_replace('#/+#', '/', $host.'/'.ltrim($path, '/')), '/').$queryString;
     229
    226230    }
    227231   
  • jinx-fast-cache/trunk/src/Plugin.php

    r3434586 r3435242  
    3636    public static function bootstrap()
    3737    {
    38        
     38
    3939      add_filter('jinx_fast_cache_active', function($active) {
    4040        return (bool) Settings::getOption('active', $active);
     
    8484        return array_diff($queryParams, Settings::getOption('ignore_query_params', []));
    8585      }, 0);
     86
     87      add_filter('jinx_fast_cache_active', function($cache) {
     88
     89        if ($cache === true) {
     90         
     91          $disabled = null;
     92         
     93          // disable caching if
     94          // * in maintenance mode
     95          // * admin bar is showing
     96          // * is preview
     97          // * is user logged in
     98          if (wp_is_maintenance_mode() || is_admin_bar_showing() || is_preview()) {
     99            $disabled = true;
     100          } elseif (is_user_logged_in()) {
     101            $disabled = apply_filters('jinx_fast_cache_ignore_logged_in_users', true);
     102          } elseif (is_404()) {
     103            $disabled = apply_filters('jinx_fast_cache_ignore_404', true);
     104          } else {
     105         
     106            $metaKey = Helper::getDisabledMetaKey();
     107
     108            $object = get_queried_object();
     109
     110            if (is_a($object, 'WP_Post')) {
     111
     112              $postTypes = Helper::getPostTypes();
     113
     114              if (in_array($object->post_type, $postTypes)) {
     115                $disabled = (bool) get_post_meta($object->ID, $metaKey, true);
     116              } else {
     117                $disabled = true;
     118              }
     119
     120            } elseif (is_a($object, 'WP_Term')) {
     121
     122              $taxonomies = Helper::getTaxonomies();
     123
     124              if (in_array($object->taxonomy, $taxonomies)) {
     125                $disabled = (bool) get_term_meta($object->term_id, $metaKey, true);
     126              } else {
     127                $disabled = true;
     128              }
     129             
     130            }
     131         
     132          }
     133         
     134          if (is_bool($disabled)) {   
     135            return !$disabled;
     136          }
     137         
     138        }
     139
     140        return $cache;
     141
     142      }, PHP_INT_MAX); 
    86143
    87144    }
  • jinx-fast-cache/trunk/src/Url.php

    r3434620 r3435242  
    191191    {
    192192
    193       $host = parse_url($url, PHP_URL_HOST);
    194       $port = parse_url($url, PHP_URL_PORT);
    195       $fullHost = $host . ($port ? ':' . $port : '');
    196 
    197       $path = parse_url($url, PHP_URL_PATH) ?: '';
    198 
    199       $basePath = parse_url(site_url(), PHP_URL_PATH) ?: '';
     193      $parts = parse_url($url);
     194      $host = $parts['host'] ?? '';
     195
     196      $port = isset($parts['port']) ? ':'.$parts['port'] : '';
     197      $path = $parts['path'] ?? '';
     198
     199      $basePath = '';
     200      if (function_exists('site_url')) {
     201          $basePath = parse_url(site_url(), PHP_URL_PATH) ?: '';
     202      }
    200203      $basePath = trim($basePath, '/');
    201204
    202205      if (!empty($basePath)) {
    203           $path = preg_replace('#^/?' . preg_quote($basePath, '#') . '/?#i', '/', $path);
    204       }
    205 
    206       if (!empty($fullHost)) {
    207           $url = $fullHost . '/' . $path;
    208       } else {
    209           $url = $path;
    210       }
    211 
    212       $url = preg_replace('#/+#', '/', $url);
    213 
    214       return trim($url, '/').'/';
    215 
     206          $pattern = '#^/?'.preg_quote($basePath, '#').'(?=/|$)#i';
     207          $path = preg_replace($pattern, '', $path);
     208      }
     209
     210      return trim(preg_replace('#/+#', '/', $host.$port.'/'.$path), '/');
    216211     
    217212    }
Note: See TracChangeset for help on using the changeset viewer.