From 1abfa16fec630b0691704fed062c7b88bf911027 Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Fri, 20 Jan 2023 18:28:35 +0100 Subject: [PATCH 1/7] Fix indentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e869b50..aa6d213 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ To load the static cache files from PHP, please place the following code snippet return; } - // determine the exact file to use + // determine the exact file to use $path = $root . '/' . ltrim($_SERVER['REQUEST_URI'] ?? '', '/'); if (is_file($path . '/index.html') === true) { // a HTML representation exists in the cache @@ -271,7 +271,7 @@ Afterwards add the following block to your `.htaccess` file to make Apache use ` Replace the last line of the loader function with this code: ```php - // split the file into headers (before two line breaks) and body + // split the file into headers (before two line breaks) and body $file = file_get_contents($path); $divide = mb_strpos($file, "\n\n"); $headers = mb_substr($file, 0, $divide); From 0a9aca4bcdd3040550d1f4a688e3a66ab87d7445 Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Sat, 11 Mar 2023 13:17:00 +0100 Subject: [PATCH 2/7] Add notes on server setups with custom roots https://github.com/getkirby/staticache/issues/10 https://forum.getkirby.com/t/static-cache-with-public-folder-setup/27902 --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index aa6d213..47caa05 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,13 @@ return [ If you use a custom root and/or prefix, please modify the following server configuration examples accordingly. +If your custom root is outside of the server's document root, users have been successful with these solutions: + +- Create a symbolic link (symlink) from your custom root to a path inside the document root. Then use the path inside the document root in the server configuration. For this to work, the server needs to be set up to follow symlinks. +- In an Apache setup: Replace the `%{DOCUMENT_ROOT}` variable with the absolute path to your custom root on the server. E.g. `RewriteCond /var/www/yourPath/%{REQUEST_URI}/...` + +In any case, please ensure that your web server has read access to the cache files in your custom root, otherwise it will not be able to handle requests with the statically cached files. + ### Web server integration This plugin will automatically generate and store the cache files, however you need to configure your web server to pick the files up and prefer them over a dynamic result from PHP. From 26ca407b68a783964c8299004a1a872a05aff8f9 Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Sat, 11 Mar 2023 13:20:55 +0100 Subject: [PATCH 3/7] Gracefully handle plugin responses Not every ID maps to an existing page, so in this case the URL is dynamically constructed. Fixes #20. --- src/StatiCache.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/StatiCache.php b/src/StatiCache.php index 4674bc3..92374be 100644 --- a/src/StatiCache.php +++ b/src/StatiCache.php @@ -4,6 +4,7 @@ use Closure; use Kirby\Cms\App; +use Kirby\Cms\Url; use Kirby\Filesystem\F; use Kirby\Filesystem\Mime; use Kirby\Toolkit\Str; @@ -104,7 +105,7 @@ protected function file(string|array $key): string } $page = $kirby->page($key['id']); - $url = $page->url($key['language']); + $url = $page?->url($key['language']) ?? Url::to($key['id']); // content representation paths of the home page contain the home slug if ($page->isHomePage() === true && $key['contentType'] !== 'html') { From dda10d97abc962f0dce1448469737e52d34ad97e Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Sat, 11 Mar 2023 13:21:30 +0100 Subject: [PATCH 4/7] Update version number --- composer.json | 2 +- composer.lock | 84 ++++++++++++++++++++++++++------------------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index 010242d..bd5defc 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "kirby-plugin", "license": "MIT", "homepage": "https://getkirby.com/plugins/getkirby/staticache", - "version": "1.0.0", + "version": "1.0.1", "authors": [ { "name": "Bastian Allgeier", diff --git a/composer.lock b/composer.lock index 0965102..706c00a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d2638ad8e683618f06d1fecf6d4c5482", + "content-hash": "00c013e128893a3c7d7751d198ee7c2b", "packages": [ { "name": "claviska/simpleimage", - "version": "3.7.0", + "version": "3.7.2", "source": { "type": "git", "url": "https://github.com/claviska/SimpleImage.git", - "reference": "abd15ced313c7b8041d7d73d8d2398b4f2510cf1" + "reference": "82dbef988e356baa5d73993a1351bcb6c0959269" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/claviska/SimpleImage/zipball/abd15ced313c7b8041d7d73d8d2398b4f2510cf1", - "reference": "abd15ced313c7b8041d7d73d8d2398b4f2510cf1", + "url": "https://api.github.com/repos/claviska/SimpleImage/zipball/82dbef988e356baa5d73993a1351bcb6c0959269", + "reference": "82dbef988e356baa5d73993a1351bcb6c0959269", "shasum": "" }, "require": { @@ -45,7 +45,7 @@ "description": "A PHP class that makes working with images as simple as possible.", "support": { "issues": "https://github.com/claviska/SimpleImage/issues", - "source": "https://github.com/claviska/SimpleImage/tree/3.7.0" + "source": "https://github.com/claviska/SimpleImage/tree/3.7.2" }, "funding": [ { @@ -53,7 +53,7 @@ "type": "github" } ], - "time": "2022-07-05T13:18:44+00:00" + "time": "2022-12-12T14:31:53+00:00" }, { "name": "composer/semver", @@ -209,20 +209,20 @@ }, { "name": "getkirby/cms", - "version": "3.8.3", + "version": "3.9.2", "source": { "type": "git", "url": "https://github.com/getkirby/kirby.git", - "reference": "41719bd54310dfc2e321a75a8549da98ccf5cd1d" + "reference": "9ecd11cd5b7d4875d4212f767a2b3ad3e52b3528" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getkirby/kirby/zipball/41719bd54310dfc2e321a75a8549da98ccf5cd1d", - "reference": "41719bd54310dfc2e321a75a8549da98ccf5cd1d", + "url": "https://api.github.com/repos/getkirby/kirby/zipball/9ecd11cd5b7d4875d4212f767a2b3ad3e52b3528", + "reference": "9ecd11cd5b7d4875d4212f767a2b3ad3e52b3528", "shasum": "" }, "require": { - "claviska/simpleimage": "3.7.0", + "claviska/simpleimage": "3.7.2", "composer/semver": "3.3.2", "ext-ctype": "*", "ext-curl": "*", @@ -239,10 +239,10 @@ "getkirby/composer-installer": "^1.2.1", "laminas/laminas-escaper": "2.12.0", "michelf/php-smartypants": "1.8.1", - "php": ">=8.0.0 <8.2.0", - "phpmailer/phpmailer": "6.6.5", - "symfony/polyfill-intl-idn": "1.26.0", - "symfony/polyfill-mbstring": "1.26.0" + "php": ">=8.0.0 <8.3.0", + "phpmailer/phpmailer": "6.7.1", + "symfony/polyfill-intl-idn": "1.27.0", + "symfony/polyfill-mbstring": "1.27.0" }, "replace": { "symfony/polyfill-php72": "*" @@ -305,7 +305,7 @@ "type": "custom" } ], - "time": "2022-12-06T14:31:06+00:00" + "time": "2023-03-08T11:15:05+00:00" }, { "name": "getkirby/composer-installer", @@ -530,16 +530,16 @@ }, { "name": "phpmailer/phpmailer", - "version": "v6.6.5", + "version": "v6.7.1", "source": { "type": "git", "url": "https://github.com/PHPMailer/PHPMailer.git", - "reference": "8b6386d7417526d1ea4da9edb70b8352f7543627" + "reference": "49cd7ea3d2563f028d7811f06864a53b1f15ff55" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/8b6386d7417526d1ea4da9edb70b8352f7543627", - "reference": "8b6386d7417526d1ea4da9edb70b8352f7543627", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/49cd7ea3d2563f028d7811f06864a53b1f15ff55", + "reference": "49cd7ea3d2563f028d7811f06864a53b1f15ff55", "shasum": "" }, "require": { @@ -549,17 +549,19 @@ "php": ">=5.5.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", - "doctrine/annotations": "^1.2", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2", + "doctrine/annotations": "^1.2.6 || ^1.13.3", "php-parallel-lint/php-console-highlighter": "^1.0.0", "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9.3.5", "roave/security-advisories": "dev-latest", - "squizlabs/php_codesniffer": "^3.6.2", - "yoast/phpunit-polyfills": "^1.0.0" + "squizlabs/php_codesniffer": "^3.7.1", + "yoast/phpunit-polyfills": "^1.0.4" }, "suggest": { "ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses", + "ext-openssl": "Needed for secure SMTP sending and DKIM signing", + "greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication", "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", "league/oauth2-google": "Needed for Google XOAUTH2 authentication", "psr/log": "For optional PSR-3 debug logging", @@ -596,7 +598,7 @@ "description": "PHPMailer is a full-featured email creation and transfer class for PHP", "support": { "issues": "https://github.com/PHPMailer/PHPMailer/issues", - "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.6.5" + "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.7.1" }, "funding": [ { @@ -604,7 +606,7 @@ "type": "github" } ], - "time": "2022-10-07T12:23:10+00:00" + "time": "2022-12-08T13:30:06+00:00" }, { "name": "psr/log", @@ -658,16 +660,16 @@ }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.26.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "59a8d271f00dd0e4c2e518104cc7963f655a1aa8" + "reference": "639084e360537a19f9ee352433b84ce831f3d2da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/59a8d271f00dd0e4c2e518104cc7963f655a1aa8", - "reference": "59a8d271f00dd0e4c2e518104cc7963f655a1aa8", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/639084e360537a19f9ee352433b84ce831f3d2da", + "reference": "639084e360537a19f9ee352433b84ce831f3d2da", "shasum": "" }, "require": { @@ -681,7 +683,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -725,7 +727,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.27.0" }, "funding": [ { @@ -741,7 +743,7 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "symfony/polyfill-intl-normalizer", @@ -829,16 +831,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.26.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e" + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e", - "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", "shasum": "" }, "require": { @@ -853,7 +855,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -892,7 +894,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" }, "funding": [ { @@ -908,7 +910,7 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-11-03T14:55:06+00:00" } ], "packages-dev": [], From 6b1deb1d4987d1badc985d541edc39d624d76f2e Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Sun, 19 Mar 2023 13:01:19 +0100 Subject: [PATCH 5/7] Fix another use of `$page` --- src/StatiCache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StatiCache.php b/src/StatiCache.php index 92374be..2b99c90 100644 --- a/src/StatiCache.php +++ b/src/StatiCache.php @@ -108,7 +108,7 @@ protected function file(string|array $key): string $url = $page?->url($key['language']) ?? Url::to($key['id']); // content representation paths of the home page contain the home slug - if ($page->isHomePage() === true && $key['contentType'] !== 'html') { + if ($page?->isHomePage() === true && $key['contentType'] !== 'html') { $url .= '/' . $page->uri($key['language']); } From dbc9d0f85840862fd14cffbc0b73329af8a7df96 Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Sun, 19 Mar 2023 13:06:17 +0100 Subject: [PATCH 6/7] PHP loader: Try to determine the content type https://github.com/getkirby/staticache/pull/22#issuecomment-1466342398 --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 47caa05..f886928 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,11 @@ To load the static cache files from PHP, please place the following code snippet return; } + // try to determine the content type from the static file + if ($mime = @mime_content_type($path)) { + header("Content-Type: $mime"); + } + die(file_get_contents($path)); })(); ``` @@ -275,7 +280,7 @@ Afterwards add the following block to your `.htaccess` file to make Apache use ` **PHP loader:** -Replace the last line of the loader function with this code: +Replace the last six lines of the loader function with this code: ```php // split the file into headers (before two line breaks) and body From 4a4c130d4563e617f6142de095b1bc3a41af5985 Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Sun, 19 Mar 2023 15:21:39 +0100 Subject: [PATCH 7/7] Recommend header mode with PHP loader https://github.com/getkirby/staticache/pull/22#pullrequestreview-1347461717 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f886928..cdd24ff 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,8 @@ To load the static cache files from PHP, please place the following code snippet })(); ``` +If you want to use the PHP loader, we recommend to use it together with header support (see below). Storing the headers increases performance by a bit and also gives you more accurate responses. + ### Header support Staticache stores only the response bodies by default. The HTTP status code as well as headers set by your pages are not preserved in this mode. This ensures compatibility with all web servers.