Changeset 1402700
- Timestamp:
- 04/23/2016 06:33:03 AM (10 years ago)
- Location:
- full-site-cache-kc/trunk
- Files:
-
- 3 edited
-
full-site-cache-kc.php (modified) (1 diff)
-
functions.php (modified) (4 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
full-site-cache-kc/trunk/full-site-cache-kc.php
r1402195 r1402700 46 46 require_once( $fskeycdn_path ); 47 47 add_filter( 'plugin_row_meta', 'fsckeycdn_meta', 91, 2 ); 48 add_filter( 'style_loader_src' , 'fsckeycdn_remove_admin' , 91 , 1 );49 add_filter( 'script_loader_src' , 'fsckeycdn_remove_admin' , 91 , 1 );50 48 add_filter( 'plugin_action_links', 'fsckeycdn_add_settings', 91, 2 ); 51 add_action( 'wp', 'fsckeycdn_header' );52 49 add_action( 'admin_menu', 'fsckeycdn_admin_menu', 5 ); 53 add_action( 'trashed_post', 'fsckeycdn_purge_blog', 91 ); 54 add_action( 'switch_theme', 'fsckeycdn_purge_blog', 91 ); 55 add_action( '_core_updated_successfully', 'fsckeycdn_purge_all', 91 ); 56 add_action( 'init', 'fsckeycdn_purge_button', 5 ); 57 add_action( 'init', 'fsckeycdn_register_publish_hooks', 99 ); 58 add_action( 'plugins_loaded', 'fsckeycdn_check_ce' ); 59 add_action( 'admin_bar_menu', 'fsckeycdn_add_admin_links', 99); 60 add_action( 'transition_comment_status', 'fsckeycdn_change_comment', 91, 3 ); 61 add_action( 'edit_comment', 'fsckeycdn_edit_comment' ); 62 add_action( 'pre_comment_approved', 'fsckeycdn_new_comment', 99, 2); 63 /* Add rewrite action */ 64 if(isset(explode('.',$fsckeycdn_realhost)[2]) && $_SERVER['HTTP_X_PULL'] == $fsckeycdn_x_pull_key){ 65 add_action( 'template_redirect','fsckeycdn_minify_html', 99 ); 66 } elseif((substr($fsckeycdn_realhost,0,9) == 'wp-admin.' || substr($fsckeycdn_realhost,0,9) == 'wp-admin-') && !strstr($_SERVER['REQUEST_URI'],'/options-general.php')) { 67 add_action( 'wp_loaded','fsckeycdn_minify_html_admin', 99 ); 50 if(fsckeycdn_status()){ 51 add_action( 'init', 'fsckeycdn_register_publish_hooks', 99 ); 52 add_action( 'init', 'fsckeycdn_purge_button', 5 ); 53 add_action( 'wp', 'fsckeycdn_header' ); 54 add_action( 'admin_bar_menu', 'fsckeycdn_add_admin_links', 99); 55 add_action( 'plugins_loaded', 'fsckeycdn_check_ce' ); 56 add_action( 'transition_comment_status', 'fsckeycdn_change_comment', 91, 3 ); 57 add_action( 'edit_comment', 'fsckeycdn_edit_comment' ); 58 add_action( 'pre_comment_approved', 'fsckeycdn_new_comment', 99, 2); 59 add_action( 'trashed_post', 'fsckeycdn_purge_blog', 91 ); 60 add_action( 'switch_theme', 'fsckeycdn_purge_blog', 91 ); 61 add_action( '_core_updated_successfully', 'fsckeycdn_purge_all', 91 ); 62 /* Add rewrite action */ 63 if(isset(explode('.',$fsckeycdn_realhost)[2]) && $_SERVER['HTTP_X_PULL'] == $fsckeycdn_x_pull_key){ 64 add_action( 'template_redirect','fsckeycdn_minify_html', 99 ); 65 } elseif((substr($fsckeycdn_realhost,0,9) == 'wp-admin.' || substr($fsckeycdn_realhost,0,9) == 'wp-admin-') && !strstr($_SERVER['REQUEST_URI'],'/options-general.php')) { 66 add_action( 'wp_loaded','fsckeycdn_minify_html_admin', 99 ); 67 } 68 68 } 69 69 } else { -
full-site-cache-kc/trunk/functions.php
r1402195 r1402700 109 109 function fsckeycdn_header(){ 110 110 global $fsckeycdn_x_pull_key, $fsckeycdn_scheme, $fsckeycdn_realhost, $fsckeycdn_blog_id; 111 if(fsckeycdn_status()){ 112 /* Set redirect if user not logged in */ 113 if(substr($_SERVER['REQUEST_URI'],0,11) != '/robots.txt' && $_SERVER['SCRIPT_NAME'] == '/index.php' && $_SERVER['HTTP_X_PULL'] != $fsckeycdn_x_pull_key && !is_user_logged_in()) { 114 if(substr($fsckeycdn_realhost,0,9) == 'wp-admin-') { 115 header('HTTP/1.1 302 Moved Temporarily'); 116 header('Location: '.wp_login_url($fsckeycdn_scheme.'://'.$fsckeycdn_realhost.$_SERVER['REQUEST_URI'])); 117 exit(); 118 } elseif(substr($fsckeycdn_realhost,0,9) == 'wp-admin.') { 119 header('HTTP/1.1 302 Moved Temporarily'); 120 header('Location: '.wp_login_url($fsckeycdn_scheme.'://'.$fsckeycdn_realhost.$_SERVER['REQUEST_URI'])); 121 exit(); 122 } 111 /* Set redirect if user not logged in */ 112 if(substr($_SERVER['REQUEST_URI'],0,11) != '/robots.txt' && $_SERVER['SCRIPT_NAME'] == '/index.php' && $_SERVER['HTTP_X_PULL'] != $fsckeycdn_x_pull_key && !is_user_logged_in()) { 113 if(substr($fsckeycdn_realhost,0,9) == 'wp-admin-') { 114 header('HTTP/1.1 302 Moved Temporarily'); 115 header('Location: '.wp_login_url($fsckeycdn_scheme.'://'.$fsckeycdn_realhost.$_SERVER['REQUEST_URI'])); 116 exit(); 117 } elseif(substr($fsckeycdn_realhost,0,9) == 'wp-admin.') { 118 header('HTTP/1.1 302 Moved Temporarily'); 119 header('Location: '.wp_login_url($fsckeycdn_scheme.'://'.$fsckeycdn_realhost.$_SERVER['REQUEST_URI'])); 120 exit(); 123 121 } 124 122 } … … 287 285 } 288 286 289 function fsckeycdn_remove_admin ( $url ) {290 $url = str_replace ( 'wp-admin.' , 'www.' , $url ) ;291 $url = str_replace ( 'wp-admin-' , '' , $url ) ;292 return $url ;293 }294 295 287 function fsckeycdn_minify_html_admin(){ 296 288 // Set URL rewrite for admin page. 297 289 ob_start('fsckeycdn_compress_admin'); 298 290 } 291 299 292 function fsckeycdn_compress_admin($html){ 300 293 global $fsckeycdn_realhost; … … 303 296 $html = str_replace('%3A%2F%2F'.$_SERVER['HTTP_HOST'],'%3A%2F%2Fwp-admin.'.substr($_SERVER['HTTP_HOST'],4),$html); 304 297 $html = str_replace(':\/\/'.$_SERVER['HTTP_HOST'],':\/\/wp-admin.'.substr($_SERVER['HTTP_HOST'],4),$html); 305 return $html;306 298 } elseif(isset(explode('.',$fsckeycdn_realhost)[2])) { 307 299 $html = str_replace('://'.$_SERVER['HTTP_HOST'],'://wp-admin-'.$_SERVER['HTTP_HOST'],$html); 308 300 $html = str_replace('%3A%2F%2F'.$_SERVER['HTTP_HOST'],'%3A%2F%2Fwp-admin-'.$_SERVER['HTTP_HOST'],$html); 309 301 $html = str_replace(':\/\/'.$_SERVER['HTTP_HOST'],':\/\/wp-admin-'.$_SERVER['HTTP_HOST'],$html); 310 return $html;311 }302 } 303 return $html; 312 304 } 313 305 … … 316 308 ob_start('fsckeycdn_compress'); 317 309 } 310 311 function fsckeycdn_rewrite_url($asset) { 312 global $fsckeycdn_cdn_domain,$fsckeycdn_scheme; 313 return str_replace($fsckeycdn_scheme.'://'.$_SERVER['HTTP_HOST'], $fsckeycdn_scheme.'://'.$fsckeycdn_cdn_domain, $asset[0]); 314 } 315 318 316 function fsckeycdn_compress($html){ 317 global $fsckeycdn_cdn_domain,$fsckeycdn_scheme; 319 318 if(substr($_SERVER['HTTP_HOST'],0,4) == 'www.') { 320 319 $html = str_replace('://wp-admin.'.substr($_SERVER['HTTP_HOST'],4),'://'.$_SERVER['HTTP_HOST'],$html); 321 320 $html = str_replace('%3A%2F%2Fwp-admin.'.substr($_SERVER['HTTP_HOST'],4),'%3A%2F%2F'.$_SERVER['HTTP_HOST'],$html); 322 321 $html = str_replace(':\/\/wp-admin.'.substr($_SERVER['HTTP_HOST'],4),':\/\/'.$_SERVER['HTTP_HOST'],$html); 323 return $html;324 322 } else { 325 323 $html = str_replace('://wp-admin-'.$_SERVER['HTTP_HOST'],'://'.$_SERVER['HTTP_HOST'],$html); 326 324 $html = str_replace('%3A%2F%2Fwp-admin-'.$_SERVER['HTTP_HOST'],'%3A%2F%2F'.$_SERVER['HTTP_HOST'],$html); 327 325 $html = str_replace(':\/\/wp-admin-'.$_SERVER['HTTP_HOST'],':\/\/'.$_SERVER['HTTP_HOST'],$html); 328 return $html; 329 } 326 } 327 328 if(isset($fsckeycdn_cdn_domain)){ 329 // get dir scope in regex format 330 $dirs = 'wp\-content|wp\-includes'; 331 332 // regex rule start 333 $regex_rule = '#(?<=[(\"\'])'.$fsckeycdn_scheme.'://'.$_SERVER['HTTP_HOST']; 334 335 // regex rule end 336 $regex_rule .= '/(?:((?:'.$dirs.')[^\"\')]+)|([^/\"\']+\.[^/\"\')]+))(?=[\"\')])#'; 337 338 // call the cdn rewriter callback 339 $html = preg_replace_callback($regex_rule, 'fsckeycdn_rewrite_url', $html); 340 } 341 342 return $html; 330 343 } 331 344 -
full-site-cache-kc/trunk/readme.txt
r1402195 r1402700 243 243 } 244 244 245 = Custom CDN Domain = 246 247 You can custom your CDN domain, it’s a specific domain that only for Images, CSS and JS. 248 249 Just add this in the `wp-config.php`. 250 251 $fsckeycdn_cdn_domain = 'cdn.example.com'; 252 245 253 == About Purge == 246 254
Note: See TracChangeset
for help on using the changeset viewer.