-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimagefields.php
More file actions
51 lines (43 loc) · 1.7 KB
/
imagefields.php
File metadata and controls
51 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Imagefields plugin for Adminer.
*
* @link https://github.com/vlgalik/adminer-imagefields
* @author Ladislav Galik, https://galik.it
*/
class AdminerImagefields
{
private $width, $height, $url;
function __construct($width = 200, $height = 200, $url = false) {
$this->width = $width;
$this->height = $height;
$this->url = $url;
}
function head(?bool $dark = null): bool {
echo sprintf('<script %s>', Adminer\nonce());
echo sprintf("
(function () {
document.addEventListener('DOMContentLoaded', function (e) {
const links = document.querySelectorAll('.scrollable table tbody a');
const re = /^.*\.(jpg|jpeg|png|gif)(\?.*)?$/
for (let i = 0; i < links.length; i++) {
if (re.test(links[i].href)) {
const img = document.createElement('img');
img.src = links[i].href;
img.alt = links[i].href;
img.style.display = 'block';
img.style.maxWidth = '%spx';
img.style.maxHeight = '%spx';
img.addEventListener('load', function (image) {
%s
links[this].insertBefore(image, links[this].firstChild);
}.bind(i, img));
}
}
});
})();
", $this->width, $this->height, $this->url ? '' : "links[this].innerHTML = '';");
echo '</script>';
return true;
}
}