Changeset 1877792 – WordPress Plugin Repository
- ️Sun Jan 08 2017
-
simple-cache/trunk/README.md
r1388942 r1877792 1 Simple Cache 1 Simple Cache [](https://travis-ci.org/tlovett1/simple-cache) 2 2 =============== 3 3 -
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 22 22 var pageCacheLengthSimple = document.getElementById( 'sc_page_cache_length_simple' ); 23 23 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' ); 24 26 var gzipCompressionSimple = document.getElementById( 'sc_enable_gzip_compression_simple' ); 25 27 var gzipCompressionAdvanced = document.getElementById( 'sc_enable_gzip_compression_advanced' ); … … 37 39 pageCacheLengthAdvanced.disabled = false; 38 40 41 pageCacheLengthUnitSimple.disabled = true; 42 pageCacheLengthUnitAdvanced.disabled = false; 43 39 44 if ( gzipCompressionSimple ) { 40 45 gzipCompressionSimple.disabled = true; … … 51 56 pageCacheLengthAdvanced.disabled = true; 52 57 58 pageCacheLengthUnitSimple.disabled = false; 59 pageCacheLengthUnitAdvanced.disabled = true; 60 53 61 if (gzipCompressionSimple) { 54 62 gzipCompressionSimple.disabled = false; -
simple-cache/trunk/inc/class-sc-advanced-cache.php
r1643085 r1877792 1 1 <?php 2 /** 3 * Page caching functionality 4 * 5 * @package simple-cache 6 */ 7 2 8 defined( 'ABSPATH' ) || exit; 3 9 10 /** 11 * Wrapper for advanced cache functionality 12 */ 4 13 class SC_Advanced_Cache { 5 14 … … 15 24 add_action( 'save_post', array( $this, 'purge_post_on_update' ), 10, 1 ); 16 25 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 ); 19 28 } 20 29 … … 22 31 * When user posts a comment, set a cookie so we don't show them page cache 23 32 * 24 * @param WP_Comment $comment 25 * @param WP_User $user 33 * @param WP_Comment $comment Comment to check. 26 34 * @since 1.3 27 35 */ 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. 32 40 if ( ! empty( $config['enable_page_caching'] ) && empty( $config['enable_in_memory_object_caching'] ) ) { 33 41 $post_id = $comment->comment_post_ID; … … 40 48 * Every time a comments status changes, purge it's parent posts cache 41 49 * 42 * @param int $comment_ID 43 * @param int $comment_status 50 * @param int $comment_id Comment ID. 44 51 * @since 1.3 45 52 */ 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. 50 57 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 ); 54 61 $post_id = $comment->comment_post_ID; 55 62 … … 68 75 * Purge post cache when there is a new approved comment 69 76 * 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. 73 80 * @since 1.3 74 81 */ 75 public function purge_post_on_comment( $comment_ID, $approved, $commentdata ) { 82 public function purge_post_on_comment( $comment_id, $approved, $commentdata ) { 76 83 if ( empty( $approved ) ) { 77 84 return; … … 80 87 $config = SC_Config::factory()->get(); 81 88 82 // File based caching only 89 // File based caching only. 83 90 if ( ! empty( $config['enable_page_caching'] ) && empty( $config['enable_in_memory_object_caching'] ) ) { 84 91 $post_id = $commentdata['comment_post_ID']; … … 98 105 * Automatically purge all file based page cache on post changes 99 106 * 100 * @param int $post_id 107 * @param int $post_id Post id. 101 108 * @since 1.3 102 109 */ … … 112 119 $config = SC_Config::factory()->get(); 113 120 114 // File based caching only 121 // File based caching only. 115 122 if ( ! empty( $config['enable_page_caching'] ) && empty( $config['enable_in_memory_object_caching'] ) ) { 116 123 sc_cache_flush(); … … 134 141 135 142 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; 141 148 $advanced_cache_file_bad = true; 142 149 … … 171 178 </div> 172 179 173 <?php 180 <?php 174 181 } 175 182 … … 184 191 global $wp_filesystem; 185 192 186 $file = untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php'; 193 $file = untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php'; 187 194 188 195 $ret = true; … … 192 199 } 193 200 194 $folder = untrailingslashit( WP_CONTENT_DIR ) . '/cache/simple-cache'; 201 $folder = untrailingslashit( WP_CONTENT_DIR ) . '/cache/simple-cache'; 195 202 196 203 if ( ! $wp_filesystem->delete( $folder, true ) ) { … … 211 218 global $wp_filesystem; 212 219 213 $file = untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php'; 220 $file = untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php'; 214 221 215 222 $config = SC_Config::factory()->get(); … … 245 252 * Toggle WP_CACHE on or off in wp-config.php 246 253 * 247 * @param boolean $status 254 * @param boolean $status Status of cache. 248 255 * @since 1.0 249 256 * @return boolean … … 257 264 } 258 265 259 $file = '/wp-config.php'; 266 $file = '/wp-config.php'; 260 267 $config_path = false; 261 268 … … 265 272 } 266 273 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; 269 276 break; 270 277 } 271 278 } 272 279 273 // Couldn't find wp-config.php 280 // Couldn't find wp-config.php. 274 281 if ( ! $config_path ) { 275 282 return false; … … 284 291 285 292 $config_file = preg_split( "#(\n|\r)#", $config_file_string ); 286 $line_key = false; 293 $line_key = false; 287 294 288 295 foreach ( $config_file as $key => $line ) { … … 291 298 } 292 299 293 if ( $match[2] == 'WP_CACHE' ) { 300 if ( 'WP_CACHE' === $match[2] ) { 294 301 $line_key = $key; 295 302 } 296 303 } 297 304 298 if ( $line_key !== false ) { 305 if ( false !== $line_key ) { 299 306 unset( $config_file[ $line_key ] ); 300 307 } … … 307 314 foreach ( $config_file as $key => $line ) { 308 315 if ( '' === $line ) { 309 unset( $config_file[$key] ); 316 unset( $config_file[ $key ] ); 310 317 } 311 318 } -
simple-cache/trunk/inc/class-sc-config.php
r1643085 r1877792 1 1 <?php 2 /** 3 * Handle plugin config 4 * 5 * @package simple-cache 6 */ 7 2 8 defined( 'ABSPATH' ) || exit; 3 9 10 /** 11 * Class wrapping config functionality 12 */ 4 13 class SC_Config { 5 14 … … 8 17 * 9 18 * @since 1.0.1 19 * @var array 10 20 */ 11 21 public $defaults = array(); 12 22 13 23 24 /** 25 * Set config defaults 26 * 27 * @since 1.0 28 */ 14 29 public function __construct() { 15 30 16 31 $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( 22 37 'default' => false, 23 38 'sanitizer' => array( $this, 'boolval' ), 24 39 ), 25 40 '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( 46 65 'default' => false, 47 66 'sanitizer' => array( $this, 'boolval' ), … … 53 72 * Make sure we support old PHP with boolval 54 73 * 55 * @param string $value 74 * @param string $value Value to check. 56 75 * @since 1.0 57 76 * @return boolean 58 77 */ 59 78 public function boolval( $value ) { 60 61 79 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'; 62 96 } 63 97 … … 83 117 * 84 118 * @since 1.0 85 * @param array $config 119 * @param array $config Configuration array. 86 120 * @return bool 87 121 */ … … 125 159 * Check if a directory is writable and we can create files as the same user as the current file 126 160 * 127 * @param string $dir 161 * @param string $dir Directory path. 128 162 * @since 1.2.3 129 163 * @return boolean … … 131 165 private function _is_dir_writable( $dir ) { 132 166 $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' ); 134 168 135 169 if ( $temp_handle ) { 136 170 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; 139 174 140 175 if ( function_exists( 'fileowner' ) ) { … … 148 183 149 184 // 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 ) { 151 186 return false; 152 187 } … … 174 209 } 175 210 176 // First check wp-config.php 211 // First check wp-config.php. 177 212 if ( ! @is_writable( ABSPATH . 'wp-config.php' ) && ! @is_writable( ABSPATH . '../wp-config.php' ) ) { 178 213 return false; 179 214 } 180 215 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. 182 217 if ( ! $this->_is_dir_writable( untrailingslashit( WP_CONTENT_DIR ) ) ) { 183 218 return false; 184 219 } 185 220 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. 187 222 if ( @file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/cache' ) ) { 188 223 if ( ! $this->_is_dir_writable( untrailingslashit( WP_CONTENT_DIR ) . '/cache' ) ) { … … 197 232 } 198 233 199 // If the sc-config directory exists, make sure it's writeable 234 // If the sc-config directory exists, make sure it's writeable. 200 235 if ( @file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/sc-config' ) ) { 201 236 if ( ! $this->_is_dir_writable( untrailingslashit( WP_CONTENT_DIR ) . '/sc-config' ) ) { -
simple-cache/trunk/inc/class-sc-cron.php
r1417180 r1877792 1 1 <?php 2 /** 3 * Cron functionality 4 * 5 * @package simple-cache 6 */ 7 2 8 defined( 'ABSPATH' ) || exit; 3 9 10 /** 11 * Wrap cron functionality 12 */ 4 13 class SC_Cron { 5 6 public function __construct() { 7 8 } 9 14 10 15 /** … … 23 28 * Add custom cron schedule 24 29 * 25 * @param array $schedules 30 * @param array $schedules Current cron schedules. 26 31 * @since 1.0 27 32 * @return array … … 34 39 35 40 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 } 37 51 } 38 52 … … 66 80 $timestamp = wp_next_scheduled( 'sc_purge_cache' ); 67 81 68 // Do nothing if we are using the object cache 82 // Do nothing if we are using the object cache. 69 83 if ( ! empty( $config['advanced_mode'] ) && ! empty( $config['enable_in_memory_object_caching'] ) ) { 70 84 wp_unschedule_event( $timestamp, 'sc_purge_cache' ); … … 72 86 } 73 87 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'] ) { 76 90 wp_unschedule_event( $timestamp, 'sc_purge_cache' ); 77 91 return; … … 91 105 $config = SC_Config::factory()->get(); 92 106 93 // Do nothing, caching is turned off 107 // Do nothing, caching is turned off. 94 108 if ( empty( $config['enable_page_caching'] ) ) { 95 109 return; 96 110 } 97 111 98 // Do nothing if we are using the object cache 112 // Do nothing if we are using the object cache. 99 113 if ( ! empty( $config['advanced_mode'] ) && ! empty( $config['enable_in_memory_object_caching'] ) ) { 100 114 return; -
simple-cache/trunk/inc/class-sc-object-cache.php
r1456175 r1877792 1 1 <?php 2 /** 3 * Object cache functionality 4 * 5 * @package simple-cache 6 */ 7 2 8 defined( 'ABSPATH' ) || exit; 3 9 10 /** 11 * Wrap object caching functionality 12 */ 4 13 class SC_Object_Cache { 5 14 … … 38 47 39 48 ?> 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.' ); ?> 43 52 44 53 <a href="options-general.php?page=simple-cache&wp_http_referer=<?php echo esc_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ); ?>&action=sc_update&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> 47 56 <?php 48 57 } … … 58 67 global $wp_filesystem; 59 68 60 $file = untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php'; 69 $file = untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php'; 61 70 62 71 if ( ! $wp_filesystem->delete( $file ) ) { … … 77 86 global $wp_filesystem; 78 87 79 $file = untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php'; 88 $file = untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php'; 80 89 81 90 $config = SC_Config::factory()->get(); … … 90 99 } 91 100 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 92 111 $file_string = '<?php ' . 93 112 "\n\r" . "defined( 'ABSPATH' ) || exit;" . 94 113 "\n\r" . "define( 'SC_OBJECT_CACHE', true );" . 114 "\n\r" . "defined( 'WP_CACHE_KEY_SALT' ) || define( 'WP_CACHE_KEY_SALT', '{$cache_key_salt}' );" . 95 115 "\n\r" . "if ( ! @file_exists( WP_CONTENT_DIR . '/sc-config/config-' . \$_SERVER['HTTP_HOST'] . '.php' ) ) { return; }" . 96 116 "\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 1 1 <?php 2 /** 3 * Settings class 4 * 5 * @package simple-cache 6 */ 7 2 8 defined( 'ABSPATH' ) || exit; 3 9 10 /** 11 * Class containing settings hooks 12 */ 4 13 class SC_Settings { 5 6 public function __construct() { 7 8 } 9 14 10 15 /** … … 37 42 } 38 43 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&wp_http_referer=' . esc_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '&action=sc_purge_cache&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&wp_http_referer=' . esc_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '&action=sc_purge_cache&sc_cache_nonce=' . wp_create_nonce( 'sc_purge_cache' ) ) ), 49 'title' => esc_html__( 'Purge Cache', 'simple-cache' ), 50 ) 51 ); 45 52 } 46 53 … … 51 58 */ 52 59 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 } 57 64 58 65 $cant_write = get_option( 'sc_cant_write', false ); … … 114 121 if ( defined( WP_DEBUG ) && WP_DEBUG ) { 115 122 $js_path = '/assets/js/src/settings.js'; 116 $css_path = '/assets/css/settings.css'; 117 123 } else { 118 124 $js_path = '/assets/js/settings.min.js'; 119 $css_path = '/assets/css/settings.css'; 120 } 125 } 126 $css_path = '/assets/css/settings.css'; 121 127 122 128 wp_enqueue_script( 'sc-settings', plugins_url( $js_path, dirname( __FILE__ ) ), array( 'jquery' ), SC_VERSION, true ); … … 144 150 if ( ! empty( $_REQUEST['action'] ) && 'sc_purge_cache' === $_REQUEST['action'] ) { 145 151 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' ) ); 147 153 } 148 154 … … 177 183 delete_option( 'sc_cant_write' ); 178 184 179 $defaults = SC_Config::factory()->defaults; 185 $defaults = SC_Config::factory()->defaults; 180 186 $current_config = SC_Config::factory()->get(); 181 187 … … 188 194 } 189 195 190 // Back up configration in options 196 // Back up configration in options. 191 197 update_option( 'sc_simple_cache', $clean_config ); 192 198 … … 204 210 } 205 211 206 // Reschedule cron events 212 // Reschedule cron events. 207 213 SC_Cron::factory()->unschedule_events(); 208 214 SC_Cron::factory()->schedule_events(); … … 218 224 * Sanitize options 219 225 * 220 * @param array $option 226 * @param array $option Array of options to sanitize. 221 227 * @since 1.0 222 228 * @return array … … 277 283 <th scope="row"><label for="sc_page_cache_length_simple"><?php esc_html_e( 'Expire the cache after', 'simple-cache' ); ?></label></th> 278 284 <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> 280 292 </td> 281 293 </tr> … … 337 349 <th scope="row"><label for="sc_page_cache_length_advanced"><?php esc_html_e( 'Expire page cache after', 'simple-cache' ); ?></label></th> 338 350 <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> 340 359 </td> 341 360 </tr> … … 359 378 </tr> 360 379 <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> 362 385 <td class="in-memory-cache <?php if ( ! empty( $config['enable_in_memory_object_caching'] ) ) : ?>show<?php endif; ?>"> 363 386 <select name="sc_simple_cache[in_memory_cache]" id="sc_in_memory_cache"> -
simple-cache/trunk/inc/dropins/batcache.php
r1456175 r1877792 1 1 <?php 2 /** 3 * Batcache dropin 4 * 5 * @package simple-cache 6 */ 7 2 8 defined( 'ABSPATH' ) || exit; 3 9 … … 13 19 14 20 // nananananananananananananananana BATCACHE!!! 15 16 21 function batcache_cancel() { 17 22 … … 26 31 // Functions defined in WordPress, plugins, and themes are not available and MUST NOT be used. 27 32 // 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. 29 34 // 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. 36 41 function vary_cache_on_function( $function ) { 37 42 … … 53 58 var $max_age = 3600; // Expire batcache items aged this many seconds (zero to disable batcache) 54 59 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) 56 61 57 62 var $times = 2; // Only batcache a page after it is accessed this many times... (two or more) 58 63 var $seconds = 120; // ...in this many seconds (zero to ignore this and use batcache immediately) 59 64 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. 65 70 66 71 var $headers = array(); // Add headers here as name=>value or name=>array(values). These will be sent with every response from the cache. 67 72 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. 70 75 var $redirect_location = false; // This is set to the redirect location. 71 76 … … 73 78 var $uncached_headers = array( 'transfer-encoding' ); // These headers will never be cached. Apply strtolower. 74 79 75 var $debug = true; // Set false to hide the batcache info <!-- comment --> 80 var $debug = true; // Set false to hide the batcache info <!-- comment --> 76 81 77 82 var $cache_control = true; // Set false to disable Last-Modified and Cache-Control headers … … 81 86 var $noskip_cookies = array( 'wordpress_test_cookie' ); // Names of cookies - if they exist and the cache would normally be bypassed, don't bypass it 82 87 83 var $query = ''; 88 var $query = ''; 84 89 var $genlock = false; 85 var $do = false; 90 var $do = false; 86 91 87 92 function __construct( $settings ) { … … 112 117 113 118 $this->status_header = $status_header; 114 $this->status_code = $status_code; 119 $this->status_code = $status_code; 115 120 116 121 return $status_header; … … 120 125 121 126 if ( $this->cache_redirects ) { 122 $this->redirect_status = $status; 127 $this->redirect_status = $status; 123 128 $this->redirect_location = $location; 124 129 } … … 131 136 // Merge the arrays of headers into one 132 137 $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 ) ) ); 134 139 foreach ( $keys as $k ) { 135 140 $headers[ $k ] = array(); … … 170 175 171 176 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 ); 178 183 if ( $display ) { 179 184 echo $r; … … 197 202 // Do not batcache blank pages unless they are HTTP redirects 198 203 $output = trim( $output ); 199 if ( $output === '' && ( ! $this->redirect_status || ! $this->redirect_location) ) { 204 if ( $output === '' && ( ! $this->redirect_status || ! $this->redirect_location ) ) { 200 205 wp_cache_delete( "{$this->url_key}_genlock", $this->group ); 201 206 return; … … 213 218 // Construct and save the batcache 214 219 $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, 223 228 ); 224 229 225 230 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 ) ); 227 232 $this->cache['headers'][ $k ][] = $v; 228 233 } … … 284 289 function add_variant( $function ) { 285 290 286 $key = md5( $function ); 291 $key = md5( $function ); 287 292 $this->vary[ $key ] = $function; 288 293 } … … 300 305 ksort( $dimensions ); 301 306 foreach ( $dimensions as $key => $function ) { 302 $fun = create_function( '', $function ); 303 $value = $fun(); 307 $fun = create_function( '', $function ); 308 $value = $fun(); 304 309 $this->keys[ $key ] = $value; 305 310 } … … 310 315 311 316 // ksort($this->keys); // uncomment this when traffic is slow 312 $this->key = md5( serialize( $this->keys ) ); 317 $this->key = md5( serialize( $this->keys ) ); 313 318 $this->req_key = $this->key . '_reqs'; 314 319 } … … 317 322 318 323 $generation = $this->cache['timer']; 319 $bytes = strlen( serialize( $this->cache ) ); 320 $html = <<<HTML 324 $bytes = strlen( serialize( $this->cache ) ); 325 $html = <<<HTML 321 326 <!-- 322 327 Cached by Simple Cache … … 332 337 333 338 $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 338 343 <!-- 339 344 generated $seconds_ago seconds ago … … 367 372 global $batcache; 368 373 369 if ( empty( $batcache ) && ! empty($GLOBALS['sc_config'] ) && isset( $GLOBALS['sc_config']['page_cache_length'] ) ) { 374 if ( empty( $batcache ) && ! empty( $GLOBALS['sc_config'] ) && isset( $GLOBALS['sc_config']['page_cache_length'] ) ) { 370 375 $max_age = $GLOBALS['sc_config']['page_cache_length'] * 60; 371 376 … … 393 398 394 399 $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']}", '/' ); 396 401 397 402 if ( strtolower( $exception ) === strtolower( $url ) ) { … … 399 404 return; 400 405 } 401 402 406 } elseif ( preg_match( '#^/#', $exception ) ) { 403 407 $path = $_SERVER['REQUEST_URI']; … … 429 433 basename( $_SERVER['SCRIPT_FILENAME'] ), 430 434 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 ) 435 439 ) ) { 436 440 return; … … 452 456 if ( is_array( $_COOKIE ) && ! empty( $_COOKIE ) ) { 453 457 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' ) ) { 455 459 batcache_stats( 'batcache', 'cookie_skip' ); 456 460 return; … … 470 474 471 475 // 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. 474 478 $batcache->unique['mobile'] = is_mobile_user_agent(); 475 479 */ 476 480 477 /* Example: never batcache for this host 481 /* 482 Example: never batcache for this host 478 483 if ( $_SERVER['HTTP_HOST'] == 'do-not-batcache-me.com' ) 479 484 return; 480 485 */ 481 486 482 /* Example: batcache everything on this host regardless of traffic level 487 /* 488 Example: batcache everything on this host regardless of traffic level 483 489 if ( $_SERVER['HTTP_HOST'] == 'always-batcache-me.com' ) 484 490 return; 485 491 */ 486 492 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. 488 495 if ( include_once( 'plugins/searchterm-highlighter.php') && referrer_has_search_terms() ) 489 496 return; … … 509 516 510 517 $batcache->keys = array( 511 'host' => $_SERVER['HTTP_HOST'], 518 'host' => $_SERVER['HTTP_HOST'], 512 519 '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, 516 523 ); 517 524 … … 522 529 // Recreate the permalink from the URL 523 530 $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 ); 525 532 $batcache->configure_groups(); 526 533 $batcache->url_version = (int) wp_cache_get( "{$batcache->url_key}_version", $batcache->group ); … … 534 541 // Always refresh the cache if a newer version is available. 535 542 $batcache->do = true; 536 } else if ( $batcache->seconds < 1 || $batcache->times < 2 ) { 543 } elseif ( $batcache->seconds < 1 || $batcache->times < 2 ) { 537 544 // Are we only caching frequently-requested pages? 538 545 $batcache->do = true; … … 561 568 if ( isset( $batcache->cache['time'] ) // We have cache 562 569 && ! $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 ) ) 565 572 ) { 566 573 // Issue redirect if cached and enabled 567 574 if ( $batcache->cache['redirect_status'] && $batcache->cache['redirect_location'] && $batcache->cache_redirects ) { 568 $status = $batcache->cache['redirect_status']; 575 $status = $batcache->cache['redirect_status']; 569 576 $location = $batcache->cache['redirect_location']; 570 577 // 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 ); 572 579 573 580 $batcache->do_headers( $batcache->headers ); … … 576 583 } else { 577 584 if ( php_sapi_name() != 'cgi-fcgi' ) { 578 $texts = array( 585 $texts = array( 579 586 300 => 'Multiple Choices', 580 587 301 => 'Moved Permanently', … … 622 629 if ( $batcache->cache_control && ! isset( $batcache->cache['headers']['Last-Modified'][0] ) ) { 623 630 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 ); 625 632 } 626 633 … … 652 659 } 653 660 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 ); 656 669 657 670 ob_start( array( &$batcache, 'ob' ) ); -
simple-cache/trunk/inc/dropins/file-based-page-cache-functions.php
r1643085 r1877792 1 1 <?php 2 3 2 /** 4 3 * Holds functions used by file based cache 5 4 * 6 5 * @since 1.6 7 */ 8 6 * @package simple-cache 7 */ 9 8 10 9 /** 11 10 * Cache output before it goes to the browser 12 11 * 13 * @param string $buffer 14 * @param int $flags 12 * @param string $buffer Page HTML. 13 * @param int $flags OB flags to be passed through. 15 14 * @since 1.0 16 15 * @return string 17 16 */ 18 17 function sc_cache( $buffer, $flags ) { 18 global $post; 19 19 20 if ( strlen( $buffer ) < 255 ) { 20 21 return $buffer; 21 22 } 22 23 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 ) ) { 25 26 return $buffer; 26 27 } 27 28 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 } 35 40 36 41 include_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; … … 39 44 $filesystem = new WP_Filesystem_Direct( new StdClass() ); 40 45 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. 42 47 if ( ! $filesystem->exists( untrailingslashit( WP_CONTENT_DIR ) . '/cache' ) ) { 43 48 if ( ! $filesystem->mkdir( untrailingslashit( WP_CONTENT_DIR ) . '/cache' ) ) { … … 75 80 } 76 81 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 } 78 91 79 92 if ( preg_match( '#</html>#i', $buffer ) ) { … … 89 102 } 90 103 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. 92 105 93 106 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $modified_time ) . ' GMT' ); … … 129 142 $modified_time = (int) @filemtime( $path ); 130 143 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 ) { 134 147 if ( function_exists( 'gzencode' ) && ! empty( $GLOBALS['sc_config']['enable_gzip_compression'] ) ) { 135 148 header( 'Content-Encoding: gzip' ); … … 154 167 * Return true of exception url matches current url 155 168 * 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. 158 171 * @since 1.6 159 172 * @return boolean … … 190 203 } 191 204 } 192 193 205 } else { 194 206 $path = $_SERVER['REQUEST_URI']; -
simple-cache/trunk/inc/dropins/file-based-page-cache.php
r1570775 r1877792 1 1 <?php 2 /** 3 * File based page cache drop in 4 * 5 * @package simple-cache 6 */ 7 2 8 defined( 'ABSPATH' ) || exit; 3 9 4 10 require_once( dirname( __FILE__ ) . '/file-based-page-cache-functions.php' ); 5 11 6 // Don't cache robots.txt or htacesss 12 // Don't cache robots.txt or htacesss. 7 13 if ( strpos( $_SERVER['REQUEST_URI'], 'robots.txt' ) !== false || strpos( $_SERVER['REQUEST_URI'], '.htaccess' ) !== false ) { 8 14 return; 9 15 } 10 16 11 // Don't cache non-GET requests 12 if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || $_SERVER['REQUEST_METHOD'] !== 'GET' ) { 17 // Don't cache non-GET requests. 18 if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || 'GET' !== $_SERVER['REQUEST_METHOD'] ) { 13 19 return; 14 20 } … … 23 29 } 24 30 25 // Don't cache if logged in 31 // Don't cache if logged in. 26 32 if ( ! empty( $_COOKIE ) ) { 27 33 $wp_cookies = array( 'wordpressuser_', 'wordpresspass_', 'wordpress_sec_', 'wordpress_logged_in_' ); … … 38 44 if ( ! empty( $_COOKIE['sc_commented_posts'] ) ) { 39 45 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. 42 48 return; 43 49 } … … 46 52 } 47 53 48 // Deal with optional cache exceptions 54 // Deal with optional cache exceptions. 49 55 if ( ! empty( $GLOBALS['sc_config']['advanced_mode'] ) && ! empty( $GLOBALS['sc_config']['cache_exception_urls'] ) ) { 50 56 $exceptions = preg_split( '#(\n|\r)#', $GLOBALS['sc_config']['cache_exception_urls'] ); … … 54 60 foreach ( $exceptions as $exception ) { 55 61 if ( sc_url_exception_match( $exception, $regex ) ) { 56 // Exception match 62 // Exception match. 57 63 return; 58 64 } -
simple-cache/trunk/inc/dropins/memcached-object-cache.php
r1456175 r1877792 1 1 <?php 2 /** 3 * Memcached drop in 4 * 5 * @package simple-cache 6 */ 7 2 8 defined( 'ABSPATH' ) || exit; 3 9 … … 115 121 var $no_mc_groups = array(); 116 122 117 var $cache = array(); 118 var $mc = array(); 119 var $stats = array(); 123 var $cache = array(); 124 var $mc = array(); 125 var $stats = array(); 120 126 var $group_ops = array(); 121 127 122 var $cache_enabled = true; 128 var $cache_enabled = true; 123 129 var $default_expiration = 0; 124 130 … … 138 144 } 139 145 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; 142 148 $result = $mc->add( $key, $data, false, $expire ); 143 149 … … 145 151 @ ++$this->stats['add']; 146 152 $this->group_ops[ $group ][] = "add $id"; 147 $this->cache[ $key ] = $data; 153 $this->cache[ $key ] = $data; 148 154 } 149 155 … … 173 179 function incr( $id, $n = 1, $group = 'default' ) { 174 180 175 $key = $this->key( $id, $group ); 176 $mc =& $this->get_mc( $group ); 181 $key = $this->key( $id, $group ); 182 $mc =& $this->get_mc( $group ); 177 183 $this->cache[ $key ] = $mc->increment( $key, $n ); 178 184 return $this->cache[ $key ]; … … 181 187 function decr( $id, $n = 1, $group = 'default' ) { 182 188 183 $key = $this->key( $id, $group ); 184 $mc =& $this->get_mc( $group ); 189 $key = $this->key( $id, $group ); 190 $mc =& $this->get_mc( $group ); 185 191 $this->cache[ $key ] = $mc->decrement( $key, $n ); 186 192 return $this->cache[ $key ]; … … 228 234 229 235 $key = $this->key( $id, $group ); 230 $mc =& $this->get_mc( $group ); 236 $mc =& $this->get_mc( $group ); 231 237 232 238 if ( isset( $this->cache[ $key ] ) && ( ! $force || in_array( $group, $this->no_mc_groups ) ) ) { … … 236 242 $value = $this->cache[ $key ]; 237 243 } 238 } else if ( in_array( $group, $this->no_mc_groups ) ) { 244 } elseif ( in_array( $group, $this->no_mc_groups ) ) { 239 245 $this->cache[ $key ] = $value = false; 240 246 } else { … … 260 266 261 267 /* 262 format: $get['group-name'] = array( 'key1', 'key2' ); 263 */ 268 format: $get['group-name'] = array( 'key1', 'key2' ); 269 */ 264 270 $return = array(); 265 271 foreach ( $groups as $group => $ids ) { … … 274 280 } 275 281 continue; 276 } else if ( in_array( $group, $this->no_mc_groups ) ) { 282 } elseif ( in_array( $group, $this->no_mc_groups ) ) { 277 283 $return[ $key ] = false; 278 284 continue; … … 282 288 } 283 289 if ( $to_get ) { 284 $vals = $mc->get_multi( $to_get ); 290 $vals = $mc->get_multi( $to_get ); 285 291 $return = array_merge( $return, $vals ); 286 292 } … … 288 294 @ ++$this->stats['get_multi']; 289 295 $this->group_ops[ $group ][] = "get_multi $id"; 290 $this->cache = array_merge( $this->cache, $return ); 296 $this->cache = array_merge( $this->cache, $return ); 291 297 return $return; 292 298 } … … 309 315 function replace( $id, $data, $group = 'default', $expire = 0 ) { 310 316 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 ); 314 320 315 321 if ( is_object( $data ) ) { … … 327 333 328 334 $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 ] ) ) { 330 336 return false; 331 337 } … … 341 347 } 342 348 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 ); 345 351 $result = $mc->set( $key, $data, false, $expire ); 346 352 … … 352 358 global $table_prefix; 353 359 354 $blog_id = (int) $blog_id; 360 $blog_id = (int) $blog_id; 355 361 $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':'; 356 362 } … … 359 365 360 366 $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', 365 371 ); 366 372 … … 407 413 function failure_callback( $host, $port ) { 408 414 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'); 410 416 } 411 417 … … 427 433 foreach ( $buckets as $bucket => $servers ) { 428 434 $this->mc[ $bucket ] = new Memcache(); 429 foreach ( $servers as $server ) { 435 foreach ( $servers as $server ) { 430 436 if ( 'unix://' == substr( $server, 0, 7 ) ) { 431 437 $node = $server; … … 448 454 global $blog_id, $table_prefix; 449 455 $this->global_prefix = ''; 450 $this->blog_prefix = ''; 456 $this->blog_prefix = ''; 451 457 if ( function_exists( 'is_multisite' ) ) { 452 458 $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']; 457 463 $this->cache_misses =& $this->stats['add']; 458 464 } 459 465 } 460 ?> 466 -
simple-cache/trunk/inc/dropins/redis-object-cache.php
r1397513 r1877792 1 1 <?php 2 /** 3 * Redis cache drop in 4 * 5 * @package simple-cache 6 */ 7 2 8 defined( 'ABSPATH' ) || exit; 3 9 … … 12 18 13 19 // This file needs to be symlinked or copied to wp-content/object-cache.php 14 15 20 // Users with setups where multiple installs share a common wp-config.php or $table_prefix 16 21 // can use this to guarantee uniqueness for the keys generated by this object cache … … 396 401 $groups = (array) $groups; 397 402 398 $groups = array_fill_keys( $groups, true ); 403 $groups = array_fill_keys( $groups, true ); 399 404 $this->global_groups = array_merge( $this->global_groups, $groups ); 400 405 } … … 409 414 $groups = (array) $groups; 410 415 411 $groups = array_fill_keys( $groups, true ); 416 $groups = array_fill_keys( $groups, true ); 412 417 $this->non_persistent_groups = array_merge( $this->non_persistent_groups, $groups ); 413 418 } … … 451 456 if ( self::USE_GROUPS ) { 452 457 $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 ); 454 459 if ( $result < 0 ) { 455 460 $result = 0; … … 457 462 } 458 463 } else { 459 $id = $this->_key( $key, $group ); 464 $id = $this->_key( $key, $group ); 460 465 $result = $this->_call_redis( 'decrBy', $id, $offset ); 461 466 if ( $result < 0 ) { … … 497 502 if ( self::USE_GROUPS ) { 498 503 $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 ); 500 505 } else { 501 $id = $this->_key( $key, $group ); 506 $id = $this->_key( $key, $group ); 502 507 $result = $this->_call_redis( 'delete', $id ); 503 508 } … … 524 529 525 530 $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 ); 527 532 if ( $this->_should_persist( $group ) ) { 528 533 $result = $this->_call_redis( 'delete', $redis_safe_group ); … … 530 535 return false; 531 536 } 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 ] ) ) { 533 538 return false; 534 539 } … … 589 594 if ( self::USE_GROUPS ) { 590 595 $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 ); 592 597 } else { 593 $id = $this->_key( $key, $group ); 598 $id = $this->_key( $key, $group ); 594 599 $value = $this->_call_redis( 'get', $id ); 595 600 } … … 640 645 if ( self::USE_GROUPS ) { 641 646 $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 ); 643 648 if ( $result < 0 ) { 644 649 $result = 0; … … 646 651 } 647 652 } else { 648 $id = $this->_key( $key, $group ); 653 $id = $this->_key( $key, $group ); 649 654 $result = $this->_call_redis( 'incrBy', $id, $offset ); 650 655 if ( $result < 0 ) { … … 662 667 /** 663 668 * Replace the contents in the cache, if contents already exist 664 * 669 * 665 670 * @see WP_Object_Cache::set() 666 671 * … … 777 782 public function switch_to_blog( $blog_id ) { 778 783 779 $blog_id = (int) $blog_id; 784 $blog_id = (int) $blog_id; 780 785 $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; 781 786 } … … 864 869 $this->cache[ $multisite_safe_group ][ $key ] = $value; 865 870 } else { 866 $key = $this->_key( $key, $group ); 871 $key = $this->_key( $key, $group ); 867 872 $this->cache[ $key ] = $value; 868 873 } … … 939 944 if ( isset( $_SERVER['CACHE_HOST'] ) ) { 940 945 $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'], 944 949 ); 945 950 } else { 946 951 $redis_server = array( 947 'host' => '127.0.0.1', 948 'port' => 6379, 952 'host' => '127.0.0.1', 953 'port' => 6379, 949 954 ); 950 955 } … … 953 958 $this->redis = new Redis; 954 959 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 957 962 $port = null; 958 } else { //tcp connection 963 } else { // tcp connection 959 964 $port = ! empty( $redis_server['port'] ) ? $redis_server['port'] : 6379; 960 965 } … … 1025 1030 return call_user_func_array( array( $this, '_call_redis' ), array_merge( array( $method ), $arguments ) ); 1026 1031 } 1027 1028 1032 } 1029 1033 } … … 1033 1037 case 'incr': 1034 1038 case 'incrBy': 1035 $val = $this->cache[ $arguments[0] ]; 1039 $val = $this->cache[ $arguments[0] ]; 1036 1040 $offset = isset( $arguments[1] ) && 'incrBy' === $method ? $arguments[1] : 1; 1037 $val = $val + $offset; 1038 return $val; 1041 $val = $val + $offset; 1042 return $val; 1039 1043 case 'hIncrBy': 1040 1044 $val = $this->_get_internal( $arguments[1], $group ); 1041 return $val + $arguments[2]; 1045 return $val + $arguments[2]; 1042 1046 case 'decrBy': 1043 1047 case 'decr': 1044 $val = $this->cache[ $arguments[0] ]; 1048 $val = $this->cache[ $arguments[0] ]; 1045 1049 $offset = isset( $arguments[1] ) && 'decrBy' === $method ? $arguments[1] : 1; 1046 $val = $val - $offset; 1047 return $val; 1050 $val = $val - $offset; 1051 return $val; 1048 1052 case 'delete': 1049 1053 case 'hDel': 1050 return 1; 1054 return 1; 1051 1055 case 'flushAll': 1052 1056 case 'IsConnected': 1053 1057 case 'exists': 1054 return false; 1058 return false; 1055 1059 } 1056 1060 … … 1063 1067 */ 1064 1068 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(); 1068 1072 $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; 1069 1073 1070 1074 $this->global_prefix = ( $this->multisite || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix; 1071 1072 1075 1073 1076 $this->_connect_redis(); -
simple-cache/trunk/inc/functions.php
r1403511 r1877792 1 1 <?php 2 /** 3 * Utility functions for plugin 4 * 5 * @package simple-cache 6 */ 2 7 3 8 /** … … 9 14 global $wp_filesystem; 10 15 11 require_once( ABSPATH . 'wp-admin/includes/file.php'); 16 require_once( ABSPATH . 'wp-admin/includes/file.php' ); 12 17 13 18 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. 4 3 msgid "" 5 4 msgstr "" 6 5 "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" 14 6 "MIME-Version: 1.0\n" 15 7 "Content-Type: text/plain; charset=UTF-8\n" 16 8 "Content-Transfer-Encoding: 8bit\n" 17 "X-Generator: Poedit 1.8.6\n" 18 "Plural-Forms: nplurals=2; plural=n != 1;\n" 19 9 "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" 20 13 "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" 28 15 29 #: inc/class-sc-advanced-cache.php:162 16 #. translators: Param 1 is link to settings page. 17 #: simple-cache.php:58 18 msgid "<a href=\"%s\">Settings</a>" 19 msgstr "" 20 21 #: inc/class-sc-advanced-cache.php:167 30 22 msgid "define(\"WP_CACHE\", true); is not in wp-config.php." 31 23 msgstr "" 32 24 33 #: inc/class-sc-advanced-cache.php:166 25 #: inc/class-sc-advanced-cache.php:171 34 26 msgid "wp-content/advanced-cache.php was edited or deleted." 35 27 msgstr "" 36 28 37 #: inc/class-sc-advanced-cache.php:169 29 #: inc/class-sc-advanced-cache.php:174 38 30 msgid "Simple Cache is not able to utilize page caching." 39 31 msgstr "" 40 32 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 42 34 msgid "Fix" 43 35 msgstr "" 44 36 45 #: inc/class-sc-cron.php:41 37 #: inc/class-sc-cron.php:55 46 38 msgid "Simple Cache Purge Interval" 47 39 msgstr "" 48 40 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 56 42 msgid "Purge Cache" 57 43 msgstr "" 58 44 59 #: inc/class-sc-settings.php:69 45 #: inc/class-sc-settings.php:80 60 46 msgid "Simple Cache won't work until you turn it on." 61 47 msgstr "" 62 48 63 #: inc/class-sc-settings.php:70 49 #: inc/class-sc-settings.php:81 64 50 msgid "Turn On Caching" 65 51 msgstr "" 66 52 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 54 msgid "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." 72 55 msgstr "" 73 56 74 #: inc/class-sc-settings.php:95 57 #: inc/class-sc-settings.php:104 75 58 msgid "Try Again" 76 59 msgstr "" 77 60 78 #: inc/class-sc-settings.php:132 61 #: inc/class-sc-settings.php:140, inc/class-sc-settings.php:140 79 62 msgid "Simple Cache" 80 63 msgstr "" 81 64 82 #: inc/class-sc-settings.php:166 65 #: inc/class-sc-settings.php:152, inc/class-sc-settings.php:174 83 66 msgid "Cheatin, eh?" 84 67 msgstr "" 85 68 86 #: inc/class-sc-settings.php:246 69 #: inc/class-sc-settings.php:254 87 70 msgid "Simple Cache Settings" 88 71 msgstr "" 89 72 90 #: inc/class-sc-settings.php:254 73 #: inc/class-sc-settings.php:262 91 74 msgid "Enable Advanced Mode" 92 75 msgstr "" 93 76 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 98 78 msgid "No" 99 79 msgstr "" 100 80 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 105 82 msgid "Yes" 106 83 msgstr "" 107 84 108 #: inc/class-sc-settings.php:264 85 #: inc/class-sc-settings.php:272 109 86 msgid "Enable Caching" 110 87 msgstr "" 111 88 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 90 msgid "Turn this on to get started. This setting turns on caching and is really all you need." 116 91 msgstr "" 117 92 118 #: inc/class-sc-settings.php:275 93 #: inc/class-sc-settings.php:283 119 94 msgid "Expire the cache after" 120 95 msgstr "" 121 96 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 123 98 msgid "minutes" 124 99 msgstr "" 125 100 126 #: inc/class-sc-settings.php:283 101 #: inc/class-sc-settings.php:288, inc/class-sc-settings.php:355 102 msgid "hours" 103 msgstr "" 104 105 #: inc/class-sc-settings.php:289, inc/class-sc-settings.php:356 106 msgid "days" 107 msgstr "" 108 109 #: inc/class-sc-settings.php:290, inc/class-sc-settings.php:357 110 msgid "weeks" 111 msgstr "" 112 113 #: inc/class-sc-settings.php:297 127 114 msgid "Enable Compression" 128 115 msgstr "" 129 116 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 118 msgid "When enabled, pages will be compressed. This is a good thing! This should always be enabled unless it causes issues." 134 119 msgstr "" 135 120 136 #: inc/class-sc-settings.php:301 121 #: inc/class-sc-settings.php:315 137 122 msgid "Page Cache" 138 123 msgstr "" 139 124 140 #: inc/class-sc-settings.php:306 125 #: inc/class-sc-settings.php:320 141 126 msgid "Enable Page Caching" 142 127 msgstr "" 143 128 144 #: inc/class-sc-settings.php:313 129 #: inc/class-sc-settings.php:327 145 130 msgid "When enabled, entire front end pages will be cached." 146 131 msgstr "" 147 132 148 #: inc/class-sc-settings.php:318 133 #: inc/class-sc-settings.php:332 149 134 msgid "Exception URL(s)" 150 135 msgstr "" 151 136 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 138 msgid "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/)." 158 139 msgstr "" 159 140 160 #: inc/class-sc-settings.php:329 141 #: inc/class-sc-settings.php:343 161 142 msgid "Enable Regex" 162 143 msgstr "" 163 144 164 #: inc/class-sc-settings.php:335 145 #: inc/class-sc-settings.php:349 165 146 msgid "Expire page cache after" 166 147 msgstr "" 167 148 168 #: inc/class-sc-settings.php:342 149 #: inc/class-sc-settings.php:363 169 150 msgid "Object Cache (Redis or Memcache)" 170 151 msgstr "" 171 152 172 #: inc/class-sc-settings.php:348 153 #: inc/class-sc-settings.php:369 173 154 msgid "Enable In-Memory Object Caching" 174 155 msgstr "" 175 156 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 158 msgid "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." 183 159 msgstr "" 184 160 185 #: inc/class-sc-settings.php:359 161 #: inc/class-sc-settings.php:384 186 162 msgid "In Memory Cache" 187 163 msgstr "" 188 164 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 166 msgid "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." 194 167 msgstr "" 195 168 196 #: inc/class-sc-settings.php:381 169 #: inc/class-sc-settings.php:406 197 170 msgid "Compression" 198 171 msgstr "" 199 172 200 #: inc/class-sc-settings.php:387 173 #: inc/class-sc-settings.php:412 201 174 msgid "Enable gzip Compression" 202 175 msgstr "" 203 176 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 178 msgid "When enabled pages will be gzip compressed at the PHP level. Note many hosts set up gzip compression in Apache or nginx." 208 179 msgstr "" 209 180 210 #: inc/class-sc-settings.php:402 181 #: inc/class-sc-settings.php:427 211 182 msgid "Save Changes" 212 183 msgstr "" 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 1 1 === Simple Cache === 2 2 Contributors: tlovett1 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HR34W94MM53RQ 4 3 Tags: cache, page cache, object caching, object cache, memcache, redis, memcached 5 4 Requires at least: 3.9 6 Tested up to: 4.8 5 Tested up to: 5.0 7 6 Stable tag: trunk 8 7 License: GPLv2 or later … … 37 36 38 37 == 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 ). 39 43 40 44 = 1.6.3 = -
simple-cache/trunk/simple-cache.php
r1643085 r1877792 5 5 * Description: A simple caching plugin that just works. 6 6 * Author: Taylor Lovett 7 * Version: 1.6.3 7 * Version: 1.6.4 8 8 * Text Domain: simple-cache 9 9 * Domain Path: /languages 10 10 * Author URI: http://taylorlovett.com 11 * 12 * @package simple-cache 11 13 */ 12 14 13 15 defined( 'ABSPATH' ) || exit; 14 16 15 define( 'SC_VERSION', '1.6.3' ); 17 define( 'SC_VERSION', '1.6.4' ); 16 18 17 19 require_once dirname( __FILE__ ) . '/inc/functions.php'; … … 43 45 * Add settings link to plugin actions 44 46 * 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. 47 49 * @since 1.0 48 50 * @return array … … 53 55 54 56 if ( basename( dirname( __FILE__ ) ) . '/simple-cache.php' === $plugin_file ) { 57 /* translators: Param 1 is link to settings page. */ 55 58 $new_actions['sc_settings'] = sprintf( __( '<a href="%s">Settings</a>', 'simple-cache' ), esc_url( admin_url( 'options-general.php?page=simple-cache' ) ) ); 56 59 }