Compare commits
10 Commits
cf07363a8d
...
543e44abc8
Author | SHA1 | Date | |
---|---|---|---|
543e44abc8 | |||
1443cfee12 | |||
0d17b5d474 | |||
3eed66b9a9 | |||
184e673277 | |||
83926b0f9a | |||
469ef7f5ea | |||
fbe7613f97 | |||
028a4b54f4 | |||
f54d35c312 |
7
.devcontainer/Caddyfile
Normal file
7
.devcontainer/Caddyfile
Normal file
@ -0,0 +1,7 @@
|
||||
:8080 {
|
||||
root * xxxxxxxxxx
|
||||
php_fastcgi 127.0.0.1:9000
|
||||
file_server
|
||||
|
||||
try_files {path} {path}/ /index.php?{query}
|
||||
}
|
23
.devcontainer/Dockerfile
Normal file
23
.devcontainer/Dockerfile
Normal file
@ -0,0 +1,23 @@
|
||||
FROM alpine:3.21
|
||||
|
||||
|
||||
RUN apk add --no-cache git curl php84 php84-fpm php84-opcache caddy php84-curl php84-xdebug chromium-chromedriver
|
||||
|
||||
ADD .devcontainer/start.sh /start.sh
|
||||
RUN chmod +x /start.sh
|
||||
|
||||
RUN apk add --no-cache php84-ctype php84-dom php84-fileinfo php84-gd php84-iconv php84-simplexml php84-xml php84-xmlreader php84-xmlwriter php84-zip php84-phar php84-openssl
|
||||
RUN curl -sS https://getcomposer.org/installer | /usr/bin/php84 -- --install-dir=/usr/bin --filename=composer
|
||||
|
||||
# caddy stuff
|
||||
ADD .devcontainer/Caddyfile /etc/caddy/Caddyfile
|
||||
RUN sed -i 's/nobody/caddy/g' /etc/php84/php-fpm.d/www.conf
|
||||
RUN sed -i 's/E_ALL \& ~E_DEPRECATED \& ~E_STRICT/E_ALL \& ~E_DEPRECATED \& ~E_STRICT \& ~E_NOTICE \& ~E_WARNING/g' /etc/php84/php.ini
|
||||
|
||||
# configure xdebug
|
||||
RUN echo "zend_extension=xdebug.so" > /etc/php84/conf.d/xdebug.ini
|
||||
RUN echo "xdebug.mode=debug" >> /etc/php84/conf.d/xdebug.ini
|
||||
RUN echo "xdebug.start_with_request=yes" >> /etc/php84/conf.d/xdebug.ini
|
||||
RUN echo "xdebug.client_host=127.0.0.1" >> /etc/php84/conf.d/xdebug.ini
|
||||
RUN echo "xdebug.client_port=9003" >> /etc/php84/conf.d/xdebug.ini
|
||||
RUN echo "xdebug.idekey=VSCODE" >> /etc/php84/conf.d/xdebug.ini
|
35
.devcontainer/devcontainer.json
Normal file
35
.devcontainer/devcontainer.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "Web Project Dev Container",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"context": ".."
|
||||
},
|
||||
"forwardPorts": [8080],
|
||||
"postCreateCommand": "/start.sh",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"terminal.integrated.shell.linux": "/bin/ash",
|
||||
"php.validate.executablePath": "/usr/bin/php",
|
||||
"php.debug.listenPort": 9003,
|
||||
"php.debug.log": true
|
||||
},
|
||||
"extensions": [
|
||||
"ms-azuretools.vscode-docker",
|
||||
"felixfbecker.php-debug",
|
||||
"bmewburn.vscode-intelephense-client",
|
||||
"otovo-oss.htmx-tags",
|
||||
"devsense.phptools-vscode",
|
||||
"bmewburn.vscode-intelephense-client",
|
||||
"github.copilot",
|
||||
"github.copilot-chat",
|
||||
"anbuselvanrocky.bootstrap5-vscode",
|
||||
"hansuxdev.bootstrap5-snippets",
|
||||
"alefragnani.Bookmarks",
|
||||
"eamodio.gitlens"
|
||||
]
|
||||
}
|
||||
},
|
||||
"remoteUser": "root"
|
||||
}
|
||||
|
24
.devcontainer/start.sh
Normal file
24
.devcontainer/start.sh
Normal file
@ -0,0 +1,24 @@
|
||||
WORKSPACE_PATH=$( pwd )
|
||||
# Escape the path for safe use in sed
|
||||
ESCAPED_PATH=$(echo "$WORKSPACE_PATH" | sed 's/\//\\\//g')
|
||||
|
||||
echo "[!] Folder is $WORKSPACE_PATH"
|
||||
|
||||
echo ' [+] Starting php'
|
||||
php-fpm83
|
||||
|
||||
echo ' [+] Starting Caddy'
|
||||
sed -i "s|xxxxxxxxxx|$ESCAPED_PATH\/web|g" /etc/caddy/Caddyfile
|
||||
|
||||
cd ${WORKSPACE_PATH}/src
|
||||
composer install
|
||||
|
||||
echo ' [+] Starting Chrome'
|
||||
cd /tmp
|
||||
nohup chromedriver --port=4444 &
|
||||
|
||||
|
||||
chmod 777 ${WORKSPACE_PATH}/cache
|
||||
chmod 777 ${WORKSPACE_PATH}/logs
|
||||
|
||||
caddy start --config /etc/caddy/Caddyfile
|
49
.gitea/workflows/build-docker.yml
Executable file
49
.gitea/workflows/build-docker.yml
Executable file
@ -0,0 +1,49 @@
|
||||
name: Build Container
|
||||
run-name: ${{ gitea.actor }} is pushing
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
env:
|
||||
REGISTRY: gitea.haschek.at
|
||||
IMAGE_NAME: ${{ gitea.repository }}
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "🎉 Building ${{ gitea.repository }} because of a ${{ gitea.event_name }} event."
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
type=sha
|
||||
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.BUILD_TOKEN}}
|
||||
|
||||
- name: Build
|
||||
uses: docker/build-push-action@v3
|
||||
env:
|
||||
ACTIONS_RUNTIME_TOKEN: ''
|
||||
with:
|
||||
context: .
|
||||
file: docker/Dockerfile
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
|
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Listen for Xdebug",
|
||||
"type": "php",
|
||||
"request": "launch",
|
||||
"port": 9003
|
||||
}
|
||||
]
|
||||
}
|
18
docker-compose-dev.yml
Normal file
18
docker-compose-dev.yml
Normal file
@ -0,0 +1,18 @@
|
||||
version: '3.3'
|
||||
services:
|
||||
http2pic:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/Dockerfile
|
||||
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./cache:/srv/cache
|
||||
- ./src:/srv/src
|
||||
- ./web:/srv/web
|
||||
- ./logs:/srv/logs
|
||||
|
||||
environment:
|
||||
- URL=http://localhost:8080
|
||||
ports:
|
||||
- 8080:80
|
10
docker-compose.yml
Normal file
10
docker-compose.yml
Normal file
@ -0,0 +1,10 @@
|
||||
version: '3.3'
|
||||
services:
|
||||
http2pic:
|
||||
image: ghcr.io/hascheksolutions/http2pic:2
|
||||
restart: unless-stopped
|
||||
|
||||
environment:
|
||||
- URL=http://localhost:8080
|
||||
ports:
|
||||
- 8080:80
|
9
docker/Caddyfile
Normal file → Executable file
9
docker/Caddyfile
Normal file → Executable file
@ -1,5 +1,12 @@
|
||||
:80 {
|
||||
root * /srv
|
||||
root * /srv/web
|
||||
php_fastcgi 127.0.0.1:9000
|
||||
file_server
|
||||
|
||||
log {
|
||||
output file /srv/logs/web.error.log
|
||||
level ERROR
|
||||
}
|
||||
|
||||
try_files {path} {path}/ /index.php?{query}
|
||||
}
|
29
docker/Dockerfile
Normal file → Executable file
29
docker/Dockerfile
Normal file → Executable file
@ -1,16 +1,31 @@
|
||||
FROM ghcr.io/surnet/alpine-wkhtmltopdf:3.20.3-0.12.6-full
|
||||
FROM alpine:3.21
|
||||
|
||||
# Install PHP and necessary extensions
|
||||
RUN apk add --no-cache php83 php83-fpm php83-opcache caddy php83-curl
|
||||
RUN apk add --no-cache curl php84 php84-fpm php84-opcache caddy php84-curl php84-xdebug chromium-chromedriver
|
||||
|
||||
RUN sed -i 's/nobody/caddy/g' /etc/php83/php-fpm.d/www.conf
|
||||
RUN sed -i 's/E_ALL \& ~E_DEPRECATED \& ~E_STRICT/E_ALL \& ~E_DEPRECATED \& ~E_STRICT \& ~E_NOTICE \& ~E_WARNING/g' /etc/php83/php.ini
|
||||
RUN sed -i 's/nobody/caddy/g' /etc/php84/php-fpm.d/www.conf
|
||||
RUN sed -i 's/E_ALL \& ~E_DEPRECATED \& ~E_STRICT/E_ALL \& ~E_DEPRECATED \& ~E_STRICT \& ~E_NOTICE \& ~E_WARNING/g' /etc/php84/php.ini
|
||||
# log php errors to /srv/logs/php_errors.log
|
||||
RUN echo "error_log = /srv/logs/php_errors.log" >> /etc/php84/php.ini
|
||||
|
||||
# Install additional PHP extensions
|
||||
RUN apk add --no-cache php84-ctype php84-dom php84-fileinfo php84-gd php84-iconv php84-simplexml php84-xml php84-xmlreader php84-xmlwriter php84-zip php84-phar php84-openssl
|
||||
RUN curl -sS https://getcomposer.org/installer | /usr/bin/php84 -- --install-dir=/usr/bin --filename=composer
|
||||
|
||||
ADD docker/start.sh /start.sh
|
||||
RUN chmod +x /start.sh
|
||||
|
||||
# Copy the contents of the web/ directory to /srv
|
||||
COPY web/ /srv
|
||||
ADD . /srv
|
||||
|
||||
# Cleanup
|
||||
RUN rm -rf /srv/.git
|
||||
RUN rm -rf /srv/.github
|
||||
RUN rm -rf /srv/.vscode
|
||||
|
||||
|
||||
# Copy the Caddyfile to the container
|
||||
COPY docker/Caddyfile /etc/caddy/Caddyfile
|
||||
|
||||
# Set the default command to start PHP-FPM and Caddy
|
||||
CMD ["sh", "-c", "php-fpm83 && caddy run --config /etc/caddy/Caddyfile"]
|
||||
# Run start script
|
||||
CMD ["sh", "-c", "/start.sh"]
|
||||
|
25
docker/start.sh
Executable file
25
docker/start.sh
Executable file
@ -0,0 +1,25 @@
|
||||
|
||||
echo ' [+] Starting php'
|
||||
php-fpm84
|
||||
|
||||
cd /srv/src
|
||||
composer install
|
||||
|
||||
echo ' [+] Starting Chrome'
|
||||
chromedriver --port=4444 &
|
||||
|
||||
|
||||
chmod 777 /srv/cache
|
||||
chmod 777 /srv/logs
|
||||
|
||||
echo ' [+] Building config'
|
||||
_buildConfig() {
|
||||
echo "<?php"
|
||||
echo "date_default_timezone_set('Europe/Vienna');"
|
||||
echo "define('URL','${URL:-http://localhost:8080}');"
|
||||
echo ""
|
||||
}
|
||||
|
||||
_buildConfig > src/inc/config.inc.php
|
||||
|
||||
caddy run --config /etc/caddy/Caddyfile
|
2
logs/.gitignore
vendored
Executable file
2
logs/.gitignore
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
1
src/.gitignore
vendored
Normal file
1
src/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
vendor/
|
5
src/composer.json
Normal file
5
src/composer.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"require": {
|
||||
"php-webdriver/webdriver": "^1.15"
|
||||
}
|
||||
}
|
226
src/composer.lock
generated
Normal file
226
src/composer.lock
generated
Normal file
@ -0,0 +1,226 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "9c8ecf7ef31de7c4a3608d683b57a301",
|
||||
"packages": [
|
||||
{
|
||||
"name": "php-webdriver/webdriver",
|
||||
"version": "1.15.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-webdriver/php-webdriver.git",
|
||||
"reference": "998e499b786805568deaf8cbf06f4044f05d91bf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/998e499b786805568deaf8cbf06f4044f05d91bf",
|
||||
"reference": "998e499b786805568deaf8cbf06f4044f05d91bf",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-zip": "*",
|
||||
"php": "^7.3 || ^8.0",
|
||||
"symfony/polyfill-mbstring": "^1.12",
|
||||
"symfony/process": "^5.0 || ^6.0 || ^7.0"
|
||||
},
|
||||
"replace": {
|
||||
"facebook/webdriver": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"ergebnis/composer-normalize": "^2.20.0",
|
||||
"ondram/ci-detector": "^4.0",
|
||||
"php-coveralls/php-coveralls": "^2.4",
|
||||
"php-mock/php-mock-phpunit": "^2.0",
|
||||
"php-parallel-lint/php-parallel-lint": "^1.2",
|
||||
"phpunit/phpunit": "^9.3",
|
||||
"squizlabs/php_codesniffer": "^3.5",
|
||||
"symfony/var-dumper": "^5.0 || ^6.0 || ^7.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-SimpleXML": "For Firefox profile creation"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"lib/Exception/TimeoutException.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Facebook\\WebDriver\\": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "A PHP client for Selenium WebDriver. Previously facebook/webdriver.",
|
||||
"homepage": "https://github.com/php-webdriver/php-webdriver",
|
||||
"keywords": [
|
||||
"Chromedriver",
|
||||
"geckodriver",
|
||||
"php",
|
||||
"selenium",
|
||||
"webdriver"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/php-webdriver/php-webdriver/issues",
|
||||
"source": "https://github.com/php-webdriver/php-webdriver/tree/1.15.2"
|
||||
},
|
||||
"time": "2024-11-21T15:12:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.31.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341",
|
||||
"reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/polyfill",
|
||||
"name": "symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-09-09T11:45:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/process",
|
||||
"version": "v7.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/process.git",
|
||||
"reference": "d34b22ba9390ec19d2dd966c40aa9e8462f27a7e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/process/zipball/d34b22ba9390ec19d2dd966c40aa9e8462f27a7e",
|
||||
"reference": "d34b22ba9390ec19d2dd966c40aa9e8462f27a7e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.2"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Process\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Executes commands in sub-processes",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/process/tree/v7.2.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-11-06T14:24:19+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {},
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
<?php
|
||||
|
||||
define('URL','http://localhost:8081');
|
||||
define('URL','http://localhost:8080');
|
@ -27,7 +27,7 @@ define('ONDOMAINFAILIMAGE', __DIR__.'/img/domainfailed.jpg');
|
||||
define('RENDERINGENGINE','wkhtmltoimage');
|
||||
|
||||
//location of wkhtmltoimage
|
||||
define('WKHTMLTOIMAGEPATH','/usr/sbin/wkhtmltoimage');
|
||||
define('WKHTMLTOIMAGEPATH','wkhtmltoimage');
|
||||
|
||||
//location of phantomJS
|
||||
define('PHANTOMJSPATH',__DIR__.'/phantomjs');
|
||||
@ -143,46 +143,7 @@ class http2pic
|
||||
|
||||
function render()
|
||||
{
|
||||
//if phantomjs is selected and installed
|
||||
if(RENDERINGENGINE=='phantomjs' && file_exists(PHANTOMJSPATH))
|
||||
return $this->renderPagePHANTOMJS();
|
||||
|
||||
//no? well ok how about WKHTMLToImage?
|
||||
else if(RENDERINGENGINE=='wkhtmltoimage' && file_exists(WKHTMLTOIMAGEPATH))
|
||||
return $this->renderPageWKHTMLTOIMAGE();
|
||||
|
||||
//you're fucked
|
||||
else
|
||||
throw new Exception('No valid rendering engine found');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render using PhantomJS
|
||||
**/
|
||||
function renderPagePHANTOMJS()
|
||||
{
|
||||
$cmd = 'timeout '.$this->params['timeout'].' '.PHANTOMJSPATH;
|
||||
$cmd.= ' --ignore-ssl-errors=yes --ssl-protocol=any '.__DIR__.'/phantom.js ';
|
||||
|
||||
$cmd.= ($this->params['url']);
|
||||
$cmd.= ','.($this->params['file']);
|
||||
$cmd.= ','.$this->params['vp_w'];
|
||||
$cmd.= ','.$this->params['vp_h'];
|
||||
$cmd.= ','.$this->params['js'];
|
||||
|
||||
$cmd = escapeshellcmd($cmd);
|
||||
shell_exec($cmd);
|
||||
$this->params['cmd'] = $cmd;
|
||||
|
||||
$this->postRender();
|
||||
if(DEBUG)
|
||||
{
|
||||
$fp = fopen('debug.log', 'a');
|
||||
fwrite($fp, $cmd."\n");
|
||||
fclose($fp);
|
||||
}
|
||||
return $cmd;
|
||||
return $this->renderPageWKHTMLTOIMAGE();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,6 +175,10 @@ class http2pic
|
||||
|
||||
//add storage path to cmd
|
||||
$cmd.=' '.escapeshellarg($this->params['file']);
|
||||
|
||||
$cmd.=' --wait-for-network-idle';
|
||||
|
||||
var_dump($cmd);
|
||||
|
||||
$cmd = escapeshellcmd($cmd);
|
||||
shell_exec($cmd);
|
||||
@ -241,7 +206,8 @@ class http2pic
|
||||
// resize if necessary
|
||||
if($this->params['resizewidth'])
|
||||
$this->resizeImage($this->params['file']);
|
||||
|
||||
|
||||
if(!file_exists($this->params['file'])) exit("Error: File not found");
|
||||
|
||||
//print image to user
|
||||
if ($this->params['type'] === 'png') {
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
<!-- Page Header -->
|
||||
<!-- Set your background image for this header on the line below. -->
|
||||
<header id="intro-header" class="intro-header" style="background-image: url('img/home-bg.jpg')">
|
||||
<header id="intro-header" class="intro-header" style="background-image: url('/img/home-bg.jpg')">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||
@ -58,7 +58,7 @@
|
||||
<h1 style="text-shadow: 0px 0px 12px #000000;">http2pic</h1>
|
||||
<h2 id="loading"><img src="img/loading.gif" /><br/>Loading..</h2>
|
||||
<hr class="small">
|
||||
<span style="text-shadow: 0px 0px 12px #000000;" class="subheading">Give it a try! <input id="showcase_url" type="url" placeholder="eg. http://xkcd.com" />
|
||||
<span style="text-shadow: 0px 0px 12px #000000;" class="subheading">Give it a try! <input id="showcase_url" type="url" placeholder="eg. http://xkcd.com" value="https://xkcd.com" />
|
||||
<input id="showcase_button" type="button" value="GO" /></div>
|
||||
</div>
|
||||
</div>
|
||||
@ -71,7 +71,7 @@
|
||||
<!-- Main Content -->
|
||||
<div class="container">
|
||||
<h2>How the API works</h2>
|
||||
<div class="well"><h2 ><?=URL?>/api.php?<span style="color:#C73C49">[OPTIONS]</span>&url=<span style="color:#1e90ff">[WEBSITE_URL]</span></h2></div><hr/><br/>
|
||||
<div class="well"><h2 ><?=URL?>/api/url=<span style="color:#1e90ff">[WEBSITE_URL]</span>&<span style="color:#C73C49">[OPTIONS]</span></h2></div><hr/><br/>
|
||||
<div >
|
||||
<div>
|
||||
<section>
|
||||
@ -90,12 +90,6 @@
|
||||
<td>The URL of the webpage you'd like to take a screenshot of. Make sure to encode the URL!</td>
|
||||
<td>url=http://xkcd.com</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>width</td>
|
||||
<td>WIDTH</td>
|
||||
<td>Resizes the screenshot to a specified maximum width. Default value is the original size</td>
|
||||
<td>width=400</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>viewport</td>
|
||||
<td>WIDTHxHEIGHT</td>
|
||||
@ -104,33 +98,9 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>js</td>
|
||||
<td>yes|no</td>
|
||||
<td>true|false</td>
|
||||
<td>Allows you to enable/disable JavaScript in the rendered Website. Default value: yes</td>
|
||||
<td>js=yes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>type</td>
|
||||
<td>jpg|png</td>
|
||||
<td>Sets the output file format of the rendered screenshot. Default value: jpg</td>
|
||||
<td>type=png</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onfail</td>
|
||||
<td>[url of .jpg]</td>
|
||||
<td>If the page can't be reached, this image will be displayed instead</td>
|
||||
<td><?=URL?>/img/pagefailed.jpg</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ondomainfail</td>
|
||||
<td>[url of .jpg]</td>
|
||||
<td>If the web server can't be reached, this image will be displayed instead</td>
|
||||
<td><?=URL?>/img/domainfailed.jpg</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>cache</td>
|
||||
<td>[any alphanumeric string]</td>
|
||||
<td>If provided, caches the rendered image (based on the URL) so it loads faster on next request. The same cache id with the same url will return the cached image. Change cache id to re-render</td>
|
||||
<td>f01d0</td>
|
||||
<td>js=false</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -146,11 +116,10 @@
|
||||
<pre><code class="php">
|
||||
<?php
|
||||
$url = 'http://www.xkcd.com';
|
||||
$query = 'type=jpg&viewport=1200x330&url='.rawurlencode($url);
|
||||
$img="<?=URL?>/api.php?$query";
|
||||
$query = 'viewport=1200x330&url='.rawurlencode($url);
|
||||
$img="<?=URL?>/api/?$query";
|
||||
|
||||
echo "<img src='$img' />";
|
||||
?>
|
||||
</code></pre>
|
||||
</p>
|
||||
|
||||
@ -161,7 +130,7 @@
|
||||
<pre><code class="php">
|
||||
<?php
|
||||
$targeturl = 'http://www.xkcd.com';
|
||||
$url = '<?=URL?>/api.php?url='.rawurlencode($targeturl);
|
||||
$url = '<?=URL?>/api/?url='.rawurlencode($targeturl);
|
||||
|
||||
$ch = curl_init($url);
|
||||
$fp = fopen('xkcd.jpg', 'wb');
|
||||
@ -170,7 +139,6 @@
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
fclose($fp);
|
||||
?>
|
||||
</code></pre>
|
||||
</p>
|
||||
</section>
|
||||
|
23
web/api.php
23
web/api.php
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
include_once(ROOT.DS.'src'.DS.'http2pic.class.php');
|
||||
|
||||
$url = $_GET['url'];
|
||||
$type = $_GET['type'];
|
||||
$timeout = $_GET['timeout'];
|
||||
$viewport = $_GET['viewport'];
|
||||
$js = $_GET['js'];
|
||||
$resizewidth = $_GET['width'];
|
||||
$cache = $_GET['cache'];
|
||||
$onfail = rawurldecode($_GET['onfail']);
|
||||
|
||||
$params = array('url'=>trim($url),
|
||||
'type'=>$type,
|
||||
'timeout'=>$timeout,
|
||||
'viewport'=>$viewport,
|
||||
'js'=>$js,
|
||||
'resizewidth'=>$resizewidth,
|
||||
'cache'=>$cache,
|
||||
'onfail'=>$onfail);
|
||||
|
||||
$http2pic = new http2pic($params);
|
||||
//echo nl2br(print_r($http2pic->debug(),true));
|
@ -1,10 +1,14 @@
|
||||
<?php
|
||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
||||
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
define('ROOT', dirname(__FILE__).DS.'..');
|
||||
|
||||
require_once(ROOT.DS.'src'.DS.'config.inc.php');
|
||||
require_once(ROOT.DS.'src'.DS.'helpers.php');
|
||||
require_once(ROOT.DS.'src'.DS.'http2pic.class.php');
|
||||
require_once(ROOT.DS.'src'.DS.'vendor'.DS.'autoload.php');
|
||||
|
||||
$url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/')));
|
||||
|
||||
@ -16,30 +20,55 @@ if(php_sapi_name()=='cli-server' && file_exists(ROOT.DS.'web'.DS.implode('/',$ur
|
||||
switch($url[0])
|
||||
{
|
||||
case 'api':
|
||||
$url = $_GET['url'];
|
||||
$type = $_GET['type'];
|
||||
$timeout = $_GET['timeout'];
|
||||
$viewport = $_GET['viewport'];
|
||||
$js = $_GET['js'];
|
||||
$resizewidth = $_GET['width'];
|
||||
$cache = $_GET['cache'];
|
||||
$onfail = rawurldecode($_GET['onfail']);
|
||||
$target = substr($_SERVER['REQUEST_URI'],5);
|
||||
if(!$target || !filter_var($target, FILTER_VALIDATE_URL))
|
||||
$target = $_REQUEST['url'];
|
||||
if(!filter_var($target, FILTER_VALIDATE_URL))
|
||||
{
|
||||
header('HTTP/1.0 400 Bad Request');
|
||||
echo 'Invalid URL';
|
||||
exit;
|
||||
}
|
||||
$viewport = $_REQUEST['viewport'];
|
||||
$js = $_REQUEST['js']=='false'?false:true;
|
||||
|
||||
$params = array('url'=>trim($url),
|
||||
'type'=>$type,
|
||||
'timeout'=>$timeout,
|
||||
'viewport'=>$viewport,
|
||||
'js'=>$js,
|
||||
'resizewidth'=>$resizewidth,
|
||||
'cache'=>$cache,
|
||||
'onfail'=>$onfail);
|
||||
$serverUrl = 'http://localhost:4444';
|
||||
$options = new \Facebook\WebDriver\Chrome\ChromeOptions();
|
||||
$options->addArguments(['--headless', '--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage']);
|
||||
|
||||
$capabilities = DesiredCapabilities::chrome();
|
||||
$capabilities->setCapability(\Facebook\WebDriver\Chrome\ChromeOptions::CAPABILITY, $options);
|
||||
|
||||
$http2pic = new http2pic($params);
|
||||
|
||||
break;
|
||||
case 'img':
|
||||
|
||||
break;
|
||||
//disable javascript if $js is false
|
||||
if(!$js)
|
||||
$capabilities->setCapability('javascriptEnabled', false);
|
||||
|
||||
$driver = RemoteWebDriver::create($serverUrl, $capabilities);
|
||||
|
||||
$driver->get($target);
|
||||
|
||||
//hide scroll bars
|
||||
$driver->executeScript('document.body.style.overflow = "hidden";');
|
||||
|
||||
//set screenshot size to 1920x1080
|
||||
//$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension(1024, 768));
|
||||
//if $viewport is set, set window size
|
||||
if($viewport)
|
||||
{
|
||||
$viewport = explode('x',$viewport);
|
||||
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($viewport[0], $viewport[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension(1024, 768));
|
||||
}
|
||||
|
||||
// take screenshot and save to file
|
||||
//header for png
|
||||
header('Content-Type: image/png');
|
||||
echo $driver->takeScreenshot();
|
||||
|
||||
break;
|
||||
default:
|
||||
echo renderTemplate('index.html.php');
|
||||
break;
|
||||
|
@ -3,7 +3,8 @@ $(function() {
|
||||
{
|
||||
$("#showcase_button").attr("disabled","true");
|
||||
var urlenc = encodeURIComponent(url);
|
||||
var imageURL = "api.php?js=no&cache=1&viewport=1200x330&url="+urlenc;
|
||||
var host = location.protocol + '//' + location.host;
|
||||
var imageURL = host+"/api/?js=false&viewport=1200x330&url="+urlenc;
|
||||
//$("#intro-header").css('background-image', 'url(\'/img/loading.gif\')');
|
||||
|
||||
$("#loading").show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user