5fbcf025 by Jeff Balicki

t

1 parent 881df4ef
Showing 68 changed files with 2401 additions and 0 deletions
1 <?php
2 // WP SUPER CACHE 1.2
3 function wpcache_broken_message() {
4 global $wp_cache_config_file;
5 if ( isset( $wp_cache_config_file ) == false ) {
6 return '';
7 }
8
9 $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
10 $xmlrpc_request = defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST;
11 $rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
12 $robots_request = strpos( $_SERVER['REQUEST_URI'], 'robots.txt' ) != false;
13
14 $skip_output = ( $doing_ajax || $xmlrpc_request || $rest_request || $robots_request );
15 if ( false == strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) && ! $skip_output ) {
16 echo '<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->';
17 }
18 }
19
20 if ( false == defined( 'WPCACHEHOME' ) ) {
21 define( 'ADVANCEDCACHEPROBLEM', 1 );
22 } elseif ( ! include_once WPCACHEHOME . 'wp-cache-phase1.php' ) {
23 if ( ! @is_file( WPCACHEHOME . 'wp-cache-phase1.php' ) ) {
24 define( 'ADVANCEDCACHEPROBLEM', 1 );
25 }
26 }
27 if ( defined( 'ADVANCEDCACHEPROBLEM' ) ) {
28 register_shutdown_function( 'wpcache_broken_message' );
29 }
30
This diff could not be displayed because it is too large.
1 <?php
2 extract( wpsc_update_debug_settings() ); // $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $wp_super_cache_comments, $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug, $wp_cache_debug_username
3 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
4
5 echo '<a name="debug"></a>';
6 echo '<fieldset class="options">';
7 echo '<p>' . __( 'Fix problems with the plugin by debugging it here. It will log to a file in your cache directory.', 'wp-super-cache' ) . '</p>';
8 if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) {
9 extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
10 }
11
12 $log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}view_{$wp_cache_debug_log}?wp-admin=1&wp-json=1&filter=" ) ) . "'>$wp_cache_debug_log</a>";
13
14 if ( $wp_super_cache_debug == 1 ) {
15 echo "<p>" . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>";
16 } else {
17 echo "<p>" . sprintf( __( 'Last Logged to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>";
18 }
19 echo "<p>" . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . "</p>";
20
21 echo '<form name="wpsc_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'debug', $admin_url ) ) . '" method="post">';
22 wp_nonce_field('wp-cache');
23 echo "<input type='hidden' name='wpsc_delete_log' value='1' />";
24 submit_button( __( 'Delete', 'wp-super-cache' ), 'delete', 'wpsc_delete_log_form', false );
25 echo "</form>";
26
27 echo '<form name="wpsc_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'debug', $admin_url ) ) . '" method="post">';
28 if ( ! isset( $wp_super_cache_debug ) || $wp_super_cache_debug == 0 ) {
29 $debug_status_message = __( 'Enable Logging', 'wp-super-cache' );
30 $not_status = 1;
31 } else {
32 $debug_status_message = __( 'Disable Logging', 'wp-super-cache' );
33 $not_status = 0;
34 }
35 echo "<input type='hidden' name='wp_super_cache_debug' value='" . $not_status . "' />";
36 wp_nonce_field('wp-cache');
37 submit_button( $debug_status_message, 'primary', 'wpsc_log_status', true );
38 echo "</form>";
39
40 echo '<form name="wp_cache_debug" action="' . esc_url_raw( add_query_arg( 'tab', 'debug', $admin_url ) ) . '" method="post">';
41 echo "<input type='hidden' name='wp_cache_debug' value='1' /><br />";
42 echo "<table class='form-table'>";
43 echo "<tr><th>" . __( 'IP Address', 'wp-super-cache' ) . "</th><td> <input type='text' size='20' name='wp_cache_debug_ip' value='{$wp_cache_debug_ip}' /> " . sprintf( __( '(only log requests from this IP address. Your IP is %s)', 'wp-super-cache' ), $_SERVER[ 'REMOTE_ADDR' ] ) . "</td></tr>";
44 echo "<tr><th valign='top'>" . __( 'Cache Status Messages', 'wp-super-cache' ) . "</th><td><input type='checkbox' name='wp_super_cache_comments' value='1' " . checked( 1, $wp_super_cache_comments, false ) . " /> " . __( 'enabled', 'wp-super-cache' ) . "<br />";
45 echo __( 'Display comments at the end of every page like this:', 'wp-super-cache' ) . "<br />";
46 echo "<pre>&lt;!-- Dynamic page generated in 0.450 seconds. -->
47 &lt;!-- Cached page generated by WP-Super-Cache on " . date( "Y-m-d H:i:s", time() ) . " -->
48 &lt;!-- super cache --></pre></td></tr>";
49 echo "</table>\n";
50 if ( isset( $wp_super_cache_advanced_debug ) ) {
51 echo "<h5>" . __( 'Advanced', 'wp-super-cache' ) . "</h5><p>" . __( 'In very rare cases two problems may arise on some blogs:<ol><li> The front page may start downloading as a zip file.</li><li> The wrong page is occasionally cached as the front page if your blog uses a static front page and the permalink structure is <em>/%category%/%postname%/</em>.</li></ol>', 'wp-super-cache' ) . '</p>';
52 echo "<p>" . __( 'I&#8217;m 99% certain that they aren&#8217;t bugs in WP Super Cache and they only happen in very rare cases but you can run a simple check once every 5 minutes to verify that your site is ok if you&#8217;re worried. You will be emailed if there is a problem.', 'wp-super-cache' ) . "</p>";
53 echo "<table class='form-table'>";
54 echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_check' value='1' " . checked( 1, $wp_super_cache_front_page_check, false ) . " /> " . __( 'Check front page every 5 minutes.', 'wp-super-cache' ) . "</td></tr>";
55 echo "<tr><td valign='top'>" . __( 'Front page text', 'wp-super-cache' ) . "</td><td> <input type='text' size='30' name='wp_super_cache_front_page_text' value='{$wp_super_cache_front_page_text}' /> (" . __( 'Text to search for on your front page. If this text is missing, the cache will be cleared. Leave blank to disable.', 'wp-super-cache' ) . ")</td></tr>";
56 echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_clear' value='1' " . checked( 1, $wp_super_cache_front_page_clear, false ) . " /> " . __( 'Clear cache on error.', 'wp-super-cache' ) . "</td></tr>";
57 echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_notification' value='1' " . checked( 1, $wp_super_cache_front_page_notification, false ) . " /> " . __( 'Email the blog admin when checks are made. (useful for testing)', 'wp-super-cache' ) . "</td></tr>";
58
59 echo "</table>\n";
60 }
61 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Settings', 'wp-super-cache' ) . '" /></div>';
62 wp_nonce_field('wp-cache');
63 echo "</form>\n";
64 echo '</fieldset>';
1 <a name='lockdown'></a>
2 <fieldset class="options">
3 <h4><?php _e( 'Lock Down:', 'wp-super-cache' ); ?> <?php echo $wp_lock_down == '0' ? '<span style="color:red">' . __( 'Disabled', 'wp-super-cache' ) . '</span>' : '<span style="color:green">' . __( 'Enabled', 'wp-super-cache' ) . '</span>'; ?></h4>
4 <p><?php _e( 'Prepare your server for an expected spike in traffic by enabling the lock down. When this is enabled, new comments on a post will not refresh the cached static files.', 'wp-super-cache' ); ?></p>
5 <p><?php _e( 'Developers: Make your plugin lock down compatible by checking the "WPLOCKDOWN" constant. The following code will make sure your plugin respects the WPLOCKDOWN setting.', 'wp-super-cache' ); ?>
6 <blockquote><code>if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) {
7 &nbsp;&nbsp;&nbsp;&nbsp;echo "<?php _e( 'Sorry. My blog is locked down. Updates will appear shortly', 'wp-super-cache' ); ?>";
8 }</code></blockquote>
9 <?php
10 if( $wp_lock_down == '1' ) {
11 ?><p><?php _e( 'WordPress is locked down. Super Cache static files will not be deleted when new comments are made.', 'wp-super-cache' ); ?></p><?php
12 } else {
13 ?><p><?php _e( 'WordPress is not locked down. New comments will refresh Super Cache static files as normal.', 'wp-super-cache' ); ?></p><?php
14 }
15 $new_lockdown = $wp_lock_down == '1' ? '0' : '1';
16 $new_lockdown_desc = $wp_lock_down == '1' ? __( 'Disable', 'wp-super-cache' ) : __( 'Enable', 'wp-super-cache' );
17 echo '<form name="wp_lock_down" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#lockdown' ) . '" method="post">';
18 echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
19 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . ' value="' . esc_attr( $new_lockdown_desc . ' ' . __( 'Lock Down', 'wp-super-cache' ) ) . '" /></div>';
20 wp_nonce_field( 'wp-cache' );
21 echo '</form>';
22
23 ?></fieldset><?php
24 if( $cache_enabled == true && $super_cache_enabled == true ) {
25 ?><a name='direct'></a>
26 <fieldset class="options">
27 <h4><?php _e( 'Directly Cached Files', 'wp-super-cache' ); ?></h4><?php
28
29 $cached_direct_pages = wpsc_update_direct_pages();
30
31 $readonly = '';
32 if( !is_writeable_ACLSafe( ABSPATH ) ) {
33 $readonly = 'READONLY';
34 ?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( 'You must make %s writable to enable this feature. As this is a security risk, please make it read-only after your page is generated.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
35 } else {
36 $abspath_stat = stat(ABSPATH . '/');
37 $abspath_mode = decoct( $abspath_stat[ 'mode' ] & 0777 );
38 if ( substr( $abspath_mode, -2 ) == '77' ) {
39 ?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( '%s is writable. Please make it readonly after your page is generated as this is a security risk.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
40 }
41 }
42 echo '<form name="direct_page" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#direct' ) . '" method="post">';
43 if( is_array( $cached_direct_pages ) ) {
44 $out = '';
45 foreach( $cached_direct_pages as $page ) {
46 if( $page == '' )
47 continue;
48 $generated = '';
49 if( is_file( ABSPATH . $page . '/index.html' ) )
50 $generated = '<input class="button-secondary" type="Submit" name="deletepage" value="' . $page . '">';
51 $out .= "<tr><td><input type='text' $readonly name='direct_pages[]' size='30' value='$page' /></td><td>$generated</td></tr>";
52 }
53 if( $out != '' ) {
54 ?><table><tr><th><?php _e( 'Existing direct page', 'wp-super-cache' ); ?></th><th><?php _e( 'Delete cached file', 'wp-super-cache' ); ?></th></tr><?php
55 echo "$out</table>";
56 }
57 }
58
59 if ( 'READONLY' !== $readonly ) {
60 echo esc_html__( 'Add direct page:', 'wp-super-cache' ) . '<input type="text" name="new_direct_page" size="30" value="" />';
61 }
62 echo '<p>' . sprintf(
63 esc_html__( 'Directly cached files are files created directly off %s where your blog lives. This feature is only useful if you are expecting a major Digg or Slashdot level of traffic to one post or page.', 'wp-super-cache' ),
64 esc_attr( ABSPATH )
65 ) . '</p>';
66 if ( 'READONLY' !== $readonly ) {
67 echo '<p>' . sprintf( __( 'For example: to cache <em>%1$sabout/</em>, you would enter %1$sabout/ or /about/. The cached file will be generated the next time an anonymous user visits that page.', 'wp-super-cache' ),
68 esc_attr( trailingslashit( get_option( 'home' ) ) )
69 ) . '</p>';
70 echo '<p>' . esc_html__( 'Make the textbox blank to remove it from the list of direct pages and delete the cached file.', 'wp-super-cache' ) . '</p>';
71
72 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . ' value="' . esc_attr__( 'Update Direct Pages', 'wp-super-cache' ) . '" /></div>';
73 }
74 wp_nonce_field( 'wp-cache' );
75 echo '</form>';
76 ?>
77 </fieldset>
78 <?php
79 } // if $super_cache_enabled
1 <?php
2 echo '<a name="preload"></a>';
3 if ( ! $cache_enabled || ! $super_cache_enabled || true === defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
4 echo '<div class="notice notice-warning"><p>' . __( 'Preloading of cache disabled. Please make sure simple or expert mode is enabled or talk to your host administrator.', 'wp-super-cache' ) . '</p></div>';
5 return;
6 }
7
8 $count = wpsc_post_count();
9 if ( $count > 1000 ) {
10 $min_refresh_interval = 720;
11 } else {
12 $min_refresh_interval = 30;
13 }
14
15 echo '<p>' . __( 'This will cache every published post and page on your site. It will create supercache static files so unknown visitors (including bots) will hit a cached page. This will probably help your Google ranking as they are using speed as a metric when judging websites now.', 'wp-super-cache' ) . '</p>';
16 echo '<p>' . __( 'Preloading creates lots of files however. Caching is done from the newest post to the oldest so please consider only caching the newest if you have lots (10,000+) of posts. This is especially important on shared hosting.', 'wp-super-cache' ) . '</p>';
17 echo '<p>' . __( 'In &#8217;Preload Mode&#8217; regular garbage collection will be disabled so that old cache files are not deleted. This is a recommended setting when the cache is preloaded.', 'wp-super-cache' ) . '</p>';
18 echo '<form name="cache_filler" action="' . esc_url_raw( add_query_arg( 'tab', 'preload', $admin_url ) ) . '" method="POST">';
19 echo '<input type="hidden" name="action" value="preload" />';
20 echo '<input type="hidden" name="page" value="wpsupercache" />';
21 echo '<p>' . sprintf( __( 'Refresh preloaded cache files every %s minutes. (0 to disable, minimum %d minutes.)', 'wp-super-cache' ), "<input type='text' size=4 name='wp_cache_preload_interval' value='" . (int) $wp_cache_preload_interval . "' />", $min_refresh_interval ) . '</p>';
22 if ( $count > 100 ) {
23 $step = (int)( $count / 10 );
24
25 $select = "<select name='wp_cache_preload_posts' size=1>";
26 $select .= "<option value='all' ";
27 if ( ! isset( $wp_cache_preload_posts ) || $wp_cache_preload_posts == 'all' ) {
28 $checked = 'selectect=1 ';
29 $best = 'all';
30 } else {
31 $checked = ' ';
32 $best = $wp_cache_preload_posts;
33 }
34 $select .= "{$checked}>" . __( 'all', 'wp-super-cache' ) . "</option>";
35
36 for( $c = $step; $c < $count; $c += $step ) {
37 $checked = ' ';
38 if ( $best == $c )
39 $checked = 'selected=1 ';
40 $select .= "<option value='$c'{$checked}>$c</option>";
41 }
42 $checked = ' ';
43 if ( $best == $count )
44 $checked = 'selected=1 ';
45 $select .= "<option value='$count'{$checked}>$count</option>";
46 $select .= "</select>";
47 echo '<p>' . sprintf( __( 'Preload %s posts.', 'wp-super-cache' ), $select ) . '</p>';
48 } else {
49 echo '<input type="hidden" name="wp_cache_preload_posts" value="' . $count . '" />';
50 }
51
52 echo '<input type="checkbox" name="wp_cache_preload_on" value="1" ';
53 echo $wp_cache_preload_on == 1 ? 'checked=1' : '';
54 echo ' /> ' . __( 'Preload mode (garbage collection disabled. Recommended.)', 'wp-super-cache' ) . '<br />';
55 echo '<input type="checkbox" name="wp_cache_preload_taxonomies" value="1" ';
56 echo $wp_cache_preload_taxonomies == 1 ? 'checked=1' : '';
57 echo ' /> ' . __( 'Preload tags, categories and other taxonomies.', 'wp-super-cache' ) . '<br />';
58 echo __( 'Send me status emails when files are refreshed.', 'wp-super-cache' ) . '<br />';
59 if ( !isset( $wp_cache_preload_email_volume ) )
60 $wp_cache_preload_email_volume = 'none';
61 echo '<select type="select" name="wp_cache_preload_email_volume">';
62 echo '<option value="none" '. selected( 'none', $wp_cache_preload_email_volume ) . '>'. __( 'No Emails', 'wp-super-cache' ) . '</option>';
63 echo '<option value="many" '. selected( 'many', $wp_cache_preload_email_volume ) . '>'. __( 'Many emails, 2 emails per 100 posts.', 'wp-super-cache' ) . '</option>';
64 echo '<option value="medium" '. selected( 'medium', $wp_cache_preload_email_volume ) . '>'. __( 'Medium, 1 email per 100 posts.', 'wp-super-cache' ) . '</option>';
65 echo '<option value="less" '. selected( 'less', $wp_cache_preload_email_volume ) . '>'. __( 'Less emails, 1 at the start and 1 at the end of preloading all posts.', 'wp-super-cache' ) . '</option>';
66 echo "</select>";
67
68 if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
69 $currently_preloading = true;
70 }
71 echo '<div class="submit"><input class="button-primary" type="submit" name="preload" value="' . __( 'Save Settings', 'wp-super-cache' ) . '" />';
72 echo '</div>';
73 wp_nonce_field( 'wp-cache' );
74 echo '</form>';
75 echo '<form name="do_preload" action="' . esc_url_raw( add_query_arg( 'tab', 'preload', $admin_url ) ) . '" method="POST">';
76 echo '<input type="hidden" name="action" value="preload" />';
77 echo '<input type="hidden" name="page" value="wpsupercache" />';
78 echo '<div class="submit">';
79 if ( false == $currently_preloading ) {
80 echo '<input class="button-primary" type="submit" name="preload_now" value="' . __( 'Preload Cache Now', 'wp-super-cache' ) . '" />';
81 } else {
82 echo '<input class="button-primary" type="submit" name="preload_off" value="' . __( 'Cancel Cache Preload', 'wp-super-cache' ) . '" />';
83 }
84 echo '</div>';
85 wp_nonce_field( 'wp-cache' );
86 echo '</form>';
1 <?php
2 echo '<a name="useragents"></a><fieldset class="options"><h4>' . __( 'Rejected User Agents', 'wp-super-cache' ) . '</h4>';
3 echo "<p>" . __( 'Strings in the HTTP &#8217;User Agent&#8217; header that prevent WP-Cache from caching bot, spiders, and crawlers&#8217; requests. Note that super cached files are still sent to these agents if they already exists.', 'wp-super-cache' ) . "</p>\n";
4 echo '<form name="wp_edit_rejected_user_agent" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#useragents' ) . '" method="post">';
5 echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
6 foreach( $cache_rejected_user_agent as $ua ) {
7 echo esc_html( $ua ) . "\n";
8 }
9 echo '</textarea> ';
10 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save UA Strings', 'wp-super-cache' ) . '" /></div>';
11 wp_nonce_field('wp-cache');
12 echo '</form>';
13 echo "</fieldset>\n";
14
1 <?php
2 echo '<fieldset class="options"><h4>' . __( 'Fix Configuration', 'wp-super-cache' ) . '</h4>';
3 echo '<form name="wp_restore" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#top' ) . '" method="post">';
4 echo '<input type="hidden" name="wp_restore_config" />';
5 echo '<div class="submit"><input class="button-secondary" type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="' . __( 'Restore Default Configuration', 'wp-super-cache' ) . '" /></div>';
6 wp_nonce_field('wp-cache');
7 echo "</form>\n";
8 echo '</fieldset>';
1 <?php
2 echo '<a name="trackingparameters"></a><fieldset class="options"><h4>' . __( 'Tracking Parameters', 'wp-super-cache' ) . '</h4>';
3 echo '<form name="edit_tracking_parameters" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#trackingparameters' ) . '" method="post">';
4 echo "<p>" . __( 'Tracking parameters to ignore when caching. Visitors from Facebook, Twitter and elsewhere to your website will go to a URL with tracking parameters added. This setting allows the plugin to ignore those parameters and show an already cached page. Any actual tracking by Google Analytics or other Javascript based code should still work as the URL of the page is not modified.', 'wp-super-cache' ) . "</p>\n";
5 echo '<textarea name="tracking_parameters" cols="20" rows="10" style="width: 50%; font-size: 12px;" class="code">';
6 foreach ( $wpsc_tracking_parameters as $parameter) {
7 echo esc_html( $parameter ) . "\n";
8 }
9 echo '</textarea> ';
10 echo "<p><label><input type='checkbox' name='wpsc_ignore_tracking_parameters' value='1' " . checked( 1, $wpsc_ignore_tracking_parameters, false ) . " /> " . __( 'Enable', 'wp-super-cache' ) . "</label></p>";
11 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save', 'wp-super-cache' ) . '" /></div>';
12 wp_nonce_field('wp-cache');
13 echo "</form>\n";
1 <?php
2
3 function awaitingmoderation_action( $buffer ) {
4 $buffer = str_replace( __( 'Your comment is awaiting moderation.', 'wp-super-cache' ), '', $buffer );
5 return $buffer;
6 }
7
8 function awaitingmoderation_actions() {
9 global $cache_awaitingmoderation;
10 if ( '1' === $cache_awaitingmoderation ) {
11 add_filter( 'wpsupercache_buffer', 'awaitingmoderation_action' );
12 }
13 }
14 add_cacheaction( 'add_cacheaction', 'awaitingmoderation_actions' );
15
16 // Your comment is awaiting moderation.
17 function wp_supercache_awaitingmoderation_admin() {
18 global $cache_awaitingmoderation, $wp_cache_config_file, $valid_nonce;
19
20 $cache_awaitingmoderation = '' === $cache_awaitingmoderation ? '0' : $cache_awaitingmoderation;
21
22 if ( isset( $_POST['cache_awaitingmoderation'] ) && $valid_nonce ) {
23 $cache_awaitingmoderation = (int) $_POST['cache_awaitingmoderation'];
24 wp_cache_replace_line( '^ *\$cache_awaitingmoderation', "\$cache_awaitingmoderation = '$cache_awaitingmoderation';", $wp_cache_config_file );
25 $changed = true;
26 } else {
27 $changed = false;
28 }
29 $id = 'awaitingmoderation-section';
30 ?>
31 <fieldset id="<?php echo $id; ?>" class="options">
32 <h4><?php _e( 'Awaiting Moderation', 'wp-super-cache' ); ?></h4>
33 <form name="wp_manager" action="" method="post">
34 <label><input type="radio" name="cache_awaitingmoderation" value="1" <?php if ( $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
35 <label><input type="radio" name="cache_awaitingmoderation" value="0" <?php if ( ! $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
36 <p><?php _e( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ); ?></p>
37 <?php
38 if ( $changed ) {
39 if ( $cache_awaitingmoderation ) {
40 $status = __( 'enabled', 'wp-super-cache' );
41 } else {
42 $status = __( 'disabled', 'wp-super-cache' );
43 }
44 echo '<p><strong>' . sprintf( __( 'Awaiting Moderation is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
45 }
46 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
47 wp_nonce_field( 'wp-cache' );
48 ?>
49 </form>
50 </fieldset>
51 <?php
52
53 }
54 add_cacheaction( 'cache_admin_page', 'wp_supercache_awaitingmoderation_admin' );
55
56 function wpsc_awaiting_moderation_list( $list ) {
57 $list['awaitingmoderation'] = array(
58 'key' => 'awaitingmoderation',
59 'url' => '',
60 'title' => __( 'Awaiting Moderation', 'wp-super-cache' ),
61 'desc' => __( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ),
62 );
63 return $list;
64 }
65 add_cacheaction( 'wpsc_filter_list', 'wpsc_awaiting_moderation_list' );
1 <?php
2
3 function wp_supercache_badbehaviour( $file ) {
4 global $cache_badbehaviour;
5
6 if ( 1 !== $cache_badbehaviour ) {
7 return $file;
8 }
9 wp_supercache_badbehaviour_include();
10 return $file;
11 }
12 add_cacheaction( 'wp_cache_served_cache_file', 'wp_supercache_badbehaviour' );
13
14 function wp_supercache_badbehaviour_include() {
15 $bbfile = get_bb_file_loc();
16 if ( ! $bbfile ) {
17 require_once $bbfile;
18 }
19 }
20
21 function get_bb_file_loc() {
22 global $cache_badbehaviour_file;
23 if ( $cache_badbehaviour_file ) {
24 return $cache_badbehaviour_file;
25 }
26
27 if ( file_exists( WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php' ) ) {
28 $bbfile = WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php';
29 } elseif ( file_exists( WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php' ) ) {
30 $bbfile = WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php';
31 } else {
32 $bbfile = false;
33 }
34 return $bbfile;
35 }
36
37 function wp_supercache_badbehaviour_admin() {
38 global $cache_badbehaviour, $wp_cache_config_file, $valid_nonce;
39
40 $cache_badbehaviour = '' === $cache_badbehaviour ? 0 : $cache_badbehaviour;
41 if ( 'no' === $cache_badbehaviour ) {
42 $cache_badbehaviour = 0;
43 }
44
45 $err = false;
46
47 if ( isset( $_POST['cache_badbehaviour'] ) && $valid_nonce ) {
48 $bbfile = get_bb_file_loc();
49 if ( ! $bbfile ) {
50 $_POST['cache_badbehaviour'] = 0;
51 $err = __( 'Bad Behaviour not found. Please check your install.', 'wp-super-cache' );
52 }
53 if ( $cache_badbehaviour === (int) $_POST['cache_badbehaviour'] ) {
54 $changed = false;
55 } else {
56 $changed = true;
57 }
58 $cache_badbehaviour = (int) $_POST['cache_badbehaviour'];
59 wp_cache_replace_line( '^ *\$cache_compression', "\$cache_compression = 0;", $wp_cache_config_file );
60 wp_cache_replace_line( '^ *\$cache_badbehaviour', "\$cache_badbehaviour = $cache_badbehaviour;", $wp_cache_config_file );
61 wp_cache_replace_line( '^ *\$cache_badbehaviour_file', "\$cache_badbehaviour_file = '$bbfile';", $wp_cache_config_file );
62 $changed = true;
63 }
64 $id = 'badbehavior-section';
65 ?>
66 <fieldset id="<?php echo $id; ?>" class="options">
67 <h4><?php _e( 'Bad Behavior', 'wp-super-cache' ); ?></h4>
68 <form name="wp_manager" action="" method="post">
69 <label><input type="radio" name="cache_badbehaviour" value="1" <?php if ( $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
70 <label><input type="radio" name="cache_badbehaviour" value="0" <?php if ( ! $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
71 <p><?php _e( '', 'wp-super-cache' ); ?></p><?php
72 echo '<p>' . sprintf( __( '(Only WPCache caching supported, disabled compression and requires <a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p>';
73 if ( isset( $changed ) && $changed ) {
74 if ( $cache_badbehaviour ) {
75 $status = __( 'enabled', 'wp-super-cache' );
76 } else {
77 $status = __( 'disable', 'wp-super-cache' );
78 }
79 echo '<p><strong>' . sprintf( __( 'Bad Behavior support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
80 }
81 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
82 wp_nonce_field( 'wp-cache' );
83 ?>
84 </form>
85 </fieldset>
86 <?php
87 if ( $err ) {
88 echo '<p><strong>' . __( 'Warning!', 'wp-super-cache' ) . "</strong> $err</p>";
89 }
90
91 }
92 add_cacheaction( 'cache_admin_page', 'wp_supercache_badbehaviour_admin' );
93
94 function wpsc_badbehaviour_list( $list ) {
95 $list['badbehaviour'] = array(
96 'key' => 'badbehaviour',
97 'url' => 'http://www.bad-behavior.ioerror.us/',
98 'title' => __( 'Bad Behavior', 'wp-super-cache' ),
99 'desc' => sprintf( __( 'Support for Bad Behavior. (Only WPCache caching supported, disabled compression and requires Bad Behavior in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ),
100 );
101 return $list;
102 }
103 add_cacheaction( 'wpsc_filter_list', 'wpsc_badbehaviour_list' );
1 <?php
2
3 function domain_mapping_gc_cache( $function, $directory ) {
4 global $cache_path;
5
6 if ( ! function_exists( 'domain_mapping_warning' ) ) {
7 return;
8 }
9
10 $siteurl = domain_mapping_siteurl( false );
11 if ( ! $siteurl ) {
12 return;
13 }
14
15 $sitedir = trailingslashit( preg_replace( '`^(https?:)?//`', '', $siteurl ) );
16
17 if ( 'homepage' === $directory ) {
18 $directory = '';
19 }
20
21 switch ( $function ) {
22 case 'rebuild':
23 wpsc_rebuild_files( $cache_path . 'supercache/' . $sitedir . $directory );
24 break;
25 case 'prune':
26 wpsc_delete_files( $cache_path . 'supercache/' . $sitedir . $directory );
27 break;
28 }
29 }
30
31 function domain_mapping_supercachedir( $dir ) {
32 global $cache_path;
33
34 if ( ! function_exists( 'domain_mapping_warning' ) ) {
35 return $dir;
36 }
37
38 $siteurl = domain_mapping_siteurl( false );
39 if ( ! $siteurl ) {
40 return $dir;
41 }
42
43 $sitedir = trailingslashit( preg_replace( '`^(https?:)?//`', '', $siteurl ) );
44
45 return trailingslashit( $cache_path . 'supercache/' . $sitedir );
46 }
47
48 function domain_mapping_actions() {
49 global $cache_domain_mapping;
50
51 $cache_domain_mapping = (int) $cache_domain_mapping;
52 if ( 1 !== $cache_domain_mapping ) {
53 return;
54 }
55
56 add_filter( 'wp_super_cache_supercachedir', 'domain_mapping_supercachedir' );
57 add_action( 'gc_cache', 'domain_mapping_gc_cache', 10, 2 );
58 }
59 add_cacheaction( 'add_cacheaction', 'domain_mapping_actions' );
60
61 function wp_supercache_domain_mapping_admin() {
62 global $cache_domain_mapping, $wp_cache_config_file, $valid_nonce;
63
64 $requested_state = isset( $_POST['cache_domain_mapping'] ) ? (int) $_POST['cache_domain_mapping'] : null;
65 $cache_domain_mapping = (int) $cache_domain_mapping;
66
67 $changed = false;
68 if ( null !== $requested_state && $valid_nonce ) {
69 $cache_domain_mapping = $requested_state;
70
71 wp_cache_replace_line( '^\s*\$cache_domain_mapping\s*=', '$cache_domain_mapping = ' . intval( $cache_domain_mapping ) . ';', $wp_cache_config_file );
72 $changed = true;
73 }
74
75 $id = 'domain_mapping-section';
76 ?>
77 <fieldset id="<?php echo esc_attr( $id ); ?>" class="options">
78
79 <h4><?php esc_html_e( 'Domain Mapping', 'wp-super-cache' ); ?></h4>
80
81 <form name="wp_manager" action="" method="post">
82 <label><input type="radio" name="cache_domain_mapping" value="1" <?php checked( $cache_domain_mapping ); ?>/> <?php esc_html_e( 'Enabled', 'wp-super-cache' ); ?></label>
83 <label><input type="radio" name="cache_domain_mapping" value="0" <?php checked( ! $cache_domain_mapping ); ?>/> <?php esc_html_e( 'Disabled', 'wp-super-cache' ); ?></label>
84 <?php
85 echo '<p>' . __( 'Provides support for <a href="https://wordpress.org/plugins/wordpress-mu-domain-mapping/">Domain Mapping</a> plugin to map multiple domains to a blog.', 'wp-super-cache' ) . '</p>';
86
87 if ( $changed ) {
88 echo '<p><strong>' . sprintf(
89 esc_html__( 'Domain Mapping support is now %s', 'wp-super-cache' ),
90 esc_html( $cache_domain_mapping ? __( 'enabled', 'wp-super-cache' ) : __( 'disabled', 'wp-super-cache' ) )
91 ) . '</strong></p>';
92 }
93
94 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . ' type="submit" value="' . esc_html__( 'Update', 'wp-super-cache' ) . '" /></div>';
95 wp_nonce_field( 'wp-cache' );
96 ?>
97 </form>
98
99 </fieldset>
100 <?php
101 }
102 add_cacheaction( 'cache_admin_page', 'wp_supercache_domain_mapping_admin' );
103
104 function wp_supercache_domain_mapping_notice() {
105 global $cache_enabled;
106
107 if ( $cache_enabled ) {
108 echo '<div class="error"><p><strong>' . esc_html__( 'Domain Mapping plugin detected! Please go to the Supercache plugins page and enable the domain mapping helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
109 }
110 }
111 function wp_supercache_domain_mapping_exists() {
112 global $cache_domain_mapping;
113
114 $cache_domain_mapping = (int) $cache_domain_mapping;
115 if ( 1 === $cache_domain_mapping ) {
116 return;
117 }
118
119 if ( is_admin() && function_exists( 'domain_mapping_warning' ) ) {
120 add_action( 'admin_notices', 'wp_supercache_domain_mapping_notice' );
121 }
122 }
123
124 if ( isset( $_GET['page'] ) && 'wpsupercache' === $_GET['page'] ) {
125 add_cacheaction( 'add_cacheaction', 'wp_supercache_domain_mapping_exists' );
126 }
127
128 function wpsc_domain_mapping_list( $list ) {
129 $list['domain_mapping'] = array(
130 'key' => 'domain_mapping',
131 'url' => 'https://wordpress.org/plugins/wordpress-mu-domain-mapping/',
132 'title' => esc_html__( 'Domain Mapping', 'wp-super-cache' ),
133 'desc' => esc_html__( 'Provides support for Domain Mapping plugin to map multiple domains to a blog.', 'wp-super-cache' ),
134 );
135 return $list;
136 }
137 add_cacheaction( 'wpsc_filter_list', 'wpsc_domain_mapping_list' );
1 <?php
2
3 /*
4 * On the Advanced Settings page enable "Enable dynamic caching" and clear
5 * the cache.
6 *
7 * Plugin authors: NEVER define the template tag for your users. Make them
8 * choose one so it will be unique to their site.
9 *
10 * There are two examples in this file. Both use template tags that must be
11 * kept secret.
12 *
13 * GLOSSARY:
14 *
15 * Dynamic content: the text or widget you want to show visitors to your site
16 * that changes every time it's viewed.
17 * Placeholder/template tag: the string of random characters placed in your
18 * theme file or printed in an action where the dynamic content will go.
19 * Output buffer (ob): any text that is printed by PHP to be sent to the browser
20 * but captured by PHP for further manipulation.
21 * OB Callback function: A function that is called when the output buffer is
22 * filled with a html page. The contents of the page are passed to the function
23 * for processing.
24 *
25 * **** MAKE SURE YOU KEEP THE TEMPLATE TAG SECRET ****
26 * You should probably add 'deny from all' to the .htaccess in the cache directory
27 * so visitors can't directly load any cached html files and discover the secret
28 * tag. Or you can move the cache directory out of the web path and set the
29 * cache location to that new directory on the advanced settings page.
30 *
31 */
32
33 /*
34 * EXAMPLE 1
35 * http://ocaoimh.ie/2013/10/21/shiny-new-dynamic-content-wp-super-cache/
36 * Replace a string in your theme with the dynamic content.
37 *
38 * dynamic_cache_test_init()
39 * This function is the first one to be called. This function hooks
40 * dynamic_cache_test_template() to the WordPress action, wp_footer.
41 * This script is loaded before WordPress is and the add_action()
42 * function isn't defined at this time.
43 * This init function hooks onto the cache action "add_cacheaction"
44 * that fires after WordPress (and add_action) is loaded.
45 *
46 *
47 * dynamic_cache_test_template_tag()
48 * This function hooks on to wp_footer and displays the secret template
49 * tag that will be replaced by our dynamic content on each page view.
50 *
51 *
52 * dynamic_cache_test_filter()
53 * This function hooks on to the filter through which all the cached data
54 * sent to visitors is sent.
55 * In this simple example the template tag is replaced by a html comment
56 * containing the text "Hello world at " and the current server time.
57 * If you want to use the output of a WordPress plugin or command you
58 * must enable "late init" on the settings page. Each time you reload
59 * the cached page this time will change. View the page source to examine
60 * this text.
61 *
62 * Chronology of a request:
63 * 1. dynamic_cache_test_init() hooks dynamic_cache_test_template_tag() on
64 * to the wp_footer action. dynamic_cache_test_filter() is hooked on to
65 * the wpsc_cachedata filter.
66 * 2. An output buffer is created by WP Super Cache.
67 * 3. Most of the page is generated by WordPress.
68 * 4. The wp_footer action fires and the TAG is printed to the page.
69 * 5. Processing continues and the page is created.
70 * 6. The output buffer finishes. A WP Super Cache callback function runs
71 * and saves the output buffer to a cache file. The wpsc_cachedata
72 * filter is called.
73 * 7. The function dynamic_cache_test_filter() runs and replaces the TAG in
74 * the buffer with the "Hello world" string.
75 * 8. The output buffer is pushed to the browser to be displayed.
76 */
77 define( 'DYNAMIC_CACHE_TEST_TAG', '' ); // Change this to a secret placeholder tag.
78 if ( '' !== DYNAMIC_CACHE_TEST_TAG ) {
79 function dynamic_cache_test_safety( $safety ) {
80 return 1;
81 }
82 add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_cache_test_safety' );
83
84 function dynamic_cache_test_filter( $cachedata ) {
85 return str_replace( DYNAMIC_CACHE_TEST_TAG, '<!-- Hello world at ' . date( 'H:i:s' ) . ' -->', $cachedata );
86 }
87 add_cacheaction( 'wpsc_cachedata', 'dynamic_cache_test_filter' );
88
89 function dynamic_cache_test_template_tag() {
90 echo DYNAMIC_CACHE_TEST_TAG; // This is the template tag.
91 }
92
93 function dynamic_cache_test_init() {
94 add_action( 'wp_footer', 'dynamic_cache_test_template_tag' );
95 }
96 add_cacheaction( 'add_cacheaction', 'dynamic_cache_test_init' );
97 }
98
99 /*
100 * EXAMPLE 2
101 *
102 * This is going to be complicated. Hang on!
103 *
104 * When the cache file for a new page is generated the plugin uses an output
105 * buffer to capture the page. A callback function processes the buffer and
106 * writes to the cache file. The placeholder tag for any dynamic content has
107 * to be written to that cache file but also, it has to be replaced with
108 * dynamic content before the page is shown to the user.
109 * More on output buffers here: http://php.net/ob_start
110 *
111 * Unfortunately an extra output buffer is often required when capturing dynamic
112 * content such as sidebar widgets. Due to a quirk of the way PHP works it's
113 * not possible to have an output buffer run in an output buffer callback. That
114 * dynamic content has to be generated before the callback function is reached.
115 * The following error occurs when an output buffer is created in the
116 * callback function of another output buffer:
117 * "PHP Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in..."
118 *
119 * In this example the function add_action() isn't available when this file is
120 * loaded so dynamic_output_buffer_init() is hooked on to the "add_cacheaction"
121 * cacheaction. That function then hooks dynamic_output_buffer_test() on to the
122 * familiar wp_footer action.
123 *
124 * The first time dynamic_output_buffer_test() runs it generates the dynamic
125 * content and captures it with ob_start() in the DYNAMIC_OB_TEXT constant.
126 *
127 * When the main WP Super Cache output buffer is ready the callback is called.
128 * This fires the wpsc_cachedata_safety filter. If the DYNAMIC_OB_TEXT constant
129 * is set, which means dynamic content is ready, then it returns 1, a signal
130 * that everything is ok.
131 * Finally, the wpsc_cachedata filter is run. The function
132 * dynamic_output_buffer_test() is hooked on to it. Since DYNAMIC_OB_TEXT is
133 * set it replaces the placeholder text with that constant.
134 * The resulting html is then sent to the browser.
135 *
136 * Already cached pages call the safety filter, and then the wpsc_cachedata
137 * filter so any hooked function must be ready to generate dynamic content. The
138 * very last line of dynamic_output_buffer_test() replaces the placeholder tag
139 * with the dynamic content in the cache file.
140 *
141 * Use an output buffer to capture dynamic content while the page is generated
142 * and insert into the right place:
143 * Remember to add the DYNAMIC_OUTPUT_BUFFER_TAG text (as defined below) to
144 * your theme where the dynamic content should be.
145 *
146 * dynamic_output_buffer_test() is a function that uses the wpsc_cachedata
147 * filter to add a small message and the current server time to every web
148 * page. The time increments on every reload.
149 *
150 */
151
152 define( 'DYNAMIC_OUTPUT_BUFFER_TAG', '' ); // Change this to a secret placeholder tag.
153
154 if ( '' !== DYNAMIC_OUTPUT_BUFFER_TAG ) {
155 function dynamic_output_buffer_test( $cachedata = 0 ) {
156 if ( defined( 'DYNAMIC_OB_TEXT' ) ) {
157 return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
158 }
159
160 ob_start();
161 // call the sidebar function, do something dynamic
162 echo '<p>This is a test. The current time on the server is: ' . date( 'H:i:s' ) . '</p>';
163 $text = ob_get_contents();
164 ob_end_clean();
165
166 if ( 0 === $cachedata ) { // called directly from the theme so store the output.
167 define( 'DYNAMIC_OB_TEXT', $text );
168 } else { // called via the wpsc_cachedata filter. We only get here in cached pages in wp-cache-phase1.php.
169 return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
170 }
171
172 }
173 add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_test' );
174
175 function dynamic_output_buffer_init() {
176 add_action( 'wp_footer', 'dynamic_output_buffer_test' );
177 }
178 add_cacheaction( 'add_cacheaction', 'dynamic_output_buffer_init' );
179
180 function dynamic_output_buffer_test_safety( $safety ) {
181 if ( defined( 'DYNAMIC_OB_TEXT' ) ) {// this is set when you call dynamic_output_buffer_test() from the theme.
182 return 1; // ready to replace tag with dynamic content.
183 } else {
184 return 0; // tag cannot be replaced.
185 }
186 }
187 add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
188 }
1 <?php
2
3 function wp_super_cache_jetpack_admin() {
4 global $cache_jetpack, $wp_cache_config_file, $valid_nonce;
5
6 $cache_jetpack = '' === $cache_jetpack ? '0' : $cache_jetpack;
7
8 if ( isset( $_POST['cache_jetpack'] ) && $valid_nonce ) {
9 if ( $cache_jetpack === (int) $_POST['cache_jetpack'] ) {
10 $changed = false;
11 } else {
12 $changed = true;
13 }
14 $cache_jetpack = (int) $_POST['cache_jetpack'];
15 wp_cache_replace_line( '^ *\$cache_jetpack', "\$cache_jetpack = '$cache_jetpack';", $wp_cache_config_file );
16 if ( $changed && $cache_jetpack ) {
17 wp_cache_replace_line( '^ *\$wp_cache_mobile_enabled', '$wp_cache_mobile_enabled = 1;', $wp_cache_config_file );
18 wp_cache_replace_line( '^ *\$wp_cache_mod_rewrite', '$wp_cache_mod_rewrite = 0;', $wp_cache_config_file );
19 wp_cache_replace_line( '^ *\$super_cache_enabled', '$super_cache_enabled = 1;', $wp_cache_config_file );
20 }
21 }
22 $id = 'jetpack-section';
23 ?>
24 <fieldset id="<?php echo $id; ?>" class="options">
25 <h4><?php _e( 'Jetpack Mobile Theme', 'wp-super-cache' ); ?></h4>
26 <?php
27 if ( false === file_exists( dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php' ) ) {
28 echo '<strong>' . sprintf( __( 'Jetpack not found in %s. Install it and enable the mobile theme and this helper plugin to cache visits by mobile visitors.', 'wp-super-cache' ), dirname( WPCACHEHOME ) ) . '</strong>';
29 } else {
30 ?>
31 <form name="wp_manager" action="" method="post">
32 <label><input type="radio" name="cache_jetpack" value="1" <?php if ( $cache_jetpack ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
33 <label><input type="radio" name="cache_jetpack" value="0" <?php if ( ! $cache_jetpack ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
34 <?php
35 echo '<p>' . __( 'Provides support for the <a href="https://wordpress.org/plugins/jetpack/">Jetpack</a> mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ) . '</p>';
36 if ( isset( $changed ) && $changed ) {
37 if ( $cache_jetpack ) {
38 $status = __( 'enabled', 'wp-super-cache' );
39 } else {
40 $status = __( 'disabled', 'wp-super-cache' );
41 }
42 echo '<p><strong>' . sprintf( __( 'Jetpack Mobile Theme support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
43 }
44 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
45 wp_nonce_field( 'wp-cache' );
46 ?>
47 </form>
48 <?php } ?>
49 </fieldset>
50 <?php
51 }
52 add_cacheaction( 'cache_admin_page', 'wp_super_cache_jetpack_admin' );
53
54 function wp_super_cache_jetpack_cookie_check( $cache_key ) {
55 if ( false === function_exists( 'jetpack_is_mobile' ) ) {
56
57 if ( file_exists( dirname( WPCACHEHOME ) . '/jetpack-dev/class.jetpack-user-agent.php' ) ) {
58 wp_cache_debug( "wp_super_cache_jetpack_cookie_check: jetpack dev detected. Returning 'normal' to avoid loading Jetpack." );
59 return 'normal';
60 } elseif ( file_exists( dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php' ) ) {
61 include_once dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php';
62 } else {
63 wp_cache_debug( 'wp_super_cache_jetpack_cookie_check: jetpack UA file not found.' );
64 }
65 }
66
67 if ( isset ( $_COOKIE['akm_mobile'] ) ) {
68 if ( $_COOKIE['akm_mobile'] == 'true' ) {
69 return 'mobile';
70 } elseif ( $_COOKIE['akm_mobile'] == 'false' ) {
71 return 'normal';
72 }
73 }
74
75 if ( function_exists( 'jetpack_is_mobile' ) ) {
76 if ( jetpack_is_mobile() ) {
77 return 'mobile';
78 } else {
79 return 'normal';
80 }
81 } else {
82 return 'normal';
83 }
84 }
85
86 if ( isset( $cache_jetpack ) && '1' === $cache_jetpack ) {
87 add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_jetpack_cookie_check' );
88 }
89
90 function wpsc_cache_jetpack_list( $list ) {
91 $list['jetpack'] = array(
92 'key' => 'jetpack',
93 'url' => 'https://wordpress.org/plugins/jetpack/',
94 'title' => __( 'Jetpack Mobile Theme', 'wp-super-cache' ),
95 'desc' => __( 'Provides support for the Jetpack mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ),
96 );
97 return $list;
98 }
99 add_cacheaction( 'wpsc_filter_list', 'wpsc_cache_jetpack_list' );
1 <?php
2
3 if ( is_multisite() ) {
4 add_cacheaction( 'add_cacheaction', 'wp_super_cache_multisite_init' );
5 }
6
7 function wp_super_cache_multisite_init() {
8 add_filter( 'wpmu_blogs_columns', 'wp_super_cache_blogs_col' );
9 add_action( 'manage_sites_custom_column', 'wp_super_cache_blogs_field', 10, 2 );
10 add_action( 'init', 'wp_super_cache_override_on_flag', 9 );
11 }
12
13 function wp_super_cache_blogs_col( $col ) {
14 $col['wp_super_cache'] = __( 'Cached', 'wp-super-cache' );
15 return $col;
16 }
17
18 function wp_super_cache_blogs_field( $name, $blog_id ) {
19 if ( 'wp_super_cache' !== $name ) {
20 return false;
21 }
22
23 $blog_id = (int) $blog_id;
24
25 if ( isset( $_GET['id'], $_GET['action'], $_GET['_wpnonce'] )
26 && $blog_id === filter_input( INPUT_GET, 'id', FILTER_VALIDATE_INT )
27 && wp_verify_nonce( $_GET['_wpnonce'], 'wp-cache' . $blog_id )
28 ) {
29 if ( 'disable_cache' === filter_input( INPUT_GET, 'action' ) ) {
30 add_blog_option( $blog_id, 'wp_super_cache_disabled', 1 );
31 } elseif ( 'enable_cache' === filter_input( INPUT_GET, 'action' ) ) {
32 delete_blog_option( $blog_id, 'wp_super_cache_disabled' );
33 }
34 }
35
36 if ( 1 === (int) get_blog_option( $blog_id, 'wp_super_cache_disabled' ) ) {
37 echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'enable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Enable', 'wp-super-cache' ) . '</a>';
38 } else {
39 echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'disable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Disable', 'wp-super-cache' ) . '</a>';
40 }
41 }
42
43 function wp_super_cache_multisite_notice() {
44 if ( 'wpsupercache' === filter_input( INPUT_GET, 'page' ) ) {
45 echo '<div class="error"><p><strong>' . __( 'Caching has been disabled on this blog on the Network Admin Sites page.', 'wp-super-cache' ) . '</strong></p></div>';
46 }
47 }
48
49 function wp_super_cache_override_on_flag() {
50 global $cache_enabled, $super_cache_enabled;
51 if ( true !== $cache_enabled ) {
52 return false;
53 }
54
55 if ( 1 === (int) get_option( 'wp_super_cache_disabled' ) ) {
56 $cache_enabled = false;
57 $super_cache_enabled = false;
58 define( 'DONOTCACHEPAGE', 1 );
59 define( 'SUBMITDISABLED', 'disabled style="color: #aaa" ' );
60 if ( is_admin() ) {
61 add_action( 'admin_notices', 'wp_super_cache_multisite_notice' );
62 }
63 }
64 }
1 <?php
2
3 function wp_super_cache_wptouch_admin() {
4 global $cache_wptouch, $wp_cache_config_file, $valid_nonce;
5
6 $cache_wptouch = '' === $cache_wptouch ? '0' : $cache_wptouch;
7
8 if ( isset( $_POST['cache_wptouch'] ) && $valid_nonce ) {
9 if ( $cache_wptouch === (int) $_POST['cache_wptouch'] ) {
10 $changed = false;
11 } else {
12 $changed = true;
13 }
14 $cache_wptouch = (int) $_POST['cache_wptouch'];
15 wp_cache_replace_line( '^ *\$cache_wptouch', "\$cache_wptouch = '$cache_wptouch';", $wp_cache_config_file );
16 }
17 $id = 'wptouch-section';
18 ?>
19 <fieldset id="<?php echo $id; ?>" class="options">
20 <h4><?php _e( 'WPTouch', 'wp-super-cache' ); ?></h4>
21 <form name="wp_manager" action="" method="post">
22 <label><input type="radio" name="cache_wptouch" value="1" <?php if ( $cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
23 <label><input type="radio" name="cache_wptouch" value="0" <?php if ( ! $cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
24 <?php
25 echo '<p>' . __( 'Provides support for <a href="https://wordpress.org/plugins/wptouch/">WPTouch</a> mobile theme and plugin.', 'wp-super-cache' ) . '</p>';
26 if ( isset( $changed ) && $changed ) {
27 if ( $cache_wptouch ) {
28 $status = __( 'enabled', 'wp-super-cache' );
29 } else {
30 $status = __( 'disabled', 'wp-super-cache' );
31 }
32 echo '<p><strong>' . sprintf( __( 'WPTouch support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
33 }
34 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
35 wp_nonce_field( 'wp-cache' );
36 ?>
37 </form>
38 </fieldset>
39 <?php
40 }
41 add_cacheaction( 'cache_admin_page', 'wp_super_cache_wptouch_admin' );
42
43 function wp_super_cache_wptouch_notice() {
44 global $cache_enabled;
45 if ( $cache_enabled ) {
46 echo '<div class="error"><p><strong>' . __( 'WPTouch plugin detected! Please go to the Supercache plugins page and enable the WPTouch helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
47 }
48 }
49 function wp_super_cache_wptouch_exists() {
50 global $cache_wptouch;
51 if ( '1' === $cache_wptouch ) {
52 return false;
53 }
54
55 if ( is_admin() && function_exists( 'wptouch_get_plugin_dir_name' ) ) {
56 add_action( 'admin_notices', 'wp_super_cache_wptouch_notice' );
57 }
58 }
59
60 if ( isset( $_GET['page'] ) && 'wpsupercache' === $_GET['page'] ) {
61 add_cacheaction( 'add_cacheaction', 'wp_super_cache_wptouch_exists' );
62 }
63
64 // disable mobile checking if.
65 function wp_super_cache_maybe_disable_wptouch( $t ) {
66 global $cache_wptouch, $wptouch_exclude_ua;
67 if ( '1' !== $cache_wptouch ) {
68 return false;
69 }
70
71 if ( ( isset( $_COOKIE['wptouch_switch_toggle'] ) && 'normal' === $_COOKIE['wptouch_switch_toggle'] ) ||
72 ( isset( $_COOKIE['wptouch-pro-view'] ) && 'desktop' === $_COOKIE['wptouch-pro-view'] ) ) {
73 return true;
74 }
75
76 $ua = explode( ',', $wptouch_exclude_ua );
77 foreach ( $ua as $agent ) {
78 if ( preg_match( "#$agent#i", $_SERVER['HTTP_HOST'] ) ) {
79 return true; // disable mobile ua check if matches the exclude list in wptouch.
80 }
81 }
82
83 return false;
84
85 }
86
87 add_cacheaction( 'disable_mobile_check', 'wp_super_cache_maybe_disable_wptouch' );
88
89 function wp_super_cache_wptouch_browsers( $browsers ) {
90 global $wptouch_exclude_ua, $wp_cache_config_file;
91
92 if ( false === function_exists( 'bnc_wptouch_get_exclude_user_agents' ) || false === function_exists( 'bnc_wptouch_get_user_agents' ) ) {
93 return $browsers;
94 }
95
96 $browsers = implode( ',', bnc_wptouch_get_exclude_user_agents() ); // hack, support exclude agents too.
97 if ( $browsers !== $wptouch_exclude_ua ) {
98 wp_cache_replace_line( '^ *\$wptouch_exclude_ua', "\$wptouch_exclude_ua = '$browsers';", $wp_cache_config_file );
99 $wptouch_exclude_ua = $browsers;
100 }
101
102 return bnc_wptouch_get_user_agents();
103 }
104
105 function wp_super_cache_wptouch_prefixes( $prefixes ) {
106 return array(); // wptouch doesn't support UA prefixes.
107 }
108
109 function wp_super_cache_wptouch_cookie_check( $cache_key ) {
110 if ( false === isset( $_COOKIE['wptouch_switch_toggle'] ) ) {
111 return $cache_key;
112 }
113 if ( 'normal' === $_COOKIE['wptouch_switch_toggle'] || 'mobile' === $_COOKIE['wptouch_switch_toggle'] ) {
114 return $_COOKIE['wptouch_switch_toggle'];
115 }
116
117 if ( isset( $_COOKIE['wptouch-pro-view'] ) ) {
118 if ( 'desktop' === $_COOKIE['wptouch-pro-view'] ) {
119 return 'normal';
120 } else {
121 return $_COOKIE['wptouch-pro-view'];
122 }
123 }
124
125 return $cache_key;
126 }
127
128 if ( isset( $cache_wptouch ) && '1' === $cache_wptouch ) {
129 add_cacheaction( 'wp_super_cache_mobile_browsers', 'wp_super_cache_wptouch_browsers' );
130 add_cacheaction( 'wp_super_cache_mobile_prefixes', 'wp_super_cache_wptouch_prefixes' );
131 add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_wptouch_cookie_check' );
132 }
133
134 function wpsc_wptouch_list( $list ) {
135 $list['wptouch'] = array(
136 'key' => 'wptouch',
137 'url' => 'https://wordpress.org/plugins/wptouch/',
138 'title' => __( 'WPTouch', 'wp-super-cache' ),
139 'desc' => __( 'Provides support for WPTouch mobile theme and plugin.', 'wp-super-cache' ),
140 );
141 return $list;
142 }
143 add_cacheaction( 'wpsc_filter_list', 'wpsc_wptouch_list' );
1 <?php
2
3 class WP_Super_Cache_Rest_Delete_Cache extends WP_REST_Controller {
4
5 /**
6 * Get a collection of items
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 $params = $request->get_json_params();
13
14 if ( isset( $params['id'] ) && is_numeric( $params['id'] ) ) {
15 wpsc_delete_post_cache( $params['id'] );
16
17 } elseif ( !empty( $params['expired'] ) ) {
18 global $file_prefix;
19 wp_cache_clean_expired( $file_prefix );
20
21 } elseif ( isset( $params['url'] ) ) {
22 global $cache_path;
23
24 $directory = $cache_path . 'supercache/' . $params[ 'url' ];
25 wpsc_delete_files( $directory );
26 prune_super_cache( $directory . '/page', true );
27
28 } else {
29 global $file_prefix;
30 wp_cache_clean_cache( $file_prefix, !empty( $params['all'] ) );
31 }
32
33 return rest_ensure_response( array( 'Cache Cleared' => true ) );
34 }
35 }
1 <?php
2
3 class WP_Super_Cache_Rest_Get_Cache extends WP_REST_Controller {
4
5 /**
6 * Get a collection of items
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 global $valid_nonce;
13
14 $valid_nonce = true;
15 $_GET[ 'listfiles' ] = 1;
16 $sizes = wpsc_generate_sizes_array();
17 $supercachedir = get_supercache_dir();
18 $list = wpsc_dirsize( $supercachedir, $sizes );
19 $return_list = array();
20
21 foreach( $list as $type => $file_list ) {
22 foreach ( $file_list as $state => $value ) {
23 if ( is_array( $value ) ) {
24 foreach( $value as $filenames ) {
25 foreach( $filenames as $filename => $t ) {
26 if ( $type == 'wpcache' ) {
27 $filename = dirname( $filename );
28 }
29 if ( false == isset( $return_list[ $type ][ $state ] ) || false == in_array( $filename, $return_list[ $type ][ $state ] ) )
30 $return_list[ $type ][ $state ][] = $filename;
31 }
32 }
33 }
34 }
35
36 if ( isset ( $return_list[ $type ] ) ) {
37 $list[ $type ] = $return_list[ $type ];
38 }
39
40 unset( $return_list[ $type ] );
41 }
42
43 return rest_ensure_response( $list );
44 }
45 }
1 <?php
2
3 class WP_Super_Cache_Rest_Get_Plugins extends WP_REST_Controller {
4
5 /**
6 * GET a list of plugins through the /plugins/ endpoint
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12
13 $list = wpsc_get_plugin_list();
14 return rest_ensure_response( $list );
15 }
16 }
1 <?php
2
3 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-settings-map.php' );
4
5 class WP_Super_Cache_Rest_Get_Settings extends WP_REST_Controller {
6
7 /**
8 * Get the settings.
9 *
10 * @param WP_REST_Request $request Full data about the request.
11 * @return WP_Error|WP_REST_Response
12 */
13 public function callback( $request ) {
14 $settings = array();
15
16 global $wp_cache_config_file;
17
18 if ( defined( 'WPLOCKDOWN' ) ) {
19 $config_file = file_get_contents( $wp_cache_config_file );
20 if ( false === strpos( $config_file, "defined( 'WPLOCKDOWN' )" ) ) {
21 wp_cache_replace_line( '^.*WPLOCKDOWN', "if ( ! defined( 'WPLOCKDOWN' ) ) define( 'WPLOCKDOWN', " . $this->get_is_lock_down_enabled() . " );", $wp_cache_config_file );
22 }
23 }
24
25 if ( function_exists( "opcache_invalidate" ) ) {
26 @opcache_invalidate( $wp_cache_config_file );
27 }
28 include( $wp_cache_config_file );
29
30 foreach ( WP_Super_Cache_Settings_Map::$map as $name => $map ) {
31 if ( isset ( $map['get'] ) ) {
32 $get_method = $map['get'];
33
34 if ( method_exists( $this, $get_method ) ) {
35 $settings[ $name ] = $this->$get_method();
36
37 } elseif ( function_exists( $get_method ) ) {
38 $settings[ $name ] = $get_method();
39 }
40
41 } else if ( isset ( $map['option'] ) ) {
42 $settings[ $name ] = get_option( $map['option'] );
43
44 } elseif ( isset( $map['global'] ) ) {
45 if ( false == isset( $GLOBALS[ $map[ 'global' ] ] ) ) {
46 $settings[ $name ] = false;
47 } else {
48 $settings[ $name ] = $GLOBALS[ $map[ 'global' ] ];
49 }
50 }
51 }
52
53 return $this->prepare_item_for_response( $settings, $request );
54 }
55
56 /**
57 * @return string
58 */
59 public function get_ossdl_off_blog_url() {
60 $url = get_option( 'ossdl_off_blog_url' );
61 if ( ! $url )
62 $url = apply_filters( 'ossdl_off_blog_url', untrailingslashit( get_option( 'siteurl' ) ) );
63 return $url;
64 }
65
66 /**
67 * @return string
68 */
69 public function get_cache_path_url() {
70 global $cache_path;
71
72 return site_url( str_replace( ABSPATH, '', "{$cache_path}" ) );
73 }
74
75 /**
76 * @return string
77 */
78 public function get_cache_type() {
79 global $wp_cache_config_file;
80 if ( function_exists( "opcache_invalidate" ) ) {
81 @opcache_invalidate( $wp_cache_config_file );
82 }
83 include( $wp_cache_config_file );
84
85 if ( $wp_cache_mod_rewrite == 1 ) {
86 return 'mod_rewrite';
87 } else {
88 return 'PHP';
89 }
90 }
91
92 /**
93 * Prepare the item for the REST response
94 *
95 * @param mixed $item WordPress representation of the item.
96 * @param WP_REST_Request $request Request object.
97 * @return mixed
98 */
99 public function prepare_item_for_response( $item, $request ) {
100 $settings = array();
101
102 $integers = array( 'cache_max_time', 'preload_interval' );
103 $string_arrays = array( 'cache_stats', 'cache_acceptable_files', 'cache_rejected_uri', 'cache_rejected_user_agent',
104 'cache_direct_pages' );
105 foreach( $item as $key => $value ) {
106 if ( is_array( $value ) && false == in_array( $key, $string_arrays ) ) {
107 array_walk( $value, array( $this, 'make_array_bool' ) );
108
109 } elseif ( ( $value === 0 || $value === 1 ) && false == in_array( $key, $integers ) ) {
110 $value = (bool)$value;
111 }
112
113 $settings[ $key ] = $value;
114 }
115
116 $strings_to_bool = array( 'ossdl_https', 'refresh_current_only_on_comments' );
117 foreach( $strings_to_bool as $key ) {
118 if ( isset( $settings[ $key ] ) ) {
119 $settings[ $key ] = (bool)$settings[ $key ];
120 }
121 }
122
123 return rest_ensure_response( $settings );
124 }
125
126 /**
127 * @param mixed $value
128 * @param string $key
129 */
130 public function make_array_bool( &$value, $key ) {
131 if ( $value == 0 || $value == 1 ) {
132 $value = (bool) $value;
133 }
134 }
135
136 /**
137 * @return bool
138 */
139 protected function get_is_submit_enabled() {
140 global $wp_cache_config_file;
141 return is_writeable_ACLSafe( $wp_cache_config_file );
142 }
143
144 /**
145 * @return bool
146 */
147 protected function get_is_preload_enabled() {
148 return false === defined( 'DISABLESUPERCACHEPRELOADING' );
149 }
150
151 /**
152 * @return false|int
153 */
154 protected function get_next_gc() {
155 return wp_next_scheduled( 'wp_cache_gc' );
156 }
157
158 /**
159 * @return int
160 */
161 protected function get_is_preload_active() {
162 if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
163 return true;
164 } else {
165 return false;
166 }
167 }
168
169 /**
170 * @return int
171 */
172 protected function get_minimum_preload_interval() {
173 global $wpdb;
174 $count = $this->get_post_count();
175 if ( $count > 1000 ) {
176 $min_refresh_interval = 720;
177 } else {
178 $min_refresh_interval = 30;
179 }
180
181 return $min_refresh_interval;
182 }
183
184 /**
185 * @return int
186 */
187 protected function get_is_lock_down_enabled() {
188 if ( defined( 'WPLOCKDOWN' ) ) {
189 return constant( 'WPLOCKDOWN' ) ? 1 : 0;
190 }
191
192 return 0;
193 }
194
195 /**
196 * @return int
197 */
198 protected function get_post_count() {
199 return wpsc_post_count();
200 }
201
202 /**
203 * @return string
204 */
205 protected function get_default_cache_path() {
206 return WP_CONTENT_DIR . '/wp-cache/';
207 }
208 }
1 <?php
2
3 class WP_Super_Cache_Rest_Get_Stats extends WP_REST_Controller {
4
5 /**
6 * Get the cache stats for the site.
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 global $valid_nonce;
13 $_GET[ 'listfiles' ] = 1;
14 $valid_nonce = true;
15
16 return rest_ensure_response( wp_cache_regenerate_cache_file_stats() );
17 }
18 }
1 <?php
2
3 class WP_Super_Cache_Rest_Get_Status extends WP_REST_Controller {
4
5 /**
6 * Get any status that might be visible.
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 $status = array();
13
14 include_once( ABSPATH . 'wp-admin/includes/file.php' ); // get_home_path()
15 include_once( ABSPATH . 'wp-admin/includes/misc.php' ); // extract_from_markers()
16 $this->add_rewrite_status( $status );
17 $this->add_cache_disabled_status( $status );
18 $this->add_compression_status( $status );
19 $this->add_php_mod_rewrite_status( $status );
20 $this->add_preload_status( $status );
21
22 if ( empty( $status ) ) {
23 return rest_ensure_response( new stdclass() );
24 } else {
25 return rest_ensure_response( $status );
26 }
27 }
28
29 /**
30 * @param array $status
31 */
32 protected function add_preload_status( & $status ) {
33 global $wp_cache_config_file;
34
35 include( $wp_cache_config_file );
36
37 if ( false == $cache_enabled ) {
38 $status[ 'preload_disabled_cache_off' ] = true;
39 }
40 if ( false == $super_cache_enabled ) {
41 $status[ 'preload_disabled_supercache_off' ] = true;
42 }
43 if ( true === defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
44 $status[ 'preload_disabled_by_admin' ] = true;
45 }
46 }
47
48 /**
49 * @param array $status
50 */
51 protected function add_php_mod_rewrite_status( & $status ) {
52 global $wp_cache_config_file;
53
54 include( $wp_cache_config_file );
55
56 if ( $cache_enabled && !$wp_cache_mod_rewrite ) {
57 $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
58 if ( $scrules != '' ) {
59 $status[ 'php_mod_rewrite' ] = true;
60 }
61 }
62 }
63
64 /**
65 * @param array $status
66 */
67 protected function add_cache_disabled_status( & $status ) {
68 global $wp_cache_config_file;
69
70 if ( ! is_writeable_ACLSafe( $wp_cache_config_file ) ) {
71 $status['cache_disabled'] = true;
72 }
73 }
74
75 /**
76 * @param array $status
77 */
78 protected function add_compression_status( & $status ) {
79 if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
80 $status['compression_disabled_by_admin'] = true;
81 } elseif ( false == function_exists( 'gzencode' ) ) {
82 $status['compression_disabled_no_gzencode'] = true;
83 }
84 }
85
86 /**
87 * @param array $status
88 */
89 protected function add_rewrite_status( & $status ) {
90 global $home_path, $wp_cache_config_file;
91
92 include( $wp_cache_config_file );
93
94 // Return if the rewrite caching is disabled.
95 if ( ! $cache_enabled || ! $super_cache_enabled || ! $wp_cache_mod_rewrite ) {
96 return;
97 }
98
99 $scrules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) );
100 extract( wpsc_get_htaccess_info() );
101
102 if ( $scrules != $rules ) {
103 $status[ 'mod_rewrite_rules' ] = true;
104 }
105 $got_rewrite = apache_mod_loaded( 'mod_rewrite', true );
106 if ( $wp_cache_mod_rewrite && false == apply_filters( 'got_rewrite', $got_rewrite ) ) {
107 $status[ 'mod_rewrite_missing' ] = true;
108 }
109
110 if ( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
111 $status[ 'htaccess_ro' ] = true;
112 }
113 }
114 }
1 <?php
2
3 class WP_Super_Cache_Rest_Preload extends WP_REST_Controller {
4
5 /**
6 * Update the cache settings.
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 $parameters = $request->get_json_params();
13
14 if ( defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
15 wp_cache_debug( 'WP_Super_Cache_Rest_Preload: preload disabled by admin' );
16 return rest_ensure_response( array( 'error' => 'preload disabled by admin' ) );
17 }
18
19 if ( isset( $parameters[ 'enable' ] ) ) {
20 if ( $parameters[ 'enable' ] == true ) {
21 wp_cache_debug( 'WP_Super_Cache_Rest_Preload: enable' );
22 wpsc_enable_preload();
23 return( rest_ensure_response( array( 'enabled' => true ) ) );
24 } else {
25 wp_cache_debug( 'WP_Super_Cache_Rest_Preload: cancel' );
26 wpsc_cancel_preload();
27 return( rest_ensure_response( array( 'enabled' => false ) ) );
28 }
29 }
30 }
31 }
1 <?php
2
3 class WP_Super_Cache_Rest_Test_Cache extends WP_REST_Controller {
4
5 /**
6 * Get a collection of items
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 global $cache_path;
13
14 $url = trailingslashit( get_bloginfo( 'url' ) );
15
16 $response = array( 'status' => 'UNKNOWN' );
17 $has_errors = false;
18
19 $attempts = array( 'prime', 'first', 'second' );
20
21 $c = 0;
22 foreach ( $attempts as $attempt_name ) {
23 $attempt = array();
24 $page[ $c ] = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
25
26 if ( ! is_wp_error( $page[ $c ] ) ) {
27 $fp = fopen( $cache_path . $c . ".html", "w" );
28 fwrite( $fp, $page[ $c ][ 'body' ] );
29 fclose( $fp );
30 }
31
32 if ( is_wp_error( $page[ $c ] ) ) {
33 $has_errors = true;
34 $attempt['status'] = false;
35 $attempt['errors'] = $this->format_error( $page[ $c ] );
36
37 } elseif ( $page[ $c ]['response']['code'] != 200 ) {
38 $has_errors = true;
39 $attempt['status'] = false;
40 $attempt['errors'] = array( $page[ $c ]['response']['message'] );
41
42 // Don't run this step on prime cache.
43 } elseif ( 0 !== $c && 0 === preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ $c ]['body'], $matches2 ) ) {
44 $has_errors = true;
45 $attempt['status'] = false;
46 $attempt['errors'] = array( __( 'Timestamps not found', 'wp-super-cache' ) );
47
48 } else {
49 $attempt['status'] = true;
50 }
51
52
53 $response[ 'attempts' ][ $attempt_name ] = $attempt;
54 $c++;
55 }
56
57 if (
58 false == $has_errors &&
59 preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 1 ][ 'body' ], $matches1 ) &&
60 preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 2 ][ 'body' ], $matches2 ) &&
61 $matches1[2] == $matches2[2]
62 ) {
63 $response[ 'status' ] = true;
64 } else {
65 $response[ 'status' ] = false;
66 $response[ 'error' ] = array( __( 'Timestamps do not match', 'wp-super-cache' ) );
67 }
68
69 $error = '';
70 if ( $response[ 'status' ] == false ) {
71 if ( isset( $response[ 'error' ] ) ) {
72 $error = $response[ 'error' ];
73 } else {
74 foreach( $response[ 'attempts' ] as $attempt ) {
75 $error .= $attempt[ 'errors' ] . "\n";
76 }
77 }
78 return new WP_Error( 'test_error', $error, array( 'status' => 500 ) );
79 }
80 return rest_ensure_response( $response );
81 }
82
83 /**
84 * @param WP_Error $error
85 * @return array
86 */
87 protected function format_error( WP_Error $error ) {
88 $messages = array();
89 foreach ( $error->get_error_codes() as $code ) {
90 foreach ( $error->get_error_messages( $code ) as $err ) {
91 $messages[] = $err;
92 }
93 }
94
95 return $messages;
96 }
97 }
1 <?php
2
3 class WP_Super_Cache_Rest_Update_Plugins extends WP_REST_Controller {
4
5 /**
6 * Toggle plugins on/off through the /plugins/ endpoint
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 $parameters = $request->get_json_params();
13
14 global $valid_nonce;
15 $valid_nonce = true;
16
17 wpsc_update_plugin_list( $parameters );
18 $list = wpsc_get_plugin_list();
19
20 return rest_ensure_response( $list );
21 }
22 }
1 <?php
2
3 class WP_Super_Cache_Settings_Map {
4 /**
5 * A map describing how settings transform from their external names
6 * into internal methods and globals.
7 *
8 * Key definitions:
9 *
10 * - get: A getter method or function that will be called to return the var
11 * - set: A setter method or function that will be called to set the var
12 * - option: An option name that will be used to get or set the var
13 * - global: A name of a global that can GET
14 *
15 * @var array
16 */
17 public static $map = array(
18 'is_submit_enabled' => array(
19 'get' => 'get_is_submit_enabled',
20 'set' => '',
21 ),
22 'is_preload_enabled' => array(
23 'get' => 'get_is_preload_enabled',
24 'set' => '',
25 ),
26 'cache_lock_down' => array(
27 'get' => 'get_is_lock_down_enabled',
28 'set' => 'set_lock_down',
29 ),
30 'cache_next_gc' => array(
31 'get' => 'get_next_gc',
32 'set' => '',
33 ),
34 'cache_gc_email_me' => array(
35 'global' => 'cache_gc_email_me',
36 'set' => 'set_time_setting',
37 ),
38 'cache_path_url' => array(
39 'get' => 'get_cache_path_url',
40 ),
41 'cache_type' => array(
42 'get' => 'get_cache_type',
43 'set' => 'set_super_cache_enabled',
44 ),
45 'is_preloading' => array(
46 'get' => 'wpsc_is_preloading',
47 'set' => '',
48 ),
49 'post_count' => array(
50 'get' => 'get_post_count',
51 'set' => '',
52 ),
53 'is_cache_enabled' => array(
54 'global' => 'cache_enabled',
55 'set' => 'set_cache_enabled',
56 ),
57 'is_super_cache_enabled' => array(
58 'global' => 'super_cache_enabled',
59 'set' => 'set_super_cache_enabled',
60 ),
61 'is_mobile_enabled' => array(
62 'global' => 'wp_cache_mobile_enabled',
63 ),
64 'is_mfunc_enabled' => array(
65 'global' => 'wp_cache_mfunc_enabled',
66 ),
67 'cache_list' => array(
68 'global' => 'wp_supercache_cache_list',
69 ),
70 'clear_cache_on_post_edit' => array(
71 'global' => 'wp_cache_clear_on_post_edit',
72 ),
73 'wpsc_save_headers' => array(
74 'global' => 'wpsc_save_headers',
75 ),
76 'cache_rebuild' => array(
77 'global' => 'cache_rebuild_files',
78 ),
79 'dont_cache_logged_in' => array(
80 'global' => 'wp_cache_not_logged_in',
81 ),
82 'make_known_anon' => array(
83 'global' => 'wp_cache_make_known_anon',
84 ),
85 'cache_path' => array(
86 'global' => 'cache_path',
87 'set' => 'set_wp_cache_location',
88 ),
89 'default_cache_path' => array(
90 'get' => 'get_default_cache_path',
91 ),
92 'use_object_cache' => array(
93 'global' => 'wp_cache_object_cache',
94 ),
95 'refresh_current_only_on_comments' => array(
96 'global' => 'wp_cache_refresh_single_only',
97 ),
98 'cache_compression' => array(
99 'global' => 'cache_compression',
100 'set' => 'set_cache_compression',
101 ),
102 'cache_mod_rewrite' => array(
103 'global' => 'wp_cache_mod_rewrite',
104 ),
105 'use_304_headers' => array(
106 'global' => 'wp_supercache_304',
107 ),
108 'cache_late_init' => array(
109 'global' => 'wp_super_cache_late_init',
110 ),
111 'front_page_checks' => array(
112 'global' => 'wp_cache_front_page_checks',
113 ),
114 'cache_page_secret' => array(
115 'global' => 'cache_page_secret',
116 ),
117 'disable_utf8' => array(
118 'global' => 'wp_cache_disable_utf8',
119 ),
120 'no_cache_for_get' => array(
121 'global' => 'wp_cache_no_cache_for_get',
122 ),
123 'cache_schedule_type' => array(
124 'global' => 'cache_schedule_type',
125 'set' => 'set_time_setting',
126 ),
127 'cache_scheduled_time' => array(
128 'global' => 'cache_scheduled_time',
129 'set' => 'set_time_setting',
130 ),
131 'cache_max_time' => array(
132 'global' => 'cache_max_time',
133 'set' => 'set_time_setting',
134 ),
135 'cache_time_interval' => array(
136 'global' => 'cache_time_interval',
137 'set' => 'set_time_setting',
138 ),
139 'shutdown_garbage_collector' => array(
140 'global' => 'wp_cache_shutdown_gc',
141 ),
142 'pages' => array(
143 'global' => 'wp_cache_pages',
144 ),
145 'minimum_preload_interval' => array(
146 'get' => 'get_minimum_preload_interval',
147 ),
148 'preload_interval' => array(
149 'global' => 'wp_cache_preload_interval',
150 'set' => 'set_preload_setting',
151 ),
152 'preload_posts' => array(
153 'global' => 'wp_cache_preload_posts',
154 'set' => 'set_preload_setting',
155 ),
156 'preload_on' => array(
157 'global' => 'wp_cache_preload_on',
158 'set' => 'set_preload_setting',
159 ),
160 'preload_active' => array(
161 'get' => 'get_is_preload_active',
162 ),
163 'preload_taxonomies' => array(
164 'global' => 'wp_cache_preload_taxonomies',
165 'set' => 'set_preload_setting',
166 ),
167 'preload_email_me' => array(
168 'global' => 'wp_cache_preload_email_me',
169 'set' => 'set_preload_setting',
170 ),
171 'preload_email_volume' => array(
172 'global' => 'wp_cache_preload_email_volume',
173 'set' => 'set_preload_setting',
174 ),
175 'cache_mobile_browsers' => array(
176 'global' => 'wp_cache_mobile_browsers',
177 ),
178 'cache_mobile_prefixes' => array(
179 'global' => 'wp_cache_mobile_prefixes',
180 ),
181 'cache_disable_locking' => array(
182 'global' => 'wp_cache_mutex_disabled',
183 ),
184 'cache_hello_world' => array(
185 'global' => 'wp_cache_hello_world',
186 ),
187 'cache_schedule_interval' => array(
188 'global' => 'cache_schedule_interval',
189 'set' => 'set_time_setting',
190 ),
191 'cache_acceptable_files' => array(
192 'global' => 'cache_acceptable_files',
193 ),
194 'cache_rejected_uri' => array(
195 'global' => 'cache_rejected_uri',
196 ),
197 'cache_rejected_user_agent' => array(
198 'global' => 'cache_rejected_user_agent',
199 ),
200 'cache_direct_pages' => array(
201 'global' => 'cached_direct_pages',
202 'set' => 'set_cache_direct_pages',
203 ),
204 'new_direct_page' => array(
205 'set' => 'new_direct_page',
206 ),
207 'ossdl_cname' => array(
208 'option' => 'ossdl_cname',
209 'set' => 'set_ossdl_cname',
210 ),
211 'ossdl_https' => array(
212 'option' => 'ossdl_https',
213 'set' => 'set_ossdl_https',
214 ),
215 'ossdl_off_cdn_url' => array(
216 'option' => 'ossdl_off_cdn_url',
217 'set' => 'set_ossdl_off_cdn_url',
218 ),
219 'ossdl_off_blog_url' => array(
220 'option' => 'ossdl_off_blog_url',
221 'set' => 'set_ossdl_off_blog_url',
222 ),
223 'ossdl_off_exclude' => array(
224 'option' => 'ossdl_off_exclude',
225 'set' => 'set_ossdl_off_exclude',
226 ),
227 'ossdl_off_include_dirs' => array(
228 'option' => 'ossdl_off_include_dirs',
229 'set' => 'set_ossdl_off_include_dirs',
230 ),
231 'ossdlcdn' => array(
232 'global' => 'ossdlcdn',
233 'set' => 'set_ossdlcdn',
234 ),
235 'wp_super_cache_debug' => array(
236 'global' => 'wp_super_cache_debug',
237 ),
238 'wp_cache_debug_username' => array(
239 'get' => 'wpsc_debug_username',
240 ),
241 'wp_cache_debug_log' => array(
242 'global' => 'wp_cache_debug_log',
243 ),
244 'wp_cache_debug_ip' => array(
245 'global' => 'wp_cache_debug_ip',
246 ),
247 'wp_super_cache_comments' => array(
248 'global' => 'wp_super_cache_comments',
249 ),
250 'wp_super_cache_front_page_check' => array(
251 'global' => 'wp_super_cache_front_page_check',
252 ),
253 'wp_super_cache_front_page_clear' => array(
254 'global' => 'wp_super_cache_front_page_clear',
255 ),
256 'wp_super_cache_front_page_text' => array(
257 'global' => 'wp_super_cache_front_page_text',
258 ),
259 'wp_super_cache_front_page_notification' => array(
260 'global' => 'wp_super_cache_front_page_notification',
261 ),
262 );
263 }
1 <?php
2
3 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-settings.php' );
4 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-update-settings.php' );
5 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-stats.php' );
6 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-cache.php' );
7 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-status.php' );
8 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-test-cache.php' );
9 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-delete-cache.php' );
10 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-preload.php' );
11 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-plugins.php' );
12 require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-update-plugins.php' );
13
14 class WP_Super_Cache_Router {
15
16 /**
17 * Register the routes for the objects of the controller.
18 *
19 * GET /wp-super-cache/v1/settings
20 * POST /wp-super-cache/v1/settings
21 * GET /wp-super-cache/v1/stats
22 * GET /wp-super-cache/v1/cache
23 * POST /wp-super-cache/v1/cache
24 */
25 public static function register_routes() {
26 $version = '1';
27 $namespace = 'wp-super-cache/v' . $version;
28
29 $get_settings = new WP_Super_Cache_Rest_Get_Settings();
30 $update_settings = new WP_Super_Cache_Rest_Update_Settings();
31 $get_stats = new WP_Super_Cache_Rest_Get_Stats();
32 $get_cache = new WP_Super_Cache_Rest_Get_Cache();
33 $test_cache = new WP_Super_Cache_Rest_Test_Cache();
34 $delete_cache = new WP_Super_Cache_Rest_Delete_Cache();
35 $preload_cache = new WP_Super_Cache_Rest_Preload();
36 $get_status = new WP_Super_Cache_Rest_Get_Status();
37 $get_plugins = new WP_Super_Cache_Rest_Get_Plugins();
38 $update_plugins = new WP_Super_Cache_Rest_Update_Plugins();
39
40 register_rest_route( $namespace, '/settings', array(
41 array(
42 'methods' => WP_REST_Server::READABLE,
43 'callback' => array( $get_settings, 'callback' ),
44 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
45 'args' => array(),
46 ),
47 array(
48 'methods' => WP_REST_Server::CREATABLE,
49 'callback' => array( $update_settings, 'callback' ),
50 'permission_callback' => __CLASS__ . '::update_item_permissions_check',
51 'args' => array(),
52 ),
53 ) );
54
55 register_rest_route( $namespace, '/status', array(
56 'methods' => WP_REST_Server::READABLE,
57 'callback' => array( $get_status, 'callback' ),
58 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
59 ) );
60
61 register_rest_route( $namespace, '/stats', array(
62 'methods' => WP_REST_Server::READABLE,
63 'callback' => array( $get_stats, 'callback' ),
64 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
65 ) );
66
67 register_rest_route( $namespace, '/cache', array(
68 array(
69 'methods' => WP_REST_Server::READABLE,
70 'callback' => array( $get_cache, 'callback' ),
71 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
72 'args' => array(),
73 ),
74 array(
75 'methods' => WP_REST_Server::CREATABLE,
76 'callback' => array( $delete_cache, 'callback' ),
77 'permission_callback' => __CLASS__ . '::delete_item_permissions_check',
78 'args' => array(),
79 ),
80 ) );
81
82 register_rest_route( $namespace, '/preload', array(
83 'methods' => WP_REST_Server::CREATABLE,
84 'callback' => array( $preload_cache, 'callback' ),
85 'permission_callback' => __CLASS__ . '::update_item_permissions_check',
86 ) );
87
88 register_rest_route( $namespace, '/cache/test', array(
89 'methods' => WP_REST_Server::CREATABLE,
90 'callback' => array( $test_cache, 'callback' ),
91 'permission_callback' => __CLASS__ . '::create_item_permissions_check',
92 ) );
93
94 register_rest_route( $namespace, '/plugins', array(
95 array(
96 'methods' => WP_REST_Server::READABLE,
97 'callback' => array( $get_plugins, 'callback' ),
98 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
99 'args' => array(),
100 ),
101 array(
102 'methods' => WP_REST_Server::CREATABLE,
103 'callback' => array( $update_plugins, 'callback' ),
104 'permission_callback' => __CLASS__ . '::update_item_permissions_check',
105 'args' => array(),
106 ),
107 ) );
108
109 }
110
111 /**
112 * Check if a given request has access to get items
113 *
114 * @param WP_REST_Request $request Full data about the request.
115 * @return WP_Error|bool
116 */
117 public static function get_items_permissions_check( $request ) {
118 return wpsupercache_site_admin();
119 }
120
121 /**
122 * Check if a given request has access to get a specific item
123 *
124 * @param WP_REST_Request $request Full data about the request.
125 * @return WP_Error|bool
126 */
127 public static function get_item_permissions_check( $request ) {
128 return self::get_items_permissions_check( $request );
129 }
130
131 /**
132 * Check if a given request has access to create items
133 *
134 * @param WP_REST_Request $request Full data about the request.
135 * @return WP_Error|bool
136 */
137 public static function create_item_permissions_check( $request ) {
138 return self::get_items_permissions_check( $request );
139 }
140
141 /**
142 * Check if a given request has access to update a specific item
143 *
144 * @param WP_REST_Request $request Full data about the request.
145 * @return WP_Error|bool
146 */
147 public static function update_item_permissions_check( $request ) {
148 return self::create_item_permissions_check( $request );
149 }
150
151 /**
152 * Check if a given request has access to update a specific item
153 *
154 * @param WP_REST_Request $request Full data about the request.
155 * @return WP_Error|bool
156 */
157 public static function delete_item_permissions_check( $request ) {
158 return self::update_item_permissions_check( $request );
159 }
160
161 }
162
163 function wpsc_load_rest_api() {
164 $wpsupercache_route = new WP_Super_Cache_Router;
165 $wpsupercache_route->register_routes();
166 };
167
168 add_action( 'rest_api_init', 'wpsc_load_rest_api' );
1 <?php
2 global $WPSC_HTTP_HOST, $cache_enabled, $cache_path, $blogcacheid, $blog_cache_dir;
3
4 if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
5 $WPSC_HTTP_HOST = function_exists( 'mb_strtolower' ) ? mb_strtolower( $_SERVER['HTTP_HOST'] ) : strtolower( $_SERVER['HTTP_HOST'] );
6 $WPSC_HTTP_HOST = htmlentities( $WPSC_HTTP_HOST );
7 } elseif ( PHP_SAPI === 'cli' && function_exists( 'get_option' ) ) {
8 $WPSC_HTTP_HOST = (string) parse_url( get_option( 'home' ), PHP_URL_HOST );
9 } else {
10 $cache_enabled = false;
11 $WPSC_HTTP_HOST = '';
12 }
13
14 // We want to be able to identify each blog in a WordPress MU install
15 $blogcacheid = '';
16 $blog_cache_dir = $cache_path;
17
18 if ( is_multisite() ) {
19 global $current_blog;
20
21 if ( is_object( $current_blog ) && function_exists( 'is_subdomain_install' ) ) {
22 $blogcacheid = is_subdomain_install() ? $current_blog->domain : trim( $current_blog->path, '/' );
23 } elseif ( ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) || ( defined( 'VHOST' ) && VHOST === 'yes' ) ) {
24 $blogcacheid = $WPSC_HTTP_HOST;
25 } else {
26 $request_uri = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
27 $request_uri = str_replace( '//', '/', $request_uri );
28
29 $wpsc_path_segs = array_filter( explode( '/', trim( $request_uri, '/' ) ) );
30 $wpsc_base_count = defined( 'PATH_CURRENT_SITE' ) ? count( array_filter( explode( '/', trim( PATH_CURRENT_SITE, '/' ) ) ) ) : 0;
31 if ( '/' !== substr( $request_uri, -1 ) ) {
32 $wpsc_path_segs = array_slice( $wpsc_path_segs, 0, -1 );
33 }
34
35 if ( count( $wpsc_path_segs ) > $wpsc_base_count &&
36 ( ! defined( 'PATH_CURRENT_SITE' ) || 0 === strpos( $request_uri, PATH_CURRENT_SITE ) )
37 ) {
38 $blogcacheid = $wpsc_path_segs[ $wpsc_base_count ];
39 }
40 }
41
42 // If blogcacheid is empty then set it to main blog.
43 if ( empty( $blogcacheid ) ) {
44 $blogcacheid = 'blog';
45 }
46 $blog_cache_dir = str_replace( '//', '/', $cache_path . 'blogs/' . $blogcacheid . '/' );
47 }
1 <?php
2 /*
3 WP-Cache Config Sample File
4
5 See wp-cache.php for author details.
6 */
7
8 if ( ! defined('WPCACHEHOME') )
9 define( 'WPCACHEHOME', WP_PLUGIN_DIR . '/wp-super-cache/' );
10
11 $cache_compression = 0; // Super cache compression
12 $cache_enabled = false;
13 $super_cache_enabled = true;
14 $cache_max_time = 3600; //in seconds
15 //$use_flock = true; // Set it true or false if you know what to use
16 $cache_path = WP_CONTENT_DIR . '/cache/';
17 $file_prefix = 'wp-cache-';
18 $ossdlcdn = 0;
19
20 // Array of files that have 'wp-' but should still be cached
21 $cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', 'wp-locations.php' );
22
23 $cache_rejected_uri = array('wp-.*\\.php', 'index\\.php');
24 $cache_rejected_user_agent = array();
25
26 $cache_rebuild_files = 1;
27
28 // Disable the file locking system.
29 // If you are experiencing problems with clearing or creating cache files
30 // uncommenting this may help.
31 $wp_cache_mutex_disabled = 1;
32
33 // Just modify it if you have conflicts with semaphores
34 $sem_id = 5419;
35
36 if ( '/' != substr($cache_path, -1)) {
37 $cache_path .= '/';
38 }
39
40 $wp_cache_mobile = 0;
41 $wp_cache_mobile_whitelist = 'Stand Alone/QNws';
42 $wp_cache_mobile_browsers = 'Android, 2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP';
43
44 // change to relocate the supercache plugins directory
45 $wp_cache_plugins_dir = WPCACHEHOME . 'plugins';
46 // set to 1 to do garbage collection during normal process shutdown instead of wp-cron
47 $wp_cache_shutdown_gc = 0;
48 $wp_super_cache_late_init = 0;
49
50 // uncomment the next line to enable advanced debugging features
51 $wp_super_cache_advanced_debug = 0;
52 $wp_super_cache_front_page_text = '';
53 $wp_super_cache_front_page_clear = 0;
54 $wp_super_cache_front_page_check = 0;
55 $wp_super_cache_front_page_notification = '0';
56
57 $wp_cache_anon_only = 0;
58 $wp_supercache_cache_list = 0;
59 $wp_cache_debug_to_file = 0;
60 $wp_super_cache_debug = 0;
61 $wp_cache_debug_level = 5;
62 $wp_cache_debug_ip = '';
63 $wp_cache_debug_log = '';
64 $wp_cache_debug_email = '';
65 $wp_cache_pages[ "search" ] = 0;
66 $wp_cache_pages[ "feed" ] = 0;
67 $wp_cache_pages[ "category" ] = 0;
68 $wp_cache_pages[ "home" ] = 0;
69 $wp_cache_pages[ "frontpage" ] = 0;
70 $wp_cache_pages[ "tag" ] = 0;
71 $wp_cache_pages[ "archives" ] = 0;
72 $wp_cache_pages[ "pages" ] = 0;
73 $wp_cache_pages[ "single" ] = 0;
74 $wp_cache_pages[ "author" ] = 0;
75 $wp_cache_hide_donation = 0;
76 $wp_cache_not_logged_in = 0;
77 $wp_cache_clear_on_post_edit = 0;
78 $wp_cache_hello_world = 0;
79 $wp_cache_mobile_enabled = 0;
80 $wp_cache_cron_check = 0;
81 $wp_cache_mfunc_enabled = 0;
82 $wp_cache_make_known_anon = 0;
83 $wp_cache_refresh_single_only = 0;
84 $wp_cache_mod_rewrite = 0;
85 $wp_supercache_304 = 0;
86 $wp_cache_front_page_checks = 0;
87 $wp_cache_disable_utf8 = 0;
88 $wp_cache_no_cache_for_get = 0;
89 $cache_scheduled_time = "00:00";
90 $wp_cache_preload_interval = 600;
91 $cache_schedule_type = 'interval';
92 $wp_cache_preload_posts = 0;
93 $wp_cache_preload_on = 0;
94 $wp_cache_preload_taxonomies = 0;
95 $wp_cache_preload_email_me = 0;
96 $wp_cache_preload_email_volume = 'none';
97 $wp_cache_mobile_prefixes = '';
98 $cached_direct_pages = array();
99 $wpsc_served_header = false;
100 $cache_gc_email_me = 0;
101 $wpsc_save_headers = 0;
102 $cache_schedule_interval = 'daily';
103 $wp_super_cache_comments = 1;
104 $wpsc_version = 169;
105 ?>
1 <?php
2
3 if ( ! function_exists( 'wp_cache_phase2' ) ) {
4 require_once dirname( __FILE__ ) . '/wp-cache-phase2.php';
5 }
6
7 // error_reporting(E_ERROR | E_PARSE); // uncomment to debug this file!
8 if ( !defined( 'WPCACHECONFIGPATH' ) ) {
9 define( 'WPCACHECONFIGPATH', WP_CONTENT_DIR );
10 }
11
12 if ( ! @include WPCACHECONFIGPATH . '/wp-cache-config.php' ) {
13 return false;
14 }
15
16 if ( ! defined( 'WPCACHEHOME' ) ) {
17 define( 'WPCACHEHOME', dirname( __FILE__ ) . '/' );
18 }
19
20 if ( defined( 'DISABLE_SUPERCACHE' ) ) {
21 wp_cache_debug( 'DISABLE_SUPERCACHE set, super_cache disabled.' );
22 $super_cache_enabled = 0;
23 }
24
25 require WPCACHEHOME . 'wp-cache-base.php';
26
27 if ( '/' === $cache_path || empty( $cache_path ) ) {
28 define( 'WPSCSHUTDOWNMESSAGE', 'WARNING! Caching disabled. Configuration corrupted. Reset configuration on Advanced Settings page.' );
29 add_action( 'wp_footer', 'wpsc_shutdown_message' );
30 define( 'DONOTCACHEPAGE', 1 );
31 return;
32 }
33
34 if ( $blogcacheid != '' ) {
35 $blog_cache_dir = str_replace( '//', '/', $cache_path . 'blogs/' . $blogcacheid . '/' );
36 } else {
37 $blog_cache_dir = $cache_path;
38 }
39
40 $wp_cache_phase1_loaded = true;
41
42 $mutex_filename = 'wp_cache_mutex.lock';
43 $new_cache = false;
44
45 if ( ! isset( $wp_cache_plugins_dir ) ) {
46 $wp_cache_plugins_dir = WPCACHEHOME . 'plugins';
47 }
48
49 if ( isset( $_GET['donotcachepage'] ) && isset( $cache_page_secret ) && $_GET['donotcachepage'] == $cache_page_secret ) {
50 $cache_enabled = false;
51 define( 'DONOTCACHEPAGE', 1 );
52 }
53
54 $plugins = glob( $wp_cache_plugins_dir . '/*.php' );
55 if ( is_array( $plugins ) ) {
56 foreach ( $plugins as $plugin ) {
57 if ( is_file( $plugin ) ) {
58 require_once $plugin;
59 }
60 }
61 }
62
63 if ( isset( $wpsc_plugins ) && is_array( $wpsc_plugins ) ) {
64 foreach( $wpsc_plugins as $plugin_file ) {
65 if ( file_exists( ABSPATH . $plugin_file ) ) {
66 include_once( ABSPATH . $plugin_file );
67 }
68 }
69 }
70
71 if (
72 file_exists( WPCACHEHOME . '../wp-super-cache-plugins/' ) &&
73 is_dir( WPCACHEHOME . '../wp-super-cache-plugins/' )
74 ) {
75 $plugins = glob( WPCACHEHOME . '../wp-super-cache-plugins/*.php' );
76 if ( is_array( $plugins ) ) {
77 foreach ( $plugins as $plugin ) {
78 if ( is_file( $plugin ) ) {
79 require_once $plugin;
80 }
81 }
82 }
83 }
84
85 $wp_start_time = microtime();
86
87 if ( wpsc_is_backend() ) {
88 return true;
89 }
90
91 if ( wpsc_is_rejected_cookie() ) {
92 define( 'DONOTCACHEPAGE', 1 );
93 $cache_enabled = false;
94 wp_cache_debug( 'Caching disabled because rejected cookie found.' );
95 return true;
96 }
97
98 if ( wpsc_is_caching_user_disabled() ) {
99 wp_cache_debug( 'Caching disabled for logged in users on settings page.' );
100 return true;
101 }
102
103 if ( isset( $wp_cache_make_known_anon ) && $wp_cache_make_known_anon ) {
104 wp_supercache_cache_for_admins();
105 }
106
107 do_cacheaction( 'cache_init' );
108
109 if ( ! $cache_enabled || ( isset( $_SERVER['REQUEST_METHOD'] ) && in_array( $_SERVER['REQUEST_METHOD'], array( 'POST', 'PUT', 'DELETE' ) ) ) || isset( $_GET['customize_changeset_uuid'] ) ) {
110 return true;
111 }
112
113 $file_expired = false;
114 $cache_filename = '';
115 $meta_file = '';
116 $wp_cache_gzip_encoding = '';
117
118 $gzipped = 0;
119 $gzsize = 0;
120
121 if ( $cache_compression ) {
122 $wp_cache_gzip_encoding = gzip_accepted();
123 }
124
125 add_cacheaction( 'supercache_filename_str', 'wp_cache_check_mobile' );
126 if ( function_exists( 'add_filter' ) ) { // loaded since WordPress 4.6
127 add_filter( 'supercache_filename_str', 'wp_cache_check_mobile' );
128 }
129
130 $wp_cache_request_uri = wpsc_remove_tracking_params_from_uri( $_SERVER['REQUEST_URI'] ); // Cache this in case any plugin modifies it and filter out tracking parameters.
131
132 if ( defined( 'DOING_CRON' ) ) {
133 extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname
134 return true;
135 }
136
137 if ( ! isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && false == $wp_super_cache_late_init ) ) {
138 wp_cache_serve_cache_file();
139 }
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.