plugins.trac.wordpress.org

Changeset 1877792 – WordPress Plugin Repository

  • ️Sun Jan 08 2017
  • simple-cache/trunk/README.md

    r1388942 r1877792  
    1 Simple Cache
     1Simple Cache [![Build Status](https://travis-ci.org/tlovett1/simple-cache.svg?branch=master)](https://travis-ci.org/tlovett1/simple-cache)
    22===============
    33
  • simple-cache/trunk/assets/js/settings.min.js

    r1396118 r1877792  
    1 !function(e){var a=e(document.getElementById("sc_enable_in_memory_object_caching")),s=document.querySelectorAll(".in-memory-cache");a.on("change",function(e){"1"===e.target.value?(s[0].className=s[0].className.replace(/show/i,"")+" show",s[1].className=s[1].className.replace(/show/i,"")+" show"):(s[0].className=s[0].className.replace(/show/i,""),s[1].className=s[1].className.replace(/show/i,""))});var c=e(document.getElementById("sc_advanced_mode")),l=document.querySelectorAll(".sc-advanced-mode-table")[0],d=document.querySelectorAll(".sc-simple-mode-table")[0],m=document.getElementById("sc_enable_page_caching_simple"),n=document.getElementById("sc_enable_page_caching_advanced"),t=document.getElementById("sc_page_cache_length_simple"),o=document.getElementById("sc_page_cache_length_advanced"),i=document.getElementById("sc_enable_gzip_compression_simple"),_=document.getElementById("sc_enable_gzip_compression_advanced");c.on("change",function(e){"1"===e.target.value?(l.className=l.className.replace(/show/i,"")+" show",d.className=d.className.replace(/show/i,""),m.disabled=!0,n.disabled=!1,t.disabled=!0,o.disabled=!1,i&&(i.disabled=!0,_.disabled=!1)):(d.className=d.className.replace(/show/i,"")+" show",l.className=l.className.replace(/show/i,""),m.disabled=!1,n.disabled=!0,t.disabled=!1,o.disabled=!0,i&&(i.disabled=!1,_.disabled=!0))})}(jQuery);
     1!function(e){var a=e(document.getElementById("sc_enable_in_memory_object_caching")),c=document.querySelectorAll(".in-memory-cache");a.on("change",function(e){"1"===e.target.value?(c[0].className=c[0].className.replace(/show/i,"")+" show",c[1].className=c[1].className.replace(/show/i,"")+" show"):(c[0].className=c[0].className.replace(/show/i,""),c[1].className=c[1].className.replace(/show/i,""))});var s=e(document.getElementById("sc_advanced_mode")),l=document.querySelectorAll(".sc-advanced-mode-table")[0],d=document.querySelectorAll(".sc-simple-mode-table")[0],n=document.getElementById("sc_enable_page_caching_simple"),m=document.getElementById("sc_enable_page_caching_advanced"),t=document.getElementById("sc_page_cache_length_simple"),o=document.getElementById("sc_page_cache_length_advanced"),i=document.getElementById("sc_page_cache_length_unit_simple"),_=document.getElementById("sc_page_cache_length_unit_advanced"),g=document.getElementById("sc_enable_gzip_compression_simple"),h=document.getElementById("sc_enable_gzip_compression_advanced");s.on("change",function(e){"1"===e.target.value?(l.className=l.className.replace(/show/i,"")+" show",d.className=d.className.replace(/show/i,""),n.disabled=!0,m.disabled=!1,t.disabled=!0,o.disabled=!1,i.disabled=!0,_.disabled=!1,g&&(g.disabled=!0,h.disabled=!1)):(d.className=d.className.replace(/show/i,"")+" show",l.className=l.className.replace(/show/i,""),n.disabled=!1,m.disabled=!0,t.disabled=!1,o.disabled=!0,i.disabled=!1,_.disabled=!0,g&&(g.disabled=!1,h.disabled=!0))})}(jQuery);
  • simple-cache/trunk/assets/js/src/settings.js

    r1396118 r1877792  
    2222    var pageCacheLengthSimple = document.getElementById( 'sc_page_cache_length_simple' );
    2323    var pageCacheLengthAdvanced = document.getElementById( 'sc_page_cache_length_advanced' );
     24    var pageCacheLengthUnitSimple = document.getElementById( 'sc_page_cache_length_unit_simple' );
     25    var pageCacheLengthUnitAdvanced = document.getElementById( 'sc_page_cache_length_unit_advanced' );
    2426    var gzipCompressionSimple = document.getElementById( 'sc_enable_gzip_compression_simple' );
    2527    var gzipCompressionAdvanced = document.getElementById( 'sc_enable_gzip_compression_advanced' );
     
    3739                pageCacheLengthAdvanced.disabled = false;
    3840
     41                pageCacheLengthUnitSimple.disabled = true;
     42                pageCacheLengthUnitAdvanced.disabled = false;
     43
    3944                if ( gzipCompressionSimple ) {
    4045                    gzipCompressionSimple.disabled = true;
     
    5156                pageCacheLengthAdvanced.disabled = true;
    5257
     58                pageCacheLengthUnitSimple.disabled = false;
     59                pageCacheLengthUnitAdvanced.disabled = true;
     60
    5361                if (gzipCompressionSimple) {
    5462                    gzipCompressionSimple.disabled = false;
  • simple-cache/trunk/inc/class-sc-advanced-cache.php

    r1643085 r1877792  
    11<?php
     2/**
     3 * Page caching functionality
     4 *
     5 * @package  simple-cache
     6 */
     7
    28defined( 'ABSPATH' ) || exit;
    39
     10/**
     11 * Wrapper for advanced cache functionality
     12 */
    413class SC_Advanced_Cache {
    514
     
    1524        add_action( 'save_post', array( $this, 'purge_post_on_update' ), 10, 1 );
    1625        add_action( 'wp_trash_post', array( $this, 'purge_post_on_update' ), 10, 1 );
    17         add_action( 'wp_set_comment_status', array( $this, 'purge_post_on_comment_status_change' ), 10, 2 );
    18         add_action( 'set_comment_cookies', array( $this, 'set_comment_cookie_exceptions' ), 10, 2 );
     26        add_action( 'wp_set_comment_status', array( $this, 'purge_post_on_comment_status_change' ), 10 );
     27        add_action( 'set_comment_cookies', array( $this, 'set_comment_cookie_exceptions' ), 10 );
    1928    }
    2029
     
    2231     * When user posts a comment, set a cookie so we don't show them page cache
    2332     *
    24      * @param  WP_Comment $comment
    25      * @param  WP_User $user
     33     * @param  WP_Comment $comment Comment to check.
    2634     * @since  1.3
    2735     */
    28     public function set_comment_cookie_exceptions( $comment, $user ) {
    29         $config = SC_Config::factory()->get();
    30 
    31         // File based caching only
     36    public function set_comment_cookie_exceptions( $comment ) {
     37        $config = SC_Config::factory()->get();
     38
     39        // File based caching only.
    3240        if ( ! empty( $config['enable_page_caching'] ) && empty( $config['enable_in_memory_object_caching'] ) ) {
    3341            $post_id = $comment->comment_post_ID;
     
    4048     * Every time a comments status changes, purge it's parent posts cache
    4149     *
    42      * @param  int $comment_ID
    43      * @param  int $comment_status
     50     * @param  int $comment_id Comment ID.
    4451     * @since  1.3
    4552     */
    46     public function purge_post_on_comment_status_change( $comment_ID, $comment_status ) {
    47         $config = SC_Config::factory()->get();
    48 
    49         // File based caching only
     53    public function purge_post_on_comment_status_change( $comment_id ) {
     54        $config = SC_Config::factory()->get();
     55
     56        // File based caching only.
    5057        if ( ! empty( $config['enable_page_caching'] ) && empty( $config['enable_in_memory_object_caching'] ) ) {
    51             require_once( ABSPATH . 'wp-admin/includes/file.php');
    52            
    53             $comment = get_comment( $comment_ID );
     58            require_once( ABSPATH . 'wp-admin/includes/file.php' );
     59
     60            $comment = get_comment( $comment_id );
    5461            $post_id = $comment->comment_post_ID;
    5562
     
    6875     * Purge post cache when there is a new approved comment
    6976     *
    70      * @param  int $comment_ID
    71      * @param  int $approved
    72      * @param  array $commentdata
     77     * @param  int   $comment_id Comment ID.
     78     * @param  int   $approved Comment approved status.
     79     * @param  array $commentdata Comment data array.
    7380     * @since  1.3
    7481     */
    75     public function purge_post_on_comment( $comment_ID, $approved, $commentdata ) {
     82    public function purge_post_on_comment( $comment_id, $approved, $commentdata ) {
    7683        if ( empty( $approved ) ) {
    7784            return;
     
    8087        $config = SC_Config::factory()->get();
    8188
    82         // File based caching only
     89        // File based caching only.
    8390        if ( ! empty( $config['enable_page_caching'] ) && empty( $config['enable_in_memory_object_caching'] ) ) {
    8491            $post_id = $commentdata['comment_post_ID'];
     
    98105     * Automatically purge all file based page cache on post changes
    99106     *
    100      * @param  int $post_id
     107     * @param  int $post_id Post id.
    101108     * @since  1.3
    102109     */
     
    112119        $config = SC_Config::factory()->get();
    113120
    114         // File based caching only
     121        // File based caching only.
    115122        if ( ! empty( $config['enable_page_caching'] ) && empty( $config['enable_in_memory_object_caching'] ) ) {
    116123            sc_cache_flush();
     
    134141
    135142        if ( empty( $config['enable_page_caching'] ) ) {
    136             // Not turned on do nothing
    137             return;
    138         }
    139 
    140         $config_file_bad = true;
     143            // Not turned on do nothing.
     144            return;
     145        }
     146
     147        $config_file_bad         = true;
    141148        $advanced_cache_file_bad = true;
    142149
     
    171178        </div>
    172179
    173      <?php
     180        <?php
    174181    }
    175182
     
    184191        global $wp_filesystem;
    185192
    186         $file = untrailingslashit( WP_CONTENT_DIR )  . '/advanced-cache.php';
     193        $file = untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php';
    187194
    188195        $ret = true;
     
    192199        }
    193200
    194         $folder = untrailingslashit( WP_CONTENT_DIR )  . '/cache/simple-cache';
     201        $folder = untrailingslashit( WP_CONTENT_DIR ) . '/cache/simple-cache';
    195202
    196203        if ( ! $wp_filesystem->delete( $folder, true ) ) {
     
    211218        global $wp_filesystem;
    212219
    213         $file = untrailingslashit( WP_CONTENT_DIR )  . '/advanced-cache.php';
     220        $file = untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php';
    214221
    215222        $config = SC_Config::factory()->get();
     
    245252     * Toggle WP_CACHE on or off in wp-config.php
    246253     *
    247      * @param  boolean $status
     254     * @param  boolean $status Status of cache.
    248255     * @since  1.0
    249256     * @return boolean
     
    257264        }
    258265
    259         $file = '/wp-config.php';
     266        $file        = '/wp-config.php';
    260267        $config_path = false;
    261268
     
    265272            }
    266273
    267             if ( $wp_filesystem->exists( untrailingslashit( ABSPATH )  . $file ) ) {
    268                 $config_path = untrailingslashit( ABSPATH )  . $file;
     274            if ( $wp_filesystem->exists( untrailingslashit( ABSPATH ) . $file ) ) {
     275                $config_path = untrailingslashit( ABSPATH ) . $file;
    269276                break;
    270277            }
    271278        }
    272279
    273         // Couldn't find wp-config.php
     280        // Couldn't find wp-config.php.
    274281        if ( ! $config_path ) {
    275282            return false;
     
    284291
    285292        $config_file = preg_split( "#(\n|\r)#", $config_file_string );
    286         $line_key = false;
     293        $line_key    = false;
    287294
    288295        foreach ( $config_file as $key => $line ) {
     
    291298            }
    292299
    293             if ( $match[2] == 'WP_CACHE' ) {
     300            if ( 'WP_CACHE' === $match[2] ) {
    294301                $line_key = $key;
    295302            }
    296303        }
    297304
    298         if ( $line_key !== false ) {
     305        if ( false !== $line_key ) {
    299306            unset( $config_file[ $line_key ] );
    300307        }
     
    307314        foreach ( $config_file as $key => $line ) {
    308315            if ( '' === $line ) {
    309                 unset( $config_file[$key] );
     316                unset( $config_file[ $key ] );
    310317            }
    311318        }
  • simple-cache/trunk/inc/class-sc-config.php

    r1643085 r1877792  
    11<?php
     2/**
     3 * Handle plugin config
     4 *
     5 * @package  simple-cache
     6 */
     7
    28defined( 'ABSPATH' ) || exit;
    39
     10/**
     11 * Class wrapping config functionality
     12 */
    413class SC_Config {
    514
     
    817     *
    918     * @since 1.0.1
     19     * @var   array
    1020     */
    1121    public $defaults = array();
    1222
    1323
     24    /**
     25     * Set config defaults
     26     *
     27     * @since 1.0
     28     */
    1429    public function __construct() {
    1530
    1631        $this->defaults = array(
    17             'enable_page_caching' => array(
    18                 'default'         => false,
    19                 'sanitizer'       => array( $this, 'boolval' ),
    20             ),
    21             'advanced_mode' => array(
     32            'enable_page_caching'             => array(
     33                'default'   => false,
     34                'sanitizer' => array( $this, 'boolval' ),
     35            ),
     36            'advanced_mode'                   => array(
    2237                'default'   => false,
    2338                'sanitizer' => array( $this, 'boolval' ),
    2439            ),
    2540            'enable_in_memory_object_caching' => array(
    26                 'default'                     => false,
    27                 'sanitizer'                   => array( $this, 'boolval' ),
    28             ),
    29             'enable_gzip_compression' => array(
    30                 'default'             => false,
    31                 'sanitizer'           => array( $this, 'boolval' ),
    32             ),
    33             'in_memory_cache' => array(
    34                 'default'     => 'memcached',
    35                 'sanitizer'   => 'sanitize_text_field',
    36             ),
    37             'page_cache_length' => array(
    38                 'default'       => 1440, // One day
    39                 'sanitizer'     => 'intval',
    40             ),
    41             'cache_exception_urls' => array(
    42                 'default'       => '',
    43                 'sanitizer'     => 'wp_kses_post',
    44             ),
    45             'enable_url_exemption_regex' => array(
     41                'default'   => false,
     42                'sanitizer' => array( $this, 'boolval' ),
     43            ),
     44            'enable_gzip_compression'         => array(
     45                'default'   => false,
     46                'sanitizer' => array( $this, 'boolval' ),
     47            ),
     48            'in_memory_cache'                 => array(
     49                'default'   => 'memcached',
     50                'sanitizer' => 'sanitize_text_field',
     51            ),
     52            'page_cache_length'               => array(
     53                'default'   => 24,
     54                'sanitizer' => 'floatval',
     55            ),
     56            'page_cache_length_unit'          => array(
     57                'default'   => 'hours',
     58                'sanitizer' => array( $this, 'sanitize_length_unit' ),
     59            ),
     60            'cache_exception_urls'            => array(
     61                'default'   => '',
     62                'sanitizer' => 'wp_kses_post',
     63            ),
     64            'enable_url_exemption_regex'      => array(
    4665                'default'   => false,
    4766                'sanitizer' => array( $this, 'boolval' ),
     
    5372     * Make sure we support old PHP with boolval
    5473     *
    55      * @param  string $value
     74     * @param  string $value Value to check.
    5675     * @since  1.0
    5776     * @return boolean
    5877     */
    5978    public function boolval( $value ) {
    60 
    6179        return (bool) $value;
     80    }
     81
     82    /**
     83     * Make sure the length unit has an expected value
     84     *
     85     * @param  string $value Value to sanitize.
     86     * @return string
     87     */
     88    public function sanitize_length_unit( $value ) {
     89        $accepted_values = array( 'minutes', 'hours', 'days', 'weeks' );
     90
     91        if ( in_array( $value, $accepted_values ) ) {
     92            return $value;
     93        }
     94
     95        return 'minutes';
    6296    }
    6397
     
    83117     *
    84118     * @since  1.0
    85      * @param  array $config
     119     * @param  array $config Configuration array.
    86120     * @return bool
    87121     */
     
    125159     * Check if a directory is writable and we can create files as the same user as the current file
    126160     *
    127      * @param  string  $dir
     161     * @param  string $dir Directory path.
    128162     * @since  1.2.3
    129163     * @return boolean
     
    131165    private function _is_dir_writable( $dir ) {
    132166        $temp_file_name = untrailingslashit( $dir ) . '/temp-write-test-' . time();
    133         $temp_handle = fopen( $temp_file_name, 'w' );
     167        $temp_handle    = fopen( $temp_file_name, 'w' );
    134168
    135169        if ( $temp_handle ) {
    136170
    137             // Attempt to determine the file owner of the WordPress files, and that of newly created files
    138             $wp_file_owner = $temp_file_owner = false;
     171            // Attempt to determine the file owner of the WordPress files, and that of newly created files.
     172            $wp_file_owner   = false;
     173            $temp_file_owner = false;
    139174
    140175            if ( function_exists( 'fileowner' ) ) {
     
    148183
    149184                // Return if we cannot determine the file owner, or if the owner IDs do not match.
    150                 if ( $wp_file_owner === false || $wp_file_owner !== $temp_file_owner ) {
     185                if ( false === $wp_file_owner || $wp_file_owner !== $temp_file_owner ) {
    151186                    return false;
    152187                }
     
    174209        }
    175210
    176         // First check wp-config.php
     211        // First check wp-config.php.
    177212        if ( ! @is_writable( ABSPATH . 'wp-config.php' ) && ! @is_writable( ABSPATH . '../wp-config.php' ) ) {
    178213            return false;
    179214        }
    180215
    181         // Now check wp-content. We need to be able to create files of the same user as this file
     216        // Now check wp-content. We need to be able to create files of the same user as this file.
    182217        if ( ! $this->_is_dir_writable( untrailingslashit( WP_CONTENT_DIR ) ) ) {
    183218            return false;
    184219        }
    185220
    186         // If the cache and/or cache/simple-cache directories exist, make sure it's writeable
     221        // If the cache and/or cache/simple-cache directories exist, make sure it's writeable.
    187222        if ( @file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/cache' ) ) {
    188223            if ( ! $this->_is_dir_writable( untrailingslashit( WP_CONTENT_DIR ) . '/cache' ) ) {
     
    197232        }
    198233
    199         // If the sc-config directory exists, make sure it's writeable
     234        // If the sc-config directory exists, make sure it's writeable.
    200235        if ( @file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/sc-config' ) ) {
    201236            if ( ! $this->_is_dir_writable( untrailingslashit( WP_CONTENT_DIR ) . '/sc-config' ) ) {
  • simple-cache/trunk/inc/class-sc-cron.php

    r1417180 r1877792  
    11<?php
     2/**
     3 * Cron functionality
     4 *
     5 * @package  simple-cache
     6 */
     7
    28defined( 'ABSPATH' ) || exit;
    39
     10/**
     11 * Wrap cron functionality
     12 */
    413class SC_Cron {
    5 
    6     public function __construct() {
    7 
    8     }
    914
    1015    /**
     
    2328     * Add custom cron schedule
    2429     *
    25      * @param  array $schedules
     30     * @param  array $schedules Current cron schedules.
    2631     * @since  1.0
    2732     * @return array
     
    3439
    3540        if ( ! empty( $config['page_cache_length'] ) && $config['page_cache_length'] > 0 ) {
    36             $interval = $config['page_cache_length'] * 60;
     41
     42            $interval = $config['page_cache_length'] * MINUTE_IN_SECONDS;
     43
     44            if ( ! empty( $config['page_cache_length'] ) && 'hours' === $config['page_cache_length'] ) {
     45                $interval = $config['page_cache_length'] * HOUR_IN_SECONDS;
     46            } elseif ( ! empty( $config['page_cache_length'] ) && 'days' === $config['page_cache_length'] ) {
     47                $interval = $config['page_cache_length'] * DAY_IN_SECONDS;
     48            } elseif ( ! empty( $config['page_cache_length'] ) && 'weeks' === $config['page_cache_length'] ) {
     49                $interval = $config['page_cache_length'] * WEEK_IN_SECONDS;
     50            }
    3751        }
    3852
     
    6680        $timestamp = wp_next_scheduled( 'sc_purge_cache' );
    6781
    68         // Do nothing if we are using the object cache
     82        // Do nothing if we are using the object cache.
    6983        if ( ! empty( $config['advanced_mode'] ) && ! empty( $config['enable_in_memory_object_caching'] ) ) {
    7084            wp_unschedule_event( $timestamp, 'sc_purge_cache' );
     
    7286        }
    7387
    74         // Expire cache never
    75         if ( isset( $config['page_cache_length'] ) && $config['page_cache_length'] === 0 ) {
     88        // Expire cache never.
     89        if ( isset( $config['page_cache_length'] ) && 0 === $config['page_cache_length'] ) {
    7690            wp_unschedule_event( $timestamp, 'sc_purge_cache' );
    7791            return;
     
    91105        $config = SC_Config::factory()->get();
    92106
    93         // Do nothing, caching is turned off
     107        // Do nothing, caching is turned off.
    94108        if ( empty( $config['enable_page_caching'] ) ) {
    95109            return;
    96110        }
    97111
    98         // Do nothing if we are using the object cache
     112        // Do nothing if we are using the object cache.
    99113        if ( ! empty( $config['advanced_mode'] ) && ! empty( $config['enable_in_memory_object_caching'] ) ) {
    100114            return;
  • simple-cache/trunk/inc/class-sc-object-cache.php

    r1456175 r1877792  
    11<?php
     2/**
     3 * Object cache functionality
     4 *
     5 * @package  simple-cache
     6 */
     7
    28defined( 'ABSPATH' ) || exit;
    39
     10/**
     11 * Wrap object caching functionality
     12 */
    413class SC_Object_Cache {
    514
     
    3847
    3948        ?>
    40      <div class="error">
    41       <p>
    42         <?php esc_html_e( 'wp-content/object-cache.php was edited or deleted. Simple Cache is not able to utilize object caching.' ); ?>
     49        <div class="error">
     50            <p>
     51                <?php esc_html_e( 'wp-content/object-cache.php was edited or deleted. Simple Cache is not able to utilize object caching.' ); ?>
    4352
    4453                <a href="options-general.php?page=simple-cache&amp;wp_http_referer=<?php echo esc_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ); ?>&amp;action=sc_update&amp;sc_settings_nonce=<?php echo wp_create_nonce( 'sc_update_settings' ); ?>" class="button button-primary" style="margin-left: 5px;"><?php esc_html_e( 'Fix', 'simple-cache' ); ?></a>
    45       </p>
    46      </div>
     54            </p>
     55        </div>
    4756        <?php
    4857    }
     
    5867        global $wp_filesystem;
    5968
    60         $file = untrailingslashit( WP_CONTENT_DIR )  . '/object-cache.php';
     69        $file = untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php';
    6170
    6271        if ( ! $wp_filesystem->delete( $file ) ) {
     
    7786        global $wp_filesystem;
    7887
    79         $file = untrailingslashit( WP_CONTENT_DIR )  . '/object-cache.php';
     88        $file = untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php';
    8089
    8190        $config = SC_Config::factory()->get();
     
    9099            }
    91100
     101            /**
     102             * Salt to be used with the cache keys.
     103             *
     104             * We need a random string not long as cache key size is limited and
     105             * not with special characters as they cause issues with some caches.
     106             *
     107             * @var string
     108             */
     109            $cache_key_salt = wp_generate_password( 10, false );
     110
    92111            $file_string = '<?php ' .
    93112            "\n\r" . "defined( 'ABSPATH' ) || exit;" .
    94113            "\n\r" . "define( 'SC_OBJECT_CACHE', true );" .
     114            "\n\r" . "defined( 'WP_CACHE_KEY_SALT' ) || define( 'WP_CACHE_KEY_SALT', '{$cache_key_salt}' );" .
    95115            "\n\r" . "if ( ! @file_exists( WP_CONTENT_DIR . '/sc-config/config-' . \$_SERVER['HTTP_HOST'] . '.php' ) ) { return; }" .
    96116            "\n\r" . "\$GLOBALS['sc_config'] = include( WP_CONTENT_DIR . '/sc-config/config-' . \$_SERVER['HTTP_HOST'] . '.php' );" .
  • simple-cache/trunk/inc/class-sc-settings.php

    r1643085 r1877792  
    11<?php
     2/**
     3 * Settings class
     4 *
     5 * @package  simple-cache
     6 */
     7
    28defined( 'ABSPATH' ) || exit;
    39
     10/**
     11 * Class containing settings hooks
     12 */
    413class SC_Settings {
    5 
    6     public function __construct() {
    7 
    8     }
    914
    1015    /**
     
    3742        }
    3843
    39         $wp_admin_bar->add_menu( array(
    40             'id'     => 'sc-purge-cache',
    41             'parent' => 'top-secondary',
    42             'href' => esc_url( admin_url( 'options-general.php?page=simple-cache&amp;wp_http_referer=' . esc_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '&amp;action=sc_purge_cache&amp;sc_cache_nonce=' . wp_create_nonce( 'sc_purge_cache' ) ) ),
    43             'title'  => esc_html__( 'Purge Cache', 'simple-cache' ),
    44         ) );
     44        $wp_admin_bar->add_menu(
     45            array(
     46                'id'     => 'sc-purge-cache',
     47                'parent' => 'top-secondary',
     48                'href'   => esc_url( admin_url( 'options-general.php?page=simple-cache&amp;wp_http_referer=' . esc_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '&amp;action=sc_purge_cache&amp;sc_cache_nonce=' . wp_create_nonce( 'sc_purge_cache' ) ) ),
     49                'title'  => esc_html__( 'Purge Cache', 'simple-cache' ),
     50            )
     51        );
    4552    }
    4653
     
    5158     */
    5259    public function setup_notice() {
    53        
    54         if ( ! current_user_can('manage_options')) {
    55             return;
    56         }
     60
     61        if ( ! current_user_can( 'manage_options' ) ) {
     62            return;
     63        }
    5764
    5865        $cant_write = get_option( 'sc_cant_write', false );
     
    114121            if ( defined( WP_DEBUG ) && WP_DEBUG ) {
    115122                $js_path = '/assets/js/src/settings.js';
    116                 $css_path = '/assets/css/settings.css';
    117123            } else {
    118124                $js_path = '/assets/js/settings.min.js';
    119                 $css_path = '/assets/css/settings.css';
    120             }
     125            }
     126            $css_path = '/assets/css/settings.css';
    121127
    122128            wp_enqueue_script( 'sc-settings', plugins_url( $js_path, dirname( __FILE__ ) ), array( 'jquery' ), SC_VERSION, true );
     
    144150        if ( ! empty( $_REQUEST['action'] ) && 'sc_purge_cache' === $_REQUEST['action'] ) {
    145151            if ( ! current_user_can( 'manage_options' ) || empty( $_REQUEST['sc_cache_nonce'] ) || ! wp_verify_nonce( $_REQUEST['sc_cache_nonce'], 'sc_purge_cache' ) ) {
    146                 wp_die( 'Cheatin, eh?' );
     152                wp_die( esc_html__( 'Cheatin, eh?', 'simple-cache' ) );
    147153            }
    148154
     
    177183            delete_option( 'sc_cant_write' );
    178184
    179             $defaults = SC_Config::factory()->defaults;
     185            $defaults       = SC_Config::factory()->defaults;
    180186            $current_config = SC_Config::factory()->get();
    181187
     
    188194            }
    189195
    190             // Back up configration in options
     196            // Back up configration in options.
    191197            update_option( 'sc_simple_cache', $clean_config );
    192198
     
    204210            }
    205211
    206             // Reschedule cron events
     212            // Reschedule cron events.
    207213            SC_Cron::factory()->unschedule_events();
    208214            SC_Cron::factory()->schedule_events();
     
    218224     * Sanitize options
    219225     *
    220      * @param  array $option
     226     * @param  array $option Array of options to sanitize.
    221227     * @since  1.0
    222228     * @return array
     
    277283                            <th scope="row"><label for="sc_page_cache_length_simple"><?php esc_html_e( 'Expire the cache after', 'simple-cache' ); ?></label></th>
    278284                            <td>
    279                                 <input <?php if ( ! empty( $config['advanced_mode'] ) ) : ?>disabled<?php endif; ?> size="5" id="sc_page_cache_length_simple" type="text" value="<?php echo (int) $config['page_cache_length']; ?>" name="sc_simple_cache[page_cache_length]"> <span class="description"><?php esc_html_e( 'minutes', 'simple-cache' ); ?></span>
     285                                <input <?php if ( ! empty( $config['advanced_mode'] ) ) : ?>disabled<?php endif; ?> size="5" id="sc_page_cache_length_simple" type="text" value="<?php echo (float) $config['page_cache_length']; ?>" name="sc_simple_cache[page_cache_length]">
     286                                <select <?php if ( ! empty( $config['advanced_mode'] ) ) : ?>disabled<?php endif; ?> name="sc_simple_cache[page_cache_length_unit]" id="sc_page_cache_length_unit_simple">
     287                                    <option <?php selected( $config['page_cache_length_unit'], 'minutes' ); ?> value="minutes"><?php esc_html_e( 'minutes', 'simple-cache' ); ?></option>
     288                                    <option <?php selected( $config['page_cache_length_unit'], 'hours' ); ?> value="hours"><?php esc_html_e( 'hours', 'simple-cache' ); ?></option>
     289                                    <option <?php selected( $config['page_cache_length_unit'], 'days' ); ?> value="days"><?php esc_html_e( 'days', 'simple-cache' ); ?></option>
     290                                    <option <?php selected( $config['page_cache_length_unit'], 'weeks' ); ?> value="weeks"><?php esc_html_e( 'weeks', 'simple-cache' ); ?></option>
     291                                </select>
    280292                            </td>
    281293                        </tr>
     
    337349                            <th scope="row"><label for="sc_page_cache_length_advanced"><?php esc_html_e( 'Expire page cache after', 'simple-cache' ); ?></label></th>
    338350                            <td>
    339                                 <input <?php if ( empty( $config['advanced_mode'] ) ) : ?>disabled<?php endif; ?> size="5" id="sc_page_cache_length_advanced" type="text" value="<?php echo (int) $config['page_cache_length']; ?>" name="sc_simple_cache[page_cache_length]"> <span class="description"><?php esc_html_e( 'minutes', 'simple-cache' ); ?></span>
     351                                <input <?php if ( empty( $config['advanced_mode'] ) ) : ?>disabled<?php endif; ?> size="5" id="sc_page_cache_length_advanced" type="text" value="<?php echo (float) $config['page_cache_length']; ?>" name="sc_simple_cache[page_cache_length]">
     352                                <select
     353                                <?php if ( empty( $config['advanced_mode'] ) ) : ?>disabled<?php endif; ?> name="sc_simple_cache[page_cache_length_unit]" id="sc_page_cache_length_unit_advanced">
     354                                    <option <?php selected( $config['page_cache_length_unit'], 'minutes' ); ?> value="minutes"><?php esc_html_e( 'minutes', 'simple-cache' ); ?></option>
     355                                    <option <?php selected( $config['page_cache_length_unit'], 'hours' ); ?> value="hours"><?php esc_html_e( 'hours', 'simple-cache' ); ?></option>
     356                                    <option <?php selected( $config['page_cache_length_unit'], 'days' ); ?> value="days"><?php esc_html_e( 'days', 'simple-cache' ); ?></option>
     357                                    <option <?php selected( $config['page_cache_length_unit'], 'weeks' ); ?> value="weeks"><?php esc_html_e( 'weeks', 'simple-cache' ); ?></option>
     358                                </select>
    340359                            </td>
    341360                        </tr>
     
    359378                            </tr>
    360379                            <tr>
    361                                 <th class="in-memory-cache <?php if ( ! empty( $config['enable_in_memory_object_caching'] ) ) : ?>show<?php endif; ?>" scope="row"><label for="sc_in_memory_cache"><?php _e( 'In Memory Cache', 'simple-cache' ); ?></label></th>
     380                                <th class="in-memory-cache
     381                                <?php
     382                                if ( ! empty( $config['enable_in_memory_object_caching'] ) ) :
     383                                ?>
     384                                show<?php endif; ?>" scope="row"><label for="sc_in_memory_cache"><?php _e( 'In Memory Cache', 'simple-cache' ); ?></label></th>
    362385                                <td class="in-memory-cache <?php if ( ! empty( $config['enable_in_memory_object_caching'] ) ) : ?>show<?php endif; ?>">
    363386                                    <select name="sc_simple_cache[in_memory_cache]" id="sc_in_memory_cache">
  • simple-cache/trunk/inc/dropins/batcache.php

    r1456175 r1877792  
    11<?php
     2/**
     3 * Batcache dropin
     4 *
     5 * @package  simple-cache
     6 */
     7
    28defined( 'ABSPATH' ) || exit;
    39
     
    1319
    1420// nananananananananananananananana BATCACHE!!!
    15 
    1621function batcache_cancel() {
    1722
     
    2631// Functions defined in WordPress, plugins, and themes are not available and MUST NOT be used.
    2732// Example: vary_cache_on_function('return preg_match("/feedburner/i", $_SERVER["HTTP_USER_AGENT"]);');
    28 //          This will cause batcache to cache a variant for requests from Feedburner.
     33// This will cause batcache to cache a variant for requests from Feedburner.
    2934// Tips for writing $function:
    30 //  X_X  DO NOT use any functions from your theme or plugins. Those files have not been included. Fatal error.
    31 //  X_X  DO NOT use any WordPress functions except is_admin() and is_multisite(). Fatal error.
    32 //  X_X  DO NOT include or require files from anywhere without consulting expensive professionals first. Fatal error.
    33 //  X_X  DO NOT use $wpdb, $blog_id, $current_user, etc. These have not been initialized.
    34 //  ^_^  DO understand how create_function works. This is how your code is used: create_function('', $function);
    35 //  ^_^  DO remember to return something. The return value determines the cache variant.
     35// X_X  DO NOT use any functions from your theme or plugins. Those files have not been included. Fatal error.
     36// X_X  DO NOT use any WordPress functions except is_admin() and is_multisite(). Fatal error.
     37// X_X  DO NOT include or require files from anywhere without consulting expensive professionals first. Fatal error.
     38// X_X  DO NOT use $wpdb, $blog_id, $current_user, etc. These have not been initialized.
     39// ^_^  DO understand how create_function works. This is how your code is used: create_function('', $function);
     40// ^_^  DO remember to return something. The return value determines the cache variant.
    3641function vary_cache_on_function( $function ) {
    3742
     
    5358    var $max_age = 3600; // Expire batcache items aged this many seconds (zero to disable batcache)
    5459
    55     var $remote  = 0; // Zero disables sending buffers to remote datacenters (req/sec is never sent)
     60    var $remote = 0; // Zero disables sending buffers to remote datacenters (req/sec is never sent)
    5661
    5762    var $times   = 2; // Only batcache a page after it is accessed this many times... (two or more)
    5863    var $seconds = 120; // ...in this many seconds (zero to ignore this and use batcache immediately)
    5964
    60     var $group   = 'batcache'; // Name of memcached group. You can simulate a cache flush by changing this.
    61 
    62     var $unique  = array(); // If you conditionally serve different content, put the variable values here.
    63 
    64     var $vary    = array(); // Array of functions for create_function. The return value is added to $unique above.
     65    var $group = 'batcache'; // Name of memcached group. You can simulate a cache flush by changing this.
     66
     67    var $unique = array(); // If you conditionally serve different content, put the variable values here.
     68
     69    var $vary = array(); // Array of functions for create_function. The return value is added to $unique above.
    6570
    6671    var $headers = array(); // Add headers here as name=>value or name=>array(values). These will be sent with every response from the cache.
    6772
    68     var $cache_redirects = false; // Set true to enable redirect caching.
    69     var $redirect_status = false; // This is set to the response code during a redirect.
     73    var $cache_redirects   = false; // Set true to enable redirect caching.
     74    var $redirect_status   = false; // This is set to the response code during a redirect.
    7075    var $redirect_location = false; // This is set to the redirect location.
    7176
     
    7378    var $uncached_headers = array( 'transfer-encoding' ); // These headers will never be cached. Apply strtolower.
    7479
    75     var $debug   = true; // Set false to hide the batcache info <!-- comment -->
     80    var $debug = true; // Set false to hide the batcache info <!-- comment -->
    7681
    7782    var $cache_control = true; // Set false to disable Last-Modified and Cache-Control headers
     
    8186    var $noskip_cookies = array( 'wordpress_test_cookie' ); // Names of cookies - if they exist and the cache would normally be bypassed, don't bypass it
    8287
    83     var $query = '';
     88    var $query   = '';
    8489    var $genlock = false;
    85     var $do = false;
     90    var $do      = false;
    8691
    8792    function __construct( $settings ) {
     
    112117
    113118        $this->status_header = $status_header;
    114         $this->status_code = $status_code;
     119        $this->status_code   = $status_code;
    115120
    116121        return $status_header;
     
    120125
    121126        if ( $this->cache_redirects ) {
    122             $this->redirect_status = $status;
     127            $this->redirect_status   = $status;
    123128            $this->redirect_location = $location;
    124129        }
     
    131136        // Merge the arrays of headers into one
    132137        $headers = array();
    133         $keys = array_unique( array_merge( array_keys( $headers1 ), array_keys( $headers2 ) ) );
     138        $keys    = array_unique( array_merge( array_keys( $headers1 ), array_keys( $headers2 ) ) );
    134139        foreach ( $keys as $k ) {
    135140            $headers[ $k ] = array();
     
    170175
    171176        global $timestart, $timeend;
    172         $mtime = microtime();
    173         $mtime = explode( ' ', $mtime );
    174         $mtime = $mtime[1] + $mtime[0];
    175         $timeend = $mtime;
    176         $timetotal = $timeend -$timestart;
    177         $r = number_format( $timetotal, $precision );
     177        $mtime     = microtime();
     178        $mtime     = explode( ' ', $mtime );
     179        $mtime     = $mtime[1] + $mtime[0];
     180        $timeend   = $mtime;
     181        $timetotal = $timeend - $timestart;
     182        $r         = number_format( $timetotal, $precision );
    178183        if ( $display ) {
    179184            echo $r;
     
    197202        // Do not batcache blank pages unless they are HTTP redirects
    198203        $output = trim( $output );
    199         if ( $output === '' && ( ! $this->redirect_status || ! $this->redirect_location) ) {
     204        if ( $output === '' && ( ! $this->redirect_status || ! $this->redirect_location ) ) {
    200205            wp_cache_delete( "{$this->url_key}_genlock", $this->group );
    201206            return;
     
    213218        // Construct and save the batcache
    214219        $this->cache = array(
    215         'output' => $output,
    216         'time' => time(),
    217         'timer' => $this->timer_stop( false, 3 ),
    218         'headers' => array(),
    219         'status_header' => $this->status_header,
    220         'redirect_status' => $this->redirect_status,
    221         'redirect_location' => $this->redirect_location,
    222         'version' => $this->url_version,
     220            'output'            => $output,
     221            'time'              => time(),
     222            'timer'            => $this->timer_stop( false, 3 ),
     223            'headers'          => array(),
     224            'status_header'    => $this->status_header,
     225            'redirect_status'  => $this->redirect_status,
     226            'redirect_location' => $this->redirect_location,
     227            'version'          => $this->url_version,
    223228        );
    224229
    225230        foreach ( headers_list() as $header ) {
    226             list($k, $v) = array_map( 'trim', explode( ':', $header, 2 ) );
     231            list($k, $v)                    = array_map( 'trim', explode( ':', $header, 2 ) );
    227232            $this->cache['headers'][ $k ][] = $v;
    228233        }
     
    284289    function add_variant( $function ) {
    285290
    286         $key = md5( $function );
     291        $key                = md5( $function );
    287292        $this->vary[ $key ] = $function;
    288293    }
     
    300305            ksort( $dimensions );
    301306            foreach ( $dimensions as $key => $function ) {
    302                 $fun = create_function( '', $function );
    303                 $value = $fun();
     307                $fun                = create_function( '', $function );
     308                $value              = $fun();
    304309                $this->keys[ $key ] = $value;
    305310            }
     
    310315
    311316        // ksort($this->keys); // uncomment this when traffic is slow
    312         $this->key = md5( serialize( $this->keys ) );
     317        $this->key     = md5( serialize( $this->keys ) );
    313318        $this->req_key = $this->key . '_reqs';
    314319    }
     
    317322
    318323        $generation = $this->cache['timer'];
    319         $bytes = strlen( serialize( $this->cache ) );
    320         $html = <<<HTML
     324        $bytes      = strlen( serialize( $this->cache ) );
     325        $html       = <<<HTML
    321326<!--
    322327    Cached by Simple Cache
     
    332337
    333338        $seconds_ago = time() - $this->cache['time'];
    334         $generation = $this->cache['timer'];
    335         $serving = $this->timer_stop( false, 3 );
    336         $expires = $this->cache['max_age'] - time() + $this->cache['time'];
    337         $html = <<<HTML
     339        $generation  = $this->cache['timer'];
     340        $serving     = $this->timer_stop( false, 3 );
     341        $expires     = $this->cache['max_age'] - time() + $this->cache['time'];
     342        $html        = <<<HTML
    338343<!--
    339344    generated $seconds_ago seconds ago
     
    367372global $batcache;
    368373
    369 if ( empty( $batcache ) && ! empty($GLOBALS['sc_config'] ) && isset( $GLOBALS['sc_config']['page_cache_length'] ) ) {
     374if ( empty( $batcache ) && ! empty( $GLOBALS['sc_config'] ) && isset( $GLOBALS['sc_config']['page_cache_length'] ) ) {
    370375    $max_age = $GLOBALS['sc_config']['page_cache_length'] * 60;
    371376
     
    393398
    394399            $exception = rtrim( $exception, '/' );
    395             $url = rtrim( 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}", '/' );
     400            $url       = rtrim( 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}", '/' );
    396401
    397402            if ( strtolower( $exception ) === strtolower( $url ) ) {
     
    399404                return;
    400405            }
    401 
    402406        } elseif ( preg_match( '#^/#', $exception ) ) {
    403407            $path = $_SERVER['REQUEST_URI'];
     
    429433    basename( $_SERVER['SCRIPT_FILENAME'] ),
    430434    array(
    431             'wp-app.php',
    432             'xmlrpc.php',
    433             'wp-cron.php',
    434         )
     435        'wp-app.php',
     436        'xmlrpc.php',
     437        'wp-cron.php',
     438    )
    435439) ) {
    436440    return;
     
    452456if ( is_array( $_COOKIE ) && ! empty( $_COOKIE ) ) {
    453457    foreach ( array_keys( $_COOKIE ) as $batcache->cookie ) {
    454         if ( ! in_array( $batcache->cookie, $batcache->noskip_cookies ) && ( substr( $batcache->cookie, 0, 2 ) == 'wp' || substr( $batcache->cookie, 0, 9 ) == 'wordpress' || substr( $batcache->cookie, 0, 14 ) == 'comment_author' ) ) {
     458        if ( ! in_array( $batcache->cookie, $batcache->noskip_cookies ) && ( substr( $batcache->cookie, 0, 2 ) == 'wp' || substr( $batcache->cookie, 0, 9 ) == 'WordPress' || substr( $batcache->cookie, 0, 14 ) == 'comment_author' ) ) {
    455459            batcache_stats( 'batcache', 'cookie_skip' );
    456460            return;
     
    470474
    471475// Now that the defaults are set, you might want to use different settings under certain conditions.
    472 
    473 /* Example: if your documents have a mobile variant (a different document served by the same URL) you must tell batcache about the variance. Otherwise you might accidentally cache the mobile version and serve it to desktop users, or vice versa.
     476/*
     477 Example: if your documents have a mobile variant (a different document served by the same URL) you must tell batcache about the variance. Otherwise you might accidentally cache the mobile version and serve it to desktop users, or vice versa.
    474478$batcache->unique['mobile'] = is_mobile_user_agent();
    475479*/
    476480
    477 /* Example: never batcache for this host
     481/*
     482 Example: never batcache for this host
    478483if ( $_SERVER['HTTP_HOST'] == 'do-not-batcache-me.com' )
    479484return;
    480485*/
    481486
    482 /* Example: batcache everything on this host regardless of traffic level
     487/*
     488 Example: batcache everything on this host regardless of traffic level
    483489if ( $_SERVER['HTTP_HOST'] == 'always-batcache-me.com' )
    484490return;
    485491*/
    486492
    487 /* Example: If you sometimes serve variants dynamically (e.g. referrer search term highlighting) you probably don't want to batcache those variants. Remember this code is run very early in wp-settings.php so plugins are not yet loaded. You will get a fatal error if you try to call an undefined function. Either include your plugin now or define a test function in this file.
     493/*
     494 Example: If you sometimes serve variants dynamically (e.g. referrer search term highlighting) you probably don't want to batcache those variants. Remember this code is run very early in wp-settings.php so plugins are not yet loaded. You will get a fatal error if you try to call an undefined function. Either include your plugin now or define a test function in this file.
    488495if ( include_once( 'plugins/searchterm-highlighter.php') && referrer_has_search_terms() )
    489496return;
     
    509516
    510517$batcache->keys = array(
    511     'host' => $_SERVER['HTTP_HOST'],
     518    'host'   => $_SERVER['HTTP_HOST'],
    512519    'method' => $_SERVER['REQUEST_METHOD'],
    513     'path' => ( $batcache->pos = strpos( $_SERVER['REQUEST_URI'], '?' ) ) ? substr( $_SERVER['REQUEST_URI'], 0, $batcache->pos ) : $_SERVER['REQUEST_URI'],
    514     'query' => $batcache->query,
    515     'extra' => $batcache->unique,
     520    'path'   => ( $batcache->pos = strpos( $_SERVER['REQUEST_URI'], '?' ) ) ? substr( $_SERVER['REQUEST_URI'], 0, $batcache->pos ) : $_SERVER['REQUEST_URI'],
     521    'query'  => $batcache->query,
     522    'extra'  => $batcache->unique,
    516523);
    517524
     
    522529// Recreate the permalink from the URL
    523530$batcache->permalink = 'http://' . $batcache->keys['host'] . $batcache->keys['path'] . ( isset( $batcache->keys['query']['p'] ) ? '?p=' . $batcache->keys['query']['p'] : '' );
    524 $batcache->url_key = md5( $batcache->permalink );
     531$batcache->url_key   = md5( $batcache->permalink );
    525532$batcache->configure_groups();
    526533$batcache->url_version = (int) wp_cache_get( "{$batcache->url_key}_version", $batcache->group );
     
    534541    // Always refresh the cache if a newer version is available.
    535542    $batcache->do = true;
    536 } else if ( $batcache->seconds < 1 || $batcache->times < 2 ) {
     543} elseif ( $batcache->seconds < 1 || $batcache->times < 2 ) {
    537544    // Are we only caching frequently-requested pages?
    538545    $batcache->do = true;
     
    561568if ( isset( $batcache->cache['time'] )  // We have cache
    562569    && ! $batcache->genlock             // We have not obtained cache regeneration lock
    563     && (    time() < $batcache->cache['time'] + $batcache->cache['max_age']  // Batcached page that hasn't expired ||
    564     || ( $batcache->do && $batcache->use_stale )    )
     570    && ( time() < $batcache->cache['time'] + $batcache->cache['max_age']  // Batcached page that hasn't expired ||
     571    || ( $batcache->do && $batcache->use_stale ) )
    565572) {
    566573    // Issue redirect if cached and enabled
    567574    if ( $batcache->cache['redirect_status'] && $batcache->cache['redirect_location'] && $batcache->cache_redirects ) {
    568         $status = $batcache->cache['redirect_status'];
     575        $status   = $batcache->cache['redirect_status'];
    569576        $location = $batcache->cache['redirect_location'];
    570577        // From vars.php
    571         $is_IIS = (strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false);
     578        $is_IIS = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false );
    572579
    573580        $batcache->do_headers( $batcache->headers );
     
    576583        } else {
    577584            if ( php_sapi_name() != 'cgi-fcgi' ) {
    578                 $texts = array(
     585                $texts    = array(
    579586                    300 => 'Multiple Choices',
    580587                    301 => 'Moved Permanently',
     
    622629    if ( $batcache->cache_control && ! isset( $batcache->cache['headers']['Last-Modified'][0] ) ) {
    623630        header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $batcache->cache['time'] ) . ' GMT', true );
    624         header( 'Cache-Control: max-age=' . ($batcache->cache['max_age'] - time() + $batcache->cache['time']) . ', must-revalidate', true );
     631        header( 'Cache-Control: max-age=' . ( $batcache->cache['max_age'] - time() + $batcache->cache['time'] ) . ', must-revalidate', true );
    625632    }
    626633
     
    652659}
    653660
    654 $wp_filter['status_header'][10]['batcache'] = array( 'function' => array( &$batcache, 'status_header' ), 'accepted_args' => 2 );
    655 $wp_filter['wp_redirect_status'][10]['batcache'] = array( 'function' => array( &$batcache, 'redirect_status' ), 'accepted_args' => 2 );
     661$wp_filter['status_header'][10]['batcache']      = array(
     662    'function'      => array( &$batcache, 'status_header' ),
     663    'accepted_args' => 2,
     664);
     665$wp_filter['wp_redirect_status'][10]['batcache'] = array(
     666    'function'      => array( &$batcache, 'redirect_status' ),
     667    'accepted_args' => 2,
     668);
    656669
    657670ob_start( array( &$batcache, 'ob' ) );
  • simple-cache/trunk/inc/dropins/file-based-page-cache-functions.php

    r1643085 r1877792  
    11<?php
    2 
    32/**
    43 * Holds functions used by file based cache
    54 *
    65 * @since  1.6
    7  */
    8 
     6 * @package  simple-cache
     7 */
    98
    109/**
    1110 * Cache output before it goes to the browser
    1211 *
    13  * @param  string $buffer
    14  * @param  int $flags
     12 * @param  string $buffer Page HTML.
     13 * @param  int    $flags OB flags to be passed through.
    1514 * @since  1.0
    1615 * @return string
    1716 */
    1817function sc_cache( $buffer, $flags ) {
     18    global $post;
     19
    1920    if ( strlen( $buffer ) < 255 ) {
    2021        return $buffer;
    2122    }
    2223
    23     // Don't cache search, 404, or password protected
    24     if ( is_404() || is_search() || post_password_required() ) {
     24    // Don't cache search, 404, or password protected.
     25    if ( is_404() || is_search() || ! empty( $post->post_password ) ) {
    2526        return $buffer;
    2627    }
    2728
    28     // Set the permission constants if not already set.
    29     // Normally, this is taken care of in WP_Filesystem constructor, but it is
    30     // not invoked here, because WP_Filesystem_Direct is instantiated directly.
    31     if ( ! defined('FS_CHMOD_DIR') )
    32         define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
    33     if ( ! defined('FS_CHMOD_FILE') )
    34         define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
     29    /**
     30     * Set the permission constants if not already set. Normally, this is taken care of in
     31     * WP_Filesystem constructor, but it is not invoked here, because WP_Filesystem_Direct
     32     * is instantiated directly.
     33     */
     34    if ( ! defined( 'FS_CHMOD_DIR' ) ) {
     35        define( 'FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
     36    }
     37    if ( ! defined( 'FS_CHMOD_FILE' ) ) {
     38        define( 'FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
     39    }
    3540
    3641    include_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
     
    3944    $filesystem = new WP_Filesystem_Direct( new StdClass() );
    4045
    41     // Make sure we can read/write files and that proper folders exist
     46    // Make sure we can read/write files and that proper folders exist.
    4247    if ( ! $filesystem->exists( untrailingslashit( WP_CONTENT_DIR ) . '/cache' ) ) {
    4348        if ( ! $filesystem->mkdir( untrailingslashit( WP_CONTENT_DIR ) . '/cache' ) ) {
     
    7580    }
    7681
    77     $modified_time = time(); // Make sure modified time is consistent
     82    $modified_time = time(); // Make sure modified time is consistent.
     83
     84    // Prevent mixed content when there's an http request but the site URL uses https.
     85    $home_url = get_home_url();
     86    if ( ! is_ssl() && 'https' === strtolower( parse_url( $home_url, PHP_URL_SCHEME ) ) ) {
     87        $https_home_url = $home_url;
     88        $http_home_url  = str_replace( 'https://', 'http://', $https_home_url );
     89        $buffer         = str_replace( esc_url( $http_home_url ), esc_url( $https_home_url ), $buffer );
     90    }
    7891
    7992    if ( preg_match( '#</html>#i', $buffer ) ) {
     
    89102    }
    90103
    91     header( 'Cache-Control: no-cache' ); // Check back every time to see if re-download is necessary
     104    header( 'Cache-Control: no-cache' ); // Check back every time to see if re-download is necessary.
    92105
    93106    header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $modified_time ) . ' GMT' );
     
    129142    $modified_time = (int) @filemtime( $path );
    130143
    131     header( 'Cache-Control: no-cache' ); // Check back in an hour
    132 
    133     if ( ! empty( $modified_time ) && ! empty( $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ] ) && strtotime( $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ] ) === $modified_time ) {
     144    header( 'Cache-Control: no-cache' ); // Check back in an hour.
     145
     146    if ( ! empty( $modified_time ) && ! empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) && strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) === $modified_time ) {
    134147        if ( function_exists( 'gzencode' ) && ! empty( $GLOBALS['sc_config']['enable_gzip_compression'] ) ) {
    135148            header( 'Content-Encoding: gzip' );
     
    154167 * Return true of exception url matches current url
    155168 *
    156  * @param  string $exception
    157  * @param  bool   $regex
     169 * @param  string $exception Exceptions to check URL against.
     170 * @param  bool   $regex Whether to check with regex or not.
    158171 * @since  1.6
    159172 * @return boolean
     
    190203            }
    191204        }
    192 
    193205    } else {
    194206        $path = $_SERVER['REQUEST_URI'];
  • simple-cache/trunk/inc/dropins/file-based-page-cache.php

    r1570775 r1877792  
    11<?php
     2/**
     3 * File based page cache drop in
     4 *
     5 * @package  simple-cache
     6 */
     7
    28defined( 'ABSPATH' ) || exit;
    39
    410require_once( dirname( __FILE__ ) . '/file-based-page-cache-functions.php' );
    511
    6 // Don't cache robots.txt or htacesss
     12// Don't cache robots.txt or htacesss.
    713if ( strpos( $_SERVER['REQUEST_URI'], 'robots.txt' ) !== false || strpos( $_SERVER['REQUEST_URI'], '.htaccess' ) !== false ) {
    814    return;
    915}
    1016
    11 // Don't cache non-GET requests
    12 if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || $_SERVER['REQUEST_METHOD'] !== 'GET' ) {
     17// Don't cache non-GET requests.
     18if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || 'GET' !== $_SERVER['REQUEST_METHOD'] ) {
    1319    return;
    1420}
     
    2329}
    2430
    25 // Don't cache if logged in
     31// Don't cache if logged in.
    2632if ( ! empty( $_COOKIE ) ) {
    2733    $wp_cookies = array( 'wordpressuser_', 'wordpresspass_', 'wordpress_sec_', 'wordpress_logged_in_' );
     
    3844    if ( ! empty( $_COOKIE['sc_commented_posts'] ) ) {
    3945        foreach ( $_COOKIE['sc_commented_posts'] as $path ) {
    40             if ( rtrim( $path, '/') === rtrim( $_SERVER['REQUEST_URI'], '/' ) ) {
    41                 // User commented on this post
     46            if ( rtrim( $path, '/' ) === rtrim( $_SERVER['REQUEST_URI'], '/' ) ) {
     47                // User commented on this post.
    4248                return;
    4349            }
     
    4652}
    4753
    48 // Deal with optional cache exceptions
     54// Deal with optional cache exceptions.
    4955if ( ! empty( $GLOBALS['sc_config']['advanced_mode'] ) && ! empty( $GLOBALS['sc_config']['cache_exception_urls'] ) ) {
    5056    $exceptions = preg_split( '#(\n|\r)#', $GLOBALS['sc_config']['cache_exception_urls'] );
     
    5460    foreach ( $exceptions as $exception ) {
    5561        if ( sc_url_exception_match( $exception, $regex ) ) {
    56             // Exception match
     62            // Exception match.
    5763            return;
    5864        }
  • simple-cache/trunk/inc/dropins/memcached-object-cache.php

    r1456175 r1877792  
    11<?php
     2/**
     3 * Memcached drop in
     4 *
     5 * @package  simple-cache
     6 */
     7
    28defined( 'ABSPATH' ) || exit;
    39
     
    115121    var $no_mc_groups = array();
    116122
    117     var $cache = array();
    118     var $mc = array();
    119     var $stats = array();
     123    var $cache     = array();
     124    var $mc        = array();
     125    var $stats     = array();
    120126    var $group_ops = array();
    121127
    122     var $cache_enabled = true;
     128    var $cache_enabled      = true;
    123129    var $default_expiration = 0;
    124130
     
    138144        }
    139145
    140         $mc =& $this->get_mc( $group );
    141         $expire = ($expire == 0) ? $this->default_expiration : $expire;
     146        $mc     =& $this->get_mc( $group );
     147        $expire = ( $expire == 0 ) ? $this->default_expiration : $expire;
    142148        $result = $mc->add( $key, $data, false, $expire );
    143149
     
    145151            @ ++$this->stats['add'];
    146152            $this->group_ops[ $group ][] = "add $id";
    147             $this->cache[ $key ] = $data;
     153            $this->cache[ $key ]         = $data;
    148154        }
    149155
     
    173179    function incr( $id, $n = 1, $group = 'default' ) {
    174180
    175         $key = $this->key( $id, $group );
    176         $mc =& $this->get_mc( $group );
     181        $key                 = $this->key( $id, $group );
     182        $mc                  =& $this->get_mc( $group );
    177183        $this->cache[ $key ] = $mc->increment( $key, $n );
    178184        return $this->cache[ $key ];
     
    181187    function decr( $id, $n = 1, $group = 'default' ) {
    182188
    183         $key = $this->key( $id, $group );
    184         $mc =& $this->get_mc( $group );
     189        $key                 = $this->key( $id, $group );
     190        $mc                  =& $this->get_mc( $group );
    185191        $this->cache[ $key ] = $mc->decrement( $key, $n );
    186192        return $this->cache[ $key ];
     
    228234
    229235        $key = $this->key( $id, $group );
    230         $mc =& $this->get_mc( $group );
     236        $mc  =& $this->get_mc( $group );
    231237
    232238        if ( isset( $this->cache[ $key ] ) && ( ! $force || in_array( $group, $this->no_mc_groups ) ) ) {
     
    236242                $value = $this->cache[ $key ];
    237243            }
    238         } else if ( in_array( $group, $this->no_mc_groups ) ) {
     244        } elseif ( in_array( $group, $this->no_mc_groups ) ) {
    239245            $this->cache[ $key ] = $value = false;
    240246        } else {
     
    260266
    261267        /*
    262         format: $get['group-name'] = array( 'key1', 'key2' );
    263         */
     268        format: $get['group-name'] = array( 'key1', 'key2' );
     269        */
    264270        $return = array();
    265271        foreach ( $groups as $group => $ids ) {
     
    274280                    }
    275281                    continue;
    276                 } else if ( in_array( $group, $this->no_mc_groups ) ) {
     282                } elseif ( in_array( $group, $this->no_mc_groups ) ) {
    277283                    $return[ $key ] = false;
    278284                    continue;
     
    282288            }
    283289            if ( $to_get ) {
    284                 $vals = $mc->get_multi( $to_get );
     290                $vals   = $mc->get_multi( $to_get );
    285291                $return = array_merge( $return, $vals );
    286292            }
     
    288294        @ ++$this->stats['get_multi'];
    289295        $this->group_ops[ $group ][] = "get_multi $id";
    290         $this->cache = array_merge( $this->cache, $return );
     296        $this->cache                 = array_merge( $this->cache, $return );
    291297        return $return;
    292298    }
     
    309315    function replace( $id, $data, $group = 'default', $expire = 0 ) {
    310316
    311         $key = $this->key( $id, $group );
    312         $expire = ($expire == 0) ? $this->default_expiration : $expire;
    313         $mc =& $this->get_mc( $group );
     317        $key    = $this->key( $id, $group );
     318        $expire = ( $expire == 0 ) ? $this->default_expiration : $expire;
     319        $mc     =& $this->get_mc( $group );
    314320
    315321        if ( is_object( $data ) ) {
     
    327333
    328334        $key = $this->key( $id, $group );
    329         if ( isset( $this->cache[ $key ] ) && ('checkthedatabaseplease' === $this->cache[ $key ]) ) {
     335        if ( isset( $this->cache[ $key ] ) && ( 'checkthedatabaseplease' === $this->cache[ $key ] ) ) {
    330336            return false;
    331337        }
     
    341347        }
    342348
    343         $expire = ($expire == 0) ? $this->default_expiration : $expire;
    344         $mc =& $this->get_mc( $group );
     349        $expire = ( $expire == 0 ) ? $this->default_expiration : $expire;
     350        $mc     =& $this->get_mc( $group );
    345351        $result = $mc->set( $key, $data, false, $expire );
    346352
     
    352358        global $table_prefix;
    353359
    354         $blog_id = (int) $blog_id;
     360        $blog_id           = (int) $blog_id;
    355361        $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':';
    356362    }
     
    359365
    360366        $colors = array(
    361         'get' => 'green',
    362         'set' => 'purple',
    363         'add' => 'blue',
    364         'delete' => 'red',
     367            'get'    => 'green',
     368            'set'    => 'purple',
     369            'add'    => 'blue',
     370            'delete' => 'red',
    365371        );
    366372
     
    407413    function failure_callback( $host, $port ) {
    408414
    409         //error_log("Connection failure for $host:$port\n", 3, '/tmp/memcached.txt');
     415        // error_log("Connection failure for $host:$port\n", 3, '/tmp/memcached.txt');
    410416    }
    411417
     
    427433        foreach ( $buckets as $bucket => $servers ) {
    428434            $this->mc[ $bucket ] = new Memcache();
    429             foreach ( $servers as $server  ) {
     435            foreach ( $servers as $server ) {
    430436                if ( 'unix://' == substr( $server, 0, 7 ) ) {
    431437                    $node = $server;
     
    448454        global $blog_id, $table_prefix;
    449455        $this->global_prefix = '';
    450         $this->blog_prefix = '';
     456        $this->blog_prefix   = '';
    451457        if ( function_exists( 'is_multisite' ) ) {
    452458            $this->global_prefix = ( is_multisite() || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix;
    453             $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':';
    454         }
    455 
    456         $this->cache_hits =& $this->stats['get'];
     459            $this->blog_prefix   = ( is_multisite() ? $blog_id : $table_prefix ) . ':';
     460        }
     461
     462        $this->cache_hits   =& $this->stats['get'];
    457463        $this->cache_misses =& $this->stats['add'];
    458464    }
    459465}
    460 ?>
     466
  • simple-cache/trunk/inc/dropins/redis-object-cache.php

    r1397513 r1877792  
    11<?php
     2/**
     3 * Redis cache drop in
     4 *
     5 * @package  simple-cache
     6 */
     7
    28defined( 'ABSPATH' ) || exit;
    39
     
    1218
    1319// This file needs to be symlinked or copied to wp-content/object-cache.php
    14 
    1520// Users with setups where multiple installs share a common wp-config.php or $table_prefix
    1621// can use this to guarantee uniqueness for the keys generated by this object cache
     
    396401        $groups = (array) $groups;
    397402
    398         $groups = array_fill_keys( $groups, true );
     403        $groups              = array_fill_keys( $groups, true );
    399404        $this->global_groups = array_merge( $this->global_groups, $groups );
    400405    }
     
    409414        $groups = (array) $groups;
    410415
    411         $groups = array_fill_keys( $groups, true );
     416        $groups                      = array_fill_keys( $groups, true );
    412417        $this->non_persistent_groups = array_merge( $this->non_persistent_groups, $groups );
    413418    }
     
    451456        if ( self::USE_GROUPS ) {
    452457            $redis_safe_group = $this->_key( '', $group );
    453             $result = $this->_call_redis( 'hIncrBy', $redis_safe_group, $key, -$offset, $group );
     458            $result           = $this->_call_redis( 'hIncrBy', $redis_safe_group, $key, -$offset, $group );
    454459            if ( $result < 0 ) {
    455460                $result = 0;
     
    457462            }
    458463        } else {
    459             $id = $this->_key( $key, $group );
     464            $id     = $this->_key( $key, $group );
    460465            $result = $this->_call_redis( 'decrBy', $id, $offset );
    461466            if ( $result < 0 ) {
     
    497502            if ( self::USE_GROUPS ) {
    498503                $redis_safe_group = $this->_key( '', $group );
    499                 $result = $this->_call_redis( 'hDel', $redis_safe_group, $key );
     504                $result           = $this->_call_redis( 'hDel', $redis_safe_group, $key );
    500505            } else {
    501                 $id = $this->_key( $key, $group );
     506                $id     = $this->_key( $key, $group );
    502507                $result = $this->_call_redis( 'delete', $id );
    503508            }
     
    524529
    525530        $multisite_safe_group = $this->multisite && ! isset( $this->global_groups[ $group ] ) ? $this->blog_prefix . $group : $group;
    526         $redis_safe_group = $this->_key( '', $group );
     531        $redis_safe_group     = $this->_key( '', $group );
    527532        if ( $this->_should_persist( $group ) ) {
    528533            $result = $this->_call_redis( 'delete', $redis_safe_group );
     
    530535                return false;
    531536            }
    532         } else if ( ! $this->_should_persist( $group ) && ! isset( $this->cache[ $multisite_safe_group ] ) ) {
     537        } elseif ( ! $this->_should_persist( $group ) && ! isset( $this->cache[ $multisite_safe_group ] ) ) {
    533538            return false;
    534539        }
     
    589594            if ( self::USE_GROUPS ) {
    590595                $redis_safe_group = $this->_key( '', $group );
    591                 $value = $this->_call_redis( 'hGet', $redis_safe_group, $key );
     596                $value            = $this->_call_redis( 'hGet', $redis_safe_group, $key );
    592597            } else {
    593                 $id = $this->_key( $key, $group );
     598                $id    = $this->_key( $key, $group );
    594599                $value = $this->_call_redis( 'get', $id );
    595600            }
     
    640645        if ( self::USE_GROUPS ) {
    641646            $redis_safe_group = $this->_key( '', $group );
    642             $result = $this->_call_redis( 'hIncrBy', $redis_safe_group, $key, $offset, $group );
     647            $result           = $this->_call_redis( 'hIncrBy', $redis_safe_group, $key, $offset, $group );
    643648            if ( $result < 0 ) {
    644649                $result = 0;
     
    646651            }
    647652        } else {
    648             $id = $this->_key( $key, $group );
     653            $id     = $this->_key( $key, $group );
    649654            $result = $this->_call_redis( 'incrBy', $id, $offset );
    650655            if ( $result < 0 ) {
     
    662667    /**
    663668     * Replace the contents in the cache, if contents already exist
    664     *
     669     *
    665670     * @see WP_Object_Cache::set()
    666671     *
     
    777782    public function switch_to_blog( $blog_id ) {
    778783
    779         $blog_id = (int) $blog_id;
     784        $blog_id           = (int) $blog_id;
    780785        $this->blog_prefix = $this->multisite ? $blog_id . ':' : '';
    781786    }
     
    864869            $this->cache[ $multisite_safe_group ][ $key ] = $value;
    865870        } else {
    866             $key = $this->_key( $key, $group );
     871            $key                 = $this->_key( $key, $group );
    867872            $this->cache[ $key ] = $value;
    868873        }
     
    939944            if ( isset( $_SERVER['CACHE_HOST'] ) ) {
    940945                $redis_server = array(
    941                 'host' => $_SERVER['CACHE_HOST'],
    942                 'port' => $_SERVER['CACHE_PORT'],
    943                 'auth' => $_SERVER['CACHE_PASSWORD'],
     946                    'host' => $_SERVER['CACHE_HOST'],
     947                    'port' => $_SERVER['CACHE_PORT'],
     948                    'auth' => $_SERVER['CACHE_PASSWORD'],
    944949                );
    945950            } else {
    946951                $redis_server = array(
    947                 'host' => '127.0.0.1',
    948                 'port' => 6379,
     952                    'host' => '127.0.0.1',
     953                    'port' => 6379,
    949954                );
    950955            }
     
    953958        $this->redis = new Redis;
    954959
    955         if ( file_exists( $redis_server['host'] ) && 'socket' === filetype( $redis_server['host'] ) ) { //unix socket connection
    956             //port must be null or socket won't connect
     960        if ( file_exists( $redis_server['host'] ) && 'socket' === filetype( $redis_server['host'] ) ) { // unix socket connection
     961            // port must be null or socket won't connect
    957962            $port = null;
    958         } else { //tcp connection
     963        } else { // tcp connection
    959964            $port = ! empty( $redis_server['port'] ) ? $redis_server['port'] : 6379;
    960965        }
     
    10251030                    return call_user_func_array( array( $this, '_call_redis' ), array_merge( array( $method ), $arguments ) );
    10261031                }
    1027 
    10281032            }
    10291033        }
     
    10331037            case 'incr':
    10341038            case 'incrBy':
    1035                 $val = $this->cache[ $arguments[0] ];
     1039                $val    = $this->cache[ $arguments[0] ];
    10361040                $offset = isset( $arguments[1] ) && 'incrBy' === $method ? $arguments[1] : 1;
    1037                 $val = $val + $offset;
    1038             return $val;
     1041                $val    = $val + $offset;
     1042                return $val;
    10391043            case 'hIncrBy':
    10401044                $val = $this->_get_internal( $arguments[1], $group );
    1041             return $val + $arguments[2];
     1045                return $val + $arguments[2];
    10421046            case 'decrBy':
    10431047            case 'decr':
    1044                 $val = $this->cache[ $arguments[0] ];
     1048                $val    = $this->cache[ $arguments[0] ];
    10451049                $offset = isset( $arguments[1] ) && 'decrBy' === $method ? $arguments[1] : 1;
    1046                 $val = $val - $offset;
    1047             return $val;
     1050                $val    = $val - $offset;
     1051                return $val;
    10481052            case 'delete':
    10491053            case 'hDel':
    1050             return 1;
     1054                return 1;
    10511055            case 'flushAll':
    10521056            case 'IsConnected':
    10531057            case 'exists':
    1054             return false;
     1058                return false;
    10551059        }
    10561060
     
    10631067     */
    10641068    public function __construct() {
    1065         global $table_prefix;
    1066 
    1067         $this->multisite = is_multisite();
     1069        global $table_prefix, $blog_id;
     1070
     1071        $this->multisite   = is_multisite();
    10681072        $this->blog_prefix = $this->multisite ? $blog_id . ':' : '';
    10691073
    10701074        $this->global_prefix = ( $this->multisite || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix;
    1071 
    10721075
    10731076        $this->_connect_redis();
  • simple-cache/trunk/inc/functions.php

    r1403511 r1877792  
    11<?php
     2/**
     3 * Utility functions for plugin
     4 *
     5 * @package  simple-cache
     6 */
    27
    38/**
     
    914    global $wp_filesystem;
    1015
    11     require_once( ABSPATH . 'wp-admin/includes/file.php');
     16    require_once( ABSPATH . 'wp-admin/includes/file.php' );
    1217
    1318    WP_Filesystem();
  • simple-cache/trunk/languages/simple-cache.pot

    r1570845 r1877792  
    1 # Copyright (C) 2014 Taylor Lovett
    2 # This file is distributed under the same license as the Editorial Access Manager package.
    3 #, fuzzy
     1# Copyright (C) 2018 Simple Cache
     2# This file is distributed under the same license as the Simple Cache package.
    43msgid ""
    54msgstr ""
    65"Project-Id-Version: Simple Cache\n"
    7 "Report-Msgid-Bugs-To: https://github.com/tlovett1/custom-contact-forms/"
    8 "issues\n"
    9 "POT-Creation-Date: 2017-01-08 21:45-0500\n"
    10 "PO-Revision-Date: 2016-04-11 01:17-0400\n"
    11 "Last-Translator: Taylor Lovett <tlovett88@gmail.com>\n"
    12 "Language-Team: \n"
    13 "Language: en\n"
    146"MIME-Version: 1.0\n"
    157"Content-Type: text/plain; charset=UTF-8\n"
    168"Content-Transfer-Encoding: 8bit\n"
    17 "X-Generator: Poedit 1.8.6\n"
    18 "Plural-Forms: nplurals=2; plural=n != 1;\n"
    199"X-Poedit-Basepath: ..\n"
     10"X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
     11"X-Poedit-SearchPath-0: .\n"
     12"X-Poedit-SearchPathExcluded-0: *.js\n"
    2013"X-Poedit-SourceCharset: UTF-8\n"
    21 "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
    22 "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;"
    23 "esc_html_e;esc_html__;esc_attr__;esc_attr_e\n"
    24 "X-Textdomain-Support: yes\n"
    25 "X-Poedit-SearchPath-0: .\n"
    26 "X-Poedit-SearchPathExcluded-0: node_modules\n"
    27 "X-Poedit-SearchPathExcluded-1: vendor\n"
     14"Plural-Forms: nplurals=2; plural=(n != 1);\n"
    2815
    29 #: inc/class-sc-advanced-cache.php:162
     16#. translators: Param 1 is link to settings page.
     17#: simple-cache.php:58
     18msgid "<a href=\"%s\">Settings</a>"
     19msgstr ""
     20
     21#: inc/class-sc-advanced-cache.php:167
    3022msgid "define(\"WP_CACHE\", true); is not in wp-config.php."
    3123msgstr ""
    3224
    33 #: inc/class-sc-advanced-cache.php:166
     25#: inc/class-sc-advanced-cache.php:171
    3426msgid "wp-content/advanced-cache.php was edited or deleted."
    3527msgstr ""
    3628
    37 #: inc/class-sc-advanced-cache.php:169
     29#: inc/class-sc-advanced-cache.php:174
    3830msgid "Simple Cache is not able to utilize page caching."
    3931msgstr ""
    4032
    41 #: inc/class-sc-advanced-cache.php:171 inc/class-sc-object-cache.php:44
     33#: inc/class-sc-advanced-cache.php:176, inc/class-sc-object-cache.php:53
    4234msgid "Fix"
    4335msgstr ""
    4436
    45 #: inc/class-sc-cron.php:41
     37#: inc/class-sc-cron.php:55
    4638msgid "Simple Cache Purge Interval"
    4739msgstr ""
    4840
    49 #: inc/class-sc-object-cache.php:42
    50 msgid ""
    51 "wp-content/object-cache.php was edited or deleted. Simple Cache is not able "
    52 "to utilize object caching."
    53 msgstr ""
    54 
    55 #: inc/class-sc-settings.php:43 inc/class-sc-settings.php:403
     41#: inc/class-sc-settings.php:49, inc/class-sc-settings.php:428
    5642msgid "Purge Cache"
    5743msgstr ""
    5844
    59 #: inc/class-sc-settings.php:69
     45#: inc/class-sc-settings.php:80
    6046msgid "Simple Cache won't work until you turn it on."
    6147msgstr ""
    6248
    63 #: inc/class-sc-settings.php:70
     49#: inc/class-sc-settings.php:81
    6450msgid "Turn On Caching"
    6551msgstr ""
    6652
    67 #: inc/class-sc-settings.php:94
    68 msgid ""
    69 "Simple Cache can't create or modify needed files on your system. "
    70 "Specifically, Simple Cache needs to write to wp-config.php and /wp-content "
    71 "using PHP's fopen() function. Contact your host."
     53#: inc/class-sc-settings.php:103
     54msgid "Simple Cache can't create or modify needed files on your system. Specifically, Simple Cache needs to write to wp-config.php and /wp-content using PHP's fopen() function. Contact your host."
    7255msgstr ""
    7356
    74 #: inc/class-sc-settings.php:95
     57#: inc/class-sc-settings.php:104
    7558msgid "Try Again"
    7659msgstr ""
    7760
    78 #: inc/class-sc-settings.php:132
     61#: inc/class-sc-settings.php:140, inc/class-sc-settings.php:140
    7962msgid "Simple Cache"
    8063msgstr ""
    8164
    82 #: inc/class-sc-settings.php:166
     65#: inc/class-sc-settings.php:152, inc/class-sc-settings.php:174
    8366msgid "Cheatin, eh?"
    8467msgstr ""
    8568
    86 #: inc/class-sc-settings.php:246
     69#: inc/class-sc-settings.php:254
    8770msgid "Simple Cache Settings"
    8871msgstr ""
    8972
    90 #: inc/class-sc-settings.php:254
     73#: inc/class-sc-settings.php:262
    9174msgid "Enable Advanced Mode"
    9275msgstr ""
    9376
    94 #: inc/class-sc-settings.php:256 inc/class-sc-settings.php:267
    95 #: inc/class-sc-settings.php:286 inc/class-sc-settings.php:309
    96 #: inc/class-sc-settings.php:326 inc/class-sc-settings.php:351
    97 #: inc/class-sc-settings.php:390
     77#: inc/class-sc-settings.php:264, inc/class-sc-settings.php:275, inc/class-sc-settings.php:300, inc/class-sc-settings.php:323, inc/class-sc-settings.php:340, inc/class-sc-settings.php:372, inc/class-sc-settings.php:415
    9878msgid "No"
    9979msgstr ""
    10080
    101 #: inc/class-sc-settings.php:257 inc/class-sc-settings.php:268
    102 #: inc/class-sc-settings.php:287 inc/class-sc-settings.php:310
    103 #: inc/class-sc-settings.php:327 inc/class-sc-settings.php:352
    104 #: inc/class-sc-settings.php:391
     81#: inc/class-sc-settings.php:265, inc/class-sc-settings.php:276, inc/class-sc-settings.php:301, inc/class-sc-settings.php:324, inc/class-sc-settings.php:341, inc/class-sc-settings.php:373, inc/class-sc-settings.php:416
    10582msgid "Yes"
    10683msgstr ""
    10784
    108 #: inc/class-sc-settings.php:264
     85#: inc/class-sc-settings.php:272
    10986msgid "Enable Caching"
    11087msgstr ""
    11188
    112 #: inc/class-sc-settings.php:271
    113 msgid ""
    114 "Turn this on to get started. This setting turns on caching and is really all "
    115 "you need."
     89#: inc/class-sc-settings.php:279
     90msgid "Turn this on to get started. This setting turns on caching and is really all you need."
    11691msgstr ""
    11792
    118 #: inc/class-sc-settings.php:275
     93#: inc/class-sc-settings.php:283
    11994msgid "Expire the cache after"
    12095msgstr ""
    12196
    122 #: inc/class-sc-settings.php:277 inc/class-sc-settings.php:337
     97#: inc/class-sc-settings.php:287, inc/class-sc-settings.php:354
    12398msgid "minutes"
    12499msgstr ""
    125100
    126 #: inc/class-sc-settings.php:283
     101#: inc/class-sc-settings.php:288, inc/class-sc-settings.php:355
     102msgid "hours"
     103msgstr ""
     104
     105#: inc/class-sc-settings.php:289, inc/class-sc-settings.php:356
     106msgid "days"
     107msgstr ""
     108
     109#: inc/class-sc-settings.php:290, inc/class-sc-settings.php:357
     110msgid "weeks"
     111msgstr ""
     112
     113#: inc/class-sc-settings.php:297
    127114msgid "Enable Compression"
    128115msgstr ""
    129116
    130 #: inc/class-sc-settings.php:290
    131 msgid ""
    132 "When enabled, pages will be compressed. This is a good thing! This should "
    133 "always be enabled unless it causes issues."
     117#: inc/class-sc-settings.php:304
     118msgid "When enabled, pages will be compressed. This is a good thing! This should always be enabled unless it causes issues."
    134119msgstr ""
    135120
    136 #: inc/class-sc-settings.php:301
     121#: inc/class-sc-settings.php:315
    137122msgid "Page Cache"
    138123msgstr ""
    139124
    140 #: inc/class-sc-settings.php:306
     125#: inc/class-sc-settings.php:320
    141126msgid "Enable Page Caching"
    142127msgstr ""
    143128
    144 #: inc/class-sc-settings.php:313
     129#: inc/class-sc-settings.php:327
    145130msgid "When enabled, entire front end pages will be cached."
    146131msgstr ""
    147132
    148 #: inc/class-sc-settings.php:318
     133#: inc/class-sc-settings.php:332
    149134msgid "Exception URL(s)"
    150135msgstr ""
    151136
    152 #: inc/class-sc-settings.php:322
    153 msgid ""
    154 "Allows you to add URL(s) to be exempt from page caching. One URL per line. "
    155 "URL(s) can be full URLs (http://google.com) or absolute paths (/my/url/). "
    156 "You can also use wildcards like so /url/* (matches any url starting with /"
    157 "url/)."
     137#: inc/class-sc-settings.php:336
     138msgid "Allows you to add URL(s) to be exempt from page caching. One URL per line. URL(s) can be full URLs (http://google.com) or absolute paths (/my/url/). You can also use wildcards like so /url/* (matches any url starting with /url/)."
    158139msgstr ""
    159140
    160 #: inc/class-sc-settings.php:329
     141#: inc/class-sc-settings.php:343
    161142msgid "Enable Regex"
    162143msgstr ""
    163144
    164 #: inc/class-sc-settings.php:335
     145#: inc/class-sc-settings.php:349
    165146msgid "Expire page cache after"
    166147msgstr ""
    167148
    168 #: inc/class-sc-settings.php:342
     149#: inc/class-sc-settings.php:363
    169150msgid "Object Cache (Redis or Memcache)"
    170151msgstr ""
    171152
    172 #: inc/class-sc-settings.php:348
     153#: inc/class-sc-settings.php:369
    173154msgid "Enable In-Memory Object Caching"
    174155msgstr ""
    175156
    176 #: inc/class-sc-settings.php:355
    177 msgid ""
    178 "When enabled, things like database query results will be stored in memory. "
    179 "Right now Memcache and Redis are suppported. Note that if the proper <a "
    180 "href='https://pecl.php.net/package/memcache'>Memcache</a> (NOT Memcached) or "
    181 "<a href='https://pecl.php.net/package/redis'>Redis</a> PHP extensions aren't "
    182 "loaded, they won't show as options below."
     157#: inc/class-sc-settings.php:376
     158msgid "When enabled, things like database query results will be stored in memory. Right now Memcache and Redis are suppported. Note that if the proper <a href='https://pecl.php.net/package/memcache'>Memcache</a> (NOT Memcached) or <a href='https://pecl.php.net/package/redis'>Redis</a> PHP extensions aren't loaded, they won't show as options below."
    183159msgstr ""
    184160
    185 #: inc/class-sc-settings.php:359
     161#: inc/class-sc-settings.php:384
    186162msgid "In Memory Cache"
    187163msgstr ""
    188164
    189 #: inc/class-sc-settings.php:374
    190 msgid ""
    191 "Neither <a href=\"https://pecl.php.net/package/memcache\">Memcache</a> (NOT "
    192 "Memcached) nor <a href=\"https://pecl.php.net/package/redis\">Redis</a> PHP "
    193 "extensions are set up on your server."
     165#: inc/class-sc-settings.php:399
     166msgid "Neither <a href=\"https://pecl.php.net/package/memcache\">Memcache</a> (NOT Memcached) nor <a href=\"https://pecl.php.net/package/redis\">Redis</a> PHP extensions are set up on your server."
    194167msgstr ""
    195168
    196 #: inc/class-sc-settings.php:381
     169#: inc/class-sc-settings.php:406
    197170msgid "Compression"
    198171msgstr ""
    199172
    200 #: inc/class-sc-settings.php:387
     173#: inc/class-sc-settings.php:412
    201174msgid "Enable gzip Compression"
    202175msgstr ""
    203176
    204 #: inc/class-sc-settings.php:394
    205 msgid ""
    206 "When enabled pages will be gzip compressed at the PHP level. Note many hosts "
    207 "set up gzip compression in Apache or nginx."
     177#: inc/class-sc-settings.php:419
     178msgid "When enabled pages will be gzip compressed at the PHP level. Note many hosts set up gzip compression in Apache or nginx."
    208179msgstr ""
    209180
    210 #: inc/class-sc-settings.php:402
     181#: inc/class-sc-settings.php:427
    211182msgid "Save Changes"
    212183msgstr ""
    213 
    214 #: simple-cache.php:55
    215 #, php-format
    216 msgid "<a href=\"%s\">Settings</a>"
    217 msgstr ""
  • simple-cache/trunk/readme.txt

    r1643085 r1877792  
    11=== Simple Cache ===
    22Contributors: tlovett1
    3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HR34W94MM53RQ
    43Tags: cache, page cache, object caching, object cache, memcache, redis, memcached
    54Requires at least: 3.9
    6 Tested up to: 4.8
     5Tested up to: 5.0
    76Stable tag: trunk
    87License: GPLv2 or later
     
    3736
    3837== Changelog ==
     38
     39= 1.6.4 =
     40* Fix undefined `$blog_id` warning in redis object cache.
     41* Prevent mixed content. Props [benoitchantre](https://github.com/benoitchantre).
     42* Added WP_CACHE_KEY_SALT constant with a random value. Props [gagan0123](https://github.com/gagan0123 ).
    3943
    4044= 1.6.3 =
  • simple-cache/trunk/simple-cache.php

    r1643085 r1877792  
    55 * Description: A simple caching plugin that just works.
    66 * Author: Taylor Lovett
    7  * Version: 1.6.3
     7 * Version: 1.6.4
    88 * Text Domain: simple-cache
    99 * Domain Path: /languages
    1010 * Author URI: http://taylorlovett.com
     11 *
     12 * @package  simple-cache
    1113 */
    1214
    1315defined( 'ABSPATH' ) || exit;
    1416
    15 define( 'SC_VERSION', '1.6.3' );
     17define( 'SC_VERSION', '1.6.4' );
    1618
    1719require_once dirname( __FILE__ ) . '/inc/functions.php';
     
    4345 * Add settings link to plugin actions
    4446 *
    45  * @param  array  $plugin_actions
    46  * @param  string $plugin_file
     47 * @param  array  $plugin_actions Each action is HTML.
     48 * @param  string $plugin_file Path to plugin file.
    4749 * @since  1.0
    4850 * @return array
     
    5355
    5456    if ( basename( dirname( __FILE__ ) ) . '/simple-cache.php' === $plugin_file ) {
     57        /* translators: Param 1 is link to settings page. */
    5558        $new_actions['sc_settings'] = sprintf( __( '<a href="%s">Settings</a>', 'simple-cache' ), esc_url( admin_url( 'options-general.php?page=simple-cache' ) ) );
    5659    }