PluginProbe ʕ •ᴥ•ʔ
WP Super Cache / 1.5.3
WP Super Cache v1.5.3
3.1.1 trunk 0.1 0.2 0.3 0.3.1 0.4 0.5 0.5.1 0.5.2 0.5.3 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.6.7 0.6.8 0.7 0.7.1 0.8 0.8.1 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.8.8 0.8.9 0.9 0.9.1 0.9.2 0.9.3 0.9.3.1 0.9.4 0.9.4.1 0.9.4.2 0.9.4.3 0.9.5 0.9.6 0.9.6.1 0.9.7 0.9.8 0.9.9 0.9.9.1 0.9.9.2 0.9.9.3 0.9.9.4 0.9.9.5 0.9.9.6 0.9.9.7 0.9.9.8 0.9.9.9 1.0 1.0.1 1.1 1.1.1 1.10.0 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.12.4 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.7.1 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8 1.9 1.9.1 1.9.2 1.9.3 1.9.4 2.0.0 2.0.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0
wp-super-cache / ossdl-cdn.php
wp-super-cache Last commit date
languages 13 years ago plugins 8 years ago rest 8 years ago advanced-cache.php 9 years ago ossdl-cdn.php 8 years ago readme.txt 8 years ago wp-cache-base.php 8 years ago wp-cache-config-sample.php 8 years ago wp-cache-phase1.php 8 years ago wp-cache-phase2.php 8 years ago wp-cache.php 8 years ago wp-super-cache.pot 9 years ago
ossdl-cdn.php
220 lines
1 <?php
2
3 /* Taken from OSSDL CDN off-linker, a plugin by W-Mark Kubacki (http://mark.ossdl.de/) and used with permission */
4
5 /* Set up some defaults */
6 if ( get_option( 'ossdl_off_cdn_url' ) == false )
7 add_option( 'ossdl_off_cdn_url', get_option( 'siteurl' ) );
8 $ossdl_off_blog_url = apply_filters( 'ossdl_off_blog_url', get_option( 'siteurl' ) );
9 $ossdl_off_cdn_url = trim( get_option('ossdl_off_cdn_url') );
10 if ( get_option( 'ossdl_off_include_dirs' ) == false )
11 add_option('ossdl_off_include_dirs', 'wp-content,wp-includes');
12 $ossdl_off_include_dirs = trim(get_option('ossdl_off_include_dirs'));
13 if ( get_option( 'ossdl_off_exclude' ) == false )
14 add_option('ossdl_off_exclude', '.php');
15 $ossdl_off_exclude = trim(get_option('ossdl_off_exclude'));
16 $arr_of_excludes = array_map('trim', explode(',', $ossdl_off_exclude));
17 if ( !is_array( $arr_of_excludes ) )
18 $arr_of_excludes = array();
19
20 if ( get_option( 'ossdl_cname' ) == false )
21 add_option('ossdl_cname', '');
22 $ossdl_cname = trim(get_option('ossdl_cname'));
23 $ossdl_https = intval(get_option('ossdl_https'));
24 $arr_of_cnames = array_map('trim', explode(',', $ossdl_cname));
25 if ($arr_of_cnames[0] == '') $arr_of_cnames = array();
26
27 /**
28 * Determines whether to exclude a match.
29 *
30 * @param String $match URI to examine
31 * @param Array $excludes array of "badwords"
32 * @return Boolean true if to exclude given match from rewriting
33 */
34 function scossdl_off_exclude_match($match, $excludes) {
35 foreach ($excludes as $badword) {
36 if (stristr($match, $badword) != false) {
37 return true;
38 }
39 }
40 return false;
41 }
42
43 /**
44 * Compute string modulo, based on SHA1 hash
45 */
46 function scossdl_string_mod($s, $mod) {
47 /* The full SHA1 is too large for PHP integer types. This should be
48 * enough for our purpose */
49 $n = hexdec(substr(sha1($s), 0, 5));
50 return $n % $mod;
51 }
52
53 /**
54 * Rewriter of URLs, used as replace-callback.
55 *
56 * Called by #scossdl_off_filter.
57 */
58 function scossdl_off_rewriter($match) {
59 global $ossdl_off_blog_url, $ossdl_off_cdn_url, $arr_of_excludes, $arr_of_cnames, $ossdl_https;
60
61 if ( $ossdl_off_cdn_url == '' )
62 return $match[0];
63
64 if ( $ossdl_https && substr( $match[0], 0, 5 ) == 'https' )
65 return $match[0];
66
67 if ( false == in_array( $ossdl_off_cdn_url, $arr_of_cnames ) )
68 $arr_of_cnames[] = $ossdl_off_cdn_url;
69
70 if ( scossdl_off_exclude_match( $match[0], $arr_of_excludes ) ) {
71 return $match[0];
72 } else {
73 $include_dirs = scossdl_off_additional_directories();
74 if ( preg_match( '/' . $include_dirs . '/', $match[0] ) ) {
75 $offset = scossdl_string_mod($match[1], count($arr_of_cnames));
76 return str_replace($ossdl_off_blog_url, $arr_of_cnames[$offset], $match[0]);
77 } else {
78 return $match[0];
79 }
80 }
81 }
82
83 /**
84 * Creates a regexp compatible pattern from the directories to be included in matching.
85 *
86 * @return String with the pattern with {@literal |} as prefix, or empty
87 */
88 function scossdl_off_additional_directories() {
89 global $ossdl_off_include_dirs;
90 $input = explode(',', $ossdl_off_include_dirs);
91 if ($ossdl_off_include_dirs == '' || count($input) < 1) {
92 return 'wp\-content|wp\-includes';
93 } else {
94 return implode('|', array_map('quotemeta', array_map('trim', $input)));
95 }
96 }
97
98 /**
99 * Output filter which runs the actual plugin logic.
100 */
101 function scossdl_off_filter($content) {
102 global $ossdl_off_blog_url, $ossdl_off_cdn_url;
103 if ($ossdl_off_blog_url == $ossdl_off_cdn_url) { // no rewrite needed
104 return $content;
105 } else {
106 $dirs = scossdl_off_additional_directories();
107 $regex = '#(?<=[(\"\'])'.quotemeta($ossdl_off_blog_url).'/(?:((?:'.$dirs.')[^\"\')]+)|([^/\"\']+\.[^/\"\')]+))(?=[\"\')])#';
108 return preg_replace_callback($regex, 'scossdl_off_rewriter', $content);
109 }
110 }
111
112 /**
113 * Registers scossdl_off_filter as output buffer, if needed.
114 */
115 function do_scossdl_off_ob_start() {
116 global $ossdl_off_blog_url, $ossdl_off_cdn_url;
117 if ($ossdl_off_blog_url != $ossdl_off_cdn_url) {
118 add_filter( 'wp_cache_ob_callback_filter', 'scossdl_off_filter' );
119 }
120 }
121 if ( false == isset( $ossdlcdn ) )
122 $ossdlcdn = 1; // have to default to on for existing users.
123 if ( $ossdlcdn == 1 )
124 add_action('init', 'do_scossdl_off_ob_start');
125
126 if ( function_exists( 'wp_verify_nonce' ) )
127 $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
128 else
129 $valid_nonce = false;
130
131 function scossdl_off_update() {
132 global $ossdlcdn, $wp_cache_config_file, $valid_nonce;
133
134 if ( $valid_nonce && isset($_POST['action']) && ( $_POST['action'] == 'update_ossdl_off' )){
135 update_option('ossdl_off_cdn_url', $_POST['ossdl_off_cdn_url']);
136 update_option('ossdl_off_include_dirs', $_POST['ossdl_off_include_dirs'] == '' ? 'wp-content,wp-includes' : $_POST['ossdl_off_include_dirs']);
137 update_option('ossdl_off_exclude', $_POST['ossdl_off_exclude']);
138 update_option('ossdl_cname', $_POST['ossdl_cname']);
139 if ( !isset( $_POST[ 'ossdl_https' ] ) )
140 $_POST[ 'ossdl_https' ] = 0;
141 update_option('ossdl_https', (int)$_POST['ossdl_https']);
142 if ( isset( $_POST[ 'ossdlcdn' ] ) ) {
143 $ossdlcdn = 1;
144 } else {
145 $ossdlcdn = 0;
146 }
147 wp_cache_replace_line('^ *\$ossdlcdn', "\$ossdlcdn = $ossdlcdn;", $wp_cache_config_file);
148 }
149 }
150
151 function scossdl_off_options() {
152 global $ossdlcdn, $wp_cache_config_file, $valid_nonce, $ossdl_off_blog_url;
153
154 scossdl_off_update();
155
156 $example_cdn_uri = str_replace( 'http://', 'http://cdn.', str_replace( 'www.', '', get_option( 'siteurl' ) ) );
157 $example_cnames = str_replace( 'http://cdn.', 'http://cdn1.', $example_cdn_uri );
158 $example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn2.', $example_cdn_uri );
159 $example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn3.', $example_cdn_uri );
160
161 $example_cdn_uri = get_option('ossdl_off_cdn_url') == get_option( 'siteurl' ) ? $example_cdn_uri : get_option('ossdl_off_cdn_url');
162 $example_cdn_uri .= '/wp-includes/js/jquery/jquery-migrate.js';
163 ?>
164 <p><?php _e( 'Your website probably uses lots of static files. Image, Javascript and CSS files are usually static files that could just as easily be served from another site or CDN. Therefore, this plugin replaces any links in the <code>wp-content</code> and <code>wp-includes</code> directories (except for PHP files) on your site with the URL you provide below. That way you can either copy all the static content to a dedicated host or mirror the files to a CDN by <a href="https://knowledgelayer.softlayer.com/faq/how-does-origin-pull-work" target="_blank">origin pull</a>.', 'wp-super-cache' ); ?></p>
165 <p><?php printf( __( '<strong style="color: red">WARNING:</strong> Test some static urls e.g., %s to ensure your CDN service is fully working before saving changes.', 'wp-super-cache' ), '<code>' . $example_cdn_uri . '</code>' ); ?></p>
166
167 <?php if ( $ossdl_off_blog_url != get_home_url() ) { ?>
168 <p><?php printf( __( '<strong style="color: red">WARNING:</strong> Your siteurl and homeurl are different. The plugin is using %s as the homepage URL of your site but if that is wrong please use the filter "ossdl_off_blog_url" to fix it.', 'wp-super-cache' ), '<code>' . $ossdl_off_blog_url . '</code>' ); ?></p>
169 <?php } ?>
170
171 <p><?php _e( 'You can define different CDN URLs for each site on a multsite network.', 'wp-super-cache' ); ?></p>
172 <p><form method="post" action="">
173 <?php wp_nonce_field('wp-cache'); ?>
174 <table class="form-table"><tbody>
175 <tr valign="top">
176 <td style='text-align: right'>
177 <input id='ossdlcdn' type="checkbox" name="ossdlcdn" value="1" <?php if ( $ossdlcdn ) echo "checked=1"; ?> />
178 </td>
179 <th scope="row"><label for="ossdlcdn"><?php _e( 'Enable CDN Support', 'wp-super-cache' ); ?></label></th>
180 </tr>
181 <tr valign="top">
182 <th scope="row"><label for="ossdl_off_cdn_url"><?php _e( 'Off-site URL', 'wp-super-cache' ); ?></label></th>
183 <td>
184 <input type="text" name="ossdl_off_cdn_url" value="<?php echo esc_url( get_option( 'ossdl_off_cdn_url' ) ); ?>" size="64" class="regular-text code" /><br />
185 <span class="description"><?php printf( __( 'The new URL to be used in place of %1$s for rewriting. No trailing <code>/</code> please.<br />Example: <code>%2$s</code>.', 'wp-super-cache' ), get_option( 'siteurl' ), $example_cdn_uri ); ?></span>
186 </td>
187 </tr>
188 <tr valign="top">
189 <th scope="row"><label for="ossdl_off_include_dirs"><?php _e( 'Include directories', 'wp-super-cache' ); ?></label></th>
190 <td>
191 <input type="text" name="ossdl_off_include_dirs" value="<?php echo esc_attr( get_option( 'ossdl_off_include_dirs' ) ); ?>" size="64" class="regular-text code" /><br />
192 <span class="description"><?php _e( 'Directories to include in static file matching. Use a comma as the delimiter. Default is <code>wp-content, wp-includes</code>, which will be enforced if this field is left empty.', 'wp-super-cache' ); ?></span>
193 </td>
194 </tr>
195 <tr valign="top">
196 <th scope="row"><label for="ossdl_off_exclude"><?php _e( 'Exclude if substring', 'wp-super-cache' ); ?></label></th>
197 <td>
198 <input type="text" name="ossdl_off_exclude" value="<?php echo esc_attr( get_option( 'ossdl_off_exclude' ) ); ?>" size="64" class="regular-text code" /><br />
199 <span class="description"><?php _e( 'Excludes something from being rewritten if one of the above strings is found in the match. Use a comma as the delimiter like this, <code>.php, .flv, .do</code>, and always include <code>.php</code> (default).', 'wp-super-cache' ); ?></span>
200 </td>
201 </tr>
202 <tr valign="top">
203 <th scope="row"><label for="ossdl_cname"><?php _e( 'Additional CNAMES', 'wp-super-cache' ); ?></label></th>
204 <td>
205 <input type="text" name="ossdl_cname" value="<?php echo esc_attr( get_option( 'ossdl_cname' ) ); ?>" size="64" class="regular-text code" /><br />
206 <span class="description"><?php printf( __( 'These <a href="http://en.wikipedia.org/wiki/CNAME_record">CNAMES</a> will be used in place of %1$s for rewriting (in addition to the off-site URL above). Use a comma as the delimiter. For pages with a large number of static files, this can improve browser performance. CNAMEs may also need to be configured on your CDN.<br />Example: %2$s', 'wp-super-cache' ), get_option( 'siteurl' ), $example_cnames ); ?></span>
207 </td>
208 </tr>
209 <tr valign="top">
210 <th scope="row" colspan='2'><label><input type='checkbox' name='ossdl_https' value='1' <?php if ( get_option( 'ossdl_https' ) ) { echo 'checked'; } ?> /> <?php _e( 'Skip https URLs to avoid "mixed content" errors', 'wp-super-cache' ); ?></label></th>
211 </tr>
212 </tbody></table>
213 <input type="hidden" name="action" value="update_ossdl_off" />
214 <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'wp-super-cache' ) ?>" /></p>
215 </form></p>
216 <p><?php _e( 'CDN functionality provided by <a href="http://wordpress.org/plugins/ossdl-cdn-off-linker/">OSSDL CDN Off Linker</a> by <a href="http://mark.ossdl.de/">Mark Kubacki</a>', 'wp-super-cache' ); ?></p>
217 <?php
218 }
219 ?>
220