Skip to content

Commit

Permalink
Code refactoring inside wp-cache-base.php (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
stodorovic authored and donnchawp committed Sep 5, 2018
1 parent a6d4af7 commit ed8747a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
50 changes: 29 additions & 21 deletions wp-cache-base.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
global $WPSC_HTTP_HOST, $blogcacheid;
global $WPSC_HTTP_HOST, $cache_enabled, $cache_path, $blogcacheid, $blog_cache_dir;

if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
$WPSC_HTTP_HOST = htmlentities( $_SERVER['HTTP_HOST'] );
$WPSC_HTTP_HOST = function_exists( 'mb_strtolower' ) ? mb_strtolower( $_SERVER['HTTP_HOST'] ) : strtolower( $_SERVER['HTTP_HOST'] );
$WPSC_HTTP_HOST = htmlentities( $WPSC_HTTP_HOST );
} elseif ( PHP_SAPI === 'cli' && function_exists( 'get_option' ) ) {
$WPSC_HTTP_HOST = (string) parse_url( get_option( 'home' ), PHP_URL_HOST );
} else {
Expand All @@ -11,29 +12,36 @@
}

// We want to be able to identify each blog in a WordPress MU install
$blogcacheid = '';
$blogcacheid = '';
$blog_cache_dir = $cache_path;

if ( is_multisite() ) {
$blogcacheid = 'blog'; // main blog
if ( ( defined('SUBDOMAIN_INSTALL') && SUBDOMAIN_INSTALL ) || ( defined( 'VHOST' ) && VHOST == 'yes' ) ) {
global $current_blog;

if ( is_object( $current_blog ) && function_exists( 'is_subdomain_install' ) ) {
$blogcacheid = is_subdomain_install() ? $current_blog->domain : trim( $current_blog->path, '/' );
} elseif ( ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) || ( defined( 'VHOST' ) && VHOST === 'yes' ) ) {
$blogcacheid = $WPSC_HTTP_HOST;
} else {
if ( isset( $base ) == false ) {
$base = '';
}
$request_uri = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
if ( strlen( $request_uri ) > 0 && strpos( $request_uri, '/', 1 ) ) {
if ( $base == '/' ) {
$blogcacheid = substr( $request_uri, 1, strpos( $request_uri, '/', 1 ) - 1 );
} else {
$blogcacheid = str_replace( $base, '', $request_uri );
if ( $blogcacheid != '' ) {
$blogcacheid = substr( $blogcacheid, 0, strpos( $blogcacheid, '/', 1 ) );
}
}
if ( '/' == substr( $blogcacheid, -1 ) ) {
$blogcacheid = substr( $blogcacheid, 0, -1 );
}
$request_uri = str_replace( '//', '/', $request_uri );

$wpsc_path_segs = array_filter( explode( '/', trim( $request_uri, '/' ) ) );
$wpsc_base_count = defined( 'PATH_CURRENT_SITE' ) ? count( array_filter( explode( '/', trim( PATH_CURRENT_SITE, '/' ) ) ) ) : 0;
if ( '/' !== substr( $request_uri, -1 ) ) {
$wpsc_path_segs = array_slice( $wpsc_path_segs, 0, -1 );
}
$blogcacheid = str_replace( '/', '', $blogcacheid );

if ( count( $wpsc_path_segs ) > $wpsc_base_count &&
( ! defined( 'PATH_CURRENT_SITE' ) || 0 === strpos( $request_uri, PATH_CURRENT_SITE ) )
) {
$blogcacheid = $wpsc_path_segs[ $wpsc_base_count ];
}
}

// If blogcacheid is empty then set it to main blog.
if ( empty( $blogcacheid ) ) {
$blogcacheid = 'blog';
}
$blog_cache_dir = str_replace( '//', '/', $cache_path . 'blogs/' . $blogcacheid . '/' );
}
2 changes: 1 addition & 1 deletion wp-cache-phase2.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ function get_oc_key( $url = false ) {
global $wp_cache_gzip_encoding, $WPSC_HTTP_HOST;

if ( $url ) {
$key = intval( $_SERVER[ 'SERVER_PORT' ] ) . strtolower( preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) ) . $url;
$key = intval( $_SERVER[ 'SERVER_PORT' ] ) . preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) . $url;
} else {
$key = get_current_url_supercache_dir();
}
Expand Down

0 comments on commit ed8747a

Please sign in to comment.