PluginProbe ʕ •ᴥ•ʔ
Aruba HiSpeed Cache / trunk
Aruba HiSpeed Cache vtrunk
3.0.14 3.0.13 1.2.4 1.2.5 1.2.6 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.19 2.0.20 2.0.21 2.0.22 2.0.23 2.0.24 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3
aruba-hispeed-cache / src / AHSC_Static.php
aruba-hispeed-cache / src Last commit date
APC 3 months ago Events 3 months ago Purger 3 months ago assets 3 months ago AHSC_Apc.php 3 months ago AHSC_Check.php 3 months ago AHSC_Config.php 2 months ago AHSC_Dboptimization.php 3 months ago AHSC_Functions.php 2 months ago AHSC_HtmlOptimizer.php 3 months ago AHSC_Lazyload.php 1 week ago AHSC_Preconnect.php 3 months ago AHSC_Static.php 2 months ago AHSC_Version.php 3 months ago AHSC_Warmer.php 3 months ago AHSC_XmlRPC.php 3 months ago index.php 3 months ago
AHSC_Static.php
163 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5 //die(var_dump(AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']));
6 if ( is_array( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS'] ) && array_key_exists( 'ahsc_static_cache', AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS'] ) ) {
7 add_action( 'updated_option', 'AHSC_handle_static_cache_option_update', 10, 3 );
8 }
9 //$AHSC_marker = 'AHSC_RULES';
10
11 /**
12 * Sync directives in .htaccess file when the option changes
13 */
14 function AHSC_handle_static_cache_option_update( $option, $old_value, $value ) {
15 if ( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'] !== $option ) {
16 return;
17 }
18
19 if ( ! is_array( $value ) ) {
20 return;
21 }
22
23 $old_status = false;
24 if ( is_array( $old_value ) && isset( $old_value['ahsc_static_cache'] ) ) {
25 $old_status = (bool) $old_value['ahsc_static_cache'];
26 }
27
28 $new_status = false;
29 if ( isset( $value['ahsc_static_cache'] ) ) {
30 $new_status = (bool) $value['ahsc_static_cache'];
31 }
32
33 if ( $old_status === $new_status ) {
34 return;
35 }
36
37 if ( $new_status ) {
38 AHSC_edit_htaccess();
39 } else {
40 AHSC_remove_htaccess();
41 }
42 }
43
44 /**
45 * Get directives for .htaccess file
46 */
47 function AHSC_get_htaccess_rules() {
48 return array(
49 '<IfModule mod_expires.c>',
50 'ExpiresActive on',
51 '# CSS',
52 'ExpiresByType text/css "access plus 1 year"',
53 '# Data interchange',
54 'ExpiresByType application/json "access plus 0 seconds"',
55 'ExpiresByType application/xml "access plus 0 seconds"',
56 'ExpiresByType text/xml "access plus 0 seconds"',
57 '# Favicon (cannot be renamed!)',
58 'ExpiresByType image/x-icon "access plus 1 week"',
59 '# HTML components (HTCs)',
60 'ExpiresByType text/x-component "access plus 1 month"',
61 '# JavaScript',
62 'ExpiresByType application/javascript "access plus 1 year"',
63 '# Manifest files',
64 'ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"',
65 'ExpiresByType text/cache-manifest "access plus 0 seconds"',
66 '# Media',
67 'ExpiresByType audio/ogg "access plus 1 month"',
68 'ExpiresByType image/gif "access plus 1 month"',
69 'ExpiresByType image/jpeg "access plus 1 month"',
70 'ExpiresByType image/png "access plus 1 month"',
71 'ExpiresByType image/webp "access plus 1 month"',
72 'ExpiresByType video/mp4 "access plus 1 month"',
73 'ExpiresByType video/ogg "access plus 1 month"',
74 'ExpiresByType video/webm "access plus 1 month"',
75 '# Web feeds',
76 'ExpiresByType application/atom+xml "access plus 1 hour"',
77 'ExpiresByType application/rss+xml "access plus 1 hour"',
78 '# Web fonts',
79 'ExpiresByType application/font-woff2 "access plus 1 month"',
80 'ExpiresByType application/font-woff "access plus 1 month"',
81 'ExpiresByType application/vnd.ms-fontobject "access plus 1 month"',
82 'ExpiresByType application/x-font-ttf "access plus 1 month"',
83 'ExpiresByType font/opentype "access plus 1 month"',
84 'ExpiresByType image/svg+xml "access plus 1 month"',
85 '</IfModule>',
86 '# Set the cache-control max-age',
87 '# 1 year',
88 '<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|webp|woff2|woff|ttf)$">',
89 'Header set Cache-Control "max-age=31449600, public"',
90 '</FilesMatch>',
91 '# 2 DAYS',
92 '<FilesMatch ".(xml|txt)$">',
93 'Header set Cache-Control "max-age=172800, public, must-revalidate"',
94 '</FilesMatch>',
95 '<IfModule mod_deflate.c>',
96 '# Compress HTML, CSS, JavaScript, Text, XML and fonts',
97 'AddOutputFilterByType DEFLATE application/javascript',
98 'AddOutputFilterByType DEFLATE application/rss+xml',
99 'AddOutputFilterByType DEFLATE application/vnd.ms-fontobject',
100 'AddOutputFilterByType DEFLATE application/x-font',
101 'AddOutputFilterByType DEFLATE application/x-font-opentype',
102 'AddOutputFilterByType DEFLATE application/x-font-otf',
103 'AddOutputFilterByType DEFLATE application/x-font-truetype',
104 'AddOutputFilterByType DEFLATE application/x-font-ttf',
105 'AddOutputFilterByType DEFLATE application/x-javascript',
106 'AddOutputFilterByType DEFLATE application/xhtml+xml',
107 'AddOutputFilterByType DEFLATE application/xml',
108 'AddOutputFilterByType DEFLATE font/opentype',
109 'AddOutputFilterByType DEFLATE font/otf',
110 'AddOutputFilterByType DEFLATE font/ttf',
111 'AddOutputFilterByType DEFLATE image/svg+xml',
112 'AddOutputFilterByType DEFLATE image/x-icon',
113 'AddOutputFilterByType DEFLATE text/css',
114 'AddOutputFilterByType DEFLATE text/html',
115 'AddOutputFilterByType DEFLATE text/javascript',
116 'AddOutputFilterByType DEFLATE text/plain',
117 'AddOutputFilterByType DEFLATE text/xml',
118 '# Remove browser bugs (only needed for really old browsers)',
119 'BrowserMatch ^Mozilla/4 gzip-only-text/html',
120 'BrowserMatch ^Mozilla/4\.0[678] no-gzip',
121 'BrowserMatch \bMSIE !no-gzip !gzip-only-text/html',
122 //'Header append Vary User-Agent',
123 '</IfModule>',
124 );
125 }
126
127 /**
128 * ADD directives from .htaccess file
129 */
130 function AHSC_edit_htaccess() {
131 if ( ! is_multisite() ) {
132 require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
133 require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');
134 require_once( ABSPATH . 'wp-admin/includes/file.php' );
135 $AHSC_marker = 'AHSC_RULES';
136 $home_path = get_home_path();
137 $htaccess_location = $home_path . '.htaccess';
138 $filesystem = new WP_Filesystem_Direct( true );
139
140 $str = "# BEGIN $AHSC_marker\n ".implode("\n",AHSC_get_htaccess_rules())."\n# END $AHSC_marker\n";
141 $str .= $filesystem->get_contents($htaccess_location);
142 $filesystem->put_contents($htaccess_location,$str,0644);
143 }
144 }
145
146 /**
147 * REMOVE directives from .htaccess file
148 */
149 function AHSC_remove_htaccess() {
150 if ( ! is_multisite() ) {
151 require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
152 require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');
153 require_once( ABSPATH . 'wp-admin/includes/file.php' );
154 $AHSC_marker = 'AHSC_RULES';
155 $htaccess_location = get_home_path() . '.htaccess';
156 $filesystem = new WP_Filesystem_Direct( true );
157 $content= $filesystem->get_contents($htaccess_location);
158 // Rimuovi tutto tra i marker (inclusi i marker stessi)
159 $pattern = '/# BEGIN '.$AHSC_marker.'.*?# END '.$AHSC_marker.'\s*/s';
160 $newContent = preg_replace($pattern, '', $content);
161 $filesystem->put_contents($htaccess_location,$newContent,0644);
162 }
163 }