forked from Automattic/wp-super-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-cache.php
3454 lines (3135 loc) · 193 KB
/
wp-cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: WP Super Cache
Plugin URI: https://wordpress.org/plugins/wp-super-cache/
Description: Very fast caching plugin for WordPress.
Version: 1.4.8
Author: Automattic
Author URI: https://automattic.com/
License: GPL2+
Text Domain: wp-super-cache
*/
/*
Copyright Automattic and many other contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Pre-2.6 compatibility
if( !defined('WP_CONTENT_URL') )
define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
if( !defined('WP_CONTENT_DIR') )
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
$wp_cache_config_file = WP_CONTENT_DIR . '/wp-cache-config.php';
if ( !defined( 'WPCACHEHOME' ) ) {
define( 'WPCACHEHOME', dirname( __FILE__ ) . '/' );
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
$wp_cache_file = WPCACHEHOME . 'advanced-cache.php';
} elseif ( WPCACHEHOME != dirname( __FILE__ ) . '/' ) {
$wp_cache_config_file_sample = dirname( __FILE__ ) . '/wp-cache-config-sample.php';
$wp_cache_file = dirname( __FILE__ ) . '/advanced-cache.php';
} else {
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
$wp_cache_file = WPCACHEHOME . 'advanced-cache.php';
}
if( !@include($wp_cache_config_file) ) {
get_wpcachehome();
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
@include($wp_cache_config_file_sample);
} else {
get_wpcachehome();
}
$wp_cache_link = WP_CONTENT_DIR . '/advanced-cache.php';
if( !defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) {
$wp_cache_check_wp_config = true;
}
include(WPCACHEHOME . 'wp-cache-base.php');
function wp_super_cache_text_domain() {
load_plugin_textdomain( 'wp-super-cache', WPCACHEHOME . 'languages', basename( dirname( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'wp_super_cache_text_domain' );
function wp_cache_set_home() {
global $wp_cache_is_home;
$wp_cache_is_home = ( is_front_page() || is_home() );
if ( $wp_cache_is_home && is_paged() )
$wp_cache_is_home = false;
}
add_action( 'template_redirect', 'wp_cache_set_home' );
// OSSDL CDN plugin (http://wordpress.org/plugins/ossdl-cdn-off-linker/)
include_once( WPCACHEHOME . 'ossdl-cdn.php' );
// from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
function is_writeable_ACLSafe($path) {
// PHP's is_writable does not work with Win32 NTFS
if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
return is_writeable_ACLSafe($path.uniqid(mt_rand()).'.tmp');
else if (is_dir($path))
return is_writeable_ACLSafe($path.'/'.uniqid(mt_rand()).'.tmp');
// check tmp file for read/write capabilities
$rm = file_exists($path);
$f = @fopen($path, 'a');
if ($f===false)
return false;
fclose($f);
if (!$rm)
unlink($path);
return true;
}
function get_wpcachehome() {
if( defined( 'WPCACHEHOME' ) == false ) {
if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
define( 'WPCACHEHOME', trailingslashit( dirname(__FILE__) ) );
} elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
define( 'WPCACHEHOME', dirname(__FILE__) . '/wp-super-cache/' );
} else {
die( sprintf( __( 'Please create %s /wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php', 'wp-super-cache' ), WP_CONTENT_DIR ) );
}
}
}
function wpsupercache_uninstall() {
global $wp_cache_config_file, $wp_cache_link, $cache_path;
$files = array( $wp_cache_config_file, $wp_cache_link );
foreach( $files as $file ) {
if ( file_exists( $file ) )
unlink( $file );
}
if ( !function_exists( 'wp_cache_debug' ) )
include_once( 'wp-cache-phase1.php' );
if ( !function_exists( 'prune_super_cache' ) )
include_once( 'wp-cache-phase2.php' );
prune_super_cache( $cache_path, true );
wp_cache_remove_index();
@unlink( $cache_path . '.htaccess' );
@unlink( $cache_path . 'meta' );
@unlink( $cache_path . 'supercache' );
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
wp_cache_disable_plugin();
delete_site_option( 'wp_super_cache_index_detected' );
}
register_uninstall_hook( __FILE__, 'wpsupercache_uninstall' );
function wpsupercache_deactivate() {
global $wp_cache_config_file, $wp_cache_link, $cache_path;
if ( file_exists( $wp_cache_link ) )
unlink( $wp_cache_link );
if ( !function_exists( 'wp_cache_debug' ) )
include_once( 'wp-cache-phase1.php' );
if ( !function_exists( 'prune_super_cache' ) )
include_once( 'wp-cache-phase2.php' );
prune_super_cache( $cache_path, true );
wp_cache_remove_index();
@unlink( $cache_path . '.htaccess' );
@unlink( $cache_path . 'meta' );
@unlink( $cache_path . 'supercache' );
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file);
wp_cache_disable_plugin( false ); // don't delete configuration file
}
register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
function wpsupercache_activate() {
wp_schedule_single_event( time() + 10, 'wp_cache_add_site_cache_index' );
}
register_activation_hook( __FILE__, 'wpsupercache_activate' );
function wpsupercache_site_admin() {
if ( function_exists( 'is_super_admin' ) ) {
return is_super_admin();
} elseif ( function_exists( 'is_site_admin' ) ) {
return is_site_admin();
} else {
return true;
}
}
function wp_cache_add_pages() {
global $wpmu_version;
if ( function_exists( 'is_multisite' ) && is_multisite() && wpsupercache_site_admin() ) {
add_submenu_page( 'ms-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
} elseif ( isset( $wpmu_version ) && wpsupercache_site_admin() ) {
add_submenu_page( 'wpmu-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
}
if ( wpsupercache_site_admin() ) { // in single or MS mode add this menu item too, but only for superadmins in MS mode.
add_options_page( 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
}
}
add_action('admin_menu', 'wp_cache_add_pages');
function wp_cache_network_pages() {
add_submenu_page('settings.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
}
add_action( 'network_admin_menu', 'wp_cache_network_pages' );
function wp_cache_manager_error_checks() {
global $wpmu_version, $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite, $cache_path;
global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc;
if ( !wpsupercache_site_admin() )
return false;
if ( version_compare( PHP_VERSION, '5.3.0', '<' ) && ( 1 == ini_get( 'safe_mode' ) || "on" == strtolower( ini_get( 'safe_mode' ) ) ) ) {
echo '<div id="message" class="updated fade"><h3>' . __( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h3><p>' .
__( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . ' ';
if( !ini_get( 'safe_mode_gid' ) ) {
_e( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' ) . " ";
printf( __( 'You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details.', 'wp-super-cache' ), WP_CONTENT_DIR );
} else {
_e( 'You or an administrator must disable this. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache' );
}
echo '</p></div>';
}
if ( '' == get_option( 'permalink_structure' ) ) {
echo '<div id="message" class="updated fade"><h3>' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '</h3>';
echo "<p>" . __( 'A custom url or permalink structure is required for this plugin to work correctly. Please go to the <a href="options-permalink.php">Permalinks Options Page</a> to configure your permalinks.' ) . "</p>";
echo '</div>';
return false;
}
if( $wp_cache_debug || !$wp_cache_cron_check ) {
if( function_exists( "wp_remote_get" ) == false ) {
$hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
if( strpos( $hostname, '/' ) )
$hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
$ip = gethostbyname( $hostname );
if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
?><div id="message" class="updated fade"><h3><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h3>
<p><?php printf( __( 'Your server thinks your hostname resolves to %s. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.', 'wp-super-cache' ), $ip ); ?></p>
<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
</div>
<?php
return false;
} else {
wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
}
} else {
$cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
$cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
if( is_array( $cron ) ) {
if( $cron[ 'response' ][ 'code' ] == '404' ) {
?><div id="message" class="updated fade"><h3>Warning! wp-cron.php not found!</h3>
<p><?php _e( 'Unfortunately, WordPress cannot find the file wp-cron.php. This script is required for the correct operation of garbage collection by this plugin, WordPress scheduled posts as well as other critical activities.', 'wp-super-cache' ); ?></p>
<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
</div>
<?php
} else {
wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
}
}
}
}
if ( !wp_cache_check_link() ||
!wp_cache_verify_config_file() ||
!wp_cache_verify_cache_dir() ) {
echo '<p>' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '</p>';
return false;
}
if (!wp_cache_check_global_config()) {
return false;
}
if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
?><div id="message" class="updated fade"><h3><?php _e( 'Zlib Output Compression Enabled!', 'wp-super-cache' ); ?></h3>
<p><?php _e( 'PHP is compressing the data sent to the visitors of your site. Disabling this is recommended as the plugin caches the compressed output once instead of compressing the same page over and over again. Also see #21 in the Troubleshooting section. See <a href="http://php.net/manual/en/zlib.configuration.php">this page</a> for instructions on modifying your php.ini.', 'wp-super-cache' ); ?></p></div><?php
}
if( $cache_enabled == true && $super_cache_enabled == true && $wp_cache_mod_rewrite && !got_mod_rewrite() ) {
?><div id="message" class="updated fade"><h3><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h3>
<p><?php _e( 'It appears that mod_rewrite is not installed. Sometimes this check isn’t 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files. You will still be able to use legacy or PHP modes.', 'wp-super-cache' ); ?></p></div><?php
}
if( !is_writeable_ACLSafe( $wp_cache_config_file ) ) {
if ( !defined( 'SUBMITDISABLED' ) )
define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
?><div id="message" class="updated fade"><h3><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h3>
<p><?php printf( __( 'The WP Super Cache configuration file is <code>%s/wp-cache-config.php</code> and cannot be modified. That file must be writeable by the web server to make any changes.', 'wp-super-cache' ), WP_CONTENT_DIR ); ?>
<?php _e( 'A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it’s globally writeable and it should be fine.', 'wp-super-cache' ); ?></p>
<p><?php _e( '<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
<?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code>
<?php _e( 'Read-only:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code></p>
</div><?php
} elseif ( !defined( 'SUBMITDISABLED' ) ) {
define( "SUBMITDISABLED", ' ' );
}
$valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
// Check that garbage collection is running
if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_gc_warning' ) {
wp_cache_replace_line('^ *\$dismiss_gc_warning', "\$dismiss_gc_warning = 1;", $wp_cache_config_file);
$dismiss_gc_warning = 1;
} elseif ( !isset( $dismiss_gc_warning ) ) {
$dismiss_gc_warning = 0;
}
if ( $cache_enabled && ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && function_exists( 'get_gc_flag' ) ) {
$gc_flag = get_gc_flag();
if ( $dismiss_gc_warning == 0 ) {
if ( false == maybe_stop_gc( $gc_flag ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
?><div id="message" class="updated fade"><h3><?php _e( 'Warning! Garbage collection is not scheduled!', 'wp-super-cache' ); ?></h3>
<p><?php _e( 'Garbage collection by this plugin clears out expired and old cached pages on a regular basis. Use <a href="#expirytime">this form</a> to enable it.', 'wp-super-cache' ); ?> </p>
<form action="" method="POST">
<input type="hidden" name="action" value="dismiss_gc_warning" />
<input type="hidden" name="page" value="wpsupercache" />
<?php wp_nonce_field( 'wp-cache' ); ?>
<input class='button-secondary' type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
</form>
<br />
</div>
<?php
}
}
}
// Server could be running as the owner of the wp-content directory. Therefore, if it's
// writable, issue a warning only if the permissions aren't 755.
if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_readable_warning' ) {
wp_cache_replace_line('^ *\$dismiss_readable_warning', "\$dismiss_readable_warning = 1;", $wp_cache_config_file);
$dismiss_readable_warning = 1;
} elseif ( !isset( $dismiss_readable_warning ) ) {
$dismiss_readable_warning = 0;
}
if( $dismiss_readable_warning == 0 && is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) {
$wp_content_stat = stat(WP_CONTENT_DIR . '/');
$wp_content_mode = decoct( $wp_content_stat[ 'mode' ] & 0777 );
if( substr( $wp_content_mode, -2 ) == '77' ) {
?><div id="message" class="updated fade"><h3><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h3>
<p><?php printf( __( 'You should change the permissions on %s and make it more restrictive. Use your ftp client, or the following command to fix things:', 'wp-super-cache' ), WP_CONTENT_DIR ); ?> <code>chmod 755 <?php echo WP_CONTENT_DIR; ?>/</code></p>
<p><?php _e( '<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
<form action="" method="POST">
<input type="hidden" name="action" value="dismiss_readable_warning" />
<input type="hidden" name="page" value="wpsupercache" />
<?php wp_nonce_field( 'wp-cache' ); ?>
<input class='button-secondary' type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
</form>
<br />
</div>
<?php
}
}
if ( function_exists( "is_main_site" ) && true == is_main_site() ) {
$home_path = trailingslashit( get_home_path() );
$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) ) ) {
echo '<div id="message" class="updated fade"><h3>' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "</h3>";
echo "<p>" . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . "</p><p>" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "</p></div>";
} elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && (
( false == empty( $wp_cache_mobile_prefixes ) && false === strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) ||
( false == empty( $wp_cache_mobile_browsers ) && false === strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) ) ) )
) {
?>
<div id="message" class="updated fade"><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
<p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
<?php _e( 'Mobile support requires extra rules in your .htaccess file, or you can set the plugin to legacy mode. Here are your options (in order of difficulty):', 'wp-super-cache' ); ?>
<ol><li> <?php _e( 'Set the plugin to legacy mode and enable mobile support.', 'wp-super-cache' ); ?></li>
<li> <?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></li>
<li> <?php printf( __( 'Delete the plugin mod_rewrite rules in %s.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?></li>
<li> <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?></p>
<div style='padding: 2px; margin: 2px; border: 1px solid #333; width:400px; overflow: scroll'><pre><?php echo "RewriteCond %{HTTP_user_agent} !^.*(" . addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) . ").*\nRewriteCond %{HTTP_user_agent} !^(" . addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) . ").*"; ?></pre></div></li></ol></div><?php
}
if ( $cache_enabled && $super_cache_enabled && $wp_cache_mod_rewrite && $scrules == '' ) {
?><div id="message" class="updated fade"><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
<p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
<?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></p></div><?php
}
}
if ( $wp_cache_mod_rewrite && $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
$mods = apache_get_modules();
$required_modules = array( 'mod_mime' => __( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ) );
foreach( $required_modules as $req => $desc ) {
if( !in_array( $req, $mods ) ) {
$missing_mods[ $req ] = $desc;
}
}
if( isset( $missing_mods) && is_array( $missing_mods ) ) {
?><div id="message" class="updated fade"><h3><?php _e( 'Missing Apache Modules', 'wp-super-cache' ); ?></h3>
<p><?php __( 'The following Apache modules are missing. The plugin will work in legacy mode without them. In full Supercache mode, your visitors may see corrupted pages or out of date content however.', 'wp-super-cache' ); ?></p><?php
echo "<ul>";
foreach( $missing_mods as $req => $desc ) {
echo "<li> $req - $desc</li>";
}
echo "</ul>";
echo "</div>";
}
}
if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_htaccess_warning' ) {
wp_cache_replace_line('^ *\$dismiss_htaccess_warning', "\$dismiss_htaccess_warning = 1;", $wp_cache_config_file);
$dismiss_htaccess_warning = 1;
} elseif ( !isset( $dismiss_htaccess_warning ) ) {
$dismiss_htaccess_warning = 0;
}
if ( isset( $disable_supercache_htaccess_warning ) == false )
$disable_supercache_htaccess_warning = false;
if ( $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) {
$home_dir = str_replace( get_option( 'home' ), '', get_option( 'siteurl' ) );
?><div id="message" class="updated fade"><h3><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h3>
<p><?php _e( 'It appears you have WordPress installed in a sub directory as described <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">here</a>. Unfortunately, WordPress writes to the .htaccess in the install directory, not where your site is served from.<br />When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?></p>
<form action="" method="POST">
<input type="hidden" name="action" value="dismiss_htaccess_warning" />
<input type="hidden" name="page" value="wpsupercache" />
<?php wp_nonce_field( 'wp-cache' ); ?>
<input class='button-secondary' type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
</form>
<br />
</div><?php
}
return true;
}
add_filter( 'wp_super_cache_error_checking', 'wp_cache_manager_error_checks' );
function admin_bar_delete_page() {
// Delete cache for a specific page
if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') )
return false;
if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' && ( isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'delete-cache' ) : false ) ) {
$path = realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $_GET[ 'path' ] ) ) ) ) . '/';
if ( $path == '/' )
return false; // Directory not found. Probably not cached.
if ( false == wp_cache_confirm_delete( $path ) || substr( $path, 0, strlen( get_supercache_dir() ) ) != get_supercache_dir() )
die( "Could not delete directory" );
$files = get_all_supercache_filenames( $path );
foreach( $files as $cache_file )
prune_super_cache( $path . $cache_file, true );
wp_redirect( preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_GET[ 'path' ] ) );
die();
}
}
if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' )
add_action( 'admin_init', 'admin_bar_delete_page' );
function wp_cache_manager_updates() {
global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_hello_world, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $cache_compression, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get, $wp_super_cache_send_link_headers;
global $cache_schedule_type, $cache_scheduled_time, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc;
if ( !wpsupercache_site_admin() )
return false;
if ( false == isset( $cache_page_secret ) ) {
$cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() );
wp_cache_replace_line('^ *\$cache_page_secret', "\$cache_page_secret = '" . $cache_page_secret . "';", $wp_cache_config_file);
}
$valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
if ( $valid_nonce == false )
return false;
if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'easysetup' ) {
$_POST[ 'action' ] = 'scupdates';
if( isset( $_POST[ 'wp_cache_easy_on' ] ) && $_POST[ 'wp_cache_easy_on' ] == 1 ) {
$_POST[ 'wp_cache_mobile_enabled' ] = 1;
$_POST[ 'wp_cache_status' ] = 'all';
$_POST[ 'super_cache_enabled' ] = 2; // PHP
$_POST[ 'cache_rebuild_files' ] = 1;
unset( $_POST[ 'cache_compression' ] );
if ( $cache_path != WP_CONTENT_DIR . '/cache/' )
$_POST[ 'wp_cache_location' ] = $cache_path;
//
// set up garbage collection with some default settings
if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
if ( false == isset( $cache_schedule_type ) ) {
$cache_schedule_type = 'interval';
$cache_time_interval = 600;
$cache_max_time = 1800;
wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = '$cache_max_time';", $wp_cache_config_file);
}
wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
}
} else {
unset( $_POST[ 'wp_cache_status' ] );
$_POST[ 'super_cache_enabled' ] = 0;
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
}
$advanced_settings = array( 'wp_super_cache_late_init', 'wp_cache_disable_utf8', 'wp_cache_no_cache_for_get', 'wp_supercache_304', 'wp_cache_mfunc_enabled', 'wp_cache_mobile_enabled', 'wp_cache_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_hello_world', 'wp_cache_clear_on_post_edit', 'wp_cache_not_logged_in', 'wp_cache_make_known_anon','wp_cache_object_cache', 'wp_cache_refresh_single_only', 'cache_compression', 'wp_cache_mutex_disabled', 'wp_super_cache_send_link_headers' );
foreach( $advanced_settings as $setting ) {
if ( isset( $$setting ) && $$setting == 1 ) {
$_POST[ $setting ] = 1;
}
}
}
if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) {
if( isset( $_POST[ 'wp_cache_location' ] ) && $_POST[ 'wp_cache_location' ] != '' ) {
$dir = realpath( trailingslashit( dirname( $_POST[ 'wp_cache_location' ] ) ) );
if ( $dir == false )
$dir = WP_CONTENT_DIR . '/cache/';
else
$dir = trailingslashit( $dir ) . wpsc_deep_replace( array( '..', '\\' ), basename( $_POST[ 'wp_cache_location' ] ) );
$new_cache_path = $dir;
} else {
$new_cache_path = WP_CONTENT_DIR . '/cache/';
}
if ( $new_cache_path != $cache_path ) {
if ( file_exists( $new_cache_path ) == false )
rename( $cache_path, $new_cache_path );
$cache_path = $new_cache_path;
wp_cache_replace_line('^ *\$cache_path', "\$cache_path = '" . $cache_path . "';", $wp_cache_config_file);
}
if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) {
$wp_super_cache_late_init = 1;
} else {
$wp_super_cache_late_init = 0;
}
wp_cache_replace_line('^ *\$wp_super_cache_late_init', "\$wp_super_cache_late_init = " . $wp_super_cache_late_init . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_disable_utf8' ] ) ) {
$wp_cache_disable_utf8 = 1;
} else {
$wp_cache_disable_utf8 = 0;
}
wp_cache_replace_line('^ *\$wp_cache_disable_utf8', "\$wp_cache_disable_utf8 = " . $wp_cache_disable_utf8 . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_no_cache_for_get' ] ) ) {
$wp_cache_no_cache_for_get = 1;
} else {
$wp_cache_no_cache_for_get = 0;
}
wp_cache_replace_line('^ *\$wp_cache_no_cache_for_get', "\$wp_cache_no_cache_for_get = " . $wp_cache_no_cache_for_get . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_supercache_304' ] ) ) {
$wp_supercache_304 = 1;
} else {
$wp_supercache_304 = 0;
}
wp_cache_replace_line('^ *\$wp_supercache_304', "\$wp_supercache_304 = " . $wp_supercache_304 . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_mfunc_enabled' ] ) ) {
$wp_cache_mfunc_enabled = 1;
} else {
$wp_cache_mfunc_enabled = 0;
}
wp_cache_replace_line('^ *\$wp_cache_mfunc_enabled', "\$wp_cache_mfunc_enabled = " . $wp_cache_mfunc_enabled . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_mobile_enabled' ] ) ) {
$wp_cache_mobile_enabled = 1;
} else {
$wp_cache_mobile_enabled = 0;
}
wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_front_page_checks' ] ) ) {
$wp_cache_front_page_checks = 1;
} else {
$wp_cache_front_page_checks = 0;
}
wp_cache_replace_line('^ *\$wp_cache_front_page_checks', "\$wp_cache_front_page_checks = " . $wp_cache_front_page_checks . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_supercache_cache_list' ] ) ) {
$wp_supercache_cache_list = 1;
} else {
$wp_supercache_cache_list = 0;
}
wp_cache_replace_line('^ *\$wp_supercache_cache_list', "\$wp_supercache_cache_list = " . $wp_supercache_cache_list . ";", $wp_cache_config_file);
if ( isset( $_POST[ 'wp_cache_status' ] ) ) {
if ( $_POST[ 'wp_cache_status' ] == 'all' )
wp_cache_enable();
if ( isset( $_POST[ 'super_cache_enabled' ] ) ) {
if ( $_POST[ 'super_cache_enabled' ] == 0 ) {
wp_cache_enable();
wp_super_cache_disable();
}
if( $_POST[ 'super_cache_enabled' ] == 1 ) {
$wp_cache_mod_rewrite = 1; // we need this because supercached files can be served by PHP too.
} else {
$wp_cache_mod_rewrite = 0;
}
wp_cache_replace_line('^ *\$wp_cache_mod_rewrite', '$wp_cache_mod_rewrite = ' . $wp_cache_mod_rewrite . ";", $wp_cache_config_file);
}
} else {
wp_cache_disable();
}
if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
$wp_cache_hello_world = 1;
} else {
$wp_cache_hello_world = 0;
}
wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . $wp_cache_hello_world . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
$wp_cache_clear_on_post_edit = 1;
} else {
$wp_cache_clear_on_post_edit = 0;
}
wp_cache_replace_line('^ *\$wp_cache_clear_on_post_edit', "\$wp_cache_clear_on_post_edit = " . $wp_cache_clear_on_post_edit . ";", $wp_cache_config_file);
if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
$cache_rebuild_files = 1;
} else {
$cache_rebuild_files = 0;
}
wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
$wp_cache_mutex_disabled = 0;
} else {
$wp_cache_mutex_disabled = 1;
}
if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
$wp_cache_mutex_disabled = 1;
}
wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
if(isset( $_POST[ 'wp_super_cache_send_link_headers' ] ) ) {
$wp_super_cache_send_link_headers = 1;
} else {
$wp_super_cache_send_link_headers = 0;
}
wp_cache_replace_line('^ *\$wp_super_cache_send_link_headers', "\$wp_super_cache_send_link_headers = " . $wp_super_cache_send_link_headers . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) {
if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) )
prune_super_cache ($cache_path, true);
$wp_cache_not_logged_in = 1;
} else {
$wp_cache_not_logged_in = 0;
}
wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_make_known_anon' ] ) ) {
if( $wp_cache_make_known_anon == 0 && function_exists( 'prune_super_cache' ) )
prune_super_cache ($cache_path, true);
$wp_cache_make_known_anon = 1;
} else {
$wp_cache_make_known_anon = 0;
}
wp_cache_replace_line('^ *\$wp_cache_make_known_anon', "\$wp_cache_make_known_anon = " . $wp_cache_make_known_anon . ";", $wp_cache_config_file);
if( $_wp_using_ext_object_cache && isset( $_POST[ 'wp_cache_object_cache' ] ) ) {
if( $wp_cache_object_cache == 0 && function_exists( 'prune_super_cache' ) )
prune_super_cache( $cache_path, true );
$wp_cache_object_cache = 1;
} else {
$wp_cache_object_cache = 0;
}
wp_cache_replace_line('^ *\$wp_cache_object_cache', "\$wp_cache_object_cache = " . $wp_cache_object_cache . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_refresh_single_only' ] ) ) {
$wp_cache_refresh_single_only = 1;
} else {
$wp_cache_refresh_single_only = 0;
}
wp_cache_replace_line('^ *\$wp_cache_refresh_single_only', "\$wp_cache_refresh_single_only = '" . $wp_cache_refresh_single_only . "';", $wp_cache_config_file);
if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
$cache_compression = 0;
wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
} else {
if ( isset( $_POST[ 'cache_compression' ] ) ) {
$new_cache_compression = 1;
} else {
$new_cache_compression = 0;
}
if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
echo '<div id="message" class="updated fade">' . __( "<strong>Warning!</strong> You attempted to enable compression but <code>zlib.output_compression</code> is enabled. See #21 in the Troubleshooting section of the readme file.", 'wp-super-cache' ) . '</div>';
} else {
if ( $new_cache_compression != $cache_compression ) {
$cache_compression = $new_cache_compression;
wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
if ( function_exists( 'prune_super_cache' ) )
prune_super_cache( $cache_path, true );
delete_option( 'super_cache_meta' );
}
}
}
}
}
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
add_action( 'admin_init', 'wp_cache_manager_updates' );
function wp_cache_manager() {
global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get, $wp_super_cache_send_link_headers;
global $wp_cache_cron_check, $wp_cache_debug, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret, $cache_home_path;
global $wp_super_cache_front_page_check, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes;
global $wpmu_version, $cache_max_time, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled;
if ( !wpsupercache_site_admin() )
return false;
// used by mod_rewrite rules and config file
if ( function_exists( "cfmobi_default_browsers" ) ) {
$wp_cache_mobile_browsers = cfmobi_default_browsers( "mobile" );
$wp_cache_mobile_browsers = array_merge( $wp_cache_mobile_browsers, cfmobi_default_browsers( "touch" ) );
} elseif ( function_exists( 'lite_detection_ua_contains' ) ) {
$wp_cache_mobile_browsers = explode( '|', lite_detection_ua_contains() );
} else {
$wp_cache_mobile_browsers = array( '2.0 MMP', '240x320', '400X240', 'AvantGo', 'BlackBerry', 'Blazer', 'Cellphone', 'Danger', 'DoCoMo', 'Elaine/3.0', 'EudoraWeb', 'Googlebot-Mobile', 'hiptop', 'IEMobile', 'KYOCERA/WX310K', 'LG/U990', 'MIDP-2.', 'MMEF20', 'MOT-V', 'NetFront', 'Newt', 'Nintendo Wii', 'Nitro', 'Nokia', 'Opera Mini', 'Palm', 'PlayStation Portable', 'portalmmm', 'Proxinet', 'ProxiNet', 'SHARP-TQ-GX10', 'SHG-i900', 'Small', 'SonyEricsson', 'Symbian OS', 'SymbianOS', 'TS21i-10', 'UP.Browser', 'UP.Link', 'webOS', 'Windows CE', 'WinWAP', 'YahooSeeker/M1A1-R2D2', 'iPhone', 'iPod', 'Android', 'BlackBerry9530', 'LG-TU915 Obigo', 'LGE VX', 'webOS', 'Nokia5800' );
}
if ( function_exists( "lite_detection_ua_prefixes" ) ) {
$wp_cache_mobile_prefixes = lite_detection_ua_prefixes();
} else {
$wp_cache_mobile_prefixes = array( 'w3c ', 'w3c-', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac', 'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'htc_', 'inno', 'ipaq', 'ipod', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-', 'lg/u', 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-', 'newt', 'noki', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox', 'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar', 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-', 'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp', 'wapr', 'webc', 'winw', 'winw', 'xda ', 'xda-' ); // from http://svn.wp-plugins.org/wordpress-mobile-pack/trunk/plugins/wpmp_switcher/lite_detection.php
}
$wp_cache_mobile_browsers = apply_filters( 'cached_mobile_browsers', $wp_cache_mobile_browsers ); // Allow mobile plugins access to modify the mobile UA list
$wp_cache_mobile_prefixes = apply_filters( 'cached_mobile_prefixes', $wp_cache_mobile_prefixes ); // Allow mobile plugins access to modify the mobile UA prefix list
if ( function_exists( 'do_cacheaction' ) ) {
$wp_cache_mobile_browsers = do_cacheaction( 'wp_super_cache_mobile_browsers', $wp_cache_mobile_browsers );
$wp_cache_mobile_prefixes = do_cacheaction( 'wp_super_cache_mobile_prefixes', $wp_cache_mobile_prefixes );
}
$mobile_groups = apply_filters( 'cached_mobile_groups', array() ); // Group mobile user agents by capabilities. Lump them all together by default
// mobile_groups = array( 'apple' => array( 'ipod', 'iphone' ), 'nokia' => array( 'nokia5800', 'symbianos' ) );
if ( false == apply_filters( 'wp_super_cache_error_checking', true ) )
return false;
if ( function_exists( 'get_supercache_dir' ) )
$supercachedir = get_supercache_dir();
if( get_option( 'gzipcompression' ) == 1 )
update_option( 'gzipcompression', 0 );
if( !isset( $cache_rebuild_files ) )
$cache_rebuild_files = 0;
$valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
/* http://www.netlobo.com/div_hiding.html */
?>
<script type='text/javascript'>
<!--
function toggleLayer( whichLayer ) {
var elem, vis;
if( document.getElementById ) // this is the way the standards work
elem = document.getElementById( whichLayer );
else if( document.all ) // this is the way old msie versions work
elem = document.all[whichLayer];
else if( document.layers ) // this is the way nn4 works
elem = document.layers[whichLayer];
vis = elem.style;
// if the style.display value is blank we try to figure it out here
if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
// -->
//Clicking header opens fieldset options
jQuery(document).ready(function(){
jQuery("fieldset h3").css("cursor","pointer").click(function(){
jQuery(this).parent("fieldset").find("p,form,ul,blockquote").toggle("slow");
});
});
</script>
<style type='text/css'>
#nav h2 {
border-bottom: 1px solid #ccc;
padding-bottom: 0;
}
table.wpsc-settings-table {
clear: both;
}
</style>
<?php
echo '<a name="top"></a>';
echo '<div class="wrap">';
echo '<h2>' . __( 'WP Super Cache Settings', 'wp-super-cache' ) . '</h2>';
// set a default
if ( $cache_enabled == false && isset( $wp_cache_mod_rewrite ) == false ) {
$wp_cache_mod_rewrite = 0;
} elseif ( !isset( $wp_cache_mod_rewrite ) && $cache_enabled && $super_cache_enabled ) {
$wp_cache_mod_rewrite = 1;
}
if ( !isset( $_GET[ 'tab' ] ) )
$_GET[ 'tab' ] = '';
if ( $_GET[ 'tab' ] == '' && $cache_enabled && ( $wp_cache_mod_rewrite || $super_cache_enabled == false ) ) {
$_GET[ 'tab' ] = 'settings';
echo '<div id="message" class="updated fade"><p>' . __( 'Notice: <em>Mod_rewrite or Legacy caching enabled</em>. Showing Advanced Settings Page by default.', 'wp-super-cache' ) . '</p></div>';
}
wpsc_admin_tabs();
if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
}
if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
unlink($wp_cache_config_file);
echo '<strong>' . __( 'Configuration file changed, some values might be wrong. Load the page again from the "Settings" menu to reset them.', 'wp-super-cache' ) . '</strong>';
}
if ( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 1;", $wp_cache_config_file);
} else {
wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 0;", $wp_cache_config_file);
}
$home_path = parse_url( site_url() );
$home_path = trailingslashit( array_key_exists( 'path', $home_path ) ? $home_path[ 'path' ] : '' );
if (! isset( $wp_cache_home_path ) )
$wp_cache_home_path = '/';
if ( "$home_path" != "$wp_cache_home_path" )
wp_cache_replace_line('^ *\$wp_cache_home_path', "\$wp_cache_home_path = '$home_path';", $wp_cache_config_file);
if( $wp_cache_mobile_enabled == 1 ) {
update_cached_mobile_ua_list( $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $mobile_groups );
}
?> <table class="wpsc-settings-table"><td valign='top'><?php
switch( $_GET[ 'tab' ] ) {
case "cdn":
scossdl_off_options();
break;
case "tester":
case "contents":
echo '<a name="test"></a>';
wp_cache_files();
break;
case "preload":
if ( !$cache_enabled )
wp_die( __( 'Caching must be enabled to use this feature', 'wp-super-cache' ) );
echo '<a name="preload"></a>';
if ( $super_cache_enabled == true && false == defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_taxonomies, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;
$count = $wpdb->get_var( "SELECT count(*) FROM {$wpdb->posts} WHERE post_status = 'publish'" );
if ( $count > 1000 ) {
$min_refresh_interval = 720;
} else {
$min_refresh_interval = 30;
}
if ( array_key_exists('action', $_POST) && $_POST[ 'action' ] == 'preload' && $valid_nonce ) {
if ( $_POST[ 'posts_to_cache' ] == 'all' ) {
$wp_cache_preload_posts = 'all';
} else {
$wp_cache_preload_posts = (int)$_POST[ 'posts_to_cache' ];
}
wp_cache_replace_line('^ *\$wp_cache_preload_posts', "\$wp_cache_preload_posts = '$wp_cache_preload_posts';", $wp_cache_config_file);
if ( isset( $_POST[ 'preload' ] ) && $_POST[ 'preload' ] == __( 'Cancel Cache Preload', 'wp-super-cache' ) ) {
$next_preload = wp_next_scheduled( 'wp_cache_preload_hook' );
if ( $next_preload ) {
update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
wp_unschedule_event( $next_preload, 'wp_cache_preload_hook' );
}
$fp = @fopen( $cache_path . "stop_preload.txt", 'w' );
@fclose( $fp );
echo "<p><strong>" . __( 'Scheduled preloading of cache almost cancelled. It may take up to a minute for it to cancel completely.', 'wp-super-cache' ) . "</strong></p>";
} elseif ( isset( $_POST[ 'custom_preload_interval' ] ) && ( $_POST[ 'custom_preload_interval' ] == 0 || $_POST[ 'custom_preload_interval' ] >= $min_refresh_interval ) ) {
// if preload interval changes than unschedule any preload jobs and schedule any new one.
$_POST[ 'custom_preload_interval' ] = (int)$_POST[ 'custom_preload_interval' ];
if ( $wp_cache_preload_interval != $_POST[ 'custom_preload_interval' ] ) {
$next_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' );
if ( $next_preload ) {
update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
add_option( 'preload_cache_stop', 1 );
wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' );
if ( $wp_cache_preload_interval == 0 ) {
echo "<p><strong>" . __( 'Scheduled preloading of cache cancelled.', 'wp-super-cache' ) . "</strong></p>";
}
}
if ( $_POST[ 'custom_preload_interval' ] != 0 )
wp_schedule_single_event( time() + ( $_POST[ 'custom_preload_interval' ] * 60 ), 'wp_cache_full_preload_hook' );
}
$wp_cache_preload_interval = (int)$_POST[ 'custom_preload_interval' ];
wp_cache_replace_line('^ *\$wp_cache_preload_interval', "\$wp_cache_preload_interval = $wp_cache_preload_interval;", $wp_cache_config_file);
if ( isset( $_POST[ 'preload_email_me' ] ) ) {
$wp_cache_preload_email_me = 1;
} else {
$wp_cache_preload_email_me = 0;
}
wp_cache_replace_line('^ *\$wp_cache_preload_email_me', "\$wp_cache_preload_email_me = $wp_cache_preload_email_me;", $wp_cache_config_file);
if ( isset( $_POST[ 'wp_cache_preload_email_volume' ] ) && in_array( $_POST[ 'wp_cache_preload_email_volume' ], array( 'less', 'medium', 'many' ) ) ) {
$wp_cache_preload_email_volume = $_POST[ 'wp_cache_preload_email_volume' ];
} else {
$wp_cache_preload_email_volume = 'medium';
}
wp_cache_replace_line('^ *\$wp_cache_preload_email_volume', "\$wp_cache_preload_email_volume = '$wp_cache_preload_email_volume';", $wp_cache_config_file);
if ( isset( $_POST[ 'preload_taxonomies' ] ) ) {
$wp_cache_preload_taxonomies = 1;
} else {
$wp_cache_preload_taxonomies = 0;
}
wp_cache_replace_line('^ *\$wp_cache_preload_taxonomies', "\$wp_cache_preload_taxonomies = $wp_cache_preload_taxonomies;", $wp_cache_config_file);
if ( isset( $_POST[ 'preload_on' ] ) ) {
$wp_cache_preload_on = 1;
} else {
$wp_cache_preload_on = 0;
}
wp_cache_replace_line('^ *\$wp_cache_preload_on', "\$wp_cache_preload_on = $wp_cache_preload_on;", $wp_cache_config_file);
if ( isset( $_POST[ 'preload' ] ) && $_POST[ 'preload' ] == __( 'Preload Cache Now', 'wp-super-cache' ) ) {
@unlink( $cache_path . "preload_mutex.tmp" );
update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
wp_schedule_single_event( time() + 10, 'wp_cache_preload_hook' );
echo "<p><strong>" . __( 'Scheduled preloading of cache in 10 seconds.' ) . "</strong></p>";
} elseif ( (int)$_POST[ 'custom_preload_interval' ] ) {
@unlink( $cache_path . "preload_mutex.tmp" );
update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
wp_schedule_single_event( time() + ( (int)$_POST[ 'custom_preload_interval' ] * 60 ), 'wp_cache_full_preload_hook' );
echo "<p><strong>" . sprintf( __( 'Scheduled preloading of cache in %d minutes', 'wp-super-cache' ), (int)$_POST[ 'custom_preload_interval' ] ) . "</strong></p>";
}
}
}
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>';
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>';
echo '<p>' . __( 'In ’Preload Mode’ regular garbage collection will only clean out old legacy files for known users, not the preloaded supercache files. This is a recommended setting when the cache is preloaded.', 'wp-super-cache' ) . '</p>';
echo '<form name="cache_filler" action="" method="POST">';
echo '<input type="hidden" name="action" value="preload" />';
echo '<input type="hidden" name="page" value="wpsupercache" />';
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='custom_preload_interval' value='" . (int)$wp_cache_preload_interval . "' />", $min_refresh_interval ) . '</p>';
if ( $count > 100 ) {
$step = (int)( $count / 10 );
$select = "<select name='posts_to_cache' size=1>";
$select .= "<option value='all' ";
if ( !isset( $wp_cache_preload_posts ) || $wp_cache_preload_posts == 'all' ) {
$checked = 'selectect=1 ';
$best = 'all';
} else {
$checked = ' ';
$best = $wp_cache_preload_posts;
}
$select .= "{$checked}>" . __( 'all', 'wp-super-cache' ) . "</option>";
for( $c = $step; $c < $count; $c += $step ) {
$checked = ' ';
if ( $best == $c )
$checked = 'selected=1 ';
$select .= "<option value='$c'{$checked}>$c</option>";
}
$checked = ' ';
if ( $best == $count )
$checked = 'selected=1 ';
$select .= "<option value='$count'{$checked}>$count</option>";
$select .= "</select>";
echo '<p>' . sprintf( __( 'Preload %s posts.', 'wp-super-cache' ), $select ) . '</p>';
} else {
echo '<input type="hidden" name="posts_to_cache" value="' . $count . '" />';
}
echo '<input type="checkbox" name="preload_on" value="1" ';
echo $wp_cache_preload_on == 1 ? 'checked=1' : '';
echo ' /> ' . __( 'Preload mode (garbage collection only on legacy cache files. Recommended.)', 'wp-super-cache' ) . '<br />';
echo '<input type="checkbox" name="preload_taxonomies" value="1" ';
echo $wp_cache_preload_taxonomies == 1 ? 'checked=1' : '';
echo ' /> ' . __( 'Preload tags, categories and other taxonomies.', 'wp-super-cache' ) . '<br />';
echo '<input type="checkbox" name="preload_email_me" value="1" ';
echo $wp_cache_preload_email_me == 1 ? 'checked=1' : '';
echo ' /> ' . __( 'Send me status emails when files are refreshed.', 'wp-super-cache' ) . '<br />';
if ( !isset( $wp_cache_preload_email_volume ) )
$wp_cache_preload_email_volume = 'many';
echo ' <input name="wp_cache_preload_email_volume" type="radio" value="many" class="tog" ';
checked( 'many', $wp_cache_preload_email_volume );
echo '/> ' . __( 'Many emails, 2 emails per 100 posts.', 'wp-super-cache' ) . '<br >';
echo ' <input name="wp_cache_preload_email_volume" type="radio" value="medium" class="tog" ';
checked( 'medium', $wp_cache_preload_email_volume );
echo '/> ' . __( 'Medium, 1 email per 100 posts.', 'wp-super-cache' ) . '<br >';
echo ' <input name="wp_cache_preload_email_volume" type="radio" value="less" class="tog" ';
checked( 'less', $wp_cache_preload_email_volume );
echo '/> ' . __( 'Less emails, 1 at the start and 1 at the end of preloading all posts.', 'wp-super-cache' ) . '<br >';
$currently_preloading = false;
next_preload_message( 'wp_cache_preload_hook', __( 'Refresh of cache in %d hours %d minutes and %d seconds.', 'wp-super-cache' ), 60 );
next_preload_message( 'wp_cache_full_preload_hook', __( 'Full refresh of cache in %d hours %d minutes and %d seconds.', 'wp-super-cache' ) );
$preload_counter = get_option( 'preload_cache_counter' );
if ( isset( $preload_counter[ 'first' ] ) ) // converted from int to array
update_option( 'preload_cache_counter', array( 'c' => $preload_counter[ 'c' ], 't' => time() ) );
if ( is_array( $preload_counter ) && $preload_counter[ 'c' ] > 0 ) {
echo '<p><strong>' . sprintf( __( 'Currently caching from post %d to %d.', 'wp-super-cache' ), ( $preload_counter[ 'c' ] - 100 ), $preload_counter[ 'c' ] ) . '</strong></p>';
$currently_preloading = true;
if ( @file_exists( $cache_path . "preload_permalink.txt" ) ) {
$url = file_get_contents( $cache_path . "preload_permalink.txt" );
echo "<p>" . sprintf( __( "<strong>Page last cached:</strong> %s", 'wp-super-cache' ), $url ) . "</p>";
}
}
echo '<div class="submit"><input class="button-primary" type="submit" name="preload" value="' . __( 'Update Settings', 'wp-super-cache' ) . '" /> <input class="button-secondary" type="submit" name="preload" value="' . __( 'Preload Cache Now', 'wp-super-cache' ) . '" />';
if ( $currently_preloading ) {
echo ' <input class="button-primary" type="submit" name="preload" value="' . __( 'Cancel Cache Preload', 'wp-super-cache' ) . '" />';
}
echo '</div>';
wp_nonce_field('wp-cache');
echo '</form>';
} else {
echo '<p>' . __( 'Preloading of cache disabled. Please disable legacy page caching or talk to your host administrator.', 'wp-super-cache' ) . '</p>';
}
break;
case 'plugins':
wpsc_plugins_tab();
break;
case 'debug':