From 2f2f8e2eda4410abd7b524a84ebd474b1305ee05 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 2 Jan 2024 23:57:38 +0000 Subject: [PATCH 01/29] [system] add a basic test, see #986 --- ext/system/test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ext/system/test.php diff --git a/ext/system/test.php b/ext/system/test.php new file mode 100644 index 000000000..170d3b08e --- /dev/null +++ b/ext/system/test.php @@ -0,0 +1,15 @@ +get_page("system"); + $this->assertEquals(PageMode::REDIRECT, $page->mode); + } +} From 1f9de8dd5ad3c2441d26dddf6e81ab57ba6d6e00 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 3 Jan 2024 03:45:06 +0000 Subject: [PATCH 02/29] more tests --- core/testcase.php | 6 ++++++ ext/download/main.php | 4 ---- ext/download/test.php | 16 ++++++++++++++++ ext/et_server/main.php | 1 - ext/et_server/test.php | 21 +++++++++++++++++++++ ext/image_view_counter/test.php | 23 +++++++++++++++++++++++ ext/image_view_counter/theme.php | 5 ++++- 7 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 ext/download/test.php create mode 100644 ext/et_server/test.php create mode 100644 ext/image_view_counter/test.php diff --git a/core/testcase.php b/core/testcase.php index f536e92b4..74cd686a9 100644 --- a/core/testcase.php +++ b/core/testcase.php @@ -161,6 +161,9 @@ protected function page_to_text(string $section = null): string } } + /** + * Assert that the page contains the given text somewhere in the blocks + */ protected function assert_text(string $text, string $section = null): void { $this->assertStringContainsString($text, $this->page_to_text($section)); @@ -171,6 +174,9 @@ protected function assert_no_text(string $text, string $section = null): void $this->assertStringNotContainsString($text, $this->page_to_text($section)); } + /** + * Assert that the page contains the given text somewhere in the binary data + */ protected function assert_content(string $content): void { global $page; diff --git a/ext/download/main.php b/ext/download/main.php index 52f428886..5bf5facc2 100644 --- a/ext/download/main.php +++ b/ext/download/main.php @@ -14,17 +14,13 @@ public function get_priority(): int return 99; } - public function onImageDownloading(ImageDownloadingEvent $event) { global $page; $page->set_mime($event->mime); - $page->set_mode(PageMode::FILE); - $page->set_file($event->path, $event->file_modified); - $event->stop_processing = true; } } diff --git a/ext/download/test.php b/ext/download/test.php new file mode 100644 index 000000000..b0ac2949e --- /dev/null +++ b/ext/download/test.php @@ -0,0 +1,16 @@ +post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->get_page("/image/$image_id"); + $this->assertEquals(PageMode::FILE, $page->mode); + } +} diff --git a/ext/et_server/main.php b/ext/et_server/main.php index c88ac6cc2..dbc314c6f 100644 --- a/ext/et_server/main.php +++ b/ext/et_server/main.php @@ -12,7 +12,6 @@ public function onPageRequest(PageRequestEvent $event) { global $database, $page, $user; if ($event->page_matches("register.php")) { - error_log("register.php"); if (isset($_POST["data"])) { $database->execute( "INSERT INTO registration(data) VALUES(:data)", diff --git a/ext/et_server/test.php b/ext/et_server/test.php new file mode 100644 index 000000000..9b80e6373 --- /dev/null +++ b/ext/et_server/test.php @@ -0,0 +1,21 @@ +post_page("register.php", ["data" => "test entry"]); + + $this->log_in_as_user(); + $this->get_page("register.php"); + $this->assert_no_text("test entry"); + + $this->log_in_as_admin(); + $this->get_page("register.php"); + $this->assert_text("test entry"); + } +} diff --git a/ext/image_view_counter/test.php b/ext/image_view_counter/test.php new file mode 100644 index 000000000..1722d1c5c --- /dev/null +++ b/ext/image_view_counter/test.php @@ -0,0 +1,23 @@ +post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->log_in_as_admin(); + $this->get_page("post/view/$image_id"); + $this->assert_text("Views"); + } + + public function testPopular() + { + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->get_page("popular_images"); + $this->assert_text("$image_id"); + } +} diff --git a/ext/image_view_counter/theme.php b/ext/image_view_counter/theme.php index d6c07f349..5ba946566 100644 --- a/ext/image_view_counter/theme.php +++ b/ext/image_view_counter/theme.php @@ -6,7 +6,10 @@ class ImageViewCounterTheme extends Themelet { - public function view_popular($images) + /** + * @param Image[] $images + */ + public function view_popular(array $images) { global $page, $config; $pop_images = ""; From 886b884bd6ea4f1d86e0edc42a05387f104fdbb6 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 3 Jan 2024 12:02:39 +0000 Subject: [PATCH 03/29] [image_view_counter] give post a view so it isn't null --- ext/image_view_counter/test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/image_view_counter/test.php b/ext/image_view_counter/test.php index 1722d1c5c..fc6e1c84d 100644 --- a/ext/image_view_counter/test.php +++ b/ext/image_view_counter/test.php @@ -17,6 +17,7 @@ public function testPostView() public function testPopular() { $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->get_page("post/view/$image_id"); $this->get_page("popular_images"); $this->assert_text("$image_id"); } From 49d2760ab65817acc77ff5cf739f67f3fee5729b Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 3 Jan 2024 14:47:58 +0000 Subject: [PATCH 04/29] happy new year --- core/basepage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/basepage.php b/core/basepage.php index f151e2f95..e23abbac6 100644 --- a/core/basepage.php +++ b/core/basepage.php @@ -615,7 +615,7 @@ protected function footer_html(): string Shimmie © Shish & The Team - 2007-2023, + 2007-2024, based on the Danbooru concept. $debug $contact From 61b28c50317fdc0e43d3c163d2184a7b57d68c8d Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 3 Jan 2024 15:08:41 +0000 Subject: [PATCH 05/29] [image] set thumb width / height as CSS varibles, see #938 --- ext/image/main.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ext/image/main.php b/ext/image/main.php index a0acad933..04cecd6d9 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -79,7 +79,12 @@ public function onDatabaseUpgrade(DatabaseUpgradeEvent $event) public function onPageRequest(PageRequestEvent $event) { - global $config; + global $config, $page; + + $thumb_width = $config->get_int(ImageConfig::THUMB_WIDTH, 192); + $thumb_height = $config->get_int(ImageConfig::THUMB_HEIGHT, 192); + $page->add_html_header(""); + if ($event->page_matches("image/delete")) { global $page, $user; if ($user->can(Permissions::DELETE_IMAGE) && isset($_POST['image_id']) && $user->check_auth_token()) { From c5c972fe9431e6959a23a55d6e248cacd1af848f Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 3 Jan 2024 15:30:20 +0000 Subject: [PATCH 06/29] [themes] use CSS variables + CSS grid to control image grid layouts, fixes #938 --- ext/index/style.css | 8 ++++++++ themes/danbooru/style.css | 7 ------- themes/danbooru2/style.css | 7 ------- themes/default/style.css | 7 ------- themes/rule34v2/style.css | 9 ++++----- themes/warm/style.css | 5 ----- 6 files changed, 12 insertions(+), 31 deletions(-) diff --git a/ext/index/style.css b/ext/index/style.css index 8fdee55d7..3bebb4bfa 100644 --- a/ext/index/style.css +++ b/ext/index/style.css @@ -7,3 +7,11 @@ text-align: left; margin: 0 10px 10px 0; } +.shm-image-list { + display: grid; + grid-template-columns: repeat( auto-fill, calc(var(--thumb-width) + 42px) ); + place-items: center; +} +.shm-image-list .thumb { + margin-bottom: 8px; +} diff --git a/themes/danbooru/style.css b/themes/danbooru/style.css index b912670b4..32946a14d 100644 --- a/themes/danbooru/style.css +++ b/themes/danbooru/style.css @@ -200,13 +200,6 @@ background:blue none repeat scroll 0 0; border:1px solid #EEEEEE; color:white; } -span.thumb { -display:inline-block; -float:left; -height:220px; -text-align:center; -width:220px; -} #pagelist { margin-top:32px; } diff --git a/themes/danbooru2/style.css b/themes/danbooru2/style.css index 70d23acd2..c649c2fd0 100644 --- a/themes/danbooru2/style.css +++ b/themes/danbooru2/style.css @@ -223,13 +223,6 @@ color:white; -moz-background-inline-policy:continuous; -moz-background-origin:padding; } -span.thumb { -display:inline-block; -float:left; -width:220px; -height:220px; -text-align:center; -} #pagelist { margin-top:32px; } diff --git a/themes/default/style.css b/themes/default/style.css index 4fad4fff5..6df2cdd58 100644 --- a/themes/default/style.css +++ b/themes/default/style.css @@ -210,12 +210,6 @@ ARTICLE TABLE { margin-top: 32px; } -.thumb { - width: 226px; - display: inline-block; - text-align: center; - margin-bottom: 8px; -} .thumb IMG { border: 1px solid var(--block-border); background: var(--block); @@ -223,4 +217,3 @@ ARTICLE TABLE { border-radius: 12px; box-shadow: 2px 2px 6px rgba(0,0,0,0.6); } - diff --git a/themes/rule34v2/style.css b/themes/rule34v2/style.css index 84a8ebe34..b685fb49f 100644 --- a/themes/rule34v2/style.css +++ b/themes/rule34v2/style.css @@ -195,13 +195,12 @@ SECTION>H3 { padding: 8px; } +.shm-image-list { + justify-items: center; + align-items: end; +} .thumb { - width: 226px; - display: inline-block; - zoom: 1; /* ie6 */ - *display: inline; /* ie6 */ text-align: center; - margin-bottom: 8px; } .thumb IMG { border: 1px solid #7EB977; diff --git a/themes/warm/style.css b/themes/warm/style.css index 894ea9d36..ae5e0c175 100644 --- a/themes/warm/style.css +++ b/themes/warm/style.css @@ -175,12 +175,7 @@ ARTICLE TABLE { } .thumb { - width: 226px; - display: inline-block; - zoom: 1; /* ie6 */ - *display: inline; /* ie6 */ text-align: center; - margin-bottom: 8px; } .thumb IMG { border: 1px solid #B89F7C; From febaa815f7321354a77afa7ccd3faef470c3036d Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 3 Jan 2024 15:51:22 +0000 Subject: [PATCH 07/29] [setup] wider forms on setup page --- ext/setup/main.php | 4 ++-- ext/setup/style.css | 6 ++++++ ext/wiki/main.php | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ext/setup/main.php b/ext/setup/main.php index 1587060e3..c942644d0 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -222,7 +222,7 @@ public function add_int_option(string $name, string $label = null, bool $table_r { $val = $this->config->get_int($name); - $html = "\n"; + $html = "\n"; $html .= "\n"; $this->format_option($name, $html, $label, $table_row); @@ -231,7 +231,7 @@ public function add_int_option(string $name, string $label = null, bool $table_r public function add_shorthand_int_option(string $name, string $label = null, bool $table_row = false) { $val = to_shorthand_int($this->config->get_int($name)); - $html = "\n"; + $html = "\n"; $html .= "\n"; $this->format_option($name, $html, $label, $table_row); diff --git a/ext/setup/style.css b/ext/setup/style.css index c8904a5b1..56d9a40fe 100644 --- a/ext/setup/style.css +++ b/ext/setup/style.css @@ -24,3 +24,9 @@ margin: 0; padding: 0; } +.setupblock .form { + width: 100%; +} +.setupblock .form TH { + font-weight: normal; +} \ No newline at end of file diff --git a/ext/wiki/main.php b/ext/wiki/main.php index 179eacfc9..671d0bb7e 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -135,9 +135,9 @@ public function onSetupBuilding(SetupBuildingEvent $event) { $sb = $event->panel->create_new_block("Wiki"); $sb->add_bool_option(WikiConfig::ENABLE_REVISIONS, "Enable wiki revisions: "); - $sb->add_longtext_option(WikiConfig::TAG_PAGE_TEMPLATE, "Tag page template: "); - $sb->add_text_option(WikiConfig::EMPTY_TAGINFO, "Empty list text: "); - $sb->add_bool_option(WikiConfig::TAG_SHORTWIKIS, "Show shortwiki entry when searching for a single tag: "); + $sb->add_longtext_option(WikiConfig::TAG_PAGE_TEMPLATE, "
Tag page template: "); + $sb->add_text_option(WikiConfig::EMPTY_TAGINFO, "
Empty list text: "); + $sb->add_bool_option(WikiConfig::TAG_SHORTWIKIS, "
Show shortwiki entry when searching for a single tag: "); } public function onDatabaseUpgrade(DatabaseUpgradeEvent $event) From 4066e6db81672cc450797337fd61c6686869078d Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 3 Jan 2024 23:54:03 +0000 Subject: [PATCH 08/29] Slightly better client-side tag blocking, fixes #802 --- ext/index/script.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/index/script.js b/ext/index/script.js index a599a97e1..bca2a9cda 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -1,14 +1,14 @@ /*jshint bitwise:false, curly:true, eqeqeq:true, evil:true, forin:false, noarg:true, noempty:true, nonew:true, undef:false, strict:false, browser:true, jquery:true */ document.addEventListener('DOMContentLoaded', () => { - var blocked_tags = (shm_cookie_get("ui-blocked-tags") || "").split(" "); - var needs_refresh = false; - for(var i=0; i tag.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")) + .map(tag => `.shm-thumb[data-tags~="${tag}"]`).join(", "); + if(blocked_css) { + let style = document.createElement("style"); + style.innerHTML = blocked_css + " { display: none; }"; + document.head.appendChild(style); } //Generate a random seed when using order:random From f4da2e92f0b328893ca275601dc45cd1078c48b0 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 3 Jan 2024 23:57:17 +0000 Subject: [PATCH 09/29] don't try blocking empty tag --- ext/index/script.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/index/script.js b/ext/index/script.js index bca2a9cda..1ee59f9f9 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -3,6 +3,7 @@ document.addEventListener('DOMContentLoaded', () => { let blocked_tags = (shm_cookie_get("ui-blocked-tags") || "").split(" "); let blocked_css = blocked_tags + .filter(tag => tag.length > 0) .map(tag => tag.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")) .map(tag => `.shm-thumb[data-tags~="${tag}"]`).join(", "); if(blocked_css) { From a3d7a05f710f2fd6f70281cc9b1fe2d89957498f Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 4 Jan 2024 00:15:08 +0000 Subject: [PATCH 10/29] move db setup to a script for easier re-use --- .github/workflows/tests.yml | 29 +---------------------------- tests/setup-db.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 28 deletions(-) create mode 100755 tests/setup-db.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 43a213284..889e7e845 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -85,25 +85,7 @@ jobs: extensions: mbstring - name: Set up database - run: | - mkdir -p data/config - if [[ "${{ matrix.database }}" == "pgsql" ]]; then - sudo systemctl start postgresql ; - psql --version ; - sudo -u postgres psql -c "SELECT set_config('log_statement', 'all', false);" -U postgres ; - sudo -u postgres psql -c "CREATE USER shimmie WITH PASSWORD 'shimmie';" -U postgres ; - sudo -u postgres psql -c "CREATE DATABASE shimmie WITH OWNER shimmie;" -U postgres ; - fi - if [[ "${{ matrix.database }}" == "mysql" ]]; then - sudo systemctl start mysql ; - mysql --version ; - mysql -e "SET GLOBAL general_log = 'ON';" -uroot -proot ; - mysql -e "CREATE DATABASE shimmie;" -uroot -proot ; - fi - if [[ "${{ matrix.database }}" == "sqlite" ]]; then - sudo apt update && sudo apt-get install -y sqlite3 ; - sqlite3 --version ; - fi + run: ./tests/setup-db.sh "${{ matrix.database }}" - name: Check versions run: php -v && composer -V @@ -116,15 +98,6 @@ jobs: - name: Run test suite run: | - if [[ "${{ matrix.database }}" == "pgsql" ]]; then - export TEST_DSN="pgsql:user=shimmie;password=shimmie;host=127.0.0.1;dbname=shimmie" - fi - if [[ "${{ matrix.database }}" == "mysql" ]]; then - export TEST_DSN="mysql:user=root;password=root;host=127.0.0.1;dbname=shimmie" - fi - if [[ "${{ matrix.database }}" == "sqlite" ]]; then - export TEST_DSN="sqlite:data/shimmie.sqlite" - fi if [[ "${{ matrix.php }}" == "8.3" ]]; then vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover else diff --git a/tests/setup-db.sh b/tests/setup-db.sh new file mode 100755 index 000000000..f3370c3bd --- /dev/null +++ b/tests/setup-db.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +DATABASE=$1 + +mkdir -p data/config + +if [[ "$DATABASE" == "pgsql" ]]; then + sudo systemctl start postgresql + psql --version + sudo -u postgres psql -c "SELECT set_config('log_statement', 'all', false);" -U postgres + sudo -u postgres psql -c "CREATE USER shimmie WITH PASSWORD 'shimmie';" -U postgres + sudo -u postgres psql -c "CREATE DATABASE shimmie WITH OWNER shimmie;" -U postgres + export TEST_DSN="pgsql:user=shimmie;password=shimmie;host=127.0.0.1;dbname=shimmie" +fi +if [[ "$DATABASE" == "mysql" ]]; then + sudo systemctl start mysql + mysql --version + mysql -e "SET GLOBAL general_log = 'ON';" -uroot -proot + mysql -e "CREATE DATABASE shimmie;" -uroot -proot + export TEST_DSN="mysql:user=root;password=root;host=127.0.0.1;dbname=shimmie" +fi +if [[ "$DATABASE" == "sqlite" ]]; then + sudo apt update && sudo apt-get install -y sqlite3 + sqlite3 --version + export TEST_DSN="sqlite:data/shimmie.sqlite" +fi + +if [[ -n "$GITHUB_ENV" ]]; then + echo "TEST_DSN=$TEST_DSN" >> $GITHUB_ENV +fi From 96f7293c71e0475482cf6fac30b67fea9627be50 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 4 Jan 2024 12:00:20 +0000 Subject: [PATCH 11/29] [dev] run composer install when devcontainer is started --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 968d7a846..68c51b012 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,7 +17,7 @@ // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [8000], - // Uncomment the next line to run commands after the container is created. + "updateContentCommand": "composer install", "postCreateCommand": "./.docker/entrypoint.sh unitd --no-daemon --control unix:/var/run/control.unit.sock", "containerEnv": { "UID": "2000", From 72a0d3f90b0f2e72d9ed4ae8391a6deeda026451 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 4 Jan 2024 11:58:15 +0000 Subject: [PATCH 12/29] [install] sqlite as the default DB --- core/install.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/core/install.php b/core/install.php index b18c14f84..8014bed62 100644 --- a/core/install.php +++ b/core/install.php @@ -114,9 +114,9 @@ function ask_questions() "; } + $db_s = in_array(DatabaseDriverID::SQLITE->value, $drivers) ? '' : ""; $db_m = in_array(DatabaseDriverID::MYSQL->value, $drivers) ? '' : ""; $db_p = in_array(DatabaseDriverID::PGSQL->value, $drivers) ? '' : ""; - $db_s = in_array(DatabaseDriverID::SQLITE->value, $drivers) ? '' : ""; $warn_msg = $warnings ? "

Warnings

".implode("\n

", $warnings) : ""; $err_msg = $errors ? "

Errors

".implode("\n

", $errors) : ""; @@ -132,9 +132,9 @@ function ask_questions() Type: @@ -161,13 +161,9 @@ function q(n) { return document.querySelectorAll(n); } function update_qs() { - Array.prototype.forEach.call(q('.dbconf'), function(el, i){ - el.style.display = 'none'; - }); + q('.dbconf').forEach(el => el.style.display = 'none'); let seldb = q("#database_type")[0].value || "none"; - Array.prototype.forEach.call(q('.'+seldb), function(el, i){ - el.style.display = null; - }); + q('.'+seldb).forEach(el => el.style.display = null); } @@ -178,8 +174,9 @@ function update_qs() { The username provided must have access to create tables within the database.

- For SQLite the database name will be a filename on disk, relative to - where shimmie was installed. + SQLite with default settings is fine for tens of users with thousands + of images. For thousands of users or millions of images, postgres is + recommended.

Drivers can generally be downloaded with your OS package manager; From e6116297fefd679c3ea261334781395721109cb3 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 4 Jan 2024 11:58:44 +0000 Subject: [PATCH 13/29] [dev] set INSTALL_DSN to get started faster --- .devcontainer/devcontainer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 68c51b012..1594d85b1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -23,6 +23,7 @@ "UID": "2000", "GID": "2000", "UPLOAD_MAX_FILESIZE": "50M", + "INSTALL_DSN": "sqlite:data/shimmie.dev.sqlite" }, "customizations": { "vscode": { From 4de08a7e01ea5dfea7989fbd9fac670e3c8767de Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 4 Jan 2024 12:15:29 +0000 Subject: [PATCH 14/29] [dev] one-click dev environment --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6db176276..d68483c8c 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ [![Code Coverage](https://scrutinizer-ci.com/g/shish/shimmie2/badges/coverage.png?b=main)](https://scrutinizer-ci.com/g/shish/shimmie2/?branch=main) [![Matrix](https://matrix.to/img/matrix-badge.svg)](https://matrix.to/#/#shimmie:matrix.org) +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/shish/shimmie2?quickstart=1) # Documentation From 9754e114e2b81ed9f5895746a100f731656c2863 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 4 Jan 2024 12:36:11 +0000 Subject: [PATCH 15/29] [docker] send error logs to stderr --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 3b391da1b..17b42fc81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,7 @@ RUN apt update && \ php${PHP_VERSION}-pgsql php${PHP_VERSION}-mysql php${PHP_VERSION}-sqlite3 php${PHP_VERSION}-curl \ curl imagemagick zip unzip unit unit-php gettext && \ rm -rf /var/lib/apt/lists/* +RUN ln -sf /dev/stderr /var/log/unit.log # Install dev packages # Things which are only needed during development - Composer has 100MB of From 0c31a11f9bd048b67c4463e80cb42b16d0b6c698 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 4 Jan 2024 13:12:41 +0000 Subject: [PATCH 16/29] [themes/danbooru2] dark mode, see #937 --- themes/danbooru2/style.css | 84 ++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 22 deletions(-) diff --git a/themes/danbooru2/style.css b/themes/danbooru2/style.css index c649c2fd0..be8301973 100644 --- a/themes/danbooru2/style.css +++ b/themes/danbooru2/style.css @@ -1,3 +1,45 @@ +:root { + --page: #FFFFFF; + --text: black; + + --link-first: #FF3333; + --link-default: #006FFA; + --link-hover: #33CFFF; + --link-header: black; + + --header-selected: #EEEEFF; + --footer-fg: #555555; + --tag-count: #AAAAAA; + --comment-meta: gray; + + --paginator-border: #EEEEEE; + --paginator-hover-bg: blue; + --paginator-hover-fg: white; + + --block-border: #AAAAAA; + + --zebra-heading-fg: #171BB3; + --zebra-hover-bg: #FFD; +} + +@media (prefers-color-scheme: dark) { + :root { + --page: #1E1E2C; + --text: #E8E8EC; + + --link-first: #FF5A5B; + --link-default: #009BE9; + + --header-selected: #2C2D3F; + + --paginator-hover-bg: #009BE9; + --paginator-hover-fg: white; + + --zebra-heading-fg: #E8E8EC; + --zebra-hover-bg: #2C2D3F; + } +} + .noleft{ padding-left:2rem; } @@ -25,18 +67,18 @@ padding:0.4rem 0.6rem; } HEADER ul#navbar li:first-child a { margin-left: -0.6rem; -color: #FF3333; +color: var(--link-first); font-weight: bold; } HEADER ul#navbar li a.current-page { -background-color:#EEEEFF; +background-color: var(--header-selected); border-radius:0.2rem 0.2rem 0 0; font-weight:bold; } HEADER ul#subnavbar { margin:0 0 0.5rem; padding:0 1rem 0 2rem; -background-color:#EEEEFF; +background-color: var(--header-selected); } HEADER ul#subnavbar li { display:inline-block; @@ -47,7 +89,8 @@ HEADER ul#subnavbar li:first-child { margin-left: -0.6rem; } body { -background-color:#FFFFFF; +background-color: var(--page); +color: var(--text); font-weight:normal; font-style:normal; font-variant:normal; @@ -64,7 +107,7 @@ padding:0.3rem; font-size:2.2rem; } h1 a { -color:black; +color: var(--link-header); } h3 { margin-top:0; @@ -79,8 +122,8 @@ h5 { font-size:1.2rem; } table.zebra {border-spacing: 0;border-collapse: collapse;} -table.zebra > tbody > tr:hover {background: #FFD;} -table.zebra th { padding-right: 0.4rem;color: #171BB3;} +table.zebra > tbody > tr:hover {background: var(--zebra-hover-bg);} +table.zebra th { padding-right: 0.4rem;color: var(--zebra-heading-fg);} table.zebra td {margin: 0;padding-right: 0.6rem;border: 1px dotted #EEE;} table.zebra th {margin: 0;text-align: left;} thead { @@ -111,7 +154,7 @@ clear:both; border-top:solid 1px #E7E7F7; margin-top:1rem; text-align:center; -color:#555555; +color: var(--footer-fg); font-size:0.8rem; } FOOTER > DIV { @@ -176,7 +219,7 @@ TABLE.tag_list>TBODY>TR>TD:after { .tag_count { display:inline-block; margin-left:0.4rem; -color:#AAAAAA; +color: var(--tag-count); } .more { content:"More â"; @@ -186,7 +229,7 @@ margin-bottom:8px; } .comment .meta { width: 15rem; -color: gray; +color: var(--comment-meta); } .comment TD { text-align: left; @@ -213,15 +256,12 @@ padding:4px 8px; div#paginator a { margin:3px; padding:4px 8px; -border:1px solid #EEEEEE; +border:1px solid var(--paginator-border); } div#paginator a:hover { -border:1px solid #EEEEEE; -background:blue none repeat scroll 0 0; -color:white; --moz-background-clip:border; --moz-background-inline-policy:continuous; --moz-background-origin:padding; +border:1px solid var(--paginator-border); +background: var(--paginator-hover-bg) none repeat scroll 0 0; +color:var(--paginator-hover-fg); } #pagelist { margin-top:32px; @@ -233,7 +273,7 @@ width:600px; margin:0.6rem 1rem 0.6rem 0; padding:0.5rem 0.6rem 0.7rem; width:18rem; -border:1px solid #AAAAAA; +border:1px solid var(--block-border); border-radius:0.25rem; display:inline-block; } @@ -278,19 +318,19 @@ padding:0; font-family:Tahoma,Verdana,Helvetica,sans-serif; } a:link { -color:#006FFA; +color: var(--link-default); text-decoration:none; } a:visited { -color:#006FFA; +color: var(--link-default); text-decoration:none; } a:hover { -color:#33CFFF; +color: var(--link-hover); text-decoration:none; } a:active { -color:#006FFA; +color: var(--link-default); text-decoration:none; } ul.flat-list { From 55d5dc0a35f3c504508142875a49444b610c95b6 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 4 Jan 2024 13:57:45 +0000 Subject: [PATCH 17/29] [themes] have themes implement head_html/body_html rather than render --- core/basepage.php | 57 ++++++++-------- core/microhtml.php | 9 +-- themes/danbooru/page.class.php | 45 ++++++------ themes/danbooru2/page.class.php | 11 +-- themes/futaba/page.class.php | 11 +-- themes/lite/page.class.php | 11 +-- themes/rule34v2/page.class.php | 117 ++++++++++++++++---------------- themes/warm/page.class.php | 11 +-- 8 files changed, 114 insertions(+), 158 deletions(-) diff --git a/core/basepage.php b/core/basepage.php index e23abbac6..e991a6ff1 100644 --- a/core/basepage.php +++ b/core/basepage.php @@ -6,6 +6,8 @@ use MicroHTML\HTMLElement; +use function MicroHTML\{emptyHTML,rawHTML,HTML,HEAD,BODY}; + require_once "core/event.php"; enum PageMode: string @@ -530,16 +532,17 @@ protected function get_nav_links(): array */ public function render() { - $head_html = $this->head_html(); - $body_html = $this->body_html(); + $head = $this->head_html(); + $body = $this->body_html(); - print << - - $head_html - $body_html - -EOD; + print emptyHTML( + rawHTML(""), + HTML( + ["lang" => "en"], + HEAD(rawHTML($head)), + BODY(rawHTML($body)) + ) + ); } protected function head_html(): string @@ -547,10 +550,8 @@ protected function head_html(): string $html_header_html = $this->get_all_html_headers(); return " - - {$this->title} - $html_header_html - + {$this->title} + $html_header_html "; } @@ -585,22 +586,20 @@ protected function body_html(): string $footer_html = $this->footer_html(); $flash_html = $this->flash ? "".nl2br(html_escape(implode("\n", $this->flash)))."" : ""; return " - -

- {$this->heading} - $sub_block_html -
- -
- $flash_html - $main_block_html -
-
- $footer_html -
- +
+ {$this->heading} + $sub_block_html +
+ +
+ $flash_html + $main_block_html +
+
+ $footer_html +
"; } diff --git a/core/microhtml.php b/core/microhtml.php index c7848900b..f3eb3681f 100644 --- a/core/microhtml.php +++ b/core/microhtml.php @@ -6,7 +6,7 @@ use MicroHTML\HTMLElement; -use function MicroHTML\emptyHTML; +use function MicroHTML\{emptyHTML}; use function MicroHTML\A; use function MicroHTML\FORM; use function MicroHTML\INPUT; @@ -16,12 +16,7 @@ use function MicroHTML\P; use function MicroHTML\SELECT; use function MicroHTML\SPAN; -use function MicroHTML\TABLE; -use function MicroHTML\THEAD; -use function MicroHTML\TFOOT; -use function MicroHTML\TR; -use function MicroHTML\TH; -use function MicroHTML\TD; +use function MicroHTML\{TABLE,THEAD,TFOOT,TR,TH,TD}; function SHM_FORM(string $target, string $method = "POST", bool $multipart = false, string $form_id = "", string $onsubmit = "", string $name = ""): HTMLElement { diff --git a/themes/danbooru/page.class.php b/themes/danbooru/page.class.php index 6ff8dba7f..d0bafacc4 100644 --- a/themes/danbooru/page.class.php +++ b/themes/danbooru/page.class.php @@ -50,7 +50,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ class Page extends BasePage { - public function render() + public function body_html(): string { global $config; @@ -123,33 +123,26 @@ public function render() } $flash_html = $this->flash ? "".nl2br(html_escape(implode("\n", $this->flash)))."" : ""; - $head_html = $this->head_html(); $footer_html = $this->footer_html(); - print << - - $head_html - -
- $title_link - - -
- $subheading - $sub_block_html - $left -
- $flash_html - $main_block_html -
-
$footer_html
- - + return << + $title_link + + + + $subheading + $sub_block_html + $left +
+ $flash_html + $main_block_html +
+
$footer_html
EOD; } diff --git a/themes/danbooru2/page.class.php b/themes/danbooru2/page.class.php index d34354a32..d714cbdac 100644 --- a/themes/danbooru2/page.class.php +++ b/themes/danbooru2/page.class.php @@ -51,7 +51,7 @@ class Page extends BasePage { - public function render() + public function body_html(): string { global $config; @@ -124,14 +124,9 @@ public function render() } $flash_html = $this->flash ? "".nl2br(html_escape(implode("\n", $this->flash)))."" : ""; - $head_html = $this->head_html(); $footer_html = $this->footer_html(); - print << - - $head_html - + return << $title_link