2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Generic plugin interface.
10 * array PMA_getPlugins(string $plugins_dir, mixed $plugin_param)
12 * Reads all plugin information from directory $plugins_dir.
14 * @param string $plugins_dir directrory with plugins
15 * @param mixed $plugin_param parameter to plugin by which they can decide whether they can work
16 * @return array list of plugins
18 function PMA_getPlugins($plugins_dir, $plugin_param)
20 /* Scan for plugins */
21 $plugin_list = array();
22 if ($handle = @opendir
($plugins_dir)) {
24 while ($file = @readdir
($handle)) {
25 // In some situations, Mac OS creates a new file for each file
26 // (for example ._csv.php) so the following regexp
27 // matches a file which does not start with a dot but ends
29 if (is_file($plugins_dir . $file) && preg_match('@^[^\.](.)*\.php$@i', $file)) {
30 include $plugins_dir . $file;
39 * string PMA_getString(string $name)
41 * returns locale string for $name or $name if no locale is found
43 * @param string $name for local string
44 * @return string locale string for $name
46 function PMA_getString($name)
48 return isset($GLOBALS[$name]) ?
$GLOBALS[$name] : $name;
52 * string PMA_pluginCheckboxCheck(string $section, string $opt)
54 * returns html input tag option 'checked' if plugin $opt should be set by config or request
56 * @param string $section name of config section in
57 * $GLOBALS['cfg'][$section] for plugin
58 * @param string $opt name of option
59 * @return string hmtl input tag option 'checked'
61 function PMA_pluginCheckboxCheck($section, $opt)
63 // If the form is being repopulated using $_GET data, that is priority
64 if (isset($_GET[$opt]) ||
! isset($_GET['repopulate']) && ((isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) ||
65 (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt]))) {
66 return ' checked="checked"';
72 * string PMA_pluginGetDefault(string $section, string $opt)
74 * returns default value for option $opt
76 * @param string $section name of config section in
77 * $GLOBALS['cfg'][$section] for plugin
78 * @param string $opt name of option
79 * @return string default value for option $opt
81 function PMA_pluginGetDefault($section, $opt)
83 if (isset($_GET[$opt])) { // If the form is being repopulated using $_GET data, that is priority
84 return htmlspecialchars($_GET[$opt]);
85 } elseif (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) {
86 return htmlspecialchars($_REQUEST[$opt]);
87 } elseif (isset($GLOBALS['cfg'][$section][$opt])) {
89 /* Possibly replace localised texts */
90 if (preg_match_all('/(str[A-Z][A-Za-z0-9]*)/', $GLOBALS['cfg'][$section][$opt], $matches)) {
91 $val = $GLOBALS['cfg'][$section][$opt];
92 foreach ($matches[0] as $match) {
93 if (isset($GLOBALS[$match])) {
94 $val = str_replace($match, $GLOBALS[$match], $val);
97 return htmlspecialchars($val);
99 return htmlspecialchars($GLOBALS['cfg'][$section][$opt]);
106 * string PMA_pluginIsActive(string $section, string $opt, string $val)
108 * returns html input tag option 'checked' if option $opt should be set by config or request
110 * @param string $section name of config section in
111 * $GLOBALS['cfg'][$section] for plugin
112 * @param string $opt name of option
113 * @param string $val value of option to check against
114 * @return string html input tag option 'checked'
116 function PMA_pluginIsActive($section, $opt, $val)
118 if (! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt])) {
119 if ($_REQUEST[$opt] == $val) {
120 return ' checked="checked"';
122 } elseif (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt] == $val) {
123 return ' checked="checked"';
129 * string PMA_pluginGetChoice(string $section, string $name, array &$list, string $cfgname)
131 * returns html select form element for plugin choice
132 * and hidden fields denoting whether each plugin must be exported as a file
134 * @param string $section name of config section in
135 * $GLOBALS['cfg'][$section] for plugin
136 * @param string $name name of select element
137 * @param array &$list array with plugin configuration defined in plugin file
138 * @param string $cfgname name of config value, if none same as $name
139 * @return string html select tag
141 function PMA_pluginGetChoice($section, $name, &$list, $cfgname = null)
143 if (! isset($cfgname)) {
146 $ret = '<select id="plugins" name="' . $name . '">';
147 $default = PMA_pluginGetDefault($section, $cfgname);
148 foreach ($list as $plugin_name => $val) {
150 // If the form is being repopulated using $_GET data, that is priority
151 if (isset($_GET[$name]) && $plugin_name == $_GET[$name] ||
! isset($_GET[$name]) && $plugin_name == $default) {
152 $ret .= ' selected="selected"';
154 $ret .= ' value="' . $plugin_name . '">' . PMA_getString($val['text']) . '</option>' . "\n";
156 $ret .= '</select>' . "\n";
158 // Whether each plugin has to be saved as a file
159 foreach ($list as $plugin_name => $val) {
160 $ret .= '<input type="hidden" id="force_file_' . $plugin_name . '" value="';
161 if (isset($val['force_file'])) {
166 $ret .= '" />'. "\n";
172 * string PMA_pluginGetOneOption(string $section, string $plugin_name, string $id, array &$opt)
174 * returns single option in a list element
176 * @param string $section name of config section in
177 * $GLOBALS['cfg'][$section] for plugin
178 * @param string $plugin_name unique plugin name
179 * @param string $id option id
180 * @param array &$opt plugin option details
181 * @return string table row with option
183 function PMA_pluginGetOneOption($section, $plugin_name, $id, &$opt)
186 if ($opt['type'] == 'bool') {
187 $ret .= '<li>' . "\n";
188 $ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
189 . ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
190 . ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']);
191 if (isset($opt['force'])) {
192 /* Same code is also few lines lower, update both if needed */
193 $ret .= ' onclick="if (!this.checked && '
194 . '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
195 . '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
196 . 'return false; else return true;"';
199 $ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
200 . PMA_getString($opt['text']) . '</label>';
201 } elseif ($opt['type'] == 'text') {
202 $ret .= '<li>' . "\n";
203 $ret .= '<label for="text_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
204 . PMA_getString($opt['text']) . '</label>';
205 $ret .= '<input type="text" name="' . $plugin_name . '_' . $opt['name'] . '"'
206 . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"'
207 . ' id="text_' . $plugin_name . '_' . $opt['name'] . '"'
208 . (isset($opt['size']) ?
' size="' . $opt['size'] . '"' : '')
209 . (isset($opt['len']) ?
' maxlength="' . $opt['len'] . '"' : '') . ' />';
210 } elseif ($opt['type'] == 'message_only') {
211 $ret .= '<li>' . "\n";
212 $ret .= '<p>' . PMA_getString($opt['text']) . '</p>';
213 } elseif ($opt['type'] == 'select') {
214 $ret .= '<li>' . "\n";
215 $ret .= '<label for="select_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
216 . PMA_getString($opt['text']) . '</label>';
217 $ret .= '<select name="' . $plugin_name . '_' . $opt['name'] . '"'
218 . ' id="select_' . $plugin_name . '_' . $opt['name'] . '">';
219 $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']);
220 foreach ($opt['values'] as $key => $val) {
221 $ret .= '<option value="' . $key . '"';
222 if ($key == $default) {
223 $ret .= ' selected="selected"';
225 $ret .= '>' . PMA_getString($val) . '</option>';
228 } elseif ($opt['type'] == 'radio') {
229 $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']);
230 foreach ($opt['values'] as $key => $val) {
231 $ret .= '<li><input type="radio" name="' . $plugin_name . '_' . $opt['name'] . '" value="' . $key
232 . '" id="radio_' . $plugin_name . '_' . $opt['name'] . '_' . $key . '"';
233 if ($key == $default) {
234 $ret .= 'checked="checked"';
236 $ret .= ' />' . '<label for="radio_' . $plugin_name . '_' . $opt['name'] . '_' . $key . '">'
237 . PMA_getString($val) . '</label></li>';
239 } elseif ($opt['type'] == 'hidden') {
240 $ret .= '<li><input type="hidden" name="' . $plugin_name . '_' . $opt['name'] . '"'
241 . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"' . ' /></li>';
242 } elseif ($opt['type'] == 'begin_group') {
243 $ret .= '<div class="export_sub_options" id="' . $plugin_name . '_' . $opt['name'] . '">';
244 if (isset($opt['text'])) {
245 $ret .= '<h4>' . PMA_getString($opt['text']) . '</h4>';
248 } elseif ($opt['type'] == 'end_group') {
249 $ret .= '</ul></div>';
250 } elseif ($opt['type'] == 'begin_subgroup') {
251 /* each subgroup can have a header, which may also be a form element */
252 $ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt['subgroup_header']) . '<li class="subgroup"><ul';
253 if (isset($opt['subgroup_header']['name'])) {
254 $ret .= ' id="ul_' . $opt['subgroup_header']['name'] . '">';
258 } elseif ($opt['type'] == 'end_subgroup') {
259 $ret .= '</ul></li>';
261 /* This should be seen only by plugin writers, so I do not thing this
262 * needs translation. */
263 $ret .= 'UNKNOWN OPTION ' . $opt['type'] . ' IN IMPORT PLUGIN ' . $plugin_name . '!';
265 if (isset($opt['doc'])) {
266 if (count($opt['doc']) == 3) {
267 $ret .= PMA_showMySQLDocu($opt['doc'][0], $opt['doc'][1], false, $opt['doc'][2]);
268 } elseif (count($opt['doc']) == 1) {
269 $ret .= PMA_showDocu($opt['doc'][0]);
271 $ret .= PMA_showMySQLDocu($opt['doc'][0], $opt['doc'][1]);
275 // Close the list element after $opt['doc'] link is displayed
276 if ($opt['type'] == 'bool' ||
$opt['type'] == 'text' ||
$opt['type'] == 'message_only' ||
$opt['type'] == 'select') {
284 * string PMA_pluginGetOptions(string $section, array &$list)
286 * return html div with editable options for plugin
288 * @param string $section name of config section in $GLOBALS['cfg'][$section]
289 * @param array &$list array with plugin configuration defined in plugin file
290 * @return string html fieldset with plugin options
292 function PMA_pluginGetOptions($section, &$list)
295 $default = PMA_pluginGetDefault('Export', 'format');
296 // Options for plugins that support them
297 foreach ($list as $plugin_name => $val) {
298 $ret .= '<div id="' . $plugin_name . '_options" class="format_specific_options">';
300 $ret .= '<h3>' . PMA_getString($val['text']) . '</h3>';
301 if (isset($val['options']) && count($val['options']) > 0) {
302 foreach ($val['options'] as $id => $opt) {
303 if ($opt['type'] != 'hidden' && $opt['type'] != 'begin_group' && $opt['type'] != 'end_group' && $opt['type'] != 'begin_subgroup' && $opt['type'] != 'end_subgroup') {
306 $ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt);
310 $ret .= '<p>' . __('This format has no options') . '</p>';