-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make wordpress.html configurable via query params
Read startup configuration from the query params in wordpress.html. Supported params: mode (string): `seamless` or `browser` – whether to make the WordPress iframe fill the entire available space, or display the fake browser UI. url (string) – the initial page URL to open, e.g. /wp-login.php plugin (string) – the plugin to and preinstall. It must be a name of the zip file that’s available in the `https://downloads.wordpress.org/plugin/` directory, e.g. `gutenberg.14.3.1.zip`. This commit also ships a JS and PHP versions of a minimalistic HTTP proxy to make plugins downloadable from the same domain. Unfortunately the downloads.wordpress.org URLs can’t be requested via XHR or fetch() due to cross-origin limitations. Downloading the plugins is taken into account when rendering the progress bar. Examples: * `wordpress.html?mode=seamless` – render WordPress.wasm in the seamless mode and fill the entire page * `wordpress.html?mode=browser&plugin=gutenberg.14.3.1.zip` – render the fake browser UI and preinstall the Gutenberg plugin before rendering the page
- Loading branch information
Showing
11 changed files
with
556 additions
and
349 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
function download_file($url){ | ||
$ch = curl_init($url); | ||
curl_setopt($ch, CURLOPT_HEADER, 1); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); | ||
|
||
$response = curl_exec($ch); | ||
|
||
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | ||
$headers = array_map('trim', explode("\n", substr($response, 0, $header_size))); | ||
$body = substr($response, $header_size); | ||
|
||
return [$headers, $body]; | ||
} | ||
|
||
|
||
$plugin_name = preg_replace('#[^a-zA-Z0-9\.\-_]#', '', $_GET['plugin']); | ||
$zip_url = 'https://downloads.wordpress.org/plugin/' . $plugin_name; | ||
|
||
[$received_headers, $bytes] = download_file($zip_url); | ||
|
||
$forward_headers = [ | ||
'content-length', | ||
'content-type', | ||
'content-disposition', | ||
'x-frame-options', | ||
'last-modified', | ||
'etag', | ||
'date', | ||
'age', | ||
'vary', | ||
'cache-Control' | ||
]; | ||
|
||
foreach($received_headers as $received_header) { | ||
$comparable_header = strtolower($received_header); | ||
foreach($forward_headers as $sought_header) { | ||
if(substr($comparable_header, 0, strlen($sought_header)) === $sought_header){ | ||
header($received_header); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
echo $bytes; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
function download_file($url){ | ||
$ch = curl_init($url); | ||
curl_setopt($ch, CURLOPT_HEADER, 1); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); | ||
|
||
$response = curl_exec($ch); | ||
|
||
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | ||
$headers = array_map('trim', explode("\n", substr($response, 0, $header_size))); | ||
$body = substr($response, $header_size); | ||
|
||
return [$headers, $body]; | ||
} | ||
|
||
|
||
$plugin_name = preg_replace('#[^a-zA-Z0-9\.\-_]#', '', $_GET['plugin']); | ||
$zip_url = 'https://downloads.wordpress.org/plugin/' . $plugin_name; | ||
|
||
[$received_headers, $bytes] = download_file($zip_url); | ||
|
||
$forward_headers = [ | ||
'content-length', | ||
'content-type', | ||
'content-disposition', | ||
'x-frame-options', | ||
'last-modified', | ||
'etag', | ||
'date', | ||
'age', | ||
'vary', | ||
'cache-Control' | ||
]; | ||
|
||
foreach($received_headers as $received_header) { | ||
$comparable_header = strtolower($received_header); | ||
foreach($forward_headers as $sought_header) { | ||
if(substr($comparable_header, 0, strlen($sought_header)) === $sought_header){ | ||
header($received_header); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
echo $bytes; |
This file contains 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
Oops, something went wrong.