1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** Adminer customization allowing usage of plugins |
4
|
|
|
* @link https://www.adminer.org/plugins/#use |
5
|
|
|
* @author Jakub Vrana, http://www.vrana.cz/ |
6
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
7
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) |
8
|
|
|
*/ |
9
|
|
|
class AdminerPlugin extends Adminer { |
10
|
|
|
/** @access protected */ |
11
|
|
|
var $plugins; |
12
|
|
|
|
13
|
|
|
function _findRootClass($class) { // is_subclass_of(string, string) is available since PHP 5.0.3 |
|
|
|
|
14
|
|
|
do { |
15
|
|
|
$return = $class; |
16
|
|
|
} while ($class = get_parent_class($class)); |
17
|
|
|
return $return; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** Register plugins |
21
|
|
|
* @param array object instances or null to register all classes starting by 'Adminer' |
22
|
|
|
*/ |
23
|
|
|
function __construct($plugins) { |
|
|
|
|
24
|
|
|
if ($plugins === null) { |
25
|
|
|
$plugins = array(); |
26
|
|
|
foreach (get_declared_classes() as $class) { |
27
|
|
|
if (preg_match('~^Adminer.~i', $class) && strcasecmp($this->_findRootClass($class), 'Adminer')) { //! can use interface |
|
|
|
|
28
|
|
|
$plugins[$class] = new $class; |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
$this->plugins = $plugins; |
33
|
|
|
//! it is possible to use ReflectionObject to find out which plugins defines which methods at once |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function _callParent($function, $args) { |
|
|
|
|
37
|
|
|
return call_user_func_array(array('parent', $function), $args); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function _applyPlugin($function, $args) { |
|
|
|
|
41
|
|
|
foreach ($this->plugins as $plugin) { |
42
|
|
|
if (method_exists($plugin, $function)) { |
43
|
|
|
switch (count($args)) { // call_user_func_array() doesn't work well with references |
44
|
|
|
case 0: $return = $plugin->$function(); break; |
45
|
|
|
case 1: $return = $plugin->$function($args[0]); break; |
46
|
|
|
case 2: $return = $plugin->$function($args[0], $args[1]); break; |
47
|
|
View Code Duplication |
case 3: $return = $plugin->$function($args[0], $args[1], $args[2]); break; |
|
|
|
|
48
|
|
View Code Duplication |
case 4: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3]); break; |
|
|
|
|
49
|
|
View Code Duplication |
case 5: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3], $args[4]); break; |
|
|
|
|
50
|
|
|
case 6: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); break; |
51
|
|
|
default: trigger_error('Too many parameters.', E_USER_WARNING); |
52
|
|
|
} |
53
|
|
|
if ($return !== null) { |
54
|
|
|
return $return; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
return $this->_callParent($function, $args); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function _appendPlugin($function, $args) { |
|
|
|
|
62
|
|
|
$return = $this->_callParent($function, $args); |
63
|
|
|
foreach ($this->plugins as $plugin) { |
64
|
|
|
if (method_exists($plugin, $function)) { |
65
|
|
|
$return += call_user_func_array(array($plugin, $function), $args); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
return $return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// appendPlugin |
72
|
|
|
|
73
|
|
|
function dumpFormat() { |
|
|
|
|
74
|
|
|
$args = func_get_args(); |
75
|
|
|
return $this->_appendPlugin(__FUNCTION__, $args); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
function dumpOutput() { |
|
|
|
|
79
|
|
|
$args = func_get_args(); |
80
|
|
|
return $this->_appendPlugin(__FUNCTION__, $args); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function editFunctions($field) { |
|
|
|
|
84
|
|
|
$args = func_get_args(); |
85
|
|
|
return $this->_appendPlugin(__FUNCTION__, $args); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// applyPlugin |
89
|
|
|
|
90
|
|
|
function name() { |
|
|
|
|
91
|
|
|
$args = func_get_args(); |
92
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
function credentials() { |
|
|
|
|
96
|
|
|
$args = func_get_args(); |
97
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
function permanentLogin($create = false) { |
|
|
|
|
101
|
|
|
$args = func_get_args(); |
102
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
function database() { |
|
|
|
|
106
|
|
|
$args = func_get_args(); |
107
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
function schemas() { |
|
|
|
|
111
|
|
|
$args = func_get_args(); |
112
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
function databases($flush = true) { |
|
|
|
|
116
|
|
|
$args = func_get_args(); |
117
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
function queryTimeout() { |
|
|
|
|
121
|
|
|
$args = func_get_args(); |
122
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
function headers() { |
|
|
|
|
126
|
|
|
$args = func_get_args(); |
127
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
function head() { |
|
|
|
|
131
|
|
|
$args = func_get_args(); |
132
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
function loginForm() { |
|
|
|
|
136
|
|
|
$args = func_get_args(); |
137
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
function login($login, $password) { |
|
|
|
|
141
|
|
|
$args = func_get_args(); |
142
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
function tableName($tableStatus) { |
|
|
|
|
146
|
|
|
$args = func_get_args(); |
147
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
function fieldName($field, $order = 0) { |
|
|
|
|
151
|
|
|
$args = func_get_args(); |
152
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
function selectLinks($tableStatus, $set = '') { |
|
|
|
|
156
|
|
|
$args = func_get_args(); |
157
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
function foreignKeys($table) { |
|
|
|
|
161
|
|
|
$args = func_get_args(); |
162
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
function backwardKeys($table, $tableName) { |
|
|
|
|
166
|
|
|
$args = func_get_args(); |
167
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
function backwardKeysPrint($backwardKeys, $row) { |
|
|
|
|
171
|
|
|
$args = func_get_args(); |
172
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
function selectQuery($query, $time) { |
|
|
|
|
176
|
|
|
$args = func_get_args(); |
177
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
function rowDescription($table) { |
|
|
|
|
181
|
|
|
$args = func_get_args(); |
182
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
function rowDescriptions($rows, $foreignKeys) { |
|
|
|
|
186
|
|
|
$args = func_get_args(); |
187
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
function selectLink($val, $field) { |
|
|
|
|
191
|
|
|
$args = func_get_args(); |
192
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
function selectVal($val, $link, $field, $original) { |
|
|
|
|
196
|
|
|
$args = func_get_args(); |
197
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
function editVal($val, $field) { |
|
|
|
|
201
|
|
|
$args = func_get_args(); |
202
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
function selectColumnsPrint($select, $columns) { |
|
|
|
|
206
|
|
|
$args = func_get_args(); |
207
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
function selectSearchPrint($where, $columns, $indexes) { |
|
|
|
|
211
|
|
|
$args = func_get_args(); |
212
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
function selectOrderPrint($order, $columns, $indexes) { |
|
|
|
|
216
|
|
|
$args = func_get_args(); |
217
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
function selectLimitPrint($limit) { |
|
|
|
|
221
|
|
|
$args = func_get_args(); |
222
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
function selectLengthPrint($text_length) { |
|
|
|
|
226
|
|
|
$args = func_get_args(); |
227
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
function selectActionPrint($indexes) { |
|
|
|
|
231
|
|
|
$args = func_get_args(); |
232
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
function selectCommandPrint() { |
|
|
|
|
236
|
|
|
$args = func_get_args(); |
237
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
function selectImportPrint() { |
|
|
|
|
241
|
|
|
$args = func_get_args(); |
242
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
function selectEmailPrint($emailFields, $columns) { |
|
|
|
|
246
|
|
|
$args = func_get_args(); |
247
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
function selectColumnsProcess($columns, $indexes) { |
|
|
|
|
251
|
|
|
$args = func_get_args(); |
252
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
function selectSearchProcess($fields, $indexes) { |
|
|
|
|
256
|
|
|
$args = func_get_args(); |
257
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
function selectOrderProcess($fields, $indexes) { |
|
|
|
|
261
|
|
|
$args = func_get_args(); |
262
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
function selectLimitProcess() { |
|
|
|
|
266
|
|
|
$args = func_get_args(); |
267
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
function selectLengthProcess() { |
|
|
|
|
271
|
|
|
$args = func_get_args(); |
272
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
function selectEmailProcess($where, $foreignKeys) { |
|
|
|
|
276
|
|
|
$args = func_get_args(); |
277
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
function selectQueryBuild($select, $where, $group, $order, $limit, $page) { |
|
|
|
|
281
|
|
|
$args = func_get_args(); |
282
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
function messageQuery($query, $time) { |
|
|
|
|
286
|
|
|
$args = func_get_args(); |
287
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
function editInput($table, $field, $attrs, $value) { |
|
|
|
|
291
|
|
|
$args = func_get_args(); |
292
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
function processInput($field, $value, $function = '') { |
|
|
|
|
296
|
|
|
$args = func_get_args(); |
297
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
function dumpDatabase($db) { |
|
|
|
|
301
|
|
|
$args = func_get_args(); |
302
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
function dumpTable($table, $style, $is_view = 0) { |
|
|
|
|
306
|
|
|
$args = func_get_args(); |
307
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
function dumpData($table, $style, $query) { |
|
|
|
|
311
|
|
|
$args = func_get_args(); |
312
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
function dumpFilename($identifier) { |
|
|
|
|
316
|
|
|
$args = func_get_args(); |
317
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
function dumpHeaders($identifier, $multi_table = false) { |
|
|
|
|
321
|
|
|
$args = func_get_args(); |
322
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
function homepage() { |
|
|
|
|
326
|
|
|
$args = func_get_args(); |
327
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
function navigation($missing) { |
|
|
|
|
331
|
|
|
$args = func_get_args(); |
332
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
function databasesPrint($missing) { |
|
|
|
|
336
|
|
|
$args = func_get_args(); |
337
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
function tablesPrint($tables) { |
|
|
|
|
341
|
|
|
$args = func_get_args(); |
342
|
|
|
return $this->_applyPlugin(__FUNCTION__, $args); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
} |
346
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.