mirror of
https://github.com/vrana/adminer.git
synced 2025-08-08 15:47:00 +02:00
Plugins: Allow setting dark mode in css() (bug #1049)
This commit is contained in:
@@ -5,8 +5,9 @@
|
|||||||
- PostgreSQL, CockroachDB: Creating partitioned tables (bug #1031)
|
- PostgreSQL, CockroachDB: Creating partitioned tables (bug #1031)
|
||||||
- PostgreSQL: Move partitioned tables from table list to parent table
|
- PostgreSQL: Move partitioned tables from table list to parent table
|
||||||
- PostgreSQL: Support calling functions returning table (bug #1040)
|
- PostgreSQL: Support calling functions returning table (bug #1040)
|
||||||
- Designs: adminer.css with 'prefers-color-scheme: dark' don't disable dark mode
|
- Designs: adminer.css with 'prefers-color-scheme: dark' doesn't disable dark mode
|
||||||
- Plugins: Method bodyClass() to add <body class>
|
- Plugins: Method bodyClass() to add <body class>
|
||||||
|
- Plugins: Allow setting dark mode in css()
|
||||||
- Hindi translation
|
- Hindi translation
|
||||||
|
|
||||||
## Adminer 5.2.1 (released 2025-04-11)
|
## Adminer 5.2.1 (released 2025-04-11)
|
||||||
|
@@ -114,14 +114,18 @@ class Adminer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get URLs of the CSS files
|
/** Get URLs of the CSS files
|
||||||
* @return list<string>
|
* @return string[] key is URL, value is either 'light' (supports only light color scheme), 'dark' or '' (both)
|
||||||
*/
|
*/
|
||||||
function css(): array {
|
function css(): array {
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach (array("", "-dark") as $mode) {
|
foreach (array("", "-dark") as $mode) {
|
||||||
$filename = "adminer$mode.css";
|
$filename = "adminer$mode.css";
|
||||||
if (file_exists($filename)) {
|
if (file_exists($filename)) {
|
||||||
$return[] = "$filename?v=" . crc32(file_get_contents($filename));
|
$file = file_get_contents($filename);
|
||||||
|
$return["$filename?v=" . crc32($file)] = ($mode
|
||||||
|
? "dark"
|
||||||
|
: (preg_match('~prefers-color-scheme:\s*dark~', $file) ? '' : 'light')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
|
@@ -29,20 +29,11 @@ function page_header(string $title, string $error = "", $breadcrumb = array(), s
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$css = adminer()->css();
|
$css = adminer()->css();
|
||||||
$has_light = false;
|
if (is_int(key($css))) { // legacy return value
|
||||||
$has_dark = false;
|
$css = array_fill_keys($css, 'light');
|
||||||
foreach ($css as $url) {
|
|
||||||
if (strpos($url, "adminer.css") !== false) {
|
|
||||||
$has_light = true;
|
|
||||||
$filename = preg_replace('~\?.*~', '', $url);
|
|
||||||
if (!preg_match('~//~', $url) && is_readable($filename) && preg_match('~prefers-color-scheme:\s*dark~', file_get_contents($filename))) {
|
|
||||||
$has_dark = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (strpos($url, "adminer-dark.css") !== false) {
|
|
||||||
$has_dark = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$has_light = in_array('light', $css) || in_array('', $css);
|
||||||
|
$has_dark = in_array('dark', $css) || in_array('', $css);
|
||||||
$dark = ($has_light
|
$dark = ($has_light
|
||||||
? ($has_dark ? null : false) // both styles - autoswitching, only adminer.css - light
|
? ($has_dark ? null : false) // both styles - autoswitching, only adminer.css - light
|
||||||
: ($has_dark ?: null) // only adminer-dark.css - dark, neither - autoswitching
|
: ($has_dark ?: null) // only adminer-dark.css - dark, neither - autoswitching
|
||||||
@@ -60,8 +51,8 @@ function page_header(string $title, string $error = "", $breadcrumb = array(), s
|
|||||||
echo "<link rel='icon' href='data:image/gif;base64,R0lGODlhEAAQAJEAAAQCBPz+/PwCBAROZCH5BAEAAAAALAAAAAAQABAAAAI2hI+pGO1rmghihiUdvUBnZ3XBQA7f05mOak1RWXrNq5nQWHMKvuoJ37BhVEEfYxQzHjWQ5qIAADs='>\n";
|
echo "<link rel='icon' href='data:image/gif;base64,R0lGODlhEAAQAJEAAAQCBPz+/PwCBAROZCH5BAEAAAAALAAAAAAQABAAAAI2hI+pGO1rmghihiUdvUBnZ3XBQA7f05mOak1RWXrNq5nQWHMKvuoJ37BhVEEfYxQzHjWQ5qIAADs='>\n";
|
||||||
echo "<link rel='apple-touch-icon' href='../adminer/static/logo.png'>\n";
|
echo "<link rel='apple-touch-icon' href='../adminer/static/logo.png'>\n";
|
||||||
}
|
}
|
||||||
foreach ($css as $val) {
|
foreach ($css as $url => $mode) {
|
||||||
echo "<link rel='stylesheet'" . (preg_match('~-dark\.~', $val) && !$dark ? $media : "") . " href='" . h($val) . "'>\n";
|
echo "<link rel='stylesheet'" . ($mode == 'dark' && !$dark ? $media : "") . " href='" . h($url) . "'>\n";
|
||||||
}
|
}
|
||||||
echo "\n<body class='" . lang('ltr') . " nojs";
|
echo "\n<body class='" . lang('ltr') . " nojs";
|
||||||
adminer()->bodyClass();
|
adminer()->bodyClass();
|
||||||
|
@@ -79,7 +79,11 @@ class Adminer {
|
|||||||
foreach (array("", "-dark") as $mode) {
|
foreach (array("", "-dark") as $mode) {
|
||||||
$filename = "adminer$mode.css";
|
$filename = "adminer$mode.css";
|
||||||
if (file_exists($filename)) {
|
if (file_exists($filename)) {
|
||||||
$return[] = "$filename?v=" . crc32(file_get_contents($filename));
|
$file = file_get_contents($filename);
|
||||||
|
$return["$filename?v=" . crc32($file)] = ($mode
|
||||||
|
? "dark"
|
||||||
|
: (preg_match('~prefers-color-scheme:\s*dark~', $file) ? '' : 'light')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
|
@@ -27,7 +27,7 @@ class AdminerDesigns extends Adminer\Plugin {
|
|||||||
function css() {
|
function css() {
|
||||||
$return = array();
|
$return = array();
|
||||||
if (array_key_exists($_SESSION["design"], $this->designs)) {
|
if (array_key_exists($_SESSION["design"], $this->designs)) {
|
||||||
$return[] = $_SESSION["design"];
|
$return[$_SESSION["design"]] = (preg_match('~-dark~', $_SESSION["design"]) ? "dark" : "light");
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user