2
/* $Id: plugin_interface.lib.php 9131 2006-06-25 11:42:18Z lem9 $ */
3
// vim: expandtab sw=4 ts=4 sts=4:
6
* Generic plugin interface.
10
* array PMA_getPlugins(string $plugins_dir, mixed $plugin_param)
12
* Reads all plugin information from directory $plugins_dir.
19
* @param string $plugins_dir directrory with plugins
20
* @param mixed $plugin_param parameter to plugin by which they can decide whether they can work
21
* @return array list of plugins
23
function PMA_getPlugins($plugins_dir, $plugin_param)
25
/* Scan for plugins */
26
$plugin_list = array();
27
if ($handle = @opendir($plugins_dir)) {
29
while ($file = @readdir($handle)) {
30
if (is_file($plugins_dir . $file) && eregi('\.php$', $file)) {
31
include $plugins_dir . $file;
40
* string PMA_getString(string $name)
42
* returns locale string for $name or $name if no locale is found
45
* @param string $name for local string
46
* @return string locale string for $name
48
function PMA_getString($name)
50
return isset($GLOBALS[$name]) ? $GLOBALS[$name] : $name;
54
* string PMA_pluginCheckboxCheck(string $section, string $opt)
56
* returns html input tag option 'checked' if plugin $opt should be set by config or request
59
* @uses $GLOBALS['cfg']
60
* @uses $GLOBALS['timeout_passed']
61
* @param string $section name of config section in
62
* $GLOBALS['cfg'][$section] for plugin
63
* @param string $opt name of option
64
* @return string hmtl input tag option 'checked'
66
function PMA_pluginCheckboxCheck($section, $opt)
68
if ((isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) ||
69
(isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt])) {
70
return ' checked="checked"';
76
* string PMA_pluginGetDefault(string $section, string $opt)
78
* returns default value for option $opt
80
* @uses htmlspecialchars()
82
* @uses $GLOBALS['cfg']
83
* @uses $GLOBALS['timeout_passed']
84
* @param string $section name of config section in
85
* $GLOBALS['cfg'][$section] for plugin
86
* @param string $opt name of option
87
* @return string default value for option $opt
89
function PMA_pluginGetDefault($section, $opt)
91
if (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) {
92
return htmlspecialchars($_REQUEST[$opt]);
93
} elseif (isset($GLOBALS['cfg'][$section][$opt])) {
95
/* Possibly replace localised texts */
96
if (preg_match_all('/(str[A-Z][A-Za-z0-9]*)/', $GLOBALS['cfg'][$section][$opt], $matches)) {
97
$val = $GLOBALS['cfg'][$section][$opt];
98
foreach($matches[0] as $match) {
99
if (isset($GLOBALS[$match])) {
100
$val = str_replace($match, $GLOBALS[$match], $val);
103
return htmlspecialchars($val);
105
return htmlspecialchars($GLOBALS['cfg'][$section][$opt]);
112
* string PMA_pluginIsActive(string $section, string $opt, string $val)
114
* returns html input tag option 'checked' if option $opt should be set by config or request
117
* @uses $GLOBALS['cfg']
118
* @uses $GLOBALS['timeout_passed']
119
* @param string $section name of config section in
120
* $GLOBALS['cfg'][$section] for plugin
121
* @param string $opt name of option
122
* @param string $val value of option to check against
123
* @return string html input tag option 'checked'
125
function PMA_pluginIsActive($section, $opt, $val)
127
if ( ! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt])) {
128
if ($_REQUEST[$opt] == $val) {
129
return ' checked="checked"';
131
} elseif (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt] == $val) {
132
return ' checked="checked"';
138
* string PMA_pluginGetChoice(string $section, string $name, array &$list, string $cfgname)
140
* returns html radio form element for plugin choice
142
* @uses PMA_pluginIsActive()
143
* @uses PMA_getString()
144
* @param string $section name of config section in
145
* $GLOBALS['cfg'][$section] for plugin
146
* @param string $name name of radio element
147
* @param array &$list array with plugin configuration defined in plugin file
148
* @param string $cfgname name of config value, if none same as $name
149
* @return string html input radio tag
151
function PMA_pluginGetChoice($section, $name, &$list, $cfgname = NULL)
153
if (!isset($cfgname)) {
157
foreach ($list as $plugin_name => $val) {
158
$ret .= '<!-- ' . $plugin_name . ' -->' . "\n";
159
$ret .= '<input type="radio" name="' . $name . '" value="' . $plugin_name . '"'
160
. ' id="radio_plugin_' . $plugin_name . '"'
161
. ' onclick="if(this.checked) { hide_them_all();';
162
if (isset($val['force_file'])) {
163
$ret .= 'document.getElementById(\'checkbox_dump_asfile\').checked = true;';
165
$ret .= ' document.getElementById(\'' . $plugin_name . '_options\').style.display = \'block\'; };'
167
. PMA_pluginIsActive($section, $cfgname, $plugin_name) . '/>' . "\n";
168
$ret .= '<label for="radio_plugin_' . $plugin_name . '">'
169
. PMA_getString($val['text']) . '</label>' . "\n";
170
$ret .= '<br /><br />' . "\n";
176
* string PMA_pluginGetOneOption(string $section, string $plugin_name, string $id, array &$opt)
178
* returns single option in a table row
180
* @uses PMA_getString()
181
* @uses PMA_pluginCheckboxCheck()
182
* @uses PMA_pluginGetDefault()
183
* @param string $section name of config section in
184
* $GLOBALS['cfg'][$section] for plugin
185
* @param string $plugin_name unique plugin name
186
* @param string $id option id
187
* @param array &$opt plugin option details
188
* @return string table row with option
190
function PMA_pluginGetOneOption($section, $plugin_name, $id, &$opt)
193
if ($opt['type'] == 'bool') {
194
$ret .= '<div class="formelementrow">' . "\n";
195
$ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
196
. ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
197
. ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']);
198
if (isset($opt['force'])) {
199
/* Same code is also few lines lower, update both if needed */
200
$ret .= ' onclick="if (!this.checked && '
201
. '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
202
. '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
203
. 'return false; else return true;"';
206
$ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
207
. PMA_getString($opt['text']) . '</label>';
208
$ret .= '</div>' . "\n";
209
} elseif ($opt['type'] == 'text') {
210
$ret .= '<div class="formelementrow">' . "\n";
211
$ret .= '<label for="text_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
212
. PMA_getString($opt['text']) . '</label>';
213
$ret .= '<input type="text" name="' . $plugin_name . '_' . $opt['name'] . '"'
214
. ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"'
215
. ' id="text_' . $plugin_name . '_' . $opt['name'] . '"'
216
. (isset($opt['size']) ? ' size="' . $opt['size'] . '"' : '' )
217
. (isset($opt['len']) ? ' maxlength="' . $opt['len'] . '"' : '' ) . ' />';
218
$ret .= '</div>' . "\n";
219
} elseif ($opt['type'] == 'message_only') {
220
$ret .= '<div class="formelementrow">' . "\n";
221
$ret .= '<label for="text_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
222
. PMA_getString($opt['text']) . '</label>';
223
$ret .= '</div>' . "\n";
224
} elseif ($opt['type'] == 'select') {
225
$ret .= '<div class="formelementrow">' . "\n";
226
$ret .= '<label for="select_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
227
. PMA_getString($opt['text']) . '</label>';
228
$ret .= '<select name="' . $plugin_name . '_' . $opt['name'] . '"'
229
. ' id="select_' . $plugin_name . '_' . $opt['name'] . '">';
230
$default = PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']);
231
foreach($opt['values'] as $key => $val) {
232
$ret .= '<option name="' . $key . '"';
233
if ($key == $default) {
234
$ret .= ' selected="selected"';
236
$ret .= '>' . PMA_getString($val) . '</option>';
239
$ret .= '</div>' . "\n";
240
} elseif ($opt['type'] == 'hidden') {
241
$ret .= '<input type="hidden" name="' . $plugin_name . '_' . $opt['name'] . '"'
242
. ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"' . ' />';
243
} elseif ($opt['type'] == 'bgroup') {
244
$ret .= '<fieldset><legend>';
245
/* No checkbox without name */
246
if (!empty($opt['name'])) {
247
$ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
248
. ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
249
. ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']);
250
if (isset($opt['force'])) {
251
/* Same code is also few lines higher, update both if needed */
252
$ret .= ' onclick="if (!this.checked && '
253
. '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
254
. '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
255
. 'return false; else return true;"';
258
$ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
259
. PMA_getString($opt['text']) . '</label>';
261
$ret .= PMA_getString($opt['text']);
264
} elseif ($opt['type'] == 'egroup') {
265
$ret .= '</fieldset>';
267
/* This should be seen only by plugin writers, so I do not thing this
268
* needs translation. */
269
$ret .= 'UNKNOWN OPTION ' . $opt['type'] . ' IN IMPORT PLUGIN ' . $plugin_name . '!';
271
if (isset($opt['doc'])) {
272
$ret .= PMA_showMySQLDocu($opt['doc'][0], $opt['doc'][1]);
279
* string PMA_pluginGetOptions(string $section, array &$list)
281
* return html fieldset with editable options for plugin
283
* @uses PMA_getString()
284
* @uses PMA_pluginGetOneOption()
285
* @param string $section name of config section in $GLOBALS['cfg'][$section]
286
* @param array &$list array with plugin configuration defined in plugin file
287
* @return string html fieldset with plugin options
289
function PMA_pluginGetOptions($section, &$list)
292
// Options for plugins that support them
293
foreach ($list as $plugin_name => $val) {
294
$ret .= '<fieldset id="' . $plugin_name . '_options" class="options">';
295
$ret .= '<legend>' . PMA_getString($val['options_text']) . '</legend>';
297
if (isset($val['options']) && count($val['options']) > 0) {
298
foreach ($val['options'] as $id => $opt) {
299
if ($opt['type'] != 'hidden') $count++;
300
$ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt);
304
$ret .= $GLOBALS['strNoOptions'];
306
$ret .= '</fieldset>';
312
* string PMA_pluginGetJavascript(array &$list)
314
* return html/javascript code which is needed for handling plugin stuff
316
* @param array &$list array with plugin configuration defined in plugin file
317
* @return string html fieldset with plugin options
319
function PMA_pluginGetJavascript(&$list) {
321
<script type="text/javascript" language="javascript">
323
function hide_them_all() {
325
foreach ($list as $plugin_name => $val) {
326
$ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "none";' . "\n";
331
function init_options() {
334
foreach ($list as $plugin_name => $val) {
335
$ret .= 'if (document.getElementById("radio_plugin_' . $plugin_name . '").checked) {' . "\n";
336
if (isset($val['force_file'])) {
337
$ret .= 'document.getElementById(\'checkbox_dump_asfile\').checked = true;' . "\n";
339
$ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "block";' . "\n";
340
$ret .= ' } else ' . "\n";
348
function match_file(fname) {
349
farr = fname.toLowerCase().split(".");
350
if (farr.length != 0) {
352
if (farr[len - 1] == "gz" || farr[len - 1] == "bz2" || farr[len -1] == "zip") len--;
353
switch (farr[len - 1]) {
355
foreach ($list as $plugin_name => $val) {
356
$ret .= 'case "' . $val['extension'] . '" :';
357
$ret .= 'document.getElementById("radio_plugin_' . $plugin_name . '").checked = true;';
358
$ret .= 'init_options();';
359
$ret .= 'break;' . "\n";