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)) {
23 while ($file = @readdir
($handle)) {
24 // In some situations, Mac OS creates a new file for each file
25 // (for example ._csv.php) so the following regexp
26 // matches a file which does not start with a dot but ends
28 if (is_file($plugins_dir . $file) && preg_match('@^[^\.](.)*\.php$@i', $file)) {
29 include $plugins_dir . $file;
38 * string PMA_getString(string $name)
40 * returns locale string for $name or $name if no locale is found
42 * @param string $name for local string
43 * @return string locale string for $name
45 function PMA_getString($name)
47 return isset($GLOBALS[$name]) ?
$GLOBALS[$name] : $name;
51 * string PMA_pluginCheckboxCheck(string $section, string $opt)
53 * returns html input tag option 'checked' if plugin $opt should be set by config or request
55 * @param string $section name of config section in
56 * $GLOBALS['cfg'][$section] for plugin
57 * @param string $opt name of option
58 * @return string hmtl input tag option 'checked'
60 function PMA_pluginCheckboxCheck($section, $opt)
62 // If the form is being repopulated using $_GET data, that is priority
63 if (isset($_GET[$opt]) ||
! isset($_GET['repopulate']) && ((isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) ||
64 (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt]))) {
65 return ' checked="checked"';
71 * string PMA_pluginGetDefault(string $section, string $opt)
73 * returns default value for option $opt
75 * @param string $section name of config section in
76 * $GLOBALS['cfg'][$section] for plugin
77 * @param string $opt name of option
78 * @return string default value for option $opt
80 function PMA_pluginGetDefault($section, $opt)
82 if (isset($_GET[$opt])) { // If the form is being repopulated using $_GET data, that is priority
83 return htmlspecialchars($_GET[$opt]);
84 } elseif (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) {
85 return htmlspecialchars($_REQUEST[$opt]);
86 } elseif (isset($GLOBALS['cfg'][$section][$opt])) {
88 /* Possibly replace localised texts */
89 if (preg_match_all('/(str[A-Z][A-Za-z0-9]*)/', $GLOBALS['cfg'][$section][$opt], $matches)) {
90 $val = $GLOBALS['cfg'][$section][$opt];
91 foreach ($matches[0] as $match) {
92 if (isset($GLOBALS[$match])) {
93 $val = str_replace($match, $GLOBALS[$match], $val);
96 return htmlspecialchars($val);
98 return htmlspecialchars($GLOBALS['cfg'][$section][$opt]);
105 * string PMA_pluginIsActive(string $section, string $opt, string $val)
107 * returns html input tag option 'checked' if option $opt should be set by config or request
109 * @param string $section name of config section in
110 * $GLOBALS['cfg'][$section] for plugin
111 * @param string $opt name of option
112 * @param string $val value of option to check against
113 * @return string html input tag option 'checked'
115 function PMA_pluginIsActive($section, $opt, $val)
117 if (! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt])) {
118 if ($_REQUEST[$opt] == $val) {
119 return ' checked="checked"';
121 } elseif (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt] == $val) {
122 return ' checked="checked"';
128 * string PMA_pluginGetChoice(string $section, string $name, array &$list, string $cfgname)
130 * returns html select form element for plugin choice
131 * and hidden fields denoting whether each plugin must be exported as a file
133 * @param string $section name of config section in
134 * $GLOBALS['cfg'][$section] for plugin
135 * @param string $name name of select element
136 * @param array &$list array with plugin configuration defined in plugin file
137 * @param string $cfgname name of config value, if none same as $name
138 * @return string html select tag
140 function PMA_pluginGetChoice($section, $name, &$list, $cfgname = null)
142 if (! isset($cfgname)) {
145 $ret = '<select id="plugins" name="' . $name . '">';
146 $default = PMA_pluginGetDefault($section, $cfgname);
147 foreach ($list as $plugin_name => $val) {
149 // If the form is being repopulated using $_GET data, that is priority
150 if (isset($_GET[$name]) && $plugin_name == $_GET[$name] ||
! isset($_GET[$name]) && $plugin_name == $default) {
151 $ret .= ' selected="selected"';
153 $ret .= ' value="' . $plugin_name . '">' . PMA_getString($val['text']) . '</option>' . "\n";
155 $ret .= '</select>' . "\n";
157 // Whether each plugin has to be saved as a file
158 foreach ($list as $plugin_name => $val) {
159 $ret .= '<input type="hidden" id="force_file_' . $plugin_name . '" value="';
160 if (isset($val['force_file'])) {
165 $ret .= '" />'. "\n";
171 * string PMA_pluginGetOneOption(string $section, string $plugin_name, string $id, array &$opt)
173 * returns single option in a list element
175 * @param string $section name of config section in
176 * $GLOBALS['cfg'][$section] for plugin
177 * @param string $plugin_name unique plugin name
178 * @param string $id option id
179 * @param array &$opt plugin option details
180 * @return string table row with option
182 function PMA_pluginGetOneOption($section, $plugin_name, $id, &$opt)
185 if ($opt['type'] == 'bool') {
186 $ret .= '<li>' . "\n";
187 $ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
188 . ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
189 . ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']);
190 if (isset($opt['force'])) {
191 /* Same code is also few lines lower, update both if needed */
192 $ret .= ' onclick="if (!this.checked && '
193 . '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
194 . '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
195 . 'return false; else return true;"';
198 $ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
199 . PMA_getString($opt['text']) . '</label>';
200 } elseif ($opt['type'] == 'text') {
201 $ret .= '<li>' . "\n";
202 $ret .= '<label for="text_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
203 . PMA_getString($opt['text']) . '</label>';
204 $ret .= '<input type="text" name="' . $plugin_name . '_' . $opt['name'] . '"'
205 . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"'
206 . ' id="text_' . $plugin_name . '_' . $opt['name'] . '"'
207 . (isset($opt['size']) ?
' size="' . $opt['size'] . '"' : '')
208 . (isset($opt['len']) ?
' maxlength="' . $opt['len'] . '"' : '') . ' />';
209 } elseif ($opt['type'] == 'message_only') {
210 $ret .= '<li>' . "\n";
211 $ret .= '<p>' . PMA_getString($opt['text']) . '</p>';
212 } elseif ($opt['type'] == 'select') {
213 $ret .= '<li>' . "\n";
214 $ret .= '<label for="select_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
215 . PMA_getString($opt['text']) . '</label>';
216 $ret .= '<select name="' . $plugin_name . '_' . $opt['name'] . '"'
217 . ' id="select_' . $plugin_name . '_' . $opt['name'] . '">';
218 $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']);
219 foreach ($opt['values'] as $key => $val) {
220 $ret .= '<option value="' . $key . '"';
221 if ($key == $default) {
222 $ret .= ' selected="selected"';
224 $ret .= '>' . PMA_getString($val) . '</option>';
227 } elseif ($opt['type'] == 'radio') {
228 $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']);
229 foreach ($opt['values'] as $key => $val) {
230 $ret .= '<li><input type="radio" name="' . $plugin_name . '_' . $opt['name'] . '" value="' . $key
231 . '" id="radio_' . $plugin_name . '_' . $opt['name'] . '_' . $key . '"';
232 if ($key == $default) {
233 $ret .= 'checked="checked"';
235 $ret .= ' />' . '<label for="radio_' . $plugin_name . '_' . $opt['name'] . '_' . $key . '">'
236 . PMA_getString($val) . '</label></li>';
238 } elseif ($opt['type'] == 'hidden') {
239 $ret .= '<li><input type="hidden" name="' . $plugin_name . '_' . $opt['name'] . '"'
240 . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"' . ' /></li>';
241 } elseif ($opt['type'] == 'begin_group') {
242 $ret .= '<div class="export_sub_options" id="' . $plugin_name . '_' . $opt['name'] . '">';
243 if (isset($opt['text'])) {
244 $ret .= '<h4>' . PMA_getString($opt['text']) . '</h4>';
247 } elseif ($opt['type'] == 'end_group') {
248 $ret .= '</ul></div>';
249 } elseif ($opt['type'] == 'begin_subgroup') {
250 /* each subgroup can have a header, which may also be a form element */
251 $ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt['subgroup_header']) . '<li class="subgroup"><ul';
252 if (isset($opt['subgroup_header']['name'])) {
253 $ret .= ' id="ul_' . $opt['subgroup_header']['name'] . '">';
257 } elseif ($opt['type'] == 'end_subgroup') {
258 $ret .= '</ul></li>';
260 /* This should be seen only by plugin writers, so I do not thing this
261 * needs translation. */
262 $ret .= 'UNKNOWN OPTION ' . $opt['type'] . ' IN IMPORT PLUGIN ' . $plugin_name . '!';
264 if (isset($opt['doc'])) {
265 if (count($opt['doc']) == 3) {
266 $ret .= PMA_showMySQLDocu($opt['doc'][0], $opt['doc'][1], false, $opt['doc'][2]);
267 } elseif (count($opt['doc']) == 1) {
268 $ret .= PMA_showDocu($opt['doc'][0]);
270 $ret .= PMA_showMySQLDocu($opt['doc'][0], $opt['doc'][1]);
274 // Close the list element after $opt['doc'] link is displayed
275 if ($opt['type'] == 'bool' ||
$opt['type'] == 'text' ||
$opt['type'] == 'message_only' ||
$opt['type'] == 'select') {
283 * string PMA_pluginGetOptions(string $section, array &$list)
285 * return html div with editable options for plugin
287 * @param string $section name of config section in $GLOBALS['cfg'][$section]
288 * @param array &$list array with plugin configuration defined in plugin file
289 * @return string html fieldset with plugin options
291 function PMA_pluginGetOptions($section, &$list)
294 $default = PMA_pluginGetDefault('Export', 'format');
295 // Options for plugins that support them
296 foreach ($list as $plugin_name => $val) {
297 $ret .= '<div id="' . $plugin_name . '_options" class="format_specific_options">';
299 $ret .= '<h3>' . PMA_getString($val['text']) . '</h3>';
300 if (isset($val['options']) && count($val['options']) > 0) {
301 foreach ($val['options'] as $id => $opt) {
302 if ($opt['type'] != 'hidden' && $opt['type'] != 'begin_group' && $opt['type'] != 'end_group' && $opt['type'] != 'begin_subgroup' && $opt['type'] != 'end_subgroup') {
305 $ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt);
309 $ret .= '<p>' . __('This format has no options') . '</p>';