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 pathAdminerSimpleMenu.php
More file actions
127 lines (106 loc) · 3.68 KB
/
AdminerSimpleMenu.php
File metadata and controls
127 lines (106 loc) · 3.68 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Displays only one prefered action in table list.
*
* Get rid of schizophrenic decisions between selecting data and showing table structure.
* Optimize your workflow!
*
* @link https://github.com/pematon/adminer-plugins
*
* @author Peter Knut
* @copyright 2014-2018 Pematon, s.r.o. (http://www.pematon.com/)
*/
class AdminerSimpleMenu
{
/** @var bool */
private $preferSelect;
/** @var bool */
private $reorderLinks;
/**
* @param bool $preferSelect Whether to prefer table selection before editing structure.
* @param bool $reorderLinks Whether links above data table will be reordered to reflect workflow priority.
*/
public function __construct($preferSelect = true, $reorderLinks = true)
{
$this->preferSelect = $preferSelect;
$this->reorderLinks = $reorderLinks;
}
/**
* Prints table list in menu.
*
* @param array $tables Table list.
* @return bool|null
*/
public function tablesPrint($tables)
{
if (defined("PMTN_ADMINER_THEME")) {
echo "<ul id='tables' class='simple'>\n";
} else {
echo "<ul id='tables' class='simple'>" . script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");
}
$actions = [$_GET["select"], $_GET["edit"], $_GET["table"], $_GET["create"], $_GET["indexes"], $_GET["foreign"], $_GET["trigger"]];
foreach ($tables as $table => $status) {
$name = adminer()->tableName($status);
if ($name == "") {
continue;
}
$active = in_array($table, $actions);
if ($this->preferSelect) {
$action = "select";
$title = "Select data";
} else {
$action = "table";
$title = "Show structure";
}
echo "<li data-table-name='$name'>";
if ($this->preferSelect || support("table") || support("indexes")) {
echo '<a href="' . h(ME) . $action . '=' . urlencode($table) . '"' . bold($active, (is_view($status) ? "view" : "")) . "' data-link='main' data-main='true'>$name</a>";
} else {
echo "<span data-link='main' data-main='true'>$name</span>";
}
echo "</li>\n";
}
echo "</ul>\n";
return true;
}
/*
* Prints links after select heading.
*
* @param array $tableStatus Result of SHOW TABLE STATUS.
* @param string $set New item options, NULL for no new item.
*
* @return bool|null
*/
public function selectLinks($tableStatus, $set = "")
{
if (!$this->reorderLinks) {
return null; // null has to be returned to force Adminer print original links.
}
echo '<p class="links">';
$links = [];
if ($this->preferSelect) {
$links["select"] = lang('Select data');
}
if (support("table") || support("indexes")) {
$links["table"] = lang('Show structure');
}
if (!$this->preferSelect) {
$links["select"] = lang('Select data');
}
if (support("table")) {
if (is_view($tableStatus)) {
$links["view"] = lang('Alter view');
} else {
$links["create"] = lang('Alter table');
}
}
if ($set !== null) {
$links["edit"] = lang('New item');
}
foreach ($links as $key => $val) {
echo " <a href='" . h(ME) . "$key=" . urlencode($tableStatus["Name"]) . ($key == "edit" ? $set : "") . "'" . bold(isset($_GET[$key])) . ">$val</a>";
}
echo "\n";
return true;
}
}