Skip to content
Merged
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
23 changes: 23 additions & 0 deletions packages/playground/website/public/plugin-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,29 @@ function ($curl, $body) use (&$extra_headers_sent, $default_response_headers) {
}

$downloader->streamFromGithubReleases($_GET['repo'], $_GET['name']);
} else if ( isset( $_GET['wordpress-branch'] ) ) {
$branch = strtolower( $_GET['wordpress-branch'] );
if ( $branch === 'trunk' || $branch === 'master' ) {
$branch = 'master';
// If the brach is of the form x.x append '-branch' to it.
} elseif ( preg_match( '/^\d+\.\d+$/', $branch ) ) {
$branch .= '-branch';
} elseif ( ! preg_match( '/^\d+\.\d+-branch$/', $branch ) ) {
throw new ApiException( 'Invalid branch' );
}

$url = "https://codeload.github.com/WordPress/WordPress/zip/refs/heads/{$branch}";

streamHttpResponse(
$url,
'GET',
[],
file_get_contents('php://input'),
null,
[
'Content-Disposition: attachment; filename="wordpress.zip"',
]
);
} else if (isset($_GET['url'])) {
// Proxy the current request to $_GET['url'] and return the response,
// but only if the URL is allowlisted.
Expand Down
22 changes: 21 additions & 1 deletion packages/playground/wordpress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,32 @@ export async function unzipWordPress(php: PHP, wpZip: File) {
// @TODO: Don't make so many guesses about the zip file contents. Allow the
// API consumer to specify the exact "coordinates" of WordPress inside
// the zip archive.
const wpPath = php.fileExists('/tmp/unzipped-wordpress/wordpress')
let wpPath = php.fileExists('/tmp/unzipped-wordpress/wordpress')
? '/tmp/unzipped-wordpress/wordpress'
: php.fileExists('/tmp/unzipped-wordpress/build')
? '/tmp/unzipped-wordpress/build'
: '/tmp/unzipped-wordpress';

// Dive one directory deeper if the zip root does not contain the sample
// config file. This is relevant when unzipping a zipped branch from the
// https://github.com/WordPress/WordPress repository.
if (!php.fileExists(joinPaths(wpPath, 'wp-config-sample.php'))) {
// Still don't know the directory structure of the zip file.
// 1. Get the first item in path.
const files = php.listFiles(wpPath);
if (files.length) {
const firstDir = files[0];
// 2. If it's a directory that contains wp-config-sample.php, use it.
if (
php.fileExists(
joinPaths(wpPath, firstDir, 'wp-config-sample.php')
)
) {
wpPath = joinPaths(wpPath, firstDir);
}
}
}

if (
php.isDir(php.documentRoot) &&
isCleanDirContainingSiteMetadata(php.documentRoot, php)
Expand Down
Loading