Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 28
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2global $WPSC_HTTP_HOST, $cache_enabled, $cache_path, $blogcacheid, $blog_cache_dir;
3
4// we need to backup HTTP_HOST early in the PHP process, and if running in command line set it to something useful.
5if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
6    $WPSC_HTTP_HOST = function_exists( 'mb_strtolower' ) ? mb_strtolower( $_SERVER['HTTP_HOST'] ) : strtolower( $_SERVER['HTTP_HOST'] );
7    // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
8    $WPSC_HTTP_HOST = htmlentities( $WPSC_HTTP_HOST, ENT_COMPAT );
9} elseif ( PHP_SAPI === 'cli' && function_exists( 'get_option' ) ) {
10    $WPSC_HTTP_HOST = (string) parse_url( get_option( 'home' ), PHP_URL_HOST );
11} else {
12    $cache_enabled  = false;
13    $WPSC_HTTP_HOST = '';
14}
15
16// We want to be able to identify each blog in a WordPress MU install
17$blogcacheid    = '';
18$blog_cache_dir = $cache_path;
19
20// we might be able to simplify this. I run a multisite and the blogs directory isn't used any more.
21// $blogcacheid is set to the domain or prefix path of your site, and all files are put in $cache_path/supercache/$blogcacheid/[REQUEST_URI path]/
22if ( is_multisite() ) {
23    global $current_blog;
24
25    if ( is_object( $current_blog ) && function_exists( 'is_subdomain_install' ) ) {
26        $blogcacheid = is_subdomain_install() ? $current_blog->domain : trim( $current_blog->path, '/' );
27    } elseif ( ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) || ( defined( 'VHOST' ) && VHOST === 'yes' ) ) {
28        $blogcacheid = $WPSC_HTTP_HOST;
29    } else {
30        $request_uri = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
31        $request_uri = str_replace( '//', '/', $request_uri );
32
33        $wpsc_path_segs  = array_filter( explode( '/', trim( $request_uri, '/' ) ) );
34        $wpsc_base_count = defined( 'PATH_CURRENT_SITE' ) ? count( array_filter( explode( '/', trim( PATH_CURRENT_SITE, '/' ) ) ) ) : 0;
35        if ( ! str_ends_with( $request_uri, '/' ) ) {
36            $wpsc_path_segs = array_slice( $wpsc_path_segs, 0, -1 );
37        }
38
39        if ( count( $wpsc_path_segs ) > $wpsc_base_count &&
40            ( ! defined( 'PATH_CURRENT_SITE' ) || str_starts_with( $request_uri, PATH_CURRENT_SITE ) )
41        ) {
42            $blogcacheid = $wpsc_path_segs[ $wpsc_base_count ];
43        }
44    }
45
46    // If blogcacheid is empty then set it to main blog.
47    if ( empty( $blogcacheid ) ) {
48        $blogcacheid = 'blog';
49    }
50    $blog_cache_dir = str_replace( '//', '/', $cache_path . 'blogs/' . $blogcacheid . '/' );
51}