Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions concat-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function do_items( $handles = false, $group = false ) {
$handles = false === $handles ? $this->queue : (array) $handles;
$stylesheets = array();
$siteurl = apply_filters( 'page_optimize_site_url', $this->base_url );
$site_uri_path = page_optimize_get_uri_path( $siteurl );

$this->all_deps( $handles );

Expand Down Expand Up @@ -136,7 +137,9 @@ function do_items( $handles = false, $group = false ) {
$media = 'all';
}

$stylesheets[ $concat_group ][ $media ][ $handle ] = $css_url_parsed['path'];
$css_uri_path = page_optimize_remove_uri_prefix( $site_uri_path, $css_url_parsed['path'] );

$stylesheets[ $concat_group ][ $media ][ $handle ] = $css_uri_path;
$this->done[] = $handle;
} else {
$stylesheet_group_index ++;
Expand All @@ -158,7 +161,7 @@ function do_items( $handles = false, $group = false ) {
} elseif ( count( $css ) > 1 ) {
$fs_paths = array();
foreach ( $css as $css_uri_path ) {
$fs_paths[] = $this->dependency_path_mapping->uri_path_to_fs_path( $css_uri_path );
$fs_paths[] = $this->dependency_path_mapping->uri_path_to_fs_path( $site_uri_path . $css_uri_path );
}

$mtime = max( array_map( 'filemtime', $fs_paths ) );
Expand Down
7 changes: 5 additions & 2 deletions concat-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function do_items( $handles = false, $group = false ) {
$handles = false === $handles ? $this->queue : (array) $handles;
$javascripts = array();
$siteurl = apply_filters( 'page_optimize_site_url', $this->base_url );
$site_uri_path = page_optimize_get_uri_path( $siteurl );
$this->all_deps( $handles );
$level = 0;

Expand Down Expand Up @@ -171,7 +172,9 @@ function do_items( $handles = false, $group = false ) {
$javascripts[ $level ]['type'] = 'concat';
}

$javascripts[ $level ]['paths'][] = $js_url_parsed['path'];
$js_uri_path = page_optimize_remove_uri_prefix( $site_uri_path, $js_url_parsed['path'] );

$javascripts[ $level ]['paths'][] = $js_uri_path;
$javascripts[ $level ]['handles'][] = $handle;

} else {
Expand Down Expand Up @@ -211,7 +214,7 @@ function do_items( $handles = false, $group = false ) {
if ( isset( $js_array['paths'] ) && count( $js_array['paths'] ) > 1 ) {
$fs_paths = array();
foreach ( $js_array['paths'] as $js_url ) {
$fs_paths[] = $this->dependency_path_mapping->uri_path_to_fs_path( $js_url );
$fs_paths[] = $this->dependency_path_mapping->uri_path_to_fs_path( $site_uri_path . $js_url );
}

$mtime = max( array_map( 'filemtime', $fs_paths ) );
Expand Down
24 changes: 23 additions & 1 deletion page-optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// TODO: Copy tests from nginx-http-concat and/or write them

// TODO: Make concat URL dir configurable
if ( isset( $_SERVER['REQUEST_URI'] ) && '/_static/' === substr( $_SERVER['REQUEST_URI'], 0, 9 ) ) {
if ( isset( $_SERVER['REQUEST_URI'] ) && false !== strpos( $_SERVER['REQUEST_URI'], '/_static/??' ) ) {
require_once __DIR__ . '/service.php';
exit;
}
Expand Down Expand Up @@ -213,6 +213,28 @@ function page_optimize_starts_with( $prefix, $str ) {
return substr( $str, 0, $prefix_length ) === $prefix;
}

/**
* Returns the uri path from the url.
*/
function page_optimize_get_uri_path( $url ) {
$path = trailingslashit( parse_url( $url, PHP_URL_PATH ) );
return $path == '/' ? '' : $path;
}

/**
* Removes the path prefix from the uri string.
*/
function page_optimize_remove_uri_prefix( $prefix, $uri ) {
if ( empty( $prefix ) ) {
return $uri;
}
if ( ! page_optimize_starts_with( $prefix, $uri ) ) {
return $uri;
}

return '/' . ltrim( substr( $uri, strlen($prefix) ), '/' );
}

/**
* Answers whether the plugin should provide concat resource URIs
* that are relative to a common ancestor directory. Assuming a common ancestor
Expand Down
2 changes: 1 addition & 1 deletion service.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function page_optimize_build_output() {
}

foreach ( $args as $uri ) {
$fullpath = page_optimize_get_path( $uri );
$fullpath = page_optimize_get_path( $subdir_path_prefix . $uri );

if ( ! file_exists( $fullpath ) ) {
page_optimize_status_exit( 404 );
Expand Down