Last active
February 25, 2019 01:58
-
-
Save earth3300/c0307b852d0fe3223fac73f4f46a30fc to your computer and use it in GitHub Desktop.
Adjusted file path function from the cache-enabler plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Generate the Cache Path | |
| * | |
| * @param string $path | |
| * | |
| * @return string | |
| */ | |
| function _ce_file_path($path = NULL) { | |
| $url = parse_url( $_SERVER['REQUEST_URI'] ); | |
| $page = isset( $url['path'] ) ? $url['path'] : ''; | |
| $path = sprintf( '%s/%s', SITE_CACHE_PATH, $page ); | |
| if ( is_file($path) > 0 ) { | |
| header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404 ); | |
| exit; | |
| } | |
| // add trailing slash | |
| $path = rtrim( $path, '/\\' ) . '/'; | |
| //remove double slashes | |
| $path = str_replace( '//', '/', $path ); | |
| //remove double /a/a | |
| $path = str_replace( '/a/a', '/a', $path ); | |
| return $path; | |
| } | |
| /** | |
| * Cache Path | |
| * | |
| * Adjusted file path generator. Slightly different from the one | |
| * in advanced-cache.php | |
| * | |
| * @since 1.0.0 | |
| * @change 1.4.0 | |
| * | |
| * @param string $path uri or permlink | |
| * @return string $diff path to cached asset | |
| */ | |
| private static function _file_path($path = NULL) { | |
| $url = parse_url( $_SERVER['REQUEST_URI'] ); | |
| $page = isset( $url['path'] ) ? $url['path'] : ''; | |
| $path = sprintf( '%s/%s', SITE_CACHE_PATH, $page ); | |
| if ( is_file($path) > 0 ) { | |
| header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404 ); | |
| exit; | |
| } | |
| //remove double slashes | |
| $path = str_replace( '//', '/', $path ); | |
| //remove double /a/a | |
| $path = str_replace( '/a/a', '/a', $path ); | |
| if ( is_file($path) > 0 ) { | |
| wp_die('Path is not valid.'); | |
| } | |
| // add trailing slash | |
| $path = rtrim( $path, '/\\' ) . '/'; | |
| return $path; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment