This repository was archived by the owner on Mar 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathAdminerCollations.php
More file actions
97 lines (78 loc) · 2.81 KB
/
AdminerCollations.php
File metadata and controls
97 lines (78 loc) · 2.81 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Custom character sets in collation select boxes.
*
* @link https://github.com/pematon/adminer-plugins
*
* @author Peter Knut
* @copyright 2015-2018 Pematon, s.r.o. (http://www.pematon.com/)
*/
class AdminerCollations
{
/** @var array */
private $characterSets;
/**
* @param array $characterSets Array of allowed character sets.
*/
public function __construct(array $characterSets = ["utf8mb4_general_ci", "ascii_general_ci"])
{
$this->characterSets = $characterSets;
}
/**
* Prints HTML code inside <head>.
*/
public function head()
{
if (empty($this->characterSets)) {
return;
}
?>
<script <?php echo nonce(); ?>>
(function(document) {
"use strict";
const characterSets = [
<?php
echo "'(" . lang('collation') . ")'";
foreach ($this->characterSets as $characterSet) {
echo ", '" . $characterSet . "'";
}
?>
];
document.addEventListener("DOMContentLoaded", init, false);
function init() {
var selects = document.querySelectorAll("select[name='Collation'], select[name*='collation']");
for (var i = 0; i < selects.length; i++) {
replaceOptions(selects[i]);
}
}
function replaceOptions(select) {
var selectedSet = getSelectedSet(select);
var html = '';
var hasSelected = false;
for (var i = 0; i < characterSets.length; i++) {
if (characterSets[i] === selectedSet) {
hasSelected = true;
html += '<option selected="selected">' + characterSets[i] + '</option>';
} else {
html += '<option>' + characterSets[i] + '</option>';
}
}
if (!hasSelected && selectedSet !== "") {
html += '<option selected="selected">' + selectedSet + '</option>';
}
select.innerHTML = html;
}
function getSelectedSet(select) {
var options = select.getElementsByTagName("option");
for (var i = 0; i < options.length; i++) {
if (options[i].selected) {
return options[i].innerHTML.trim();
}
}
return "";
}
})(document);
</script>
<?php
}
}