mirror of
https://github.com/bdnugget/php-wasm.git
synced 2026-11-07 09:07:28 +00:00
Simple inline script.
This commit is contained in:
1 parent
6af9e95894
commit
72568202e6
6 files changed
+99
-67
No files matched your search
+9
-1
@@ -2,7 +2,15 @@
|
||||
|
||||
Changes
|
||||
|
||||
## 0.0.6 - Remodermizing
|
||||
## 0.0.8 - Remodermizing
|
||||
|
||||
* Adding ESM Module support!
|
||||
* Fixing `<script type = "text/php">` support.
|
||||
* Adding support for iconv & html-tidy
|
||||
* Updating PHP to 8.2.11
|
||||
* Building with Emscripten 3.1.43
|
||||
|
||||
## 0.0.7 - Remodermizing
|
||||
|
||||
* Updating PHP to 8.2.4
|
||||
* Updating SQLite to 3.41
|
||||
|
||||
@@ -177,9 +177,6 @@ lib/lib/libiconv.a: third_party/libiconv-1.17/README
|
||||
lib/${PHP_AR}.a: third_party/php${PHP_VERSION}-src/configured third_party/php${PHP_VERSION}-src/patched third_party/php${PHP_VERSION}-src/**.c source/sqlite3.c
|
||||
@ echo -e "\e[33mBuilding PHP symbol files"
|
||||
@ ${DOCKER_RUN_IN_PHP} emmake make -j`nproc` EXTRA_CFLAGS='-Wno-int-conversion -Wno-incompatible-function-pointer-types -fPIC'
|
||||
@ ${DOCKER_RUN} cp -v \
|
||||
third_party/php${PHP_VERSION}-src/.libs/${PHP_AR}.la \
|
||||
third_party/php${PHP_VERSION}-src/.libs/${PHP_AR}.a lib/
|
||||
|
||||
########### Build the final files. ###########
|
||||
|
||||
@@ -188,6 +185,7 @@ third_party/php${PHP_VERSION}-src/configured: third_party/php${PHP_VERSION}-src/
|
||||
${DOCKER_RUN_IN_PHP} ./buildconf --force
|
||||
${DOCKER_RUN_IN_PHP} emconfigure ./configure \
|
||||
PKG_CONFIG_PATH=${PKG_CONFIG_PATH} \
|
||||
--prefix=/src/lib/ \
|
||||
--enable-embed=static \
|
||||
--with-layout=GNU \
|
||||
--with-libxml \
|
||||
|
||||
@@ -28,6 +28,24 @@
|
||||
+ [Drupal 7](https://seanmorris.github.io/php-wasm/?autorun=1&persist=0&single-expression=0&code=%253C%253Fphp%2520%252F%252F%2520%257B%2522autorun%2522%253Atrue%252C%2520%2522persist%2522%253Afalse%252C%2520%2522single-expression%2522%253A%2520false%252C%2520%2522render-as%2522%253A%2520%2522html%2522%257D%250Aini_set%28%27session.save_path%27%252C%2520%27%252Fhome%252Fweb_user%27%29%253B%250A%250A%2524stdErr%2520%253D%2520fopen%28%27php%253A%252F%252Fstderr%27%252C%2520%27w%27%29%253B%250A%2524errors%2520%253D%2520%255B%255D%253B%250A%250Aregister_shutdown_function%28function%28%29%2520use%28%2524stdErr%252C%2520%2526%2524errors%29%257B%250A%2509fwrite%28%2524stdErr%252C%2520json_encode%28%255B%27session_id%27%2520%253D%253E%2520session_id%28%29%255D%29%2520.%2520%2522%255Cn%2522%29%253B%250A%2509fwrite%28%2524stdErr%252C%2520json_encode%28%255B%27headers%27%253D%253Eheaders_list%28%29%255D%29%2520.%2520%2522%255Cn%2522%29%253B%250A%2509fwrite%28%2524stdErr%252C%2520json_encode%28%255B%27errors%27%2520%253D%253E%2520error_get_last%28%29%255D%29%2520.%2520%2522%255Cn%2522%29%253B%250A%257D%29%253B%250A%250Aset_error_handler%28function%28...%2524args%29%2520use%28%2524stdErr%252C%2520%2526%2524errors%29%257B%250A%2509fwrite%28%2524stdErr%252C%2520print_r%28%2524args%252C1%29%29%253B%250A%257D%29%253B%250A%250A%2524docroot%2520%253D%2520%27%252Fpreload%252Fdrupal-7.95%27%253B%250A%2524path%2520%2520%2520%2520%253D%2520%27%252F%27%253B%250A%2524script%2520%2520%253D%2520%27index.php%27%253B%250A%250A%2524_SERVER%255B%27REQUEST_URI%27%255D%2520%2520%2520%2520%2520%253D%2520%2524docroot%2520.%2520%2524path%253B%250A%2524_SERVER%255B%27REMOTE_ADDR%27%255D%2520%2520%2520%2520%2520%253D%2520%27127.0.0.1%27%253B%250A%2524_SERVER%255B%27SERVER_NAME%27%255D%2520%2520%2520%2520%2520%253D%2520%27localhost%27%253B%250A%2524_SERVER%255B%27SERVER_PORT%27%255D%2520%2520%2520%2520%2520%253D%25203333%253B%250A%2524_SERVER%255B%27REQUEST_METHOD%27%255D%2520%2520%253D%2520%27GET%27%253B%250A%2524_SERVER%255B%27SCRIPT_FILENAME%27%255D%2520%253D%2520%2524docroot%2520.%2520%27%252F%27%2520.%2520%2524script%253B%250A%2524_SERVER%255B%27SCRIPT_NAME%27%255D%2520%2520%2520%2520%2520%253D%2520%2524docroot%2520.%2520%27%252F%27%2520.%2520%2524script%253B%250A%2524_SERVER%255B%27PHP_SELF%27%255D%2520%2520%2520%2520%2520%2520%2520%2520%253D%2520%2524docroot%2520.%2520%27%252F%27%2520.%2520%2524script%253B%250A%250Achdir%28%2524docroot%29%253B%250A%250Aob_start%28%29%253B%250A%250Adefine%28%27DRUPAL_ROOT%27%252C%2520getcwd%28%29%29%253B%250A%250Arequire_once%2520DRUPAL_ROOT%2520.%2520%27%252Fincludes%252Fbootstrap.inc%27%253B%250Adrupal_bootstrap%28DRUPAL_BOOTSTRAP_FULL%29%253B%250A%250A%2524uid%2520%2520%2520%2520%2520%253D%25201%253B%250A%2524user%2520%2520%2520%2520%253D%2520user_load%28%2524uid%29%253B%250A%2524account%2520%253D%2520array%28%27uid%27%2520%253D%253E%2520%2524user-%253Euid%29%253B%250Auser_login_submit%28array%28%29%252C%2520%2524account%29%253B%250A%250A%2524itemPath%2520%253D%2520%2524path%253B%250A%2524itemPath%2520%253D%2520preg_replace%28%27%252F%255E%255C%255C%252Fpreload%252F%27%252C%2520%27%27%252C%2520%2524itemPath%29%253B%250A%2524itemPath%2520%253D%2520preg_replace%28%27%252F%255E%255C%255C%252Fdrupal-7.59%252F%27%252C%2520%27%27%252C%2520%2524itemPath%29%253B%250A%2524itemPath%2520%253D%2520preg_replace%28%27%252F%255E%255C%252F%252F%27%252C%2520%27%27%252C%2520%2524itemPath%29%253B%250A%250Aif%28%2524itemPath%29%250A%257B%250A%250A%2509%2524router_item%2520%253D%2520menu_get_item%28%2524itemPath%29%253B%250A%2509%2524router_item%255B%27access_callback%27%255D%2520%253D%2520true%253B%250A%2509%2524router_item%255B%27access%27%255D%2520%253D%2520true%253B%250A%250A%2509if%2520%28%2524router_item%255B%27include_file%27%255D%29%2520%257B%250A%2509%2520%2520require_once%2520DRUPAL_ROOT%2520.%2520%27%252F%27%2520.%2520%2524router_item%255B%27include_file%27%255D%253B%250A%2509%257D%250A%250A%2509%2524page_callback_result%2520%253D%2520call_user_func_array%28%2524router_item%255B%27page_callback%27%255D%252C%2520unserialize%28%2524router_item%255B%27page_arguments%27%255D%29%29%253B%250A%250A%2509drupal_deliver_page%28%2524page_callback_result%29%253B%250A%257D%250Aelse%250A%257B%250A%2509menu_execute_active_handler%28%29%253B%250A%257D%250A&render-as=html)
|
||||
|
||||
|
||||
## Quickstart
|
||||
|
||||
### Inline PHP
|
||||
|
||||
Include the `php-tags.js` script from Unpkg:
|
||||
|
||||
```html
|
||||
<script async type = "text/javascript" src = "https://www.unpkg.com/php-wasm/php-tags.mjs"></script>
|
||||
```
|
||||
|
||||
And run some PHP right in the page!
|
||||
|
||||
```html
|
||||
<script type = "text/php">
|
||||
<?php phpinfo();
|
||||
</script>
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
|
||||
Install with npm:
|
||||
@@ -145,12 +163,6 @@ vrzno_eval('document.title = "' . $newTitle . '"' );
|
||||
|
||||
```
|
||||
|
||||
# php-wasm is a fork of oraoto/PIB...
|
||||
|
||||
**[Run PIB](https://seanmorris.github.io/php-wasm/)**
|
||||
|
||||
Firefox is recommended for better user experience.
|
||||
|
||||
## Building From Source
|
||||
|
||||
### Using Docker
|
||||
@@ -161,16 +173,8 @@ The quickest way to build PIB is by using Make & Docker. Simply issue the `make`
|
||||
make
|
||||
```
|
||||
|
||||
### Using Emscripten SDK (emsdk) manually
|
||||
## php-wasm is a fork of oraoto/PIB...
|
||||
|
||||
Steps:
|
||||
**[Run PIB](https://seanmorris.github.io/php-wasm/)**
|
||||
|
||||
+ Setup emsdk (>= 1.38.11), see [Installation Instructions](https://emscripten.org/docs/getting_started/downloads.html#installation-instructions)
|
||||
+ Run `bash configure.sh`
|
||||
+ Run `bash build-objects.sh`
|
||||
+ Run `bash build.sh` to build the web binary
|
||||
|
||||
# Acknowledgements
|
||||
|
||||
- php-wasm and makefile contributed by @seanmorris
|
||||
- The Web UI is based on [Rust Playground](https://play.rust-lang.org/).
|
||||
Firefox is recommended for better user experience.
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "php-wasm",
|
||||
"version": "0.0.0-esm-preview-4",
|
||||
"version": "0.0.0-esm-preview-12",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "php-wasm",
|
||||
"version": "0.0.0-esm-preview-4",
|
||||
"version": "0.0.0-esm-preview-12",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.8.4",
|
||||
|
||||
+3
-2
@@ -3,7 +3,7 @@
|
||||
"description": "Run PHP right in the browser.",
|
||||
"repository": "https://github.com/seanmorris/pib",
|
||||
"author": "Oraoto <oraoto@outlook.com>",
|
||||
"version": "0.0.0-esm-preview-5",
|
||||
"version": "0.0.0-esm-preview-12",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
@@ -62,6 +62,7 @@
|
||||
"UniqueIndex.js",
|
||||
"UniqueIndex.mjs",
|
||||
"ZVal.js",
|
||||
"ZVal.mjs"
|
||||
"ZVal.mjs",
|
||||
"php-tags.mjs"
|
||||
]
|
||||
}
|
||||
+63
-42
@@ -10,62 +10,83 @@ export class PhpWeb extends PhpBase
|
||||
}
|
||||
}
|
||||
|
||||
if(window && document)
|
||||
{
|
||||
const runPhpScript = element => {
|
||||
|
||||
const inlineCode = element.innerText.trim();
|
||||
|
||||
if(!inlineCode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const output = document.createElement('div');
|
||||
|
||||
element.parentNode.insertBefore(output, element.nextSibling);
|
||||
|
||||
let buffer = '';
|
||||
|
||||
const php = new PhpWeb;
|
||||
|
||||
const runScriptTag = element => {
|
||||
|
||||
const src = element.getAttribute('src');
|
||||
|
||||
if(src)
|
||||
{
|
||||
fetch(src).then(r => r.text()).then(r => {
|
||||
php.run(r).then(exit=>console.log(exit));
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const inlineCode = element.innerText.trim();
|
||||
|
||||
if(inlineCode)
|
||||
{
|
||||
php.run(inlineCode);
|
||||
}
|
||||
|
||||
};
|
||||
php.addEventListener('output', (event) => buffer += event.detail);
|
||||
|
||||
php.addEventListener('ready', () => {
|
||||
const phpSelector = 'script[type="text/php"]';
|
||||
php.run(inlineCode).then(() => {
|
||||
output.innerHTML = buffer;
|
||||
});
|
||||
});
|
||||
|
||||
const htmlNode = document.body.parentElement;
|
||||
const observer = new MutationObserver((mutations, observer)=>{
|
||||
for(const mutation of mutations)
|
||||
{
|
||||
for(const addedNode of mutation.addedNodes)
|
||||
{
|
||||
if(!addedNode.matches || !addedNode.matches(phpSelector))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
php.addEventListener('error', (event) => {
|
||||
event.detail.forEach(error => {
|
||||
error = error.trim();
|
||||
if(error) console.log(error);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
runScriptTag(addedNode);
|
||||
}
|
||||
const runPhpScriptTag = element => {
|
||||
|
||||
}
|
||||
const src = element.getAttribute('src');
|
||||
|
||||
if(src)
|
||||
{
|
||||
fetch(src).then(r => r.text()).then(r => {
|
||||
runPhpScript(r).then(exit=>console.log(exit));
|
||||
});
|
||||
|
||||
observer.observe(htmlNode, {childList: true, subtree: true});
|
||||
return;
|
||||
}
|
||||
|
||||
const phpNodes = document.querySelectorAll(phpSelector);
|
||||
return runPhpScript(element);
|
||||
};
|
||||
|
||||
for(const phpNode of phpNodes)
|
||||
export const runPhpTags = (doc) => {
|
||||
|
||||
const phpSelector = 'script[type="text/php"]';
|
||||
|
||||
const htmlNode = doc.body.parentElement;
|
||||
const observer = new MutationObserver((mutations, observer)=>{
|
||||
for(const mutation of mutations)
|
||||
{
|
||||
const code = phpNode.innerText.trim();
|
||||
for(const addedNode of mutation.addedNodes)
|
||||
{
|
||||
if(!addedNode.matches || !addedNode.matches(phpSelector))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
runScriptTag(phpNode);
|
||||
runPhpScriptTag(addedNode.innerText);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(htmlNode, {childList: true, subtree: true});
|
||||
|
||||
const phpNodes = doc.querySelectorAll(phpSelector);
|
||||
|
||||
for(const phpNode of phpNodes)
|
||||
{
|
||||
const code = phpNode.innerText.trim();
|
||||
|
||||
runPhpScriptTag(phpNode);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user